2 * shadow_copy2: a shadow copy module (second implementation)
4 * Copyright (C) Andrew Tridgell 2007 (portions taken from shadow_copy2)
5 * Copyright (C) Ed Plese 2009
6 * Copyright (C) Volker Lendecke 2011
7 * Copyright (C) Christian Ambach 2011
8 * Copyright (C) Michael Adam 2013
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 * This is a second implemetation of a shadow copy module for exposing
27 * file system snapshots to windows clients as shadow copies.
29 * See the manual page for documentation.
33 #include "system/filesys.h"
34 #include "include/ntioctl.h"
35 #include <ccan/hash/hash.h>
38 struct shadow_copy2_config
{
43 bool snapdirseverywhere
;
44 bool crossmountpoints
;
47 bool snapdir_absolute
;
50 char *rel_connectpath
; /* share root, relative to the basedir */
51 char *snapshot_basepath
; /* the absolute version of snapdir */
54 static bool shadow_copy2_find_slashes(TALLOC_CTX
*mem_ctx
, const char *str
,
56 unsigned *pnum_offsets
)
65 while ((p
= strchr(p
, '/')) != NULL
) {
70 offsets
= talloc_array(mem_ctx
, size_t, num_offsets
);
71 if (offsets
== NULL
) {
77 while ((p
= strchr(p
, '/')) != NULL
) {
78 offsets
[num_offsets
] = p
-str
;
84 *pnum_offsets
= num_offsets
;
89 * Given a timestamp, build the posix level GMT-tag string
90 * based on the configurable format.
92 static size_t shadow_copy2_posix_gmt_string(struct vfs_handle_struct
*handle
,
94 char *snaptime_string
,
99 struct shadow_copy2_config
*config
;
101 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
104 if (config
->use_sscanf
) {
105 snaptime_len
= snprintf(snaptime_string
,
108 (unsigned long)snapshot
);
109 if (snaptime_len
<= 0) {
110 DEBUG(10, ("snprintf failed\n"));
114 if (config
->use_localtime
) {
115 if (localtime_r(&snapshot
, &snap_tm
) == 0) {
116 DEBUG(10, ("gmtime_r failed\n"));
120 if (gmtime_r(&snapshot
, &snap_tm
) == 0) {
121 DEBUG(10, ("gmtime_r failed\n"));
125 snaptime_len
= strftime(snaptime_string
,
129 if (snaptime_len
== 0) {
130 DEBUG(10, ("strftime failed\n"));
139 * Given a timestamp, build the string to insert into a path
140 * as a path component for creating the local path to the
141 * snapshot at the given timestamp of the input path.
143 * In the case of a parallel snapdir (specified with an
144 * absolute path), this is the inital portion of the
145 * local path of any snapshot file. The complete path is
146 * obtained by appending the portion of the file's path
147 * below the share root's mountpoint.
149 static char *shadow_copy2_insert_string(TALLOC_CTX
*mem_ctx
,
150 struct vfs_handle_struct
*handle
,
153 fstring snaptime_string
;
154 size_t snaptime_len
= 0;
156 struct shadow_copy2_config
*config
;
158 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
161 snaptime_len
= shadow_copy2_posix_gmt_string(handle
,
164 sizeof(snaptime_string
));
165 if (snaptime_len
<= 0) {
169 if (config
->snapdir_absolute
) {
170 result
= talloc_asprintf(mem_ctx
, "%s/%s",
171 config
->snapdir
, snaptime_string
);
173 result
= talloc_asprintf(mem_ctx
, "/%s/%s",
174 config
->snapdir
, snaptime_string
);
176 if (result
== NULL
) {
177 DEBUG(1, (__location__
" talloc_asprintf failed\n"));
184 * Build the posix snapshot path for the connection
185 * at the given timestamp, i.e. the absolute posix path
186 * that contains the snapshot for this file system.
188 * This only applies to classical case, i.e. not
189 * to the "snapdirseverywhere" mode.
191 static char *shadow_copy2_snapshot_path(TALLOC_CTX
*mem_ctx
,
192 struct vfs_handle_struct
*handle
,
195 fstring snaptime_string
;
196 size_t snaptime_len
= 0;
198 struct shadow_copy2_config
*config
;
200 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
203 snaptime_len
= shadow_copy2_posix_gmt_string(handle
,
206 sizeof(snaptime_string
));
207 if (snaptime_len
<= 0) {
211 result
= talloc_asprintf(mem_ctx
, "%s/%s",
212 config
->snapshot_basepath
, snaptime_string
);
213 if (result
== NULL
) {
214 DEBUG(1, (__location__
" talloc_asprintf failed\n"));
221 * Strip a snapshot component from a filename as
222 * handed in via the smb layer.
223 * Returns the parsed timestamp and the stripped filename.
225 static bool shadow_copy2_strip_snapshot(TALLOC_CTX
*mem_ctx
,
226 struct vfs_handle_struct
*handle
,
236 size_t rest_len
, dst_len
;
237 struct shadow_copy2_config
*config
;
239 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
242 DEBUG(10, (__location__
": enter path '%s'\n", name
));
244 p
= strstr_m(name
, "@GMT-");
246 DEBUG(11, ("@GMT not found\n"));
249 if ((p
> name
) && (p
[-1] != '/')) {
250 /* the GMT-token does not start a path-component */
251 DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
252 p
, name
, (int)p
[-1]));
255 q
= strptime(p
, GMT_FORMAT
, &tm
);
257 DEBUG(10, ("strptime failed\n"));
261 timestamp
= timegm(&tm
);
262 if (timestamp
== (time_t)-1) {
263 DEBUG(10, ("timestamp==-1\n"));
267 /* the name consists of only the GMT token */
268 if (pstripped
!= NULL
) {
269 stripped
= talloc_strndup(mem_ctx
, name
, p
- name
);
270 if (stripped
== NULL
) {
273 *pstripped
= stripped
;
275 *ptimestamp
= timestamp
;
280 * The GMT token is either at the end of the path
281 * or it is not a complete path component, i.e. the
282 * path component continues after the gmt-token.
284 * TODO: Is this correct? Or would the GMT tag as the
285 * last component be a valid input?
287 DEBUG(10, ("q[0] = %d\n", (int)q
[0]));
292 rest_len
= strlen(q
);
293 dst_len
= (p
-name
) + rest_len
;
295 if (config
->snapdirseverywhere
) {
298 insert
= shadow_copy2_insert_string(talloc_tos(), handle
,
300 if (insert
== NULL
) {
305 DEBUG(10, (__location__
": snapdirseverywhere mode.\n"
307 "insert string '%s'\n", name
, insert
));
309 have_insert
= (strstr(name
, insert
+1) != NULL
);
310 DEBUG(10, ("have_insert=%d, name=%s, insert+1=%s\n",
311 (int)have_insert
, name
, insert
+1));
313 DEBUG(10, (__location__
": insert string '%s' found in "
314 "path '%s' found in snapdirseverywhere mode "
315 "==> already converted\n", insert
, name
));
324 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
327 if (snapshot_path
== NULL
) {
332 DEBUG(10, (__location__
" path: '%s'.\n"
333 "snapshot path: '%s'\n", name
, snapshot_path
));
335 s
= strstr(name
, snapshot_path
);
338 * this starts with "snapshot_basepath/GMT-Token"
339 * so it is already a converted absolute
340 * path. Don't process further.
342 DEBUG(10, (__location__
": path '%s' starts with "
343 "snapshot path '%s' (not in "
344 "snapdirseverywhere mode) ==> "
345 "already converted\n", name
, snapshot_path
));
346 talloc_free(snapshot_path
);
349 talloc_free(snapshot_path
);
352 if (pstripped
!= NULL
) {
353 stripped
= talloc_array(mem_ctx
, char, dst_len
+1);
354 if (stripped
== NULL
) {
359 memcpy(stripped
, name
, p
-name
);
362 memcpy(stripped
+ (p
-name
), q
, rest_len
);
364 stripped
[dst_len
] = '\0';
365 *pstripped
= stripped
;
367 *ptimestamp
= timestamp
;
374 static char *shadow_copy2_find_mount_point(TALLOC_CTX
*mem_ctx
,
375 vfs_handle_struct
*handle
)
377 char *path
= talloc_strdup(mem_ctx
, handle
->conn
->connectpath
);
382 if (stat(path
, &st
) != 0) {
389 while ((p
= strrchr(path
, '/')) && p
> path
) {
391 if (stat(path
, &st
) != 0) {
395 if (st
.st_dev
!= dev
) {
405 * Convert from a name as handed in via the SMB layer
406 * and a timestamp into the local path of the snapshot
407 * of the provided file at the provided time.
409 static char *shadow_copy2_convert(TALLOC_CTX
*mem_ctx
,
410 struct vfs_handle_struct
*handle
,
411 const char *name
, time_t timestamp
)
413 struct smb_filename converted_fname
;
415 size_t *slashes
= NULL
;
416 unsigned num_slashes
;
420 char *converted
= NULL
;
424 struct shadow_copy2_config
*config
;
426 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
429 DEBUG(10, ("converting '%s'\n", name
));
431 if (!config
->snapdirseverywhere
) {
435 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
438 if (snapshot_path
== NULL
) {
442 if (config
->rel_connectpath
== NULL
) {
443 converted
= talloc_asprintf(mem_ctx
, "%s/%s",
444 snapshot_path
, name
);
446 converted
= talloc_asprintf(mem_ctx
, "%s/%s/%s",
448 config
->rel_connectpath
,
451 if (converted
== NULL
) {
455 ZERO_STRUCT(converted_fname
);
456 converted_fname
.base_name
= converted
;
458 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
459 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
461 ret
, ret
== 0 ? "ok" : strerror(errno
)));
463 DEBUG(10, ("Found %s\n", converted
));
471 /* never reached ... */
474 path
= talloc_asprintf(mem_ctx
, "%s/%s", handle
->conn
->connectpath
,
480 pathlen
= talloc_get_size(path
)-1;
482 if (!shadow_copy2_find_slashes(talloc_tos(), path
,
483 &slashes
, &num_slashes
)) {
487 insert
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
488 if (insert
== NULL
) {
491 insertlen
= talloc_get_size(insert
)-1;
494 * Note: We deliberatly don't expensively initialize the
495 * array with talloc_zero here: Putting zero into
496 * converted[pathlen+insertlen] below is sufficient, because
497 * in the following for loop, the insert string is inserted
498 * at various slash places. So the memory up to position
499 * pathlen+insertlen will always be initialized when the
500 * converted string is used.
502 converted
= talloc_array(mem_ctx
, char, pathlen
+ insertlen
+ 1);
503 if (converted
== NULL
) {
507 if (path
[pathlen
-1] != '/') {
509 * Append a fake slash to find the snapshot root
512 tmp
= talloc_realloc(talloc_tos(), slashes
,
513 size_t, num_slashes
+1);
518 slashes
[num_slashes
] = pathlen
;
524 if (!config
->crossmountpoints
) {
525 min_offset
= strlen(config
->mount_point
);
528 memcpy(converted
, path
, pathlen
+1);
529 converted
[pathlen
+insertlen
] = '\0';
531 ZERO_STRUCT(converted_fname
);
532 converted_fname
.base_name
= converted
;
534 for (i
= num_slashes
-1; i
>=0; i
--) {
540 if (offset
< min_offset
) {
545 memcpy(converted
+offset
, insert
, insertlen
);
548 memcpy(converted
+offset
, path
+ slashes
[i
],
549 pathlen
- slashes
[i
]);
551 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
553 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
555 ret
, ret
== 0 ? "ok" : strerror(errno
)));
560 if (errno
== ENOTDIR
) {
562 * This is a valid condition: We appended the
563 * .snaphots/@GMT.. to a file name. Just try
564 * with the upper levels.
568 if (errno
!= ENOENT
) {
569 /* Other problem than "not found" */
578 DEBUG(10, ("Found %s\n", converted
));
586 TALLOC_FREE(converted
);
588 TALLOC_FREE(slashes
);
595 modify a sbuf return to ensure that inodes in the shadow directory
596 are different from those in the main directory
598 static void convert_sbuf(vfs_handle_struct
*handle
, const char *fname
,
599 SMB_STRUCT_STAT
*sbuf
)
601 struct shadow_copy2_config
*config
;
603 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
606 if (config
->fixinodes
) {
607 /* some snapshot systems, like GPFS, return the name
608 device:inode for the snapshot files as the current
609 files. That breaks the 'restore' button in the shadow copy
610 GUI, as the client gets a sharing violation.
612 This is a crude way of allowing both files to be
613 open at once. It has a slight chance of inode
614 number collision, but I can't see a better approach
615 without significant VFS changes
619 shash
= hash(fname
, strlen(fname
), 0) & 0xFF000000;
623 sbuf
->st_ex_ino
^= shash
;
627 static DIR *shadow_copy2_opendir(vfs_handle_struct
*handle
,
638 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
639 ×tamp
, &stripped
)) {
642 if (timestamp
== 0) {
643 return SMB_VFS_NEXT_OPENDIR(handle
, fname
, mask
, attr
);
645 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
646 TALLOC_FREE(stripped
);
650 ret
= SMB_VFS_NEXT_OPENDIR(handle
, conv
, mask
, attr
);
657 static int shadow_copy2_rename(vfs_handle_struct
*handle
,
658 const struct smb_filename
*smb_fname_src
,
659 const struct smb_filename
*smb_fname_dst
)
661 time_t timestamp_src
, timestamp_dst
;
663 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
664 smb_fname_src
->base_name
,
665 ×tamp_src
, NULL
)) {
668 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
669 smb_fname_dst
->base_name
,
670 ×tamp_dst
, NULL
)) {
673 if (timestamp_src
!= 0) {
677 if (timestamp_dst
!= 0) {
681 return SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, smb_fname_dst
);
684 static int shadow_copy2_symlink(vfs_handle_struct
*handle
,
685 const char *oldname
, const char *newname
)
687 time_t timestamp_old
, timestamp_new
;
689 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
690 ×tamp_old
, NULL
)) {
693 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
694 ×tamp_new
, NULL
)) {
697 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
701 return SMB_VFS_NEXT_SYMLINK(handle
, oldname
, newname
);
704 static int shadow_copy2_link(vfs_handle_struct
*handle
,
705 const char *oldname
, const char *newname
)
707 time_t timestamp_old
, timestamp_new
;
709 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
710 ×tamp_old
, NULL
)) {
713 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
714 ×tamp_new
, NULL
)) {
717 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
721 return SMB_VFS_NEXT_LINK(handle
, oldname
, newname
);
724 static int shadow_copy2_stat(vfs_handle_struct
*handle
,
725 struct smb_filename
*smb_fname
)
728 char *stripped
, *tmp
;
729 int ret
, saved_errno
;
731 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
732 smb_fname
->base_name
,
733 ×tamp
, &stripped
)) {
736 if (timestamp
== 0) {
737 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
740 tmp
= smb_fname
->base_name
;
741 smb_fname
->base_name
= shadow_copy2_convert(
742 talloc_tos(), handle
, stripped
, timestamp
);
743 TALLOC_FREE(stripped
);
745 if (smb_fname
->base_name
== NULL
) {
746 smb_fname
->base_name
= tmp
;
750 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
753 TALLOC_FREE(smb_fname
->base_name
);
754 smb_fname
->base_name
= tmp
;
757 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
763 static int shadow_copy2_lstat(vfs_handle_struct
*handle
,
764 struct smb_filename
*smb_fname
)
767 char *stripped
, *tmp
;
768 int ret
, saved_errno
;
770 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
771 smb_fname
->base_name
,
772 ×tamp
, &stripped
)) {
775 if (timestamp
== 0) {
776 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
779 tmp
= smb_fname
->base_name
;
780 smb_fname
->base_name
= shadow_copy2_convert(
781 talloc_tos(), handle
, stripped
, timestamp
);
782 TALLOC_FREE(stripped
);
784 if (smb_fname
->base_name
== NULL
) {
785 smb_fname
->base_name
= tmp
;
789 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
792 TALLOC_FREE(smb_fname
->base_name
);
793 smb_fname
->base_name
= tmp
;
796 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
802 static int shadow_copy2_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
803 SMB_STRUCT_STAT
*sbuf
)
808 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
812 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
813 fsp
->fsp_name
->base_name
,
817 if (timestamp
!= 0) {
818 convert_sbuf(handle
, fsp
->fsp_name
->base_name
, sbuf
);
823 static int shadow_copy2_open(vfs_handle_struct
*handle
,
824 struct smb_filename
*smb_fname
, files_struct
*fsp
,
825 int flags
, mode_t mode
)
828 char *stripped
, *tmp
;
829 int ret
, saved_errno
;
831 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
832 smb_fname
->base_name
,
833 ×tamp
, &stripped
)) {
836 if (timestamp
== 0) {
837 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
840 tmp
= smb_fname
->base_name
;
841 smb_fname
->base_name
= shadow_copy2_convert(
842 talloc_tos(), handle
, stripped
, timestamp
);
843 TALLOC_FREE(stripped
);
845 if (smb_fname
->base_name
== NULL
) {
846 smb_fname
->base_name
= tmp
;
850 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
853 TALLOC_FREE(smb_fname
->base_name
);
854 smb_fname
->base_name
= tmp
;
860 static int shadow_copy2_unlink(vfs_handle_struct
*handle
,
861 const struct smb_filename
*smb_fname
)
865 int ret
, saved_errno
;
866 struct smb_filename
*conv
;
868 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
869 smb_fname
->base_name
,
870 ×tamp
, &stripped
)) {
873 if (timestamp
== 0) {
874 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
876 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
881 conv
->base_name
= shadow_copy2_convert(
882 conv
, handle
, stripped
, timestamp
);
883 TALLOC_FREE(stripped
);
884 if (conv
->base_name
== NULL
) {
887 ret
= SMB_VFS_NEXT_UNLINK(handle
, conv
);
894 static int shadow_copy2_chmod(vfs_handle_struct
*handle
, const char *fname
,
899 int ret
, saved_errno
;
902 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
903 ×tamp
, &stripped
)) {
906 if (timestamp
== 0) {
907 return SMB_VFS_NEXT_CHMOD(handle
, fname
, mode
);
909 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
910 TALLOC_FREE(stripped
);
914 ret
= SMB_VFS_NEXT_CHMOD(handle
, conv
, mode
);
921 static int shadow_copy2_chown(vfs_handle_struct
*handle
, const char *fname
,
922 uid_t uid
, gid_t gid
)
926 int ret
, saved_errno
;
929 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
930 ×tamp
, &stripped
)) {
933 if (timestamp
== 0) {
934 return SMB_VFS_NEXT_CHOWN(handle
, fname
, uid
, gid
);
936 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
937 TALLOC_FREE(stripped
);
941 ret
= SMB_VFS_NEXT_CHOWN(handle
, conv
, uid
, gid
);
948 static int shadow_copy2_chdir(vfs_handle_struct
*handle
,
953 int ret
, saved_errno
;
956 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
957 ×tamp
, &stripped
)) {
960 if (timestamp
== 0) {
961 return SMB_VFS_NEXT_CHDIR(handle
, fname
);
963 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
964 TALLOC_FREE(stripped
);
968 ret
= SMB_VFS_NEXT_CHDIR(handle
, conv
);
975 static int shadow_copy2_ntimes(vfs_handle_struct
*handle
,
976 const struct smb_filename
*smb_fname
,
977 struct smb_file_time
*ft
)
981 int ret
, saved_errno
;
982 struct smb_filename
*conv
;
984 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
985 smb_fname
->base_name
,
986 ×tamp
, &stripped
)) {
989 if (timestamp
== 0) {
990 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
992 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
997 conv
->base_name
= shadow_copy2_convert(
998 conv
, handle
, stripped
, timestamp
);
999 TALLOC_FREE(stripped
);
1000 if (conv
->base_name
== NULL
) {
1003 ret
= SMB_VFS_NEXT_NTIMES(handle
, conv
, ft
);
1004 saved_errno
= errno
;
1006 errno
= saved_errno
;
1010 static int shadow_copy2_readlink(vfs_handle_struct
*handle
,
1011 const char *fname
, char *buf
, size_t bufsiz
)
1015 int ret
, saved_errno
;
1018 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1019 ×tamp
, &stripped
)) {
1022 if (timestamp
== 0) {
1023 return SMB_VFS_NEXT_READLINK(handle
, fname
, buf
, bufsiz
);
1025 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1026 TALLOC_FREE(stripped
);
1030 ret
= SMB_VFS_NEXT_READLINK(handle
, conv
, buf
, bufsiz
);
1031 saved_errno
= errno
;
1033 errno
= saved_errno
;
1037 static int shadow_copy2_mknod(vfs_handle_struct
*handle
,
1038 const char *fname
, mode_t mode
, SMB_DEV_T dev
)
1042 int ret
, saved_errno
;
1045 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1046 ×tamp
, &stripped
)) {
1049 if (timestamp
== 0) {
1050 return SMB_VFS_NEXT_MKNOD(handle
, fname
, mode
, dev
);
1052 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1053 TALLOC_FREE(stripped
);
1057 ret
= SMB_VFS_NEXT_MKNOD(handle
, conv
, mode
, dev
);
1058 saved_errno
= errno
;
1060 errno
= saved_errno
;
1064 static char *shadow_copy2_realpath(vfs_handle_struct
*handle
,
1068 char *stripped
= NULL
;
1070 char *result
= NULL
;
1071 char *inserted
= NULL
;
1072 char *inserted_to
, *inserted_end
;
1075 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1076 ×tamp
, &stripped
)) {
1079 if (timestamp
== 0) {
1080 return SMB_VFS_NEXT_REALPATH(handle
, fname
);
1083 tmp
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1088 result
= SMB_VFS_NEXT_REALPATH(handle
, tmp
);
1089 if (result
== NULL
) {
1094 * Take away what we've inserted. This removes the @GMT-thingy
1095 * completely, but will give a path under the share root.
1097 inserted
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
1098 if (inserted
== NULL
) {
1101 inserted_to
= strstr_m(result
, inserted
);
1102 if (inserted_to
== NULL
) {
1103 DEBUG(2, ("SMB_VFS_NEXT_REALPATH removed %s\n", inserted
));
1106 inserted_end
= inserted_to
+ talloc_get_size(inserted
) - 1;
1107 memmove(inserted_to
, inserted_end
, strlen(inserted_end
)+1);
1110 saved_errno
= errno
;
1111 TALLOC_FREE(inserted
);
1113 TALLOC_FREE(stripped
);
1114 errno
= saved_errno
;
1119 * Check whether a given directory contains a
1120 * snapshot directory as direct subdirectory.
1121 * If yes, return the path of the snapshot-subdir,
1122 * otherwise return NULL.
1124 static char *have_snapdir(struct vfs_handle_struct
*handle
,
1127 struct smb_filename smb_fname
;
1129 struct shadow_copy2_config
*config
;
1131 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1134 ZERO_STRUCT(smb_fname
);
1135 smb_fname
.base_name
= talloc_asprintf(talloc_tos(), "%s/%s",
1136 path
, config
->snapdir
);
1137 if (smb_fname
.base_name
== NULL
) {
1141 ret
= SMB_VFS_NEXT_STAT(handle
, &smb_fname
);
1142 if ((ret
== 0) && (S_ISDIR(smb_fname
.st
.st_ex_mode
))) {
1143 return smb_fname
.base_name
;
1145 TALLOC_FREE(smb_fname
.base_name
);
1150 * Find the snapshot directory (if any) for the given
1151 * filename (which is relative to the share).
1153 static const char *shadow_copy2_find_snapdir(TALLOC_CTX
*mem_ctx
,
1154 struct vfs_handle_struct
*handle
,
1155 struct smb_filename
*smb_fname
)
1158 const char *snapdir
;
1159 struct shadow_copy2_config
*config
;
1161 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1165 * If the non-snapdisrseverywhere mode, we should not search!
1167 if (!config
->snapdirseverywhere
) {
1168 return config
->snapshot_basepath
;
1171 path
= talloc_asprintf(mem_ctx
, "%s/%s",
1172 handle
->conn
->connectpath
,
1173 smb_fname
->base_name
);
1178 snapdir
= have_snapdir(handle
, path
);
1179 if (snapdir
!= NULL
) {
1184 while ((p
= strrchr(path
, '/')) && (p
> path
)) {
1188 snapdir
= have_snapdir(handle
, path
);
1189 if (snapdir
!= NULL
) {
1198 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct
*handle
,
1200 char *gmt
, size_t gmt_len
)
1202 struct tm timestamp
;
1204 unsigned long int timestamp_long
;
1206 struct shadow_copy2_config
*config
;
1208 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1211 fmt
= config
->gmt_format
;
1213 ZERO_STRUCT(timestamp
);
1214 if (config
->use_sscanf
) {
1215 if (sscanf(name
, fmt
, ×tamp_long
) != 1) {
1216 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1217 "no sscanf match %s: %s\n",
1221 timestamp_t
= timestamp_long
;
1222 gmtime_r(×tamp_t
, ×tamp
);
1224 if (strptime(name
, fmt
, ×tamp
) == NULL
) {
1225 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1226 "no match %s: %s\n",
1230 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1233 if (config
->use_localtime
) {
1234 timestamp
.tm_isdst
= -1;
1235 timestamp_t
= mktime(×tamp
);
1236 gmtime_r(×tamp_t
, ×tamp
);
1240 strftime(gmt
, gmt_len
, GMT_FORMAT
, ×tamp
);
1244 static int shadow_copy2_label_cmp_asc(const void *x
, const void *y
)
1246 return strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1249 static int shadow_copy2_label_cmp_desc(const void *x
, const void *y
)
1251 return -strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1255 sort the shadow copy data in ascending or descending order
1257 static void shadow_copy2_sort_data(vfs_handle_struct
*handle
,
1258 struct shadow_copy_data
*shadow_copy2_data
)
1260 int (*cmpfunc
)(const void *, const void *);
1262 struct shadow_copy2_config
*config
;
1264 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1267 sort
= config
->sort_order
;
1272 if (strcmp(sort
, "asc") == 0) {
1273 cmpfunc
= shadow_copy2_label_cmp_asc
;
1274 } else if (strcmp(sort
, "desc") == 0) {
1275 cmpfunc
= shadow_copy2_label_cmp_desc
;
1280 if (shadow_copy2_data
&& shadow_copy2_data
->num_volumes
> 0 &&
1281 shadow_copy2_data
->labels
)
1283 TYPESAFE_QSORT(shadow_copy2_data
->labels
,
1284 shadow_copy2_data
->num_volumes
,
1289 static int shadow_copy2_get_shadow_copy_data(
1290 vfs_handle_struct
*handle
, files_struct
*fsp
,
1291 struct shadow_copy_data
*shadow_copy2_data
,
1295 const char *snapdir
;
1297 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1299 snapdir
= shadow_copy2_find_snapdir(tmp_ctx
, handle
, fsp
->fsp_name
);
1300 if (snapdir
== NULL
) {
1301 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1302 handle
->conn
->connectpath
));
1304 talloc_free(tmp_ctx
);
1308 p
= SMB_VFS_NEXT_OPENDIR(handle
, snapdir
, NULL
, 0);
1311 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1312 " - %s\n", snapdir
, strerror(errno
)));
1313 talloc_free(tmp_ctx
);
1318 shadow_copy2_data
->num_volumes
= 0;
1319 shadow_copy2_data
->labels
= NULL
;
1321 while ((d
= SMB_VFS_NEXT_READDIR(handle
, p
, NULL
))) {
1322 char snapshot
[GMT_NAME_LEN
+1];
1323 SHADOW_COPY_LABEL
*tlabels
;
1326 * ignore names not of the right form in the snapshot
1329 if (!shadow_copy2_snapshot_to_gmt(
1331 snapshot
, sizeof(snapshot
))) {
1333 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1334 "ignoring %s\n", d
->d_name
));
1337 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1338 d
->d_name
, snapshot
));
1341 /* the caller doesn't want the labels */
1342 shadow_copy2_data
->num_volumes
++;
1346 tlabels
= talloc_realloc(shadow_copy2_data
,
1347 shadow_copy2_data
->labels
,
1349 shadow_copy2_data
->num_volumes
+1);
1350 if (tlabels
== NULL
) {
1351 DEBUG(0,("shadow_copy2: out of memory\n"));
1352 SMB_VFS_NEXT_CLOSEDIR(handle
, p
);
1353 talloc_free(tmp_ctx
);
1357 strlcpy(tlabels
[shadow_copy2_data
->num_volumes
], snapshot
,
1360 shadow_copy2_data
->num_volumes
++;
1361 shadow_copy2_data
->labels
= tlabels
;
1364 SMB_VFS_NEXT_CLOSEDIR(handle
,p
);
1366 shadow_copy2_sort_data(handle
, shadow_copy2_data
);
1368 talloc_free(tmp_ctx
);
1372 static NTSTATUS
shadow_copy2_fget_nt_acl(vfs_handle_struct
*handle
,
1373 struct files_struct
*fsp
,
1374 uint32 security_info
,
1375 TALLOC_CTX
*mem_ctx
,
1376 struct security_descriptor
**ppdesc
)
1383 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
1384 fsp
->fsp_name
->base_name
,
1385 ×tamp
, &stripped
)) {
1386 return map_nt_error_from_unix(errno
);
1388 if (timestamp
== 0) {
1389 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1393 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1394 TALLOC_FREE(stripped
);
1396 return map_nt_error_from_unix(errno
);
1398 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1404 static NTSTATUS
shadow_copy2_get_nt_acl(vfs_handle_struct
*handle
,
1406 uint32 security_info
,
1407 TALLOC_CTX
*mem_ctx
,
1408 struct security_descriptor
**ppdesc
)
1415 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1416 ×tamp
, &stripped
)) {
1417 return map_nt_error_from_unix(errno
);
1419 if (timestamp
== 0) {
1420 return SMB_VFS_NEXT_GET_NT_ACL(handle
, fname
, security_info
,
1423 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1424 TALLOC_FREE(stripped
);
1426 return map_nt_error_from_unix(errno
);
1428 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1434 static int shadow_copy2_mkdir(vfs_handle_struct
*handle
,
1435 const char *fname
, mode_t mode
)
1439 int ret
, saved_errno
;
1442 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1443 ×tamp
, &stripped
)) {
1446 if (timestamp
== 0) {
1447 return SMB_VFS_NEXT_MKDIR(handle
, fname
, mode
);
1449 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1450 TALLOC_FREE(stripped
);
1454 ret
= SMB_VFS_NEXT_MKDIR(handle
, conv
, mode
);
1455 saved_errno
= errno
;
1457 errno
= saved_errno
;
1461 static int shadow_copy2_rmdir(vfs_handle_struct
*handle
, const char *fname
)
1465 int ret
, saved_errno
;
1468 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1469 ×tamp
, &stripped
)) {
1472 if (timestamp
== 0) {
1473 return SMB_VFS_NEXT_RMDIR(handle
, fname
);
1475 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1476 TALLOC_FREE(stripped
);
1480 ret
= SMB_VFS_NEXT_RMDIR(handle
, conv
);
1481 saved_errno
= errno
;
1483 errno
= saved_errno
;
1487 static int shadow_copy2_chflags(vfs_handle_struct
*handle
, const char *fname
,
1492 int ret
, saved_errno
;
1495 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1496 ×tamp
, &stripped
)) {
1499 if (timestamp
== 0) {
1500 return SMB_VFS_NEXT_CHFLAGS(handle
, fname
, flags
);
1502 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1503 TALLOC_FREE(stripped
);
1507 ret
= SMB_VFS_NEXT_CHFLAGS(handle
, conv
, flags
);
1508 saved_errno
= errno
;
1510 errno
= saved_errno
;
1514 static ssize_t
shadow_copy2_getxattr(vfs_handle_struct
*handle
,
1515 const char *fname
, const char *aname
,
1516 void *value
, size_t size
)
1524 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1525 ×tamp
, &stripped
)) {
1528 if (timestamp
== 0) {
1529 return SMB_VFS_NEXT_GETXATTR(handle
, fname
, aname
, value
,
1532 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1533 TALLOC_FREE(stripped
);
1537 ret
= SMB_VFS_NEXT_GETXATTR(handle
, conv
, aname
, value
, size
);
1538 saved_errno
= errno
;
1540 errno
= saved_errno
;
1544 static ssize_t
shadow_copy2_listxattr(struct vfs_handle_struct
*handle
,
1546 char *list
, size_t size
)
1554 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1555 ×tamp
, &stripped
)) {
1558 if (timestamp
== 0) {
1559 return SMB_VFS_NEXT_LISTXATTR(handle
, fname
, list
, size
);
1561 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1562 TALLOC_FREE(stripped
);
1566 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, conv
, list
, size
);
1567 saved_errno
= errno
;
1569 errno
= saved_errno
;
1573 static int shadow_copy2_removexattr(vfs_handle_struct
*handle
,
1574 const char *fname
, const char *aname
)
1578 int ret
, saved_errno
;
1581 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1582 ×tamp
, &stripped
)) {
1585 if (timestamp
== 0) {
1586 return SMB_VFS_NEXT_REMOVEXATTR(handle
, fname
, aname
);
1588 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1589 TALLOC_FREE(stripped
);
1593 ret
= SMB_VFS_NEXT_REMOVEXATTR(handle
, conv
, aname
);
1594 saved_errno
= errno
;
1596 errno
= saved_errno
;
1600 static int shadow_copy2_setxattr(struct vfs_handle_struct
*handle
,
1602 const char *aname
, const void *value
,
1603 size_t size
, int flags
)
1611 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1612 ×tamp
, &stripped
)) {
1615 if (timestamp
== 0) {
1616 return SMB_VFS_NEXT_SETXATTR(handle
, fname
, aname
, value
, size
,
1619 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1620 TALLOC_FREE(stripped
);
1624 ret
= SMB_VFS_NEXT_SETXATTR(handle
, conv
, aname
, value
, size
, flags
);
1625 saved_errno
= errno
;
1627 errno
= saved_errno
;
1631 static int shadow_copy2_chmod_acl(vfs_handle_struct
*handle
,
1632 const char *fname
, mode_t mode
)
1640 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1641 ×tamp
, &stripped
)) {
1644 if (timestamp
== 0) {
1645 return SMB_VFS_NEXT_CHMOD_ACL(handle
, fname
, mode
);
1647 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1648 TALLOC_FREE(stripped
);
1652 ret
= SMB_VFS_NEXT_CHMOD_ACL(handle
, conv
, mode
);
1653 saved_errno
= errno
;
1655 errno
= saved_errno
;
1659 static int shadow_copy2_get_real_filename(struct vfs_handle_struct
*handle
,
1662 TALLOC_CTX
*mem_ctx
,
1671 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1672 ×tamp
, &stripped
)) {
1675 if (timestamp
== 0) {
1676 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
1677 mem_ctx
, found_name
);
1679 if (stripped
[0] == '\0') {
1680 *found_name
= talloc_strdup(mem_ctx
, name
);
1681 if (*found_name
== NULL
) {
1687 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1688 TALLOC_FREE(stripped
);
1692 ret
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, conv
, name
,
1693 mem_ctx
, found_name
);
1694 saved_errno
= errno
;
1696 errno
= saved_errno
;
1700 static uint64_t shadow_copy2_disk_free(vfs_handle_struct
*handle
,
1701 const char *path
, bool small_query
,
1702 uint64_t *bsize
, uint64_t *dfree
,
1711 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1712 ×tamp
, &stripped
)) {
1715 if (timestamp
== 0) {
1716 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1717 bsize
, dfree
, dsize
);
1720 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1721 TALLOC_FREE(stripped
);
1726 ret
= SMB_VFS_NEXT_DISK_FREE(handle
, conv
, small_query
, bsize
, dfree
,
1729 saved_errno
= errno
;
1731 errno
= saved_errno
;
1736 static int shadow_copy2_connect(struct vfs_handle_struct
*handle
,
1737 const char *service
, const char *user
)
1739 struct shadow_copy2_config
*config
;
1741 const char *snapdir
;
1742 const char *gmt_format
;
1743 const char *sort_order
;
1744 const char *basedir
;
1745 const char *mount_point
;
1747 DEBUG(10, (__location__
": cnum[%u], connectpath[%s]\n",
1748 (unsigned)handle
->conn
->cnum
,
1749 handle
->conn
->connectpath
));
1751 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1756 config
= talloc_zero(handle
->conn
, struct shadow_copy2_config
);
1757 if (config
== NULL
) {
1758 DEBUG(0, ("talloc_zero() failed\n"));
1763 gmt_format
= lp_parm_const_string(SNUM(handle
->conn
),
1766 config
->gmt_format
= talloc_strdup(config
, gmt_format
);
1767 if (config
->gmt_format
== NULL
) {
1768 DEBUG(0, ("talloc_strdup() failed\n"));
1773 config
->use_sscanf
= lp_parm_bool(SNUM(handle
->conn
),
1774 "shadow", "sscanf", false);
1776 config
->use_localtime
= lp_parm_bool(SNUM(handle
->conn
),
1777 "shadow", "localtime",
1780 snapdir
= lp_parm_const_string(SNUM(handle
->conn
),
1781 "shadow", "snapdir",
1783 config
->snapdir
= talloc_strdup(config
, snapdir
);
1784 if (config
->snapdir
== NULL
) {
1785 DEBUG(0, ("talloc_strdup() failed\n"));
1790 config
->snapdirseverywhere
= lp_parm_bool(SNUM(handle
->conn
),
1792 "snapdirseverywhere",
1795 config
->crossmountpoints
= lp_parm_bool(SNUM(handle
->conn
),
1796 "shadow", "crossmountpoints",
1799 config
->fixinodes
= lp_parm_bool(SNUM(handle
->conn
),
1800 "shadow", "fixinodes",
1803 sort_order
= lp_parm_const_string(SNUM(handle
->conn
),
1804 "shadow", "sort", "desc");
1805 config
->sort_order
= talloc_strdup(config
, sort_order
);
1806 if (config
->sort_order
== NULL
) {
1807 DEBUG(0, ("talloc_strdup() failed\n"));
1812 mount_point
= lp_parm_const_string(SNUM(handle
->conn
),
1813 "shadow", "mountpoint", NULL
);
1814 if (mount_point
!= NULL
) {
1815 if (mount_point
[0] != '/') {
1816 DEBUG(1, (__location__
" Warning: 'mountpoint' is "
1817 "relative ('%s'), but it has to be an "
1818 "absolute path. Ignoring provided value.\n",
1823 p
= strstr(handle
->conn
->connectpath
, mount_point
);
1824 if (p
!= handle
->conn
->connectpath
) {
1825 DEBUG(1, ("Warning: mount_point (%s) is not a "
1826 "subdirectory of the share root "
1827 "(%s). Ignoring provided value.\n",
1829 handle
->conn
->connectpath
));
1835 if (mount_point
!= NULL
) {
1836 config
->mount_point
= talloc_strdup(config
, mount_point
);
1837 if (config
->mount_point
== NULL
) {
1838 DEBUG(0, (__location__
" talloc_strdup() failed\n"));
1842 config
->mount_point
= shadow_copy2_find_mount_point(config
,
1844 if (config
->mount_point
== NULL
) {
1845 DEBUG(0, (__location__
": shadow_copy2_find_mount_point"
1846 " failed: %s\n", strerror(errno
)));
1851 basedir
= lp_parm_const_string(SNUM(handle
->conn
),
1852 "shadow", "basedir", NULL
);
1854 if (basedir
!= NULL
) {
1855 if (basedir
[0] != '/') {
1856 DEBUG(1, (__location__
" Warning: 'basedir' is "
1857 "relative ('%s'), but it has to be an "
1858 "absolute path. Disabling basedir.\n",
1862 p
= strstr(basedir
, config
->mount_point
);
1864 DEBUG(1, ("Warning: basedir (%s) is not a "
1865 "subdirectory of the share root's "
1866 "mount point (%s). "
1867 "Disabling basedir\n",
1868 basedir
, config
->mount_point
));
1870 config
->basedir
= talloc_strdup(config
,
1872 if (config
->basedir
== NULL
) {
1873 DEBUG(0, ("talloc_strdup() failed\n"));
1881 if (config
->snapdirseverywhere
&& config
->basedir
!= NULL
) {
1882 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1883 "with 'snapdirseverywhere'. Disabling basedir.\n"));
1884 TALLOC_FREE(config
->basedir
);
1887 if (config
->crossmountpoints
&& config
->basedir
!= NULL
) {
1888 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1889 "with 'crossmountpoints'. Disabling basedir.\n"));
1890 TALLOC_FREE(config
->basedir
);
1893 if (config
->basedir
== NULL
) {
1894 config
->basedir
= config
->mount_point
;
1897 if (strlen(config
->basedir
) != strlen(handle
->conn
->connectpath
)) {
1898 config
->rel_connectpath
= talloc_strdup(config
,
1899 handle
->conn
->connectpath
+ strlen(config
->basedir
));
1900 if (config
->rel_connectpath
== NULL
) {
1901 DEBUG(0, ("talloc_strdup() failed\n"));
1907 if (config
->snapdir
[0] == '/') {
1908 config
->snapdir_absolute
= true;
1910 if (config
->snapdirseverywhere
== true) {
1911 DEBUG(1, (__location__
" Warning: An absolute snapdir "
1912 "is incompatible with 'snapdirseverywhere', "
1913 "setting 'snapdirseverywhere' to false.\n"));
1914 config
->snapdirseverywhere
= false;
1917 if (config
->crossmountpoints
== true) {
1918 DEBUG(1, (__location__
" Warning: 'crossmountpoints' "
1919 "is not supported with an absolute snapdir. "
1920 "Disabling it.\n"));
1921 config
->crossmountpoints
= false;
1924 config
->snapshot_basepath
= config
->snapdir
;
1926 config
->snapshot_basepath
= talloc_asprintf(config
, "%s/%s",
1927 config
->mount_point
, config
->snapdir
);
1928 if (config
->snapshot_basepath
== NULL
) {
1929 DEBUG(0, ("talloc_asprintf() failed\n"));
1935 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
1936 " share root: '%s'\n"
1938 " mountpoint: '%s'\n"
1939 " rel share root: '%s'\n"
1941 " snapshot base path: '%s'\n"
1944 " snapdirs everywhere: %s\n"
1945 " cross mountpoints: %s\n"
1949 handle
->conn
->connectpath
,
1951 config
->mount_point
,
1952 config
->rel_connectpath
,
1954 config
->snapshot_basepath
,
1956 config
->use_sscanf
? "yes" : "no",
1957 config
->snapdirseverywhere
? "yes" : "no",
1958 config
->crossmountpoints
? "yes" : "no",
1959 config
->fixinodes
? "yes" : "no",
1964 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1965 NULL
, struct shadow_copy2_config
,
1971 static struct vfs_fn_pointers vfs_shadow_copy2_fns
= {
1972 .connect_fn
= shadow_copy2_connect
,
1973 .opendir_fn
= shadow_copy2_opendir
,
1974 .disk_free_fn
= shadow_copy2_disk_free
,
1975 .rename_fn
= shadow_copy2_rename
,
1976 .link_fn
= shadow_copy2_link
,
1977 .symlink_fn
= shadow_copy2_symlink
,
1978 .stat_fn
= shadow_copy2_stat
,
1979 .lstat_fn
= shadow_copy2_lstat
,
1980 .fstat_fn
= shadow_copy2_fstat
,
1981 .open_fn
= shadow_copy2_open
,
1982 .unlink_fn
= shadow_copy2_unlink
,
1983 .chmod_fn
= shadow_copy2_chmod
,
1984 .chown_fn
= shadow_copy2_chown
,
1985 .chdir_fn
= shadow_copy2_chdir
,
1986 .ntimes_fn
= shadow_copy2_ntimes
,
1987 .readlink_fn
= shadow_copy2_readlink
,
1988 .mknod_fn
= shadow_copy2_mknod
,
1989 .realpath_fn
= shadow_copy2_realpath
,
1990 .get_nt_acl_fn
= shadow_copy2_get_nt_acl
,
1991 .fget_nt_acl_fn
= shadow_copy2_fget_nt_acl
,
1992 .get_shadow_copy_data_fn
= shadow_copy2_get_shadow_copy_data
,
1993 .mkdir_fn
= shadow_copy2_mkdir
,
1994 .rmdir_fn
= shadow_copy2_rmdir
,
1995 .getxattr_fn
= shadow_copy2_getxattr
,
1996 .listxattr_fn
= shadow_copy2_listxattr
,
1997 .removexattr_fn
= shadow_copy2_removexattr
,
1998 .setxattr_fn
= shadow_copy2_setxattr
,
1999 .chmod_acl_fn
= shadow_copy2_chmod_acl
,
2000 .chflags_fn
= shadow_copy2_chflags
,
2001 .get_real_filename_fn
= shadow_copy2_get_real_filename
,
2004 NTSTATUS
vfs_shadow_copy2_init(void);
2005 NTSTATUS
vfs_shadow_copy2_init(void)
2007 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
2008 "shadow_copy2", &vfs_shadow_copy2_fns
);