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"
37 struct shadow_copy2_config
{
42 bool snapdirseverywhere
;
43 bool crossmountpoints
;
46 bool snapdir_absolute
;
49 char *rel_connectpath
; /* share root, relative to the basedir */
50 char *snapshot_basepath
; /* the absolute version of snapdir */
53 static bool shadow_copy2_find_slashes(TALLOC_CTX
*mem_ctx
, const char *str
,
55 unsigned *pnum_offsets
)
64 while ((p
= strchr(p
, '/')) != NULL
) {
69 offsets
= talloc_array(mem_ctx
, size_t, num_offsets
);
70 if (offsets
== NULL
) {
76 while ((p
= strchr(p
, '/')) != NULL
) {
77 offsets
[num_offsets
] = p
-str
;
83 *pnum_offsets
= num_offsets
;
88 * Given a timestamp, build the posix level GMT-tag string
89 * based on the configurable format.
91 static size_t shadow_copy2_posix_gmt_string(struct vfs_handle_struct
*handle
,
93 char *snaptime_string
,
98 struct shadow_copy2_config
*config
;
100 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
103 if (config
->use_sscanf
) {
104 snaptime_len
= snprintf(snaptime_string
,
107 (unsigned long)snapshot
);
108 if (snaptime_len
<= 0) {
109 DEBUG(10, ("snprintf failed\n"));
113 if (config
->use_localtime
) {
114 if (localtime_r(&snapshot
, &snap_tm
) == 0) {
115 DEBUG(10, ("gmtime_r failed\n"));
119 if (gmtime_r(&snapshot
, &snap_tm
) == 0) {
120 DEBUG(10, ("gmtime_r failed\n"));
124 snaptime_len
= strftime(snaptime_string
,
128 if (snaptime_len
== 0) {
129 DEBUG(10, ("strftime failed\n"));
138 * Given a timestamp, build the string to insert into a path
139 * as a path component for creating the local path to the
140 * snapshot at the given timestamp of the input path.
142 * In the case of a parallel snapdir (specified with an
143 * absolute path), this is the inital portion of the
144 * local path of any snapshot file. The complete path is
145 * obtained by appending the portion of the file's path
146 * below the share root's mountpoint.
148 static char *shadow_copy2_insert_string(TALLOC_CTX
*mem_ctx
,
149 struct vfs_handle_struct
*handle
,
152 fstring snaptime_string
;
153 size_t snaptime_len
= 0;
155 struct shadow_copy2_config
*config
;
157 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
160 snaptime_len
= shadow_copy2_posix_gmt_string(handle
,
163 sizeof(snaptime_string
));
164 if (snaptime_len
<= 0) {
168 if (config
->snapdir_absolute
) {
169 result
= talloc_asprintf(mem_ctx
, "%s/%s",
170 config
->snapdir
, snaptime_string
);
172 result
= talloc_asprintf(mem_ctx
, "/%s/%s",
173 config
->snapdir
, snaptime_string
);
175 if (result
== NULL
) {
176 DEBUG(1, (__location__
" talloc_asprintf failed\n"));
183 * Build the posix snapshot path for the connection
184 * at the given timestamp, i.e. the absolute posix path
185 * that contains the snapshot for this file system.
187 * This only applies to classical case, i.e. not
188 * to the "snapdirseverywhere" mode.
190 static char *shadow_copy2_snapshot_path(TALLOC_CTX
*mem_ctx
,
191 struct vfs_handle_struct
*handle
,
194 fstring snaptime_string
;
195 size_t snaptime_len
= 0;
197 struct shadow_copy2_config
*config
;
199 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
202 snaptime_len
= shadow_copy2_posix_gmt_string(handle
,
205 sizeof(snaptime_string
));
206 if (snaptime_len
<= 0) {
210 result
= talloc_asprintf(mem_ctx
, "%s/%s",
211 config
->snapshot_basepath
, snaptime_string
);
212 if (result
== NULL
) {
213 DEBUG(1, (__location__
" talloc_asprintf failed\n"));
220 * Strip a snapshot component from a filename as
221 * handed in via the smb layer.
222 * Returns the parsed timestamp and the stripped filename.
224 static bool shadow_copy2_strip_snapshot(TALLOC_CTX
*mem_ctx
,
225 struct vfs_handle_struct
*handle
,
235 size_t rest_len
, dst_len
;
236 struct shadow_copy2_config
*config
;
239 ptrdiff_t len_before_gmt
;
241 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
244 DEBUG(10, (__location__
": enter path '%s'\n", name
));
246 p
= strstr_m(name
, "@GMT-");
248 DEBUG(11, ("@GMT not found\n"));
251 if ((p
> name
) && (p
[-1] != '/')) {
252 /* the GMT-token does not start a path-component */
253 DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
254 p
, name
, (int)p
[-1]));
259 * Figure out whether we got an already converted string. One
260 * case where this happens is in a smb2 create call with the
261 * mxac create blob set. We do the get_acl call on
262 * fsp->fsp_name, which is already converted. We are converted
263 * if we got a file name of the form ".snapshots/@GMT-",
264 * i.e. ".snapshots/" precedes "p".
267 snapdir
= lp_parm_const_string(SNUM(handle
->conn
), "shadow", "snapdir",
269 snapdirlen
= strlen(snapdir
);
270 len_before_gmt
= p
- name
;
272 if ((len_before_gmt
>= (snapdirlen
+ 1)) && (p
[-1] == '/')) {
273 const char *parent_snapdir
= p
- (snapdirlen
+1);
275 DEBUG(10, ("parent_snapdir = %s\n", parent_snapdir
));
277 if (strncmp(parent_snapdir
, snapdir
, snapdirlen
) == 0) {
278 DEBUG(10, ("name=%s is already converted\n", name
));
282 q
= strptime(p
, GMT_FORMAT
, &tm
);
284 DEBUG(10, ("strptime failed\n"));
288 timestamp
= timegm(&tm
);
289 if (timestamp
== (time_t)-1) {
290 DEBUG(10, ("timestamp==-1\n"));
295 * The name consists of only the GMT token or the GMT
296 * token is at the end of the path. XP seems to send
297 * @GMT- at the end under certain circumstances even
298 * with a path prefix.
300 if (pstripped
!= NULL
) {
301 stripped
= talloc_strndup(mem_ctx
, name
, p
- name
);
302 if (stripped
== NULL
) {
305 *pstripped
= stripped
;
307 *ptimestamp
= timestamp
;
312 * It is not a complete path component, i.e. the path
313 * component continues after the gmt-token.
315 DEBUG(10, ("q[0] = %d\n", (int)q
[0]));
320 rest_len
= strlen(q
);
321 dst_len
= (p
-name
) + rest_len
;
323 if (config
->snapdirseverywhere
) {
326 insert
= shadow_copy2_insert_string(talloc_tos(), handle
,
328 if (insert
== NULL
) {
333 DEBUG(10, (__location__
": snapdirseverywhere mode.\n"
335 "insert string '%s'\n", name
, insert
));
337 have_insert
= (strstr(name
, insert
+1) != NULL
);
338 DEBUG(10, ("have_insert=%d, name=%s, insert+1=%s\n",
339 (int)have_insert
, name
, insert
+1));
341 DEBUG(10, (__location__
": insert string '%s' found in "
342 "path '%s' found in snapdirseverywhere mode "
343 "==> already converted\n", insert
, name
));
352 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
355 if (snapshot_path
== NULL
) {
360 DEBUG(10, (__location__
" path: '%s'.\n"
361 "snapshot path: '%s'\n", name
, snapshot_path
));
363 s
= strstr(name
, snapshot_path
);
366 * this starts with "snapshot_basepath/GMT-Token"
367 * so it is already a converted absolute
368 * path. Don't process further.
370 DEBUG(10, (__location__
": path '%s' starts with "
371 "snapshot path '%s' (not in "
372 "snapdirseverywhere mode) ==> "
373 "already converted\n", name
, snapshot_path
));
374 talloc_free(snapshot_path
);
377 talloc_free(snapshot_path
);
380 if (pstripped
!= NULL
) {
381 stripped
= talloc_array(mem_ctx
, char, dst_len
+1);
382 if (stripped
== NULL
) {
387 memcpy(stripped
, name
, p
-name
);
390 memcpy(stripped
+ (p
-name
), q
, rest_len
);
392 stripped
[dst_len
] = '\0';
393 *pstripped
= stripped
;
395 *ptimestamp
= timestamp
;
402 static char *shadow_copy2_find_mount_point(TALLOC_CTX
*mem_ctx
,
403 vfs_handle_struct
*handle
)
405 char *path
= talloc_strdup(mem_ctx
, handle
->conn
->connectpath
);
410 if (stat(path
, &st
) != 0) {
417 while ((p
= strrchr(path
, '/')) && p
> path
) {
419 if (stat(path
, &st
) != 0) {
423 if (st
.st_dev
!= dev
) {
433 * Convert from a name as handed in via the SMB layer
434 * and a timestamp into the local path of the snapshot
435 * of the provided file at the provided time.
437 static char *shadow_copy2_convert(TALLOC_CTX
*mem_ctx
,
438 struct vfs_handle_struct
*handle
,
439 const char *name
, time_t timestamp
)
441 struct smb_filename converted_fname
;
443 size_t *slashes
= NULL
;
444 unsigned num_slashes
;
448 char *converted
= NULL
;
452 struct shadow_copy2_config
*config
;
454 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
457 DEBUG(10, ("converting '%s'\n", name
));
459 if (!config
->snapdirseverywhere
) {
463 snapshot_path
= shadow_copy2_snapshot_path(talloc_tos(),
466 if (snapshot_path
== NULL
) {
470 if (config
->rel_connectpath
== NULL
) {
471 converted
= talloc_asprintf(mem_ctx
, "%s/%s",
472 snapshot_path
, name
);
474 converted
= talloc_asprintf(mem_ctx
, "%s/%s/%s",
476 config
->rel_connectpath
,
479 if (converted
== NULL
) {
483 ZERO_STRUCT(converted_fname
);
484 converted_fname
.base_name
= converted
;
486 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
487 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
489 ret
, ret
== 0 ? "ok" : strerror(errno
)));
491 DEBUG(10, ("Found %s\n", converted
));
499 /* never reached ... */
503 path
= talloc_strdup(mem_ctx
, handle
->conn
->connectpath
);
505 path
= talloc_asprintf(
506 mem_ctx
, "%s/%s", handle
->conn
->connectpath
, name
);
512 pathlen
= talloc_get_size(path
)-1;
514 if (!shadow_copy2_find_slashes(talloc_tos(), path
,
515 &slashes
, &num_slashes
)) {
519 insert
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
520 if (insert
== NULL
) {
523 insertlen
= talloc_get_size(insert
)-1;
526 * Note: We deliberatly don't expensively initialize the
527 * array with talloc_zero here: Putting zero into
528 * converted[pathlen+insertlen] below is sufficient, because
529 * in the following for loop, the insert string is inserted
530 * at various slash places. So the memory up to position
531 * pathlen+insertlen will always be initialized when the
532 * converted string is used.
534 converted
= talloc_array(mem_ctx
, char, pathlen
+ insertlen
+ 1);
535 if (converted
== NULL
) {
539 if (path
[pathlen
-1] != '/') {
541 * Append a fake slash to find the snapshot root
544 tmp
= talloc_realloc(talloc_tos(), slashes
,
545 size_t, num_slashes
+1);
550 slashes
[num_slashes
] = pathlen
;
556 if (!config
->crossmountpoints
) {
557 min_offset
= strlen(config
->mount_point
);
560 memcpy(converted
, path
, pathlen
+1);
561 converted
[pathlen
+insertlen
] = '\0';
563 ZERO_STRUCT(converted_fname
);
564 converted_fname
.base_name
= converted
;
566 for (i
= num_slashes
-1; i
>=0; i
--) {
572 if (offset
< min_offset
) {
577 memcpy(converted
+offset
, insert
, insertlen
);
580 memcpy(converted
+offset
, path
+ slashes
[i
],
581 pathlen
- slashes
[i
]);
583 ret
= SMB_VFS_NEXT_LSTAT(handle
, &converted_fname
);
585 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
587 ret
, ret
== 0 ? "ok" : strerror(errno
)));
592 if (errno
== ENOTDIR
) {
594 * This is a valid condition: We appended the
595 * .snaphots/@GMT.. to a file name. Just try
596 * with the upper levels.
600 if (errno
!= ENOENT
) {
601 /* Other problem than "not found" */
610 DEBUG(10, ("Found %s\n", converted
));
618 TALLOC_FREE(converted
);
620 TALLOC_FREE(slashes
);
627 modify a sbuf return to ensure that inodes in the shadow directory
628 are different from those in the main directory
630 static void convert_sbuf(vfs_handle_struct
*handle
, const char *fname
,
631 SMB_STRUCT_STAT
*sbuf
)
633 struct shadow_copy2_config
*config
;
635 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
638 if (config
->fixinodes
) {
639 /* some snapshot systems, like GPFS, return the name
640 device:inode for the snapshot files as the current
641 files. That breaks the 'restore' button in the shadow copy
642 GUI, as the client gets a sharing violation.
644 This is a crude way of allowing both files to be
645 open at once. It has a slight chance of inode
646 number collision, but I can't see a better approach
647 without significant VFS changes
649 TDB_DATA key
= { .dptr
= discard_const_p(uint8_t, fname
),
650 .dsize
= strlen(fname
) };
653 shash
= tdb_jenkins_hash(&key
) & 0xFF000000;
657 sbuf
->st_ex_ino
^= shash
;
661 static DIR *shadow_copy2_opendir(vfs_handle_struct
*handle
,
672 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
673 ×tamp
, &stripped
)) {
676 if (timestamp
== 0) {
677 return SMB_VFS_NEXT_OPENDIR(handle
, fname
, mask
, attr
);
679 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
680 TALLOC_FREE(stripped
);
684 ret
= SMB_VFS_NEXT_OPENDIR(handle
, conv
, mask
, attr
);
691 static int shadow_copy2_rename(vfs_handle_struct
*handle
,
692 const struct smb_filename
*smb_fname_src
,
693 const struct smb_filename
*smb_fname_dst
)
695 time_t timestamp_src
, timestamp_dst
;
697 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
698 smb_fname_src
->base_name
,
699 ×tamp_src
, NULL
)) {
702 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
703 smb_fname_dst
->base_name
,
704 ×tamp_dst
, NULL
)) {
707 if (timestamp_src
!= 0) {
711 if (timestamp_dst
!= 0) {
715 return SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, smb_fname_dst
);
718 static int shadow_copy2_symlink(vfs_handle_struct
*handle
,
719 const char *oldname
, const char *newname
)
721 time_t timestamp_old
, timestamp_new
;
723 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
724 ×tamp_old
, NULL
)) {
727 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
728 ×tamp_new
, NULL
)) {
731 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
735 return SMB_VFS_NEXT_SYMLINK(handle
, oldname
, newname
);
738 static int shadow_copy2_link(vfs_handle_struct
*handle
,
739 const char *oldname
, const char *newname
)
741 time_t timestamp_old
, timestamp_new
;
743 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, oldname
,
744 ×tamp_old
, NULL
)) {
747 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, newname
,
748 ×tamp_new
, NULL
)) {
751 if ((timestamp_old
!= 0) || (timestamp_new
!= 0)) {
755 return SMB_VFS_NEXT_LINK(handle
, oldname
, newname
);
758 static int shadow_copy2_stat(vfs_handle_struct
*handle
,
759 struct smb_filename
*smb_fname
)
762 char *stripped
, *tmp
;
763 int ret
, saved_errno
;
765 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
766 smb_fname
->base_name
,
767 ×tamp
, &stripped
)) {
770 if (timestamp
== 0) {
771 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
774 tmp
= smb_fname
->base_name
;
775 smb_fname
->base_name
= shadow_copy2_convert(
776 talloc_tos(), handle
, stripped
, timestamp
);
777 TALLOC_FREE(stripped
);
779 if (smb_fname
->base_name
== NULL
) {
780 smb_fname
->base_name
= tmp
;
784 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
787 TALLOC_FREE(smb_fname
->base_name
);
788 smb_fname
->base_name
= tmp
;
791 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
797 static int shadow_copy2_lstat(vfs_handle_struct
*handle
,
798 struct smb_filename
*smb_fname
)
801 char *stripped
, *tmp
;
802 int ret
, saved_errno
;
804 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
805 smb_fname
->base_name
,
806 ×tamp
, &stripped
)) {
809 if (timestamp
== 0) {
810 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
813 tmp
= smb_fname
->base_name
;
814 smb_fname
->base_name
= shadow_copy2_convert(
815 talloc_tos(), handle
, stripped
, timestamp
);
816 TALLOC_FREE(stripped
);
818 if (smb_fname
->base_name
== NULL
) {
819 smb_fname
->base_name
= tmp
;
823 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
826 TALLOC_FREE(smb_fname
->base_name
);
827 smb_fname
->base_name
= tmp
;
830 convert_sbuf(handle
, smb_fname
->base_name
, &smb_fname
->st
);
836 static int shadow_copy2_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
837 SMB_STRUCT_STAT
*sbuf
)
842 ret
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
846 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
847 fsp
->fsp_name
->base_name
,
851 if (timestamp
!= 0) {
852 convert_sbuf(handle
, fsp
->fsp_name
->base_name
, sbuf
);
857 static int shadow_copy2_open(vfs_handle_struct
*handle
,
858 struct smb_filename
*smb_fname
, files_struct
*fsp
,
859 int flags
, mode_t mode
)
862 char *stripped
, *tmp
;
863 int ret
, saved_errno
;
865 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
866 smb_fname
->base_name
,
867 ×tamp
, &stripped
)) {
870 if (timestamp
== 0) {
871 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
874 tmp
= smb_fname
->base_name
;
875 smb_fname
->base_name
= shadow_copy2_convert(
876 talloc_tos(), handle
, stripped
, timestamp
);
877 TALLOC_FREE(stripped
);
879 if (smb_fname
->base_name
== NULL
) {
880 smb_fname
->base_name
= tmp
;
884 ret
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
887 TALLOC_FREE(smb_fname
->base_name
);
888 smb_fname
->base_name
= tmp
;
894 static int shadow_copy2_unlink(vfs_handle_struct
*handle
,
895 const struct smb_filename
*smb_fname
)
899 int ret
, saved_errno
;
900 struct smb_filename
*conv
;
902 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
903 smb_fname
->base_name
,
904 ×tamp
, &stripped
)) {
907 if (timestamp
== 0) {
908 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
910 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
915 conv
->base_name
= shadow_copy2_convert(
916 conv
, handle
, stripped
, timestamp
);
917 TALLOC_FREE(stripped
);
918 if (conv
->base_name
== NULL
) {
921 ret
= SMB_VFS_NEXT_UNLINK(handle
, conv
);
928 static int shadow_copy2_chmod(vfs_handle_struct
*handle
, const char *fname
,
933 int ret
, saved_errno
;
936 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
937 ×tamp
, &stripped
)) {
940 if (timestamp
== 0) {
941 return SMB_VFS_NEXT_CHMOD(handle
, fname
, mode
);
943 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
944 TALLOC_FREE(stripped
);
948 ret
= SMB_VFS_NEXT_CHMOD(handle
, conv
, mode
);
955 static int shadow_copy2_chown(vfs_handle_struct
*handle
, const char *fname
,
956 uid_t uid
, gid_t gid
)
960 int ret
, saved_errno
;
963 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
964 ×tamp
, &stripped
)) {
967 if (timestamp
== 0) {
968 return SMB_VFS_NEXT_CHOWN(handle
, fname
, uid
, gid
);
970 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
971 TALLOC_FREE(stripped
);
975 ret
= SMB_VFS_NEXT_CHOWN(handle
, conv
, uid
, gid
);
982 static int shadow_copy2_chdir(vfs_handle_struct
*handle
,
987 int ret
, saved_errno
;
990 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
991 ×tamp
, &stripped
)) {
994 if (timestamp
== 0) {
995 return SMB_VFS_NEXT_CHDIR(handle
, fname
);
997 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
998 TALLOC_FREE(stripped
);
1002 ret
= SMB_VFS_NEXT_CHDIR(handle
, conv
);
1003 saved_errno
= errno
;
1005 errno
= saved_errno
;
1009 static int shadow_copy2_ntimes(vfs_handle_struct
*handle
,
1010 const struct smb_filename
*smb_fname
,
1011 struct smb_file_time
*ft
)
1015 int ret
, saved_errno
;
1016 struct smb_filename
*conv
;
1018 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
1019 smb_fname
->base_name
,
1020 ×tamp
, &stripped
)) {
1023 if (timestamp
== 0) {
1024 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1026 conv
= cp_smb_filename(talloc_tos(), smb_fname
);
1031 conv
->base_name
= shadow_copy2_convert(
1032 conv
, handle
, stripped
, timestamp
);
1033 TALLOC_FREE(stripped
);
1034 if (conv
->base_name
== NULL
) {
1037 ret
= SMB_VFS_NEXT_NTIMES(handle
, conv
, ft
);
1038 saved_errno
= errno
;
1040 errno
= saved_errno
;
1044 static int shadow_copy2_readlink(vfs_handle_struct
*handle
,
1045 const char *fname
, char *buf
, size_t bufsiz
)
1049 int ret
, saved_errno
;
1052 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1053 ×tamp
, &stripped
)) {
1056 if (timestamp
== 0) {
1057 return SMB_VFS_NEXT_READLINK(handle
, fname
, buf
, bufsiz
);
1059 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1060 TALLOC_FREE(stripped
);
1064 ret
= SMB_VFS_NEXT_READLINK(handle
, conv
, buf
, bufsiz
);
1065 saved_errno
= errno
;
1067 errno
= saved_errno
;
1071 static int shadow_copy2_mknod(vfs_handle_struct
*handle
,
1072 const char *fname
, mode_t mode
, SMB_DEV_T dev
)
1076 int ret
, saved_errno
;
1079 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1080 ×tamp
, &stripped
)) {
1083 if (timestamp
== 0) {
1084 return SMB_VFS_NEXT_MKNOD(handle
, fname
, mode
, dev
);
1086 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1087 TALLOC_FREE(stripped
);
1091 ret
= SMB_VFS_NEXT_MKNOD(handle
, conv
, mode
, dev
);
1092 saved_errno
= errno
;
1094 errno
= saved_errno
;
1098 static char *shadow_copy2_realpath(vfs_handle_struct
*handle
,
1102 char *stripped
= NULL
;
1104 char *result
= NULL
;
1105 char *inserted
= NULL
;
1106 char *inserted_to
, *inserted_end
;
1109 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1110 ×tamp
, &stripped
)) {
1113 if (timestamp
== 0) {
1114 return SMB_VFS_NEXT_REALPATH(handle
, fname
);
1117 tmp
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1122 result
= SMB_VFS_NEXT_REALPATH(handle
, tmp
);
1123 if (result
== NULL
) {
1128 * Take away what we've inserted. This removes the @GMT-thingy
1129 * completely, but will give a path under the share root.
1131 inserted
= shadow_copy2_insert_string(talloc_tos(), handle
, timestamp
);
1132 if (inserted
== NULL
) {
1135 inserted_to
= strstr_m(result
, inserted
);
1136 if (inserted_to
== NULL
) {
1137 DEBUG(2, ("SMB_VFS_NEXT_REALPATH removed %s\n", inserted
));
1140 inserted_end
= inserted_to
+ talloc_get_size(inserted
) - 1;
1141 memmove(inserted_to
, inserted_end
, strlen(inserted_end
)+1);
1144 saved_errno
= errno
;
1145 TALLOC_FREE(inserted
);
1147 TALLOC_FREE(stripped
);
1148 errno
= saved_errno
;
1153 * Check whether a given directory contains a
1154 * snapshot directory as direct subdirectory.
1155 * If yes, return the path of the snapshot-subdir,
1156 * otherwise return NULL.
1158 static char *have_snapdir(struct vfs_handle_struct
*handle
,
1161 struct smb_filename smb_fname
;
1163 struct shadow_copy2_config
*config
;
1165 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1168 ZERO_STRUCT(smb_fname
);
1169 smb_fname
.base_name
= talloc_asprintf(talloc_tos(), "%s/%s",
1170 path
, config
->snapdir
);
1171 if (smb_fname
.base_name
== NULL
) {
1175 ret
= SMB_VFS_NEXT_STAT(handle
, &smb_fname
);
1176 if ((ret
== 0) && (S_ISDIR(smb_fname
.st
.st_ex_mode
))) {
1177 return smb_fname
.base_name
;
1179 TALLOC_FREE(smb_fname
.base_name
);
1184 * Find the snapshot directory (if any) for the given
1185 * filename (which is relative to the share).
1187 static const char *shadow_copy2_find_snapdir(TALLOC_CTX
*mem_ctx
,
1188 struct vfs_handle_struct
*handle
,
1189 struct smb_filename
*smb_fname
)
1192 const char *snapdir
;
1193 struct shadow_copy2_config
*config
;
1195 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1199 * If the non-snapdisrseverywhere mode, we should not search!
1201 if (!config
->snapdirseverywhere
) {
1202 return config
->snapshot_basepath
;
1205 path
= talloc_asprintf(mem_ctx
, "%s/%s",
1206 handle
->conn
->connectpath
,
1207 smb_fname
->base_name
);
1212 snapdir
= have_snapdir(handle
, path
);
1213 if (snapdir
!= NULL
) {
1218 while ((p
= strrchr(path
, '/')) && (p
> path
)) {
1222 snapdir
= have_snapdir(handle
, path
);
1223 if (snapdir
!= NULL
) {
1232 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct
*handle
,
1234 char *gmt
, size_t gmt_len
)
1236 struct tm timestamp
;
1238 unsigned long int timestamp_long
;
1240 struct shadow_copy2_config
*config
;
1242 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1245 fmt
= config
->gmt_format
;
1247 ZERO_STRUCT(timestamp
);
1248 if (config
->use_sscanf
) {
1249 if (sscanf(name
, fmt
, ×tamp_long
) != 1) {
1250 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1251 "no sscanf match %s: %s\n",
1255 timestamp_t
= timestamp_long
;
1256 gmtime_r(×tamp_t
, ×tamp
);
1258 if (strptime(name
, fmt
, ×tamp
) == NULL
) {
1259 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1260 "no match %s: %s\n",
1264 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1267 if (config
->use_localtime
) {
1268 timestamp
.tm_isdst
= -1;
1269 timestamp_t
= mktime(×tamp
);
1270 gmtime_r(×tamp_t
, ×tamp
);
1274 strftime(gmt
, gmt_len
, GMT_FORMAT
, ×tamp
);
1278 static int shadow_copy2_label_cmp_asc(const void *x
, const void *y
)
1280 return strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1283 static int shadow_copy2_label_cmp_desc(const void *x
, const void *y
)
1285 return -strncmp((const char *)x
, (const char *)y
, sizeof(SHADOW_COPY_LABEL
));
1289 sort the shadow copy data in ascending or descending order
1291 static void shadow_copy2_sort_data(vfs_handle_struct
*handle
,
1292 struct shadow_copy_data
*shadow_copy2_data
)
1294 int (*cmpfunc
)(const void *, const void *);
1296 struct shadow_copy2_config
*config
;
1298 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct shadow_copy2_config
,
1301 sort
= config
->sort_order
;
1306 if (strcmp(sort
, "asc") == 0) {
1307 cmpfunc
= shadow_copy2_label_cmp_asc
;
1308 } else if (strcmp(sort
, "desc") == 0) {
1309 cmpfunc
= shadow_copy2_label_cmp_desc
;
1314 if (shadow_copy2_data
&& shadow_copy2_data
->num_volumes
> 0 &&
1315 shadow_copy2_data
->labels
)
1317 TYPESAFE_QSORT(shadow_copy2_data
->labels
,
1318 shadow_copy2_data
->num_volumes
,
1323 static int shadow_copy2_get_shadow_copy_data(
1324 vfs_handle_struct
*handle
, files_struct
*fsp
,
1325 struct shadow_copy_data
*shadow_copy2_data
,
1329 const char *snapdir
;
1331 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1333 snapdir
= shadow_copy2_find_snapdir(tmp_ctx
, handle
, fsp
->fsp_name
);
1334 if (snapdir
== NULL
) {
1335 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1336 handle
->conn
->connectpath
));
1338 talloc_free(tmp_ctx
);
1342 p
= SMB_VFS_NEXT_OPENDIR(handle
, snapdir
, NULL
, 0);
1345 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1346 " - %s\n", snapdir
, strerror(errno
)));
1347 talloc_free(tmp_ctx
);
1352 shadow_copy2_data
->num_volumes
= 0;
1353 shadow_copy2_data
->labels
= NULL
;
1355 while ((d
= SMB_VFS_NEXT_READDIR(handle
, p
, NULL
))) {
1356 char snapshot
[GMT_NAME_LEN
+1];
1357 SHADOW_COPY_LABEL
*tlabels
;
1360 * ignore names not of the right form in the snapshot
1363 if (!shadow_copy2_snapshot_to_gmt(
1365 snapshot
, sizeof(snapshot
))) {
1367 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1368 "ignoring %s\n", d
->d_name
));
1371 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1372 d
->d_name
, snapshot
));
1375 /* the caller doesn't want the labels */
1376 shadow_copy2_data
->num_volumes
++;
1380 tlabels
= talloc_realloc(shadow_copy2_data
,
1381 shadow_copy2_data
->labels
,
1383 shadow_copy2_data
->num_volumes
+1);
1384 if (tlabels
== NULL
) {
1385 DEBUG(0,("shadow_copy2: out of memory\n"));
1386 SMB_VFS_NEXT_CLOSEDIR(handle
, p
);
1387 talloc_free(tmp_ctx
);
1391 strlcpy(tlabels
[shadow_copy2_data
->num_volumes
], snapshot
,
1394 shadow_copy2_data
->num_volumes
++;
1395 shadow_copy2_data
->labels
= tlabels
;
1398 SMB_VFS_NEXT_CLOSEDIR(handle
,p
);
1400 shadow_copy2_sort_data(handle
, shadow_copy2_data
);
1402 talloc_free(tmp_ctx
);
1406 static NTSTATUS
shadow_copy2_fget_nt_acl(vfs_handle_struct
*handle
,
1407 struct files_struct
*fsp
,
1408 uint32_t security_info
,
1409 TALLOC_CTX
*mem_ctx
,
1410 struct security_descriptor
**ppdesc
)
1417 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
,
1418 fsp
->fsp_name
->base_name
,
1419 ×tamp
, &stripped
)) {
1420 return map_nt_error_from_unix(errno
);
1422 if (timestamp
== 0) {
1423 return SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
1427 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1428 TALLOC_FREE(stripped
);
1430 return map_nt_error_from_unix(errno
);
1432 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1438 static NTSTATUS
shadow_copy2_get_nt_acl(vfs_handle_struct
*handle
,
1440 uint32_t security_info
,
1441 TALLOC_CTX
*mem_ctx
,
1442 struct security_descriptor
**ppdesc
)
1449 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1450 ×tamp
, &stripped
)) {
1451 return map_nt_error_from_unix(errno
);
1453 if (timestamp
== 0) {
1454 return SMB_VFS_NEXT_GET_NT_ACL(handle
, fname
, security_info
,
1457 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1458 TALLOC_FREE(stripped
);
1460 return map_nt_error_from_unix(errno
);
1462 status
= SMB_VFS_NEXT_GET_NT_ACL(handle
, conv
, security_info
,
1468 static int shadow_copy2_mkdir(vfs_handle_struct
*handle
,
1469 const char *fname
, mode_t mode
)
1473 int ret
, saved_errno
;
1476 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1477 ×tamp
, &stripped
)) {
1480 if (timestamp
== 0) {
1481 return SMB_VFS_NEXT_MKDIR(handle
, fname
, mode
);
1483 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1484 TALLOC_FREE(stripped
);
1488 ret
= SMB_VFS_NEXT_MKDIR(handle
, conv
, mode
);
1489 saved_errno
= errno
;
1491 errno
= saved_errno
;
1495 static int shadow_copy2_rmdir(vfs_handle_struct
*handle
, const char *fname
)
1499 int ret
, saved_errno
;
1502 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1503 ×tamp
, &stripped
)) {
1506 if (timestamp
== 0) {
1507 return SMB_VFS_NEXT_RMDIR(handle
, fname
);
1509 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1510 TALLOC_FREE(stripped
);
1514 ret
= SMB_VFS_NEXT_RMDIR(handle
, conv
);
1515 saved_errno
= errno
;
1517 errno
= saved_errno
;
1521 static int shadow_copy2_chflags(vfs_handle_struct
*handle
, const char *fname
,
1526 int ret
, saved_errno
;
1529 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1530 ×tamp
, &stripped
)) {
1533 if (timestamp
== 0) {
1534 return SMB_VFS_NEXT_CHFLAGS(handle
, fname
, flags
);
1536 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1537 TALLOC_FREE(stripped
);
1541 ret
= SMB_VFS_NEXT_CHFLAGS(handle
, conv
, flags
);
1542 saved_errno
= errno
;
1544 errno
= saved_errno
;
1548 static ssize_t
shadow_copy2_getxattr(vfs_handle_struct
*handle
,
1549 const char *fname
, const char *aname
,
1550 void *value
, size_t size
)
1558 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1559 ×tamp
, &stripped
)) {
1562 if (timestamp
== 0) {
1563 return SMB_VFS_NEXT_GETXATTR(handle
, fname
, aname
, value
,
1566 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1567 TALLOC_FREE(stripped
);
1571 ret
= SMB_VFS_NEXT_GETXATTR(handle
, conv
, aname
, value
, size
);
1572 saved_errno
= errno
;
1574 errno
= saved_errno
;
1578 static ssize_t
shadow_copy2_listxattr(struct vfs_handle_struct
*handle
,
1580 char *list
, size_t size
)
1588 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1589 ×tamp
, &stripped
)) {
1592 if (timestamp
== 0) {
1593 return SMB_VFS_NEXT_LISTXATTR(handle
, fname
, list
, size
);
1595 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1596 TALLOC_FREE(stripped
);
1600 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, conv
, list
, size
);
1601 saved_errno
= errno
;
1603 errno
= saved_errno
;
1607 static int shadow_copy2_removexattr(vfs_handle_struct
*handle
,
1608 const char *fname
, const char *aname
)
1612 int ret
, saved_errno
;
1615 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1616 ×tamp
, &stripped
)) {
1619 if (timestamp
== 0) {
1620 return SMB_VFS_NEXT_REMOVEXATTR(handle
, fname
, aname
);
1622 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1623 TALLOC_FREE(stripped
);
1627 ret
= SMB_VFS_NEXT_REMOVEXATTR(handle
, conv
, aname
);
1628 saved_errno
= errno
;
1630 errno
= saved_errno
;
1634 static int shadow_copy2_setxattr(struct vfs_handle_struct
*handle
,
1636 const char *aname
, const void *value
,
1637 size_t size
, int flags
)
1645 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1646 ×tamp
, &stripped
)) {
1649 if (timestamp
== 0) {
1650 return SMB_VFS_NEXT_SETXATTR(handle
, fname
, aname
, value
, size
,
1653 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1654 TALLOC_FREE(stripped
);
1658 ret
= SMB_VFS_NEXT_SETXATTR(handle
, conv
, aname
, value
, size
, flags
);
1659 saved_errno
= errno
;
1661 errno
= saved_errno
;
1665 static int shadow_copy2_chmod_acl(vfs_handle_struct
*handle
,
1666 const char *fname
, mode_t mode
)
1674 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, fname
,
1675 ×tamp
, &stripped
)) {
1678 if (timestamp
== 0) {
1679 return SMB_VFS_NEXT_CHMOD_ACL(handle
, fname
, mode
);
1681 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1682 TALLOC_FREE(stripped
);
1686 ret
= SMB_VFS_NEXT_CHMOD_ACL(handle
, conv
, mode
);
1687 saved_errno
= errno
;
1689 errno
= saved_errno
;
1693 static int shadow_copy2_get_real_filename(struct vfs_handle_struct
*handle
,
1696 TALLOC_CTX
*mem_ctx
,
1705 DEBUG(10, ("shadow_copy2_get_real_filename called for path=[%s], "
1706 "name=[%s]\n", path
, name
));
1708 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1709 ×tamp
, &stripped
)) {
1710 DEBUG(10, ("shadow_copy2_strip_snapshot failed\n"));
1713 if (timestamp
== 0) {
1714 DEBUG(10, ("timestamp == 0\n"));
1715 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, path
, name
,
1716 mem_ctx
, found_name
);
1718 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1719 TALLOC_FREE(stripped
);
1721 DEBUG(10, ("shadow_copy2_convert failed\n"));
1724 DEBUG(10, ("Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
1725 "name=[%s]\n", conv
, name
));
1726 ret
= SMB_VFS_NEXT_GET_REAL_FILENAME(handle
, conv
, name
,
1727 mem_ctx
, found_name
);
1728 DEBUG(10, ("NEXT_REAL_FILE_NAME returned %d\n", (int)ret
));
1729 saved_errno
= errno
;
1731 errno
= saved_errno
;
1735 static uint64_t shadow_copy2_disk_free(vfs_handle_struct
*handle
,
1736 const char *path
, uint64_t *bsize
,
1737 uint64_t *dfree
, uint64_t *dsize
)
1745 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle
, path
,
1746 ×tamp
, &stripped
)) {
1749 if (timestamp
== 0) {
1750 return SMB_VFS_NEXT_DISK_FREE(handle
, path
,
1751 bsize
, dfree
, dsize
);
1754 conv
= shadow_copy2_convert(talloc_tos(), handle
, stripped
, timestamp
);
1755 TALLOC_FREE(stripped
);
1760 ret
= SMB_VFS_NEXT_DISK_FREE(handle
, conv
, bsize
, dfree
, dsize
);
1762 saved_errno
= errno
;
1764 errno
= saved_errno
;
1769 static int shadow_copy2_connect(struct vfs_handle_struct
*handle
,
1770 const char *service
, const char *user
)
1772 struct shadow_copy2_config
*config
;
1774 const char *snapdir
;
1775 const char *gmt_format
;
1776 const char *sort_order
;
1777 const char *basedir
;
1778 const char *mount_point
;
1780 DEBUG(10, (__location__
": cnum[%u], connectpath[%s]\n",
1781 (unsigned)handle
->conn
->cnum
,
1782 handle
->conn
->connectpath
));
1784 ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1789 config
= talloc_zero(handle
->conn
, struct shadow_copy2_config
);
1790 if (config
== NULL
) {
1791 DEBUG(0, ("talloc_zero() failed\n"));
1796 gmt_format
= lp_parm_const_string(SNUM(handle
->conn
),
1799 config
->gmt_format
= talloc_strdup(config
, gmt_format
);
1800 if (config
->gmt_format
== NULL
) {
1801 DEBUG(0, ("talloc_strdup() failed\n"));
1806 config
->use_sscanf
= lp_parm_bool(SNUM(handle
->conn
),
1807 "shadow", "sscanf", false);
1809 config
->use_localtime
= lp_parm_bool(SNUM(handle
->conn
),
1810 "shadow", "localtime",
1813 snapdir
= lp_parm_const_string(SNUM(handle
->conn
),
1814 "shadow", "snapdir",
1816 config
->snapdir
= talloc_strdup(config
, snapdir
);
1817 if (config
->snapdir
== NULL
) {
1818 DEBUG(0, ("talloc_strdup() failed\n"));
1823 config
->snapdirseverywhere
= lp_parm_bool(SNUM(handle
->conn
),
1825 "snapdirseverywhere",
1828 config
->crossmountpoints
= lp_parm_bool(SNUM(handle
->conn
),
1829 "shadow", "crossmountpoints",
1832 config
->fixinodes
= lp_parm_bool(SNUM(handle
->conn
),
1833 "shadow", "fixinodes",
1836 sort_order
= lp_parm_const_string(SNUM(handle
->conn
),
1837 "shadow", "sort", "desc");
1838 config
->sort_order
= talloc_strdup(config
, sort_order
);
1839 if (config
->sort_order
== NULL
) {
1840 DEBUG(0, ("talloc_strdup() failed\n"));
1845 mount_point
= lp_parm_const_string(SNUM(handle
->conn
),
1846 "shadow", "mountpoint", NULL
);
1847 if (mount_point
!= NULL
) {
1848 if (mount_point
[0] != '/') {
1849 DEBUG(1, (__location__
" Warning: 'mountpoint' is "
1850 "relative ('%s'), but it has to be an "
1851 "absolute path. Ignoring provided value.\n",
1856 p
= strstr(handle
->conn
->connectpath
, mount_point
);
1857 if (p
!= handle
->conn
->connectpath
) {
1858 DEBUG(1, ("Warning: mount_point (%s) is not a "
1859 "subdirectory of the share root "
1860 "(%s). Ignoring provided value.\n",
1862 handle
->conn
->connectpath
));
1868 if (mount_point
!= NULL
) {
1869 config
->mount_point
= talloc_strdup(config
, mount_point
);
1870 if (config
->mount_point
== NULL
) {
1871 DEBUG(0, (__location__
" talloc_strdup() failed\n"));
1875 config
->mount_point
= shadow_copy2_find_mount_point(config
,
1877 if (config
->mount_point
== NULL
) {
1878 DEBUG(0, (__location__
": shadow_copy2_find_mount_point"
1879 " failed: %s\n", strerror(errno
)));
1884 basedir
= lp_parm_const_string(SNUM(handle
->conn
),
1885 "shadow", "basedir", NULL
);
1887 if (basedir
!= NULL
) {
1888 if (basedir
[0] != '/') {
1889 DEBUG(1, (__location__
" Warning: 'basedir' is "
1890 "relative ('%s'), but it has to be an "
1891 "absolute path. Disabling basedir.\n",
1895 p
= strstr(basedir
, config
->mount_point
);
1897 DEBUG(1, ("Warning: basedir (%s) is not a "
1898 "subdirectory of the share root's "
1899 "mount point (%s). "
1900 "Disabling basedir\n",
1901 basedir
, config
->mount_point
));
1903 config
->basedir
= talloc_strdup(config
,
1905 if (config
->basedir
== NULL
) {
1906 DEBUG(0, ("talloc_strdup() failed\n"));
1914 if (config
->snapdirseverywhere
&& config
->basedir
!= NULL
) {
1915 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1916 "with 'snapdirseverywhere'. Disabling basedir.\n"));
1917 TALLOC_FREE(config
->basedir
);
1920 if (config
->crossmountpoints
&& config
->basedir
!= NULL
) {
1921 DEBUG(1, (__location__
" Warning: 'basedir' is incompatible "
1922 "with 'crossmountpoints'. Disabling basedir.\n"));
1923 TALLOC_FREE(config
->basedir
);
1926 if (config
->basedir
== NULL
) {
1927 config
->basedir
= config
->mount_point
;
1930 if (strlen(config
->basedir
) != strlen(handle
->conn
->connectpath
)) {
1931 config
->rel_connectpath
= talloc_strdup(config
,
1932 handle
->conn
->connectpath
+ strlen(config
->basedir
));
1933 if (config
->rel_connectpath
== NULL
) {
1934 DEBUG(0, ("talloc_strdup() failed\n"));
1940 if (config
->snapdir
[0] == '/') {
1941 config
->snapdir_absolute
= true;
1943 if (config
->snapdirseverywhere
== true) {
1944 DEBUG(1, (__location__
" Warning: An absolute snapdir "
1945 "is incompatible with 'snapdirseverywhere', "
1946 "setting 'snapdirseverywhere' to false.\n"));
1947 config
->snapdirseverywhere
= false;
1950 if (config
->crossmountpoints
== true) {
1951 DEBUG(1, (__location__
" Warning: 'crossmountpoints' "
1952 "is not supported with an absolute snapdir. "
1953 "Disabling it.\n"));
1954 config
->crossmountpoints
= false;
1957 config
->snapshot_basepath
= config
->snapdir
;
1959 config
->snapshot_basepath
= talloc_asprintf(config
, "%s/%s",
1960 config
->mount_point
, config
->snapdir
);
1961 if (config
->snapshot_basepath
== NULL
) {
1962 DEBUG(0, ("talloc_asprintf() failed\n"));
1968 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
1969 " share root: '%s'\n"
1971 " mountpoint: '%s'\n"
1972 " rel share root: '%s'\n"
1974 " snapshot base path: '%s'\n"
1977 " snapdirs everywhere: %s\n"
1978 " cross mountpoints: %s\n"
1982 handle
->conn
->connectpath
,
1984 config
->mount_point
,
1985 config
->rel_connectpath
,
1987 config
->snapshot_basepath
,
1989 config
->use_sscanf
? "yes" : "no",
1990 config
->snapdirseverywhere
? "yes" : "no",
1991 config
->crossmountpoints
? "yes" : "no",
1992 config
->fixinodes
? "yes" : "no",
1997 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1998 NULL
, struct shadow_copy2_config
,
2004 static struct vfs_fn_pointers vfs_shadow_copy2_fns
= {
2005 .connect_fn
= shadow_copy2_connect
,
2006 .opendir_fn
= shadow_copy2_opendir
,
2007 .disk_free_fn
= shadow_copy2_disk_free
,
2008 .rename_fn
= shadow_copy2_rename
,
2009 .link_fn
= shadow_copy2_link
,
2010 .symlink_fn
= shadow_copy2_symlink
,
2011 .stat_fn
= shadow_copy2_stat
,
2012 .lstat_fn
= shadow_copy2_lstat
,
2013 .fstat_fn
= shadow_copy2_fstat
,
2014 .open_fn
= shadow_copy2_open
,
2015 .unlink_fn
= shadow_copy2_unlink
,
2016 .chmod_fn
= shadow_copy2_chmod
,
2017 .chown_fn
= shadow_copy2_chown
,
2018 .chdir_fn
= shadow_copy2_chdir
,
2019 .ntimes_fn
= shadow_copy2_ntimes
,
2020 .readlink_fn
= shadow_copy2_readlink
,
2021 .mknod_fn
= shadow_copy2_mknod
,
2022 .realpath_fn
= shadow_copy2_realpath
,
2023 .get_nt_acl_fn
= shadow_copy2_get_nt_acl
,
2024 .fget_nt_acl_fn
= shadow_copy2_fget_nt_acl
,
2025 .get_shadow_copy_data_fn
= shadow_copy2_get_shadow_copy_data
,
2026 .mkdir_fn
= shadow_copy2_mkdir
,
2027 .rmdir_fn
= shadow_copy2_rmdir
,
2028 .getxattr_fn
= shadow_copy2_getxattr
,
2029 .listxattr_fn
= shadow_copy2_listxattr
,
2030 .removexattr_fn
= shadow_copy2_removexattr
,
2031 .setxattr_fn
= shadow_copy2_setxattr
,
2032 .chmod_acl_fn
= shadow_copy2_chmod_acl
,
2033 .chflags_fn
= shadow_copy2_chflags
,
2034 .get_real_filename_fn
= shadow_copy2_get_real_filename
,
2037 NTSTATUS
vfs_shadow_copy2_init(void);
2038 NTSTATUS
vfs_shadow_copy2_init(void)
2040 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
2041 "shadow_copy2", &vfs_shadow_copy2_fns
);