source: vendor/current/source3/modules/vfs_shadow_copy2.c@ 590

Last change on this file since 590 was 414, checked in by Herwig Bauernfeind, 16 years ago

Samba 3.5.0: Initial import

File size: 23.3 KB
Line 
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
69static 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 */
79static inline bool shadow_copy2_match_name(const char *name, const char **gmt_start)
80{
81 unsigned year, month, day, hr, min, sec;
82 const char *p;
83 if (gmt_start) {
84 (*gmt_start) = NULL;
85 }
86 p = strstr_m(name, "@GMT-");
87 if (p == NULL) return false;
88 if (p > name && p[-1] != '/') return False;
89 if (sscanf(p, "@GMT-%04u.%02u.%02u-%02u.%02u.%02u", &year, &month,
90 &day, &hr, &min, &sec) != 6) {
91 return False;
92 }
93 if (p[24] != 0 && p[24] != '/') {
94 return False;
95 }
96 if (gmt_start) {
97 (*gmt_start) = p;
98 }
99 return True;
100}
101
102/*
103 shadow copy paths can also come into the server in this form:
104
105 /foo/bar/@GMT-XXXXX/some/file
106
107 This function normalises the filename to be of the form:
108
109 @GMT-XXXX/foo/bar/some/file
110 */
111static const char *shadow_copy2_normalise_path(TALLOC_CTX *mem_ctx, const char *path, const char *gmt_start)
112{
113 char *pcopy;
114 char buf[GMT_NAME_LEN];
115 size_t prefix_len;
116
117 if (path == gmt_start) {
118 return path;
119 }
120
121 prefix_len = gmt_start - path - 1;
122
123 DEBUG(10, ("path=%s, gmt_start=%s, prefix_len=%d\n", path, gmt_start,
124 (int)prefix_len));
125
126 /*
127 * We've got a/b/c/@GMT-YYYY.MM.DD-HH.MM.SS/d/e. convert to
128 * @GMT-YYYY.MM.DD-HH.MM.SS/a/b/c/d/e before further
129 * processing. As many VFS calls provide a const char *,
130 * unfortunately we have to make a copy.
131 */
132
133 pcopy = talloc_strdup(talloc_tos(), path);
134 if (pcopy == NULL) {
135 return NULL;
136 }
137
138 gmt_start = pcopy + prefix_len;
139
140 /*
141 * Copy away "@GMT-YYYY.MM.DD-HH.MM.SS"
142 */
143 memcpy(buf, gmt_start+1, GMT_NAME_LEN);
144
145 /*
146 * Make space for it including a trailing /
147 */
148 memmove(pcopy + GMT_NAME_LEN + 1, pcopy, prefix_len);
149
150 /*
151 * Move in "@GMT-YYYY.MM.DD-HH.MM.SS/" at the beginning again
152 */
153 memcpy(pcopy, buf, GMT_NAME_LEN);
154 pcopy[GMT_NAME_LEN] = '/';
155
156 DEBUG(10, ("shadow_copy2_normalise_path: %s -> %s\n", path, pcopy));
157
158 return pcopy;
159}
160
161/*
162 convert a name to the shadow directory
163 */
164
165#define _SHADOW2_NEXT(op, args, rtype, eret, extra) do { \
166 const char *name = fname; \
167 const char *gmt_start; \
168 if (shadow_copy2_match_name(fname, &gmt_start)) { \
169 char *name2; \
170 rtype ret; \
171 name2 = convert_shadow2_name(handle, fname, gmt_start); \
172 if (name2 == NULL) { \
173 errno = EINVAL; \
174 return eret; \
175 } \
176 name = name2; \
177 ret = SMB_VFS_NEXT_ ## op args; \
178 talloc_free(name2); \
179 if (ret != eret) extra; \
180 return ret; \
181 } else { \
182 return SMB_VFS_NEXT_ ## op args; \
183 } \
184} while (0)
185
186#define _SHADOW2_NEXT_SMB_FNAME(op, args, rtype, eret, extra) do { \
187 const char *gmt_start; \
188 if (shadow_copy2_match_name(smb_fname->base_name, &gmt_start)) { \
189 char *name2; \
190 char *smb_base_name_tmp = NULL; \
191 rtype ret; \
192 name2 = convert_shadow2_name(handle, smb_fname->base_name, gmt_start); \
193 if (name2 == NULL) { \
194 errno = EINVAL; \
195 return eret; \
196 } \
197 smb_base_name_tmp = smb_fname->base_name; \
198 smb_fname->base_name = name2; \
199 ret = SMB_VFS_NEXT_ ## op args; \
200 smb_fname->base_name = smb_base_name_tmp; \
201 talloc_free(name2); \
202 if (ret != eret) extra; \
203 return ret; \
204 } else { \
205 return SMB_VFS_NEXT_ ## op args; \
206 } \
207} while (0)
208
209/*
210 convert a name to the shadow directory: NTSTATUS-specific handling
211 */
212
213#define _SHADOW2_NTSTATUS_NEXT(op, args, eret, extra) do { \
214 const char *name = fname; \
215 const char *gmt_start; \
216 if (shadow_copy2_match_name(fname, &gmt_start)) { \
217 char *name2; \
218 NTSTATUS ret; \
219 name2 = convert_shadow2_name(handle, fname, gmt_start); \
220 if (name2 == NULL) { \
221 errno = EINVAL; \
222 return eret; \
223 } \
224 name = name2; \
225 ret = SMB_VFS_NEXT_ ## op args; \
226 talloc_free(name2); \
227 if (!NT_STATUS_EQUAL(ret, eret)) extra; \
228 return ret; \
229 } else { \
230 return SMB_VFS_NEXT_ ## op args; \
231 } \
232} while (0)
233
234#define SHADOW2_NTSTATUS_NEXT(op, args, eret) _SHADOW2_NTSTATUS_NEXT(op, args, eret, )
235
236#define SHADOW2_NEXT(op, args, rtype, eret) _SHADOW2_NEXT(op, args, rtype, eret, )
237
238#define SHADOW2_NEXT_SMB_FNAME(op, args, rtype, eret) _SHADOW2_NEXT_SMB_FNAME(op, args, rtype, eret, )
239
240#define SHADOW2_NEXT2(op, args) do { \
241 const char *gmt_start1, *gmt_start2; \
242 if (shadow_copy2_match_name(oldname, &gmt_start1) || \
243 shadow_copy2_match_name(newname, &gmt_start2)) { \
244 errno = EROFS; \
245 return -1; \
246 } else { \
247 return SMB_VFS_NEXT_ ## op args; \
248 } \
249} while (0)
250
251#define SHADOW2_NEXT2_SMB_FNAME(op, args) do { \
252 const char *gmt_start1, *gmt_start2; \
253 if (shadow_copy2_match_name(smb_fname_src->base_name, &gmt_start1) || \
254 shadow_copy2_match_name(smb_fname_dst->base_name, &gmt_start2)) { \
255 errno = EROFS; \
256 return -1; \
257 } else { \
258 return SMB_VFS_NEXT_ ## op args; \
259 } \
260} while (0)
261
262
263/*
264 find the mount point of a filesystem
265 */
266static char *find_mount_point(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle)
267{
268 char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
269 dev_t dev;
270 struct stat st;
271 char *p;
272
273 if (stat(path, &st) != 0) {
274 talloc_free(path);
275 return NULL;
276 }
277
278 dev = st.st_dev;
279
280 while ((p = strrchr(path, '/')) && p > path) {
281 *p = 0;
282 if (stat(path, &st) != 0) {
283 talloc_free(path);
284 return NULL;
285 }
286 if (st.st_dev != dev) {
287 *p = '/';
288 break;
289 }
290 }
291
292 return path;
293}
294
295/*
296 work out the location of the snapshot for this share
297 */
298static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle)
299{
300 const char *snapdir;
301 char *mount_point;
302 const char *ret;
303
304 snapdir = lp_parm_const_string(SNUM(handle->conn), "shadow", "snapdir", NULL);
305 if (snapdir == NULL) {
306 return NULL;
307 }
308 /* if its an absolute path, we're done */
309 if (*snapdir == '/') {
310 return snapdir;
311 }
312
313 /* other its relative to the filesystem mount point */
314 mount_point = find_mount_point(mem_ctx, handle);
315 if (mount_point == NULL) {
316 return NULL;
317 }
318
319 ret = talloc_asprintf(mem_ctx, "%s/%s", mount_point, snapdir);
320 talloc_free(mount_point);
321 return ret;
322}
323
324/*
325 work out the location of the base directory for snapshots of this share
326 */
327static const char *shadow_copy2_find_basedir(TALLOC_CTX *mem_ctx, vfs_handle_struct *handle)
328{
329 const char *basedir = lp_parm_const_string(SNUM(handle->conn), "shadow", "basedir", NULL);
330
331 /* other its the filesystem mount point */
332 if (basedir == NULL) {
333 basedir = find_mount_point(mem_ctx, handle);
334 }
335
336 return basedir;
337}
338
339/*
340 convert a filename from a share relative path, to a path in the
341 snapshot directory
342 */
343static char *convert_shadow2_name(vfs_handle_struct *handle, const char *fname, const char *gmt_path)
344{
345 TALLOC_CTX *tmp_ctx = talloc_new(handle->data);
346 const char *snapdir, *relpath, *baseoffset, *basedir;
347 size_t baselen;
348 char *ret;
349
350 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
351 if (snapdir == NULL) {
352 DEBUG(2,("no snapdir found for share at %s\n", handle->conn->connectpath));
353 talloc_free(tmp_ctx);
354 return NULL;
355 }
356
357 basedir = shadow_copy2_find_basedir(tmp_ctx, handle);
358 if (basedir == NULL) {
359 DEBUG(2,("no basedir found for share at %s\n", handle->conn->connectpath));
360 talloc_free(tmp_ctx);
361 return NULL;
362 }
363
364 if (strncmp(fname, "@GMT-", 5) != 0) {
365 fname = shadow_copy2_normalise_path(tmp_ctx, fname, gmt_path);
366 if (fname == NULL) {
367 talloc_free(tmp_ctx);
368 return NULL;
369 }
370 }
371
372 relpath = fname + GMT_NAME_LEN;
373 baselen = strlen(basedir);
374 baseoffset = handle->conn->connectpath + baselen;
375
376 /* some sanity checks */
377 if (strncmp(basedir, handle->conn->connectpath, baselen) != 0 ||
378 (handle->conn->connectpath[baselen] != 0 && handle->conn->connectpath[baselen] != '/')) {
379 DEBUG(0,("convert_shadow2_name: basedir %s is not a parent of %s\n",
380 basedir, handle->conn->connectpath));
381 talloc_free(tmp_ctx);
382 return NULL;
383 }
384
385 if (*relpath == '/') relpath++;
386 if (*baseoffset == '/') baseoffset++;
387
388 ret = talloc_asprintf(handle->data, "%s/%.*s/%s/%s",
389 snapdir,
390 GMT_NAME_LEN, fname,
391 baseoffset,
392 relpath);
393 DEBUG(6,("convert_shadow2_name: '%s' -> '%s'\n", fname, ret));
394 talloc_free(tmp_ctx);
395 return ret;
396}
397
398
399/*
400 simple string hash
401 */
402static uint32 string_hash(const char *s)
403{
404 uint32 n = 0;
405 while (*s) {
406 n = ((n << 5) + n) ^ (uint32)(*s++);
407 }
408 return n;
409}
410
411/*
412 modify a sbuf return to ensure that inodes in the shadow directory
413 are different from those in the main directory
414 */
415static void convert_sbuf(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf)
416{
417 if (lp_parm_bool(SNUM(handle->conn), "shadow", "fixinodes", False)) {
418 /* some snapshot systems, like GPFS, return the name
419 device:inode for the snapshot files as the current
420 files. That breaks the 'restore' button in the shadow copy
421 GUI, as the client gets a sharing violation.
422
423 This is a crude way of allowing both files to be
424 open at once. It has a slight chance of inode
425 number collision, but I can't see a better approach
426 without significant VFS changes
427 */
428 uint32_t shash = string_hash(fname) & 0xFF000000;
429 if (shash == 0) {
430 shash = 1;
431 }
432 sbuf->st_ex_ino ^= shash;
433 }
434}
435
436static int shadow_copy2_rename(vfs_handle_struct *handle,
437 const struct smb_filename *smb_fname_src,
438 const struct smb_filename *smb_fname_dst)
439{
440 SHADOW2_NEXT2_SMB_FNAME(RENAME,
441 (handle, smb_fname_src, smb_fname_dst));
442}
443
444static int shadow_copy2_symlink(vfs_handle_struct *handle,
445 const char *oldname, const char *newname)
446{
447 SHADOW2_NEXT2(SYMLINK, (handle, oldname, newname));
448}
449
450static int shadow_copy2_link(vfs_handle_struct *handle,
451 const char *oldname, const char *newname)
452{
453 SHADOW2_NEXT2(LINK, (handle, oldname, newname));
454}
455
456static int shadow_copy2_open(vfs_handle_struct *handle,
457 struct smb_filename *smb_fname, files_struct *fsp,
458 int flags, mode_t mode)
459{
460 SHADOW2_NEXT_SMB_FNAME(OPEN,
461 (handle, smb_fname, fsp, flags, mode),
462 int, -1);
463}
464
465static SMB_STRUCT_DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
466 const char *fname, const char *mask, uint32 attr)
467{
468 SHADOW2_NEXT(OPENDIR, (handle, name, mask, attr), SMB_STRUCT_DIR *, NULL);
469}
470
471static int shadow_copy2_stat(vfs_handle_struct *handle,
472 struct smb_filename *smb_fname)
473{
474 _SHADOW2_NEXT_SMB_FNAME(STAT, (handle, smb_fname), int, -1,
475 convert_sbuf(handle, smb_fname->base_name,
476 &smb_fname->st));
477}
478
479static int shadow_copy2_lstat(vfs_handle_struct *handle,
480 struct smb_filename *smb_fname)
481{
482 _SHADOW2_NEXT_SMB_FNAME(LSTAT, (handle, smb_fname), int, -1,
483 convert_sbuf(handle, smb_fname->base_name,
484 &smb_fname->st));
485}
486
487static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
488{
489 int ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
490 if (ret == 0 && shadow_copy2_match_name(fsp->fsp_name->base_name, NULL)) {
491 convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
492 }
493 return ret;
494}
495
496static int shadow_copy2_unlink(vfs_handle_struct *handle,
497 const struct smb_filename *smb_fname_in)
498{
499 struct smb_filename *smb_fname = NULL;
500 NTSTATUS status;
501
502 status = copy_smb_filename(talloc_tos(), smb_fname_in, &smb_fname);
503 if (!NT_STATUS_IS_OK(status)) {
504 errno = map_errno_from_nt_status(status);
505 return -1;
506 }
507
508 SHADOW2_NEXT_SMB_FNAME(UNLINK, (handle, smb_fname), int, -1);
509}
510
511static int shadow_copy2_chmod(vfs_handle_struct *handle,
512 const char *fname, mode_t mode)
513{
514 SHADOW2_NEXT(CHMOD, (handle, name, mode), int, -1);
515}
516
517static int shadow_copy2_chown(vfs_handle_struct *handle,
518 const char *fname, uid_t uid, gid_t gid)
519{
520 SHADOW2_NEXT(CHOWN, (handle, name, uid, gid), int, -1);
521}
522
523static int shadow_copy2_chdir(vfs_handle_struct *handle,
524 const char *fname)
525{
526 SHADOW2_NEXT(CHDIR, (handle, name), int, -1);
527}
528
529static int shadow_copy2_ntimes(vfs_handle_struct *handle,
530 const struct smb_filename *smb_fname_in,
531 struct smb_file_time *ft)
532{
533 struct smb_filename *smb_fname = NULL;
534 NTSTATUS status;
535
536 status = copy_smb_filename(talloc_tos(), smb_fname_in, &smb_fname);
537 if (!NT_STATUS_IS_OK(status)) {
538 errno = map_errno_from_nt_status(status);
539 return -1;
540 }
541
542 SHADOW2_NEXT_SMB_FNAME(NTIMES, (handle, smb_fname, ft), int, -1);
543}
544
545static int shadow_copy2_readlink(vfs_handle_struct *handle,
546 const char *fname, char *buf, size_t bufsiz)
547{
548 SHADOW2_NEXT(READLINK, (handle, name, buf, bufsiz), int, -1);
549}
550
551static int shadow_copy2_mknod(vfs_handle_struct *handle,
552 const char *fname, mode_t mode, SMB_DEV_T dev)
553{
554 SHADOW2_NEXT(MKNOD, (handle, name, mode, dev), int, -1);
555}
556
557static char *shadow_copy2_realpath(vfs_handle_struct *handle,
558 const char *fname, char *resolved_path)
559{
560 const char *gmt;
561
562 if (shadow_copy2_match_name(fname, &gmt)
563 && (gmt[GMT_NAME_LEN] == '\0')) {
564 char *copy, *result;
565
566 copy = talloc_strdup(talloc_tos(), fname);
567 if (copy == NULL) {
568 errno = ENOMEM;
569 return NULL;
570 }
571
572 copy[gmt - fname] = '.';
573
574 DEBUG(10, ("calling NEXT_REALPATH with %s\n", copy));
575 result = SMB_VFS_NEXT_REALPATH(handle, copy, resolved_path);
576 TALLOC_FREE(copy);
577 return result;
578 }
579 SHADOW2_NEXT(REALPATH, (handle, name, resolved_path), char *, NULL);
580}
581
582static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
583 const char *fname)
584{
585 TALLOC_CTX *tmp_ctx = talloc_stackframe();
586 const char *snapdir, *baseoffset, *basedir, *gmt_start;
587 size_t baselen;
588 char *ret;
589
590 DEBUG(10, ("shadow_copy2_connectpath called with %s\n", fname));
591
592 if (!shadow_copy2_match_name(fname, &gmt_start)) {
593 return handle->conn->connectpath;
594 }
595
596 fname = shadow_copy2_normalise_path(talloc_tos(), fname, gmt_start);
597 if (fname == NULL) {
598 TALLOC_FREE(tmp_ctx);
599 return NULL;
600 }
601
602 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
603 if (snapdir == NULL) {
604 DEBUG(2,("no snapdir found for share at %s\n",
605 handle->conn->connectpath));
606 TALLOC_FREE(tmp_ctx);
607 return NULL;
608 }
609
610 basedir = shadow_copy2_find_basedir(tmp_ctx, handle);
611 if (basedir == NULL) {
612 DEBUG(2,("no basedir found for share at %s\n",
613 handle->conn->connectpath));
614 TALLOC_FREE(tmp_ctx);
615 return NULL;
616 }
617
618 baselen = strlen(basedir);
619 baseoffset = handle->conn->connectpath + baselen;
620
621 /* some sanity checks */
622 if (strncmp(basedir, handle->conn->connectpath, baselen) != 0 ||
623 (handle->conn->connectpath[baselen] != 0
624 && handle->conn->connectpath[baselen] != '/')) {
625 DEBUG(0,("shadow_copy2_connectpath: basedir %s is not a "
626 "parent of %s\n", basedir,
627 handle->conn->connectpath));
628 TALLOC_FREE(tmp_ctx);
629 return NULL;
630 }
631
632 if (*baseoffset == '/') baseoffset++;
633
634 ret = talloc_asprintf(talloc_tos(), "%s/%.*s/%s",
635 snapdir,
636 GMT_NAME_LEN, fname,
637 baseoffset);
638 DEBUG(6,("shadow_copy2_connectpath: '%s' -> '%s'\n", fname, ret));
639 TALLOC_FREE(tmp_ctx);
640 return ret;
641}
642
643static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
644 const char *fname, uint32 security_info,
645 struct security_descriptor **ppdesc)
646{
647 SHADOW2_NTSTATUS_NEXT(GET_NT_ACL, (handle, name, security_info, ppdesc), NT_STATUS_ACCESS_DENIED);
648}
649
650static int shadow_copy2_mkdir(vfs_handle_struct *handle, const char *fname, mode_t mode)
651{
652 SHADOW2_NEXT(MKDIR, (handle, name, mode), int, -1);
653}
654
655static int shadow_copy2_rmdir(vfs_handle_struct *handle, const char *fname)
656{
657 SHADOW2_NEXT(RMDIR, (handle, name), int, -1);
658}
659
660static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
661 unsigned int flags)
662{
663 SHADOW2_NEXT(CHFLAGS, (handle, name, flags), int, -1);
664}
665
666static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
667 const char *fname, const char *aname, void *value, size_t size)
668{
669 SHADOW2_NEXT(GETXATTR, (handle, name, aname, value, size), ssize_t, -1);
670}
671
672static ssize_t shadow_copy2_lgetxattr(vfs_handle_struct *handle,
673 const char *fname, const char *aname, void *value, size_t size)
674{
675 SHADOW2_NEXT(LGETXATTR, (handle, name, aname, value, size), ssize_t, -1);
676}
677
678static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle, const char *fname,
679 char *list, size_t size)
680{
681 SHADOW2_NEXT(LISTXATTR, (handle, name, list, size), ssize_t, -1);
682}
683
684static int shadow_copy2_removexattr(struct vfs_handle_struct *handle, const char *fname,
685 const char *aname)
686{
687 SHADOW2_NEXT(REMOVEXATTR, (handle, name, aname), int, -1);
688}
689
690static int shadow_copy2_lremovexattr(struct vfs_handle_struct *handle, const char *fname,
691 const char *aname)
692{
693 SHADOW2_NEXT(LREMOVEXATTR, (handle, name, aname), int, -1);
694}
695
696static int shadow_copy2_setxattr(struct vfs_handle_struct *handle, const char *fname,
697 const char *aname, const void *value, size_t size, int flags)
698{
699 SHADOW2_NEXT(SETXATTR, (handle, name, aname, value, size, flags), int, -1);
700}
701
702static int shadow_copy2_lsetxattr(struct vfs_handle_struct *handle, const char *fname,
703 const char *aname, const void *value, size_t size, int flags)
704{
705 SHADOW2_NEXT(LSETXATTR, (handle, name, aname, value, size, flags), int, -1);
706}
707
708static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
709 const char *fname, mode_t mode)
710{
711 SHADOW2_NEXT(CHMOD_ACL, (handle, name, mode), int, -1);
712}
713
714static int shadow_copy2_get_shadow_copy2_data(vfs_handle_struct *handle,
715 files_struct *fsp,
716 SHADOW_COPY_DATA *shadow_copy2_data,
717 bool labels)
718{
719 SMB_STRUCT_DIR *p;
720 const char *snapdir;
721 SMB_STRUCT_DIRENT *d;
722 TALLOC_CTX *tmp_ctx = talloc_new(handle->data);
723
724 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle);
725 if (snapdir == NULL) {
726 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
727 handle->conn->connectpath));
728 errno = EINVAL;
729 talloc_free(tmp_ctx);
730 return -1;
731 }
732
733 p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
734
735 if (!p) {
736 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
737 " - %s\n", snapdir, strerror(errno)));
738 talloc_free(tmp_ctx);
739 errno = ENOSYS;
740 return -1;
741 }
742
743 talloc_free(tmp_ctx);
744
745 shadow_copy2_data->num_volumes = 0;
746 shadow_copy2_data->labels = NULL;
747
748 while ((d = SMB_VFS_NEXT_READDIR(handle, p, NULL))) {
749 SHADOW_COPY_LABEL *tlabels;
750
751 /* ignore names not of the right form in the snapshot directory */
752 if (!shadow_copy2_match_name(d->d_name, NULL)) {
753 continue;
754 }
755
756 if (!labels) {
757 /* the caller doesn't want the labels */
758 shadow_copy2_data->num_volumes++;
759 continue;
760 }
761
762 tlabels = talloc_realloc(shadow_copy2_data->mem_ctx,
763 shadow_copy2_data->labels,
764 SHADOW_COPY_LABEL, shadow_copy2_data->num_volumes+1);
765 if (tlabels == NULL) {
766 DEBUG(0,("shadow_copy2: out of memory\n"));
767 SMB_VFS_NEXT_CLOSEDIR(handle, p);
768 return -1;
769 }
770
771 strlcpy(tlabels[shadow_copy2_data->num_volumes], d->d_name, sizeof(*tlabels));
772 shadow_copy2_data->num_volumes++;
773 shadow_copy2_data->labels = tlabels;
774 }
775
776 SMB_VFS_NEXT_CLOSEDIR(handle,p);
777 return 0;
778}
779
780static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
781 .opendir = shadow_copy2_opendir,
782 .mkdir = shadow_copy2_mkdir,
783 .rmdir = shadow_copy2_rmdir,
784 .chflags = shadow_copy2_chflags,
785 .getxattr = shadow_copy2_getxattr,
786 .lgetxattr = shadow_copy2_lgetxattr,
787 .listxattr = shadow_copy2_listxattr,
788 .removexattr = shadow_copy2_removexattr,
789 .lremovexattr = shadow_copy2_lremovexattr,
790 .setxattr = shadow_copy2_setxattr,
791 .lsetxattr = shadow_copy2_lsetxattr,
792 .open = shadow_copy2_open,
793 .rename = shadow_copy2_rename,
794 .stat = shadow_copy2_stat,
795 .lstat = shadow_copy2_lstat,
796 .fstat = shadow_copy2_fstat,
797 .unlink = shadow_copy2_unlink,
798 .chmod = shadow_copy2_chmod,
799 .chown = shadow_copy2_chown,
800 .chdir = shadow_copy2_chdir,
801 .ntimes = shadow_copy2_ntimes,
802 .symlink = shadow_copy2_symlink,
803 .vfs_readlink = shadow_copy2_readlink,
804 .link = shadow_copy2_link,
805 .mknod = shadow_copy2_mknod,
806 .realpath = shadow_copy2_realpath,
807 .connectpath = shadow_copy2_connectpath,
808 .get_nt_acl = shadow_copy2_get_nt_acl,
809 .chmod_acl = shadow_copy2_chmod_acl,
810 .get_shadow_copy_data = shadow_copy2_get_shadow_copy2_data,
811};
812
813NTSTATUS vfs_shadow_copy2_init(void);
814NTSTATUS vfs_shadow_copy2_init(void)
815{
816 NTSTATUS ret;
817
818 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "shadow_copy2",
819 &vfs_shadow_copy2_fns);
820
821 if (!NT_STATUS_IS_OK(ret))
822 return ret;
823
824 vfs_shadow_copy2_debug_level = debug_add_class("shadow_copy2");
825 if (vfs_shadow_copy2_debug_level == -1) {
826 vfs_shadow_copy2_debug_level = DBGC_VFS;
827 DEBUG(0, ("%s: Couldn't register custom debugging class!\n",
828 "vfs_shadow_copy2_init"));
829 } else {
830 DEBUG(10, ("%s: Debug class number of '%s': %d\n",
831 "vfs_shadow_copy2_init","shadow_copy2",vfs_shadow_copy2_debug_level));
832 }
833
834 return ret;
835}
Note: See TracBrowser for help on using the repository browser.