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 "smbd/smbd.h"
34 #include "system/filesys.h"
35 #include "include/ntioctl.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;
240 ptrdiff_t len_before_gmt;
242 SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
245 DEBUG(10, (__location__ ": enter path '%s'\n", name));
247 p = strstr_m(name, "@GMT-");
249 DEBUG(11, ("@GMT not found\n"));
252 if ((p > name) && (p[-1] != '/')) {
253 /* the GMT-token does not start a path-component */
254 DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
255 p, name, (int)p[-1]));
260 * Figure out whether we got an already converted string. One
261 * case where this happens is in a smb2 create call with the
262 * mxac create blob set. We do the get_acl call on
263 * fsp->fsp_name, which is already converted. We are converted
264 * if we got a file name of the form ".snapshots/@GMT-",
265 * i.e. ".snapshots/" precedes "p".
268 snapdir = lp_parm_const_string(SNUM(handle->conn), "shadow", "snapdir",
270 snapdirlen = strlen(snapdir);
271 len_before_gmt = p - name;
273 if ((len_before_gmt >= (snapdirlen + 1)) && (p[-1] == '/')) {
274 const char *parent_snapdir = p - (snapdirlen+1);
276 DEBUG(10, ("parent_snapdir = %s\n", parent_snapdir));
278 if (strncmp(parent_snapdir, snapdir, snapdirlen) == 0) {
279 DEBUG(10, ("name=%s is already converted\n", name));
283 q = strptime(p, GMT_FORMAT, &tm);
285 DEBUG(10, ("strptime failed\n"));
289 timestamp = timegm(&tm);
290 if (timestamp == (time_t)-1) {
291 DEBUG(10, ("timestamp==-1\n"));
296 * The name consists of only the GMT token or the GMT
297 * token is at the end of the path. XP seems to send
298 * @GMT- at the end under certain circumstances even
299 * with a path prefix.
301 if (pstripped != NULL) {
302 stripped = talloc_strndup(mem_ctx, name, p - name);
303 if (stripped == NULL) {
306 *pstripped = stripped;
308 *ptimestamp = timestamp;
313 * It is not a complete path component, i.e. the path
314 * component continues after the gmt-token.
316 DEBUG(10, ("q[0] = %d\n", (int)q[0]));
321 rest_len = strlen(q);
322 dst_len = (p-name) + rest_len;
324 if (config->snapdirseverywhere) {
327 insert = shadow_copy2_insert_string(talloc_tos(), handle,
329 if (insert == NULL) {
334 DEBUG(10, (__location__ ": snapdirseverywhere mode.\n"
336 "insert string '%s'\n", name, insert));
338 have_insert = (strstr(name, insert+1) != NULL);
339 DEBUG(10, ("have_insert=%d, name=%s, insert+1=%s\n",
340 (int)have_insert, name, insert+1));
342 DEBUG(10, (__location__ ": insert string '%s' found in "
343 "path '%s' found in snapdirseverywhere mode "
344 "==> already converted\n", insert, name));
353 snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
356 if (snapshot_path == NULL) {
361 DEBUG(10, (__location__ " path: '%s'.\n"
362 "snapshot path: '%s'\n", name, snapshot_path));
364 s = strstr(name, snapshot_path);
367 * this starts with "snapshot_basepath/GMT-Token"
368 * so it is already a converted absolute
369 * path. Don't process further.
371 DEBUG(10, (__location__ ": path '%s' starts with "
372 "snapshot path '%s' (not in "
373 "snapdirseverywhere mode) ==> "
374 "already converted\n", name, snapshot_path));
375 talloc_free(snapshot_path);
378 talloc_free(snapshot_path);
381 if (pstripped != NULL) {
382 stripped = talloc_array(mem_ctx, char, dst_len+1);
383 if (stripped == NULL) {
388 memcpy(stripped, name, p-name);
391 memcpy(stripped + (p-name), q, rest_len);
393 stripped[dst_len] = '\0';
394 *pstripped = stripped;
396 *ptimestamp = timestamp;
403 static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
404 vfs_handle_struct *handle)
406 char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
411 if (stat(path, &st) != 0) {
418 while ((p = strrchr(path, '/')) && p > path) {
420 if (stat(path, &st) != 0) {
424 if (st.st_dev != dev) {
434 * Convert from a name as handed in via the SMB layer
435 * and a timestamp into the local path of the snapshot
436 * of the provided file at the provided time.
437 * Also return the path in the snapshot corresponding
438 * to the file's share root.
440 static char *shadow_copy2_do_convert(TALLOC_CTX *mem_ctx,
441 struct vfs_handle_struct *handle,
442 const char *name, time_t timestamp,
443 size_t *snaproot_len)
445 struct smb_filename converted_fname;
447 size_t *slashes = NULL;
448 unsigned num_slashes;
452 char *converted = NULL;
453 size_t insertlen, connectlen = 0;
456 struct shadow_copy2_config *config;
457 size_t in_share_offset = 0;
459 SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
462 DEBUG(10, ("converting '%s'\n", name));
464 if (!config->snapdirseverywhere) {
468 snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
471 if (snapshot_path == NULL) {
475 if (config->rel_connectpath == NULL) {
476 converted = talloc_asprintf(mem_ctx, "%s/%s",
477 snapshot_path, name);
479 converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
481 config->rel_connectpath,
484 if (converted == NULL) {
488 ZERO_STRUCT(converted_fname);
489 converted_fname.base_name = converted;
491 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
492 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
494 ret, ret == 0 ? "ok" : strerror(errno)));
496 DEBUG(10, ("Found %s\n", converted));
499 if (snaproot_len != NULL) {
500 *snaproot_len = strlen(snapshot_path);
501 if (config->rel_connectpath != NULL) {
503 strlen(config->rel_connectpath) + 1;
511 /* never reached ... */
514 connectlen = strlen(handle->conn->connectpath);
516 path = talloc_strdup(mem_ctx, handle->conn->connectpath);
518 path = talloc_asprintf(
519 mem_ctx, "%s/%s", handle->conn->connectpath, name);
525 pathlen = talloc_get_size(path)-1;
527 if (!shadow_copy2_find_slashes(talloc_tos(), path,
528 &slashes, &num_slashes)) {
532 insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
533 if (insert == NULL) {
536 insertlen = talloc_get_size(insert)-1;
539 * Note: We deliberatly don't expensively initialize the
540 * array with talloc_zero here: Putting zero into
541 * converted[pathlen+insertlen] below is sufficient, because
542 * in the following for loop, the insert string is inserted
543 * at various slash places. So the memory up to position
544 * pathlen+insertlen will always be initialized when the
545 * converted string is used.
547 converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
548 if (converted == NULL) {
552 if (path[pathlen-1] != '/') {
554 * Append a fake slash to find the snapshot root
557 tmp = talloc_realloc(talloc_tos(), slashes,
558 size_t, num_slashes+1);
563 slashes[num_slashes] = pathlen;
569 if (!config->crossmountpoints) {
570 min_offset = strlen(config->mount_point);
573 memcpy(converted, path, pathlen+1);
574 converted[pathlen+insertlen] = '\0';
576 ZERO_STRUCT(converted_fname);
577 converted_fname.base_name = converted;
579 for (i = num_slashes-1; i>=0; i--) {
585 if (offset < min_offset) {
590 if (offset >= connectlen) {
591 in_share_offset = offset;
594 memcpy(converted+offset, insert, insertlen);
597 memcpy(converted+offset, path + slashes[i],
598 pathlen - slashes[i]);
600 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
602 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
604 ret, ret == 0 ? "ok" : strerror(errno)));
607 if (snaproot_len != NULL) {
608 *snaproot_len = in_share_offset + insertlen;
612 if (errno == ENOTDIR) {
614 * This is a valid condition: We appended the
615 * .snaphots/@GMT.. to a file name. Just try
616 * with the upper levels.
620 if (errno != ENOENT) {
621 /* Other problem than "not found" */
630 DEBUG(10, ("Found %s\n", converted));
638 TALLOC_FREE(converted);
640 TALLOC_FREE(slashes);
647 * Convert from a name as handed in via the SMB layer
648 * and a timestamp into the local path of the snapshot
649 * of the provided file at the provided time.
651 static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
652 struct vfs_handle_struct *handle,
653 const char *name, time_t timestamp)
655 return shadow_copy2_do_convert(mem_ctx, handle, name, timestamp, NULL);
659 modify a sbuf return to ensure that inodes in the shadow directory
660 are different from those in the main directory
662 static void convert_sbuf(vfs_handle_struct *handle, const char *fname,
663 SMB_STRUCT_STAT *sbuf)
665 struct shadow_copy2_config *config;
667 SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
670 if (config->fixinodes) {
671 /* some snapshot systems, like GPFS, return the name
672 device:inode for the snapshot files as the current
673 files. That breaks the 'restore' button in the shadow copy
674 GUI, as the client gets a sharing violation.
676 This is a crude way of allowing both files to be
677 open at once. It has a slight chance of inode
678 number collision, but I can't see a better approach
679 without significant VFS changes
681 TDB_DATA key = { .dptr = discard_const_p(uint8_t, fname),
682 .dsize = strlen(fname) };
685 shash = tdb_jenkins_hash(&key) & 0xFF000000;
689 sbuf->st_ex_ino ^= shash;
693 static DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
704 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
705 ×tamp, &stripped)) {
708 if (timestamp == 0) {
709 return SMB_VFS_NEXT_OPENDIR(handle, fname, mask, attr);
711 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
712 TALLOC_FREE(stripped);
716 ret = SMB_VFS_NEXT_OPENDIR(handle, conv, mask, attr);
723 static int shadow_copy2_rename(vfs_handle_struct *handle,
724 const struct smb_filename *smb_fname_src,
725 const struct smb_filename *smb_fname_dst)
727 time_t timestamp_src, timestamp_dst;
729 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
730 smb_fname_src->base_name,
731 ×tamp_src, NULL)) {
734 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
735 smb_fname_dst->base_name,
736 ×tamp_dst, NULL)) {
739 if (timestamp_src != 0) {
743 if (timestamp_dst != 0) {
747 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
750 static int shadow_copy2_symlink(vfs_handle_struct *handle,
751 const char *oldname, const char *newname)
753 time_t timestamp_old, timestamp_new;
755 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
756 ×tamp_old, NULL)) {
759 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
760 ×tamp_new, NULL)) {
763 if ((timestamp_old != 0) || (timestamp_new != 0)) {
767 return SMB_VFS_NEXT_SYMLINK(handle, oldname, newname);
770 static int shadow_copy2_link(vfs_handle_struct *handle,
771 const char *oldname, const char *newname)
773 time_t timestamp_old, timestamp_new;
775 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
776 ×tamp_old, NULL)) {
779 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
780 ×tamp_new, NULL)) {
783 if ((timestamp_old != 0) || (timestamp_new != 0)) {
787 return SMB_VFS_NEXT_LINK(handle, oldname, newname);
790 static int shadow_copy2_stat(vfs_handle_struct *handle,
791 struct smb_filename *smb_fname)
794 char *stripped, *tmp;
795 int ret, saved_errno;
797 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
798 smb_fname->base_name,
799 ×tamp, &stripped)) {
802 if (timestamp == 0) {
803 return SMB_VFS_NEXT_STAT(handle, smb_fname);
806 tmp = smb_fname->base_name;
807 smb_fname->base_name = shadow_copy2_convert(
808 talloc_tos(), handle, stripped, timestamp);
809 TALLOC_FREE(stripped);
811 if (smb_fname->base_name == NULL) {
812 smb_fname->base_name = tmp;
816 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
819 TALLOC_FREE(smb_fname->base_name);
820 smb_fname->base_name = tmp;
823 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
829 static int shadow_copy2_lstat(vfs_handle_struct *handle,
830 struct smb_filename *smb_fname)
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_LSTAT(handle, smb_fname);
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_LSTAT(handle, smb_fname);
858 TALLOC_FREE(smb_fname->base_name);
859 smb_fname->base_name = tmp;
862 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
868 static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
869 SMB_STRUCT_STAT *sbuf)
874 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
878 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
879 fsp->fsp_name->base_name,
883 if (timestamp != 0) {
884 convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
889 static int shadow_copy2_open(vfs_handle_struct *handle,
890 struct smb_filename *smb_fname, files_struct *fsp,
891 int flags, mode_t mode)
894 char *stripped, *tmp;
895 int ret, saved_errno;
897 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
898 smb_fname->base_name,
899 ×tamp, &stripped)) {
902 if (timestamp == 0) {
903 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
906 tmp = smb_fname->base_name;
907 smb_fname->base_name = shadow_copy2_convert(
908 talloc_tos(), handle, stripped, timestamp);
909 TALLOC_FREE(stripped);
911 if (smb_fname->base_name == NULL) {
912 smb_fname->base_name = tmp;
916 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
919 TALLOC_FREE(smb_fname->base_name);
920 smb_fname->base_name = tmp;
926 static int shadow_copy2_unlink(vfs_handle_struct *handle,
927 const struct smb_filename *smb_fname)
931 int ret, saved_errno;
932 struct smb_filename *conv;
934 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
935 smb_fname->base_name,
936 ×tamp, &stripped)) {
939 if (timestamp == 0) {
940 return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
942 conv = cp_smb_filename(talloc_tos(), smb_fname);
947 conv->base_name = shadow_copy2_convert(
948 conv, handle, stripped, timestamp);
949 TALLOC_FREE(stripped);
950 if (conv->base_name == NULL) {
953 ret = SMB_VFS_NEXT_UNLINK(handle, conv);
960 static int shadow_copy2_chmod(vfs_handle_struct *handle, const char *fname,
965 int ret, saved_errno;
968 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
969 ×tamp, &stripped)) {
972 if (timestamp == 0) {
973 return SMB_VFS_NEXT_CHMOD(handle, fname, mode);
975 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
976 TALLOC_FREE(stripped);
980 ret = SMB_VFS_NEXT_CHMOD(handle, conv, mode);
987 static int shadow_copy2_chown(vfs_handle_struct *handle, const char *fname,
988 uid_t uid, gid_t gid)
992 int ret, saved_errno;
995 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
996 ×tamp, &stripped)) {
999 if (timestamp == 0) {
1000 return SMB_VFS_NEXT_CHOWN(handle, fname, uid, gid);
1002 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1003 TALLOC_FREE(stripped);
1007 ret = SMB_VFS_NEXT_CHOWN(handle, conv, uid, gid);
1008 saved_errno = errno;
1010 errno = saved_errno;
1014 static int shadow_copy2_chdir(vfs_handle_struct *handle,
1019 int ret, saved_errno;
1022 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1023 ×tamp, &stripped)) {
1026 if (timestamp == 0) {
1027 return SMB_VFS_NEXT_CHDIR(handle, fname);
1029 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1030 TALLOC_FREE(stripped);
1034 ret = SMB_VFS_NEXT_CHDIR(handle, conv);
1035 saved_errno = errno;
1037 errno = saved_errno;
1041 static int shadow_copy2_ntimes(vfs_handle_struct *handle,
1042 const struct smb_filename *smb_fname,
1043 struct smb_file_time *ft)
1047 int ret, saved_errno;
1048 struct smb_filename *conv;
1050 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1051 smb_fname->base_name,
1052 ×tamp, &stripped)) {
1055 if (timestamp == 0) {
1056 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1058 conv = cp_smb_filename(talloc_tos(), smb_fname);
1063 conv->base_name = shadow_copy2_convert(
1064 conv, handle, stripped, timestamp);
1065 TALLOC_FREE(stripped);
1066 if (conv->base_name == NULL) {
1069 ret = SMB_VFS_NEXT_NTIMES(handle, conv, ft);
1070 saved_errno = errno;
1072 errno = saved_errno;
1076 static int shadow_copy2_readlink(vfs_handle_struct *handle,
1077 const char *fname, char *buf, size_t bufsiz)
1081 int ret, saved_errno;
1084 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1085 ×tamp, &stripped)) {
1088 if (timestamp == 0) {
1089 return SMB_VFS_NEXT_READLINK(handle, fname, buf, bufsiz);
1091 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1092 TALLOC_FREE(stripped);
1096 ret = SMB_VFS_NEXT_READLINK(handle, conv, buf, bufsiz);
1097 saved_errno = errno;
1099 errno = saved_errno;
1103 static int shadow_copy2_mknod(vfs_handle_struct *handle,
1104 const char *fname, mode_t mode, SMB_DEV_T dev)
1108 int ret, saved_errno;
1111 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1112 ×tamp, &stripped)) {
1115 if (timestamp == 0) {
1116 return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
1118 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1119 TALLOC_FREE(stripped);
1123 ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
1124 saved_errno = errno;
1126 errno = saved_errno;
1130 static char *shadow_copy2_realpath(vfs_handle_struct *handle,
1134 char *stripped = NULL;
1136 char *result = NULL;
1139 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1140 ×tamp, &stripped)) {
1143 if (timestamp == 0) {
1144 return SMB_VFS_NEXT_REALPATH(handle, fname);
1147 tmp = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1152 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
1155 saved_errno = errno;
1157 TALLOC_FREE(stripped);
1158 errno = saved_errno;
1163 * Check whether a given directory contains a
1164 * snapshot directory as direct subdirectory.
1165 * If yes, return the path of the snapshot-subdir,
1166 * otherwise return NULL.
1168 static char *have_snapdir(struct vfs_handle_struct *handle,
1171 struct smb_filename smb_fname;
1173 struct shadow_copy2_config *config;
1175 SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
1178 ZERO_STRUCT(smb_fname);
1179 smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
1180 path, config->snapdir);
1181 if (smb_fname.base_name == NULL) {
1185 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1186 if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
1187 return smb_fname.base_name;
1189 TALLOC_FREE(smb_fname.base_name);
1193 static bool check_access_snapdir(struct vfs_handle_struct *handle,
1196 struct smb_filename smb_fname;
1200 ZERO_STRUCT(smb_fname);
1201 smb_fname.base_name = talloc_asprintf(talloc_tos(),
1204 if (smb_fname.base_name == NULL) {
1208 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1209 if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
1210 TALLOC_FREE(smb_fname.base_name);
1214 status = smbd_check_access_rights(handle->conn,
1218 if (!NT_STATUS_IS_OK(status)) {
1219 DEBUG(0,("user does not have list permission "
1221 smb_fname.base_name));
1222 TALLOC_FREE(smb_fname.base_name);
1225 TALLOC_FREE(smb_fname.base_name);
1230 * Find the snapshot directory (if any) for the given
1231 * filename (which is relative to the share).
1233 static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx,
1234 struct vfs_handle_struct *handle,
1235 struct smb_filename *smb_fname)
1238 const char *snapdir;
1239 struct shadow_copy2_config *config;
1241 SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
1245 * If the non-snapdisrseverywhere mode, we should not search!
1247 if (!config->snapdirseverywhere) {
1248 return config->snapshot_basepath;
1251 path = talloc_asprintf(mem_ctx, "%s/%s",
1252 handle->conn->connectpath,
1253 smb_fname->base_name);
1258 snapdir = have_snapdir(handle, path);
1259 if (snapdir != NULL) {
1264 while ((p = strrchr(path, '/')) && (p > path)) {
1268 snapdir = have_snapdir(handle, path);
1269 if (snapdir != NULL) {
1278 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
1280 char *gmt, size_t gmt_len)
1282 struct tm timestamp;
1284 unsigned long int timestamp_long;
1286 struct shadow_copy2_config *config;
1288 SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
1291 fmt = config->gmt_format;
1293 ZERO_STRUCT(timestamp);
1294 if (config->use_sscanf) {
1295 if (sscanf(name, fmt, ×tamp_long) != 1) {
1296 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1297 "no sscanf match %s: %s\n",
1301 timestamp_t = timestamp_long;
1302 gmtime_r(×tamp_t, ×tamp);
1304 if (strptime(name, fmt, ×tamp) == NULL) {
1305 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1306 "no match %s: %s\n",
1310 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1313 if (config->use_localtime) {
1314 timestamp.tm_isdst = -1;
1315 timestamp_t = mktime(×tamp);
1316 gmtime_r(×tamp_t, ×tamp);
1320 strftime(gmt, gmt_len, GMT_FORMAT, ×tamp);
1324 static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
1326 return strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1329 static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
1331 return -strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1335 sort the shadow copy data in ascending or descending order
1337 static void shadow_copy2_sort_data(vfs_handle_struct *handle,
1338 struct shadow_copy_data *shadow_copy2_data)
1340 int (*cmpfunc)(const void *, const void *);
1342 struct shadow_copy2_config *config;
1344 SMB_VFS_HANDLE_GET_DATA(handle, config, struct shadow_copy2_config,
1347 sort = config->sort_order;
1352 if (strcmp(sort, "asc") == 0) {
1353 cmpfunc = shadow_copy2_label_cmp_asc;
1354 } else if (strcmp(sort, "desc") == 0) {
1355 cmpfunc = shadow_copy2_label_cmp_desc;
1360 if (shadow_copy2_data && shadow_copy2_data->num_volumes > 0 &&
1361 shadow_copy2_data->labels)
1363 TYPESAFE_QSORT(shadow_copy2_data->labels,
1364 shadow_copy2_data->num_volumes,
1369 static int shadow_copy2_get_shadow_copy_data(
1370 vfs_handle_struct *handle, files_struct *fsp,
1371 struct shadow_copy_data *shadow_copy2_data,
1375 const char *snapdir;
1377 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1380 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
1381 if (snapdir == NULL) {
1382 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1383 handle->conn->connectpath));
1385 talloc_free(tmp_ctx);
1388 ret = check_access_snapdir(handle, snapdir);
1390 DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
1392 talloc_free(tmp_ctx);
1396 p = SMB_VFS_NEXT_OPENDIR(handle, snapdir, NULL, 0);
1399 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1400 " - %s\n", snapdir, strerror(errno)));
1401 talloc_free(tmp_ctx);
1406 shadow_copy2_data->num_volumes = 0;
1407 shadow_copy2_data->labels = NULL;
1409 while ((d = SMB_VFS_NEXT_READDIR(handle, p, NULL))) {
1410 char snapshot[GMT_NAME_LEN+1];
1411 SHADOW_COPY_LABEL *tlabels;
1414 * ignore names not of the right form in the snapshot
1417 if (!shadow_copy2_snapshot_to_gmt(
1419 snapshot, sizeof(snapshot))) {
1421 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1422 "ignoring %s\n", d->d_name));
1425 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1426 d->d_name, snapshot));
1429 /* the caller doesn't want the labels */
1430 shadow_copy2_data->num_volumes++;
1434 tlabels = talloc_realloc(shadow_copy2_data,
1435 shadow_copy2_data->labels,
1437 shadow_copy2_data->num_volumes+1);
1438 if (tlabels == NULL) {
1439 DEBUG(0,("shadow_copy2: out of memory\n"));
1440 SMB_VFS_NEXT_CLOSEDIR(handle, p);
1441 talloc_free(tmp_ctx);
1445 strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot,
1448 shadow_copy2_data->num_volumes++;
1449 shadow_copy2_data->labels = tlabels;
1452 SMB_VFS_NEXT_CLOSEDIR(handle,p);
1454 shadow_copy2_sort_data(handle, shadow_copy2_data);
1456 talloc_free(tmp_ctx);
1460 static NTSTATUS shadow_copy2_fget_nt_acl(vfs_handle_struct *handle,
1461 struct files_struct *fsp,
1462 uint32_t security_info,
1463 TALLOC_CTX *mem_ctx,
1464 struct security_descriptor **ppdesc)
1471 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1472 fsp->fsp_name->base_name,
1473 ×tamp, &stripped)) {
1474 return map_nt_error_from_unix(errno);
1476 if (timestamp == 0) {
1477 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1481 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1482 TALLOC_FREE(stripped);
1484 return map_nt_error_from_unix(errno);
1486 status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv, security_info,
1492 static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
1494 uint32_t security_info,
1495 TALLOC_CTX *mem_ctx,
1496 struct security_descriptor **ppdesc)
1503 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1504 ×tamp, &stripped)) {
1505 return map_nt_error_from_unix(errno);
1507 if (timestamp == 0) {
1508 return SMB_VFS_NEXT_GET_NT_ACL(handle, fname, security_info,
1511 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1512 TALLOC_FREE(stripped);
1514 return map_nt_error_from_unix(errno);
1516 status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv, security_info,
1522 static int shadow_copy2_mkdir(vfs_handle_struct *handle,
1523 const char *fname, mode_t mode)
1527 int ret, saved_errno;
1530 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1531 ×tamp, &stripped)) {
1534 if (timestamp == 0) {
1535 return SMB_VFS_NEXT_MKDIR(handle, fname, mode);
1537 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1538 TALLOC_FREE(stripped);
1542 ret = SMB_VFS_NEXT_MKDIR(handle, conv, mode);
1543 saved_errno = errno;
1545 errno = saved_errno;
1549 static int shadow_copy2_rmdir(vfs_handle_struct *handle, const char *fname)
1553 int ret, saved_errno;
1556 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1557 ×tamp, &stripped)) {
1560 if (timestamp == 0) {
1561 return SMB_VFS_NEXT_RMDIR(handle, fname);
1563 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1564 TALLOC_FREE(stripped);
1568 ret = SMB_VFS_NEXT_RMDIR(handle, conv);
1569 saved_errno = errno;
1571 errno = saved_errno;
1575 static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
1580 int ret, saved_errno;
1583 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1584 ×tamp, &stripped)) {
1587 if (timestamp == 0) {
1588 return SMB_VFS_NEXT_CHFLAGS(handle, fname, flags);
1590 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1591 TALLOC_FREE(stripped);
1595 ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
1596 saved_errno = errno;
1598 errno = saved_errno;
1602 static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
1603 const char *fname, const char *aname,
1604 void *value, size_t size)
1612 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1613 ×tamp, &stripped)) {
1616 if (timestamp == 0) {
1617 return SMB_VFS_NEXT_GETXATTR(handle, fname, aname, value,
1620 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1621 TALLOC_FREE(stripped);
1625 ret = SMB_VFS_NEXT_GETXATTR(handle, conv, aname, value, size);
1626 saved_errno = errno;
1628 errno = saved_errno;
1632 static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
1634 char *list, size_t size)
1642 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1643 ×tamp, &stripped)) {
1646 if (timestamp == 0) {
1647 return SMB_VFS_NEXT_LISTXATTR(handle, fname, list, size);
1649 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1650 TALLOC_FREE(stripped);
1654 ret = SMB_VFS_NEXT_LISTXATTR(handle, conv, list, size);
1655 saved_errno = errno;
1657 errno = saved_errno;
1661 static int shadow_copy2_removexattr(vfs_handle_struct *handle,
1662 const char *fname, const char *aname)
1666 int ret, saved_errno;
1669 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1670 ×tamp, &stripped)) {
1673 if (timestamp == 0) {
1674 return SMB_VFS_NEXT_REMOVEXATTR(handle, fname, aname);
1676 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1677 TALLOC_FREE(stripped);
1681 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv, aname);
1682 saved_errno = errno;
1684 errno = saved_errno;
1688 static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
1690 const char *aname, const void *value,
1691 size_t size, int flags)
1699 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1700 ×tamp, &stripped)) {
1703 if (timestamp == 0) {
1704 return SMB_VFS_NEXT_SETXATTR(handle, fname, aname, value, size,
1707 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1708 TALLOC_FREE(stripped);
1712 ret = SMB_VFS_NEXT_SETXATTR(handle, conv, aname, value, size, flags);
1713 saved_errno = errno;
1715 errno = saved_errno;
1719 static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
1720 const char *fname, mode_t mode)
1728 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1729 ×tamp, &stripped)) {
1732 if (timestamp == 0) {
1733 return SMB_VFS_NEXT_CHMOD_ACL(handle, fname, mode);
1735 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1736 TALLOC_FREE(stripped);
1740 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv, mode);
1741 saved_errno = errno;
1743 errno = saved_errno;
1747 static int shadow_copy2_get_real_filename(struct vfs_handle_struct *handle,
1750 TALLOC_CTX *mem_ctx,
1759 DEBUG(10, ("shadow_copy2_get_real_filename called for path=[%s], "
1760 "name=[%s]\n", path, name));
1762 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
1763 ×tamp, &stripped)) {
1764 DEBUG(10, ("shadow_copy2_strip_snapshot failed\n"));
1767 if (timestamp == 0) {
1768 DEBUG(10, ("timestamp == 0\n"));
1769 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
1770 mem_ctx, found_name);
1772 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1773 TALLOC_FREE(stripped);
1775 DEBUG(10, ("shadow_copy2_convert failed\n"));
1778 DEBUG(10, ("Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
1779 "name=[%s]\n", conv, name));
1780 ret = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, conv, name,
1781 mem_ctx, found_name);
1782 DEBUG(10, ("NEXT_REAL_FILE_NAME returned %d\n", (int)ret));
1783 saved_errno = errno;
1785 errno = saved_errno;
1789 static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
1793 char *stripped = NULL;
1795 char *result = NULL;
1797 size_t rootpath_len = 0;
1799 DBG_DEBUG("Calc connect path for [%s]\n", fname);
1801 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1802 ×tamp, &stripped)) {
1805 if (timestamp == 0) {
1806 return SMB_VFS_NEXT_CONNECTPATH(handle, fname);
1809 tmp = shadow_copy2_do_convert(talloc_tos(), handle, stripped, timestamp,
1815 DBG_DEBUG("converted path is [%s] root path is [%.*s]\n", tmp,
1816 (int)rootpath_len, tmp);
1818 tmp[rootpath_len] = '\0';
1819 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
1820 if (result == NULL) {
1824 DBG_DEBUG("connect path is [%s]\n", result);
1827 saved_errno = errno;
1829 TALLOC_FREE(stripped);
1830 errno = saved_errno;
1834 static uint64_t shadow_copy2_disk_free(vfs_handle_struct *handle,
1835 const char *path, uint64_t *bsize,
1836 uint64_t *dfree, uint64_t *dsize)
1844 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
1845 ×tamp, &stripped)) {
1848 if (timestamp == 0) {
1849 return SMB_VFS_NEXT_DISK_FREE(handle, path,
1850 bsize, dfree, dsize);
1853 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1854 TALLOC_FREE(stripped);
1859 ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
1861 saved_errno = errno;
1863 errno = saved_errno;
1868 static int shadow_copy2_connect(struct vfs_handle_struct *handle,
1869 const char *service, const char *user)
1871 struct shadow_copy2_config *config;
1873 const char *snapdir;
1874 const char *gmt_format;
1875 const char *sort_order;
1876 const char *basedir;
1877 const char *mount_point;
1879 DEBUG(10, (__location__ ": cnum[%u], connectpath[%s]\n",
1880 (unsigned)handle->conn->cnum,
1881 handle->conn->connectpath));
1883 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
1888 config = talloc_zero(handle->conn, struct shadow_copy2_config);
1889 if (config == NULL) {
1890 DEBUG(0, ("talloc_zero() failed\n"));
1895 gmt_format = lp_parm_const_string(SNUM(handle->conn),
1898 config->gmt_format = talloc_strdup(config, gmt_format);
1899 if (config->gmt_format == NULL) {
1900 DEBUG(0, ("talloc_strdup() failed\n"));
1905 config->use_sscanf = lp_parm_bool(SNUM(handle->conn),
1906 "shadow", "sscanf", false);
1908 config->use_localtime = lp_parm_bool(SNUM(handle->conn),
1909 "shadow", "localtime",
1912 snapdir = lp_parm_const_string(SNUM(handle->conn),
1913 "shadow", "snapdir",
1915 config->snapdir = talloc_strdup(config, snapdir);
1916 if (config->snapdir == NULL) {
1917 DEBUG(0, ("talloc_strdup() failed\n"));
1922 config->snapdirseverywhere = lp_parm_bool(SNUM(handle->conn),
1924 "snapdirseverywhere",
1927 config->crossmountpoints = lp_parm_bool(SNUM(handle->conn),
1928 "shadow", "crossmountpoints",
1931 config->fixinodes = lp_parm_bool(SNUM(handle->conn),
1932 "shadow", "fixinodes",
1935 sort_order = lp_parm_const_string(SNUM(handle->conn),
1936 "shadow", "sort", "desc");
1937 config->sort_order = talloc_strdup(config, sort_order);
1938 if (config->sort_order == NULL) {
1939 DEBUG(0, ("talloc_strdup() failed\n"));
1944 mount_point = lp_parm_const_string(SNUM(handle->conn),
1945 "shadow", "mountpoint", NULL);
1946 if (mount_point != NULL) {
1947 if (mount_point[0] != '/') {
1948 DEBUG(1, (__location__ " Warning: 'mountpoint' is "
1949 "relative ('%s'), but it has to be an "
1950 "absolute path. Ignoring provided value.\n",
1955 p = strstr(handle->conn->connectpath, mount_point);
1956 if (p != handle->conn->connectpath) {
1957 DBG_WARNING("Warning: the share root (%s) is "
1958 "not a subdirectory of the "
1959 "specified mountpoint (%s). "
1960 "Ignoring provided value.\n",
1961 handle->conn->connectpath,
1968 if (mount_point != NULL) {
1969 config->mount_point = talloc_strdup(config, mount_point);
1970 if (config->mount_point == NULL) {
1971 DEBUG(0, (__location__ " talloc_strdup() failed\n"));
1975 config->mount_point = shadow_copy2_find_mount_point(config,
1977 if (config->mount_point == NULL) {
1978 DBG_WARNING("shadow_copy2_find_mount_point "
1979 "of the share root '%s' failed: %s\n",
1980 handle->conn->connectpath, strerror(errno));
1985 basedir = lp_parm_const_string(SNUM(handle->conn),
1986 "shadow", "basedir", NULL);
1988 if (basedir != NULL) {
1989 if (basedir[0] != '/') {
1990 DEBUG(1, (__location__ " Warning: 'basedir' is "
1991 "relative ('%s'), but it has to be an "
1992 "absolute path. Disabling basedir.\n",
1996 p = strstr(basedir, config->mount_point);
1998 DEBUG(1, ("Warning: basedir (%s) is not a "
1999 "subdirectory of the share root's "
2000 "mount point (%s). "
2001 "Disabling basedir\n",
2002 basedir, config->mount_point));
2004 config->basedir = talloc_strdup(config,
2006 if (config->basedir == NULL) {
2007 DEBUG(0, ("talloc_strdup() failed\n"));
2015 if (config->snapdirseverywhere && config->basedir != NULL) {
2016 DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
2017 "with 'snapdirseverywhere'. Disabling basedir.\n"));
2018 TALLOC_FREE(config->basedir);
2021 if (config->crossmountpoints && config->basedir != NULL) {
2022 DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
2023 "with 'crossmountpoints'. Disabling basedir.\n"));
2024 TALLOC_FREE(config->basedir);
2027 if (config->basedir == NULL) {
2028 config->basedir = config->mount_point;
2031 if (strlen(config->basedir) != strlen(handle->conn->connectpath)) {
2032 config->rel_connectpath = talloc_strdup(config,
2033 handle->conn->connectpath + strlen(config->basedir));
2034 if (config->rel_connectpath == NULL) {
2035 DEBUG(0, ("talloc_strdup() failed\n"));
2041 if (config->snapdir[0] == '/') {
2042 config->snapdir_absolute = true;
2044 if (config->snapdirseverywhere == true) {
2045 DEBUG(1, (__location__ " Warning: An absolute snapdir "
2046 "is incompatible with 'snapdirseverywhere', "
2047 "setting 'snapdirseverywhere' to false.\n"));
2048 config->snapdirseverywhere = false;
2051 if (config->crossmountpoints == true) {
2052 DEBUG(1, (__location__ " Warning: 'crossmountpoints' "
2053 "is not supported with an absolute snapdir. "
2054 "Disabling it.\n"));
2055 config->crossmountpoints = false;
2058 config->snapshot_basepath = config->snapdir;
2060 config->snapshot_basepath = talloc_asprintf(config, "%s/%s",
2061 config->mount_point, config->snapdir);
2062 if (config->snapshot_basepath == NULL) {
2063 DEBUG(0, ("talloc_asprintf() failed\n"));
2069 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
2070 " share root: '%s'\n"
2072 " mountpoint: '%s'\n"
2073 " rel share root: '%s'\n"
2075 " snapshot base path: '%s'\n"
2078 " snapdirs everywhere: %s\n"
2079 " cross mountpoints: %s\n"
2083 handle->conn->connectpath,
2085 config->mount_point,
2086 config->rel_connectpath,
2088 config->snapshot_basepath,
2090 config->use_sscanf ? "yes" : "no",
2091 config->snapdirseverywhere ? "yes" : "no",
2092 config->crossmountpoints ? "yes" : "no",
2093 config->fixinodes ? "yes" : "no",
2098 SMB_VFS_HANDLE_SET_DATA(handle, config,
2099 NULL, struct shadow_copy2_config,
2105 static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
2106 .connect_fn = shadow_copy2_connect,
2107 .opendir_fn = shadow_copy2_opendir,
2108 .disk_free_fn = shadow_copy2_disk_free,
2109 .rename_fn = shadow_copy2_rename,
2110 .link_fn = shadow_copy2_link,
2111 .symlink_fn = shadow_copy2_symlink,
2112 .stat_fn = shadow_copy2_stat,
2113 .lstat_fn = shadow_copy2_lstat,
2114 .fstat_fn = shadow_copy2_fstat,
2115 .open_fn = shadow_copy2_open,
2116 .unlink_fn = shadow_copy2_unlink,
2117 .chmod_fn = shadow_copy2_chmod,
2118 .chown_fn = shadow_copy2_chown,
2119 .chdir_fn = shadow_copy2_chdir,
2120 .ntimes_fn = shadow_copy2_ntimes,
2121 .readlink_fn = shadow_copy2_readlink,
2122 .mknod_fn = shadow_copy2_mknod,
2123 .realpath_fn = shadow_copy2_realpath,
2124 .get_nt_acl_fn = shadow_copy2_get_nt_acl,
2125 .fget_nt_acl_fn = shadow_copy2_fget_nt_acl,
2126 .get_shadow_copy_data_fn = shadow_copy2_get_shadow_copy_data,
2127 .mkdir_fn = shadow_copy2_mkdir,
2128 .rmdir_fn = shadow_copy2_rmdir,
2129 .getxattr_fn = shadow_copy2_getxattr,
2130 .listxattr_fn = shadow_copy2_listxattr,
2131 .removexattr_fn = shadow_copy2_removexattr,
2132 .setxattr_fn = shadow_copy2_setxattr,
2133 .chmod_acl_fn = shadow_copy2_chmod_acl,
2134 .chflags_fn = shadow_copy2_chflags,
2135 .get_real_filename_fn = shadow_copy2_get_real_filename,
2136 .connectpath_fn = shadow_copy2_connectpath,
2139 NTSTATUS vfs_shadow_copy2_init(void);
2140 NTSTATUS vfs_shadow_copy2_init(void)
2142 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2143 "shadow_copy2", &vfs_shadow_copy2_fns);