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;
83 static int shadow_copy2_get_shadow_copy_data(
84 vfs_handle_struct *handle, files_struct *fsp,
85 struct shadow_copy_data *shadow_copy2_data,
89 *This function will create a new snapshot list entry and
90 * return to the caller. This entry will also be added to
91 * the global snapshot list.
93 * @param[in] priv shadow_copy2 specific data structure
94 * @return Newly created snapshot entry or NULL on failure
96 static struct shadow_copy2_snapentry *shadow_copy2_create_snapentry(
97 struct shadow_copy2_private *priv)
99 struct shadow_copy2_snapentry *tmpentry = NULL;
101 tmpentry = talloc_zero(priv->snaps, struct shadow_copy2_snapentry);
102 if (tmpentry == NULL) {
103 DBG_ERR("talloc_zero() failed\n");
108 DLIST_ADD(priv->snaps->snaplist, tmpentry);
114 *This function will delete the entire snaplist and reset
115 * priv->snaps->snaplist to NULL.
117 * @param[in] priv shadow_copye specific data structure
119 static void shadow_copy2_delete_snaplist(struct shadow_copy2_private *priv)
121 struct shadow_copy2_snapentry *tmp = NULL;
123 while ((tmp = priv->snaps->snaplist) != NULL) {
124 DLIST_REMOVE(priv->snaps->snaplist, tmp);
130 * Given a timestamp this function searches the global snapshot list
131 * and returns the complete snapshot directory name saved in the entry.
133 * @param[in] priv shadow_copy2 specific structure
134 * @param[in] timestamp timestamp corresponding to one of the snapshot
135 * @param[out] snap_str buffer to copy the actual snapshot name
136 * @param[in] len length of snap_str buffer
138 * @return Length of actual snapshot name, and -1 on failure
140 static ssize_t shadow_copy2_saved_snapname(struct shadow_copy2_private *priv,
141 struct tm *timestamp,
142 char *snap_str, size_t len)
144 ssize_t snaptime_len = -1;
145 struct shadow_copy2_snapentry *entry = NULL;
147 snaptime_len = strftime(snap_str, len, GMT_FORMAT, timestamp);
148 if (snaptime_len == 0) {
149 DBG_ERR("strftime failed\n");
155 for (entry = priv->snaps->snaplist; entry; entry = entry->next) {
156 if (strcmp(entry->time_fmt, snap_str) == 0) {
157 snaptime_len = snprintf(snap_str, len, "%s",
169 * This function will check if snaplist is updated or not. If snaplist
170 * is empty then it will create a new list. Each time snaplist is updated
171 * the time is recorded. If the snapshot time is greater than the snaplist
172 * update time then chances are we are working on an older list. Then discard
173 * the old list and fetch a new snaplist.
175 * @param[in] handle VFS handle struct
176 * @param[in] snap_time time of snapshot
178 * @return true if the list is updated else false
180 static bool shadow_copy2_update_snaplist(struct vfs_handle_struct *handle,
184 bool snaplist_updated = false;
185 struct files_struct fsp = {0};
186 struct smb_filename smb_fname = {0};
187 double seconds = 0.0;
188 struct shadow_copy2_private *priv = NULL;
190 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
193 seconds = difftime(snap_time, priv->snaps->fetch_time);
196 * Fetch the snapshot list if either the snaplist is empty or the
197 * required snapshot time is greater than the last fetched snaplist
200 if (seconds > 0 || (priv->snaps->snaplist == NULL)) {
201 smb_fname.base_name = discard_const_p(char, ".");
202 fsp.fsp_name = &smb_fname;
204 ret = shadow_copy2_get_shadow_copy_data(handle, &fsp,
207 snaplist_updated = true;
209 DBG_ERR("Failed to get shadow copy data\n");
214 return snaplist_updated;
217 static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
219 unsigned *pnum_offsets)
221 unsigned num_offsets;
228 while ((p = strchr(p, '/')) != NULL) {
233 offsets = talloc_array(mem_ctx, size_t, num_offsets);
234 if (offsets == NULL) {
240 while ((p = strchr(p, '/')) != NULL) {
241 offsets[num_offsets] = p-str;
247 *pnum_offsets = num_offsets;
252 * Given a timestamp, build the posix level GMT-tag string
253 * based on the configurable format.
255 static ssize_t shadow_copy2_posix_gmt_string(struct vfs_handle_struct *handle,
257 char *snaptime_string,
261 ssize_t snaptime_len;
262 struct shadow_copy2_config *config;
263 struct shadow_copy2_private *priv;
265 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
268 config = priv->config;
270 if (config->use_sscanf) {
271 snaptime_len = snprintf(snaptime_string,
274 (unsigned long)snapshot);
275 if (snaptime_len <= 0) {
276 DEBUG(10, ("snprintf failed\n"));
280 if (config->use_localtime) {
281 if (localtime_r(&snapshot, &snap_tm) == 0) {
282 DEBUG(10, ("gmtime_r failed\n"));
286 if (gmtime_r(&snapshot, &snap_tm) == 0) {
287 DEBUG(10, ("gmtime_r failed\n"));
292 if (priv->snaps->regex != NULL) {
293 snaptime_len = shadow_copy2_saved_snapname(priv,
294 &snap_tm, snaptime_string, len);
295 if (snaptime_len >= 0)
299 * If we fail to find the snapshot name, chances are
300 * that we have not updated our snaplist. Make sure the
301 * snaplist is updated.
303 if (!shadow_copy2_update_snaplist(handle, snapshot)) {
304 DBG_DEBUG("shadow_copy2_update_snaplist "
309 return shadow_copy2_saved_snapname(priv,
310 &snap_tm, snaptime_string, len);
313 snaptime_len = strftime(snaptime_string,
317 if (snaptime_len == 0) {
318 DEBUG(10, ("strftime failed\n"));
327 * Given a timestamp, build the string to insert into a path
328 * as a path component for creating the local path to the
329 * snapshot at the given timestamp of the input path.
331 * In the case of a parallel snapdir (specified with an
332 * absolute path), this is the inital portion of the
333 * local path of any snapshot file. The complete path is
334 * obtained by appending the portion of the file's path
335 * below the share root's mountpoint.
337 static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
338 struct vfs_handle_struct *handle,
341 fstring snaptime_string;
342 ssize_t snaptime_len = 0;
344 struct shadow_copy2_config *config;
345 struct shadow_copy2_private *priv;
347 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
350 config = priv->config;
352 snaptime_len = shadow_copy2_posix_gmt_string(handle,
355 sizeof(snaptime_string));
356 if (snaptime_len <= 0) {
360 if (config->snapdir_absolute) {
361 result = talloc_asprintf(mem_ctx, "%s/%s",
362 config->snapdir, snaptime_string);
364 result = talloc_asprintf(mem_ctx, "/%s/%s",
365 config->snapdir, snaptime_string);
367 if (result == NULL) {
368 DEBUG(1, (__location__ " talloc_asprintf failed\n"));
375 * Build the posix snapshot path for the connection
376 * at the given timestamp, i.e. the absolute posix path
377 * that contains the snapshot for this file system.
379 * This only applies to classical case, i.e. not
380 * to the "snapdirseverywhere" mode.
382 static char *shadow_copy2_snapshot_path(TALLOC_CTX *mem_ctx,
383 struct vfs_handle_struct *handle,
386 fstring snaptime_string;
387 ssize_t snaptime_len = 0;
389 struct shadow_copy2_private *priv;
391 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
394 snaptime_len = shadow_copy2_posix_gmt_string(handle,
397 sizeof(snaptime_string));
398 if (snaptime_len <= 0) {
402 result = talloc_asprintf(mem_ctx, "%s/%s",
403 priv->config->snapshot_basepath, snaptime_string);
404 if (result == NULL) {
405 DEBUG(1, (__location__ " talloc_asprintf failed\n"));
411 static char *make_path_absolute(TALLOC_CTX *mem_ctx,
412 struct shadow_copy2_private *priv,
415 char *newpath = NULL;
416 char *abs_path = NULL;
418 if (name[0] != '/') {
419 newpath = talloc_asprintf(mem_ctx,
423 if (newpath == NULL) {
428 abs_path = canonicalize_absolute_path(mem_ctx, name);
429 TALLOC_FREE(newpath);
433 /* Return a $cwd-relative path. */
434 static bool make_relative_path(const char *cwd, char *abs_path)
436 size_t cwd_len = strlen(cwd);
437 size_t abs_len = strlen(abs_path);
439 if (abs_len < cwd_len) {
442 if (memcmp(abs_path, cwd, cwd_len) != 0) {
445 if (abs_path[cwd_len] != '/' && abs_path[cwd_len] != '\0') {
448 if (abs_path[cwd_len] == '/') {
451 memmove(abs_path, &abs_path[cwd_len], abs_len + 1 - cwd_len);
455 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
457 char *gmt, size_t gmt_len);
460 * Check if an incoming filename is already a snapshot converted pathname.
462 * If so, it returns the pathname truncated at the snapshot point which
463 * will be used as the connectpath.
466 static int check_for_converted_path(TALLOC_CTX *mem_ctx,
467 struct vfs_handle_struct *handle,
468 struct shadow_copy2_private *priv,
470 bool *ppath_already_converted,
473 size_t snapdirlen = 0;
474 char *p = strstr_m(abs_path, priv->config->snapdir);
476 char *connect_path = NULL;
477 char snapshot[GMT_NAME_LEN+1];
479 *ppath_already_converted = false;
482 /* Must at least contain shadow:snapdir. */
486 if (priv->config->snapdir[0] == '/' &&
488 /* Absolute shadow:snapdir must be at the start. */
492 snapdirlen = strlen(priv->config->snapdir);
493 if (p[snapdirlen] != '/') {
494 /* shadow:snapdir must end as a separate component. */
498 if (p > abs_path && p[-1] != '/') {
499 /* shadow:snapdir must start as a separate component. */
504 p++; /* Move past the / */
507 * Need to return up to the next path
508 * component after the time.
509 * This will be used as the connectpath.
514 * No next path component.
517 connect_path = talloc_strdup(mem_ctx,
520 connect_path = talloc_strndup(mem_ctx,
524 if (connect_path == NULL) {
529 * Point p at the same offset in connect_path as
533 p = &connect_path[p - abs_path];
536 * Now ensure there is a time string at p.
537 * The SMB-format @GMT-token string is returned
541 if (!shadow_copy2_snapshot_to_gmt(handle,
545 TALLOC_FREE(connect_path);
549 if (pconnectpath != NULL) {
550 *pconnectpath = connect_path;
553 *ppath_already_converted = true;
555 DBG_DEBUG("path |%s| is already converted. "
556 "connect path = |%s|\n",
564 * This function does two things.
566 * 1). Checks if an incoming filename is already a
567 * snapshot converted pathname.
568 * If so, it returns the pathname truncated
569 * at the snapshot point which will be used
570 * as the connectpath, and then does an early return.
572 * 2). Checks if an incoming filename contains an
573 * SMB-layer @GMT- style timestamp.
574 * If so, it strips the timestamp, and returns
575 * both the timestamp and the stripped path
576 * (making it cwd-relative).
579 static bool shadow_copy2_strip_snapshot_internal(TALLOC_CTX *mem_ctx,
580 struct vfs_handle_struct *handle,
581 const char *orig_name,
587 time_t timestamp = 0;
590 char *stripped = NULL;
591 size_t rest_len, dst_len;
592 struct shadow_copy2_private *priv;
593 ptrdiff_t len_before_gmt;
594 const char *name = orig_name;
595 char *abs_path = NULL;
597 bool already_converted = false;
600 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
603 DEBUG(10, (__location__ ": enter path '%s'\n", name));
605 abs_path = make_path_absolute(mem_ctx, priv, name);
606 if (abs_path == NULL) {
612 DEBUG(10, (__location__ ": abs path '%s'\n", name));
614 err = check_for_converted_path(mem_ctx,
621 /* error in conversion. */
626 if (already_converted) {
631 * From here we're only looking to strip an
632 * SMB-layer @GMT- token.
635 p = strstr_m(name, "@GMT-");
637 DEBUG(11, ("@GMT not found\n"));
640 if ((p > name) && (p[-1] != '/')) {
641 /* the GMT-token does not start a path-component */
642 DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
643 p, name, (int)p[-1]));
647 len_before_gmt = p - name;
649 q = strptime(p, GMT_FORMAT, &tm);
651 DEBUG(10, ("strptime failed\n"));
655 timestamp = timegm(&tm);
656 if (timestamp == (time_t)-1) {
657 DEBUG(10, ("timestamp==-1\n"));
662 * The name consists of only the GMT token or the GMT
663 * token is at the end of the path. XP seems to send
664 * @GMT- at the end under certain circumstances even
665 * with a path prefix.
667 if (pstripped != NULL) {
668 if (len_before_gmt > 0) {
670 * There is a slash before
671 * the @GMT-. Remove it.
675 stripped = talloc_strndup(mem_ctx, name,
677 if (stripped == NULL) {
681 if (orig_name[0] != '/') {
682 if (make_relative_path(priv->shadow_cwd,
683 stripped) == false) {
684 DEBUG(10, (__location__ ": path '%s' "
685 "doesn't start with cwd '%s\n",
686 stripped, priv->shadow_cwd));
692 *pstripped = stripped;
694 *ptimestamp = timestamp;
699 * It is not a complete path component, i.e. the path
700 * component continues after the gmt-token.
702 DEBUG(10, ("q[0] = %d\n", (int)q[0]));
707 rest_len = strlen(q);
708 dst_len = len_before_gmt + rest_len;
710 if (pstripped != NULL) {
711 stripped = talloc_array(mem_ctx, char, dst_len+1);
712 if (stripped == NULL) {
717 memcpy(stripped, name, len_before_gmt);
720 memcpy(stripped + len_before_gmt, q, rest_len);
722 stripped[dst_len] = '\0';
723 if (orig_name[0] != '/') {
724 if (make_relative_path(priv->shadow_cwd,
725 stripped) == false) {
726 DEBUG(10, (__location__ ": path '%s' "
727 "doesn't start with cwd '%s\n",
728 stripped, priv->shadow_cwd));
734 *pstripped = stripped;
736 *ptimestamp = timestamp;
740 TALLOC_FREE(abs_path);
744 static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
745 struct vfs_handle_struct *handle,
746 const char *orig_name,
750 return shadow_copy2_strip_snapshot_internal(mem_ctx,
758 static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
759 vfs_handle_struct *handle)
761 char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
766 if (stat(path, &st) != 0) {
773 while ((p = strrchr(path, '/')) && p > path) {
775 if (stat(path, &st) != 0) {
779 if (st.st_dev != dev) {
789 * Convert from a name as handed in via the SMB layer
790 * and a timestamp into the local path of the snapshot
791 * of the provided file at the provided time.
792 * Also return the path in the snapshot corresponding
793 * to the file's share root.
795 static char *shadow_copy2_do_convert(TALLOC_CTX *mem_ctx,
796 struct vfs_handle_struct *handle,
797 const char *name, time_t timestamp,
798 size_t *snaproot_len)
800 struct smb_filename converted_fname;
802 size_t *slashes = NULL;
803 unsigned num_slashes;
807 char *converted = NULL;
808 size_t insertlen, connectlen = 0;
811 struct shadow_copy2_config *config;
812 struct shadow_copy2_private *priv;
813 size_t in_share_offset = 0;
815 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
818 config = priv->config;
820 DEBUG(10, ("converting '%s'\n", name));
822 if (!config->snapdirseverywhere) {
826 snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
829 if (snapshot_path == NULL) {
833 if (config->rel_connectpath == NULL) {
834 converted = talloc_asprintf(mem_ctx, "%s/%s",
835 snapshot_path, name);
837 converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
839 config->rel_connectpath,
842 if (converted == NULL) {
846 ZERO_STRUCT(converted_fname);
847 converted_fname.base_name = converted;
849 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
850 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
852 ret, ret == 0 ? "ok" : strerror(errno)));
854 DEBUG(10, ("Found %s\n", converted));
857 if (snaproot_len != NULL) {
858 *snaproot_len = strlen(snapshot_path);
859 if (config->rel_connectpath != NULL) {
861 strlen(config->rel_connectpath) + 1;
869 /* never reached ... */
872 connectlen = strlen(handle->conn->connectpath);
874 path = talloc_strdup(mem_ctx, handle->conn->connectpath);
876 path = talloc_asprintf(
877 mem_ctx, "%s/%s", handle->conn->connectpath, name);
883 pathlen = talloc_get_size(path)-1;
885 if (!shadow_copy2_find_slashes(talloc_tos(), path,
886 &slashes, &num_slashes)) {
890 insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
891 if (insert == NULL) {
894 insertlen = talloc_get_size(insert)-1;
897 * Note: We deliberatly don't expensively initialize the
898 * array with talloc_zero here: Putting zero into
899 * converted[pathlen+insertlen] below is sufficient, because
900 * in the following for loop, the insert string is inserted
901 * at various slash places. So the memory up to position
902 * pathlen+insertlen will always be initialized when the
903 * converted string is used.
905 converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
906 if (converted == NULL) {
910 if (path[pathlen-1] != '/') {
912 * Append a fake slash to find the snapshot root
915 tmp = talloc_realloc(talloc_tos(), slashes,
916 size_t, num_slashes+1);
921 slashes[num_slashes] = pathlen;
927 if (!config->crossmountpoints) {
928 min_offset = strlen(config->mount_point);
931 memcpy(converted, path, pathlen+1);
932 converted[pathlen+insertlen] = '\0';
934 ZERO_STRUCT(converted_fname);
935 converted_fname.base_name = converted;
937 for (i = num_slashes-1; i>=0; i--) {
943 if (offset < min_offset) {
948 if (offset >= connectlen) {
949 in_share_offset = offset;
952 memcpy(converted+offset, insert, insertlen);
955 memcpy(converted+offset, path + slashes[i],
956 pathlen - slashes[i]);
958 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
960 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
962 ret, ret == 0 ? "ok" : strerror(errno)));
965 if (snaproot_len != NULL) {
966 *snaproot_len = in_share_offset + insertlen;
970 if (errno == ENOTDIR) {
972 * This is a valid condition: We appended the
973 * .snaphots/@GMT.. to a file name. Just try
974 * with the upper levels.
978 if (errno != ENOENT) {
979 /* Other problem than "not found" */
988 DEBUG(10, ("Found %s\n", converted));
996 TALLOC_FREE(converted);
998 TALLOC_FREE(slashes);
1000 errno = saved_errno;
1005 * Convert from a name as handed in via the SMB layer
1006 * and a timestamp into the local path of the snapshot
1007 * of the provided file at the provided time.
1009 static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
1010 struct vfs_handle_struct *handle,
1011 const char *name, time_t timestamp)
1013 return shadow_copy2_do_convert(mem_ctx, handle, name, timestamp, NULL);
1017 modify a sbuf return to ensure that inodes in the shadow directory
1018 are different from those in the main directory
1020 static void convert_sbuf(vfs_handle_struct *handle, const char *fname,
1021 SMB_STRUCT_STAT *sbuf)
1023 struct shadow_copy2_private *priv;
1025 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1028 if (priv->config->fixinodes) {
1029 /* some snapshot systems, like GPFS, return the name
1030 device:inode for the snapshot files as the current
1031 files. That breaks the 'restore' button in the shadow copy
1032 GUI, as the client gets a sharing violation.
1034 This is a crude way of allowing both files to be
1035 open at once. It has a slight chance of inode
1036 number collision, but I can't see a better approach
1037 without significant VFS changes
1039 TDB_DATA key = { .dptr = discard_const_p(uint8_t, fname),
1040 .dsize = strlen(fname) };
1043 shash = tdb_jenkins_hash(&key) & 0xFF000000;
1047 sbuf->st_ex_ino ^= shash;
1051 static DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
1052 const struct smb_filename *smb_fname,
1056 time_t timestamp = 0;
1057 char *stripped = NULL;
1061 struct smb_filename *conv_smb_fname = NULL;
1063 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1065 smb_fname->base_name,
1070 if (timestamp == 0) {
1071 return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
1073 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1074 TALLOC_FREE(stripped);
1078 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1083 if (conv_smb_fname == NULL) {
1087 ret = SMB_VFS_NEXT_OPENDIR(handle, conv_smb_fname, mask, attr);
1088 saved_errno = errno;
1090 TALLOC_FREE(conv_smb_fname);
1091 errno = saved_errno;
1095 static int shadow_copy2_rename(vfs_handle_struct *handle,
1096 const struct smb_filename *smb_fname_src,
1097 const struct smb_filename *smb_fname_dst)
1099 time_t timestamp_src = 0;
1100 time_t timestamp_dst = 0;
1102 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1103 smb_fname_src->base_name,
1104 ×tamp_src, NULL)) {
1107 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1108 smb_fname_dst->base_name,
1109 ×tamp_dst, NULL)) {
1112 if (timestamp_src != 0) {
1116 if (timestamp_dst != 0) {
1120 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1123 static int shadow_copy2_symlink(vfs_handle_struct *handle,
1124 const char *oldname, const char *newname)
1126 time_t timestamp_old = 0;
1127 time_t timestamp_new = 0;
1129 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
1130 ×tamp_old, NULL)) {
1133 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
1134 ×tamp_new, NULL)) {
1137 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1141 return SMB_VFS_NEXT_SYMLINK(handle, oldname, newname);
1144 static int shadow_copy2_link(vfs_handle_struct *handle,
1145 const char *oldname, const char *newname)
1147 time_t timestamp_old = 0;
1148 time_t timestamp_new = 0;
1150 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
1151 ×tamp_old, NULL)) {
1154 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
1155 ×tamp_new, NULL)) {
1158 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1162 return SMB_VFS_NEXT_LINK(handle, oldname, newname);
1165 static int shadow_copy2_stat(vfs_handle_struct *handle,
1166 struct smb_filename *smb_fname)
1168 time_t timestamp = 0;
1169 char *stripped = NULL;
1171 int ret, saved_errno;
1173 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1174 smb_fname->base_name,
1175 ×tamp, &stripped)) {
1178 if (timestamp == 0) {
1179 return SMB_VFS_NEXT_STAT(handle, smb_fname);
1182 tmp = smb_fname->base_name;
1183 smb_fname->base_name = shadow_copy2_convert(
1184 talloc_tos(), handle, stripped, timestamp);
1185 TALLOC_FREE(stripped);
1187 if (smb_fname->base_name == NULL) {
1188 smb_fname->base_name = tmp;
1192 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1193 saved_errno = errno;
1195 TALLOC_FREE(smb_fname->base_name);
1196 smb_fname->base_name = tmp;
1199 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1201 errno = saved_errno;
1205 static int shadow_copy2_lstat(vfs_handle_struct *handle,
1206 struct smb_filename *smb_fname)
1208 time_t timestamp = 0;
1209 char *stripped = NULL;
1211 int ret, saved_errno;
1213 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1214 smb_fname->base_name,
1215 ×tamp, &stripped)) {
1218 if (timestamp == 0) {
1219 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1222 tmp = smb_fname->base_name;
1223 smb_fname->base_name = shadow_copy2_convert(
1224 talloc_tos(), handle, stripped, timestamp);
1225 TALLOC_FREE(stripped);
1227 if (smb_fname->base_name == NULL) {
1228 smb_fname->base_name = tmp;
1232 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1233 saved_errno = errno;
1235 TALLOC_FREE(smb_fname->base_name);
1236 smb_fname->base_name = tmp;
1239 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1241 errno = saved_errno;
1245 static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
1246 SMB_STRUCT_STAT *sbuf)
1248 time_t timestamp = 0;
1251 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1255 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1256 fsp->fsp_name->base_name,
1257 ×tamp, NULL)) {
1260 if (timestamp != 0) {
1261 convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
1266 static int shadow_copy2_open(vfs_handle_struct *handle,
1267 struct smb_filename *smb_fname, files_struct *fsp,
1268 int flags, mode_t mode)
1270 time_t timestamp = 0;
1271 char *stripped = NULL;
1273 int ret, saved_errno;
1275 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1276 smb_fname->base_name,
1277 ×tamp, &stripped)) {
1280 if (timestamp == 0) {
1281 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1284 tmp = smb_fname->base_name;
1285 smb_fname->base_name = shadow_copy2_convert(
1286 talloc_tos(), handle, stripped, timestamp);
1287 TALLOC_FREE(stripped);
1289 if (smb_fname->base_name == NULL) {
1290 smb_fname->base_name = tmp;
1294 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1295 saved_errno = errno;
1297 TALLOC_FREE(smb_fname->base_name);
1298 smb_fname->base_name = tmp;
1300 errno = saved_errno;
1304 static int shadow_copy2_unlink(vfs_handle_struct *handle,
1305 const struct smb_filename *smb_fname)
1307 time_t timestamp = 0;
1308 char *stripped = NULL;
1309 int ret, saved_errno;
1310 struct smb_filename *conv;
1312 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1313 smb_fname->base_name,
1314 ×tamp, &stripped)) {
1317 if (timestamp == 0) {
1318 return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1320 conv = cp_smb_filename(talloc_tos(), smb_fname);
1325 conv->base_name = shadow_copy2_convert(
1326 conv, handle, stripped, timestamp);
1327 TALLOC_FREE(stripped);
1328 if (conv->base_name == NULL) {
1331 ret = SMB_VFS_NEXT_UNLINK(handle, conv);
1332 saved_errno = errno;
1334 errno = saved_errno;
1338 static int shadow_copy2_chmod(vfs_handle_struct *handle,
1339 const struct smb_filename *smb_fname,
1342 time_t timestamp = 0;
1343 char *stripped = NULL;
1344 int ret, saved_errno;
1346 struct smb_filename *conv_smb_fname;
1348 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1350 smb_fname->base_name,
1355 if (timestamp == 0) {
1356 TALLOC_FREE(stripped);
1357 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1359 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1360 TALLOC_FREE(stripped);
1364 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1369 if (conv_smb_fname == NULL) {
1375 ret = SMB_VFS_NEXT_CHMOD(handle, conv_smb_fname, mode);
1376 saved_errno = errno;
1378 TALLOC_FREE(conv_smb_fname);
1379 errno = saved_errno;
1383 static int shadow_copy2_chown(vfs_handle_struct *handle,
1384 const struct smb_filename *smb_fname,
1388 time_t timestamp = 0;
1389 char *stripped = NULL;
1390 int ret, saved_errno;
1392 struct smb_filename *conv_smb_fname = NULL;
1394 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1396 smb_fname->base_name,
1401 if (timestamp == 0) {
1402 return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1404 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1405 TALLOC_FREE(stripped);
1409 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1414 if (conv_smb_fname == NULL) {
1419 ret = SMB_VFS_NEXT_CHOWN(handle, conv_smb_fname, uid, gid);
1420 saved_errno = errno;
1422 TALLOC_FREE(conv_smb_fname);
1423 errno = saved_errno;
1427 static void store_cwd_data(vfs_handle_struct *handle,
1428 const char *connectpath)
1430 struct shadow_copy2_private *priv = NULL;
1433 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1436 TALLOC_FREE(priv->shadow_cwd);
1437 cwd = SMB_VFS_NEXT_GETWD(handle);
1439 smb_panic("getwd failed\n");
1441 DBG_DEBUG("shadow cwd = %s\n", cwd);
1442 priv->shadow_cwd = talloc_strdup(priv, cwd);
1444 if (priv->shadow_cwd == NULL) {
1445 smb_panic("talloc failed\n");
1447 TALLOC_FREE(priv->shadow_connectpath);
1449 DBG_DEBUG("shadow conectpath = %s\n", connectpath);
1450 priv->shadow_connectpath = talloc_strdup(priv, connectpath);
1451 if (priv->shadow_connectpath == NULL) {
1452 smb_panic("talloc failed\n");
1457 static int shadow_copy2_chdir(vfs_handle_struct *handle,
1460 time_t timestamp = 0;
1461 char *stripped = NULL;
1462 char *snappath = NULL;
1464 int saved_errno = 0;
1466 size_t rootpath_len = 0;
1468 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, fname,
1469 ×tamp, &stripped, &snappath)) {
1472 if (stripped != NULL) {
1473 conv = shadow_copy2_do_convert(talloc_tos(),
1478 TALLOC_FREE(stripped);
1485 ret = SMB_VFS_NEXT_CHDIR(handle, fname);
1487 saved_errno = errno;
1491 if (conv != NULL && rootpath_len != 0) {
1492 conv[rootpath_len] = '\0';
1493 } else if (snappath != 0) {
1497 store_cwd_data(handle, conv);
1500 TALLOC_FREE(stripped);
1503 if (saved_errno != 0) {
1504 errno = saved_errno;
1509 static int shadow_copy2_ntimes(vfs_handle_struct *handle,
1510 const struct smb_filename *smb_fname,
1511 struct smb_file_time *ft)
1513 time_t timestamp = 0;
1514 char *stripped = NULL;
1515 int ret, saved_errno;
1516 struct smb_filename *conv;
1518 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1519 smb_fname->base_name,
1520 ×tamp, &stripped)) {
1523 if (timestamp == 0) {
1524 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1526 conv = cp_smb_filename(talloc_tos(), smb_fname);
1531 conv->base_name = shadow_copy2_convert(
1532 conv, handle, stripped, timestamp);
1533 TALLOC_FREE(stripped);
1534 if (conv->base_name == NULL) {
1537 ret = SMB_VFS_NEXT_NTIMES(handle, conv, ft);
1538 saved_errno = errno;
1540 errno = saved_errno;
1544 static int shadow_copy2_readlink(vfs_handle_struct *handle,
1545 const char *fname, char *buf, size_t bufsiz)
1547 time_t timestamp = 0;
1548 char *stripped = NULL;
1549 int ret, saved_errno;
1552 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1553 ×tamp, &stripped)) {
1556 if (timestamp == 0) {
1557 return SMB_VFS_NEXT_READLINK(handle, fname, buf, bufsiz);
1559 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1560 TALLOC_FREE(stripped);
1564 ret = SMB_VFS_NEXT_READLINK(handle, conv, buf, bufsiz);
1565 saved_errno = errno;
1567 errno = saved_errno;
1571 static int shadow_copy2_mknod(vfs_handle_struct *handle,
1572 const char *fname, mode_t mode, SMB_DEV_T dev)
1574 time_t timestamp = 0;
1575 char *stripped = NULL;
1576 int ret, saved_errno;
1579 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1580 ×tamp, &stripped)) {
1583 if (timestamp == 0) {
1584 return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
1586 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1587 TALLOC_FREE(stripped);
1591 ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
1592 saved_errno = errno;
1594 errno = saved_errno;
1598 static char *shadow_copy2_realpath(vfs_handle_struct *handle,
1601 time_t timestamp = 0;
1602 char *stripped = NULL;
1604 char *result = NULL;
1607 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1608 ×tamp, &stripped)) {
1611 if (timestamp == 0) {
1612 return SMB_VFS_NEXT_REALPATH(handle, fname);
1615 tmp = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1620 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
1623 saved_errno = errno;
1625 TALLOC_FREE(stripped);
1626 errno = saved_errno;
1631 * Check whether a given directory contains a
1632 * snapshot directory as direct subdirectory.
1633 * If yes, return the path of the snapshot-subdir,
1634 * otherwise return NULL.
1636 static char *have_snapdir(struct vfs_handle_struct *handle,
1639 struct smb_filename smb_fname;
1641 struct shadow_copy2_private *priv;
1643 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1646 ZERO_STRUCT(smb_fname);
1647 smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
1648 path, priv->config->snapdir);
1649 if (smb_fname.base_name == NULL) {
1653 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1654 if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
1655 return smb_fname.base_name;
1657 TALLOC_FREE(smb_fname.base_name);
1661 static bool check_access_snapdir(struct vfs_handle_struct *handle,
1664 struct smb_filename smb_fname;
1668 ZERO_STRUCT(smb_fname);
1669 smb_fname.base_name = talloc_asprintf(talloc_tos(),
1672 if (smb_fname.base_name == NULL) {
1676 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1677 if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
1678 TALLOC_FREE(smb_fname.base_name);
1682 status = smbd_check_access_rights(handle->conn,
1686 if (!NT_STATUS_IS_OK(status)) {
1687 DEBUG(0,("user does not have list permission "
1689 smb_fname.base_name));
1690 TALLOC_FREE(smb_fname.base_name);
1693 TALLOC_FREE(smb_fname.base_name);
1698 * Find the snapshot directory (if any) for the given
1699 * filename (which is relative to the share).
1701 static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx,
1702 struct vfs_handle_struct *handle,
1703 struct smb_filename *smb_fname)
1706 const char *snapdir;
1707 struct shadow_copy2_config *config;
1708 struct shadow_copy2_private *priv;
1710 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1713 config = priv->config;
1716 * If the non-snapdisrseverywhere mode, we should not search!
1718 if (!config->snapdirseverywhere) {
1719 return config->snapshot_basepath;
1722 path = talloc_asprintf(mem_ctx, "%s/%s",
1723 handle->conn->connectpath,
1724 smb_fname->base_name);
1729 snapdir = have_snapdir(handle, path);
1730 if (snapdir != NULL) {
1735 while ((p = strrchr(path, '/')) && (p > path)) {
1739 snapdir = have_snapdir(handle, path);
1740 if (snapdir != NULL) {
1749 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
1751 char *gmt, size_t gmt_len)
1753 struct tm timestamp;
1755 unsigned long int timestamp_long;
1757 struct shadow_copy2_config *config;
1758 struct shadow_copy2_private *priv;
1759 char *tmpstr = NULL;
1761 bool converted = false;
1764 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1767 config = priv->config;
1769 fmt = config->gmt_format;
1772 * If regex is provided, then we will have to parse the
1773 * filename which will contain both the prefix and the time format.
1774 * e.g. <prefix><delimiter><time_format>
1776 if (priv->snaps->regex != NULL) {
1777 tmpstr = talloc_strdup(talloc_tos(), name);
1778 /* point "name" to the time format */
1779 name = strstr(name, priv->config->delimiter);
1783 /* Extract the prefix */
1784 tmp = strstr(tmpstr, priv->config->delimiter);
1788 ret = regexec(priv->snaps->regex, tmpstr, 0, NULL, 0);
1790 DBG_DEBUG("shadow_copy2_snapshot_to_gmt: "
1791 "no regex match for %s\n", tmpstr);
1796 ZERO_STRUCT(timestamp);
1797 if (config->use_sscanf) {
1798 if (sscanf(name, fmt, ×tamp_long) != 1) {
1799 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1800 "no sscanf match %s: %s\n",
1804 timestamp_t = timestamp_long;
1805 gmtime_r(×tamp_t, ×tamp);
1807 if (strptime(name, fmt, ×tamp) == NULL) {
1808 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1809 "no match %s: %s\n",
1813 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1816 if (config->use_localtime) {
1817 timestamp.tm_isdst = -1;
1818 timestamp_t = mktime(×tamp);
1819 gmtime_r(×tamp_t, ×tamp);
1823 strftime(gmt, gmt_len, GMT_FORMAT, ×tamp);
1827 TALLOC_FREE(tmpstr);
1831 static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
1833 return strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1836 static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
1838 return -strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1842 sort the shadow copy data in ascending or descending order
1844 static void shadow_copy2_sort_data(vfs_handle_struct *handle,
1845 struct shadow_copy_data *shadow_copy2_data)
1847 int (*cmpfunc)(const void *, const void *);
1849 struct shadow_copy2_private *priv;
1851 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1854 sort = priv->config->sort_order;
1859 if (strcmp(sort, "asc") == 0) {
1860 cmpfunc = shadow_copy2_label_cmp_asc;
1861 } else if (strcmp(sort, "desc") == 0) {
1862 cmpfunc = shadow_copy2_label_cmp_desc;
1867 if (shadow_copy2_data && shadow_copy2_data->num_volumes > 0 &&
1868 shadow_copy2_data->labels)
1870 TYPESAFE_QSORT(shadow_copy2_data->labels,
1871 shadow_copy2_data->num_volumes,
1876 static int shadow_copy2_get_shadow_copy_data(
1877 vfs_handle_struct *handle, files_struct *fsp,
1878 struct shadow_copy_data *shadow_copy2_data,
1882 const char *snapdir;
1883 struct smb_filename *snapdir_smb_fname = NULL;
1885 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1886 struct shadow_copy2_private *priv = NULL;
1887 struct shadow_copy2_snapentry *tmpentry = NULL;
1888 bool get_snaplist = false;
1889 bool access_granted = false;
1892 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
1893 if (snapdir == NULL) {
1894 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1895 handle->conn->connectpath));
1900 access_granted = check_access_snapdir(handle, snapdir);
1901 if (!access_granted) {
1902 DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
1907 snapdir_smb_fname = synthetic_smb_fname(talloc_tos(),
1911 fsp->fsp_name->flags);
1912 if (snapdir_smb_fname == NULL) {
1917 p = SMB_VFS_NEXT_OPENDIR(handle, snapdir_smb_fname, NULL, 0);
1920 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1921 " - %s\n", snapdir, strerror(errno)));
1926 if (shadow_copy2_data != NULL) {
1927 shadow_copy2_data->num_volumes = 0;
1928 shadow_copy2_data->labels = NULL;
1931 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1935 * Normally this function is called twice once with labels = false and
1936 * then with labels = true. When labels is false it will return the
1937 * number of volumes so that the caller can allocate memory for that
1938 * many labels. Therefore to eliminate snaplist both the times it is
1939 * good to check if labels is set or not.
1941 * shadow_copy2_data is NULL when we only want to update the list and
1942 * don't want any labels.
1944 if ((priv->snaps->regex != NULL) && (labels || shadow_copy2_data == NULL)) {
1945 get_snaplist = true;
1946 /* Reset the global snaplist */
1947 shadow_copy2_delete_snaplist(priv);
1949 /* Set the current time as snaplist update time */
1950 time(&(priv->snaps->fetch_time));
1953 while ((d = SMB_VFS_NEXT_READDIR(handle, p, NULL))) {
1954 char snapshot[GMT_NAME_LEN+1];
1955 SHADOW_COPY_LABEL *tlabels;
1958 * ignore names not of the right form in the snapshot
1961 if (!shadow_copy2_snapshot_to_gmt(
1963 snapshot, sizeof(snapshot))) {
1965 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1966 "ignoring %s\n", d->d_name));
1969 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1970 d->d_name, snapshot));
1974 * Create a snap entry for each successful
1977 tmpentry = shadow_copy2_create_snapentry(priv);
1978 if (tmpentry == NULL) {
1979 DBG_ERR("talloc_zero() failed\n");
1982 tmpentry->snapname = talloc_strdup(tmpentry, d->d_name);
1983 tmpentry->time_fmt = talloc_strdup(tmpentry, snapshot);
1986 if (shadow_copy2_data == NULL) {
1991 /* the caller doesn't want the labels */
1992 shadow_copy2_data->num_volumes++;
1996 tlabels = talloc_realloc(shadow_copy2_data,
1997 shadow_copy2_data->labels,
1999 shadow_copy2_data->num_volumes+1);
2000 if (tlabels == NULL) {
2001 DEBUG(0,("shadow_copy2: out of memory\n"));
2002 SMB_VFS_NEXT_CLOSEDIR(handle, p);
2006 strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot,
2009 shadow_copy2_data->num_volumes++;
2010 shadow_copy2_data->labels = tlabels;
2013 SMB_VFS_NEXT_CLOSEDIR(handle,p);
2015 shadow_copy2_sort_data(handle, shadow_copy2_data);
2019 TALLOC_FREE(tmp_ctx);
2023 static NTSTATUS shadow_copy2_fget_nt_acl(vfs_handle_struct *handle,
2024 struct files_struct *fsp,
2025 uint32_t security_info,
2026 TALLOC_CTX *mem_ctx,
2027 struct security_descriptor **ppdesc)
2029 time_t timestamp = 0;
2030 char *stripped = NULL;
2033 struct smb_filename *smb_fname = NULL;
2035 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
2036 fsp->fsp_name->base_name,
2037 ×tamp, &stripped)) {
2038 return map_nt_error_from_unix(errno);
2040 if (timestamp == 0) {
2041 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2045 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2046 TALLOC_FREE(stripped);
2048 return map_nt_error_from_unix(errno);
2050 smb_fname = synthetic_smb_fname(talloc_tos(),
2054 fsp->fsp_name->flags);
2055 if (smb_fname == NULL) {
2057 return NT_STATUS_NO_MEMORY;
2060 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2063 TALLOC_FREE(smb_fname);
2067 static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
2068 const struct smb_filename *smb_fname,
2069 uint32_t security_info,
2070 TALLOC_CTX *mem_ctx,
2071 struct security_descriptor **ppdesc)
2073 time_t timestamp = 0;
2074 char *stripped = NULL;
2077 struct smb_filename *conv_smb_fname = NULL;
2079 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2081 smb_fname->base_name,
2084 return map_nt_error_from_unix(errno);
2086 if (timestamp == 0) {
2087 return SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2090 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2091 TALLOC_FREE(stripped);
2093 return map_nt_error_from_unix(errno);
2095 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2100 if (conv_smb_fname == NULL) {
2102 return NT_STATUS_NO_MEMORY;
2104 status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv_smb_fname, security_info,
2107 TALLOC_FREE(conv_smb_fname);
2111 static int shadow_copy2_mkdir(vfs_handle_struct *handle,
2112 const struct smb_filename *smb_fname,
2115 time_t timestamp = 0;
2116 char *stripped = NULL;
2117 int ret, saved_errno;
2119 struct smb_filename *conv_smb_fname = NULL;
2121 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2123 smb_fname->base_name,
2128 if (timestamp == 0) {
2129 return SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
2131 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2132 TALLOC_FREE(stripped);
2136 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2141 if (conv_smb_fname == NULL) {
2145 ret = SMB_VFS_NEXT_MKDIR(handle, conv_smb_fname, mode);
2146 saved_errno = errno;
2148 TALLOC_FREE(conv_smb_fname);
2149 errno = saved_errno;
2153 static int shadow_copy2_rmdir(vfs_handle_struct *handle,
2154 const struct smb_filename *smb_fname)
2156 time_t timestamp = 0;
2157 char *stripped = NULL;
2158 int ret, saved_errno;
2160 struct smb_filename *conv_smb_fname = NULL;
2162 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2164 smb_fname->base_name,
2169 if (timestamp == 0) {
2170 return SMB_VFS_NEXT_RMDIR(handle, smb_fname);
2172 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2173 TALLOC_FREE(stripped);
2177 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2182 if (conv_smb_fname == NULL) {
2186 ret = SMB_VFS_NEXT_RMDIR(handle, conv_smb_fname);
2187 saved_errno = errno;
2188 TALLOC_FREE(conv_smb_fname);
2190 errno = saved_errno;
2194 static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
2197 time_t timestamp = 0;
2198 char *stripped = NULL;
2199 int ret, saved_errno;
2202 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2203 ×tamp, &stripped)) {
2206 if (timestamp == 0) {
2207 return SMB_VFS_NEXT_CHFLAGS(handle, fname, flags);
2209 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2210 TALLOC_FREE(stripped);
2214 ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
2215 saved_errno = errno;
2217 errno = saved_errno;
2221 static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
2222 const char *fname, const char *aname,
2223 void *value, size_t size)
2225 time_t timestamp = 0;
2226 char *stripped = NULL;
2231 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2232 ×tamp, &stripped)) {
2235 if (timestamp == 0) {
2236 return SMB_VFS_NEXT_GETXATTR(handle, fname, aname, value,
2239 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2240 TALLOC_FREE(stripped);
2244 ret = SMB_VFS_NEXT_GETXATTR(handle, conv, aname, value, size);
2245 saved_errno = errno;
2247 errno = saved_errno;
2251 static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
2253 char *list, size_t size)
2255 time_t timestamp = 0;
2256 char *stripped = NULL;
2261 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2262 ×tamp, &stripped)) {
2265 if (timestamp == 0) {
2266 return SMB_VFS_NEXT_LISTXATTR(handle, fname, list, size);
2268 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2269 TALLOC_FREE(stripped);
2273 ret = SMB_VFS_NEXT_LISTXATTR(handle, conv, list, size);
2274 saved_errno = errno;
2276 errno = saved_errno;
2280 static int shadow_copy2_removexattr(vfs_handle_struct *handle,
2281 const char *fname, const char *aname)
2283 time_t timestamp = 0;
2284 char *stripped = NULL;
2285 int ret, saved_errno;
2288 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2289 ×tamp, &stripped)) {
2292 if (timestamp == 0) {
2293 return SMB_VFS_NEXT_REMOVEXATTR(handle, fname, aname);
2295 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2296 TALLOC_FREE(stripped);
2300 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv, aname);
2301 saved_errno = errno;
2303 errno = saved_errno;
2307 static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
2309 const char *aname, const void *value,
2310 size_t size, int flags)
2312 time_t timestamp = 0;
2313 char *stripped = NULL;
2318 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2319 ×tamp, &stripped)) {
2322 if (timestamp == 0) {
2323 return SMB_VFS_NEXT_SETXATTR(handle, fname, aname, value, size,
2326 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2327 TALLOC_FREE(stripped);
2331 ret = SMB_VFS_NEXT_SETXATTR(handle, conv, aname, value, size, flags);
2332 saved_errno = errno;
2334 errno = saved_errno;
2338 static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
2339 const struct smb_filename *smb_fname,
2342 time_t timestamp = 0;
2343 char *stripped = NULL;
2347 struct smb_filename *conv_smb_fname = NULL;
2349 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2351 smb_fname->base_name,
2356 if (timestamp == 0) {
2357 return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2359 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2360 TALLOC_FREE(stripped);
2364 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2369 if (conv_smb_fname == NULL) {
2374 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv_smb_fname, mode);
2375 saved_errno = errno;
2377 TALLOC_FREE(conv_smb_fname);
2378 errno = saved_errno;
2382 static int shadow_copy2_get_real_filename(struct vfs_handle_struct *handle,
2385 TALLOC_CTX *mem_ctx,
2388 time_t timestamp = 0;
2389 char *stripped = NULL;
2394 DEBUG(10, ("shadow_copy2_get_real_filename called for path=[%s], "
2395 "name=[%s]\n", path, name));
2397 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2398 ×tamp, &stripped)) {
2399 DEBUG(10, ("shadow_copy2_strip_snapshot failed\n"));
2402 if (timestamp == 0) {
2403 DEBUG(10, ("timestamp == 0\n"));
2404 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
2405 mem_ctx, found_name);
2407 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2408 TALLOC_FREE(stripped);
2410 DEBUG(10, ("shadow_copy2_convert failed\n"));
2413 DEBUG(10, ("Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
2414 "name=[%s]\n", conv, name));
2415 ret = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, conv, name,
2416 mem_ctx, found_name);
2417 DEBUG(10, ("NEXT_REAL_FILE_NAME returned %d\n", (int)ret));
2418 saved_errno = errno;
2420 errno = saved_errno;
2424 static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
2427 time_t timestamp = 0;
2428 char *stripped = NULL;
2430 char *result = NULL;
2431 char *parent_dir = NULL;
2433 size_t rootpath_len = 0;
2434 struct shadow_copy2_private *priv = NULL;
2436 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
2439 DBG_DEBUG("Calc connect path for [%s]\n", fname);
2441 if (priv->shadow_connectpath != NULL) {
2442 DBG_DEBUG("cached connect path is [%s]\n",
2443 priv->shadow_connectpath);
2444 return priv->shadow_connectpath;
2447 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2448 ×tamp, &stripped)) {
2451 if (timestamp == 0) {
2452 return SMB_VFS_NEXT_CONNECTPATH(handle, fname);
2455 tmp = shadow_copy2_do_convert(talloc_tos(), handle, stripped, timestamp,
2458 if (errno != ENOENT) {
2463 * If the converted path does not exist, and converting
2464 * the parent yields something that does exist, then
2465 * this path refers to something that has not been
2466 * created yet, relative to the parent path.
2467 * The snapshot finding is relative to the parent.
2468 * (usually snapshots are read/only but this is not
2469 * necessarily true).
2470 * This code also covers getting a wildcard in the
2471 * last component, because this function is called
2472 * prior to sanitizing the path, and in SMB1 we may
2473 * get wildcards in path names.
2475 if (!parent_dirname(talloc_tos(), stripped, &parent_dir,
2481 tmp = shadow_copy2_do_convert(talloc_tos(), handle, parent_dir,
2482 timestamp, &rootpath_len);
2488 DBG_DEBUG("converted path is [%s] root path is [%.*s]\n", tmp,
2489 (int)rootpath_len, tmp);
2491 tmp[rootpath_len] = '\0';
2492 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
2493 if (result == NULL) {
2497 DBG_DEBUG("connect path is [%s]\n", result);
2500 saved_errno = errno;
2502 TALLOC_FREE(stripped);
2503 TALLOC_FREE(parent_dir);
2504 errno = saved_errno;
2508 static uint64_t shadow_copy2_disk_free(vfs_handle_struct *handle,
2509 const char *path, uint64_t *bsize,
2510 uint64_t *dfree, uint64_t *dsize)
2512 time_t timestamp = 0;
2513 char *stripped = NULL;
2518 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2519 ×tamp, &stripped)) {
2522 if (timestamp == 0) {
2523 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2524 bsize, dfree, dsize);
2527 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2528 TALLOC_FREE(stripped);
2533 ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
2535 saved_errno = errno;
2537 errno = saved_errno;
2542 static int shadow_copy2_get_quota(vfs_handle_struct *handle, const char *path,
2543 enum SMB_QUOTA_TYPE qtype, unid_t id,
2546 time_t timestamp = 0;
2547 char *stripped = NULL;
2552 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path, ×tamp,
2556 if (timestamp == 0) {
2557 return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
2560 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2561 TALLOC_FREE(stripped);
2566 ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv, qtype, id, dq);
2568 saved_errno = errno;
2570 errno = saved_errno;
2575 static int shadow_copy2_connect(struct vfs_handle_struct *handle,
2576 const char *service, const char *user)
2578 struct shadow_copy2_config *config;
2579 struct shadow_copy2_private *priv;
2581 const char *snapdir;
2582 const char *snapprefix = NULL;
2583 const char *delimiter;
2584 const char *gmt_format;
2585 const char *sort_order;
2586 const char *basedir = NULL;
2587 const char *snapsharepath = NULL;
2588 const char *mount_point;
2590 DEBUG(10, (__location__ ": cnum[%u], connectpath[%s]\n",
2591 (unsigned)handle->conn->cnum,
2592 handle->conn->connectpath));
2594 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
2599 priv = talloc_zero(handle->conn, struct shadow_copy2_private);
2601 DBG_ERR("talloc_zero() failed\n");
2606 priv->snaps = talloc_zero(priv, struct shadow_copy2_snaplist_info);
2607 if (priv->snaps == NULL) {
2608 DBG_ERR("talloc_zero() failed\n");
2613 config = talloc_zero(priv, struct shadow_copy2_config);
2614 if (config == NULL) {
2615 DEBUG(0, ("talloc_zero() failed\n"));
2620 priv->config = config;
2622 gmt_format = lp_parm_const_string(SNUM(handle->conn),
2625 config->gmt_format = talloc_strdup(config, gmt_format);
2626 if (config->gmt_format == NULL) {
2627 DEBUG(0, ("talloc_strdup() failed\n"));
2632 /* config->gmt_format must not contain a path separator. */
2633 if (strchr(config->gmt_format, '/') != NULL) {
2634 DEBUG(0, ("shadow:format %s must not contain a /"
2635 "character. Unable to initialize module.\n",
2636 config->gmt_format));
2641 config->use_sscanf = lp_parm_bool(SNUM(handle->conn),
2642 "shadow", "sscanf", false);
2644 config->use_localtime = lp_parm_bool(SNUM(handle->conn),
2645 "shadow", "localtime",
2648 snapdir = lp_parm_const_string(SNUM(handle->conn),
2649 "shadow", "snapdir",
2651 config->snapdir = talloc_strdup(config, snapdir);
2652 if (config->snapdir == NULL) {
2653 DEBUG(0, ("talloc_strdup() failed\n"));
2658 snapprefix = lp_parm_const_string(SNUM(handle->conn),
2659 "shadow", "snapprefix",
2661 if (snapprefix != NULL) {
2662 priv->snaps->regex = talloc_zero(priv->snaps, regex_t);
2663 if (priv->snaps->regex == NULL) {
2664 DBG_ERR("talloc_zero() failed\n");
2669 /* pre-compute regex rule for matching pattern later */
2670 ret = regcomp(priv->snaps->regex, snapprefix, 0);
2672 DBG_ERR("Failed to create regex object\n");
2677 delimiter = lp_parm_const_string(SNUM(handle->conn),
2678 "shadow", "delimiter",
2680 if (delimiter != NULL) {
2681 priv->config->delimiter = talloc_strdup(priv->config, delimiter);
2682 if (priv->config->delimiter == NULL) {
2683 DBG_ERR("talloc_strdup() failed\n");
2689 config->snapdirseverywhere = lp_parm_bool(SNUM(handle->conn),
2691 "snapdirseverywhere",
2694 config->crossmountpoints = lp_parm_bool(SNUM(handle->conn),
2695 "shadow", "crossmountpoints",
2698 if (config->crossmountpoints && !config->snapdirseverywhere) {
2699 DBG_WARNING("Warning: 'crossmountpoints' depends on "
2700 "'snapdirseverywhere'. Disabling crossmountpoints.\n");
2703 config->fixinodes = lp_parm_bool(SNUM(handle->conn),
2704 "shadow", "fixinodes",
2707 sort_order = lp_parm_const_string(SNUM(handle->conn),
2708 "shadow", "sort", "desc");
2709 config->sort_order = talloc_strdup(config, sort_order);
2710 if (config->sort_order == NULL) {
2711 DEBUG(0, ("talloc_strdup() failed\n"));
2716 mount_point = lp_parm_const_string(SNUM(handle->conn),
2717 "shadow", "mountpoint", NULL);
2718 if (mount_point != NULL) {
2719 if (mount_point[0] != '/') {
2720 DEBUG(1, (__location__ " Warning: 'mountpoint' is "
2721 "relative ('%s'), but it has to be an "
2722 "absolute path. Ignoring provided value.\n",
2727 p = strstr(handle->conn->connectpath, mount_point);
2728 if (p != handle->conn->connectpath) {
2729 DBG_WARNING("Warning: the share root (%s) is "
2730 "not a subdirectory of the "
2731 "specified mountpoint (%s). "
2732 "Ignoring provided value.\n",
2733 handle->conn->connectpath,
2740 if (mount_point != NULL) {
2741 config->mount_point = talloc_strdup(config, mount_point);
2742 if (config->mount_point == NULL) {
2743 DEBUG(0, (__location__ " talloc_strdup() failed\n"));
2747 config->mount_point = shadow_copy2_find_mount_point(config,
2749 if (config->mount_point == NULL) {
2750 DBG_WARNING("shadow_copy2_find_mount_point "
2751 "of the share root '%s' failed: %s\n",
2752 handle->conn->connectpath, strerror(errno));
2757 basedir = lp_parm_const_string(SNUM(handle->conn),
2758 "shadow", "basedir", NULL);
2760 if (basedir != NULL) {
2761 if (basedir[0] != '/') {
2762 DEBUG(1, (__location__ " Warning: 'basedir' is "
2763 "relative ('%s'), but it has to be an "
2764 "absolute path. Disabling basedir.\n",
2769 p = strstr(basedir, config->mount_point);
2771 DEBUG(1, ("Warning: basedir (%s) is not a "
2772 "subdirectory of the share root's "
2773 "mount point (%s). "
2774 "Disabling basedir\n",
2775 basedir, config->mount_point));
2781 if (config->snapdirseverywhere && basedir != NULL) {
2782 DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
2783 "with 'snapdirseverywhere'. Disabling basedir.\n"));
2787 snapsharepath = lp_parm_const_string(SNUM(handle->conn), "shadow",
2788 "snapsharepath", NULL);
2789 if (snapsharepath != NULL) {
2790 if (snapsharepath[0] == '/') {
2791 DBG_WARNING("Warning: 'snapsharepath' is "
2792 "absolute ('%s'), but it has to be a "
2793 "relative path. Disabling snapsharepath.\n",
2795 snapsharepath = NULL;
2797 if (config->snapdirseverywhere && snapsharepath != NULL) {
2798 DBG_WARNING("Warning: 'snapsharepath' is incompatible "
2799 "with 'snapdirseverywhere'. Disabling "
2800 "snapsharepath.\n");
2801 snapsharepath = NULL;
2805 if (basedir != NULL && snapsharepath != NULL) {
2806 DBG_WARNING("Warning: 'snapsharepath' is incompatible with "
2807 "'basedir'. Disabling snapsharepath\n");
2808 snapsharepath = NULL;
2811 if (snapsharepath != NULL) {
2812 config->rel_connectpath = talloc_strdup(config, snapsharepath);
2813 if (config->rel_connectpath == NULL) {
2814 DBG_ERR("talloc_strdup() failed\n");
2820 if (basedir == NULL) {
2821 basedir = config->mount_point;
2824 if (config->rel_connectpath == NULL &&
2825 strlen(basedir) < strlen(handle->conn->connectpath)) {
2826 config->rel_connectpath = talloc_strdup(config,
2827 handle->conn->connectpath + strlen(basedir));
2828 if (config->rel_connectpath == NULL) {
2829 DEBUG(0, ("talloc_strdup() failed\n"));
2835 if (config->snapdir[0] == '/') {
2836 config->snapdir_absolute = true;
2838 if (config->snapdirseverywhere == true) {
2839 DEBUG(1, (__location__ " Warning: An absolute snapdir "
2840 "is incompatible with 'snapdirseverywhere', "
2841 "setting 'snapdirseverywhere' to false.\n"));
2842 config->snapdirseverywhere = false;
2845 if (config->crossmountpoints == true) {
2846 DEBUG(1, (__location__ " Warning: 'crossmountpoints' "
2847 "is not supported with an absolute snapdir. "
2848 "Disabling it.\n"));
2849 config->crossmountpoints = false;
2852 config->snapshot_basepath = config->snapdir;
2854 config->snapshot_basepath = talloc_asprintf(config, "%s/%s",
2855 config->mount_point, config->snapdir);
2856 if (config->snapshot_basepath == NULL) {
2857 DEBUG(0, ("talloc_asprintf() failed\n"));
2863 trim_string(config->mount_point, NULL, "/");
2864 trim_string(config->rel_connectpath, "/", "/");
2865 trim_string(config->snapdir, NULL, "/");
2866 trim_string(config->snapshot_basepath, NULL, "/");
2868 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
2869 " share root: '%s'\n"
2870 " mountpoint: '%s'\n"
2871 " rel share root: '%s'\n"
2873 " snapprefix: '%s'\n"
2874 " delimiter: '%s'\n"
2875 " snapshot base path: '%s'\n"
2878 " snapdirs everywhere: %s\n"
2879 " cross mountpoints: %s\n"
2883 handle->conn->connectpath,
2884 config->mount_point,
2885 config->rel_connectpath,
2889 config->snapshot_basepath,
2891 config->use_sscanf ? "yes" : "no",
2892 config->snapdirseverywhere ? "yes" : "no",
2893 config->crossmountpoints ? "yes" : "no",
2894 config->fixinodes ? "yes" : "no",
2899 SMB_VFS_HANDLE_SET_DATA(handle, priv,
2900 NULL, struct shadow_copy2_private,
2906 static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
2907 .connect_fn = shadow_copy2_connect,
2908 .opendir_fn = shadow_copy2_opendir,
2909 .disk_free_fn = shadow_copy2_disk_free,
2910 .get_quota_fn = shadow_copy2_get_quota,
2911 .rename_fn = shadow_copy2_rename,
2912 .link_fn = shadow_copy2_link,
2913 .symlink_fn = shadow_copy2_symlink,
2914 .stat_fn = shadow_copy2_stat,
2915 .lstat_fn = shadow_copy2_lstat,
2916 .fstat_fn = shadow_copy2_fstat,
2917 .open_fn = shadow_copy2_open,
2918 .unlink_fn = shadow_copy2_unlink,
2919 .chmod_fn = shadow_copy2_chmod,
2920 .chown_fn = shadow_copy2_chown,
2921 .chdir_fn = shadow_copy2_chdir,
2922 .ntimes_fn = shadow_copy2_ntimes,
2923 .readlink_fn = shadow_copy2_readlink,
2924 .mknod_fn = shadow_copy2_mknod,
2925 .realpath_fn = shadow_copy2_realpath,
2926 .get_nt_acl_fn = shadow_copy2_get_nt_acl,
2927 .fget_nt_acl_fn = shadow_copy2_fget_nt_acl,
2928 .get_shadow_copy_data_fn = shadow_copy2_get_shadow_copy_data,
2929 .mkdir_fn = shadow_copy2_mkdir,
2930 .rmdir_fn = shadow_copy2_rmdir,
2931 .getxattr_fn = shadow_copy2_getxattr,
2932 .listxattr_fn = shadow_copy2_listxattr,
2933 .removexattr_fn = shadow_copy2_removexattr,
2934 .setxattr_fn = shadow_copy2_setxattr,
2935 .chmod_acl_fn = shadow_copy2_chmod_acl,
2936 .chflags_fn = shadow_copy2_chflags,
2937 .get_real_filename_fn = shadow_copy2_get_real_filename,
2938 .connectpath_fn = shadow_copy2_connectpath,
2941 NTSTATUS vfs_shadow_copy2_init(void);
2942 NTSTATUS vfs_shadow_copy2_init(void)
2944 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2945 "shadow_copy2", &vfs_shadow_copy2_fns);