shadow_copy2: re-add the basedir option.
authorMichael Adam <obnox@samba.org>
Thu, 30 May 2013 15:26:44 +0000 (17:26 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 13 Jan 2014 09:17:21 +0000 (10:17 +0100)
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>
(cherry picked from commit ed751b9ee49d8e4a319759640321e8b49be4f154)

source3/modules/vfs_shadow_copy2.c

index e8608857f9e36a990d53cb63e8ac4141df82e0ef..5280867e4ee4a7a459bca75178c4f494bbfcf15e 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,
@@ -1582,6 +1584,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,
@@ -1648,6 +1651,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) {