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
9 * Copyright (C) Rajesh Joseph 2016
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 * This is a second implemetation of a shadow copy module for exposing
28 * file system snapshots to windows clients as shadow copies.
30 * See the manual page for documentation.
34 #include "smbd/smbd.h"
35 #include "system/filesys.h"
36 #include "include/ntioctl.h"
38 #include "lib/util_path.h"
40 struct shadow_copy2_config {
46 bool snapdirseverywhere;
47 bool crossmountpoints;
50 bool snapdir_absolute;
52 char *rel_connectpath; /* share root, relative to a snapshot root */
53 char *snapshot_basepath; /* the absolute version of snapdir */
56 /* Data-structure to hold the list of snap entries */
57 struct shadow_copy2_snapentry {
60 struct shadow_copy2_snapentry *next;
61 struct shadow_copy2_snapentry *prev;
64 struct shadow_copy2_snaplist_info {
65 struct shadow_copy2_snapentry *snaplist; /* snapshot list */
66 regex_t *regex; /* Regex to filter snaps */
67 time_t fetch_time; /* snaplist update time */
72 * shadow_copy2 private structure. This structure will be
73 * used to keep module specific information
75 struct shadow_copy2_private {
76 struct shadow_copy2_config *config;
77 struct shadow_copy2_snaplist_info *snaps;
78 char *shadow_cwd; /* Absolute $cwd path. */
79 /* Absolute connectpath - can vary depending on $cwd. */
80 char *shadow_connectpath;
81 /* malloc'ed realpath return. */
82 char *shadow_realpath;
85 static int shadow_copy2_get_shadow_copy_data(
86 vfs_handle_struct *handle, files_struct *fsp,
87 struct shadow_copy_data *shadow_copy2_data,
91 *This function will create a new snapshot list entry and
92 * return to the caller. This entry will also be added to
93 * the global snapshot list.
95 * @param[in] priv shadow_copy2 specific data structure
96 * @return Newly created snapshot entry or NULL on failure
98 static struct shadow_copy2_snapentry *shadow_copy2_create_snapentry(
99 struct shadow_copy2_private *priv)
101 struct shadow_copy2_snapentry *tmpentry = NULL;
103 tmpentry = talloc_zero(priv->snaps, struct shadow_copy2_snapentry);
104 if (tmpentry == NULL) {
105 DBG_ERR("talloc_zero() failed\n");
110 DLIST_ADD(priv->snaps->snaplist, tmpentry);
116 *This function will delete the entire snaplist and reset
117 * priv->snaps->snaplist to NULL.
119 * @param[in] priv shadow_copye specific data structure
121 static void shadow_copy2_delete_snaplist(struct shadow_copy2_private *priv)
123 struct shadow_copy2_snapentry *tmp = NULL;
125 while ((tmp = priv->snaps->snaplist) != NULL) {
126 DLIST_REMOVE(priv->snaps->snaplist, tmp);
132 * Given a timestamp this function searches the global snapshot list
133 * and returns the complete snapshot directory name saved in the entry.
135 * @param[in] priv shadow_copy2 specific structure
136 * @param[in] timestamp timestamp corresponding to one of the snapshot
137 * @param[out] snap_str buffer to copy the actual snapshot name
138 * @param[in] len length of snap_str buffer
140 * @return Length of actual snapshot name, and -1 on failure
142 static ssize_t shadow_copy2_saved_snapname(struct shadow_copy2_private *priv,
143 struct tm *timestamp,
144 char *snap_str, size_t len)
146 ssize_t snaptime_len = -1;
147 struct shadow_copy2_snapentry *entry = NULL;
149 snaptime_len = strftime(snap_str, len, GMT_FORMAT, timestamp);
150 if (snaptime_len == 0) {
151 DBG_ERR("strftime failed\n");
157 for (entry = priv->snaps->snaplist; entry; entry = entry->next) {
158 if (strcmp(entry->time_fmt, snap_str) == 0) {
159 snaptime_len = snprintf(snap_str, len, "%s",
171 * This function will check if snaplist is updated or not. If snaplist
172 * is empty then it will create a new list. Each time snaplist is updated
173 * the time is recorded. If the snapshot time is greater than the snaplist
174 * update time then chances are we are working on an older list. Then discard
175 * the old list and fetch a new snaplist.
177 * @param[in] handle VFS handle struct
178 * @param[in] snap_time time of snapshot
180 * @return true if the list is updated else false
182 static bool shadow_copy2_update_snaplist(struct vfs_handle_struct *handle,
186 bool snaplist_updated = false;
187 struct files_struct fsp = {0};
188 struct smb_filename smb_fname = {0};
189 double seconds = 0.0;
190 struct shadow_copy2_private *priv = NULL;
192 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
195 seconds = difftime(snap_time, priv->snaps->fetch_time);
198 * Fetch the snapshot list if either the snaplist is empty or the
199 * required snapshot time is greater than the last fetched snaplist
202 if (seconds > 0 || (priv->snaps->snaplist == NULL)) {
203 smb_fname.base_name = discard_const_p(char, ".");
204 fsp.fsp_name = &smb_fname;
206 ret = shadow_copy2_get_shadow_copy_data(handle, &fsp,
209 snaplist_updated = true;
211 DBG_ERR("Failed to get shadow copy data\n");
216 return snaplist_updated;
219 static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
221 unsigned *pnum_offsets)
223 unsigned num_offsets;
230 while ((p = strchr(p, '/')) != NULL) {
235 offsets = talloc_array(mem_ctx, size_t, num_offsets);
236 if (offsets == NULL) {
242 while ((p = strchr(p, '/')) != NULL) {
243 offsets[num_offsets] = p-str;
249 *pnum_offsets = num_offsets;
254 * Given a timestamp, build the posix level GMT-tag string
255 * based on the configurable format.
257 static ssize_t shadow_copy2_posix_gmt_string(struct vfs_handle_struct *handle,
259 char *snaptime_string,
263 ssize_t snaptime_len;
264 struct shadow_copy2_config *config;
265 struct shadow_copy2_private *priv;
267 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
270 config = priv->config;
272 if (config->use_sscanf) {
273 snaptime_len = snprintf(snaptime_string,
276 (unsigned long)snapshot);
277 if (snaptime_len <= 0) {
278 DEBUG(10, ("snprintf failed\n"));
282 if (config->use_localtime) {
283 if (localtime_r(&snapshot, &snap_tm) == 0) {
284 DEBUG(10, ("gmtime_r failed\n"));
288 if (gmtime_r(&snapshot, &snap_tm) == 0) {
289 DEBUG(10, ("gmtime_r failed\n"));
294 if (priv->snaps->regex != NULL) {
295 snaptime_len = shadow_copy2_saved_snapname(priv,
296 &snap_tm, snaptime_string, len);
297 if (snaptime_len >= 0)
301 * If we fail to find the snapshot name, chances are
302 * that we have not updated our snaplist. Make sure the
303 * snaplist is updated.
305 if (!shadow_copy2_update_snaplist(handle, snapshot)) {
306 DBG_DEBUG("shadow_copy2_update_snaplist "
311 return shadow_copy2_saved_snapname(priv,
312 &snap_tm, snaptime_string, len);
315 snaptime_len = strftime(snaptime_string,
319 if (snaptime_len == 0) {
320 DEBUG(10, ("strftime failed\n"));
329 * Given a timestamp, build the string to insert into a path
330 * as a path component for creating the local path to the
331 * snapshot at the given timestamp of the input path.
333 * In the case of a parallel snapdir (specified with an
334 * absolute path), this is the inital portion of the
335 * local path of any snapshot file. The complete path is
336 * obtained by appending the portion of the file's path
337 * below the share root's mountpoint.
339 static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
340 struct vfs_handle_struct *handle,
343 fstring snaptime_string;
344 ssize_t snaptime_len = 0;
346 struct shadow_copy2_config *config;
347 struct shadow_copy2_private *priv;
349 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
352 config = priv->config;
354 snaptime_len = shadow_copy2_posix_gmt_string(handle,
357 sizeof(snaptime_string));
358 if (snaptime_len <= 0) {
362 if (config->snapdir_absolute) {
363 result = talloc_asprintf(mem_ctx, "%s/%s",
364 config->snapdir, snaptime_string);
366 result = talloc_asprintf(mem_ctx, "/%s/%s",
367 config->snapdir, snaptime_string);
369 if (result == NULL) {
370 DEBUG(1, (__location__ " talloc_asprintf failed\n"));
377 * Build the posix snapshot path for the connection
378 * at the given timestamp, i.e. the absolute posix path
379 * that contains the snapshot for this file system.
381 * This only applies to classical case, i.e. not
382 * to the "snapdirseverywhere" mode.
384 static char *shadow_copy2_snapshot_path(TALLOC_CTX *mem_ctx,
385 struct vfs_handle_struct *handle,
388 fstring snaptime_string;
389 ssize_t snaptime_len = 0;
391 struct shadow_copy2_private *priv;
393 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
396 snaptime_len = shadow_copy2_posix_gmt_string(handle,
399 sizeof(snaptime_string));
400 if (snaptime_len <= 0) {
404 result = talloc_asprintf(mem_ctx, "%s/%s",
405 priv->config->snapshot_basepath, snaptime_string);
406 if (result == NULL) {
407 DEBUG(1, (__location__ " talloc_asprintf failed\n"));
413 static char *make_path_absolute(TALLOC_CTX *mem_ctx,
414 struct shadow_copy2_private *priv,
417 char *newpath = NULL;
418 char *abs_path = NULL;
420 if (name[0] != '/') {
421 newpath = talloc_asprintf(mem_ctx,
425 if (newpath == NULL) {
430 abs_path = canonicalize_absolute_path(mem_ctx, name);
431 TALLOC_FREE(newpath);
435 /* Return a $cwd-relative path. */
436 static bool make_relative_path(const char *cwd, char *abs_path)
438 size_t cwd_len = strlen(cwd);
439 size_t abs_len = strlen(abs_path);
441 if (abs_len < cwd_len) {
444 if (memcmp(abs_path, cwd, cwd_len) != 0) {
447 if (abs_path[cwd_len] != '/' && abs_path[cwd_len] != '\0') {
450 if (abs_path[cwd_len] == '/') {
453 memmove(abs_path, &abs_path[cwd_len], abs_len + 1 - cwd_len);
457 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
459 char *gmt, size_t gmt_len);
462 * Check if an incoming filename is already a snapshot converted pathname.
464 * If so, it returns the pathname truncated at the snapshot point which
465 * will be used as the connectpath.
468 static int check_for_converted_path(TALLOC_CTX *mem_ctx,
469 struct vfs_handle_struct *handle,
470 struct shadow_copy2_private *priv,
472 bool *ppath_already_converted,
475 size_t snapdirlen = 0;
476 char *p = strstr_m(abs_path, priv->config->snapdir);
478 char *connect_path = NULL;
479 char snapshot[GMT_NAME_LEN+1];
481 *ppath_already_converted = false;
484 /* Must at least contain shadow:snapdir. */
488 if (priv->config->snapdir[0] == '/' &&
490 /* Absolute shadow:snapdir must be at the start. */
494 snapdirlen = strlen(priv->config->snapdir);
495 if (p[snapdirlen] != '/') {
496 /* shadow:snapdir must end as a separate component. */
500 if (p > abs_path && p[-1] != '/') {
501 /* shadow:snapdir must start as a separate component. */
506 p++; /* Move past the / */
509 * Need to return up to the next path
510 * component after the time.
511 * This will be used as the connectpath.
516 * No next path component.
519 connect_path = talloc_strdup(mem_ctx,
522 connect_path = talloc_strndup(mem_ctx,
526 if (connect_path == NULL) {
531 * Point p at the same offset in connect_path as
535 p = &connect_path[p - abs_path];
538 * Now ensure there is a time string at p.
539 * The SMB-format @GMT-token string is returned
543 if (!shadow_copy2_snapshot_to_gmt(handle,
547 TALLOC_FREE(connect_path);
551 if (pconnectpath != NULL) {
552 *pconnectpath = connect_path;
555 *ppath_already_converted = true;
557 DBG_DEBUG("path |%s| is already converted. "
558 "connect path = |%s|\n",
566 * This function does two things.
568 * 1). Checks if an incoming filename is already a
569 * snapshot converted pathname.
570 * If so, it returns the pathname truncated
571 * at the snapshot point which will be used
572 * as the connectpath, and then does an early return.
574 * 2). Checks if an incoming filename contains an
575 * SMB-layer @GMT- style timestamp.
576 * If so, it strips the timestamp, and returns
577 * both the timestamp and the stripped path
578 * (making it cwd-relative).
581 static bool shadow_copy2_strip_snapshot_internal(TALLOC_CTX *mem_ctx,
582 struct vfs_handle_struct *handle,
583 const char *orig_name,
589 time_t timestamp = 0;
592 char *stripped = NULL;
593 size_t rest_len, dst_len;
594 struct shadow_copy2_private *priv;
595 ptrdiff_t len_before_gmt;
596 const char *name = orig_name;
597 char *abs_path = NULL;
599 bool already_converted = false;
602 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
605 DEBUG(10, (__location__ ": enter path '%s'\n", name));
607 abs_path = make_path_absolute(mem_ctx, priv, name);
608 if (abs_path == NULL) {
614 DEBUG(10, (__location__ ": abs path '%s'\n", name));
616 err = check_for_converted_path(mem_ctx,
623 /* error in conversion. */
628 if (already_converted) {
633 * From here we're only looking to strip an
634 * SMB-layer @GMT- token.
637 p = strstr_m(name, "@GMT-");
639 DEBUG(11, ("@GMT not found\n"));
642 if ((p > name) && (p[-1] != '/')) {
643 /* the GMT-token does not start a path-component */
644 DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
645 p, name, (int)p[-1]));
649 len_before_gmt = p - name;
651 q = strptime(p, GMT_FORMAT, &tm);
653 DEBUG(10, ("strptime failed\n"));
657 timestamp = timegm(&tm);
658 if (timestamp == (time_t)-1) {
659 DEBUG(10, ("timestamp==-1\n"));
664 * The name consists of only the GMT token or the GMT
665 * token is at the end of the path. XP seems to send
666 * @GMT- at the end under certain circumstances even
667 * with a path prefix.
669 if (pstripped != NULL) {
670 if (len_before_gmt > 0) {
672 * There is a slash before
673 * the @GMT-. Remove it.
677 stripped = talloc_strndup(mem_ctx, name,
679 if (stripped == NULL) {
683 if (orig_name[0] != '/') {
684 if (make_relative_path(priv->shadow_cwd,
685 stripped) == false) {
686 DEBUG(10, (__location__ ": path '%s' "
687 "doesn't start with cwd '%s\n",
688 stripped, priv->shadow_cwd));
694 *pstripped = stripped;
696 *ptimestamp = timestamp;
701 * It is not a complete path component, i.e. the path
702 * component continues after the gmt-token.
704 DEBUG(10, ("q[0] = %d\n", (int)q[0]));
709 rest_len = strlen(q);
710 dst_len = len_before_gmt + rest_len;
712 if (pstripped != NULL) {
713 stripped = talloc_array(mem_ctx, char, dst_len+1);
714 if (stripped == NULL) {
719 memcpy(stripped, name, len_before_gmt);
722 memcpy(stripped + len_before_gmt, q, rest_len);
724 stripped[dst_len] = '\0';
725 if (orig_name[0] != '/') {
726 if (make_relative_path(priv->shadow_cwd,
727 stripped) == false) {
728 DEBUG(10, (__location__ ": path '%s' "
729 "doesn't start with cwd '%s\n",
730 stripped, priv->shadow_cwd));
736 *pstripped = stripped;
738 *ptimestamp = timestamp;
742 TALLOC_FREE(abs_path);
746 static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
747 struct vfs_handle_struct *handle,
748 const char *orig_name,
752 return shadow_copy2_strip_snapshot_internal(mem_ctx,
760 static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
761 vfs_handle_struct *handle)
763 char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
768 if (stat(path, &st) != 0) {
775 while ((p = strrchr(path, '/')) && p > path) {
777 if (stat(path, &st) != 0) {
781 if (st.st_dev != dev) {
791 * Convert from a name as handed in via the SMB layer
792 * and a timestamp into the local path of the snapshot
793 * of the provided file at the provided time.
794 * Also return the path in the snapshot corresponding
795 * to the file's share root.
797 static char *shadow_copy2_do_convert(TALLOC_CTX *mem_ctx,
798 struct vfs_handle_struct *handle,
799 const char *name, time_t timestamp,
800 size_t *snaproot_len)
802 struct smb_filename converted_fname;
804 size_t *slashes = NULL;
805 unsigned num_slashes;
809 char *converted = NULL;
810 size_t insertlen, connectlen = 0;
814 struct shadow_copy2_config *config;
815 struct shadow_copy2_private *priv;
816 size_t in_share_offset = 0;
818 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
821 config = priv->config;
823 DEBUG(10, ("converting '%s'\n", name));
825 if (!config->snapdirseverywhere) {
829 snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
832 if (snapshot_path == NULL) {
836 if (config->rel_connectpath == NULL) {
837 converted = talloc_asprintf(mem_ctx, "%s/%s",
838 snapshot_path, name);
840 converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
842 config->rel_connectpath,
845 if (converted == NULL) {
849 ZERO_STRUCT(converted_fname);
850 converted_fname.base_name = converted;
852 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
853 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
855 ret, ret == 0 ? "ok" : strerror(errno)));
857 DEBUG(10, ("Found %s\n", converted));
860 if (snaproot_len != NULL) {
861 *snaproot_len = strlen(snapshot_path);
862 if (config->rel_connectpath != NULL) {
864 strlen(config->rel_connectpath) + 1;
872 /* never reached ... */
875 connectlen = strlen(handle->conn->connectpath);
877 path = talloc_strdup(mem_ctx, handle->conn->connectpath);
879 path = talloc_asprintf(
880 mem_ctx, "%s/%s", handle->conn->connectpath, name);
886 pathlen = talloc_get_size(path)-1;
888 if (!shadow_copy2_find_slashes(talloc_tos(), path,
889 &slashes, &num_slashes)) {
893 insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
894 if (insert == NULL) {
897 insertlen = talloc_get_size(insert)-1;
900 * Note: We deliberatly don't expensively initialize the
901 * array with talloc_zero here: Putting zero into
902 * converted[pathlen+insertlen] below is sufficient, because
903 * in the following for loop, the insert string is inserted
904 * at various slash places. So the memory up to position
905 * pathlen+insertlen will always be initialized when the
906 * converted string is used.
908 converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
909 if (converted == NULL) {
913 if (path[pathlen-1] != '/') {
915 * Append a fake slash to find the snapshot root
918 tmp = talloc_realloc(talloc_tos(), slashes,
919 size_t, num_slashes+1);
924 slashes[num_slashes] = pathlen;
930 if (!config->crossmountpoints) {
931 min_offset = strlen(config->mount_point);
934 memcpy(converted, path, pathlen+1);
935 converted[pathlen+insertlen] = '\0';
937 ZERO_STRUCT(converted_fname);
938 converted_fname.base_name = converted;
940 for (i = num_slashes-1; i>=0; i--) {
946 if (offset < min_offset) {
951 if (offset >= connectlen) {
952 in_share_offset = offset;
955 memcpy(converted+offset, insert, insertlen);
958 memcpy(converted+offset, path + slashes[i],
959 pathlen - slashes[i]);
961 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
963 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
965 ret, ret == 0 ? "ok" : strerror(errno)));
968 if (snaproot_len != NULL) {
969 *snaproot_len = in_share_offset + insertlen;
973 if (errno == ENOTDIR) {
975 * This is a valid condition: We appended the
976 * .snaphots/@GMT.. to a file name. Just try
977 * with the upper levels.
981 if (errno != ENOENT) {
982 /* Other problem than "not found" */
991 DEBUG(10, ("Found %s\n", converted));
998 if (result == NULL) {
1001 TALLOC_FREE(converted);
1002 TALLOC_FREE(insert);
1003 TALLOC_FREE(slashes);
1005 if (saved_errno != 0) {
1006 errno = saved_errno;
1012 * Convert from a name as handed in via the SMB layer
1013 * and a timestamp into the local path of the snapshot
1014 * of the provided file at the provided time.
1016 static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
1017 struct vfs_handle_struct *handle,
1018 const char *name, time_t timestamp)
1020 return shadow_copy2_do_convert(mem_ctx, handle, name, timestamp, NULL);
1024 modify a sbuf return to ensure that inodes in the shadow directory
1025 are different from those in the main directory
1027 static void convert_sbuf(vfs_handle_struct *handle, const char *fname,
1028 SMB_STRUCT_STAT *sbuf)
1030 struct shadow_copy2_private *priv;
1032 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1035 if (priv->config->fixinodes) {
1036 /* some snapshot systems, like GPFS, return the name
1037 device:inode for the snapshot files as the current
1038 files. That breaks the 'restore' button in the shadow copy
1039 GUI, as the client gets a sharing violation.
1041 This is a crude way of allowing both files to be
1042 open at once. It has a slight chance of inode
1043 number collision, but I can't see a better approach
1044 without significant VFS changes
1046 TDB_DATA key = { .dptr = discard_const_p(uint8_t, fname),
1047 .dsize = strlen(fname) };
1050 shash = tdb_jenkins_hash(&key) & 0xFF000000;
1054 sbuf->st_ex_ino ^= shash;
1058 static DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
1059 const struct smb_filename *smb_fname,
1063 time_t timestamp = 0;
1064 char *stripped = NULL;
1066 int saved_errno = 0;
1068 struct smb_filename *conv_smb_fname = NULL;
1070 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1072 smb_fname->base_name,
1077 if (timestamp == 0) {
1078 return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
1080 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1081 TALLOC_FREE(stripped);
1085 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1090 if (conv_smb_fname == NULL) {
1094 ret = SMB_VFS_NEXT_OPENDIR(handle, conv_smb_fname, mask, attr);
1096 saved_errno = errno;
1099 TALLOC_FREE(conv_smb_fname);
1100 if (saved_errno != 0) {
1101 errno = saved_errno;
1106 static int shadow_copy2_rename(vfs_handle_struct *handle,
1107 const struct smb_filename *smb_fname_src,
1108 const struct smb_filename *smb_fname_dst)
1110 time_t timestamp_src = 0;
1111 time_t timestamp_dst = 0;
1112 char *snappath_src = NULL;
1113 char *snappath_dst = NULL;
1115 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle,
1116 smb_fname_src->base_name,
1117 ×tamp_src, NULL, &snappath_src)) {
1120 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle,
1121 smb_fname_dst->base_name,
1122 ×tamp_dst, NULL, &snappath_dst)) {
1125 if (timestamp_src != 0) {
1129 if (timestamp_dst != 0) {
1134 * Don't allow rename on already converted paths.
1136 if (snappath_src != NULL) {
1140 if (snappath_dst != NULL) {
1144 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1147 static int shadow_copy2_symlink(vfs_handle_struct *handle,
1148 const char *oldname, const char *newname)
1150 time_t timestamp_old = 0;
1151 time_t timestamp_new = 0;
1152 char *snappath_old = NULL;
1153 char *snappath_new = NULL;
1155 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, oldname,
1156 ×tamp_old, NULL, &snappath_old)) {
1159 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, newname,
1160 ×tamp_new, NULL, &snappath_new)) {
1163 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1168 * Don't allow symlinks on already converted paths.
1170 if ((snappath_old != NULL) || (snappath_new != NULL)) {
1174 return SMB_VFS_NEXT_SYMLINK(handle, oldname, newname);
1177 static int shadow_copy2_link(vfs_handle_struct *handle,
1178 const char *oldname, const char *newname)
1180 time_t timestamp_old = 0;
1181 time_t timestamp_new = 0;
1182 char *snappath_old = NULL;
1183 char *snappath_new = NULL;
1185 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, oldname,
1186 ×tamp_old, NULL, &snappath_old)) {
1189 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, newname,
1190 ×tamp_new, NULL, &snappath_new)) {
1193 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1198 * Don't allow links on already converted paths.
1200 if ((snappath_old != NULL) || (snappath_new != NULL)) {
1204 return SMB_VFS_NEXT_LINK(handle, oldname, newname);
1207 static int shadow_copy2_stat(vfs_handle_struct *handle,
1208 struct smb_filename *smb_fname)
1210 time_t timestamp = 0;
1211 char *stripped = NULL;
1213 int saved_errno = 0;
1216 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1217 smb_fname->base_name,
1218 ×tamp, &stripped)) {
1221 if (timestamp == 0) {
1222 return SMB_VFS_NEXT_STAT(handle, smb_fname);
1225 tmp = smb_fname->base_name;
1226 smb_fname->base_name = shadow_copy2_convert(
1227 talloc_tos(), handle, stripped, timestamp);
1228 TALLOC_FREE(stripped);
1230 if (smb_fname->base_name == NULL) {
1231 smb_fname->base_name = tmp;
1235 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1237 saved_errno = errno;
1240 TALLOC_FREE(smb_fname->base_name);
1241 smb_fname->base_name = tmp;
1244 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1246 if (saved_errno != 0) {
1247 errno = saved_errno;
1252 static int shadow_copy2_lstat(vfs_handle_struct *handle,
1253 struct smb_filename *smb_fname)
1255 time_t timestamp = 0;
1256 char *stripped = NULL;
1258 int saved_errno = 0;
1261 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1262 smb_fname->base_name,
1263 ×tamp, &stripped)) {
1266 if (timestamp == 0) {
1267 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1270 tmp = smb_fname->base_name;
1271 smb_fname->base_name = shadow_copy2_convert(
1272 talloc_tos(), handle, stripped, timestamp);
1273 TALLOC_FREE(stripped);
1275 if (smb_fname->base_name == NULL) {
1276 smb_fname->base_name = tmp;
1280 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1282 saved_errno = errno;
1285 TALLOC_FREE(smb_fname->base_name);
1286 smb_fname->base_name = tmp;
1289 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1291 if (saved_errno != 0) {
1292 errno = saved_errno;
1297 static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
1298 SMB_STRUCT_STAT *sbuf)
1300 time_t timestamp = 0;
1303 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1307 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1308 fsp->fsp_name->base_name,
1309 ×tamp, NULL)) {
1312 if (timestamp != 0) {
1313 convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
1318 static int shadow_copy2_open(vfs_handle_struct *handle,
1319 struct smb_filename *smb_fname, files_struct *fsp,
1320 int flags, mode_t mode)
1322 time_t timestamp = 0;
1323 char *stripped = NULL;
1325 int saved_errno = 0;
1328 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1329 smb_fname->base_name,
1330 ×tamp, &stripped)) {
1333 if (timestamp == 0) {
1334 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1337 tmp = smb_fname->base_name;
1338 smb_fname->base_name = shadow_copy2_convert(
1339 talloc_tos(), handle, stripped, timestamp);
1340 TALLOC_FREE(stripped);
1342 if (smb_fname->base_name == NULL) {
1343 smb_fname->base_name = tmp;
1347 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1349 saved_errno = errno;
1352 TALLOC_FREE(smb_fname->base_name);
1353 smb_fname->base_name = tmp;
1355 if (saved_errno != 0) {
1356 errno = saved_errno;
1361 static int shadow_copy2_unlink(vfs_handle_struct *handle,
1362 const struct smb_filename *smb_fname)
1364 time_t timestamp = 0;
1365 char *stripped = NULL;
1366 int saved_errno = 0;
1368 struct smb_filename *conv;
1370 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1371 smb_fname->base_name,
1372 ×tamp, &stripped)) {
1375 if (timestamp == 0) {
1376 return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1378 conv = cp_smb_filename(talloc_tos(), smb_fname);
1383 conv->base_name = shadow_copy2_convert(
1384 conv, handle, stripped, timestamp);
1385 TALLOC_FREE(stripped);
1386 if (conv->base_name == NULL) {
1389 ret = SMB_VFS_NEXT_UNLINK(handle, conv);
1391 saved_errno = errno;
1394 if (saved_errno != 0) {
1395 errno = saved_errno;
1400 static int shadow_copy2_chmod(vfs_handle_struct *handle,
1401 const struct smb_filename *smb_fname,
1404 time_t timestamp = 0;
1405 char *stripped = NULL;
1406 int saved_errno = 0;
1409 struct smb_filename *conv_smb_fname;
1411 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1413 smb_fname->base_name,
1418 if (timestamp == 0) {
1419 TALLOC_FREE(stripped);
1420 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1422 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1423 TALLOC_FREE(stripped);
1427 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1432 if (conv_smb_fname == NULL) {
1438 ret = SMB_VFS_NEXT_CHMOD(handle, conv_smb_fname, mode);
1440 saved_errno = errno;
1443 TALLOC_FREE(conv_smb_fname);
1444 if (saved_errno != 0) {
1445 errno = saved_errno;
1450 static int shadow_copy2_chown(vfs_handle_struct *handle,
1451 const struct smb_filename *smb_fname,
1455 time_t timestamp = 0;
1456 char *stripped = NULL;
1457 int saved_errno = 0;
1460 struct smb_filename *conv_smb_fname = NULL;
1462 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1464 smb_fname->base_name,
1469 if (timestamp == 0) {
1470 return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1472 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1473 TALLOC_FREE(stripped);
1477 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1482 if (conv_smb_fname == NULL) {
1487 ret = SMB_VFS_NEXT_CHOWN(handle, conv_smb_fname, uid, gid);
1489 saved_errno = errno;
1492 TALLOC_FREE(conv_smb_fname);
1493 if (saved_errno != 0) {
1494 errno = saved_errno;
1499 static void store_cwd_data(vfs_handle_struct *handle,
1500 const char *connectpath)
1502 struct shadow_copy2_private *priv = NULL;
1505 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1508 TALLOC_FREE(priv->shadow_cwd);
1509 cwd = SMB_VFS_NEXT_GETWD(handle);
1511 smb_panic("getwd failed\n");
1513 DBG_DEBUG("shadow cwd = %s\n", cwd);
1514 priv->shadow_cwd = talloc_strdup(priv, cwd);
1516 if (priv->shadow_cwd == NULL) {
1517 smb_panic("talloc failed\n");
1519 TALLOC_FREE(priv->shadow_connectpath);
1521 DBG_DEBUG("shadow conectpath = %s\n", connectpath);
1522 priv->shadow_connectpath = talloc_strdup(priv, connectpath);
1523 if (priv->shadow_connectpath == NULL) {
1524 smb_panic("talloc failed\n");
1529 static int shadow_copy2_chdir(vfs_handle_struct *handle,
1532 time_t timestamp = 0;
1533 char *stripped = NULL;
1534 char *snappath = NULL;
1536 int saved_errno = 0;
1538 size_t rootpath_len = 0;
1540 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, fname,
1541 ×tamp, &stripped, &snappath)) {
1544 if (stripped != NULL) {
1545 conv = shadow_copy2_do_convert(talloc_tos(),
1550 TALLOC_FREE(stripped);
1557 ret = SMB_VFS_NEXT_CHDIR(handle, fname);
1559 saved_errno = errno;
1563 if (conv != NULL && rootpath_len != 0) {
1564 conv[rootpath_len] = '\0';
1565 } else if (snappath != 0) {
1569 store_cwd_data(handle, conv);
1572 TALLOC_FREE(stripped);
1575 if (saved_errno != 0) {
1576 errno = saved_errno;
1581 static int shadow_copy2_ntimes(vfs_handle_struct *handle,
1582 const struct smb_filename *smb_fname,
1583 struct smb_file_time *ft)
1585 time_t timestamp = 0;
1586 char *stripped = NULL;
1587 int saved_errno = 0;
1589 struct smb_filename *conv;
1591 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1592 smb_fname->base_name,
1593 ×tamp, &stripped)) {
1596 if (timestamp == 0) {
1597 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1599 conv = cp_smb_filename(talloc_tos(), smb_fname);
1604 conv->base_name = shadow_copy2_convert(
1605 conv, handle, stripped, timestamp);
1606 TALLOC_FREE(stripped);
1607 if (conv->base_name == NULL) {
1610 ret = SMB_VFS_NEXT_NTIMES(handle, conv, ft);
1612 saved_errno = errno;
1615 if (saved_errno != 0) {
1616 errno = saved_errno;
1621 static int shadow_copy2_readlink(vfs_handle_struct *handle,
1622 const char *fname, char *buf, size_t bufsiz)
1624 time_t timestamp = 0;
1625 char *stripped = NULL;
1626 int saved_errno = 0;
1630 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1631 ×tamp, &stripped)) {
1634 if (timestamp == 0) {
1635 return SMB_VFS_NEXT_READLINK(handle, fname, buf, bufsiz);
1637 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1638 TALLOC_FREE(stripped);
1642 ret = SMB_VFS_NEXT_READLINK(handle, conv, buf, bufsiz);
1644 saved_errno = errno;
1647 if (saved_errno != 0) {
1648 errno = saved_errno;
1653 static int shadow_copy2_mknod(vfs_handle_struct *handle,
1654 const char *fname, mode_t mode, SMB_DEV_T dev)
1656 time_t timestamp = 0;
1657 char *stripped = NULL;
1658 int saved_errno = 0;
1662 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1663 ×tamp, &stripped)) {
1666 if (timestamp == 0) {
1667 return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
1669 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1670 TALLOC_FREE(stripped);
1674 ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
1676 saved_errno = errno;
1679 if (saved_errno != 0) {
1680 errno = saved_errno;
1685 static char *shadow_copy2_realpath(vfs_handle_struct *handle,
1688 time_t timestamp = 0;
1689 char *stripped = NULL;
1691 char *result = NULL;
1692 int saved_errno = 0;
1694 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1695 ×tamp, &stripped)) {
1698 if (timestamp == 0) {
1699 return SMB_VFS_NEXT_REALPATH(handle, fname);
1702 tmp = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1707 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
1710 if (result == NULL) {
1711 saved_errno = errno;
1714 TALLOC_FREE(stripped);
1715 if (saved_errno != 0) {
1716 errno = saved_errno;
1722 * Check whether a given directory contains a
1723 * snapshot directory as direct subdirectory.
1724 * If yes, return the path of the snapshot-subdir,
1725 * otherwise return NULL.
1727 static char *have_snapdir(struct vfs_handle_struct *handle,
1730 struct smb_filename smb_fname;
1732 struct shadow_copy2_private *priv;
1734 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1737 ZERO_STRUCT(smb_fname);
1738 smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
1739 path, priv->config->snapdir);
1740 if (smb_fname.base_name == NULL) {
1744 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1745 if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
1746 return smb_fname.base_name;
1748 TALLOC_FREE(smb_fname.base_name);
1752 static bool check_access_snapdir(struct vfs_handle_struct *handle,
1755 struct smb_filename smb_fname;
1759 ZERO_STRUCT(smb_fname);
1760 smb_fname.base_name = talloc_asprintf(talloc_tos(),
1763 if (smb_fname.base_name == NULL) {
1767 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1768 if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
1769 TALLOC_FREE(smb_fname.base_name);
1773 status = smbd_check_access_rights(handle->conn,
1777 if (!NT_STATUS_IS_OK(status)) {
1778 DEBUG(0,("user does not have list permission "
1780 smb_fname.base_name));
1781 TALLOC_FREE(smb_fname.base_name);
1784 TALLOC_FREE(smb_fname.base_name);
1789 * Find the snapshot directory (if any) for the given
1790 * filename (which is relative to the share).
1792 static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx,
1793 struct vfs_handle_struct *handle,
1794 struct smb_filename *smb_fname)
1797 const char *snapdir;
1798 struct shadow_copy2_config *config;
1799 struct shadow_copy2_private *priv;
1801 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1804 config = priv->config;
1807 * If the non-snapdisrseverywhere mode, we should not search!
1809 if (!config->snapdirseverywhere) {
1810 return config->snapshot_basepath;
1813 path = talloc_asprintf(mem_ctx, "%s/%s",
1814 handle->conn->connectpath,
1815 smb_fname->base_name);
1820 snapdir = have_snapdir(handle, path);
1821 if (snapdir != NULL) {
1826 while ((p = strrchr(path, '/')) && (p > path)) {
1830 snapdir = have_snapdir(handle, path);
1831 if (snapdir != NULL) {
1840 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
1842 char *gmt, size_t gmt_len)
1844 struct tm timestamp;
1846 unsigned long int timestamp_long;
1848 struct shadow_copy2_config *config;
1849 struct shadow_copy2_private *priv;
1850 char *tmpstr = NULL;
1852 bool converted = false;
1855 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1858 config = priv->config;
1860 fmt = config->gmt_format;
1863 * If regex is provided, then we will have to parse the
1864 * filename which will contain both the prefix and the time format.
1865 * e.g. <prefix><delimiter><time_format>
1867 if (priv->snaps->regex != NULL) {
1868 tmpstr = talloc_strdup(talloc_tos(), name);
1869 /* point "name" to the time format */
1870 name = strstr(name, priv->config->delimiter);
1874 /* Extract the prefix */
1875 tmp = strstr(tmpstr, priv->config->delimiter);
1879 ret = regexec(priv->snaps->regex, tmpstr, 0, NULL, 0);
1881 DBG_DEBUG("shadow_copy2_snapshot_to_gmt: "
1882 "no regex match for %s\n", tmpstr);
1887 ZERO_STRUCT(timestamp);
1888 if (config->use_sscanf) {
1889 if (sscanf(name, fmt, ×tamp_long) != 1) {
1890 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1891 "no sscanf match %s: %s\n",
1895 timestamp_t = timestamp_long;
1896 gmtime_r(×tamp_t, ×tamp);
1898 if (strptime(name, fmt, ×tamp) == NULL) {
1899 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1900 "no match %s: %s\n",
1904 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1907 if (config->use_localtime) {
1908 timestamp.tm_isdst = -1;
1909 timestamp_t = mktime(×tamp);
1910 gmtime_r(×tamp_t, ×tamp);
1914 strftime(gmt, gmt_len, GMT_FORMAT, ×tamp);
1918 TALLOC_FREE(tmpstr);
1922 static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
1924 return strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1927 static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
1929 return -strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1933 sort the shadow copy data in ascending or descending order
1935 static void shadow_copy2_sort_data(vfs_handle_struct *handle,
1936 struct shadow_copy_data *shadow_copy2_data)
1938 int (*cmpfunc)(const void *, const void *);
1940 struct shadow_copy2_private *priv;
1942 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1945 sort = priv->config->sort_order;
1950 if (strcmp(sort, "asc") == 0) {
1951 cmpfunc = shadow_copy2_label_cmp_asc;
1952 } else if (strcmp(sort, "desc") == 0) {
1953 cmpfunc = shadow_copy2_label_cmp_desc;
1958 if (shadow_copy2_data && shadow_copy2_data->num_volumes > 0 &&
1959 shadow_copy2_data->labels)
1961 TYPESAFE_QSORT(shadow_copy2_data->labels,
1962 shadow_copy2_data->num_volumes,
1967 static int shadow_copy2_get_shadow_copy_data(
1968 vfs_handle_struct *handle, files_struct *fsp,
1969 struct shadow_copy_data *shadow_copy2_data,
1973 const char *snapdir;
1974 struct smb_filename *snapdir_smb_fname = NULL;
1976 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1977 struct shadow_copy2_private *priv = NULL;
1978 struct shadow_copy2_snapentry *tmpentry = NULL;
1979 bool get_snaplist = false;
1980 bool access_granted = false;
1983 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
1984 if (snapdir == NULL) {
1985 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1986 handle->conn->connectpath));
1991 access_granted = check_access_snapdir(handle, snapdir);
1992 if (!access_granted) {
1993 DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
1998 snapdir_smb_fname = synthetic_smb_fname(talloc_tos(),
2002 fsp->fsp_name->flags);
2003 if (snapdir_smb_fname == NULL) {
2008 p = SMB_VFS_NEXT_OPENDIR(handle, snapdir_smb_fname, NULL, 0);
2011 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
2012 " - %s\n", snapdir, strerror(errno)));
2017 if (shadow_copy2_data != NULL) {
2018 shadow_copy2_data->num_volumes = 0;
2019 shadow_copy2_data->labels = NULL;
2022 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
2026 * Normally this function is called twice once with labels = false and
2027 * then with labels = true. When labels is false it will return the
2028 * number of volumes so that the caller can allocate memory for that
2029 * many labels. Therefore to eliminate snaplist both the times it is
2030 * good to check if labels is set or not.
2032 * shadow_copy2_data is NULL when we only want to update the list and
2033 * don't want any labels.
2035 if ((priv->snaps->regex != NULL) && (labels || shadow_copy2_data == NULL)) {
2036 get_snaplist = true;
2037 /* Reset the global snaplist */
2038 shadow_copy2_delete_snaplist(priv);
2040 /* Set the current time as snaplist update time */
2041 time(&(priv->snaps->fetch_time));
2044 while ((d = SMB_VFS_NEXT_READDIR(handle, p, NULL))) {
2045 char snapshot[GMT_NAME_LEN+1];
2046 SHADOW_COPY_LABEL *tlabels;
2049 * ignore names not of the right form in the snapshot
2052 if (!shadow_copy2_snapshot_to_gmt(
2054 snapshot, sizeof(snapshot))) {
2056 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
2057 "ignoring %s\n", d->d_name));
2060 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
2061 d->d_name, snapshot));
2065 * Create a snap entry for each successful
2068 tmpentry = shadow_copy2_create_snapentry(priv);
2069 if (tmpentry == NULL) {
2070 DBG_ERR("talloc_zero() failed\n");
2073 tmpentry->snapname = talloc_strdup(tmpentry, d->d_name);
2074 tmpentry->time_fmt = talloc_strdup(tmpentry, snapshot);
2077 if (shadow_copy2_data == NULL) {
2082 /* the caller doesn't want the labels */
2083 shadow_copy2_data->num_volumes++;
2087 tlabels = talloc_realloc(shadow_copy2_data,
2088 shadow_copy2_data->labels,
2090 shadow_copy2_data->num_volumes+1);
2091 if (tlabels == NULL) {
2092 DEBUG(0,("shadow_copy2: out of memory\n"));
2093 SMB_VFS_NEXT_CLOSEDIR(handle, p);
2097 strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot,
2100 shadow_copy2_data->num_volumes++;
2101 shadow_copy2_data->labels = tlabels;
2104 SMB_VFS_NEXT_CLOSEDIR(handle,p);
2106 shadow_copy2_sort_data(handle, shadow_copy2_data);
2110 TALLOC_FREE(tmp_ctx);
2114 static NTSTATUS shadow_copy2_fget_nt_acl(vfs_handle_struct *handle,
2115 struct files_struct *fsp,
2116 uint32_t security_info,
2117 TALLOC_CTX *mem_ctx,
2118 struct security_descriptor **ppdesc)
2120 time_t timestamp = 0;
2121 char *stripped = NULL;
2124 struct smb_filename *smb_fname = NULL;
2126 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
2127 fsp->fsp_name->base_name,
2128 ×tamp, &stripped)) {
2129 return map_nt_error_from_unix(errno);
2131 if (timestamp == 0) {
2132 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2136 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2137 TALLOC_FREE(stripped);
2139 return map_nt_error_from_unix(errno);
2141 smb_fname = synthetic_smb_fname(talloc_tos(),
2145 fsp->fsp_name->flags);
2146 if (smb_fname == NULL) {
2148 return NT_STATUS_NO_MEMORY;
2151 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2154 TALLOC_FREE(smb_fname);
2158 static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
2159 const struct smb_filename *smb_fname,
2160 uint32_t security_info,
2161 TALLOC_CTX *mem_ctx,
2162 struct security_descriptor **ppdesc)
2164 time_t timestamp = 0;
2165 char *stripped = NULL;
2168 struct smb_filename *conv_smb_fname = NULL;
2170 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2172 smb_fname->base_name,
2175 return map_nt_error_from_unix(errno);
2177 if (timestamp == 0) {
2178 return SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2181 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2182 TALLOC_FREE(stripped);
2184 return map_nt_error_from_unix(errno);
2186 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2191 if (conv_smb_fname == NULL) {
2193 return NT_STATUS_NO_MEMORY;
2195 status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv_smb_fname, security_info,
2198 TALLOC_FREE(conv_smb_fname);
2202 static int shadow_copy2_mkdir(vfs_handle_struct *handle,
2203 const struct smb_filename *smb_fname,
2206 time_t timestamp = 0;
2207 char *stripped = NULL;
2208 int saved_errno = 0;
2211 struct smb_filename *conv_smb_fname = NULL;
2213 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2215 smb_fname->base_name,
2220 if (timestamp == 0) {
2221 return SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
2223 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2224 TALLOC_FREE(stripped);
2228 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2233 if (conv_smb_fname == NULL) {
2237 ret = SMB_VFS_NEXT_MKDIR(handle, conv_smb_fname, mode);
2239 saved_errno = errno;
2242 TALLOC_FREE(conv_smb_fname);
2243 if (saved_errno != 0) {
2244 errno = saved_errno;
2249 static int shadow_copy2_rmdir(vfs_handle_struct *handle,
2250 const struct smb_filename *smb_fname)
2252 time_t timestamp = 0;
2253 char *stripped = NULL;
2254 int saved_errno = 0;
2257 struct smb_filename *conv_smb_fname = NULL;
2259 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2261 smb_fname->base_name,
2266 if (timestamp == 0) {
2267 return SMB_VFS_NEXT_RMDIR(handle, smb_fname);
2269 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2270 TALLOC_FREE(stripped);
2274 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2279 if (conv_smb_fname == NULL) {
2283 ret = SMB_VFS_NEXT_RMDIR(handle, conv_smb_fname);
2285 saved_errno = errno;
2287 TALLOC_FREE(conv_smb_fname);
2289 if (saved_errno != 0) {
2290 errno = saved_errno;
2295 static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
2298 time_t timestamp = 0;
2299 char *stripped = NULL;
2300 int saved_errno = 0;
2304 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2305 ×tamp, &stripped)) {
2308 if (timestamp == 0) {
2309 return SMB_VFS_NEXT_CHFLAGS(handle, fname, flags);
2311 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2312 TALLOC_FREE(stripped);
2316 ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
2318 saved_errno = errno;
2321 if (saved_errno != 0) {
2322 errno = saved_errno;
2327 static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
2328 const char *fname, const char *aname,
2329 void *value, size_t size)
2331 time_t timestamp = 0;
2332 char *stripped = NULL;
2334 int saved_errno = 0;
2337 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2338 ×tamp, &stripped)) {
2341 if (timestamp == 0) {
2342 return SMB_VFS_NEXT_GETXATTR(handle, fname, aname, value,
2345 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2346 TALLOC_FREE(stripped);
2350 ret = SMB_VFS_NEXT_GETXATTR(handle, conv, aname, value, size);
2352 saved_errno = errno;
2355 if (saved_errno != 0) {
2356 errno = saved_errno;
2361 static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
2363 char *list, size_t size)
2365 time_t timestamp = 0;
2366 char *stripped = NULL;
2368 int saved_errno = 0;
2371 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2372 ×tamp, &stripped)) {
2375 if (timestamp == 0) {
2376 return SMB_VFS_NEXT_LISTXATTR(handle, fname, list, size);
2378 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2379 TALLOC_FREE(stripped);
2383 ret = SMB_VFS_NEXT_LISTXATTR(handle, conv, list, size);
2385 saved_errno = errno;
2388 if (saved_errno != 0) {
2389 errno = saved_errno;
2394 static int shadow_copy2_removexattr(vfs_handle_struct *handle,
2395 const char *fname, const char *aname)
2397 time_t timestamp = 0;
2398 char *stripped = NULL;
2399 int saved_errno = 0;
2403 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2404 ×tamp, &stripped)) {
2407 if (timestamp == 0) {
2408 return SMB_VFS_NEXT_REMOVEXATTR(handle, fname, aname);
2410 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2411 TALLOC_FREE(stripped);
2415 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv, aname);
2417 saved_errno = errno;
2420 if (saved_errno != 0) {
2421 errno = saved_errno;
2426 static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
2428 const char *aname, const void *value,
2429 size_t size, int flags)
2431 time_t timestamp = 0;
2432 char *stripped = NULL;
2434 int saved_errno = 0;
2437 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2438 ×tamp, &stripped)) {
2441 if (timestamp == 0) {
2442 return SMB_VFS_NEXT_SETXATTR(handle, fname, aname, value, size,
2445 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2446 TALLOC_FREE(stripped);
2450 ret = SMB_VFS_NEXT_SETXATTR(handle, conv, aname, value, size, flags);
2452 saved_errno = errno;
2455 if (saved_errno != 0) {
2456 errno = saved_errno;
2461 static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
2462 const struct smb_filename *smb_fname,
2465 time_t timestamp = 0;
2466 char *stripped = NULL;
2468 int saved_errno = 0;
2470 struct smb_filename *conv_smb_fname = NULL;
2472 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2474 smb_fname->base_name,
2479 if (timestamp == 0) {
2480 return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2482 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2483 TALLOC_FREE(stripped);
2487 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2492 if (conv_smb_fname == NULL) {
2497 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv_smb_fname, mode);
2499 saved_errno = errno;
2502 TALLOC_FREE(conv_smb_fname);
2503 if (saved_errno != 0) {
2504 errno = saved_errno;
2509 static int shadow_copy2_get_real_filename(struct vfs_handle_struct *handle,
2512 TALLOC_CTX *mem_ctx,
2515 time_t timestamp = 0;
2516 char *stripped = NULL;
2518 int saved_errno = 0;
2521 DEBUG(10, ("shadow_copy2_get_real_filename called for path=[%s], "
2522 "name=[%s]\n", path, name));
2524 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2525 ×tamp, &stripped)) {
2526 DEBUG(10, ("shadow_copy2_strip_snapshot failed\n"));
2529 if (timestamp == 0) {
2530 DEBUG(10, ("timestamp == 0\n"));
2531 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
2532 mem_ctx, found_name);
2534 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2535 TALLOC_FREE(stripped);
2537 DEBUG(10, ("shadow_copy2_convert failed\n"));
2540 DEBUG(10, ("Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
2541 "name=[%s]\n", conv, name));
2542 ret = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, conv, name,
2543 mem_ctx, found_name);
2544 DEBUG(10, ("NEXT_REAL_FILE_NAME returned %d\n", (int)ret));
2546 saved_errno = errno;
2549 if (saved_errno != 0) {
2550 errno = saved_errno;
2555 static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
2558 time_t timestamp = 0;
2559 char *stripped = NULL;
2561 char *result = NULL;
2562 char *parent_dir = NULL;
2563 int saved_errno = 0;
2564 size_t rootpath_len = 0;
2565 struct shadow_copy2_private *priv = NULL;
2567 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
2570 DBG_DEBUG("Calc connect path for [%s]\n", fname);
2572 if (priv->shadow_connectpath != NULL) {
2573 DBG_DEBUG("cached connect path is [%s]\n",
2574 priv->shadow_connectpath);
2575 return priv->shadow_connectpath;
2578 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2579 ×tamp, &stripped)) {
2582 if (timestamp == 0) {
2583 return SMB_VFS_NEXT_CONNECTPATH(handle, fname);
2586 tmp = shadow_copy2_do_convert(talloc_tos(), handle, stripped, timestamp,
2589 if (errno != ENOENT) {
2594 * If the converted path does not exist, and converting
2595 * the parent yields something that does exist, then
2596 * this path refers to something that has not been
2597 * created yet, relative to the parent path.
2598 * The snapshot finding is relative to the parent.
2599 * (usually snapshots are read/only but this is not
2600 * necessarily true).
2601 * This code also covers getting a wildcard in the
2602 * last component, because this function is called
2603 * prior to sanitizing the path, and in SMB1 we may
2604 * get wildcards in path names.
2606 if (!parent_dirname(talloc_tos(), stripped, &parent_dir,
2612 tmp = shadow_copy2_do_convert(talloc_tos(), handle, parent_dir,
2613 timestamp, &rootpath_len);
2619 DBG_DEBUG("converted path is [%s] root path is [%.*s]\n", tmp,
2620 (int)rootpath_len, tmp);
2622 tmp[rootpath_len] = '\0';
2623 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
2624 if (result == NULL) {
2629 * SMB_VFS_NEXT_REALPATH returns a malloc'ed string.
2630 * Don't leak memory.
2632 SAFE_FREE(priv->shadow_realpath);
2633 priv->shadow_realpath = result;
2635 DBG_DEBUG("connect path is [%s]\n", result);
2638 if (result == NULL) {
2639 saved_errno = errno;
2642 TALLOC_FREE(stripped);
2643 TALLOC_FREE(parent_dir);
2644 if (saved_errno != 0) {
2645 errno = saved_errno;
2650 static uint64_t shadow_copy2_disk_free(vfs_handle_struct *handle,
2651 const char *path, uint64_t *bsize,
2652 uint64_t *dfree, uint64_t *dsize)
2654 time_t timestamp = 0;
2655 char *stripped = NULL;
2657 int saved_errno = 0;
2660 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2661 ×tamp, &stripped)) {
2664 if (timestamp == 0) {
2665 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2666 bsize, dfree, dsize);
2669 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2670 TALLOC_FREE(stripped);
2675 ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
2678 saved_errno = errno;
2681 if (saved_errno != 0) {
2682 errno = saved_errno;
2688 static int shadow_copy2_get_quota(vfs_handle_struct *handle, const char *path,
2689 enum SMB_QUOTA_TYPE qtype, unid_t id,
2692 time_t timestamp = 0;
2693 char *stripped = NULL;
2695 int saved_errno = 0;
2698 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path, ×tamp,
2702 if (timestamp == 0) {
2703 return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
2706 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2707 TALLOC_FREE(stripped);
2712 ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv, qtype, id, dq);
2715 saved_errno = errno;
2718 if (saved_errno != 0) {
2719 errno = saved_errno;
2725 static int shadow_copy2_private_destructor(struct shadow_copy2_private *priv)
2727 SAFE_FREE(priv->shadow_realpath);
2731 static int shadow_copy2_connect(struct vfs_handle_struct *handle,
2732 const char *service, const char *user)
2734 struct shadow_copy2_config *config;
2735 struct shadow_copy2_private *priv;
2737 const char *snapdir;
2738 const char *snapprefix = NULL;
2739 const char *delimiter;
2740 const char *gmt_format;
2741 const char *sort_order;
2742 const char *basedir = NULL;
2743 const char *snapsharepath = NULL;
2744 const char *mount_point;
2746 DEBUG(10, (__location__ ": cnum[%u], connectpath[%s]\n",
2747 (unsigned)handle->conn->cnum,
2748 handle->conn->connectpath));
2750 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
2755 priv = talloc_zero(handle->conn, struct shadow_copy2_private);
2757 DBG_ERR("talloc_zero() failed\n");
2762 talloc_set_destructor(priv, shadow_copy2_private_destructor);
2764 priv->snaps = talloc_zero(priv, struct shadow_copy2_snaplist_info);
2765 if (priv->snaps == NULL) {
2766 DBG_ERR("talloc_zero() failed\n");
2771 config = talloc_zero(priv, struct shadow_copy2_config);
2772 if (config == NULL) {
2773 DEBUG(0, ("talloc_zero() failed\n"));
2778 priv->config = config;
2780 gmt_format = lp_parm_const_string(SNUM(handle->conn),
2783 config->gmt_format = talloc_strdup(config, gmt_format);
2784 if (config->gmt_format == NULL) {
2785 DEBUG(0, ("talloc_strdup() failed\n"));
2790 /* config->gmt_format must not contain a path separator. */
2791 if (strchr(config->gmt_format, '/') != NULL) {
2792 DEBUG(0, ("shadow:format %s must not contain a /"
2793 "character. Unable to initialize module.\n",
2794 config->gmt_format));
2799 config->use_sscanf = lp_parm_bool(SNUM(handle->conn),
2800 "shadow", "sscanf", false);
2802 config->use_localtime = lp_parm_bool(SNUM(handle->conn),
2803 "shadow", "localtime",
2806 snapdir = lp_parm_const_string(SNUM(handle->conn),
2807 "shadow", "snapdir",
2809 config->snapdir = talloc_strdup(config, snapdir);
2810 if (config->snapdir == NULL) {
2811 DEBUG(0, ("talloc_strdup() failed\n"));
2816 snapprefix = lp_parm_const_string(SNUM(handle->conn),
2817 "shadow", "snapprefix",
2819 if (snapprefix != NULL) {
2820 priv->snaps->regex = talloc_zero(priv->snaps, regex_t);
2821 if (priv->snaps->regex == NULL) {
2822 DBG_ERR("talloc_zero() failed\n");
2827 /* pre-compute regex rule for matching pattern later */
2828 ret = regcomp(priv->snaps->regex, snapprefix, 0);
2830 DBG_ERR("Failed to create regex object\n");
2835 delimiter = lp_parm_const_string(SNUM(handle->conn),
2836 "shadow", "delimiter",
2838 if (delimiter != NULL) {
2839 priv->config->delimiter = talloc_strdup(priv->config, delimiter);
2840 if (priv->config->delimiter == NULL) {
2841 DBG_ERR("talloc_strdup() failed\n");
2847 config->snapdirseverywhere = lp_parm_bool(SNUM(handle->conn),
2849 "snapdirseverywhere",
2852 config->crossmountpoints = lp_parm_bool(SNUM(handle->conn),
2853 "shadow", "crossmountpoints",
2856 if (config->crossmountpoints && !config->snapdirseverywhere) {
2857 DBG_WARNING("Warning: 'crossmountpoints' depends on "
2858 "'snapdirseverywhere'. Disabling crossmountpoints.\n");
2861 config->fixinodes = lp_parm_bool(SNUM(handle->conn),
2862 "shadow", "fixinodes",
2865 sort_order = lp_parm_const_string(SNUM(handle->conn),
2866 "shadow", "sort", "desc");
2867 config->sort_order = talloc_strdup(config, sort_order);
2868 if (config->sort_order == NULL) {
2869 DEBUG(0, ("talloc_strdup() failed\n"));
2874 mount_point = lp_parm_const_string(SNUM(handle->conn),
2875 "shadow", "mountpoint", NULL);
2876 if (mount_point != NULL) {
2877 if (mount_point[0] != '/') {
2878 DEBUG(1, (__location__ " Warning: 'mountpoint' is "
2879 "relative ('%s'), but it has to be an "
2880 "absolute path. Ignoring provided value.\n",
2885 p = strstr(handle->conn->connectpath, mount_point);
2886 if (p != handle->conn->connectpath) {
2887 DBG_WARNING("Warning: the share root (%s) is "
2888 "not a subdirectory of the "
2889 "specified mountpoint (%s). "
2890 "Ignoring provided value.\n",
2891 handle->conn->connectpath,
2898 if (mount_point != NULL) {
2899 config->mount_point = talloc_strdup(config, mount_point);
2900 if (config->mount_point == NULL) {
2901 DEBUG(0, (__location__ " talloc_strdup() failed\n"));
2905 config->mount_point = shadow_copy2_find_mount_point(config,
2907 if (config->mount_point == NULL) {
2908 DBG_WARNING("shadow_copy2_find_mount_point "
2909 "of the share root '%s' failed: %s\n",
2910 handle->conn->connectpath, strerror(errno));
2915 basedir = lp_parm_const_string(SNUM(handle->conn),
2916 "shadow", "basedir", NULL);
2918 if (basedir != NULL) {
2919 if (basedir[0] != '/') {
2920 DEBUG(1, (__location__ " Warning: 'basedir' is "
2921 "relative ('%s'), but it has to be an "
2922 "absolute path. Disabling basedir.\n",
2927 p = strstr(basedir, config->mount_point);
2929 DEBUG(1, ("Warning: basedir (%s) is not a "
2930 "subdirectory of the share root's "
2931 "mount point (%s). "
2932 "Disabling basedir\n",
2933 basedir, config->mount_point));
2939 if (config->snapdirseverywhere && basedir != NULL) {
2940 DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
2941 "with 'snapdirseverywhere'. Disabling basedir.\n"));
2945 snapsharepath = lp_parm_const_string(SNUM(handle->conn), "shadow",
2946 "snapsharepath", NULL);
2947 if (snapsharepath != NULL) {
2948 if (snapsharepath[0] == '/') {
2949 DBG_WARNING("Warning: 'snapsharepath' is "
2950 "absolute ('%s'), but it has to be a "
2951 "relative path. Disabling snapsharepath.\n",
2953 snapsharepath = NULL;
2955 if (config->snapdirseverywhere && snapsharepath != NULL) {
2956 DBG_WARNING("Warning: 'snapsharepath' is incompatible "
2957 "with 'snapdirseverywhere'. Disabling "
2958 "snapsharepath.\n");
2959 snapsharepath = NULL;
2963 if (basedir != NULL && snapsharepath != NULL) {
2964 DBG_WARNING("Warning: 'snapsharepath' is incompatible with "
2965 "'basedir'. Disabling snapsharepath\n");
2966 snapsharepath = NULL;
2969 if (snapsharepath != NULL) {
2970 config->rel_connectpath = talloc_strdup(config, snapsharepath);
2971 if (config->rel_connectpath == NULL) {
2972 DBG_ERR("talloc_strdup() failed\n");
2978 if (basedir == NULL) {
2979 basedir = config->mount_point;
2982 if (config->rel_connectpath == NULL &&
2983 strlen(basedir) < strlen(handle->conn->connectpath)) {
2984 config->rel_connectpath = talloc_strdup(config,
2985 handle->conn->connectpath + strlen(basedir));
2986 if (config->rel_connectpath == NULL) {
2987 DEBUG(0, ("talloc_strdup() failed\n"));
2993 if (config->snapdir[0] == '/') {
2994 config->snapdir_absolute = true;
2996 if (config->snapdirseverywhere == true) {
2997 DEBUG(1, (__location__ " Warning: An absolute snapdir "
2998 "is incompatible with 'snapdirseverywhere', "
2999 "setting 'snapdirseverywhere' to false.\n"));
3000 config->snapdirseverywhere = false;
3003 if (config->crossmountpoints == true) {
3004 DEBUG(1, (__location__ " Warning: 'crossmountpoints' "
3005 "is not supported with an absolute snapdir. "
3006 "Disabling it.\n"));
3007 config->crossmountpoints = false;
3010 config->snapshot_basepath = config->snapdir;
3012 config->snapshot_basepath = talloc_asprintf(config, "%s/%s",
3013 config->mount_point, config->snapdir);
3014 if (config->snapshot_basepath == NULL) {
3015 DEBUG(0, ("talloc_asprintf() failed\n"));
3021 trim_string(config->mount_point, NULL, "/");
3022 trim_string(config->rel_connectpath, "/", "/");
3023 trim_string(config->snapdir, NULL, "/");
3024 trim_string(config->snapshot_basepath, NULL, "/");
3026 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
3027 " share root: '%s'\n"
3028 " mountpoint: '%s'\n"
3029 " rel share root: '%s'\n"
3031 " snapprefix: '%s'\n"
3032 " delimiter: '%s'\n"
3033 " snapshot base path: '%s'\n"
3036 " snapdirs everywhere: %s\n"
3037 " cross mountpoints: %s\n"
3041 handle->conn->connectpath,
3042 config->mount_point,
3043 config->rel_connectpath,
3047 config->snapshot_basepath,
3049 config->use_sscanf ? "yes" : "no",
3050 config->snapdirseverywhere ? "yes" : "no",
3051 config->crossmountpoints ? "yes" : "no",
3052 config->fixinodes ? "yes" : "no",
3057 SMB_VFS_HANDLE_SET_DATA(handle, priv,
3058 NULL, struct shadow_copy2_private,
3064 static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
3065 .connect_fn = shadow_copy2_connect,
3066 .opendir_fn = shadow_copy2_opendir,
3067 .disk_free_fn = shadow_copy2_disk_free,
3068 .get_quota_fn = shadow_copy2_get_quota,
3069 .rename_fn = shadow_copy2_rename,
3070 .link_fn = shadow_copy2_link,
3071 .symlink_fn = shadow_copy2_symlink,
3072 .stat_fn = shadow_copy2_stat,
3073 .lstat_fn = shadow_copy2_lstat,
3074 .fstat_fn = shadow_copy2_fstat,
3075 .open_fn = shadow_copy2_open,
3076 .unlink_fn = shadow_copy2_unlink,
3077 .chmod_fn = shadow_copy2_chmod,
3078 .chown_fn = shadow_copy2_chown,
3079 .chdir_fn = shadow_copy2_chdir,
3080 .ntimes_fn = shadow_copy2_ntimes,
3081 .readlink_fn = shadow_copy2_readlink,
3082 .mknod_fn = shadow_copy2_mknod,
3083 .realpath_fn = shadow_copy2_realpath,
3084 .get_nt_acl_fn = shadow_copy2_get_nt_acl,
3085 .fget_nt_acl_fn = shadow_copy2_fget_nt_acl,
3086 .get_shadow_copy_data_fn = shadow_copy2_get_shadow_copy_data,
3087 .mkdir_fn = shadow_copy2_mkdir,
3088 .rmdir_fn = shadow_copy2_rmdir,
3089 .getxattr_fn = shadow_copy2_getxattr,
3090 .listxattr_fn = shadow_copy2_listxattr,
3091 .removexattr_fn = shadow_copy2_removexattr,
3092 .setxattr_fn = shadow_copy2_setxattr,
3093 .chmod_acl_fn = shadow_copy2_chmod_acl,
3094 .chflags_fn = shadow_copy2_chflags,
3095 .get_real_filename_fn = shadow_copy2_get_real_filename,
3096 .connectpath_fn = shadow_copy2_connectpath,
3099 NTSTATUS vfs_shadow_copy2_init(void);
3100 NTSTATUS vfs_shadow_copy2_init(void)
3102 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
3103 "shadow_copy2", &vfs_shadow_copy2_fns);