s3: libsmb: Add clistr_is_previous_version_path()
authorJeremy Allison <jra@samba.org>
Thu, 18 Aug 2016 20:06:54 +0000 (13:06 -0700)
committerUri Simchoni <uri@samba.org>
Fri, 19 Aug 2016 18:03:12 +0000 (20:03 +0200)
Looks for @GMT- token in pathname.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12165

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Uri Simchoni <uri@samba.org>
source3/libsmb/clistr.c
source3/libsmb/proto.h

index f1264f65ce521fa2275ca4c3dbac9ad6688dbc83..c3611be72ccffc0981e48b13d5628142bfe81c49 100644 (file)
@@ -37,3 +37,31 @@ size_t clistr_pull_talloc(TALLOC_CTX *ctx,
                                  src_len,
                                  flags);
 }
+
+bool clistr_is_previous_version_path(const char *path)
+{
+       char *q;
+       time_t timestamp;
+       struct tm tm;
+       const char *p = strstr_m(path, "@GMT-");
+
+       if (p == NULL) {
+               return false;
+       }
+       if (p > path && (p[-1] != '\\')) {
+               return false;
+       }
+       q = strptime(p, GMT_FORMAT, &tm);
+       if (q == NULL) {
+               return false;
+       }
+       tm.tm_isdst = -1;
+       timestamp = timegm(&tm);
+       if (timestamp == (time_t)-1) {
+               return false;
+       }
+       if (q[0] != '\0' && q[0] != '\\') {
+               return false;
+       }
+       return true;
+}
index 31d9a1183b55bb8c4b19631f159f2b5d5fa4121c..f9bb9856874a8065bfad91163fb09eb983c46ca6 100644 (file)
@@ -868,6 +868,7 @@ size_t clistr_pull_talloc(TALLOC_CTX *ctx,
                          const void *src,
                          int src_len,
                          int flags);
+bool clistr_is_previous_version_path(const char *path);
 
 /* The following definitions come from libsmb/clitrans.c  */