Menu

[r6995]: / trunk / patches / ports-samba35.patch  Maximize  Restore  History

Download this file

316 lines (315 with data), 10.0 kB

  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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
Index: net/samba35/files/patch-source3__modules__vfs_shadow_copy2.c
===================================================================
RCS file: net/samba35/files/patch-source3__modules__vfs_shadow_copy2.c
diff -N net/samba35/files/patch-source3__modules__vfs_shadow_copy2.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ files/patch-source3__modules__vfs_shadow_copy2.c 02 Jul 2011 10:45:22 -0000
@@ -0,0 +1,308 @@
+--- ./source3/modules/vfs_shadow_copy2.c.orig 2011-06-14 04:17:28.000000000 -0700
++++ ./source3/modules/vfs_shadow_copy2.c 2011-07-01 21:44:13.133596276 -0700
+@@ -2,6 +2,7 @@
+ * implementation of an Shadow Copy module - version 2
+ *
+ * Copyright (C) Andrew Tridgell 2007
++ * Copyright (C) Ed Plese 2009
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+@@ -34,6 +35,16 @@
+ from the original. This allows the 'restore' button to work
+ without a sharing violation
+
++ 3) vanity naming for snapshots. Snapshots can be named in any
++ format compatible with str[fp]time conversions.
++
++ 4) time stamps in snapshot names can be represented in localtime
++ rather than UTC.
++
++ 5) shadow copy results can be sorted before being sent to the
++ client. This is beneficial for filesystems that don't read
++ directories alphabetically (e.g. ZFS).
++
+ Module options:
+
+ shadow:snapdir = <directory where snapshots are kept>
+@@ -58,10 +69,29 @@
+ don't set this option then the 'restore' button in the shadow
+ copy UI will fail with a sharing violation.
+
+- Note that the directory names in the snapshot directory must take the form
+- @GMT-YYYY.MM.DD-HH.MM.SS
+-
+- The following command would generate a correctly formatted directory name:
++ shadow:sort = asc/desc, or blank for unsorted (default)
++
++ This is an optional parameter that specifies that the shadow
++ copy directories should be sorted before sending them to the
++ client. This is beneficial for filesystems that don't read
++ directories alphabetically (e.g. ZFS). If enabled, you typically
++ want to specify descending order.
++
++ shadow:format = <format specification for snapshot names>
++
++ This is an optional parameter that specifies the format
++ specification for the naming of snapshots. The format must
++ be compatible with the conversion specifications recognized
++ by str[fp]time. The default value is "@GMT-%Y.%m.%d-%H.%M.%S".
++
++ shadow:localtime = yes/no (default is no)
++
++ This is an optional parameter that indicates whether the
++ snapshot names are in UTC/GMT or the local time.
++
++
++ The following command would generate a correctly formatted directory name
++ for use with the default parameters:
+ date -u +@GMT-%Y.%m.%d-%H.%M.%S
+
+ */
+@@ -72,6 +102,11 @@
+ #define DBGC_CLASS vfs_shadow_copy2_debug_level
+
+ #define GMT_NAME_LEN 24 /* length of a @GMT- name */
++#define SHADOW_COPY2_GMT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
++
++#define SHADOW_COPY2_DEFAULT_SORT ""
++#define SHADOW_COPY2_DEFAULT_LOCALTIME (False)
++#define SHADOW_COPY2_DEFAULT_FORMAT "@GMT-%Y.%m.%d-%H.%M.%S"
+
+ /*
+ make very sure it is one of our special names
+@@ -158,6 +193,40 @@
+ return pcopy;
+ }
+
++static char *shadow_copy2_snapshot_to_gmt(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle, const char *name)
++{
++ struct tm timestamp;
++ time_t timestamp_t;
++ char gmt[GMT_NAME_LEN + 1];
++
++ char *fmt = talloc_strdup(mem_ctx,
++ lp_parm_const_string(SNUM(handle->conn),
++ "shadow", "format", SHADOW_COPY2_DEFAULT_FORMAT));
++
++ if (fmt == NULL) {
++ DEBUG(0, ("shadow_copy2_snapshot_to_gmt: talloc_strdup failed for format\n"));
++ return NULL;
++ }
++
++ memset(&timestamp, 0, sizeof(timestamp));
++ if (strptime(name, fmt, &timestamp) == NULL) {
++ DEBUG(10, ("shadow_copy2_snapshot_to_gmt: no match %s: %s\n", fmt, name));
++ talloc_free(fmt);
++ return NULL;
++ }
++
++ DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n", fmt, name));
++ if (lp_parm_bool(SNUM(handle->conn), "shadow", "localtime", SHADOW_COPY2_DEFAULT_LOCALTIME)) {
++ timestamp.tm_isdst = -1;
++ timestamp_t = mktime(&timestamp);
++ gmtime_r(&timestamp_t, &timestamp);
++ }
++ strftime(gmt, sizeof(gmt), SHADOW_COPY2_GMT_FORMAT, &timestamp);
++ talloc_free(fmt);
++
++ return talloc_strdup(mem_ctx, gmt);
++}
++
+ /*
+ convert a name to the shadow directory
+ */
+@@ -347,6 +416,19 @@
+ size_t baselen;
+ char *ret;
+
++ struct tm timestamp;
++ time_t timestamp_t;
++ char snapshot[MAXPATHLEN];
++ char *fmt = talloc_strdup(tmp_ctx,
++ lp_parm_const_string(SNUM(handle->conn),
++ "shadow", "format", SHADOW_COPY2_DEFAULT_FORMAT));
++
++ if (fmt == NULL) {
++ DEBUG(0, ("shadow_copy2_convert: talloc_strdup failed for format\n"));
++ 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));
+@@ -369,7 +451,22 @@
+ }
+ }
+
+- relpath = fname + GMT_NAME_LEN;
++ memset(&timestamp, 0, sizeof(timestamp));
++ relpath = strptime(fname, SHADOW_COPY2_GMT_FORMAT, &timestamp);
++ if (relpath == NULL) {
++ talloc_free(tmp_ctx);
++ return NULL;
++ }
++
++ /* relpath is the remaining portion of the path after the @GMT-xxx */
++
++ if (lp_parm_bool(SNUM(handle->conn), "shadow", "localtime", SHADOW_COPY2_DEFAULT_LOCALTIME)) {
++ timestamp_t = timegm(&timestamp);
++ localtime_r(&timestamp_t, &timestamp);
++ }
++
++ strftime(snapshot, MAXPATHLEN, fmt, &timestamp);
++
+ baselen = strlen(basedir);
+ baseoffset = handle->conn->connectpath + baselen;
+
+@@ -385,11 +482,15 @@
+ 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",
+ snapdir,
+- GMT_NAME_LEN, fname,
++ snapshot,
++ *baseoffset ? "/" : "",
+ baseoffset,
+ relpath);
++ /* XXX */
++ if (ret != NULL && strlen(ret) > 1 && ret[strlen(ret) - 1] == '/')
++ ret[strlen(ret) - 1] = '\0';
+ DEBUG(6,("convert_shadow2_name: '%s' -> '%s'\n", fname, ret));
+ talloc_free(tmp_ctx);
+ return ret;
+@@ -557,6 +658,7 @@
+ static char *shadow_copy2_realpath(vfs_handle_struct *handle,
+ const char *fname, char *resolved_path)
+ {
++#if 0
+ const char *gmt;
+
+ if (shadow_copy2_match_name(fname, &gmt)
+@@ -576,6 +678,7 @@
+ TALLOC_FREE(copy);
+ return result;
+ }
++#endif
+ SHADOW2_NEXT(REALPATH, (handle, name, resolved_path), char *, NULL);
+ }
+
+@@ -606,6 +709,7 @@
+ return NULL;
+ }
+
++#if 0
+ snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
+ if (snapdir == NULL) {
+ DEBUG(2,("no snapdir found for share at %s\n",
+@@ -642,6 +746,9 @@
+ snapdir,
+ GMT_NAME_LEN, fname,
+ baseoffset);
++#else
++ ret = convert_shadow2_name(handle, fname, gmt_start);
++#endif
+ DEBUG(6,("shadow_copy2_connectpath: '%s' -> '%s'\n", fname, ret));
+ TALLOC_FREE(tmp_ctx);
+ return ret;
+@@ -718,6 +825,45 @@
+ SHADOW2_NEXT(CHMOD_ACL, (handle, name, mode), int, -1);
+ }
+
++static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
++{
++ return strncmp((char *)x, (char *)y, sizeof(SHADOW_COPY_LABEL));
++}
++
++static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
++{
++ return -strncmp((char *)x, (char *)y, sizeof(SHADOW_COPY_LABEL));
++}
++
++/*
++ sort the shadow copy data in ascending or descending order
++ */
++static void shadow_copy2_sort_data(vfs_handle_struct *handle,
++ SHADOW_COPY_DATA *shadow_copy2_data)
++{
++ const char *tmp_str = lp_parm_const_string(SNUM(handle->conn),
++ "shadow", "sort", SHADOW_COPY2_DEFAULT_SORT);
++
++ if (tmp_str && shadow_copy2_data &&
++ shadow_copy2_data->num_volumes > 0 &&
++ shadow_copy2_data->labels) {
++
++ if (strcmp(tmp_str, "asc") == 0) {
++ qsort(shadow_copy2_data->labels,
++ shadow_copy2_data->num_volumes,
++ sizeof(SHADOW_COPY_LABEL),
++ shadow_copy2_label_cmp_asc);
++ } else if (strcmp(tmp_str, "desc") == 0) {
++ qsort(shadow_copy2_data->labels,
++ shadow_copy2_data->num_volumes,
++ sizeof(SHADOW_COPY_LABEL),
++ shadow_copy2_label_cmp_desc);
++ }
++ }
++
++ return;
++}
++
+ static int shadow_copy2_get_shadow_copy2_data(vfs_handle_struct *handle,
+ files_struct *fsp,
+ SHADOW_COPY_DATA *shadow_copy2_data,
+@@ -727,6 +873,7 @@
+ const char *snapdir;
+ SMB_STRUCT_DIRENT *d;
+ TALLOC_CTX *tmp_ctx = talloc_new(handle->data);
++ char *snapshot;
+
+ snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
+ if (snapdir == NULL) {
+@@ -747,8 +894,6 @@
+ return -1;
+ }
+
+- talloc_free(tmp_ctx);
+-
+ shadow_copy2_data->num_volumes = 0;
+ shadow_copy2_data->labels = NULL;
+
+@@ -756,7 +901,9 @@
+ SHADOW_COPY_LABEL *tlabels;
+
+ /* ignore names not of the right form in the snapshot directory */
+- if (!shadow_copy2_match_name(d->d_name, NULL)) {
++ snapshot = shadow_copy2_snapshot_to_gmt(tmp_ctx, handle, d->d_name);
++ DEBUG(6,("shadow_copy2_get_shadow_copy2_data: %s -> %s\n", d->d_name, snapshot));
++ if (!snapshot) {
+ continue;
+ }
+
+@@ -772,15 +919,22 @@
+ if (tlabels == NULL) {
+ DEBUG(0,("shadow_copy2: out of memory\n"));
+ SMB_VFS_NEXT_CLOSEDIR(handle, p);
++ talloc_free(tmp_ctx);
+ return -1;
+ }
+
+- strlcpy(tlabels[shadow_copy2_data->num_volumes], d->d_name, sizeof(*tlabels));
++ strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot, sizeof(*tlabels));
++ talloc_free(snapshot);
++
+ shadow_copy2_data->num_volumes++;
+ shadow_copy2_data->labels = tlabels;
+ }
+
+ SMB_VFS_NEXT_CLOSEDIR(handle,p);
++
++ shadow_copy2_sort_data(handle, shadow_copy2_data);
++
++ talloc_free(tmp_ctx);
+ return 0;
+ }
+
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.