summaryrefslogtreecommitdiff
path: root/net/samba36/files/patch-source3__modules__vfs_shadow_copy2.c
blob: d4eeedb6345e50fe6fc081ea0cfef25aa98e55f5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
--- ./source3/modules/vfs_shadow_copy2.c.orig	2012-10-19 03:37:47.475803452 +0000
+++ ./source3/modules/vfs_shadow_copy2.c	2012-10-19 03:39:42.665808023 +0000
@@ -237,7 +237,7 @@
 	if (shadow_copy2_match_name(fname, &gmt_start)) {	\
 		char *name2; \
 		rtype ret; \
-		name2 = convert_shadow2_name(handle, fname, gmt_start);	\
+		name2 = convert_shadow2_name(handle, fname, gmt_start, True);	\
 		if (name2 == NULL) { \
 			errno = EINVAL; \
 			return eret; \
@@ -258,7 +258,7 @@
 		char *name2; \
 		char *smb_base_name_tmp = NULL; \
 		rtype ret; \
-		name2 = convert_shadow2_name(handle, smb_fname->base_name, gmt_start); \
+		name2 = convert_shadow2_name(handle, smb_fname->base_name, gmt_start, True); \
 		if (name2 == NULL) { \
 			errno = EINVAL; \
 			return eret; \
@@ -285,7 +285,7 @@
         if (shadow_copy2_match_name(fname, &gmt_start)) {	\
                 char *name2; \
                 NTSTATUS ret; \
-                name2 = convert_shadow2_name(handle, fname, gmt_start);	\
+                name2 = convert_shadow2_name(handle, fname, gmt_start, True);	\
                 if (name2 == NULL) { \
                         errno = EINVAL; \
                         return eret; \
@@ -409,7 +409,8 @@
   convert a filename from a share relative path, to a path in the
   snapshot directory
  */
-static char *convert_shadow2_name(vfs_handle_struct *handle, const char *fname, const char *gmt_path)
+static char *convert_shadow2_name(vfs_handle_struct *handle, const char *fname,
+				  const char *gmt_path, const bool incl_rel)
 {
 	TALLOC_CTX *tmp_ctx = talloc_new(handle->data);
 	const char *snapdir, *relpath, *baseoffset, *basedir;
@@ -486,11 +487,13 @@
 	if (*relpath == '/') relpath++;
 	if (*baseoffset == '/') baseoffset++;
 
-	ret = talloc_asprintf(handle->data, "%s/%s/%s/%s",
+	ret = talloc_asprintf(handle->data, "%s/%s%s%s%s%s",
 			      snapdir, 
 			      snapshot,
+			      *baseoffset ? "/" : "",
 			      baseoffset, 
-			      relpath);
+			      *relpath ? "/" : "",
+			      incl_rel ? relpath : "");
 	DEBUG(6,("convert_shadow2_name: '%s' -> '%s'\n", fname, ret));
 	talloc_free(tmp_ctx);
 	return ret;
@@ -687,68 +690,17 @@
 static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
 					    const char *fname)
 {
-	TALLOC_CTX *tmp_ctx;
-	const char *snapdir, *baseoffset, *basedir, *gmt_start;
-	size_t baselen;
+	const char *gmt_start;
 	char *ret;
 
 	DEBUG(10, ("shadow_copy2_connectpath called with %s\n", fname));
 
 	if (!shadow_copy2_match_name(fname, &gmt_start)) {
-		return handle->conn->connectpath;
-	}
-
-        /*
-         * We have to create a real temporary context because we have
-         * to put our result on talloc_tos(). Thus we can't use a
-         * talloc_stackframe() here.
-         */
-	tmp_ctx = talloc_new(talloc_tos());
-
-	fname = shadow_copy2_normalise_path(tmp_ctx, fname, gmt_start);
-	if (fname == NULL) {
-		TALLOC_FREE(tmp_ctx);
-		return NULL;
-	}
-
-	snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
-	if (snapdir == NULL) {
-		DEBUG(2,("no snapdir found for share at %s\n",
-			 handle->conn->connectpath));
-		TALLOC_FREE(tmp_ctx);
-		return NULL;
+		return SMB_VFS_NEXT_CONNECTPATH(handle, fname);
 	}
 
-	basedir = shadow_copy2_find_basedir(tmp_ctx, handle);
-	if (basedir == NULL) {
-		DEBUG(2,("no basedir found for share at %s\n",
-			 handle->conn->connectpath));
-		TALLOC_FREE(tmp_ctx);
-		return NULL;
-	}
-
-	baselen = strlen(basedir);
-	baseoffset = handle->conn->connectpath + baselen;
-
-	/* some sanity checks */
-	if (strncmp(basedir, handle->conn->connectpath, baselen) != 0 ||
-	    (handle->conn->connectpath[baselen] != 0
-	     && handle->conn->connectpath[baselen] != '/')) {
-		DEBUG(0,("shadow_copy2_connectpath: basedir %s is not a "
-			 "parent of %s\n", basedir,
-			 handle->conn->connectpath));
-		TALLOC_FREE(tmp_ctx);
-		return NULL;
-	}
-
-	if (*baseoffset == '/') baseoffset++;
-
-	ret = talloc_asprintf(talloc_tos(), "%s/%.*s/%s",
-			      snapdir,
-			      GMT_NAME_LEN, fname,
-			      baseoffset);
+	ret = convert_shadow2_name(handle, fname, gmt_start, False);
 	DEBUG(6,("shadow_copy2_connectpath: '%s' -> '%s'\n", fname, ret));
-	TALLOC_FREE(tmp_ctx);
 	return ret;
 }