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"));
268 * The name consists of only the GMT token or the GMT
269 * token is at the end of the path. XP seems to send
270 * @GMT- at the end under certain circumstances even
271 * with a path prefix.
273 if (pstripped
!= NULL
) {
274 stripped
= talloc_strndup(mem_ctx
, name
, p
- name
);
275 if (stripped
== NULL
) {
278 *pstripped
= stripped
;
280 *ptimestamp
= timestamp
;
285 * It is not a complete path component, i.e. the path
286 * component continues after the gmt-token.
288 DEBUG(10, ("q[0] = %d\n", (int)q
[0]));
293 rest_len
= strlen(q
);
294 dst_len
= (p
-name
) + rest_len
;
296 if (config
->snapdirseverywhere
) {
299 insert
= shadow_copy2_insert_string(talloc_tos(), handle
,
301 if (insert
== NULL
) {
306 DEBUG(10, (__location__
": snapdirseverywhere mode.\n"
308 "insert string '%s'\n", name
, insert
));
310 have_insert
= (strstr(name
, insert
+1) != NULL
);
311 DEBUG(10, ("have_insert=%d, name=%s, insert+1=%s\n",
312 (int)have_insert
, name
, insert
+1));
314 DEBUG(10, (__location__
": insert string '%s' found in "
315 "path '%s' found in snapdirseverywhere mode "
316 "==> already converted\n", insert
, name
));
325 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
328 if (snapshot_path
== NULL
) {
333 DEBUG(10, (__location__
" path: '%s'.\n"
334 "snapshot path: '%s'\n", name
, snapshot_path
));
336 s
= strstr(name
, snapshot_path
);
339 * this starts with "snapshot_basepath/GMT-Token"
340 * so it is already a converted absolute
341 * path. Don't process further.
343 DEBUG(10, (__location__
": path '%s' starts with "
344 "snapshot path '%s' (not in "
345 "snapdirseverywhere mode) ==> "
346 "already converted\n", name
, snapshot_path
));
347 talloc_free(snapshot_path
);
350 talloc_free(snapshot_path
);
353 if (pstripped
!= NULL
) {
354 stripped
= talloc_array(mem_ctx
, char, dst_len
+1);
355 if (stripped
== NULL
) {
360 memcpy(stripped
, name
, p
-name
);
363 memcpy(stripped
+ (p
-name
), q
, rest_len
);
365 stripped
[dst_len
] = '\0';
366 *pstripped
= stripped
;
368 *ptimestamp
= timestamp
;
375 static char *shadow_copy2_find_mount_point(TALLOC_CTX
*mem_ctx
,
376 vfs_handle_struct
*handle
)
378 char *path
= talloc_strdup(mem_ctx
, handle
->conn
->connectpath
);
383 if (stat(path
, &st
) != 0) {
390 while ((p
= strrchr(path
, '/')) && p
> path
) {
392 if (stat(path
, &st
) != 0) {
396 if (st
.st_dev
!= dev
) {
406 * Convert from a name as handed in via the SMB layer
407 * and a timestamp into the local path of the snapshot
408 * of the provided file at the provided time.
410 static char *shadow_copy2_convert(TALLOC_CTX
*mem_ctx
,
411 struct vfs_handle_struct
*handle
,
412 const char *name
, time_t timestamp
)
414 struct smb_filename converted_fname
;
416 size_t *slashes
= NULL
;
417 unsigned num_slashes
;
421 char *converted
= NULL
;
425 struct shadow_copy2_config
*config
;
427 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
430 DEBUG(10, ("converting '%s'\n", name
));
432 if (!config
->snapdirseverywhere
) {
436 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
439 if (snapshot_path
== NULL
) {
443 if (config
->rel_connectpath
== NULL
) {
444 converted
= talloc_asprintf(mem_ctx
, "%s/%s",
445 snapshot_path
, name
);
447 converted
= talloc_asprintf(mem_ctx
, "%s/%s/%s",
449 config
->rel_connectpath
,
452 if (converted
== NULL
) {
456 ZERO_STRUCT(converted_fname
);
457 converted_fname
.base_name
= converted
;
459 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
460 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
462 ret
, ret
== 0 ? "ok" : strerror(errno
)));
464 DEBUG(10, ("Found %s\n", converted
));
472 /* never reached ... */
476 path
= talloc_strdup(mem_ctx
, handle
->conn
->connectpath
);
478 path
= talloc_asprintf(
479 mem_ctx
, "%s/%s", handle
->conn
->connectpath
, name
);
485 pathlen
= talloc_get_size(path
)-1;
487 if (!shadow_copy2_find_slashes(talloc_tos(), path
,
488 &slashes
, &num_slashes
)) {
492 insert
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
493 if (insert
== NULL
) {
496 insertlen
= talloc_get_size(insert
)-1;
499 * Note: We deliberatly don't expensively initialize the
500 * array with talloc_zero here: Putting zero into
501 * converted[pathlen+insertlen] below is sufficient, because
502 * in the following for loop, the insert string is inserted
503 * at various slash places. So the memory up to position
504 * pathlen+insertlen will always be initialized when the
505 * converted string is used.
507 converted
= talloc_array(mem_ctx
, char, pathlen
+ insertlen
+ 1);
508 if (converted
== NULL
) {
512 if (path
[pathlen
-1] != '/') {
514 * Append a fake slash to find the snapshot root
517 tmp
= talloc_realloc(talloc_tos(), slashes
,
518 size_t, num_slashes
+1);
523 slashes
[num_slashes
] = pathlen
;
529 if (!config
->crossmountpoints
) {
530 min_offset
= strlen(config
->mount_point
);
533 memcpy(converted
, path
, pathlen
+1);
534 converted
[pathlen
+insertlen
] = '\0';
536 ZERO_STRUCT(converted_fname
);
537 converted_fname
.base_name
= converted
;
539 for (i
= num_slashes
-1; i
>=0; i
--) {
545 if (offset
< min_offset
) {
550 memcpy(converted
+offset
, insert
, insertlen
);
553 memcpy(converted
+offset
, path
+ slashes
[i
],
554 pathlen
- slashes
[i
]);
556 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
558 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
560 ret
, ret
== 0 ? "ok" : strerror(errno
)));
565 if (errno
== ENOTDIR
) {
567 * This is a valid condition: We appended the
568 * .snaphots/@GMT.. to a file name. Just try
569 * with the upper levels.
573 if (errno
!= ENOENT
) {
574 /* Other problem than "not found" */
583 DEBUG(10, ("Found %s\n", converted
));
591 TALLOC_FREE(converted
);
593 TALLOC_FREE(slashes
);
600 modify a sbuf return to ensure that inodes in the shadow directory
601 are different from those in the main directory
603 static void convert_sbuf(vfs_handle_struct
*handle
, const char *fname
,
604 SMB_STRUCT_STAT
*sbuf
)
606 struct shadow_copy2_config
*config
;
608 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
611 if (config
->fixinodes
) {
612 /* some snapshot systems, like GPFS, return the name
613 device:inode for the snapshot files as the current
614 files. That breaks the 'restore' button in the shadow copy
615 GUI, as the client gets a sharing violation.
617 This is a crude way of allowing both files to be
618 open at once. It has a slight chance of inode
619 number collision, but I can't see a better approach
620 without significant VFS changes
624 shash
= hash(fname
, strlen(fname
), 0) & 0xFF000000;
628 sbuf
->st_ex_ino
^= shash
;
632 static DIR *shadow_copy2_opendir(vfs_handle_struct
*handle
,
643 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
644 ×tamp
, &stripped
)) {
647 if (timestamp
== 0) {
648 return SMB_VFS_NEXT_OPENDIR(handle
, fname
, mask
, attr
);
650 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
651 TALLOC_FREE(stripped
);
655 ret
= SMB_VFS_NEXT_OPENDIR(handle
, conv
, mask
, attr
);
662 static int shadow_copy2_rename(vfs_handle_struct
*handle
,
663 const struct smb_filename
*smb_fname_src
,
664 const struct smb_filename
*smb_fname_dst
)
666 time_t timestamp_src
, timestamp_dst
;
668 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
669 smb_fname_src
->base_name
,
670 ×tamp_src
, NULL
)) {
673 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
674 smb_fname_dst
->base_name
,
675 ×tamp_dst
, NULL
)) {
678 if (timestamp_src
!= 0) {
682 if (timestamp_dst
!= 0) {
686 return SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, smb_fname_dst
);
689 static int shadow_copy2_symlink(vfs_handle_struct
*handle
,
690 const char *oldname
, const char *newname
)
692 time_t timestamp_old
, timestamp_new
;
694 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
695 ×tamp_old
, NULL
)) {
698 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
699 ×tamp_new
, NULL
)) {
702 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
706 return SMB_VFS_NEXT_SYMLINK(handle
, oldname
, newname
);
709 static int shadow_copy2_link(vfs_handle_struct
*handle
,
710 const char *oldname
, const char *newname
)
712 time_t timestamp_old
, timestamp_new
;
714 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
715 ×tamp_old
, NULL
)) {
718 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
719 ×tamp_new
, NULL
)) {
722 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
726 return SMB_VFS_NEXT_LINK(handle
, oldname
, newname
);
729 static int shadow_copy2_stat(vfs_handle_struct
*handle
,
730 struct smb_filename
*smb_fname
)
733 char *stripped
, *tmp
;
734 int ret
, saved_errno
;
736 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
737 smb_fname
->base_name
,
738 ×tamp
, &stripped
)) {
741 if (timestamp
== 0) {
742 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
745 tmp
= smb_fname
->base_name
;
746 smb_fname
->base_name
= shadow_copy2_convert(
747 talloc_tos(), handle
, stripped
, timestamp
);
748 TALLOC_FREE(stripped
);
750 if (smb_fname
->base_name
== NULL
) {
751 smb_fname
->base_name
= tmp
;
755 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
758 TALLOC_FREE(smb_fname
->base_name
);
759 smb_fname
->base_name
= tmp
;
762 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
768 static int shadow_copy2_lstat(vfs_handle_struct
*handle
,
769 struct smb_filename
*smb_fname
)
772 char *stripped
, *tmp
;
773 int ret
, saved_errno
;
775 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
776 smb_fname
->base_name
,
777 ×tamp
, &stripped
)) {
780 if (timestamp
== 0) {
781 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
784 tmp
= smb_fname
->base_name
;
785 smb_fname
->base_name
= shadow_copy2_convert(
786 talloc_tos(), handle
, stripped
, timestamp
);
787 TALLOC_FREE(stripped
);
789 if (smb_fname
->base_name
== NULL
) {
790 smb_fname
->base_name
= tmp
;
794 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
797 TALLOC_FREE(smb_fname
->base_name
);
798 smb_fname
->base_name
= tmp
;
801 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
807 static int shadow_copy2_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
808 SMB_STRUCT_STAT
*sbuf
)
813 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
817 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
818 fsp
->fsp_name
->base_name
,
822 if (timestamp
!= 0) {
823 convert_sbuf(handle
, fsp
->fsp_name
->base_name
, sbuf
);
828 static int shadow_copy2_open(vfs_handle_struct
*handle
,
829 struct smb_filename
*smb_fname
, files_struct
*fsp
,
830 int flags
, mode_t mode
)
833 char *stripped
, *tmp
;
834 int ret
, saved_errno
;
836 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
837 smb_fname
->base_name
,
838 ×tamp
, &stripped
)) {
841 if (timestamp
== 0) {
842 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
845 tmp
= smb_fname
->base_name
;
846 smb_fname
->base_name
= shadow_copy2_convert(
847 talloc_tos(), handle
, stripped
, timestamp
);
848 TALLOC_FREE(stripped
);
850 if (smb_fname
->base_name
== NULL
) {
851 smb_fname
->base_name
= tmp
;
855 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
858 TALLOC_FREE(smb_fname
->base_name
);
859 smb_fname
->base_name
= tmp
;
865 static int shadow_copy2_unlink(vfs_handle_struct
*handle
,
866 const struct smb_filename
*smb_fname
)
870 int ret
, saved_errno
;
871 struct smb_filename
*conv
;
873 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
874 smb_fname
->base_name
,
875 ×tamp
, &stripped
)) {
878 if (timestamp
== 0) {
879 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
881 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
886 conv
->base_name
= shadow_copy2_convert(
887 conv
, handle
, stripped
, timestamp
);
888 TALLOC_FREE(stripped
);
889 if (conv
->base_name
== NULL
) {
892 ret
= SMB_VFS_NEXT_UNLINK(handle
, conv
);
899 static int shadow_copy2_chmod(vfs_handle_struct
*handle
, const char *fname
,
904 int ret
, saved_errno
;
907 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
908 ×tamp
, &stripped
)) {
911 if (timestamp
== 0) {
912 return SMB_VFS_NEXT_CHMOD(handle
, fname
, mode
);
914 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
915 TALLOC_FREE(stripped
);
919 ret
= SMB_VFS_NEXT_CHMOD(handle
, conv
, mode
);
926 static int shadow_copy2_chown(vfs_handle_struct
*handle
, const char *fname
,
927 uid_t uid
, gid_t gid
)
931 int ret
, saved_errno
;
934 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
935 ×tamp
, &stripped
)) {
938 if (timestamp
== 0) {
939 return SMB_VFS_NEXT_CHOWN(handle
, fname
, uid
, gid
);
941 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
942 TALLOC_FREE(stripped
);
946 ret
= SMB_VFS_NEXT_CHOWN(handle
, conv
, uid
, gid
);
953 static int shadow_copy2_chdir(vfs_handle_struct
*handle
,
958 int ret
, saved_errno
;
961 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
962 ×tamp
, &stripped
)) {
965 if (timestamp
== 0) {
966 return SMB_VFS_NEXT_CHDIR(handle
, fname
);
968 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
969 TALLOC_FREE(stripped
);
973 ret
= SMB_VFS_NEXT_CHDIR(handle
, conv
);
980 static int shadow_copy2_ntimes(vfs_handle_struct
*handle
,
981 const struct smb_filename
*smb_fname
,
982 struct smb_file_time
*ft
)
986 int ret
, saved_errno
;
987 struct smb_filename
*conv
;
989 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
990 smb_fname
->base_name
,
991 ×tamp
, &stripped
)) {
994 if (timestamp
== 0) {
995 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
997 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
1002 conv
->base_name
= shadow_copy2_convert(
1003 conv
, handle
, stripped
, timestamp
);
1004 TALLOC_FREE(stripped
);
1005 if (conv
->base_name
== NULL
) {
1008 ret
= SMB_VFS_NEXT_NTIMES(handle
, conv
, ft
);
1009 saved_errno
= errno
;
1011 errno
= saved_errno
;
1015 static int shadow_copy2_readlink(vfs_handle_struct
*handle
,
1016 const char *fname
, char *buf
, size_t bufsiz
)
1020 int ret
, saved_errno
;
1023 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1024 ×tamp
, &stripped
)) {
1027 if (timestamp
== 0) {
1028 return SMB_VFS_NEXT_READLINK(handle
, fname
, buf
, bufsiz
);
1030 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1031 TALLOC_FREE(stripped
);
1035 ret
= SMB_VFS_NEXT_READLINK(handle
, conv
, buf
, bufsiz
);
1036 saved_errno
= errno
;
1038 errno
= saved_errno
;
1042 static int shadow_copy2_mknod(vfs_handle_struct
*handle
,
1043 const char *fname
, mode_t mode
, SMB_DEV_T dev
)
1047 int ret
, saved_errno
;
1050 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1051 ×tamp
, &stripped
)) {
1054 if (timestamp
== 0) {
1055 return SMB_VFS_NEXT_MKNOD(handle
, fname
, mode
, dev
);
1057 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1058 TALLOC_FREE(stripped
);
1062 ret
= SMB_VFS_NEXT_MKNOD(handle
, conv
, mode
, dev
);
1063 saved_errno
= errno
;
1065 errno
= saved_errno
;
1069 static char *shadow_copy2_realpath(vfs_handle_struct
*handle
,
1073 char *stripped
= NULL
;
1075 char *result
= NULL
;
1076 char *inserted
= NULL
;
1077 char *inserted_to
, *inserted_end
;
1080 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1081 ×tamp
, &stripped
)) {
1084 if (timestamp
== 0) {
1085 return SMB_VFS_NEXT_REALPATH(handle
, fname
);
1088 tmp
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1093 result
= SMB_VFS_NEXT_REALPATH(handle
, tmp
);
1094 if (result
== NULL
) {
1099 * Take away what we've inserted. This removes the @GMT-thingy
1100 * completely, but will give a path under the share root.
1102 inserted
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
1103 if (inserted
== NULL
) {
1106 inserted_to
= strstr_m(result
, inserted
);
1107 if (inserted_to
== NULL
) {
1108 DEBUG(2, ("SMB_VFS_NEXT_REALPATH removed %s\n", inserted
));
1111 inserted_end
= inserted_to
+ talloc_get_size(inserted
) - 1;
1112 memmove(inserted_to
, inserted_end
, strlen(inserted_end
)+1);
1115 saved_errno
= errno
;
1116 TALLOC_FREE(inserted
);
1118 TALLOC_FREE(stripped
);
1119 errno
= saved_errno
;
1124 * Check whether a given directory contains a
1125 * snapshot directory as direct subdirectory.
1126 * If yes, return the path of the snapshot-subdir,
1127 * otherwise return NULL.
1129 static char *have_snapdir(struct vfs_handle_struct
*handle
,
1132 struct smb_filename smb_fname
;
1134 struct shadow_copy2_config
*config
;
1136 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1139 ZERO_STRUCT(smb_fname
);
1140 smb_fname
.base_name
= talloc_asprintf(talloc_tos(), "%s/%s",
1141 path
, config
->snapdir
);
1142 if (smb_fname
.base_name
== NULL
) {
1146 ret
= SMB_VFS_NEXT_STAT(handle
, &smb_fname
);
1147 if ((ret
== 0) && (S_ISDIR(smb_fname
.st
.st_ex_mode
))) {
1148 return smb_fname
.base_name
;
1150 TALLOC_FREE(smb_fname
.base_name
);
1155 * Find the snapshot directory (if any) for the given
1156 * filename (which is relative to the share).
1158 static const char *shadow_copy2_find_snapdir(TALLOC_CTX
*mem_ctx
,
1159 struct vfs_handle_struct
*handle
,
1160 struct smb_filename
*smb_fname
)
1163 const char *snapdir
;
1164 struct shadow_copy2_config
*config
;
1166 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1170 * If the non-snapdisrseverywhere mode, we should not search!
1172 if (!config
->snapdirseverywhere
) {
1173 return config
->snapshot_basepath
;
1176 path
= talloc_asprintf(mem_ctx
, "%s/%s",
1177 handle
->conn
->connectpath
,
1178 smb_fname
->base_name
);
1183 snapdir
= have_snapdir(handle
, path
);
1184 if (snapdir
!= NULL
) {
1189 while ((p
= strrchr(path
, '/')) && (p
> path
)) {
1193 snapdir
= have_snapdir(handle
, path
);
1194 if (snapdir
!= NULL
) {
1203 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct
*handle
,
1205 char *gmt
, size_t gmt_len
)
1207 struct tm timestamp
;
1209 unsigned long int timestamp_long
;
1211 struct shadow_copy2_config
*config
;
1213 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1216 fmt
= config
->gmt_format
;
1218 ZERO_STRUCT(timestamp
);
1219 if (config
->use_sscanf
) {
1220 if (sscanf(name
, fmt
, ×tamp_long
) != 1) {
1221 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1222 "no sscanf match %s: %s\n",
1226 timestamp_t
= timestamp_long
;
1227 gmtime_r(×tamp_t
, ×tamp
);
1229 if (strptime(name
, fmt
, ×tamp
) == NULL
) {
1230 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1231 "no match %s: %s\n",
1235 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1238 if (config
->use_localtime
) {
1239 timestamp
.tm_isdst
= -1;
1240 timestamp_t
= mktime(×tamp
);
1241 gmtime_r(×tamp_t
, ×tamp
);
1245 strftime(gmt
, gmt_len
, GMT_FORMAT
, ×tamp
);
1249 static int shadow_copy2_label_cmp_asc(const void *x
, const void *y
)
1251 return strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1254 static int shadow_copy2_label_cmp_desc(const void *x
, const void *y
)
1256 return -strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1260 sort the shadow copy data in ascending or descending order
1262 static void shadow_copy2_sort_data(vfs_handle_struct
*handle
,
1263 struct shadow_copy_data
*shadow_copy2_data
)
1265 int (*cmpfunc
)(const void *, const void *);
1267 struct shadow_copy2_config
*config
;
1269 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1272 sort
= config
->sort_order
;
1277 if (strcmp(sort
, "asc") == 0) {
1278 cmpfunc
= shadow_copy2_label_cmp_asc
;
1279 } else if (strcmp(sort
, "desc") == 0) {
1280 cmpfunc
= shadow_copy2_label_cmp_desc
;
1285 if (shadow_copy2_data
&& shadow_copy2_data
->num_volumes
> 0 &&
1286 shadow_copy2_data
->labels
)
1288 TYPESAFE_QSORT(shadow_copy2_data
->labels
,
1289 shadow_copy2_data
->num_volumes
,
1294 static int shadow_copy2_get_shadow_copy_data(
1295 vfs_handle_struct
*handle
, files_struct
*fsp
,
1296 struct shadow_copy_data
*shadow_copy2_data
,
1300 const char *snapdir
;
1302 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1304 snapdir
= shadow_copy2_find_snapdir(tmp_ctx
, handle
, fsp
->fsp_name
);
1305 if (snapdir
== NULL
) {
1306 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1307 handle
->conn
->connectpath
));
1309 talloc_free(tmp_ctx
);
1313 p
= SMB_VFS_NEXT_OPENDIR(handle
, snapdir
, NULL
, 0);
1316 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1317 " - %s\n", snapdir
, strerror(errno
)));
1318 talloc_free(tmp_ctx
);
1323 shadow_copy2_data
->num_volumes
= 0;
1324 shadow_copy2_data
->labels
= NULL
;
1326 while ((d
= SMB_VFS_NEXT_READDIR(handle
, p
, NULL
))) {
1327 char snapshot
[GMT_NAME_LEN
+1];
1328 SHADOW_COPY_LABEL
*tlabels
;
1331 * ignore names not of the right form in the snapshot
1334 if (!shadow_copy2_snapshot_to_gmt(
1336 snapshot
, sizeof(snapshot
))) {
1338 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1339 "ignoring %s\n", d
->d_name
));
1342 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1343 d
->d_name
, snapshot
));
1346 /* the caller doesn't want the labels */
1347 shadow_copy2_data
->num_volumes
++;
1351 tlabels
= talloc_realloc(shadow_copy2_data
,
1352 shadow_copy2_data
->labels
,
1354 shadow_copy2_data
->num_volumes
+1);
1355 if (tlabels
== NULL
) {
1356 DEBUG(0,("shadow_copy2: out of memory\n"));
1357 SMB_VFS_NEXT_CLOSEDIR(handle
, p
);
1358 talloc_free(tmp_ctx
);
1362 strlcpy(tlabels
[shadow_copy2_data
->num_volumes
], snapshot
,
1365 shadow_copy2_data
->num_volumes
++;
1366 shadow_copy2_data
->labels
= tlabels
;
1369 SMB_VFS_NEXT_CLOSEDIR(handle
,p
);
1371 shadow_copy2_sort_data(handle
, shadow_copy2_data
);
1373 talloc_free(tmp_ctx
);
1377 static NTSTATUS
shadow_copy2_fget_nt_acl(vfs_handle_struct
*handle
,
1378 struct files_struct
*fsp
,
1379 uint32 security_info
,
1380 TALLOC_CTX
*mem_ctx
,
1381 struct security_descriptor
**ppdesc
)
1388 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
1389 fsp
->fsp_name
->base_name
,
1390 ×tamp
, &stripped
)) {
1391 return map_nt_error_from_unix(errno
);
1393 if (timestamp
== 0) {
1394 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1398 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1399 TALLOC_FREE(stripped
);
1401 return map_nt_error_from_unix(errno
);
1403 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1409 static NTSTATUS
shadow_copy2_get_nt_acl(vfs_handle_struct
*handle
,
1411 uint32 security_info
,
1412 TALLOC_CTX
*mem_ctx
,
1413 struct security_descriptor
**ppdesc
)
1420 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1421 ×tamp
, &stripped
)) {
1422 return map_nt_error_from_unix(errno
);
1424 if (timestamp
== 0) {
1425 return SMB_VFS_NEXT_GET_NT_ACL(handle
, fname
, security_info
,
1428 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1429 TALLOC_FREE(stripped
);
1431 return map_nt_error_from_unix(errno
);
1433 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1439 static int shadow_copy2_mkdir(vfs_handle_struct
*handle
,
1440 const char *fname
, mode_t mode
)
1444 int ret
, saved_errno
;
1447 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1448 ×tamp
, &stripped
)) {
1451 if (timestamp
== 0) {
1452 return SMB_VFS_NEXT_MKDIR(handle
, fname
, mode
);
1454 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1455 TALLOC_FREE(stripped
);
1459 ret
= SMB_VFS_NEXT_MKDIR(handle
, conv
, mode
);
1460 saved_errno
= errno
;
1462 errno
= saved_errno
;
1466 static int shadow_copy2_rmdir(vfs_handle_struct
*handle
, const char *fname
)
1470 int ret
, saved_errno
;
1473 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1474 ×tamp
, &stripped
)) {
1477 if (timestamp
== 0) {
1478 return SMB_VFS_NEXT_RMDIR(handle
, fname
);
1480 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1481 TALLOC_FREE(stripped
);
1485 ret
= SMB_VFS_NEXT_RMDIR(handle
, conv
);
1486 saved_errno
= errno
;
1488 errno
= saved_errno
;
1492 static int shadow_copy2_chflags(vfs_handle_struct
*handle
, const char *fname
,
1497 int ret
, saved_errno
;
1500 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1501 ×tamp
, &stripped
)) {
1504 if (timestamp
== 0) {
1505 return SMB_VFS_NEXT_CHFLAGS(handle
, fname
, flags
);
1507 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1508 TALLOC_FREE(stripped
);
1512 ret
= SMB_VFS_NEXT_CHFLAGS(handle
, conv
, flags
);
1513 saved_errno
= errno
;
1515 errno
= saved_errno
;
1519 static ssize_t
shadow_copy2_getxattr(vfs_handle_struct
*handle
,
1520 const char *fname
, const char *aname
,
1521 void *value
, size_t size
)
1529 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1530 ×tamp
, &stripped
)) {
1533 if (timestamp
== 0) {
1534 return SMB_VFS_NEXT_GETXATTR(handle
, fname
, aname
, value
,
1537 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1538 TALLOC_FREE(stripped
);
1542 ret
= SMB_VFS_NEXT_GETXATTR(handle
, conv
, aname
, value
, size
);
1543 saved_errno
= errno
;
1545 errno
= saved_errno
;
1549 static ssize_t
shadow_copy2_listxattr(struct vfs_handle_struct
*handle
,
1551 char *list
, size_t size
)
1559 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1560 ×tamp
, &stripped
)) {
1563 if (timestamp
== 0) {
1564 return SMB_VFS_NEXT_LISTXATTR(handle
, fname
, list
, size
);
1566 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1567 TALLOC_FREE(stripped
);
1571 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, conv
, list
, size
);
1572 saved_errno
= errno
;
1574 errno
= saved_errno
;
1578 static int shadow_copy2_removexattr(vfs_handle_struct
*handle
,
1579 const char *fname
, const char *aname
)
1583 int ret
, saved_errno
;
1586 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1587 ×tamp
, &stripped
)) {
1590 if (timestamp
== 0) {
1591 return SMB_VFS_NEXT_REMOVEXATTR(handle
, fname
, aname
);
1593 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1594 TALLOC_FREE(stripped
);
1598 ret
= SMB_VFS_NEXT_REMOVEXATTR(handle
, conv
, aname
);
1599 saved_errno
= errno
;
1601 errno
= saved_errno
;
1605 static int shadow_copy2_setxattr(struct vfs_handle_struct
*handle
,
1607 const char *aname
, const void *value
,
1608 size_t size
, int flags
)
1616 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1617 ×tamp
, &stripped
)) {
1620 if (timestamp
== 0) {
1621 return SMB_VFS_NEXT_SETXATTR(handle
, fname
, aname
, value
, size
,
1624 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1625 TALLOC_FREE(stripped
);
1629 ret
= SMB_VFS_NEXT_SETXATTR(handle
, conv
, aname
, value
, size
, flags
);
1630 saved_errno
= errno
;
1632 errno
= saved_errno
;
1636 static int shadow_copy2_chmod_acl(vfs_handle_struct
*handle
,
1637 const char *fname
, mode_t mode
)
1645 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1646 ×tamp
, &stripped
)) {
1649 if (timestamp
== 0) {
1650 return SMB_VFS_NEXT_CHMOD_ACL(handle
, fname
, mode
);
1652 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1653 TALLOC_FREE(stripped
);
1657 ret
= SMB_VFS_NEXT_CHMOD_ACL(handle
, conv
, mode
);
1658 saved_errno
= errno
;
1660 errno
= saved_errno
;
1664 static int shadow_copy2_get_real_filename(struct vfs_handle_struct
*handle
,
1667 TALLOC_CTX
*mem_ctx
,
1676 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1677 ×tamp
, &stripped
)) {
1680 if (timestamp
== 0) {
1681 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
1682 mem_ctx
, found_name
);
1684 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1685 TALLOC_FREE(stripped
);
1689 ret
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, conv
, name
,
1690 mem_ctx
, found_name
);
1691 saved_errno
= errno
;
1693 errno
= saved_errno
;
1697 static uint64_t shadow_copy2_disk_free(vfs_handle_struct
*handle
,
1698 const char *path
, bool small_query
,
1699 uint64_t *bsize
, uint64_t *dfree
,
1708 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1709 ×tamp
, &stripped
)) {
1712 if (timestamp
== 0) {
1713 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, small_query
,
1714 bsize
, dfree
, dsize
);
1717 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1718 TALLOC_FREE(stripped
);
1723 ret
= SMB_VFS_NEXT_DISK_FREE(handle
, conv
, small_query
, bsize
, dfree
,
1726 saved_errno
= errno
;
1728 errno
= saved_errno
;
1733 static int shadow_copy2_connect(struct vfs_handle_struct
*handle
,
1734 const char *service
, const char *user
)
1736 struct shadow_copy2_config
*config
;
1738 const char *snapdir
;
1739 const char *gmt_format
;
1740 const char *sort_order
;
1741 const char *basedir
;
1742 const char *mount_point
;
1744 DEBUG(10, (__location__
": cnum[%u], connectpath[%s]\n",
1745 (unsigned)handle
->conn
->cnum
,
1746 handle
->conn
->connectpath
));
1748 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1753 config
= talloc_zero(handle
->conn
, struct shadow_copy2_config
);
1754 if (config
== NULL
) {
1755 DEBUG(0, ("talloc_zero() failed\n"));
1760 gmt_format
= lp_parm_const_string(SNUM(handle
->conn
),
1763 config
->gmt_format
= talloc_strdup(config
, gmt_format
);
1764 if (config
->gmt_format
== NULL
) {
1765 DEBUG(0, ("talloc_strdup() failed\n"));
1770 config
->use_sscanf
= lp_parm_bool(SNUM(handle
->conn
),
1771 "shadow", "sscanf", false);
1773 config
->use_localtime
= lp_parm_bool(SNUM(handle
->conn
),
1774 "shadow", "localtime",
1777 snapdir
= lp_parm_const_string(SNUM(handle
->conn
),
1778 "shadow", "snapdir",
1780 config
->snapdir
= talloc_strdup(config
, snapdir
);
1781 if (config
->snapdir
== NULL
) {
1782 DEBUG(0, ("talloc_strdup() failed\n"));
1787 config
->snapdirseverywhere
= lp_parm_bool(SNUM(handle
->conn
),
1789 "snapdirseverywhere",
1792 config
->crossmountpoints
= lp_parm_bool(SNUM(handle
->conn
),
1793 "shadow", "crossmountpoints",
1796 config
->fixinodes
= lp_parm_bool(SNUM(handle
->conn
),
1797 "shadow", "fixinodes",
1800 sort_order
= lp_parm_const_string(SNUM(handle
->conn
),
1801 "shadow", "sort", "desc");
1802 config
->sort_order
= talloc_strdup(config
, sort_order
);
1803 if (config
->sort_order
== NULL
) {
1804 DEBUG(0, ("talloc_strdup() failed\n"));
1809 mount_point
= lp_parm_const_string(SNUM(handle
->conn
),
1810 "shadow", "mountpoint", NULL
);
1811 if (mount_point
!= NULL
) {
1812 if (mount_point
[0] != '/') {
1813 DEBUG(1, (__location__
" Warning: 'mountpoint' is "
1814 "relative ('%s'), but it has to be an "
1815 "absolute path. Ignoring provided value.\n",
1820 p
= strstr(handle
->conn
->connectpath
, mount_point
);
1821 if (p
!= handle
->conn
->connectpath
) {
1822 DEBUG(1, ("Warning: mount_point (%s) is not a "
1823 "subdirectory of the share root "
1824 "(%s). Ignoring provided value.\n",
1826 handle
->conn
->connectpath
));
1832 if (mount_point
!= NULL
) {
1833 config
->mount_point
= talloc_strdup(config
, mount_point
);
1834 if (config
->mount_point
== NULL
) {
1835 DEBUG(0, (__location__
" talloc_strdup() failed\n"));
1839 config
->mount_point
= shadow_copy2_find_mount_point(config
,
1841 if (config
->mount_point
== NULL
) {
1842 DEBUG(0, (__location__
": shadow_copy2_find_mount_point"
1843 " failed: %s\n", strerror(errno
)));
1848 basedir
= lp_parm_const_string(SNUM(handle
->conn
),
1849 "shadow", "basedir", NULL
);
1851 if (basedir
!= NULL
) {
1852 if (basedir
[0] != '/') {
1853 DEBUG(1, (__location__
" Warning: 'basedir' is "
1854 "relative ('%s'), but it has to be an "
1855 "absolute path. Disabling basedir.\n",
1859 p
= strstr(basedir
, config
->mount_point
);
1861 DEBUG(1, ("Warning: basedir (%s) is not a "
1862 "subdirectory of the share root's "
1863 "mount point (%s). "
1864 "Disabling basedir\n",
1865 basedir
, config
->mount_point
));
1867 config
->basedir
= talloc_strdup(config
,
1869 if (config
->basedir
== NULL
) {
1870 DEBUG(0, ("talloc_strdup() failed\n"));
1878 if (config
->snapdirseverywhere
&& config
->basedir
!= NULL
) {
1879 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1880 "with 'snapdirseverywhere'. Disabling basedir.\n"));
1881 TALLOC_FREE(config
->basedir
);
1884 if (config
->crossmountpoints
&& config
->basedir
!= NULL
) {
1885 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1886 "with 'crossmountpoints'. Disabling basedir.\n"));
1887 TALLOC_FREE(config
->basedir
);
1890 if (config
->basedir
== NULL
) {
1891 config
->basedir
= config
->mount_point
;
1894 if (strlen(config
->basedir
) != strlen(handle
->conn
->connectpath
)) {
1895 config
->rel_connectpath
= talloc_strdup(config
,
1896 handle
->conn
->connectpath
+ strlen(config
->basedir
));
1897 if (config
->rel_connectpath
== NULL
) {
1898 DEBUG(0, ("talloc_strdup() failed\n"));
1904 if (config
->snapdir
[0] == '/') {
1905 config
->snapdir_absolute
= true;
1907 if (config
->snapdirseverywhere
== true) {
1908 DEBUG(1, (__location__
" Warning: An absolute snapdir "
1909 "is incompatible with 'snapdirseverywhere', "
1910 "setting 'snapdirseverywhere' to false.\n"));
1911 config
->snapdirseverywhere
= false;
1914 if (config
->crossmountpoints
== true) {
1915 DEBUG(1, (__location__
" Warning: 'crossmountpoints' "
1916 "is not supported with an absolute snapdir. "
1917 "Disabling it.\n"));
1918 config
->crossmountpoints
= false;
1921 config
->snapshot_basepath
= config
->snapdir
;
1923 config
->snapshot_basepath
= talloc_asprintf(config
, "%s/%s",
1924 config
->mount_point
, config
->snapdir
);
1925 if (config
->snapshot_basepath
== NULL
) {
1926 DEBUG(0, ("talloc_asprintf() failed\n"));
1932 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
1933 " share root: '%s'\n"
1935 " mountpoint: '%s'\n"
1936 " rel share root: '%s'\n"
1938 " snapshot base path: '%s'\n"
1941 " snapdirs everywhere: %s\n"
1942 " cross mountpoints: %s\n"
1946 handle
->conn
->connectpath
,
1948 config
->mount_point
,
1949 config
->rel_connectpath
,
1951 config
->snapshot_basepath
,
1953 config
->use_sscanf
? "yes" : "no",
1954 config
->snapdirseverywhere
? "yes" : "no",
1955 config
->crossmountpoints
? "yes" : "no",
1956 config
->fixinodes
? "yes" : "no",
1961 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1962 NULL
, struct shadow_copy2_config
,
1968 static struct vfs_fn_pointers vfs_shadow_copy2_fns
= {
1969 .connect_fn
= shadow_copy2_connect
,
1970 .opendir_fn
= shadow_copy2_opendir
,
1971 .disk_free_fn
= shadow_copy2_disk_free
,
1972 .rename_fn
= shadow_copy2_rename
,
1973 .link_fn
= shadow_copy2_link
,
1974 .symlink_fn
= shadow_copy2_symlink
,
1975 .stat_fn
= shadow_copy2_stat
,
1976 .lstat_fn
= shadow_copy2_lstat
,
1977 .fstat_fn
= shadow_copy2_fstat
,
1978 .open_fn
= shadow_copy2_open
,
1979 .unlink_fn
= shadow_copy2_unlink
,
1980 .chmod_fn
= shadow_copy2_chmod
,
1981 .chown_fn
= shadow_copy2_chown
,
1982 .chdir_fn
= shadow_copy2_chdir
,
1983 .ntimes_fn
= shadow_copy2_ntimes
,
1984 .readlink_fn
= shadow_copy2_readlink
,
1985 .mknod_fn
= shadow_copy2_mknod
,
1986 .realpath_fn
= shadow_copy2_realpath
,
1987 .get_nt_acl_fn
= shadow_copy2_get_nt_acl
,
1988 .fget_nt_acl_fn
= shadow_copy2_fget_nt_acl
,
1989 .get_shadow_copy_data_fn
= shadow_copy2_get_shadow_copy_data
,
1990 .mkdir_fn
= shadow_copy2_mkdir
,
1991 .rmdir_fn
= shadow_copy2_rmdir
,
1992 .getxattr_fn
= shadow_copy2_getxattr
,
1993 .listxattr_fn
= shadow_copy2_listxattr
,
1994 .removexattr_fn
= shadow_copy2_removexattr
,
1995 .setxattr_fn
= shadow_copy2_setxattr
,
1996 .chmod_acl_fn
= shadow_copy2_chmod_acl
,
1997 .chflags_fn
= shadow_copy2_chflags
,
1998 .get_real_filename_fn
= shadow_copy2_get_real_filename
,
2001 NTSTATUS
vfs_shadow_copy2_init(void);
2002 NTSTATUS
vfs_shadow_copy2_init(void)
2004 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
2005 "shadow_copy2", &vfs_shadow_copy2_fns
);