s3-shadow-copy2: Protect against already converted names
authorVolker Lendecke <vl@samba.org>
Thu, 18 Oct 2012 13:24:39 +0000 (15:24 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 27 Jun 2014 07:03:53 +0000 (09:03 +0200)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Fri Jun 27 09:03:53 CEST 2014 on sn-devel-104

source3/modules/vfs_shadow_copy2.c

index 30f67e27823db71847d7cfbe782d383442369f19..439df5ddf4d68bd000be701b9012ae01ba8f45a7 100644 (file)
@@ -235,6 +235,9 @@ static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
        char *stripped;
        size_t rest_len, dst_len;
        struct shadow_copy2_config *config;
+       const char *snapdir;
+       ssize_t snapdirlen;
+       ptrdiff_t len_before_gmt;
 
        SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
                                return false);
@@ -252,6 +255,31 @@ static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
                           p, name, (int)p[-1]));
                goto no_snapshot;
        }
+
+       /*
+        * Figure out whether we got an already converted string. One
+        * case where this happens is in a smb2 create call with the
+        * mxac create blob set. We do the get_acl call on
+        * fsp->fsp_name, which is already converted. We are converted
+        * if we got a file name of the form ".snapshots/@GMT-",
+        * i.e. ".snapshots/" precedes "p".
+        */
+
+       snapdir = lp_parm_const_string(SNUM(handle->conn), "shadow", "snapdir",
+                                      ".snapshots");
+       snapdirlen = strlen(snapdir);
+       len_before_gmt = p - name;
+
+       if ((len_before_gmt >= (snapdirlen + 1)) && (p[-1] == '/')) {
+               const char *parent_snapdir = p - (snapdirlen+1);
+
+               DEBUG(10, ("parent_snapdir = %s\n", parent_snapdir));
+
+               if (strncmp(parent_snapdir, snapdir, snapdirlen) == 0) {
+                       DEBUG(10, ("name=%s is already converted\n", name));
+                       goto no_snapshot;
+               }
+       }
        q = strptime(p, GMT_FORMAT, &tm);
        if (q == NULL) {
                DEBUG(10, ("strptime failed\n"));