1 | /*
|
---|
2 | * implementation of an Shadow Copy module - version 2
|
---|
3 | *
|
---|
4 | * Copyright (C) Andrew Tridgell 2007
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | */
|
---|
20 |
|
---|
21 | #include "includes.h"
|
---|
22 |
|
---|
23 | /*
|
---|
24 |
|
---|
25 | This is a 2nd implemetation of a shadow copy module for exposing
|
---|
26 | snapshots to windows clients as shadow copies. This version has the
|
---|
27 | following features:
|
---|
28 |
|
---|
29 | 1) you don't need to populate your shares with symlinks to the
|
---|
30 | snapshots. This can be very important when you have thousands of
|
---|
31 | shares, or use [homes]
|
---|
32 |
|
---|
33 | 2) the inode number of the files is altered so it is different
|
---|
34 | from the original. This allows the 'restore' button to work
|
---|
35 | without a sharing violation
|
---|
36 |
|
---|
37 | Module options:
|
---|
38 |
|
---|
39 | shadow:snapdir = <directory where snapshots are kept>
|
---|
40 |
|
---|
41 | This is the directory containing the @GMT-* snapshot directories. If it is an absolute
|
---|
42 | path it is used as-is. If it is a relative path, then it is taken relative to the mount
|
---|
43 | point of the filesystem that the root of this share is on
|
---|
44 |
|
---|
45 | shadow:basedir = <base directory that snapshots are from>
|
---|
46 |
|
---|
47 | This is an optional parameter that specifies the directory that
|
---|
48 | the snapshots are relative to. It defaults to the filesystem
|
---|
49 | mount point
|
---|
50 |
|
---|
51 | shadow:fixinodes = yes/no
|
---|
52 |
|
---|
53 | If you enable shadow:fixinodes then this module will modify the
|
---|
54 | apparent inode number of files in the snapshot directories using
|
---|
55 | a hash of the files path. This is needed for snapshot systems
|
---|
56 | where the snapshots have the same device:inode number as the
|
---|
57 | original files (such as happens with GPFS snapshots). If you
|
---|
58 | don't set this option then the 'restore' button in the shadow
|
---|
59 | copy UI will fail with a sharing violation.
|
---|
60 |
|
---|
61 | Note that the directory names in the snapshot directory must take the form
|
---|
62 | @GMT-YYYY.MM.DD-HH.MM.SS
|
---|
63 |
|
---|
64 | The following command would generate a correctly formatted directory name:
|
---|
65 | date -u +@GMT-%Y.%m.%d-%H.%M.%S
|
---|
66 |
|
---|
67 | */
|
---|
68 |
|
---|
69 | static int vfs_shadow_copy2_debug_level = DBGC_VFS;
|
---|
70 |
|
---|
71 | #undef DBGC_CLASS
|
---|
72 | #define DBGC_CLASS vfs_shadow_copy2_debug_level
|
---|
73 |
|
---|
74 | #define GMT_NAME_LEN 24 /* length of a @GMT- name */
|
---|
75 |
|
---|
76 | /*
|
---|
77 | make very sure it is one of our special names
|
---|
78 | */
|
---|
79 | static inline bool shadow_copy2_match_name(const char *name)
|
---|
80 | {
|
---|
81 | unsigned year, month, day, hr, min, sec;
|
---|
82 | if (name[0] != '@') return False;
|
---|
83 | if (strncmp(name, "@GMT-", 5) != 0) return False;
|
---|
84 | if (sscanf(name, "@GMT-%04u.%02u.%02u-%02u.%02u.%02u", &year, &month,
|
---|
85 | &day, &hr, &min, &sec) != 6) {
|
---|
86 | return False;
|
---|
87 | }
|
---|
88 | if (name[24] != 0 && name[24] != '/') {
|
---|
89 | return False;
|
---|
90 | }
|
---|
91 | return True;
|
---|
92 | }
|
---|
93 |
|
---|
94 | /*
|
---|
95 | convert a name to the shadow directory
|
---|
96 | */
|
---|
97 |
|
---|
98 | #define _SHADOW2_NEXT(op, args, rtype, eret, extra) do { \
|
---|
99 | const char *name = fname; \
|
---|
100 | if (shadow_copy2_match_name(fname)) { \
|
---|
101 | char *name2; \
|
---|
102 | rtype ret; \
|
---|
103 | name2 = convert_shadow2_name(handle, fname); \
|
---|
104 | if (name2 == NULL) { \
|
---|
105 | errno = EINVAL; \
|
---|
106 | return eret; \
|
---|
107 | } \
|
---|
108 | name = name2; \
|
---|
109 | ret = SMB_VFS_NEXT_ ## op args; \
|
---|
110 | talloc_free(name2); \
|
---|
111 | if (ret != eret) extra; \
|
---|
112 | return ret; \
|
---|
113 | } else { \
|
---|
114 | return SMB_VFS_NEXT_ ## op args; \
|
---|
115 | } \
|
---|
116 | } while (0)
|
---|
117 |
|
---|
118 | /*
|
---|
119 | convert a name to the shadow directory: NTSTATUS-specific handling
|
---|
120 | */
|
---|
121 |
|
---|
122 | #define _SHADOW2_NTSTATUS_NEXT(op, args, eret, extra) do { \
|
---|
123 | const char *name = fname; \
|
---|
124 | if (shadow_copy2_match_name(fname)) { \
|
---|
125 | char *name2; \
|
---|
126 | NTSTATUS ret; \
|
---|
127 | name2 = convert_shadow2_name(handle, fname); \
|
---|
128 | if (name2 == NULL) { \
|
---|
129 | errno = EINVAL; \
|
---|
130 | return eret; \
|
---|
131 | } \
|
---|
132 | name = name2; \
|
---|
133 | ret = SMB_VFS_NEXT_ ## op args; \
|
---|
134 | talloc_free(name2); \
|
---|
135 | if (!NT_STATUS_EQUAL(ret, eret)) extra; \
|
---|
136 | return ret; \
|
---|
137 | } else { \
|
---|
138 | return SMB_VFS_NEXT_ ## op args; \
|
---|
139 | } \
|
---|
140 | } while (0)
|
---|
141 |
|
---|
142 | #define SHADOW2_NTSTATUS_NEXT(op, args, eret) _SHADOW2_NTSTATUS_NEXT(op, args, eret, )
|
---|
143 |
|
---|
144 | #define SHADOW2_NEXT(op, args, rtype, eret) _SHADOW2_NEXT(op, args, rtype, eret, )
|
---|
145 |
|
---|
146 | #define SHADOW2_NEXT2(op, args) do { \
|
---|
147 | if (shadow_copy2_match_name(oldname) || shadow_copy2_match_name(newname)) { \
|
---|
148 | errno = EROFS; \
|
---|
149 | return -1; \
|
---|
150 | } else { \
|
---|
151 | return SMB_VFS_NEXT_ ## op args; \
|
---|
152 | } \
|
---|
153 | } while (0)
|
---|
154 |
|
---|
155 |
|
---|
156 | /*
|
---|
157 | find the mount point of a filesystem
|
---|
158 | */
|
---|
159 | static char *find_mount_point(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle)
|
---|
160 | {
|
---|
161 | char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
|
---|
162 | dev_t dev;
|
---|
163 | struct stat st;
|
---|
164 | char *p;
|
---|
165 |
|
---|
166 | if (stat(path, &st) != 0) {
|
---|
167 | talloc_free(path);
|
---|
168 | return NULL;
|
---|
169 | }
|
---|
170 |
|
---|
171 | dev = st.st_dev;
|
---|
172 |
|
---|
173 | while ((p = strrchr(path, '/')) && p > path) {
|
---|
174 | *p = 0;
|
---|
175 | if (stat(path, &st) != 0) {
|
---|
176 | talloc_free(path);
|
---|
177 | return NULL;
|
---|
178 | }
|
---|
179 | if (st.st_dev != dev) {
|
---|
180 | *p = '/';
|
---|
181 | break;
|
---|
182 | }
|
---|
183 | }
|
---|
184 |
|
---|
185 | return path;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /*
|
---|
189 | work out the location of the snapshot for this share
|
---|
190 | */
|
---|
191 | static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle)
|
---|
192 | {
|
---|
193 | const char *snapdir;
|
---|
194 | char *mount_point;
|
---|
195 | const char *ret;
|
---|
196 |
|
---|
197 | snapdir = lp_parm_const_string(SNUM(handle->conn), "shadow", "snapdir", NULL);
|
---|
198 | if (snapdir == NULL) {
|
---|
199 | return NULL;
|
---|
200 | }
|
---|
201 | /* if its an absolute path, we're done */
|
---|
202 | if (*snapdir == '/') {
|
---|
203 | return snapdir;
|
---|
204 | }
|
---|
205 |
|
---|
206 | /* other its relative to the filesystem mount point */
|
---|
207 | mount_point = find_mount_point(mem_ctx, handle);
|
---|
208 | if (mount_point == NULL) {
|
---|
209 | return NULL;
|
---|
210 | }
|
---|
211 |
|
---|
212 | ret = talloc_asprintf(mem_ctx, "%s/%s", mount_point, snapdir);
|
---|
213 | talloc_free(mount_point);
|
---|
214 | return ret;
|
---|
215 | }
|
---|
216 |
|
---|
217 | /*
|
---|
218 | work out the location of the base directory for snapshots of this share
|
---|
219 | */
|
---|
220 | static const char *shadow_copy2_find_basedir(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle)
|
---|
221 | {
|
---|
222 | const char *basedir = lp_parm_const_string(SNUM(handle->conn), "shadow", "basedir", NULL);
|
---|
223 |
|
---|
224 | /* other its the filesystem mount point */
|
---|
225 | if (basedir == NULL) {
|
---|
226 | basedir = find_mount_point(mem_ctx, handle);
|
---|
227 | }
|
---|
228 |
|
---|
229 | return basedir;
|
---|
230 | }
|
---|
231 |
|
---|
232 | /*
|
---|
233 | convert a filename from a share relative path, to a path in the
|
---|
234 | snapshot directory
|
---|
235 | */
|
---|
236 | static char *convert_shadow2_name(vfs_handle_struct *handle, const char *fname)
|
---|
237 | {
|
---|
238 | TALLOC_CTX *tmp_ctx = talloc_new(handle->data);
|
---|
239 | const char *snapdir, *relpath, *baseoffset, *basedir;
|
---|
240 | size_t baselen;
|
---|
241 | char *ret;
|
---|
242 |
|
---|
243 | snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
|
---|
244 | if (snapdir == NULL) {
|
---|
245 | DEBUG(2,("no snapdir found for share at %s\n", handle->conn->connectpath));
|
---|
246 | talloc_free(tmp_ctx);
|
---|
247 | return NULL;
|
---|
248 | }
|
---|
249 |
|
---|
250 | basedir = shadow_copy2_find_basedir(tmp_ctx, handle);
|
---|
251 | if (basedir == NULL) {
|
---|
252 | DEBUG(2,("no basedir found for share at %s\n", handle->conn->connectpath));
|
---|
253 | talloc_free(tmp_ctx);
|
---|
254 | return NULL;
|
---|
255 | }
|
---|
256 |
|
---|
257 | relpath = fname + GMT_NAME_LEN;
|
---|
258 | baselen = strlen(basedir);
|
---|
259 | baseoffset = handle->conn->connectpath + baselen;
|
---|
260 |
|
---|
261 | /* some sanity checks */
|
---|
262 | if (strncmp(basedir, handle->conn->connectpath, baselen) != 0 ||
|
---|
263 | (handle->conn->connectpath[baselen] != 0 && handle->conn->connectpath[baselen] != '/')) {
|
---|
264 | DEBUG(0,("convert_shadow2_name: basedir %s is not a parent of %s\n",
|
---|
265 | basedir, handle->conn->connectpath));
|
---|
266 | talloc_free(tmp_ctx);
|
---|
267 | return NULL;
|
---|
268 | }
|
---|
269 |
|
---|
270 | if (*relpath == '/') relpath++;
|
---|
271 | if (*baseoffset == '/') baseoffset++;
|
---|
272 |
|
---|
273 | ret = talloc_asprintf(handle->data, "%s/%.*s/%s/%s",
|
---|
274 | snapdir,
|
---|
275 | GMT_NAME_LEN, fname,
|
---|
276 | baseoffset,
|
---|
277 | relpath);
|
---|
278 | DEBUG(6,("convert_shadow2_name: '%s' -> '%s'\n", fname, ret));
|
---|
279 | talloc_free(tmp_ctx);
|
---|
280 | return ret;
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | /*
|
---|
285 | simple string hash
|
---|
286 | */
|
---|
287 | static uint32 string_hash(const char *s)
|
---|
288 | {
|
---|
289 | uint32 n = 0;
|
---|
290 | while (*s) {
|
---|
291 | n = ((n << 5) + n) ^ (uint32)(*s++);
|
---|
292 | }
|
---|
293 | return n;
|
---|
294 | }
|
---|
295 |
|
---|
296 | /*
|
---|
297 | modify a sbuf return to ensure that inodes in the shadow directory
|
---|
298 | are different from those in the main directory
|
---|
299 | */
|
---|
300 | static void convert_sbuf(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf)
|
---|
301 | {
|
---|
302 | if (lp_parm_bool(SNUM(handle->conn), "shadow", "fixinodes", False)) {
|
---|
303 | /* some snapshot systems, like GPFS, return the name
|
---|
304 | device:inode for the snapshot files as the current
|
---|
305 | files. That breaks the 'restore' button in the shadow copy
|
---|
306 | GUI, as the client gets a sharing violation.
|
---|
307 |
|
---|
308 | This is a crude way of allowing both files to be
|
---|
309 | open at once. It has a slight chance of inode
|
---|
310 | number collision, but I can't see a better approach
|
---|
311 | without significant VFS changes
|
---|
312 | */
|
---|
313 | uint32_t shash = string_hash(fname) & 0xFF000000;
|
---|
314 | if (shash == 0) {
|
---|
315 | shash = 1;
|
---|
316 | }
|
---|
317 | sbuf->st_ino ^= shash;
|
---|
318 | }
|
---|
319 | }
|
---|
320 |
|
---|
321 | static int shadow_copy2_rename(vfs_handle_struct *handle,
|
---|
322 | const char *oldname, const char *newname)
|
---|
323 | {
|
---|
324 | SHADOW2_NEXT2(RENAME, (handle, oldname, newname));
|
---|
325 | }
|
---|
326 |
|
---|
327 | static int shadow_copy2_symlink(vfs_handle_struct *handle,
|
---|
328 | const char *oldname, const char *newname)
|
---|
329 | {
|
---|
330 | SHADOW2_NEXT2(SYMLINK, (handle, oldname, newname));
|
---|
331 | }
|
---|
332 |
|
---|
333 | static int shadow_copy2_link(vfs_handle_struct *handle,
|
---|
334 | const char *oldname, const char *newname)
|
---|
335 | {
|
---|
336 | SHADOW2_NEXT2(LINK, (handle, oldname, newname));
|
---|
337 | }
|
---|
338 |
|
---|
339 | static int shadow_copy2_open(vfs_handle_struct *handle,
|
---|
340 | const char *fname, files_struct *fsp, int flags, mode_t mode)
|
---|
341 | {
|
---|
342 | SHADOW2_NEXT(OPEN, (handle, name, fsp, flags, mode), int, -1);
|
---|
343 | }
|
---|
344 |
|
---|
345 | static SMB_STRUCT_DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
|
---|
346 | const char *fname, const char *mask, uint32 attr)
|
---|
347 | {
|
---|
348 | SHADOW2_NEXT(OPENDIR, (handle, name, mask, attr), SMB_STRUCT_DIR *, NULL);
|
---|
349 | }
|
---|
350 |
|
---|
351 | static int shadow_copy2_stat(vfs_handle_struct *handle,
|
---|
352 | const char *fname, SMB_STRUCT_STAT *sbuf)
|
---|
353 | {
|
---|
354 | _SHADOW2_NEXT(STAT, (handle, name, sbuf), int, -1, convert_sbuf(handle, fname, sbuf));
|
---|
355 | }
|
---|
356 |
|
---|
357 | static int shadow_copy2_lstat(vfs_handle_struct *handle,
|
---|
358 | const char *fname, SMB_STRUCT_STAT *sbuf)
|
---|
359 | {
|
---|
360 | _SHADOW2_NEXT(LSTAT, (handle, name, sbuf), int, -1, convert_sbuf(handle, fname, sbuf));
|
---|
361 | }
|
---|
362 |
|
---|
363 | static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
|
---|
364 | {
|
---|
365 | int ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
|
---|
366 | if (ret == 0 && shadow_copy2_match_name(fsp->fsp_name)) {
|
---|
367 | convert_sbuf(handle, fsp->fsp_name, sbuf);
|
---|
368 | }
|
---|
369 | return ret;
|
---|
370 | }
|
---|
371 |
|
---|
372 | static int shadow_copy2_unlink(vfs_handle_struct *handle, const char *fname)
|
---|
373 | {
|
---|
374 | SHADOW2_NEXT(UNLINK, (handle, name), int, -1);
|
---|
375 | }
|
---|
376 |
|
---|
377 | static int shadow_copy2_chmod(vfs_handle_struct *handle,
|
---|
378 | const char *fname, mode_t mode)
|
---|
379 | {
|
---|
380 | SHADOW2_NEXT(CHMOD, (handle, name, mode), int, -1);
|
---|
381 | }
|
---|
382 |
|
---|
383 | static int shadow_copy2_chown(vfs_handle_struct *handle,
|
---|
384 | const char *fname, uid_t uid, gid_t gid)
|
---|
385 | {
|
---|
386 | SHADOW2_NEXT(CHOWN, (handle, name, uid, gid), int, -1);
|
---|
387 | }
|
---|
388 |
|
---|
389 | static int shadow_copy2_chdir(vfs_handle_struct *handle,
|
---|
390 | const char *fname)
|
---|
391 | {
|
---|
392 | SHADOW2_NEXT(CHDIR, (handle, name), int, -1);
|
---|
393 | }
|
---|
394 |
|
---|
395 | static int shadow_copy2_ntimes(vfs_handle_struct *handle,
|
---|
396 | const char *fname, const struct timespec ts[2])
|
---|
397 | {
|
---|
398 | SHADOW2_NEXT(NTIMES, (handle, name, ts), int, -1);
|
---|
399 | }
|
---|
400 |
|
---|
401 | static int shadow_copy2_readlink(vfs_handle_struct *handle,
|
---|
402 | const char *fname, char *buf, size_t bufsiz)
|
---|
403 | {
|
---|
404 | SHADOW2_NEXT(READLINK, (handle, name, buf, bufsiz), int, -1);
|
---|
405 | }
|
---|
406 |
|
---|
407 | static int shadow_copy2_mknod(vfs_handle_struct *handle,
|
---|
408 | const char *fname, mode_t mode, SMB_DEV_T dev)
|
---|
409 | {
|
---|
410 | SHADOW2_NEXT(MKNOD, (handle, name, mode, dev), int, -1);
|
---|
411 | }
|
---|
412 |
|
---|
413 | static char *shadow_copy2_realpath(vfs_handle_struct *handle,
|
---|
414 | const char *fname, char *resolved_path)
|
---|
415 | {
|
---|
416 | SHADOW2_NEXT(REALPATH, (handle, name, resolved_path), char *, NULL);
|
---|
417 | }
|
---|
418 |
|
---|
419 | static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
|
---|
420 | const char *fname, uint32 security_info,
|
---|
421 | struct security_descriptor **ppdesc)
|
---|
422 | {
|
---|
423 | SHADOW2_NTSTATUS_NEXT(GET_NT_ACL, (handle, name, security_info, ppdesc), NT_STATUS_ACCESS_DENIED);
|
---|
424 | }
|
---|
425 |
|
---|
426 | static NTSTATUS shadow_copy2_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
|
---|
427 | const char *fname, uint32 security_info_sent,
|
---|
428 | struct security_descriptor *psd)
|
---|
429 | {
|
---|
430 | SHADOW2_NTSTATUS_NEXT(SET_NT_ACL, (handle, fsp, name, security_info_sent, psd), NT_STATUS_ACCESS_DENIED);
|
---|
431 | }
|
---|
432 |
|
---|
433 | static int shadow_copy2_mkdir(vfs_handle_struct *handle, const char *fname, mode_t mode)
|
---|
434 | {
|
---|
435 | SHADOW2_NEXT(MKDIR, (handle, name, mode), int, -1);
|
---|
436 | }
|
---|
437 |
|
---|
438 | static int shadow_copy2_rmdir(vfs_handle_struct *handle, const char *fname)
|
---|
439 | {
|
---|
440 | SHADOW2_NEXT(RMDIR, (handle, name), int, -1);
|
---|
441 | }
|
---|
442 |
|
---|
443 | static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname, int flags)
|
---|
444 | {
|
---|
445 | SHADOW2_NEXT(CHFLAGS, (handle, name, flags), int, -1);
|
---|
446 | }
|
---|
447 |
|
---|
448 | static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
|
---|
449 | const char *fname, const char *aname, void *value, size_t size)
|
---|
450 | {
|
---|
451 | SHADOW2_NEXT(GETXATTR, (handle, name, aname, value, size), ssize_t, -1);
|
---|
452 | }
|
---|
453 |
|
---|
454 | static ssize_t shadow_copy2_lgetxattr(vfs_handle_struct *handle,
|
---|
455 | const char *fname, const char *aname, void *value, size_t size)
|
---|
456 | {
|
---|
457 | SHADOW2_NEXT(LGETXATTR, (handle, name, aname, value, size), ssize_t, -1);
|
---|
458 | }
|
---|
459 |
|
---|
460 | static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle, const char *fname,
|
---|
461 | char *list, size_t size)
|
---|
462 | {
|
---|
463 | SHADOW2_NEXT(LISTXATTR, (handle, name, list, size), ssize_t, -1);
|
---|
464 | }
|
---|
465 |
|
---|
466 | static int shadow_copy2_removexattr(struct vfs_handle_struct *handle, const char *fname,
|
---|
467 | const char *aname)
|
---|
468 | {
|
---|
469 | SHADOW2_NEXT(REMOVEXATTR, (handle, name, aname), int, -1);
|
---|
470 | }
|
---|
471 |
|
---|
472 | static int shadow_copy2_lremovexattr(struct vfs_handle_struct *handle, const char *fname,
|
---|
473 | const char *aname)
|
---|
474 | {
|
---|
475 | SHADOW2_NEXT(LREMOVEXATTR, (handle, name, aname), int, -1);
|
---|
476 | }
|
---|
477 |
|
---|
478 | static int shadow_copy2_setxattr(struct vfs_handle_struct *handle, const char *fname,
|
---|
479 | const char *aname, const void *value, size_t size, int flags)
|
---|
480 | {
|
---|
481 | SHADOW2_NEXT(SETXATTR, (handle, name, aname, value, size, flags), int, -1);
|
---|
482 | }
|
---|
483 |
|
---|
484 | static int shadow_copy2_lsetxattr(struct vfs_handle_struct *handle, const char *fname,
|
---|
485 | const char *aname, const void *value, size_t size, int flags)
|
---|
486 | {
|
---|
487 | SHADOW2_NEXT(LSETXATTR, (handle, name, aname, value, size, flags), int, -1);
|
---|
488 | }
|
---|
489 |
|
---|
490 | static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
|
---|
491 | const char *fname, mode_t mode)
|
---|
492 | {
|
---|
493 | /* If the underlying VFS doesn't have ACL support... */
|
---|
494 | if (!handle->vfs_next.ops.chmod_acl) {
|
---|
495 | errno = ENOSYS;
|
---|
496 | return -1;
|
---|
497 | }
|
---|
498 | SHADOW2_NEXT(CHMOD_ACL, (handle, name, mode), int, -1);
|
---|
499 | }
|
---|
500 |
|
---|
501 | static int shadow_copy2_get_shadow_copy2_data(vfs_handle_struct *handle,
|
---|
502 | files_struct *fsp,
|
---|
503 | SHADOW_COPY_DATA *shadow_copy2_data,
|
---|
504 | bool labels)
|
---|
505 | {
|
---|
506 | SMB_STRUCT_DIR *p;
|
---|
507 | const char *snapdir;
|
---|
508 | SMB_STRUCT_DIRENT *d;
|
---|
509 | TALLOC_CTX *tmp_ctx = talloc_new(handle->data);
|
---|
510 |
|
---|
511 | snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
|
---|
512 | if (snapdir == NULL) {
|
---|
513 | DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
|
---|
514 | handle->conn->connectpath));
|
---|
515 | errno = EINVAL;
|
---|
516 | talloc_free(tmp_ctx);
|
---|
517 | return -1;
|
---|
518 | }
|
---|
519 |
|
---|
520 | p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
|
---|
521 |
|
---|
522 | if (!p) {
|
---|
523 | DEBUG(0,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s' - %s\n",
|
---|
524 | snapdir, strerror(errno)));
|
---|
525 | talloc_free(tmp_ctx);
|
---|
526 | return -1;
|
---|
527 | }
|
---|
528 |
|
---|
529 | talloc_free(tmp_ctx);
|
---|
530 |
|
---|
531 | shadow_copy2_data->num_volumes = 0;
|
---|
532 | shadow_copy2_data->labels = NULL;
|
---|
533 |
|
---|
534 | while ((d = SMB_VFS_NEXT_READDIR(handle, p))) {
|
---|
535 | SHADOW_COPY_LABEL *tlabels;
|
---|
536 |
|
---|
537 | /* ignore names not of the right form in the snapshot directory */
|
---|
538 | if (!shadow_copy2_match_name(d->d_name)) {
|
---|
539 | continue;
|
---|
540 | }
|
---|
541 |
|
---|
542 | if (!labels) {
|
---|
543 | /* the caller doesn't want the labels */
|
---|
544 | shadow_copy2_data->num_volumes++;
|
---|
545 | continue;
|
---|
546 | }
|
---|
547 |
|
---|
548 | tlabels = talloc_realloc(shadow_copy2_data->mem_ctx,
|
---|
549 | shadow_copy2_data->labels,
|
---|
550 | SHADOW_COPY_LABEL, shadow_copy2_data->num_volumes+1);
|
---|
551 | if (tlabels == NULL) {
|
---|
552 | DEBUG(0,("shadow_copy2: out of memory\n"));
|
---|
553 | SMB_VFS_NEXT_CLOSEDIR(handle, p);
|
---|
554 | return -1;
|
---|
555 | }
|
---|
556 |
|
---|
557 | strlcpy(tlabels[shadow_copy2_data->num_volumes], d->d_name, sizeof(*tlabels));
|
---|
558 | shadow_copy2_data->num_volumes++;
|
---|
559 | shadow_copy2_data->labels = tlabels;
|
---|
560 | }
|
---|
561 |
|
---|
562 | SMB_VFS_NEXT_CLOSEDIR(handle,p);
|
---|
563 | return 0;
|
---|
564 | }
|
---|
565 |
|
---|
566 | /* VFS operations structure */
|
---|
567 |
|
---|
568 | static vfs_op_tuple shadow_copy2_ops[] = {
|
---|
569 | {SMB_VFS_OP(shadow_copy2_opendir), SMB_VFS_OP_OPENDIR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
570 |
|
---|
571 | /* directory operations */
|
---|
572 | {SMB_VFS_OP(shadow_copy2_mkdir), SMB_VFS_OP_MKDIR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
573 | {SMB_VFS_OP(shadow_copy2_rmdir), SMB_VFS_OP_RMDIR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
574 |
|
---|
575 | /* xattr and flags operations */
|
---|
576 | {SMB_VFS_OP(shadow_copy2_chflags), SMB_VFS_OP_CHFLAGS, SMB_VFS_LAYER_TRANSPARENT},
|
---|
577 | {SMB_VFS_OP(shadow_copy2_getxattr), SMB_VFS_OP_GETXATTR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
578 | {SMB_VFS_OP(shadow_copy2_lgetxattr), SMB_VFS_OP_LGETXATTR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
579 | {SMB_VFS_OP(shadow_copy2_listxattr), SMB_VFS_OP_LISTXATTR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
580 | {SMB_VFS_OP(shadow_copy2_removexattr), SMB_VFS_OP_REMOVEXATTR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
581 | {SMB_VFS_OP(shadow_copy2_lremovexattr),SMB_VFS_OP_LREMOVEXATTR,SMB_VFS_LAYER_TRANSPARENT},
|
---|
582 | {SMB_VFS_OP(shadow_copy2_setxattr), SMB_VFS_OP_SETXATTR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
583 | {SMB_VFS_OP(shadow_copy2_lsetxattr), SMB_VFS_OP_LSETXATTR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
584 |
|
---|
585 | /* File operations */
|
---|
586 | {SMB_VFS_OP(shadow_copy2_open), SMB_VFS_OP_OPEN, SMB_VFS_LAYER_TRANSPARENT},
|
---|
587 | {SMB_VFS_OP(shadow_copy2_rename), SMB_VFS_OP_RENAME, SMB_VFS_LAYER_TRANSPARENT},
|
---|
588 | {SMB_VFS_OP(shadow_copy2_stat), SMB_VFS_OP_STAT, SMB_VFS_LAYER_TRANSPARENT},
|
---|
589 | {SMB_VFS_OP(shadow_copy2_lstat), SMB_VFS_OP_LSTAT, SMB_VFS_LAYER_TRANSPARENT},
|
---|
590 | {SMB_VFS_OP(shadow_copy2_fstat), SMB_VFS_OP_FSTAT, SMB_VFS_LAYER_TRANSPARENT},
|
---|
591 | {SMB_VFS_OP(shadow_copy2_unlink), SMB_VFS_OP_UNLINK, SMB_VFS_LAYER_TRANSPARENT},
|
---|
592 | {SMB_VFS_OP(shadow_copy2_chmod), SMB_VFS_OP_CHMOD, SMB_VFS_LAYER_TRANSPARENT},
|
---|
593 | {SMB_VFS_OP(shadow_copy2_chown), SMB_VFS_OP_CHOWN, SMB_VFS_LAYER_TRANSPARENT},
|
---|
594 | {SMB_VFS_OP(shadow_copy2_chdir), SMB_VFS_OP_CHDIR, SMB_VFS_LAYER_TRANSPARENT},
|
---|
595 | {SMB_VFS_OP(shadow_copy2_ntimes), SMB_VFS_OP_NTIMES, SMB_VFS_LAYER_TRANSPARENT},
|
---|
596 | {SMB_VFS_OP(shadow_copy2_symlink), SMB_VFS_OP_SYMLINK, SMB_VFS_LAYER_TRANSPARENT},
|
---|
597 | {SMB_VFS_OP(shadow_copy2_readlink), SMB_VFS_OP_READLINK, SMB_VFS_LAYER_TRANSPARENT},
|
---|
598 | {SMB_VFS_OP(shadow_copy2_link), SMB_VFS_OP_LINK, SMB_VFS_LAYER_TRANSPARENT},
|
---|
599 | {SMB_VFS_OP(shadow_copy2_mknod), SMB_VFS_OP_MKNOD, SMB_VFS_LAYER_TRANSPARENT},
|
---|
600 | {SMB_VFS_OP(shadow_copy2_realpath), SMB_VFS_OP_REALPATH, SMB_VFS_LAYER_TRANSPARENT},
|
---|
601 |
|
---|
602 | /* NT File ACL operations */
|
---|
603 | {SMB_VFS_OP(shadow_copy2_get_nt_acl), SMB_VFS_OP_GET_NT_ACL, SMB_VFS_LAYER_TRANSPARENT},
|
---|
604 | {SMB_VFS_OP(shadow_copy2_set_nt_acl), SMB_VFS_OP_SET_NT_ACL, SMB_VFS_LAYER_TRANSPARENT},
|
---|
605 |
|
---|
606 | /* POSIX ACL operations */
|
---|
607 | {SMB_VFS_OP(shadow_copy2_chmod_acl), SMB_VFS_OP_CHMOD_ACL, SMB_VFS_LAYER_TRANSPARENT},
|
---|
608 |
|
---|
609 | /* special shadown copy op */
|
---|
610 | {SMB_VFS_OP(shadow_copy2_get_shadow_copy2_data),
|
---|
611 | SMB_VFS_OP_GET_SHADOW_COPY_DATA,SMB_VFS_LAYER_OPAQUE},
|
---|
612 |
|
---|
613 | {SMB_VFS_OP(NULL), SMB_VFS_OP_NOOP, SMB_VFS_LAYER_NOOP}
|
---|
614 | };
|
---|
615 |
|
---|
616 | NTSTATUS vfs_shadow_copy2_init(void);
|
---|
617 | NTSTATUS vfs_shadow_copy2_init(void)
|
---|
618 | {
|
---|
619 | NTSTATUS ret;
|
---|
620 |
|
---|
621 | ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "shadow_copy2", shadow_copy2_ops);
|
---|
622 |
|
---|
623 | if (!NT_STATUS_IS_OK(ret))
|
---|
624 | return ret;
|
---|
625 |
|
---|
626 | vfs_shadow_copy2_debug_level = debug_add_class("shadow_copy2");
|
---|
627 | if (vfs_shadow_copy2_debug_level == -1) {
|
---|
628 | vfs_shadow_copy2_debug_level = DBGC_VFS;
|
---|
629 | DEBUG(0, ("%s: Couldn't register custom debugging class!\n",
|
---|
630 | "vfs_shadow_copy2_init"));
|
---|
631 | } else {
|
---|
632 | DEBUG(10, ("%s: Debug class number of '%s': %d\n",
|
---|
633 | "vfs_shadow_copy2_init","shadow_copy2",vfs_shadow_copy2_debug_level));
|
---|
634 | }
|
---|
635 |
|
---|
636 | return ret;
|
---|
637 | }
|
---|