]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: move time_t twrp to @GMT string token conversion to canonicalize_snapshot_path()
authorRalph Boehme <slow@samba.org>
Thu, 30 Apr 2020 13:14:36 +0000 (15:14 +0200)
committerJeremy Allison <jra@samba.org>
Tue, 5 May 2020 19:18:40 +0000 (19:18 +0000)
Prepares for canonicalize_snapshot_path() being the one-stop shop for
previous-versions related stuff in subsequent commits.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/printing/nt_printing.c
source3/smbd/filename.c
source3/smbd/msdfs.c
source3/smbd/proto.h

index 50982e7e1aa8ebc1953e88dcddbc212bf7429de1..02d6a915755fbe5f5997cccbb167f2a296bdbc1a 100644 (file)
@@ -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;
        }
index 6cfc18559931529c61f6dba68f841b1de818ab54..c80b0fde797f51900624e036fbbd33e2e950ef18 100644 (file)
@@ -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",
index 81e5c6b4908bb8fb6e1009956863dbb1bfbcbc1d..7eb838cef5f2f6a2263dbc9e4be47c57d42f9ab8 100644 (file)
@@ -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)) {
index e66b759d5765832e4ceffeb59129d3851e127d01..ab2cd3539b3d2b9a3600a08462bcf1dcc6463b1a 100644 (file)
@@ -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,