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 timstamp, build the posix level GTM-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 timstamp, 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 an 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-");
248 if ((p
> name
) && (p
[-1] != '/')) {
249 /* the GMT-token does not start a path-component */
252 q
= strptime(p
, GMT_FORMAT
, &tm
);
257 timestamp
= timegm(&tm
);
258 if (timestamp
== (time_t)-1) {
261 if ((p
== name
) && (q
[0] == '\0')) {
262 /* the name consists of only the GMT token */
263 if (pstripped
!= NULL
) {
264 stripped
= talloc_strdup(mem_ctx
, "");
265 if (stripped
== NULL
) {
268 *pstripped
= stripped
;
270 *ptimestamp
= timestamp
;
275 * The GMT token is either at the end of the path
276 * or it is not a complete path component, i.e. the
277 * path component continues after the gmt-token.
279 * TODO: Is this correct? Or would the GMT tag as the
280 * last component be a valid input?
286 rest_len
= strlen(q
);
287 dst_len
= (p
-name
) + rest_len
;
289 if (config
->snapdirseverywhere
) {
292 insert
= shadow_copy2_insert_string(talloc_tos(), handle
,
294 if (insert
== NULL
) {
299 DEBUG(10, (__location__
": snapdirseverywhere mode.\n"
301 "insert string '%s'\n", name
, insert
));
303 have_insert
= (strstr(name
, insert
+1) != NULL
);
305 DEBUG(10, (__location__
": insert string '%s' found in "
306 "path '%s' found in snapdirseverywhere mode "
307 "==> already converted\n", insert
, name
));
316 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
319 if (snapshot_path
== NULL
) {
324 DEBUG(10, (__location__
" path: '%s'.\n"
325 "snapshot path: '%s'\n", name
, snapshot_path
));
327 s
= strstr(name
, snapshot_path
);
330 * this starts with "snapshot_basepath/GMT-Token"
331 * so it is already a converted absolute
332 * path. Don't process further.
334 DEBUG(10, (__location__
": path '%s' starts with "
335 "snapshot path '%s' (not in "
336 "snapdirseverywhere mode) ==> "
337 "already converted\n", name
, snapshot_path
));
338 talloc_free(snapshot_path
);
341 talloc_free(snapshot_path
);
344 if (pstripped
!= NULL
) {
345 stripped
= talloc_array(mem_ctx
, char, dst_len
+1);
346 if (stripped
== NULL
) {
351 memcpy(stripped
, name
, p
-name
);
354 memcpy(stripped
+ (p
-name
), q
, rest_len
);
356 stripped
[dst_len
] = '\0';
357 *pstripped
= stripped
;
359 *ptimestamp
= timestamp
;
366 static char *shadow_copy2_find_mount_point(TALLOC_CTX
*mem_ctx
,
367 vfs_handle_struct
*handle
)
369 char *path
= talloc_strdup(mem_ctx
, handle
->conn
->connectpath
);
374 if (stat(path
, &st
) != 0) {
381 while ((p
= strrchr(path
, '/')) && p
> path
) {
383 if (stat(path
, &st
) != 0) {
387 if (st
.st_dev
!= dev
) {
397 * Convert from a name as handed in via the SMB layer
398 * and a timestamp into the local path of the snapshot
399 * of the provided file at the provided time.
401 static char *shadow_copy2_convert(TALLOC_CTX
*mem_ctx
,
402 struct vfs_handle_struct
*handle
,
403 const char *name
, time_t timestamp
)
405 struct smb_filename converted_fname
;
407 size_t *slashes
= NULL
;
408 unsigned num_slashes
;
412 char *converted
= NULL
;
416 struct shadow_copy2_config
*config
;
418 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
421 DEBUG(10, ("converting '%s'\n", name
));
423 if (!config
->snapdirseverywhere
) {
427 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
430 if (snapshot_path
== NULL
) {
434 if (config
->rel_connectpath
== NULL
) {
435 converted
= talloc_asprintf(mem_ctx
, "%s/%s",
436 snapshot_path
, name
);
438 converted
= talloc_asprintf(mem_ctx
, "%s/%s/%s",
440 config
->rel_connectpath
,
443 if (converted
== NULL
) {
447 ZERO_STRUCT(converted_fname
);
448 converted_fname
.base_name
= converted
;
450 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
451 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
453 ret
, ret
== 0 ? "ok" : strerror(errno
)));
455 DEBUG(10, ("Found %s\n", converted
));
463 /* never reached ... */
466 path
= talloc_asprintf(mem_ctx
, "%s/%s", handle
->conn
->connectpath
,
472 pathlen
= talloc_get_size(path
)-1;
474 if (!shadow_copy2_find_slashes(talloc_tos(), path
,
475 &slashes
, &num_slashes
)) {
479 insert
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
480 if (insert
== NULL
) {
483 insertlen
= talloc_get_size(insert
)-1;
486 * Note: We deliberatly don't expensively initialize the
487 * array with talloc_zero here: Putting zero into
488 * converted[pathlen+insertlen] below is sufficient, because
489 * in the following for loop, the insert string is inserted
490 * at various slash places. So the memory up to position
491 * pathlen+insertlen will always be initialized when the
492 * converted string is used.
494 converted
= talloc_array(mem_ctx
, char, pathlen
+ insertlen
+ 1);
495 if (converted
== NULL
) {
499 if (path
[pathlen
-1] != '/') {
501 * Append a fake slash to find the snapshot root
504 tmp
= talloc_realloc(talloc_tos(), slashes
,
505 size_t, num_slashes
+1);
510 slashes
[num_slashes
] = pathlen
;
516 if (!config
->crossmountpoints
) {
517 min_offset
= strlen(config
->mount_point
);
520 memcpy(converted
, path
, pathlen
+1);
521 converted
[pathlen
+insertlen
] = '\0';
523 ZERO_STRUCT(converted_fname
);
524 converted_fname
.base_name
= converted
;
526 for (i
= num_slashes
-1; i
>=0; i
--) {
532 if (offset
< min_offset
) {
537 memcpy(converted
+offset
, insert
, insertlen
);
540 memcpy(converted
+offset
, path
+ slashes
[i
],
541 pathlen
- slashes
[i
]);
543 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
545 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
547 ret
, ret
== 0 ? "ok" : strerror(errno
)));
552 if (errno
== ENOTDIR
) {
554 * This is a valid condition: We appended the
555 * .snaphots/@GMT.. to a file name. Just try
556 * with the upper levels.
560 if (errno
!= ENOENT
) {
561 /* Other problem than "not found" */
570 DEBUG(10, ("Found %s\n", converted
));
578 TALLOC_FREE(converted
);
580 TALLOC_FREE(slashes
);
587 modify a sbuf return to ensure that inodes in the shadow directory
588 are different from those in the main directory
590 static void convert_sbuf(vfs_handle_struct
*handle
, const char *fname
,
591 SMB_STRUCT_STAT
*sbuf
)
593 struct shadow_copy2_config
*config
;
595 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
598 if (config
->fixinodes
) {
599 /* some snapshot systems, like GPFS, return the name
600 device:inode for the snapshot files as the current
601 files. That breaks the 'restore' button in the shadow copy
602 GUI, as the client gets a sharing violation.
604 This is a crude way of allowing both files to be
605 open at once. It has a slight chance of inode
606 number collision, but I can't see a better approach
607 without significant VFS changes
611 shash
= hash(fname
, strlen(fname
), 0) & 0xFF000000;
615 sbuf
->st_ex_ino
^= shash
;
619 static DIR *shadow_copy2_opendir(vfs_handle_struct
*handle
,
630 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
631 ×tamp
, &stripped
)) {
634 if (timestamp
== 0) {
635 return SMB_VFS_NEXT_OPENDIR(handle
, fname
, mask
, attr
);
637 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
638 TALLOC_FREE(stripped
);
642 ret
= SMB_VFS_NEXT_OPENDIR(handle
, conv
, mask
, attr
);
649 static int shadow_copy2_rename(vfs_handle_struct
*handle
,
650 const struct smb_filename
*smb_fname_src
,
651 const struct smb_filename
*smb_fname_dst
)
653 time_t timestamp_src
, timestamp_dst
;
655 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
656 smb_fname_src
->base_name
,
657 ×tamp_src
, NULL
)) {
660 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
661 smb_fname_dst
->base_name
,
662 ×tamp_dst
, NULL
)) {
665 if (timestamp_src
!= 0) {
669 if (timestamp_dst
!= 0) {
673 return SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, smb_fname_dst
);
676 static int shadow_copy2_symlink(vfs_handle_struct
*handle
,
677 const char *oldname
, const char *newname
)
679 time_t timestamp_old
, timestamp_new
;
681 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
682 ×tamp_old
, NULL
)) {
685 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
686 ×tamp_new
, NULL
)) {
689 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
693 return SMB_VFS_NEXT_SYMLINK(handle
, oldname
, newname
);
696 static int shadow_copy2_link(vfs_handle_struct
*handle
,
697 const char *oldname
, const char *newname
)
699 time_t timestamp_old
, timestamp_new
;
701 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
702 ×tamp_old
, NULL
)) {
705 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
706 ×tamp_new
, NULL
)) {
709 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
713 return SMB_VFS_NEXT_LINK(handle
, oldname
, newname
);
716 static int shadow_copy2_stat(vfs_handle_struct
*handle
,
717 struct smb_filename
*smb_fname
)
720 char *stripped
, *tmp
;
721 int ret
, saved_errno
;
723 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
724 smb_fname
->base_name
,
725 ×tamp
, &stripped
)) {
728 if (timestamp
== 0) {
729 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
732 tmp
= smb_fname
->base_name
;
733 smb_fname
->base_name
= shadow_copy2_convert(
734 talloc_tos(), handle
, stripped
, timestamp
);
735 TALLOC_FREE(stripped
);
737 if (smb_fname
->base_name
== NULL
) {
738 smb_fname
->base_name
= tmp
;
742 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
745 TALLOC_FREE(smb_fname
->base_name
);
746 smb_fname
->base_name
= tmp
;
749 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
755 static int shadow_copy2_lstat(vfs_handle_struct
*handle
,
756 struct smb_filename
*smb_fname
)
759 char *stripped
, *tmp
;
760 int ret
, saved_errno
;
762 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
763 smb_fname
->base_name
,
764 ×tamp
, &stripped
)) {
767 if (timestamp
== 0) {
768 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
771 tmp
= smb_fname
->base_name
;
772 smb_fname
->base_name
= shadow_copy2_convert(
773 talloc_tos(), handle
, stripped
, timestamp
);
774 TALLOC_FREE(stripped
);
776 if (smb_fname
->base_name
== NULL
) {
777 smb_fname
->base_name
= tmp
;
781 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
784 TALLOC_FREE(smb_fname
->base_name
);
785 smb_fname
->base_name
= tmp
;
788 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
794 static int shadow_copy2_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
795 SMB_STRUCT_STAT
*sbuf
)
800 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
804 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
805 fsp
->fsp_name
->base_name
,
809 if (timestamp
!= 0) {
810 convert_sbuf(handle
, fsp
->fsp_name
->base_name
, sbuf
);
815 static int shadow_copy2_open(vfs_handle_struct
*handle
,
816 struct smb_filename
*smb_fname
, files_struct
*fsp
,
817 int flags
, mode_t mode
)
820 char *stripped
, *tmp
;
821 int ret
, saved_errno
;
823 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
824 smb_fname
->base_name
,
825 ×tamp
, &stripped
)) {
828 if (timestamp
== 0) {
829 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
832 tmp
= smb_fname
->base_name
;
833 smb_fname
->base_name
= shadow_copy2_convert(
834 talloc_tos(), handle
, stripped
, timestamp
);
835 TALLOC_FREE(stripped
);
837 if (smb_fname
->base_name
== NULL
) {
838 smb_fname
->base_name
= tmp
;
842 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
845 TALLOC_FREE(smb_fname
->base_name
);
846 smb_fname
->base_name
= tmp
;
852 static int shadow_copy2_unlink(vfs_handle_struct
*handle
,
853 const struct smb_filename
*smb_fname
)
857 int ret
, saved_errno
;
858 struct smb_filename
*conv
;
861 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
862 smb_fname
->base_name
,
863 ×tamp
, &stripped
)) {
866 if (timestamp
== 0) {
867 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
869 status
= copy_smb_filename(talloc_tos(), smb_fname
, &conv
);
870 if (!NT_STATUS_IS_OK(status
)) {
874 conv
->base_name
= shadow_copy2_convert(
875 conv
, handle
, stripped
, timestamp
);
876 TALLOC_FREE(stripped
);
877 if (conv
->base_name
== NULL
) {
880 ret
= SMB_VFS_NEXT_UNLINK(handle
, conv
);
887 static int shadow_copy2_chmod(vfs_handle_struct
*handle
, const char *fname
,
892 int ret
, saved_errno
;
895 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
896 ×tamp
, &stripped
)) {
899 if (timestamp
== 0) {
900 return SMB_VFS_NEXT_CHMOD(handle
, fname
, mode
);
902 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
903 TALLOC_FREE(stripped
);
907 ret
= SMB_VFS_NEXT_CHMOD(handle
, conv
, mode
);
914 static int shadow_copy2_chown(vfs_handle_struct
*handle
, const char *fname
,
915 uid_t uid
, gid_t gid
)
919 int ret
, saved_errno
;
922 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
923 ×tamp
, &stripped
)) {
926 if (timestamp
== 0) {
927 return SMB_VFS_NEXT_CHOWN(handle
, fname
, uid
, gid
);
929 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
930 TALLOC_FREE(stripped
);
934 ret
= SMB_VFS_NEXT_CHOWN(handle
, conv
, uid
, gid
);
941 static int shadow_copy2_chdir(vfs_handle_struct
*handle
,
946 int ret
, saved_errno
;
949 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
950 ×tamp
, &stripped
)) {
953 if (timestamp
== 0) {
954 return SMB_VFS_NEXT_CHDIR(handle
, fname
);
956 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
957 TALLOC_FREE(stripped
);
961 ret
= SMB_VFS_NEXT_CHDIR(handle
, conv
);
968 static int shadow_copy2_ntimes(vfs_handle_struct
*handle
,
969 const struct smb_filename
*smb_fname
,
970 struct smb_file_time
*ft
)
974 int ret
, saved_errno
;
975 struct smb_filename
*conv
;
978 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
979 smb_fname
->base_name
,
980 ×tamp
, &stripped
)) {
983 if (timestamp
== 0) {
984 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
986 status
= copy_smb_filename(talloc_tos(), smb_fname
, &conv
);
987 if (!NT_STATUS_IS_OK(status
)) {
991 conv
->base_name
= shadow_copy2_convert(
992 conv
, handle
, stripped
, timestamp
);
993 TALLOC_FREE(stripped
);
994 if (conv
->base_name
== NULL
) {
997 ret
= SMB_VFS_NEXT_NTIMES(handle
, conv
, ft
);
1000 errno
= saved_errno
;
1004 static int shadow_copy2_readlink(vfs_handle_struct
*handle
,
1005 const char *fname
, char *buf
, size_t bufsiz
)
1009 int ret
, saved_errno
;
1012 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1013 ×tamp
, &stripped
)) {
1016 if (timestamp
== 0) {
1017 return SMB_VFS_NEXT_READLINK(handle
, fname
, buf
, bufsiz
);
1019 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1020 TALLOC_FREE(stripped
);
1024 ret
= SMB_VFS_NEXT_READLINK(handle
, conv
, buf
, bufsiz
);
1025 saved_errno
= errno
;
1027 errno
= saved_errno
;
1031 static int shadow_copy2_mknod(vfs_handle_struct
*handle
,
1032 const char *fname
, mode_t mode
, SMB_DEV_T dev
)
1036 int ret
, saved_errno
;
1039 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1040 ×tamp
, &stripped
)) {
1043 if (timestamp
== 0) {
1044 return SMB_VFS_NEXT_MKNOD(handle
, fname
, mode
, dev
);
1046 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1047 TALLOC_FREE(stripped
);
1051 ret
= SMB_VFS_NEXT_MKNOD(handle
, conv
, mode
, dev
);
1052 saved_errno
= errno
;
1054 errno
= saved_errno
;
1058 static char *shadow_copy2_realpath(vfs_handle_struct
*handle
,
1062 char *stripped
= NULL
;
1064 char *result
= NULL
;
1065 char *inserted
= NULL
;
1066 char *inserted_to
, *inserted_end
;
1069 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1070 ×tamp
, &stripped
)) {
1073 if (timestamp
== 0) {
1074 return SMB_VFS_NEXT_REALPATH(handle
, fname
);
1077 tmp
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1082 result
= SMB_VFS_NEXT_REALPATH(handle
, tmp
);
1083 if (result
== NULL
) {
1088 * Take away what we've inserted. This removes the @GMT-thingy
1089 * completely, but will give a path under the share root.
1091 inserted
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
1092 if (inserted
== NULL
) {
1095 inserted_to
= strstr_m(result
, inserted
);
1096 if (inserted_to
== NULL
) {
1097 DEBUG(2, ("SMB_VFS_NEXT_REALPATH removed %s\n", inserted
));
1100 inserted_end
= inserted_to
+ talloc_get_size(inserted
) - 1;
1101 memmove(inserted_to
, inserted_end
, strlen(inserted_end
)+1);
1104 saved_errno
= errno
;
1105 TALLOC_FREE(inserted
);
1107 TALLOC_FREE(stripped
);
1108 errno
= saved_errno
;
1113 * Check whether a given directory contains a
1114 * snapshot directory as direct subdirectory.
1115 * If yes, return the path of the snapshot-subdir,
1116 * otherwise return NULL.
1118 static char *have_snapdir(struct vfs_handle_struct
*handle
,
1121 struct smb_filename smb_fname
;
1123 struct shadow_copy2_config
*config
;
1125 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1128 ZERO_STRUCT(smb_fname
);
1129 smb_fname
.base_name
= talloc_asprintf(talloc_tos(), "%s/%s",
1130 path
, config
->snapdir
);
1131 if (smb_fname
.base_name
== NULL
) {
1135 ret
= SMB_VFS_NEXT_STAT(handle
, &smb_fname
);
1136 if ((ret
== 0) && (S_ISDIR(smb_fname
.st
.st_ex_mode
))) {
1137 return smb_fname
.base_name
;
1139 TALLOC_FREE(smb_fname
.base_name
);
1144 * Find the snapshot directory (if any) for the given
1145 * filename (which is relative to the share).
1147 static const char *shadow_copy2_find_snapdir(TALLOC_CTX
*mem_ctx
,
1148 struct vfs_handle_struct
*handle
,
1149 struct smb_filename
*smb_fname
)
1152 const char *snapdir
;
1153 struct shadow_copy2_config
*config
;
1155 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1159 * If the non-snapdisrseverywhere mode, we should not search!
1161 if (!config
->snapdirseverywhere
) {
1162 return config
->snapshot_basepath
;
1165 path
= talloc_asprintf(mem_ctx
, "%s/%s",
1166 handle
->conn
->connectpath
,
1167 smb_fname
->base_name
);
1172 snapdir
= have_snapdir(handle
, path
);
1173 if (snapdir
!= NULL
) {
1178 while ((p
= strrchr(path
, '/')) && (p
> path
)) {
1182 snapdir
= have_snapdir(handle
, path
);
1183 if (snapdir
!= NULL
) {
1192 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct
*handle
,
1194 char *gmt
, size_t gmt_len
)
1196 struct tm timestamp
;
1198 unsigned long int timestamp_long
;
1200 struct shadow_copy2_config
*config
;
1202 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1205 fmt
= config
->gmt_format
;
1207 ZERO_STRUCT(timestamp
);
1208 if (config
->use_sscanf
) {
1209 if (sscanf(name
, fmt
, ×tamp_long
) != 1) {
1210 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1211 "no sscanf match %s: %s\n",
1215 timestamp_t
= timestamp_long
;
1216 gmtime_r(×tamp_t
, ×tamp
);
1218 if (strptime(name
, fmt
, ×tamp
) == NULL
) {
1219 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1220 "no match %s: %s\n",
1224 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1227 if (config
->use_localtime
) {
1228 timestamp
.tm_isdst
= -1;
1229 timestamp_t
= mktime(×tamp
);
1230 gmtime_r(×tamp_t
, ×tamp
);
1234 strftime(gmt
, gmt_len
, GMT_FORMAT
, ×tamp
);
1238 static int shadow_copy2_label_cmp_asc(const void *x
, const void *y
)
1240 return strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1243 static int shadow_copy2_label_cmp_desc(const void *x
, const void *y
)
1245 return -strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1249 sort the shadow copy data in ascending or descending order
1251 static void shadow_copy2_sort_data(vfs_handle_struct
*handle
,
1252 struct shadow_copy_data
*shadow_copy2_data
)
1254 int (*cmpfunc
)(const void *, const void *);
1256 struct shadow_copy2_config
*config
;
1258 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1261 sort
= config
->sort_order
;
1266 if (strcmp(sort
, "asc") == 0) {
1267 cmpfunc
= shadow_copy2_label_cmp_asc
;
1268 } else if (strcmp(sort
, "desc") == 0) {
1269 cmpfunc
= shadow_copy2_label_cmp_desc
;
1274 if (shadow_copy2_data
&& shadow_copy2_data
->num_volumes
> 0 &&
1275 shadow_copy2_data
->labels
)
1277 TYPESAFE_QSORT(shadow_copy2_data
->labels
,
1278 shadow_copy2_data
->num_volumes
,
1283 static int shadow_copy2_get_shadow_copy_data(
1284 vfs_handle_struct
*handle
, files_struct
*fsp
,
1285 struct shadow_copy_data
*shadow_copy2_data
,
1289 const char *snapdir
;
1291 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1293 snapdir
= shadow_copy2_find_snapdir(tmp_ctx
, handle
, fsp
->fsp_name
);
1294 if (snapdir
== NULL
) {
1295 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1296 handle
->conn
->connectpath
));
1298 talloc_free(tmp_ctx
);
1302 p
= SMB_VFS_NEXT_OPENDIR(handle
, snapdir
, NULL
, 0);
1305 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1306 " - %s\n", snapdir
, strerror(errno
)));
1307 talloc_free(tmp_ctx
);
1312 shadow_copy2_data
->num_volumes
= 0;
1313 shadow_copy2_data
->labels
= NULL
;
1315 while ((d
= SMB_VFS_NEXT_READDIR(handle
, p
, NULL
))) {
1316 char snapshot
[GMT_NAME_LEN
+1];
1317 SHADOW_COPY_LABEL
*tlabels
;
1320 * ignore names not of the right form in the snapshot
1323 if (!shadow_copy2_snapshot_to_gmt(
1325 snapshot
, sizeof(snapshot
))) {
1327 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1328 "ignoring %s\n", d
->d_name
));
1331 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1332 d
->d_name
, snapshot
));
1335 /* the caller doesn't want the labels */
1336 shadow_copy2_data
->num_volumes
++;
1340 tlabels
= talloc_realloc(shadow_copy2_data
,
1341 shadow_copy2_data
->labels
,
1343 shadow_copy2_data
->num_volumes
+1);
1344 if (tlabels
== NULL
) {
1345 DEBUG(0,("shadow_copy2: out of memory\n"));
1346 SMB_VFS_NEXT_CLOSEDIR(handle
, p
);
1347 talloc_free(tmp_ctx
);
1351 strlcpy(tlabels
[shadow_copy2_data
->num_volumes
], snapshot
,
1354 shadow_copy2_data
->num_volumes
++;
1355 shadow_copy2_data
->labels
= tlabels
;
1358 SMB_VFS_NEXT_CLOSEDIR(handle
,p
);
1360 shadow_copy2_sort_data(handle
, shadow_copy2_data
);
1362 talloc_free(tmp_ctx
);
1366 static NTSTATUS
shadow_copy2_fget_nt_acl(vfs_handle_struct
*handle
,
1367 struct files_struct
*fsp
,
1368 uint32 security_info
,
1369 TALLOC_CTX
*mem_ctx
,
1370 struct security_descriptor
**ppdesc
)
1377 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
1378 fsp
->fsp_name
->base_name
,
1379 ×tamp
, &stripped
)) {
1380 return map_nt_error_from_unix(errno
);
1382 if (timestamp
== 0) {
1383 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1387 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1388 TALLOC_FREE(stripped
);
1390 return map_nt_error_from_unix(errno
);
1392 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1398 static NTSTATUS
shadow_copy2_get_nt_acl(vfs_handle_struct
*handle
,
1400 uint32 security_info
,
1401 TALLOC_CTX
*mem_ctx
,
1402 struct security_descriptor
**ppdesc
)
1409 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1410 ×tamp
, &stripped
)) {
1411 return map_nt_error_from_unix(errno
);
1413 if (timestamp
== 0) {
1414 return SMB_VFS_NEXT_GET_NT_ACL(handle
, fname
, security_info
,
1417 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1418 TALLOC_FREE(stripped
);
1420 return map_nt_error_from_unix(errno
);
1422 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1428 static int shadow_copy2_mkdir(vfs_handle_struct
*handle
,
1429 const char *fname
, mode_t mode
)
1433 int ret
, saved_errno
;
1436 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1437 ×tamp
, &stripped
)) {
1440 if (timestamp
== 0) {
1441 return SMB_VFS_NEXT_MKDIR(handle
, fname
, mode
);
1443 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1444 TALLOC_FREE(stripped
);
1448 ret
= SMB_VFS_NEXT_MKDIR(handle
, conv
, mode
);
1449 saved_errno
= errno
;
1451 errno
= saved_errno
;
1455 static int shadow_copy2_rmdir(vfs_handle_struct
*handle
, const char *fname
)
1459 int ret
, saved_errno
;
1462 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1463 ×tamp
, &stripped
)) {
1466 if (timestamp
== 0) {
1467 return SMB_VFS_NEXT_RMDIR(handle
, fname
);
1469 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1470 TALLOC_FREE(stripped
);
1474 ret
= SMB_VFS_NEXT_RMDIR(handle
, conv
);
1475 saved_errno
= errno
;
1477 errno
= saved_errno
;
1481 static int shadow_copy2_chflags(vfs_handle_struct
*handle
, const char *fname
,
1486 int ret
, saved_errno
;
1489 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1490 ×tamp
, &stripped
)) {
1493 if (timestamp
== 0) {
1494 return SMB_VFS_NEXT_CHFLAGS(handle
, fname
, flags
);
1496 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1497 TALLOC_FREE(stripped
);
1501 ret
= SMB_VFS_NEXT_CHFLAGS(handle
, conv
, flags
);
1502 saved_errno
= errno
;
1504 errno
= saved_errno
;
1508 static ssize_t
shadow_copy2_getxattr(vfs_handle_struct
*handle
,
1509 const char *fname
, const char *aname
,
1510 void *value
, size_t size
)
1518 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1519 ×tamp
, &stripped
)) {
1522 if (timestamp
== 0) {
1523 return SMB_VFS_NEXT_GETXATTR(handle
, fname
, aname
, value
,
1526 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1527 TALLOC_FREE(stripped
);
1531 ret
= SMB_VFS_NEXT_GETXATTR(handle
, conv
, aname
, value
, size
);
1532 saved_errno
= errno
;
1534 errno
= saved_errno
;
1538 static ssize_t
shadow_copy2_listxattr(struct vfs_handle_struct
*handle
,
1540 char *list
, size_t size
)
1548 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1549 ×tamp
, &stripped
)) {
1552 if (timestamp
== 0) {
1553 return SMB_VFS_NEXT_LISTXATTR(handle
, fname
, list
, size
);
1555 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1556 TALLOC_FREE(stripped
);
1560 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, conv
, list
, size
);
1561 saved_errno
= errno
;
1563 errno
= saved_errno
;
1567 static int shadow_copy2_removexattr(vfs_handle_struct
*handle
,
1568 const char *fname
, const char *aname
)
1572 int ret
, saved_errno
;
1575 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1576 ×tamp
, &stripped
)) {
1579 if (timestamp
== 0) {
1580 return SMB_VFS_NEXT_REMOVEXATTR(handle
, fname
, aname
);
1582 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1583 TALLOC_FREE(stripped
);
1587 ret
= SMB_VFS_NEXT_REMOVEXATTR(handle
, conv
, aname
);
1588 saved_errno
= errno
;
1590 errno
= saved_errno
;
1594 static int shadow_copy2_setxattr(struct vfs_handle_struct
*handle
,
1596 const char *aname
, const void *value
,
1597 size_t size
, int flags
)
1605 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1606 ×tamp
, &stripped
)) {
1609 if (timestamp
== 0) {
1610 return SMB_VFS_NEXT_SETXATTR(handle
, fname
, aname
, value
, size
,
1613 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1614 TALLOC_FREE(stripped
);
1618 ret
= SMB_VFS_NEXT_SETXATTR(handle
, conv
, aname
, value
, size
, flags
);
1619 saved_errno
= errno
;
1621 errno
= saved_errno
;
1625 static int shadow_copy2_chmod_acl(vfs_handle_struct
*handle
,
1626 const char *fname
, mode_t mode
)
1634 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1635 ×tamp
, &stripped
)) {
1638 if (timestamp
== 0) {
1639 return SMB_VFS_NEXT_CHMOD_ACL(handle
, fname
, mode
);
1641 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1642 TALLOC_FREE(stripped
);
1646 ret
= SMB_VFS_NEXT_CHMOD_ACL(handle
, conv
, mode
);
1647 saved_errno
= errno
;
1649 errno
= saved_errno
;
1653 static int shadow_copy2_get_real_filename(struct vfs_handle_struct
*handle
,
1656 TALLOC_CTX
*mem_ctx
,
1665 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1666 ×tamp
, &stripped
)) {
1669 if (timestamp
== 0) {
1670 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
1671 mem_ctx
, found_name
);
1673 if (stripped
[0] == '\0') {
1674 *found_name
= talloc_strdup(mem_ctx
, name
);
1675 if (*found_name
== NULL
) {
1681 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1682 TALLOC_FREE(stripped
);
1686 ret
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, conv
, name
,
1687 mem_ctx
, found_name
);
1688 saved_errno
= errno
;
1690 errno
= saved_errno
;
1694 static uint64_t shadow_copy2_disk_free(vfs_handle_struct
*handle
,
1695 const char *path
, bool small_query
,
1696 uint64_t *bsize
, uint64_t *dfree
,
1705 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1706 ×tamp
, &stripped
)) {
1709 if (timestamp
== 0) {
1710 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1711 bsize
, dfree
, dsize
);
1714 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1715 TALLOC_FREE(stripped
);
1720 ret
= SMB_VFS_NEXT_DISK_FREE(handle
, conv
, small_query
, bsize
, dfree
,
1723 saved_errno
= errno
;
1725 errno
= saved_errno
;
1730 static int shadow_copy2_connect(struct vfs_handle_struct
*handle
,
1731 const char *service
, const char *user
)
1733 struct shadow_copy2_config
*config
;
1735 const char *snapdir
;
1736 const char *gmt_format
;
1737 const char *sort_order
;
1738 const char *basedir
;
1739 const char *mount_point
;
1741 DEBUG(10, (__location__
": cnum[%u], connectpath[%s]\n",
1742 (unsigned)handle
->conn
->cnum
,
1743 handle
->conn
->connectpath
));
1745 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1750 config
= talloc_zero(handle
->conn
, struct shadow_copy2_config
);
1751 if (config
== NULL
) {
1752 DEBUG(0, ("talloc_zero() failed\n"));
1757 gmt_format
= lp_parm_const_string(SNUM(handle
->conn
),
1760 config
->gmt_format
= talloc_strdup(config
, gmt_format
);
1761 if (config
->gmt_format
== NULL
) {
1762 DEBUG(0, ("talloc_strdup() failed\n"));
1767 config
->use_sscanf
= lp_parm_bool(SNUM(handle
->conn
),
1768 "shadow", "sscanf", false);
1770 config
->use_localtime
= lp_parm_bool(SNUM(handle
->conn
),
1771 "shadow", "localtime",
1774 snapdir
= lp_parm_const_string(SNUM(handle
->conn
),
1775 "shadow", "snapdir",
1777 config
->snapdir
= talloc_strdup(config
, snapdir
);
1778 if (config
->snapdir
== NULL
) {
1779 DEBUG(0, ("talloc_strdup() failed\n"));
1784 config
->snapdirseverywhere
= lp_parm_bool(SNUM(handle
->conn
),
1786 "snapdirseverywhere",
1789 config
->crossmountpoints
= lp_parm_bool(SNUM(handle
->conn
),
1790 "shadow", "crossmountpoints",
1793 config
->fixinodes
= lp_parm_bool(SNUM(handle
->conn
),
1794 "shadow", "fixinodes",
1797 sort_order
= lp_parm_const_string(SNUM(handle
->conn
),
1798 "shadow", "sort", "desc");
1799 config
->sort_order
= talloc_strdup(config
, sort_order
);
1800 if (config
->sort_order
== NULL
) {
1801 DEBUG(0, ("talloc_strdup() failed\n"));
1806 mount_point
= lp_parm_const_string(SNUM(handle
->conn
),
1807 "shadow", "mountpoint", NULL
);
1808 if (mount_point
!= NULL
) {
1809 if (mount_point
[0] != '/') {
1810 DEBUG(1, (__location__
" Warning: 'mountpoint' is "
1811 "relative ('%s'), but it has to be an "
1812 "absolute path. Ignoring provided value.\n",
1817 p
= strstr(handle
->conn
->connectpath
, mount_point
);
1818 if (p
!= handle
->conn
->connectpath
) {
1819 DEBUG(1, ("Warning: mount_point (%s) is not a "
1820 "subdirectory of the share root "
1821 "(%s). Ignoring provided value.\n",
1823 handle
->conn
->connectpath
));
1829 if (mount_point
!= NULL
) {
1830 config
->mount_point
= talloc_strdup(config
, mount_point
);
1831 if (config
->mount_point
== NULL
) {
1832 DEBUG(0, (__location__
" talloc_strdup() failed\n"));
1836 config
->mount_point
= shadow_copy2_find_mount_point(config
,
1838 if (config
->mount_point
== NULL
) {
1839 DEBUG(0, (__location__
": shadow_copy2_find_mount_point"
1840 " failed: %s\n", strerror(errno
)));
1845 basedir
= lp_parm_const_string(SNUM(handle
->conn
),
1846 "shadow", "basedir", NULL
);
1848 if (basedir
!= NULL
) {
1849 if (basedir
[0] != '/') {
1850 DEBUG(1, (__location__
" Warning: 'basedir' is "
1851 "relative ('%s'), but it has to be an "
1852 "absolute path. Disabling basedir.\n",
1856 p
= strstr(basedir
, config
->mount_point
);
1858 DEBUG(1, ("Warning: basedir (%s) is not a "
1859 "subdirectory of the share root's "
1860 "mount point (%s). "
1861 "Disabling basedir\n",
1862 basedir
, config
->mount_point
));
1864 config
->basedir
= talloc_strdup(config
,
1866 if (config
->basedir
== NULL
) {
1867 DEBUG(0, ("talloc_strdup() failed\n"));
1875 if (config
->snapdirseverywhere
&& config
->basedir
!= NULL
) {
1876 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1877 "with 'snapdirseverywhere'. Disabling basedir.\n"));
1878 TALLOC_FREE(config
->basedir
);
1881 if (config
->crossmountpoints
&& config
->basedir
!= NULL
) {
1882 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1883 "with 'crossmountpoints'. Disabling basedir.\n"));
1884 TALLOC_FREE(config
->basedir
);
1887 if (config
->basedir
== NULL
) {
1888 config
->basedir
= config
->mount_point
;
1891 if (strlen(config
->basedir
) != strlen(handle
->conn
->connectpath
)) {
1892 config
->rel_connectpath
= talloc_strdup(config
,
1893 handle
->conn
->connectpath
+ strlen(config
->basedir
));
1894 if (config
->rel_connectpath
== NULL
) {
1895 DEBUG(0, ("talloc_strdup() failed\n"));
1901 if (config
->snapdir
[0] == '/') {
1902 config
->snapdir_absolute
= true;
1904 if (config
->snapdirseverywhere
== true) {
1905 DEBUG(1, (__location__
" Warning: An absolute snapdir "
1906 "is incompatible with 'snapdirseverywhere', "
1907 "setting 'snapdirseverywhere' to false.\n"));
1908 config
->snapdirseverywhere
= false;
1911 if (config
->crossmountpoints
== true) {
1912 DEBUG(1, (__location__
" Warning: 'crossmountpoints' "
1913 "is not supported with an absolute snapdir. "
1914 "Disabling it.\n"));
1915 config
->crossmountpoints
= false;
1918 config
->snapshot_basepath
= config
->snapdir
;
1920 config
->snapshot_basepath
= talloc_asprintf(config
, "%s/%s",
1921 config
->mount_point
, config
->snapdir
);
1922 if (config
->snapshot_basepath
== NULL
) {
1923 DEBUG(0, ("talloc_asprintf() failed\n"));
1929 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
1930 " share root: '%s'\n"
1932 " mountpoint: '%s'\n"
1933 " rel share root: '%s'\n"
1935 " snapshot base path: '%s'\n"
1938 " snapdirs everywhere: %s\n"
1939 " cross mountpoints: %s\n"
1943 handle
->conn
->connectpath
,
1945 config
->mount_point
,
1946 config
->rel_connectpath
,
1948 config
->snapshot_basepath
,
1950 config
->use_sscanf
? "yes" : "no",
1951 config
->snapdirseverywhere
? "yes" : "no",
1952 config
->crossmountpoints
? "yes" : "no",
1953 config
->fixinodes
? "yes" : "no",
1958 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1959 NULL
, struct shadow_copy2_config
,
1965 static struct vfs_fn_pointers vfs_shadow_copy2_fns
= {
1966 .connect_fn
= shadow_copy2_connect
,
1967 .opendir_fn
= shadow_copy2_opendir
,
1968 .disk_free_fn
= shadow_copy2_disk_free
,
1969 .rename_fn
= shadow_copy2_rename
,
1970 .link_fn
= shadow_copy2_link
,
1971 .symlink_fn
= shadow_copy2_symlink
,
1972 .stat_fn
= shadow_copy2_stat
,
1973 .lstat_fn
= shadow_copy2_lstat
,
1974 .fstat_fn
= shadow_copy2_fstat
,
1975 .open_fn
= shadow_copy2_open
,
1976 .unlink_fn
= shadow_copy2_unlink
,
1977 .chmod_fn
= shadow_copy2_chmod
,
1978 .chown_fn
= shadow_copy2_chown
,
1979 .chdir_fn
= shadow_copy2_chdir
,
1980 .ntimes_fn
= shadow_copy2_ntimes
,
1981 .readlink_fn
= shadow_copy2_readlink
,
1982 .mknod_fn
= shadow_copy2_mknod
,
1983 .realpath_fn
= shadow_copy2_realpath
,
1984 .get_nt_acl_fn
= shadow_copy2_get_nt_acl
,
1985 .fget_nt_acl_fn
= shadow_copy2_fget_nt_acl
,
1986 .get_shadow_copy_data_fn
= shadow_copy2_get_shadow_copy_data
,
1987 .mkdir_fn
= shadow_copy2_mkdir
,
1988 .rmdir_fn
= shadow_copy2_rmdir
,
1989 .getxattr_fn
= shadow_copy2_getxattr
,
1990 .listxattr_fn
= shadow_copy2_listxattr
,
1991 .removexattr_fn
= shadow_copy2_removexattr
,
1992 .setxattr_fn
= shadow_copy2_setxattr
,
1993 .chmod_acl_fn
= shadow_copy2_chmod_acl
,
1994 .chflags_fn
= shadow_copy2_chflags
,
1995 .get_real_filename_fn
= shadow_copy2_get_real_filename
,
1998 NTSTATUS
vfs_shadow_copy2_init(void);
1999 NTSTATUS
vfs_shadow_copy2_init(void)
2001 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
2002 "shadow_copy2", &vfs_shadow_copy2_fns
);