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
;
860 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
861 smb_fname
->base_name
,
862 ×tamp
, &stripped
)) {
865 if (timestamp
== 0) {
866 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
868 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
873 conv
->base_name
= shadow_copy2_convert(
874 conv
, handle
, stripped
, timestamp
);
875 TALLOC_FREE(stripped
);
876 if (conv
->base_name
== NULL
) {
879 ret
= SMB_VFS_NEXT_UNLINK(handle
, conv
);
886 static int shadow_copy2_chmod(vfs_handle_struct
*handle
, const char *fname
,
891 int ret
, saved_errno
;
894 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
895 ×tamp
, &stripped
)) {
898 if (timestamp
== 0) {
899 return SMB_VFS_NEXT_CHMOD(handle
, fname
, mode
);
901 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
902 TALLOC_FREE(stripped
);
906 ret
= SMB_VFS_NEXT_CHMOD(handle
, conv
, mode
);
913 static int shadow_copy2_chown(vfs_handle_struct
*handle
, const char *fname
,
914 uid_t uid
, gid_t gid
)
918 int ret
, saved_errno
;
921 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
922 ×tamp
, &stripped
)) {
925 if (timestamp
== 0) {
926 return SMB_VFS_NEXT_CHOWN(handle
, fname
, uid
, gid
);
928 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
929 TALLOC_FREE(stripped
);
933 ret
= SMB_VFS_NEXT_CHOWN(handle
, conv
, uid
, gid
);
940 static int shadow_copy2_chdir(vfs_handle_struct
*handle
,
945 int ret
, saved_errno
;
948 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
949 ×tamp
, &stripped
)) {
952 if (timestamp
== 0) {
953 return SMB_VFS_NEXT_CHDIR(handle
, fname
);
955 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
956 TALLOC_FREE(stripped
);
960 ret
= SMB_VFS_NEXT_CHDIR(handle
, conv
);
967 static int shadow_copy2_ntimes(vfs_handle_struct
*handle
,
968 const struct smb_filename
*smb_fname
,
969 struct smb_file_time
*ft
)
973 int ret
, saved_errno
;
974 struct smb_filename
*conv
;
976 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
977 smb_fname
->base_name
,
978 ×tamp
, &stripped
)) {
981 if (timestamp
== 0) {
982 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
984 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
989 conv
->base_name
= shadow_copy2_convert(
990 conv
, handle
, stripped
, timestamp
);
991 TALLOC_FREE(stripped
);
992 if (conv
->base_name
== NULL
) {
995 ret
= SMB_VFS_NEXT_NTIMES(handle
, conv
, ft
);
1002 static int shadow_copy2_readlink(vfs_handle_struct
*handle
,
1003 const char *fname
, char *buf
, size_t bufsiz
)
1007 int ret
, saved_errno
;
1010 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1011 ×tamp
, &stripped
)) {
1014 if (timestamp
== 0) {
1015 return SMB_VFS_NEXT_READLINK(handle
, fname
, buf
, bufsiz
);
1017 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1018 TALLOC_FREE(stripped
);
1022 ret
= SMB_VFS_NEXT_READLINK(handle
, conv
, buf
, bufsiz
);
1023 saved_errno
= errno
;
1025 errno
= saved_errno
;
1029 static int shadow_copy2_mknod(vfs_handle_struct
*handle
,
1030 const char *fname
, mode_t mode
, SMB_DEV_T dev
)
1034 int ret
, saved_errno
;
1037 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1038 ×tamp
, &stripped
)) {
1041 if (timestamp
== 0) {
1042 return SMB_VFS_NEXT_MKNOD(handle
, fname
, mode
, dev
);
1044 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1045 TALLOC_FREE(stripped
);
1049 ret
= SMB_VFS_NEXT_MKNOD(handle
, conv
, mode
, dev
);
1050 saved_errno
= errno
;
1052 errno
= saved_errno
;
1056 static char *shadow_copy2_realpath(vfs_handle_struct
*handle
,
1060 char *stripped
= NULL
;
1062 char *result
= NULL
;
1063 char *inserted
= NULL
;
1064 char *inserted_to
, *inserted_end
;
1067 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1068 ×tamp
, &stripped
)) {
1071 if (timestamp
== 0) {
1072 return SMB_VFS_NEXT_REALPATH(handle
, fname
);
1075 tmp
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1080 result
= SMB_VFS_NEXT_REALPATH(handle
, tmp
);
1081 if (result
== NULL
) {
1086 * Take away what we've inserted. This removes the @GMT-thingy
1087 * completely, but will give a path under the share root.
1089 inserted
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
1090 if (inserted
== NULL
) {
1093 inserted_to
= strstr_m(result
, inserted
);
1094 if (inserted_to
== NULL
) {
1095 DEBUG(2, ("SMB_VFS_NEXT_REALPATH removed %s\n", inserted
));
1098 inserted_end
= inserted_to
+ talloc_get_size(inserted
) - 1;
1099 memmove(inserted_to
, inserted_end
, strlen(inserted_end
)+1);
1102 saved_errno
= errno
;
1103 TALLOC_FREE(inserted
);
1105 TALLOC_FREE(stripped
);
1106 errno
= saved_errno
;
1111 * Check whether a given directory contains a
1112 * snapshot directory as direct subdirectory.
1113 * If yes, return the path of the snapshot-subdir,
1114 * otherwise return NULL.
1116 static char *have_snapdir(struct vfs_handle_struct
*handle
,
1119 struct smb_filename smb_fname
;
1121 struct shadow_copy2_config
*config
;
1123 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1126 ZERO_STRUCT(smb_fname
);
1127 smb_fname
.base_name
= talloc_asprintf(talloc_tos(), "%s/%s",
1128 path
, config
->snapdir
);
1129 if (smb_fname
.base_name
== NULL
) {
1133 ret
= SMB_VFS_NEXT_STAT(handle
, &smb_fname
);
1134 if ((ret
== 0) && (S_ISDIR(smb_fname
.st
.st_ex_mode
))) {
1135 return smb_fname
.base_name
;
1137 TALLOC_FREE(smb_fname
.base_name
);
1142 * Find the snapshot directory (if any) for the given
1143 * filename (which is relative to the share).
1145 static const char *shadow_copy2_find_snapdir(TALLOC_CTX
*mem_ctx
,
1146 struct vfs_handle_struct
*handle
,
1147 struct smb_filename
*smb_fname
)
1150 const char *snapdir
;
1151 struct shadow_copy2_config
*config
;
1153 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1157 * If the non-snapdisrseverywhere mode, we should not search!
1159 if (!config
->snapdirseverywhere
) {
1160 return config
->snapshot_basepath
;
1163 path
= talloc_asprintf(mem_ctx
, "%s/%s",
1164 handle
->conn
->connectpath
,
1165 smb_fname
->base_name
);
1170 snapdir
= have_snapdir(handle
, path
);
1171 if (snapdir
!= NULL
) {
1176 while ((p
= strrchr(path
, '/')) && (p
> path
)) {
1180 snapdir
= have_snapdir(handle
, path
);
1181 if (snapdir
!= NULL
) {
1190 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct
*handle
,
1192 char *gmt
, size_t gmt_len
)
1194 struct tm timestamp
;
1196 unsigned long int timestamp_long
;
1198 struct shadow_copy2_config
*config
;
1200 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1203 fmt
= config
->gmt_format
;
1205 ZERO_STRUCT(timestamp
);
1206 if (config
->use_sscanf
) {
1207 if (sscanf(name
, fmt
, ×tamp_long
) != 1) {
1208 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1209 "no sscanf match %s: %s\n",
1213 timestamp_t
= timestamp_long
;
1214 gmtime_r(×tamp_t
, ×tamp
);
1216 if (strptime(name
, fmt
, ×tamp
) == NULL
) {
1217 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1218 "no match %s: %s\n",
1222 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1225 if (config
->use_localtime
) {
1226 timestamp
.tm_isdst
= -1;
1227 timestamp_t
= mktime(×tamp
);
1228 gmtime_r(×tamp_t
, ×tamp
);
1232 strftime(gmt
, gmt_len
, GMT_FORMAT
, ×tamp
);
1236 static int shadow_copy2_label_cmp_asc(const void *x
, const void *y
)
1238 return strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1241 static int shadow_copy2_label_cmp_desc(const void *x
, const void *y
)
1243 return -strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1247 sort the shadow copy data in ascending or descending order
1249 static void shadow_copy2_sort_data(vfs_handle_struct
*handle
,
1250 struct shadow_copy_data
*shadow_copy2_data
)
1252 int (*cmpfunc
)(const void *, const void *);
1254 struct shadow_copy2_config
*config
;
1256 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1259 sort
= config
->sort_order
;
1264 if (strcmp(sort
, "asc") == 0) {
1265 cmpfunc
= shadow_copy2_label_cmp_asc
;
1266 } else if (strcmp(sort
, "desc") == 0) {
1267 cmpfunc
= shadow_copy2_label_cmp_desc
;
1272 if (shadow_copy2_data
&& shadow_copy2_data
->num_volumes
> 0 &&
1273 shadow_copy2_data
->labels
)
1275 TYPESAFE_QSORT(shadow_copy2_data
->labels
,
1276 shadow_copy2_data
->num_volumes
,
1281 static int shadow_copy2_get_shadow_copy_data(
1282 vfs_handle_struct
*handle
, files_struct
*fsp
,
1283 struct shadow_copy_data
*shadow_copy2_data
,
1287 const char *snapdir
;
1289 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1291 snapdir
= shadow_copy2_find_snapdir(tmp_ctx
, handle
, fsp
->fsp_name
);
1292 if (snapdir
== NULL
) {
1293 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1294 handle
->conn
->connectpath
));
1296 talloc_free(tmp_ctx
);
1300 p
= SMB_VFS_NEXT_OPENDIR(handle
, snapdir
, NULL
, 0);
1303 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1304 " - %s\n", snapdir
, strerror(errno
)));
1305 talloc_free(tmp_ctx
);
1310 shadow_copy2_data
->num_volumes
= 0;
1311 shadow_copy2_data
->labels
= NULL
;
1313 while ((d
= SMB_VFS_NEXT_READDIR(handle
, p
, NULL
))) {
1314 char snapshot
[GMT_NAME_LEN
+1];
1315 SHADOW_COPY_LABEL
*tlabels
;
1318 * ignore names not of the right form in the snapshot
1321 if (!shadow_copy2_snapshot_to_gmt(
1323 snapshot
, sizeof(snapshot
))) {
1325 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1326 "ignoring %s\n", d
->d_name
));
1329 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1330 d
->d_name
, snapshot
));
1333 /* the caller doesn't want the labels */
1334 shadow_copy2_data
->num_volumes
++;
1338 tlabels
= talloc_realloc(shadow_copy2_data
,
1339 shadow_copy2_data
->labels
,
1341 shadow_copy2_data
->num_volumes
+1);
1342 if (tlabels
== NULL
) {
1343 DEBUG(0,("shadow_copy2: out of memory\n"));
1344 SMB_VFS_NEXT_CLOSEDIR(handle
, p
);
1345 talloc_free(tmp_ctx
);
1349 strlcpy(tlabels
[shadow_copy2_data
->num_volumes
], snapshot
,
1352 shadow_copy2_data
->num_volumes
++;
1353 shadow_copy2_data
->labels
= tlabels
;
1356 SMB_VFS_NEXT_CLOSEDIR(handle
,p
);
1358 shadow_copy2_sort_data(handle
, shadow_copy2_data
);
1360 talloc_free(tmp_ctx
);
1364 static NTSTATUS
shadow_copy2_fget_nt_acl(vfs_handle_struct
*handle
,
1365 struct files_struct
*fsp
,
1366 uint32 security_info
,
1367 TALLOC_CTX
*mem_ctx
,
1368 struct security_descriptor
**ppdesc
)
1375 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
1376 fsp
->fsp_name
->base_name
,
1377 ×tamp
, &stripped
)) {
1378 return map_nt_error_from_unix(errno
);
1380 if (timestamp
== 0) {
1381 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1385 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1386 TALLOC_FREE(stripped
);
1388 return map_nt_error_from_unix(errno
);
1390 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1396 static NTSTATUS
shadow_copy2_get_nt_acl(vfs_handle_struct
*handle
,
1398 uint32 security_info
,
1399 TALLOC_CTX
*mem_ctx
,
1400 struct security_descriptor
**ppdesc
)
1407 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1408 ×tamp
, &stripped
)) {
1409 return map_nt_error_from_unix(errno
);
1411 if (timestamp
== 0) {
1412 return SMB_VFS_NEXT_GET_NT_ACL(handle
, fname
, security_info
,
1415 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1416 TALLOC_FREE(stripped
);
1418 return map_nt_error_from_unix(errno
);
1420 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1426 static int shadow_copy2_mkdir(vfs_handle_struct
*handle
,
1427 const char *fname
, mode_t mode
)
1431 int ret
, saved_errno
;
1434 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1435 ×tamp
, &stripped
)) {
1438 if (timestamp
== 0) {
1439 return SMB_VFS_NEXT_MKDIR(handle
, fname
, mode
);
1441 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1442 TALLOC_FREE(stripped
);
1446 ret
= SMB_VFS_NEXT_MKDIR(handle
, conv
, mode
);
1447 saved_errno
= errno
;
1449 errno
= saved_errno
;
1453 static int shadow_copy2_rmdir(vfs_handle_struct
*handle
, const char *fname
)
1457 int ret
, saved_errno
;
1460 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1461 ×tamp
, &stripped
)) {
1464 if (timestamp
== 0) {
1465 return SMB_VFS_NEXT_RMDIR(handle
, fname
);
1467 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1468 TALLOC_FREE(stripped
);
1472 ret
= SMB_VFS_NEXT_RMDIR(handle
, conv
);
1473 saved_errno
= errno
;
1475 errno
= saved_errno
;
1479 static int shadow_copy2_chflags(vfs_handle_struct
*handle
, const char *fname
,
1484 int ret
, saved_errno
;
1487 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1488 ×tamp
, &stripped
)) {
1491 if (timestamp
== 0) {
1492 return SMB_VFS_NEXT_CHFLAGS(handle
, fname
, flags
);
1494 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1495 TALLOC_FREE(stripped
);
1499 ret
= SMB_VFS_NEXT_CHFLAGS(handle
, conv
, flags
);
1500 saved_errno
= errno
;
1502 errno
= saved_errno
;
1506 static ssize_t
shadow_copy2_getxattr(vfs_handle_struct
*handle
,
1507 const char *fname
, const char *aname
,
1508 void *value
, size_t size
)
1516 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1517 ×tamp
, &stripped
)) {
1520 if (timestamp
== 0) {
1521 return SMB_VFS_NEXT_GETXATTR(handle
, fname
, aname
, value
,
1524 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1525 TALLOC_FREE(stripped
);
1529 ret
= SMB_VFS_NEXT_GETXATTR(handle
, conv
, aname
, value
, size
);
1530 saved_errno
= errno
;
1532 errno
= saved_errno
;
1536 static ssize_t
shadow_copy2_listxattr(struct vfs_handle_struct
*handle
,
1538 char *list
, size_t size
)
1546 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1547 ×tamp
, &stripped
)) {
1550 if (timestamp
== 0) {
1551 return SMB_VFS_NEXT_LISTXATTR(handle
, fname
, list
, size
);
1553 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1554 TALLOC_FREE(stripped
);
1558 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, conv
, list
, size
);
1559 saved_errno
= errno
;
1561 errno
= saved_errno
;
1565 static int shadow_copy2_removexattr(vfs_handle_struct
*handle
,
1566 const char *fname
, const char *aname
)
1570 int ret
, saved_errno
;
1573 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1574 ×tamp
, &stripped
)) {
1577 if (timestamp
== 0) {
1578 return SMB_VFS_NEXT_REMOVEXATTR(handle
, fname
, aname
);
1580 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1581 TALLOC_FREE(stripped
);
1585 ret
= SMB_VFS_NEXT_REMOVEXATTR(handle
, conv
, aname
);
1586 saved_errno
= errno
;
1588 errno
= saved_errno
;
1592 static int shadow_copy2_setxattr(struct vfs_handle_struct
*handle
,
1594 const char *aname
, const void *value
,
1595 size_t size
, int flags
)
1603 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1604 ×tamp
, &stripped
)) {
1607 if (timestamp
== 0) {
1608 return SMB_VFS_NEXT_SETXATTR(handle
, fname
, aname
, value
, size
,
1611 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1612 TALLOC_FREE(stripped
);
1616 ret
= SMB_VFS_NEXT_SETXATTR(handle
, conv
, aname
, value
, size
, flags
);
1617 saved_errno
= errno
;
1619 errno
= saved_errno
;
1623 static int shadow_copy2_chmod_acl(vfs_handle_struct
*handle
,
1624 const char *fname
, mode_t mode
)
1632 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1633 ×tamp
, &stripped
)) {
1636 if (timestamp
== 0) {
1637 return SMB_VFS_NEXT_CHMOD_ACL(handle
, fname
, mode
);
1639 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1640 TALLOC_FREE(stripped
);
1644 ret
= SMB_VFS_NEXT_CHMOD_ACL(handle
, conv
, mode
);
1645 saved_errno
= errno
;
1647 errno
= saved_errno
;
1651 static int shadow_copy2_get_real_filename(struct vfs_handle_struct
*handle
,
1654 TALLOC_CTX
*mem_ctx
,
1663 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1664 ×tamp
, &stripped
)) {
1667 if (timestamp
== 0) {
1668 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
1669 mem_ctx
, found_name
);
1671 if (stripped
[0] == '\0') {
1672 *found_name
= talloc_strdup(mem_ctx
, name
);
1673 if (*found_name
== NULL
) {
1679 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1680 TALLOC_FREE(stripped
);
1684 ret
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, conv
, name
,
1685 mem_ctx
, found_name
);
1686 saved_errno
= errno
;
1688 errno
= saved_errno
;
1692 static uint64_t shadow_copy2_disk_free(vfs_handle_struct
*handle
,
1693 const char *path
, bool small_query
,
1694 uint64_t *bsize
, uint64_t *dfree
,
1703 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1704 ×tamp
, &stripped
)) {
1707 if (timestamp
== 0) {
1708 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1709 bsize
, dfree
, dsize
);
1712 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1713 TALLOC_FREE(stripped
);
1718 ret
= SMB_VFS_NEXT_DISK_FREE(handle
, conv
, small_query
, bsize
, dfree
,
1721 saved_errno
= errno
;
1723 errno
= saved_errno
;
1728 static int shadow_copy2_connect(struct vfs_handle_struct
*handle
,
1729 const char *service
, const char *user
)
1731 struct shadow_copy2_config
*config
;
1733 const char *snapdir
;
1734 const char *gmt_format
;
1735 const char *sort_order
;
1736 const char *basedir
;
1737 const char *mount_point
;
1739 DEBUG(10, (__location__
": cnum[%u], connectpath[%s]\n",
1740 (unsigned)handle
->conn
->cnum
,
1741 handle
->conn
->connectpath
));
1743 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1748 config
= talloc_zero(handle
->conn
, struct shadow_copy2_config
);
1749 if (config
== NULL
) {
1750 DEBUG(0, ("talloc_zero() failed\n"));
1755 gmt_format
= lp_parm_const_string(SNUM(handle
->conn
),
1758 config
->gmt_format
= talloc_strdup(config
, gmt_format
);
1759 if (config
->gmt_format
== NULL
) {
1760 DEBUG(0, ("talloc_strdup() failed\n"));
1765 config
->use_sscanf
= lp_parm_bool(SNUM(handle
->conn
),
1766 "shadow", "sscanf", false);
1768 config
->use_localtime
= lp_parm_bool(SNUM(handle
->conn
),
1769 "shadow", "localtime",
1772 snapdir
= lp_parm_const_string(SNUM(handle
->conn
),
1773 "shadow", "snapdir",
1775 config
->snapdir
= talloc_strdup(config
, snapdir
);
1776 if (config
->snapdir
== NULL
) {
1777 DEBUG(0, ("talloc_strdup() failed\n"));
1782 config
->snapdirseverywhere
= lp_parm_bool(SNUM(handle
->conn
),
1784 "snapdirseverywhere",
1787 config
->crossmountpoints
= lp_parm_bool(SNUM(handle
->conn
),
1788 "shadow", "crossmountpoints",
1791 config
->fixinodes
= lp_parm_bool(SNUM(handle
->conn
),
1792 "shadow", "fixinodes",
1795 sort_order
= lp_parm_const_string(SNUM(handle
->conn
),
1796 "shadow", "sort", "desc");
1797 config
->sort_order
= talloc_strdup(config
, sort_order
);
1798 if (config
->sort_order
== NULL
) {
1799 DEBUG(0, ("talloc_strdup() failed\n"));
1804 mount_point
= lp_parm_const_string(SNUM(handle
->conn
),
1805 "shadow", "mountpoint", NULL
);
1806 if (mount_point
!= NULL
) {
1807 if (mount_point
[0] != '/') {
1808 DEBUG(1, (__location__
" Warning: 'mountpoint' is "
1809 "relative ('%s'), but it has to be an "
1810 "absolute path. Ignoring provided value.\n",
1815 p
= strstr(handle
->conn
->connectpath
, mount_point
);
1816 if (p
!= handle
->conn
->connectpath
) {
1817 DEBUG(1, ("Warning: mount_point (%s) is not a "
1818 "subdirectory of the share root "
1819 "(%s). Ignoring provided value.\n",
1821 handle
->conn
->connectpath
));
1827 if (mount_point
!= NULL
) {
1828 config
->mount_point
= talloc_strdup(config
, mount_point
);
1829 if (config
->mount_point
== NULL
) {
1830 DEBUG(0, (__location__
" talloc_strdup() failed\n"));
1834 config
->mount_point
= shadow_copy2_find_mount_point(config
,
1836 if (config
->mount_point
== NULL
) {
1837 DEBUG(0, (__location__
": shadow_copy2_find_mount_point"
1838 " failed: %s\n", strerror(errno
)));
1843 basedir
= lp_parm_const_string(SNUM(handle
->conn
),
1844 "shadow", "basedir", NULL
);
1846 if (basedir
!= NULL
) {
1847 if (basedir
[0] != '/') {
1848 DEBUG(1, (__location__
" Warning: 'basedir' is "
1849 "relative ('%s'), but it has to be an "
1850 "absolute path. Disabling basedir.\n",
1854 p
= strstr(basedir
, config
->mount_point
);
1856 DEBUG(1, ("Warning: basedir (%s) is not a "
1857 "subdirectory of the share root's "
1858 "mount point (%s). "
1859 "Disabling basedir\n",
1860 basedir
, config
->mount_point
));
1862 config
->basedir
= talloc_strdup(config
,
1864 if (config
->basedir
== NULL
) {
1865 DEBUG(0, ("talloc_strdup() failed\n"));
1873 if (config
->snapdirseverywhere
&& config
->basedir
!= NULL
) {
1874 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1875 "with 'snapdirseverywhere'. Disabling basedir.\n"));
1876 TALLOC_FREE(config
->basedir
);
1879 if (config
->crossmountpoints
&& config
->basedir
!= NULL
) {
1880 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1881 "with 'crossmountpoints'. Disabling basedir.\n"));
1882 TALLOC_FREE(config
->basedir
);
1885 if (config
->basedir
== NULL
) {
1886 config
->basedir
= config
->mount_point
;
1889 if (strlen(config
->basedir
) != strlen(handle
->conn
->connectpath
)) {
1890 config
->rel_connectpath
= talloc_strdup(config
,
1891 handle
->conn
->connectpath
+ strlen(config
->basedir
));
1892 if (config
->rel_connectpath
== NULL
) {
1893 DEBUG(0, ("talloc_strdup() failed\n"));
1899 if (config
->snapdir
[0] == '/') {
1900 config
->snapdir_absolute
= true;
1902 if (config
->snapdirseverywhere
== true) {
1903 DEBUG(1, (__location__
" Warning: An absolute snapdir "
1904 "is incompatible with 'snapdirseverywhere', "
1905 "setting 'snapdirseverywhere' to false.\n"));
1906 config
->snapdirseverywhere
= false;
1909 if (config
->crossmountpoints
== true) {
1910 DEBUG(1, (__location__
" Warning: 'crossmountpoints' "
1911 "is not supported with an absolute snapdir. "
1912 "Disabling it.\n"));
1913 config
->crossmountpoints
= false;
1916 config
->snapshot_basepath
= config
->snapdir
;
1918 config
->snapshot_basepath
= talloc_asprintf(config
, "%s/%s",
1919 config
->mount_point
, config
->snapdir
);
1920 if (config
->snapshot_basepath
== NULL
) {
1921 DEBUG(0, ("talloc_asprintf() failed\n"));
1927 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
1928 " share root: '%s'\n"
1930 " mountpoint: '%s'\n"
1931 " rel share root: '%s'\n"
1933 " snapshot base path: '%s'\n"
1936 " snapdirs everywhere: %s\n"
1937 " cross mountpoints: %s\n"
1941 handle
->conn
->connectpath
,
1943 config
->mount_point
,
1944 config
->rel_connectpath
,
1946 config
->snapshot_basepath
,
1948 config
->use_sscanf
? "yes" : "no",
1949 config
->snapdirseverywhere
? "yes" : "no",
1950 config
->crossmountpoints
? "yes" : "no",
1951 config
->fixinodes
? "yes" : "no",
1956 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1957 NULL
, struct shadow_copy2_config
,
1963 static struct vfs_fn_pointers vfs_shadow_copy2_fns
= {
1964 .connect_fn
= shadow_copy2_connect
,
1965 .opendir_fn
= shadow_copy2_opendir
,
1966 .disk_free_fn
= shadow_copy2_disk_free
,
1967 .rename_fn
= shadow_copy2_rename
,
1968 .link_fn
= shadow_copy2_link
,
1969 .symlink_fn
= shadow_copy2_symlink
,
1970 .stat_fn
= shadow_copy2_stat
,
1971 .lstat_fn
= shadow_copy2_lstat
,
1972 .fstat_fn
= shadow_copy2_fstat
,
1973 .open_fn
= shadow_copy2_open
,
1974 .unlink_fn
= shadow_copy2_unlink
,
1975 .chmod_fn
= shadow_copy2_chmod
,
1976 .chown_fn
= shadow_copy2_chown
,
1977 .chdir_fn
= shadow_copy2_chdir
,
1978 .ntimes_fn
= shadow_copy2_ntimes
,
1979 .readlink_fn
= shadow_copy2_readlink
,
1980 .mknod_fn
= shadow_copy2_mknod
,
1981 .realpath_fn
= shadow_copy2_realpath
,
1982 .get_nt_acl_fn
= shadow_copy2_get_nt_acl
,
1983 .fget_nt_acl_fn
= shadow_copy2_fget_nt_acl
,
1984 .get_shadow_copy_data_fn
= shadow_copy2_get_shadow_copy_data
,
1985 .mkdir_fn
= shadow_copy2_mkdir
,
1986 .rmdir_fn
= shadow_copy2_rmdir
,
1987 .getxattr_fn
= shadow_copy2_getxattr
,
1988 .listxattr_fn
= shadow_copy2_listxattr
,
1989 .removexattr_fn
= shadow_copy2_removexattr
,
1990 .setxattr_fn
= shadow_copy2_setxattr
,
1991 .chmod_acl_fn
= shadow_copy2_chmod_acl
,
1992 .chflags_fn
= shadow_copy2_chflags
,
1993 .get_real_filename_fn
= shadow_copy2_get_real_filename
,
1996 NTSTATUS
vfs_shadow_copy2_init(void);
1997 NTSTATUS
vfs_shadow_copy2_init(void)
1999 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
2000 "shadow_copy2", &vfs_shadow_copy2_fns
);