From ed751b9ee49d8e4a319759640321e8b49be4f154 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Thu, 30 May 2013 17:26:44 +0200 Subject: [PATCH] shadow_copy2: re-add the basedir option. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Disable basedir if it is not an absolute path or if snapdirseverywhere or crossmountpoints is enabled. Pair-Programmed-With: Björn Baumbach Signed-off-by: Michael Adam Signed-off-by: Björn Baumbach Reviewed-by: Andrew Bartlett --- source3/modules/vfs_shadow_copy2.c | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c index adcc855320..d584fa92af 100644 --- a/source3/modules/vfs_shadow_copy2.c +++ b/source3/modules/vfs_shadow_copy2.c @@ -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) { -- 2.34.1