From f8bb2f59e121e03b1e68f64cb2a2fb0a20386bb4 Mon Sep 17 00:00:00 2001 From: Ralph Boehme Date: Thu, 30 Apr 2020 15:14:36 +0200 Subject: [PATCH] smbd: move time_t twrp to @GMT string token conversion to canonicalize_snapshot_path() Prepares for canonicalize_snapshot_path() being the one-stop shop for previous-versions related stuff in subsequent commits. Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- source3/printing/nt_printing.c | 2 +- source3/smbd/filename.c | 56 ++++++++++++++++++---------------- source3/smbd/msdfs.c | 2 +- source3/smbd/proto.h | 1 + 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/source3/printing/nt_printing.c b/source3/printing/nt_printing.c index 50982e7e1aa..02d6a915755 100644 --- a/source3/printing/nt_printing.c +++ b/source3/printing/nt_printing.c @@ -277,7 +277,7 @@ static NTSTATUS driver_unix_convert(connection_struct *conn, } trim_string(name,"/","/"); - status = unix_convert(ctx, conn, name, smb_fname, 0); + status = unix_convert(ctx, conn, name, NULL, smb_fname, 0); if (!NT_STATUS_IS_OK(status)) { return NT_STATUS_NO_MEMORY; } diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index 6cfc1855993..c80b0fde797 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -364,13 +364,38 @@ static NTSTATUS rearrange_snapshot_path(struct smb_filename *smb_fname, * instead. */ -static NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname) +static NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname, + time_t *twrp) { char *startp = strchr_m(smb_fname->base_name, '@'); char *endp = NULL; struct tm tm; NTSTATUS status; + if (twrp != NULL) { + struct tm *ptm = gmtime_r(twrp, &tm); + char *twrp_name = NULL; + + twrp_name = talloc_asprintf( + smb_fname, + "@GMT-%04u.%02u.%02u-%02u.%02u.%02u/%s", + ptm->tm_year + 1900, + ptm->tm_mon + 1, + ptm->tm_mday, + ptm->tm_hour, + ptm->tm_min, + ptm->tm_sec, + smb_fname->base_name); + if (twrp_name == NULL) { + return NT_STATUS_NO_MEMORY; + } + + TALLOC_FREE(smb_fname->base_name); + smb_fname->base_name = twrp_name; + + return NT_STATUS_OK; + } + if (startp == NULL) { /* No @ */ return NT_STATUS_OK; @@ -899,6 +924,7 @@ static NTSTATUS unix_convert_step(struct uc_state *state) NTSTATUS unix_convert(TALLOC_CTX *mem_ctx, connection_struct *conn, const char *orig_path, + time_t *twrp, struct smb_filename **smb_fname_out, uint32_t ucf_flags) { @@ -988,7 +1014,7 @@ NTSTATUS unix_convert(TALLOC_CTX *mem_ctx, /* Canonicalize any @GMT- paths. */ if (state->snapshot_path) { - status = canonicalize_snapshot_path(state->smb_fname); + status = canonicalize_snapshot_path(state->smb_fname, twrp); if (!NT_STATUS_IS_OK(status)) { goto err; } @@ -1782,7 +1808,7 @@ char *get_original_lcomp(TALLOC_CTX *ctx, TALLOC_FREE(fname); return NULL; } - status = canonicalize_snapshot_path(smb_fname); + status = canonicalize_snapshot_path(smb_fname, NULL); if (!NT_STATUS_IS_OK(status)) { TALLOC_FREE(fname); TALLOC_FREE(smb_fname); @@ -1840,7 +1866,6 @@ static NTSTATUS filename_convert_internal(TALLOC_CTX *ctx, struct smb_filename **_smb_fname) { struct smb_filename *smb_fname = NULL; - const char *name = NULL; char *twrp_name = NULL; NTSTATUS status; @@ -1890,28 +1915,7 @@ static NTSTATUS filename_convert_internal(TALLOC_CTX *ctx, ucf_flags |= UCF_ALWAYS_ALLOW_WCARD_LCOMP; } - name = name_in; - if (twrp != NULL) { - struct tm *tm = NULL; - - tm = gmtime(twrp); - twrp_name = talloc_asprintf( - ctx, - "@GMT-%04u.%02u.%02u-%02u.%02u.%02u/%s", - tm->tm_year + 1900, - tm->tm_mon + 1, - tm->tm_mday, - tm->tm_hour, - tm->tm_min, - tm->tm_sec, - name); - if (twrp_name == NULL) { - return NT_STATUS_NO_MEMORY; - } - name = twrp_name; - } - - status = unix_convert(ctx, conn, name, &smb_fname, ucf_flags); + status = unix_convert(ctx, conn, name_in, twrp, &smb_fname, ucf_flags); if (!NT_STATUS_IS_OK(status)) { DEBUG(10,("filename_convert_internal: unix_convert failed " "for name %s with %s\n", diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index 81e5c6b4908..7eb838cef5f 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -686,7 +686,7 @@ static NTSTATUS dfs_path_lookup(TALLOC_CTX *ctx, * unix_convert later in the codepath. */ - status = unix_convert(ctx, conn, pdp->reqpath, &smb_fname, + status = unix_convert(ctx, conn, pdp->reqpath, NULL, &smb_fname, ucf_flags); if (!NT_STATUS_IS_OK(status)) { diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index e66b759d576..ab2cd3539b3 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -362,6 +362,7 @@ uint32_t filename_create_ucf_flags(struct smb_request *req, uint32_t create_disp NTSTATUS unix_convert(TALLOC_CTX *ctx, connection_struct *conn, const char *orig_path, + time_t *twrp, struct smb_filename **smb_fname, uint32_t ucf_flags); NTSTATUS check_name(connection_struct *conn, -- 2.47.3