lib: Move extract_snapshot_token() to util_path.c
authorVolker Lendecke <vl@samba.org>
Sat, 17 Sep 2022 17:13:27 +0000 (10:13 -0700)
committerJeremy Allison <jra@samba.org>
Mon, 19 Sep 2022 17:23:31 +0000 (17:23 +0000)
Make it available to replace clistr_is_previous_version_path() in
libsmb/

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/include/smb.h
source3/lib/util_path.c
source3/lib/util_path.h
source3/smbd/filename.c
source3/smbd/proto.h

index 6363bdc0c938f188fd6451d79459d13cba748bed..cfaf922b461257bd202b45f0ad00344c541ab584 100644 (file)
@@ -454,18 +454,6 @@ Offset  Data                       length.
 #define NOTIFY_ACTION_REMOVED_STREAM 7
 #define NOTIFY_ACTION_MODIFIED_STREAM 8
 
-/*
- * Timestamp format used in "previous versions":
- * This is the windows-level format of the @GMT- token.
- * It is a fixed format not to be confused with the
- * format for the POSIX-Level token of the shadow_copy2
- * VFS module that can be configured via the "shadow:format"
- * configuration option but defaults to the same format.
- * See the shadow_copy2 module.
- */
-#define GMT_NAME_LEN 24 /* length of a @GMT- name */
-#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
-
 /* where to find the base of the SMB packet proper */
 #define smb_base(buf) (((const char *)(buf))+4)
 
index 3591589cb8e15f8da0d65b095a8ae0a5f2f3faa1..6d2161caf84ca1f87d4ad4021d3a40d18cc0da96 100644 (file)
@@ -24,6 +24,7 @@
 #include "replace.h"
 #include <talloc.h>
 #include "lib/util/samba_util.h"
+#include "lib/util/debug.h"
 #include "lib/util_path.h"
 
 struct loadparm_substitution;
@@ -204,3 +205,74 @@ char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *pathname_in)
        *p++ = '\0';
        return pathname;
 }
+
+static bool find_snapshot_token(
+       const char *filename,
+       const char **_start,
+       const char **_next_component,
+       NTTIME *twrp)
+{
+       const char *start = NULL;
+       const char *end = NULL;
+       struct tm tm;
+       time_t t;
+
+       start = strstr_m(filename, "@GMT-");
+
+       if (start == NULL) {
+               return false;
+       }
+
+       if ((start > filename) && (start[-1] != '/')) {
+               /* the GMT-token does not start a path-component */
+               return false;
+       }
+
+       end = strptime(start, GMT_FORMAT, &tm);
+       if (end == NULL) {
+               /* Not a valid timestring. */
+               return false;
+       }
+
+       if ((end[0] != '\0') && (end[0] != '/')) {
+               /*
+                * It is not a complete path component, i.e. the path
+                * component continues after the gmt-token.
+                */
+               return false;
+       }
+
+       tm.tm_isdst = -1;
+       t = timegm(&tm);
+       unix_to_nt_time(twrp, t);
+
+       DBG_DEBUG("Extracted @GMT-Timestamp %s\n",
+                 nt_time_string(talloc_tos(), *twrp));
+
+       *_start = start;
+
+       if (end[0] == '/') {
+               end += 1;
+       }
+       *_next_component = end;
+
+       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;
+}
index 3e7d04de5507d7324e94985f1630e6d02a50d500..3251eb1e43af1f1b5344d553acf373fecbf075ee 100644 (file)
 
 #include "replace.h"
 #include <talloc.h>
+#include "lib/util/time.h"
+
+/*
+ * Timestamp format used in "previous versions":
+ * This is the windows-level format of the @GMT- token.
+ * It is a fixed format not to be confused with the
+ * format for the POSIX-Level token of the shadow_copy2
+ * VFS module that can be configured via the "shadow:format"
+ * configuration option but defaults to the same format.
+ * See the shadow_copy2 module.
+ */
+#define GMT_NAME_LEN 24 /* length of a @GMT- name */
+#define GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
 
 char *lock_path(TALLOC_CTX *mem_ctx, const char *name);
 char *state_path(TALLOC_CTX *mem_ctx, const char *name);
 char *cache_path(TALLOC_CTX *mem_ctx, const char *name);
 char *canonicalize_absolute_path(TALLOC_CTX *ctx, const char *abs_path);
+bool extract_snapshot_token(char *fname, NTTIME *twrp);
 
 #endif
index 0be8e320ffa02d765a1c8f47e3aa7135039cedc5..79bb7dffe996be2e5e302fae0d7612f1cae6238c 100644 (file)
@@ -87,77 +87,6 @@ static bool mangled_equal(const char *name1,
        return strequal(name1, mname);
 }
 
-static bool find_snapshot_token(
-       const char *filename,
-       const char **_start,
-       const char **_next_component,
-       NTTIME *twrp)
-{
-       const char *start = NULL;
-       const char *end = NULL;
-       struct tm tm;
-       time_t t;
-
-       start = strstr_m(filename, "@GMT-");
-
-       if (start == NULL) {
-               return false;
-       }
-
-       if ((start > filename) && (start[-1] != '/')) {
-               /* the GMT-token does not start a path-component */
-               return false;
-       }
-
-       end = strptime(start, GMT_FORMAT, &tm);
-       if (end == NULL) {
-               /* Not a valid timestring. */
-               return false;
-       }
-
-       if ((end[0] != '\0') && (end[0] != '/')) {
-               /*
-                * It is not a complete path component, i.e. the path
-                * component continues after the gmt-token.
-                */
-               return false;
-       }
-
-       tm.tm_isdst = -1;
-       t = timegm(&tm);
-       unix_to_nt_time(twrp, t);
-
-       DBG_DEBUG("Extracted @GMT-Timestamp %s\n",
-                 nt_time_string(talloc_tos(), *twrp));
-
-       *_start = start;
-
-       if (end[0] == '/') {
-               end += 1;
-       }
-       *_next_component = end;
-
-       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
index 89b3d224a8baa81c1c9fd33122d1f1956939dc3d..743375a7d907f3ee5403d22441ed6c1c1fd1918c 100644 (file)
@@ -350,7 +350,6 @@ NTSTATUS sync_file(connection_struct *conn, files_struct *fsp, bool write_throug
 
 uint32_t ucf_flags_from_smb_request(struct smb_request *req);
 uint32_t filename_create_ucf_flags(struct smb_request *req, uint32_t create_disposition);
-bool extract_snapshot_token(char *fname, NTTIME *twrp);
 NTSTATUS canonicalize_snapshot_path(struct smb_filename *smb_fname,
                                    uint32_t ucf_flags,
                                    NTTIME twrp);