shadow_copy2: re-add the basedir option.
authorMichael Adam <obnox@samba.org>
Thu, 30 May 2013 15:26:44 +0000 (17:26 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 4 Oct 2013 20:21:09 +0000 (09:21 +1300)
Disable basedir if it is not an absolute path or if
snapdirseverywhere or crossmountpoints is enabled.

Pair-Programmed-With: Björn Baumbach <bb@sernet.de>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Björn Baumbach <bb@sernet.de>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/modules/vfs_shadow_copy2.c

index adcc855320d95fe8f569484335de8fe7e41cd79a..d584fa92af1ce9ab5f7a856279c4ef8e67a52749 100644 (file)
@@ -117,6 +117,8 @@ struct shadow_copy2_config {
        bool fixinodes;
        char *sort_order;
        bool snapdir_absolute;
+       char *basedir;
+       char *mount_point;
 };
 
 static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
@@ -1580,6 +1582,7 @@ static int shadow_copy2_connect(struct vfs_handle_struct *handle,
        const char *snapdir;
        const char *gmt_format;
        const char *sort_order;
+       const char *basedir;
 
        DEBUG(10, (__location__ ": cnum[%u], connectpath[%s]\n",
                   (unsigned)handle->conn->cnum,
@@ -1646,6 +1649,59 @@ static int shadow_copy2_connect(struct vfs_handle_struct *handle,
                return -1;
        }
 
+       config->mount_point = shadow_copy2_find_mount_point(config, handle);
+       if (config->mount_point == NULL) {
+               DEBUG(0, (__location__ ": shadow_copy2_find_mount_point "
+                         "failed: %s\n", strerror(errno)));
+               return -1;
+       }
+
+       basedir = lp_parm_const_string(SNUM(handle->conn),
+                                      "shadow", "basedir", NULL);
+
+       if (basedir != NULL) {
+               if (basedir[0] != '/') {
+                       DEBUG(1, (__location__ " Warning: 'basedir' is "
+                                 "relative ('%s'), but it has to be an "
+                                 "absolute path. Disabling basedir.\n",
+                                 basedir));
+               } else {
+                       char *p;
+                       p = strstr(basedir, config->mount_point);
+                       if (p != basedir) {
+                               DEBUG(1, ("Warning: basedir (%s) is not a "
+                                         "subdirectory of the share root's "
+                                         "mount point (%s). "
+                                         "Disabling basedir\n",
+                                         basedir, config->mount_point));
+                       } else {
+                               config->basedir = talloc_strdup(config,
+                                                               basedir);
+                               if (config->basedir == NULL) {
+                                       DEBUG(0, ("talloc_strdup() failed\n"));
+                                       errno = ENOMEM;
+                                       return -1;
+                               }
+                       }
+               }
+       }
+
+       if (config->snapdirseverywhere && config->basedir != NULL) {
+               DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
+                         "with 'snapdirseverywhere'. Disabling basedir.\n"));
+               TALLOC_FREE(config->basedir);
+       }
+
+       if (config->crossmountpoints && config->basedir != NULL) {
+               DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
+                         "with 'crossmountpoints'. Disabling basedir.\n"));
+               TALLOC_FREE(config->basedir);
+       }
+
+       if (config->basedir == NULL) {
+               config->basedir = config->mount_point;
+       }
+
        if (config->snapdir[0] == '/') {
                config->snapdir_absolute = true;
                if (config->snapdirseverywhere == true) {