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);
456 * Strip a snapshot component from a filename as
457 * handed in via the smb layer.
458 * Returns the parsed timestamp and the stripped filename.
460 static bool shadow_copy2_strip_snapshot_internal(TALLOC_CTX *mem_ctx,
461 struct vfs_handle_struct *handle,
462 const char *orig_name,
468 time_t timestamp = 0;
471 char *stripped = NULL;
472 size_t rest_len, dst_len;
473 struct shadow_copy2_private *priv;
476 ptrdiff_t len_before_gmt;
477 const char *name = orig_name;
479 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
482 DEBUG(10, (__location__ ": enter path '%s'\n", name));
484 p = strstr_m(name, "@GMT-");
486 DEBUG(11, ("@GMT not found\n"));
489 if ((p > name) && (p[-1] != '/')) {
490 /* the GMT-token does not start a path-component */
491 DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
492 p, name, (int)p[-1]));
497 * Figure out whether we got an already converted string. One
498 * case where this happens is in a smb2 create call with the
499 * mxac create blob set. We do the get_acl call on
500 * fsp->fsp_name, which is already converted. We are converted
501 * if we got a file name of the form ".snapshots/@GMT-",
502 * i.e. ".snapshots/" precedes "p".
505 snapdir = lp_parm_const_string(SNUM(handle->conn), "shadow", "snapdir",
507 snapdirlen = strlen(snapdir);
508 len_before_gmt = p - name;
510 if ((len_before_gmt >= (snapdirlen + 1)) && (p[-1] == '/')) {
511 const char *parent_snapdir = p - (snapdirlen+1);
513 DEBUG(10, ("parent_snapdir = %s\n", parent_snapdir));
515 if (strncmp(parent_snapdir, snapdir, snapdirlen) == 0) {
516 DEBUG(10, ("name=%s is already converted\n", name));
520 q = strptime(p, GMT_FORMAT, &tm);
522 DEBUG(10, ("strptime failed\n"));
526 timestamp = timegm(&tm);
527 if (timestamp == (time_t)-1) {
528 DEBUG(10, ("timestamp==-1\n"));
533 * The name consists of only the GMT token or the GMT
534 * token is at the end of the path. XP seems to send
535 * @GMT- at the end under certain circumstances even
536 * with a path prefix.
538 if (pstripped != NULL) {
539 if (len_before_gmt > 0) {
541 * There is a slash before
542 * the @GMT-. Remove it.
546 stripped = talloc_strndup(mem_ctx, name,
548 if (stripped == NULL) {
551 *pstripped = stripped;
553 *ptimestamp = timestamp;
558 * It is not a complete path component, i.e. the path
559 * component continues after the gmt-token.
561 DEBUG(10, ("q[0] = %d\n", (int)q[0]));
566 rest_len = strlen(q);
567 dst_len = len_before_gmt + rest_len;
569 if (priv->config->snapdirseverywhere) {
572 insert = shadow_copy2_insert_string(talloc_tos(), handle,
574 if (insert == NULL) {
579 DEBUG(10, (__location__ ": snapdirseverywhere mode.\n"
581 "insert string '%s'\n", name, insert));
583 have_insert = (strstr(name, insert+1) != NULL);
584 DEBUG(10, ("have_insert=%d, name=%s, insert+1=%s\n",
585 (int)have_insert, name, insert+1));
587 DEBUG(10, (__location__ ": insert string '%s' found in "
588 "path '%s' found in snapdirseverywhere mode "
589 "==> already converted\n", insert, name));
598 snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
601 if (snapshot_path == NULL) {
606 DEBUG(10, (__location__ " path: '%s'.\n"
607 "snapshot path: '%s'\n", name, snapshot_path));
609 s = strstr(name, snapshot_path);
612 * this starts with "snapshot_basepath/GMT-Token"
613 * so it is already a converted absolute
614 * path. Don't process further.
616 DEBUG(10, (__location__ ": path '%s' starts with "
617 "snapshot path '%s' (not in "
618 "snapdirseverywhere mode) ==> "
619 "already converted\n", name, snapshot_path));
620 talloc_free(snapshot_path);
623 talloc_free(snapshot_path);
626 if (pstripped != NULL) {
627 stripped = talloc_array(mem_ctx, char, dst_len+1);
628 if (stripped == NULL) {
633 memcpy(stripped, name, len_before_gmt);
636 memcpy(stripped + len_before_gmt, q, rest_len);
638 stripped[dst_len] = '\0';
639 *pstripped = stripped;
641 *ptimestamp = timestamp;
648 static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
649 struct vfs_handle_struct *handle,
650 const char *orig_name,
654 return shadow_copy2_strip_snapshot_internal(mem_ctx,
662 static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
663 vfs_handle_struct *handle)
665 char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
670 if (stat(path, &st) != 0) {
677 while ((p = strrchr(path, '/')) && p > path) {
679 if (stat(path, &st) != 0) {
683 if (st.st_dev != dev) {
693 * Convert from a name as handed in via the SMB layer
694 * and a timestamp into the local path of the snapshot
695 * of the provided file at the provided time.
696 * Also return the path in the snapshot corresponding
697 * to the file's share root.
699 static char *shadow_copy2_do_convert(TALLOC_CTX *mem_ctx,
700 struct vfs_handle_struct *handle,
701 const char *name, time_t timestamp,
702 size_t *snaproot_len)
704 struct smb_filename converted_fname;
706 size_t *slashes = NULL;
707 unsigned num_slashes;
711 char *converted = NULL;
712 size_t insertlen, connectlen = 0;
715 struct shadow_copy2_config *config;
716 struct shadow_copy2_private *priv;
717 size_t in_share_offset = 0;
719 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
722 config = priv->config;
724 DEBUG(10, ("converting '%s'\n", name));
726 if (!config->snapdirseverywhere) {
730 snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
733 if (snapshot_path == NULL) {
737 if (config->rel_connectpath == NULL) {
738 converted = talloc_asprintf(mem_ctx, "%s/%s",
739 snapshot_path, name);
741 converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
743 config->rel_connectpath,
746 if (converted == NULL) {
750 ZERO_STRUCT(converted_fname);
751 converted_fname.base_name = converted;
753 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
754 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
756 ret, ret == 0 ? "ok" : strerror(errno)));
758 DEBUG(10, ("Found %s\n", converted));
761 if (snaproot_len != NULL) {
762 *snaproot_len = strlen(snapshot_path);
763 if (config->rel_connectpath != NULL) {
765 strlen(config->rel_connectpath) + 1;
773 /* never reached ... */
776 connectlen = strlen(handle->conn->connectpath);
778 path = talloc_strdup(mem_ctx, handle->conn->connectpath);
780 path = talloc_asprintf(
781 mem_ctx, "%s/%s", handle->conn->connectpath, name);
787 pathlen = talloc_get_size(path)-1;
789 if (!shadow_copy2_find_slashes(talloc_tos(), path,
790 &slashes, &num_slashes)) {
794 insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
795 if (insert == NULL) {
798 insertlen = talloc_get_size(insert)-1;
801 * Note: We deliberatly don't expensively initialize the
802 * array with talloc_zero here: Putting zero into
803 * converted[pathlen+insertlen] below is sufficient, because
804 * in the following for loop, the insert string is inserted
805 * at various slash places. So the memory up to position
806 * pathlen+insertlen will always be initialized when the
807 * converted string is used.
809 converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
810 if (converted == NULL) {
814 if (path[pathlen-1] != '/') {
816 * Append a fake slash to find the snapshot root
819 tmp = talloc_realloc(talloc_tos(), slashes,
820 size_t, num_slashes+1);
825 slashes[num_slashes] = pathlen;
831 if (!config->crossmountpoints) {
832 min_offset = strlen(config->mount_point);
835 memcpy(converted, path, pathlen+1);
836 converted[pathlen+insertlen] = '\0';
838 ZERO_STRUCT(converted_fname);
839 converted_fname.base_name = converted;
841 for (i = num_slashes-1; i>=0; i--) {
847 if (offset < min_offset) {
852 if (offset >= connectlen) {
853 in_share_offset = offset;
856 memcpy(converted+offset, insert, insertlen);
859 memcpy(converted+offset, path + slashes[i],
860 pathlen - slashes[i]);
862 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
864 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
866 ret, ret == 0 ? "ok" : strerror(errno)));
869 if (snaproot_len != NULL) {
870 *snaproot_len = in_share_offset + insertlen;
874 if (errno == ENOTDIR) {
876 * This is a valid condition: We appended the
877 * .snaphots/@GMT.. to a file name. Just try
878 * with the upper levels.
882 if (errno != ENOENT) {
883 /* Other problem than "not found" */
892 DEBUG(10, ("Found %s\n", converted));
900 TALLOC_FREE(converted);
902 TALLOC_FREE(slashes);
909 * Convert from a name as handed in via the SMB layer
910 * and a timestamp into the local path of the snapshot
911 * of the provided file at the provided time.
913 static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
914 struct vfs_handle_struct *handle,
915 const char *name, time_t timestamp)
917 return shadow_copy2_do_convert(mem_ctx, handle, name, timestamp, NULL);
921 modify a sbuf return to ensure that inodes in the shadow directory
922 are different from those in the main directory
924 static void convert_sbuf(vfs_handle_struct *handle, const char *fname,
925 SMB_STRUCT_STAT *sbuf)
927 struct shadow_copy2_private *priv;
929 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
932 if (priv->config->fixinodes) {
933 /* some snapshot systems, like GPFS, return the name
934 device:inode for the snapshot files as the current
935 files. That breaks the 'restore' button in the shadow copy
936 GUI, as the client gets a sharing violation.
938 This is a crude way of allowing both files to be
939 open at once. It has a slight chance of inode
940 number collision, but I can't see a better approach
941 without significant VFS changes
943 TDB_DATA key = { .dptr = discard_const_p(uint8_t, fname),
944 .dsize = strlen(fname) };
947 shash = tdb_jenkins_hash(&key) & 0xFF000000;
951 sbuf->st_ex_ino ^= shash;
955 static DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
956 const struct smb_filename *smb_fname,
960 time_t timestamp = 0;
961 char *stripped = NULL;
965 struct smb_filename *conv_smb_fname = NULL;
967 if (!shadow_copy2_strip_snapshot(talloc_tos(),
969 smb_fname->base_name,
974 if (timestamp == 0) {
975 return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
977 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
978 TALLOC_FREE(stripped);
982 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
987 if (conv_smb_fname == NULL) {
991 ret = SMB_VFS_NEXT_OPENDIR(handle, conv_smb_fname, mask, attr);
994 TALLOC_FREE(conv_smb_fname);
999 static int shadow_copy2_rename(vfs_handle_struct *handle,
1000 const struct smb_filename *smb_fname_src,
1001 const struct smb_filename *smb_fname_dst)
1003 time_t timestamp_src = 0;
1004 time_t timestamp_dst = 0;
1006 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1007 smb_fname_src->base_name,
1008 ×tamp_src, NULL)) {
1011 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1012 smb_fname_dst->base_name,
1013 ×tamp_dst, NULL)) {
1016 if (timestamp_src != 0) {
1020 if (timestamp_dst != 0) {
1024 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1027 static int shadow_copy2_symlink(vfs_handle_struct *handle,
1028 const char *oldname, const char *newname)
1030 time_t timestamp_old = 0;
1031 time_t timestamp_new = 0;
1033 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
1034 ×tamp_old, NULL)) {
1037 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
1038 ×tamp_new, NULL)) {
1041 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1045 return SMB_VFS_NEXT_SYMLINK(handle, oldname, newname);
1048 static int shadow_copy2_link(vfs_handle_struct *handle,
1049 const char *oldname, const char *newname)
1051 time_t timestamp_old = 0;
1052 time_t timestamp_new = 0;
1054 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, oldname,
1055 ×tamp_old, NULL)) {
1058 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, newname,
1059 ×tamp_new, NULL)) {
1062 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1066 return SMB_VFS_NEXT_LINK(handle, oldname, newname);
1069 static int shadow_copy2_stat(vfs_handle_struct *handle,
1070 struct smb_filename *smb_fname)
1072 time_t timestamp = 0;
1073 char *stripped = NULL;
1075 int ret, saved_errno;
1077 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1078 smb_fname->base_name,
1079 ×tamp, &stripped)) {
1082 if (timestamp == 0) {
1083 return SMB_VFS_NEXT_STAT(handle, smb_fname);
1086 tmp = smb_fname->base_name;
1087 smb_fname->base_name = shadow_copy2_convert(
1088 talloc_tos(), handle, stripped, timestamp);
1089 TALLOC_FREE(stripped);
1091 if (smb_fname->base_name == NULL) {
1092 smb_fname->base_name = tmp;
1096 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1097 saved_errno = errno;
1099 TALLOC_FREE(smb_fname->base_name);
1100 smb_fname->base_name = tmp;
1103 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1105 errno = saved_errno;
1109 static int shadow_copy2_lstat(vfs_handle_struct *handle,
1110 struct smb_filename *smb_fname)
1112 time_t timestamp = 0;
1113 char *stripped = NULL;
1115 int ret, saved_errno;
1117 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1118 smb_fname->base_name,
1119 ×tamp, &stripped)) {
1122 if (timestamp == 0) {
1123 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1126 tmp = smb_fname->base_name;
1127 smb_fname->base_name = shadow_copy2_convert(
1128 talloc_tos(), handle, stripped, timestamp);
1129 TALLOC_FREE(stripped);
1131 if (smb_fname->base_name == NULL) {
1132 smb_fname->base_name = tmp;
1136 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1137 saved_errno = errno;
1139 TALLOC_FREE(smb_fname->base_name);
1140 smb_fname->base_name = tmp;
1143 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1145 errno = saved_errno;
1149 static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
1150 SMB_STRUCT_STAT *sbuf)
1152 time_t timestamp = 0;
1155 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1159 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1160 fsp->fsp_name->base_name,
1161 ×tamp, NULL)) {
1164 if (timestamp != 0) {
1165 convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
1170 static int shadow_copy2_open(vfs_handle_struct *handle,
1171 struct smb_filename *smb_fname, files_struct *fsp,
1172 int flags, mode_t mode)
1174 time_t timestamp = 0;
1175 char *stripped = NULL;
1177 int ret, saved_errno;
1179 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1180 smb_fname->base_name,
1181 ×tamp, &stripped)) {
1184 if (timestamp == 0) {
1185 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1188 tmp = smb_fname->base_name;
1189 smb_fname->base_name = shadow_copy2_convert(
1190 talloc_tos(), handle, stripped, timestamp);
1191 TALLOC_FREE(stripped);
1193 if (smb_fname->base_name == NULL) {
1194 smb_fname->base_name = tmp;
1198 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1199 saved_errno = errno;
1201 TALLOC_FREE(smb_fname->base_name);
1202 smb_fname->base_name = tmp;
1204 errno = saved_errno;
1208 static int shadow_copy2_unlink(vfs_handle_struct *handle,
1209 const struct smb_filename *smb_fname)
1211 time_t timestamp = 0;
1212 char *stripped = NULL;
1213 int ret, saved_errno;
1214 struct smb_filename *conv;
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_UNLINK(handle, smb_fname);
1224 conv = cp_smb_filename(talloc_tos(), smb_fname);
1229 conv->base_name = shadow_copy2_convert(
1230 conv, handle, stripped, timestamp);
1231 TALLOC_FREE(stripped);
1232 if (conv->base_name == NULL) {
1235 ret = SMB_VFS_NEXT_UNLINK(handle, conv);
1236 saved_errno = errno;
1238 errno = saved_errno;
1242 static int shadow_copy2_chmod(vfs_handle_struct *handle,
1243 const struct smb_filename *smb_fname,
1246 time_t timestamp = 0;
1247 char *stripped = NULL;
1248 int ret, saved_errno;
1250 struct smb_filename *conv_smb_fname;
1252 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1254 smb_fname->base_name,
1259 if (timestamp == 0) {
1260 TALLOC_FREE(stripped);
1261 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1263 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1264 TALLOC_FREE(stripped);
1268 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1273 if (conv_smb_fname == NULL) {
1279 ret = SMB_VFS_NEXT_CHMOD(handle, conv_smb_fname, mode);
1280 saved_errno = errno;
1282 TALLOC_FREE(conv_smb_fname);
1283 errno = saved_errno;
1287 static int shadow_copy2_chown(vfs_handle_struct *handle,
1288 const struct smb_filename *smb_fname,
1292 time_t timestamp = 0;
1293 char *stripped = NULL;
1294 int ret, saved_errno;
1296 struct smb_filename *conv_smb_fname = NULL;
1298 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1300 smb_fname->base_name,
1305 if (timestamp == 0) {
1306 return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1308 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1309 TALLOC_FREE(stripped);
1313 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1318 if (conv_smb_fname == NULL) {
1323 ret = SMB_VFS_NEXT_CHOWN(handle, conv_smb_fname, uid, gid);
1324 saved_errno = errno;
1326 TALLOC_FREE(conv_smb_fname);
1327 errno = saved_errno;
1331 static void store_cwd_data(vfs_handle_struct *handle,
1332 const char *connectpath)
1334 struct shadow_copy2_private *priv = NULL;
1337 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1340 TALLOC_FREE(priv->shadow_cwd);
1341 cwd = SMB_VFS_NEXT_GETWD(handle);
1343 smb_panic("getwd failed\n");
1345 DBG_DEBUG("shadow cwd = %s\n", cwd);
1346 priv->shadow_cwd = talloc_strdup(priv, cwd);
1348 if (priv->shadow_cwd == NULL) {
1349 smb_panic("talloc failed\n");
1351 TALLOC_FREE(priv->shadow_connectpath);
1353 DBG_DEBUG("shadow conectpath = %s\n", connectpath);
1354 priv->shadow_connectpath = talloc_strdup(priv, connectpath);
1355 if (priv->shadow_connectpath == NULL) {
1356 smb_panic("talloc failed\n");
1361 static int shadow_copy2_chdir(vfs_handle_struct *handle,
1364 time_t timestamp = 0;
1365 char *stripped = NULL;
1366 char *snappath = NULL;
1368 int saved_errno = 0;
1370 size_t rootpath_len = 0;
1372 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, fname,
1373 ×tamp, &stripped, &snappath)) {
1376 if (stripped != NULL) {
1377 conv = shadow_copy2_do_convert(talloc_tos(),
1382 TALLOC_FREE(stripped);
1389 ret = SMB_VFS_NEXT_CHDIR(handle, fname);
1391 saved_errno = errno;
1395 if (conv != NULL && rootpath_len != 0) {
1396 conv[rootpath_len] = '\0';
1397 } else if (snappath != 0) {
1401 store_cwd_data(handle, conv);
1404 TALLOC_FREE(stripped);
1407 if (saved_errno != 0) {
1408 errno = saved_errno;
1413 static int shadow_copy2_ntimes(vfs_handle_struct *handle,
1414 const struct smb_filename *smb_fname,
1415 struct smb_file_time *ft)
1417 time_t timestamp = 0;
1418 char *stripped = NULL;
1419 int ret, saved_errno;
1420 struct smb_filename *conv;
1422 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1423 smb_fname->base_name,
1424 ×tamp, &stripped)) {
1427 if (timestamp == 0) {
1428 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1430 conv = cp_smb_filename(talloc_tos(), smb_fname);
1435 conv->base_name = shadow_copy2_convert(
1436 conv, handle, stripped, timestamp);
1437 TALLOC_FREE(stripped);
1438 if (conv->base_name == NULL) {
1441 ret = SMB_VFS_NEXT_NTIMES(handle, conv, ft);
1442 saved_errno = errno;
1444 errno = saved_errno;
1448 static int shadow_copy2_readlink(vfs_handle_struct *handle,
1449 const char *fname, char *buf, size_t bufsiz)
1451 time_t timestamp = 0;
1452 char *stripped = NULL;
1453 int ret, saved_errno;
1456 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1457 ×tamp, &stripped)) {
1460 if (timestamp == 0) {
1461 return SMB_VFS_NEXT_READLINK(handle, fname, buf, bufsiz);
1463 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1464 TALLOC_FREE(stripped);
1468 ret = SMB_VFS_NEXT_READLINK(handle, conv, buf, bufsiz);
1469 saved_errno = errno;
1471 errno = saved_errno;
1475 static int shadow_copy2_mknod(vfs_handle_struct *handle,
1476 const char *fname, mode_t mode, SMB_DEV_T dev)
1478 time_t timestamp = 0;
1479 char *stripped = NULL;
1480 int ret, saved_errno;
1483 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1484 ×tamp, &stripped)) {
1487 if (timestamp == 0) {
1488 return SMB_VFS_NEXT_MKNOD(handle, fname, mode, dev);
1490 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1491 TALLOC_FREE(stripped);
1495 ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
1496 saved_errno = errno;
1498 errno = saved_errno;
1502 static char *shadow_copy2_realpath(vfs_handle_struct *handle,
1505 time_t timestamp = 0;
1506 char *stripped = NULL;
1508 char *result = NULL;
1511 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1512 ×tamp, &stripped)) {
1515 if (timestamp == 0) {
1516 return SMB_VFS_NEXT_REALPATH(handle, fname);
1519 tmp = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1524 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
1527 saved_errno = errno;
1529 TALLOC_FREE(stripped);
1530 errno = saved_errno;
1535 * Check whether a given directory contains a
1536 * snapshot directory as direct subdirectory.
1537 * If yes, return the path of the snapshot-subdir,
1538 * otherwise return NULL.
1540 static char *have_snapdir(struct vfs_handle_struct *handle,
1543 struct smb_filename smb_fname;
1545 struct shadow_copy2_private *priv;
1547 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1550 ZERO_STRUCT(smb_fname);
1551 smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
1552 path, priv->config->snapdir);
1553 if (smb_fname.base_name == NULL) {
1557 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1558 if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
1559 return smb_fname.base_name;
1561 TALLOC_FREE(smb_fname.base_name);
1565 static bool check_access_snapdir(struct vfs_handle_struct *handle,
1568 struct smb_filename smb_fname;
1572 ZERO_STRUCT(smb_fname);
1573 smb_fname.base_name = talloc_asprintf(talloc_tos(),
1576 if (smb_fname.base_name == NULL) {
1580 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1581 if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
1582 TALLOC_FREE(smb_fname.base_name);
1586 status = smbd_check_access_rights(handle->conn,
1590 if (!NT_STATUS_IS_OK(status)) {
1591 DEBUG(0,("user does not have list permission "
1593 smb_fname.base_name));
1594 TALLOC_FREE(smb_fname.base_name);
1597 TALLOC_FREE(smb_fname.base_name);
1602 * Find the snapshot directory (if any) for the given
1603 * filename (which is relative to the share).
1605 static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx,
1606 struct vfs_handle_struct *handle,
1607 struct smb_filename *smb_fname)
1610 const char *snapdir;
1611 struct shadow_copy2_config *config;
1612 struct shadow_copy2_private *priv;
1614 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1617 config = priv->config;
1620 * If the non-snapdisrseverywhere mode, we should not search!
1622 if (!config->snapdirseverywhere) {
1623 return config->snapshot_basepath;
1626 path = talloc_asprintf(mem_ctx, "%s/%s",
1627 handle->conn->connectpath,
1628 smb_fname->base_name);
1633 snapdir = have_snapdir(handle, path);
1634 if (snapdir != NULL) {
1639 while ((p = strrchr(path, '/')) && (p > path)) {
1643 snapdir = have_snapdir(handle, path);
1644 if (snapdir != NULL) {
1653 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
1655 char *gmt, size_t gmt_len)
1657 struct tm timestamp;
1659 unsigned long int timestamp_long;
1661 struct shadow_copy2_config *config;
1662 struct shadow_copy2_private *priv;
1663 char *tmpstr = NULL;
1665 bool converted = false;
1668 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1671 config = priv->config;
1673 fmt = config->gmt_format;
1676 * If regex is provided, then we will have to parse the
1677 * filename which will contain both the prefix and the time format.
1678 * e.g. <prefix><delimiter><time_format>
1680 if (priv->snaps->regex != NULL) {
1681 tmpstr = talloc_strdup(talloc_tos(), name);
1682 /* point "name" to the time format */
1683 name = strstr(name, priv->config->delimiter);
1687 /* Extract the prefix */
1688 tmp = strstr(tmpstr, priv->config->delimiter);
1692 ret = regexec(priv->snaps->regex, tmpstr, 0, NULL, 0);
1694 DBG_DEBUG("shadow_copy2_snapshot_to_gmt: "
1695 "no regex match for %s\n", tmpstr);
1700 ZERO_STRUCT(timestamp);
1701 if (config->use_sscanf) {
1702 if (sscanf(name, fmt, ×tamp_long) != 1) {
1703 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1704 "no sscanf match %s: %s\n",
1708 timestamp_t = timestamp_long;
1709 gmtime_r(×tamp_t, ×tamp);
1711 if (strptime(name, fmt, ×tamp) == NULL) {
1712 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1713 "no match %s: %s\n",
1717 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1720 if (config->use_localtime) {
1721 timestamp.tm_isdst = -1;
1722 timestamp_t = mktime(×tamp);
1723 gmtime_r(×tamp_t, ×tamp);
1727 strftime(gmt, gmt_len, GMT_FORMAT, ×tamp);
1731 TALLOC_FREE(tmpstr);
1735 static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
1737 return strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1740 static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
1742 return -strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1746 sort the shadow copy data in ascending or descending order
1748 static void shadow_copy2_sort_data(vfs_handle_struct *handle,
1749 struct shadow_copy_data *shadow_copy2_data)
1751 int (*cmpfunc)(const void *, const void *);
1753 struct shadow_copy2_private *priv;
1755 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1758 sort = priv->config->sort_order;
1763 if (strcmp(sort, "asc") == 0) {
1764 cmpfunc = shadow_copy2_label_cmp_asc;
1765 } else if (strcmp(sort, "desc") == 0) {
1766 cmpfunc = shadow_copy2_label_cmp_desc;
1771 if (shadow_copy2_data && shadow_copy2_data->num_volumes > 0 &&
1772 shadow_copy2_data->labels)
1774 TYPESAFE_QSORT(shadow_copy2_data->labels,
1775 shadow_copy2_data->num_volumes,
1780 static int shadow_copy2_get_shadow_copy_data(
1781 vfs_handle_struct *handle, files_struct *fsp,
1782 struct shadow_copy_data *shadow_copy2_data,
1786 const char *snapdir;
1787 struct smb_filename *snapdir_smb_fname = NULL;
1789 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1790 struct shadow_copy2_private *priv = NULL;
1791 struct shadow_copy2_snapentry *tmpentry = NULL;
1792 bool get_snaplist = false;
1793 bool access_granted = false;
1796 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
1797 if (snapdir == NULL) {
1798 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
1799 handle->conn->connectpath));
1804 access_granted = check_access_snapdir(handle, snapdir);
1805 if (!access_granted) {
1806 DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
1811 snapdir_smb_fname = synthetic_smb_fname(talloc_tos(),
1815 fsp->fsp_name->flags);
1816 if (snapdir_smb_fname == NULL) {
1821 p = SMB_VFS_NEXT_OPENDIR(handle, snapdir_smb_fname, NULL, 0);
1824 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
1825 " - %s\n", snapdir, strerror(errno)));
1830 if (shadow_copy2_data != NULL) {
1831 shadow_copy2_data->num_volumes = 0;
1832 shadow_copy2_data->labels = NULL;
1835 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1839 * Normally this function is called twice once with labels = false and
1840 * then with labels = true. When labels is false it will return the
1841 * number of volumes so that the caller can allocate memory for that
1842 * many labels. Therefore to eliminate snaplist both the times it is
1843 * good to check if labels is set or not.
1845 * shadow_copy2_data is NULL when we only want to update the list and
1846 * don't want any labels.
1848 if ((priv->snaps->regex != NULL) && (labels || shadow_copy2_data == NULL)) {
1849 get_snaplist = true;
1850 /* Reset the global snaplist */
1851 shadow_copy2_delete_snaplist(priv);
1853 /* Set the current time as snaplist update time */
1854 time(&(priv->snaps->fetch_time));
1857 while ((d = SMB_VFS_NEXT_READDIR(handle, p, NULL))) {
1858 char snapshot[GMT_NAME_LEN+1];
1859 SHADOW_COPY_LABEL *tlabels;
1862 * ignore names not of the right form in the snapshot
1865 if (!shadow_copy2_snapshot_to_gmt(
1867 snapshot, sizeof(snapshot))) {
1869 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
1870 "ignoring %s\n", d->d_name));
1873 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
1874 d->d_name, snapshot));
1878 * Create a snap entry for each successful
1881 tmpentry = shadow_copy2_create_snapentry(priv);
1882 if (tmpentry == NULL) {
1883 DBG_ERR("talloc_zero() failed\n");
1886 tmpentry->snapname = talloc_strdup(tmpentry, d->d_name);
1887 tmpentry->time_fmt = talloc_strdup(tmpentry, snapshot);
1890 if (shadow_copy2_data == NULL) {
1895 /* the caller doesn't want the labels */
1896 shadow_copy2_data->num_volumes++;
1900 tlabels = talloc_realloc(shadow_copy2_data,
1901 shadow_copy2_data->labels,
1903 shadow_copy2_data->num_volumes+1);
1904 if (tlabels == NULL) {
1905 DEBUG(0,("shadow_copy2: out of memory\n"));
1906 SMB_VFS_NEXT_CLOSEDIR(handle, p);
1910 strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot,
1913 shadow_copy2_data->num_volumes++;
1914 shadow_copy2_data->labels = tlabels;
1917 SMB_VFS_NEXT_CLOSEDIR(handle,p);
1919 shadow_copy2_sort_data(handle, shadow_copy2_data);
1923 TALLOC_FREE(tmp_ctx);
1927 static NTSTATUS shadow_copy2_fget_nt_acl(vfs_handle_struct *handle,
1928 struct files_struct *fsp,
1929 uint32_t security_info,
1930 TALLOC_CTX *mem_ctx,
1931 struct security_descriptor **ppdesc)
1933 time_t timestamp = 0;
1934 char *stripped = NULL;
1937 struct smb_filename *smb_fname = NULL;
1939 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1940 fsp->fsp_name->base_name,
1941 ×tamp, &stripped)) {
1942 return map_nt_error_from_unix(errno);
1944 if (timestamp == 0) {
1945 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
1949 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1950 TALLOC_FREE(stripped);
1952 return map_nt_error_from_unix(errno);
1954 smb_fname = synthetic_smb_fname(talloc_tos(),
1958 fsp->fsp_name->flags);
1959 if (smb_fname == NULL) {
1961 return NT_STATUS_NO_MEMORY;
1964 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
1967 TALLOC_FREE(smb_fname);
1971 static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
1972 const struct smb_filename *smb_fname,
1973 uint32_t security_info,
1974 TALLOC_CTX *mem_ctx,
1975 struct security_descriptor **ppdesc)
1977 time_t timestamp = 0;
1978 char *stripped = NULL;
1981 struct smb_filename *conv_smb_fname = NULL;
1983 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1985 smb_fname->base_name,
1988 return map_nt_error_from_unix(errno);
1990 if (timestamp == 0) {
1991 return SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
1994 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1995 TALLOC_FREE(stripped);
1997 return map_nt_error_from_unix(errno);
1999 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2004 if (conv_smb_fname == NULL) {
2006 return NT_STATUS_NO_MEMORY;
2008 status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv_smb_fname, security_info,
2011 TALLOC_FREE(conv_smb_fname);
2015 static int shadow_copy2_mkdir(vfs_handle_struct *handle,
2016 const struct smb_filename *smb_fname,
2019 time_t timestamp = 0;
2020 char *stripped = NULL;
2021 int ret, saved_errno;
2023 struct smb_filename *conv_smb_fname = NULL;
2025 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2027 smb_fname->base_name,
2032 if (timestamp == 0) {
2033 return SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
2035 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2036 TALLOC_FREE(stripped);
2040 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2045 if (conv_smb_fname == NULL) {
2049 ret = SMB_VFS_NEXT_MKDIR(handle, conv_smb_fname, mode);
2050 saved_errno = errno;
2052 TALLOC_FREE(conv_smb_fname);
2053 errno = saved_errno;
2057 static int shadow_copy2_rmdir(vfs_handle_struct *handle,
2058 const struct smb_filename *smb_fname)
2060 time_t timestamp = 0;
2061 char *stripped = NULL;
2062 int ret, saved_errno;
2064 struct smb_filename *conv_smb_fname = NULL;
2066 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2068 smb_fname->base_name,
2073 if (timestamp == 0) {
2074 return SMB_VFS_NEXT_RMDIR(handle, smb_fname);
2076 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2077 TALLOC_FREE(stripped);
2081 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2086 if (conv_smb_fname == NULL) {
2090 ret = SMB_VFS_NEXT_RMDIR(handle, conv_smb_fname);
2091 saved_errno = errno;
2092 TALLOC_FREE(conv_smb_fname);
2094 errno = saved_errno;
2098 static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
2101 time_t timestamp = 0;
2102 char *stripped = NULL;
2103 int ret, saved_errno;
2106 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2107 ×tamp, &stripped)) {
2110 if (timestamp == 0) {
2111 return SMB_VFS_NEXT_CHFLAGS(handle, fname, flags);
2113 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2114 TALLOC_FREE(stripped);
2118 ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
2119 saved_errno = errno;
2121 errno = saved_errno;
2125 static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
2126 const char *fname, const char *aname,
2127 void *value, size_t size)
2129 time_t timestamp = 0;
2130 char *stripped = NULL;
2135 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2136 ×tamp, &stripped)) {
2139 if (timestamp == 0) {
2140 return SMB_VFS_NEXT_GETXATTR(handle, fname, aname, value,
2143 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2144 TALLOC_FREE(stripped);
2148 ret = SMB_VFS_NEXT_GETXATTR(handle, conv, aname, value, size);
2149 saved_errno = errno;
2151 errno = saved_errno;
2155 static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
2157 char *list, size_t size)
2159 time_t timestamp = 0;
2160 char *stripped = NULL;
2165 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2166 ×tamp, &stripped)) {
2169 if (timestamp == 0) {
2170 return SMB_VFS_NEXT_LISTXATTR(handle, fname, list, size);
2172 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2173 TALLOC_FREE(stripped);
2177 ret = SMB_VFS_NEXT_LISTXATTR(handle, conv, list, size);
2178 saved_errno = errno;
2180 errno = saved_errno;
2184 static int shadow_copy2_removexattr(vfs_handle_struct *handle,
2185 const char *fname, const char *aname)
2187 time_t timestamp = 0;
2188 char *stripped = NULL;
2189 int ret, saved_errno;
2192 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2193 ×tamp, &stripped)) {
2196 if (timestamp == 0) {
2197 return SMB_VFS_NEXT_REMOVEXATTR(handle, fname, aname);
2199 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2200 TALLOC_FREE(stripped);
2204 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv, aname);
2205 saved_errno = errno;
2207 errno = saved_errno;
2211 static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
2213 const char *aname, const void *value,
2214 size_t size, int flags)
2216 time_t timestamp = 0;
2217 char *stripped = NULL;
2222 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2223 ×tamp, &stripped)) {
2226 if (timestamp == 0) {
2227 return SMB_VFS_NEXT_SETXATTR(handle, fname, aname, value, size,
2230 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2231 TALLOC_FREE(stripped);
2235 ret = SMB_VFS_NEXT_SETXATTR(handle, conv, aname, value, size, flags);
2236 saved_errno = errno;
2238 errno = saved_errno;
2242 static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
2243 const struct smb_filename *smb_fname,
2246 time_t timestamp = 0;
2247 char *stripped = NULL;
2251 struct smb_filename *conv_smb_fname = NULL;
2253 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2255 smb_fname->base_name,
2260 if (timestamp == 0) {
2261 return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2263 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2264 TALLOC_FREE(stripped);
2268 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2273 if (conv_smb_fname == NULL) {
2278 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv_smb_fname, mode);
2279 saved_errno = errno;
2281 TALLOC_FREE(conv_smb_fname);
2282 errno = saved_errno;
2286 static int shadow_copy2_get_real_filename(struct vfs_handle_struct *handle,
2289 TALLOC_CTX *mem_ctx,
2292 time_t timestamp = 0;
2293 char *stripped = NULL;
2298 DEBUG(10, ("shadow_copy2_get_real_filename called for path=[%s], "
2299 "name=[%s]\n", path, name));
2301 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2302 ×tamp, &stripped)) {
2303 DEBUG(10, ("shadow_copy2_strip_snapshot failed\n"));
2306 if (timestamp == 0) {
2307 DEBUG(10, ("timestamp == 0\n"));
2308 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
2309 mem_ctx, found_name);
2311 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2312 TALLOC_FREE(stripped);
2314 DEBUG(10, ("shadow_copy2_convert failed\n"));
2317 DEBUG(10, ("Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
2318 "name=[%s]\n", conv, name));
2319 ret = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, conv, name,
2320 mem_ctx, found_name);
2321 DEBUG(10, ("NEXT_REAL_FILE_NAME returned %d\n", (int)ret));
2322 saved_errno = errno;
2324 errno = saved_errno;
2328 static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
2331 time_t timestamp = 0;
2332 char *stripped = NULL;
2334 char *result = NULL;
2335 char *parent_dir = NULL;
2337 size_t rootpath_len = 0;
2339 DBG_DEBUG("Calc connect path for [%s]\n", fname);
2341 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2342 ×tamp, &stripped)) {
2345 if (timestamp == 0) {
2346 return SMB_VFS_NEXT_CONNECTPATH(handle, fname);
2349 tmp = shadow_copy2_do_convert(talloc_tos(), handle, stripped, timestamp,
2352 if (errno != ENOENT) {
2357 * If the converted path does not exist, and converting
2358 * the parent yields something that does exist, then
2359 * this path refers to something that has not been
2360 * created yet, relative to the parent path.
2361 * The snapshot finding is relative to the parent.
2362 * (usually snapshots are read/only but this is not
2363 * necessarily true).
2364 * This code also covers getting a wildcard in the
2365 * last component, because this function is called
2366 * prior to sanitizing the path, and in SMB1 we may
2367 * get wildcards in path names.
2369 if (!parent_dirname(talloc_tos(), stripped, &parent_dir,
2375 tmp = shadow_copy2_do_convert(talloc_tos(), handle, parent_dir,
2376 timestamp, &rootpath_len);
2382 DBG_DEBUG("converted path is [%s] root path is [%.*s]\n", tmp,
2383 (int)rootpath_len, tmp);
2385 tmp[rootpath_len] = '\0';
2386 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
2387 if (result == NULL) {
2391 DBG_DEBUG("connect path is [%s]\n", result);
2394 saved_errno = errno;
2396 TALLOC_FREE(stripped);
2397 TALLOC_FREE(parent_dir);
2398 errno = saved_errno;
2402 static uint64_t shadow_copy2_disk_free(vfs_handle_struct *handle,
2403 const char *path, uint64_t *bsize,
2404 uint64_t *dfree, uint64_t *dsize)
2406 time_t timestamp = 0;
2407 char *stripped = NULL;
2412 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2413 ×tamp, &stripped)) {
2416 if (timestamp == 0) {
2417 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2418 bsize, dfree, dsize);
2421 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2422 TALLOC_FREE(stripped);
2427 ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
2429 saved_errno = errno;
2431 errno = saved_errno;
2436 static int shadow_copy2_get_quota(vfs_handle_struct *handle, const char *path,
2437 enum SMB_QUOTA_TYPE qtype, unid_t id,
2440 time_t timestamp = 0;
2441 char *stripped = NULL;
2446 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path, ×tamp,
2450 if (timestamp == 0) {
2451 return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
2454 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2455 TALLOC_FREE(stripped);
2460 ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv, qtype, id, dq);
2462 saved_errno = errno;
2464 errno = saved_errno;
2469 static int shadow_copy2_connect(struct vfs_handle_struct *handle,
2470 const char *service, const char *user)
2472 struct shadow_copy2_config *config;
2473 struct shadow_copy2_private *priv;
2475 const char *snapdir;
2476 const char *snapprefix = NULL;
2477 const char *delimiter;
2478 const char *gmt_format;
2479 const char *sort_order;
2480 const char *basedir = NULL;
2481 const char *snapsharepath = NULL;
2482 const char *mount_point;
2484 DEBUG(10, (__location__ ": cnum[%u], connectpath[%s]\n",
2485 (unsigned)handle->conn->cnum,
2486 handle->conn->connectpath));
2488 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
2493 priv = talloc_zero(handle->conn, struct shadow_copy2_private);
2495 DBG_ERR("talloc_zero() failed\n");
2500 priv->snaps = talloc_zero(priv, struct shadow_copy2_snaplist_info);
2501 if (priv->snaps == NULL) {
2502 DBG_ERR("talloc_zero() failed\n");
2507 config = talloc_zero(priv, struct shadow_copy2_config);
2508 if (config == NULL) {
2509 DEBUG(0, ("talloc_zero() failed\n"));
2514 priv->config = config;
2516 gmt_format = lp_parm_const_string(SNUM(handle->conn),
2519 config->gmt_format = talloc_strdup(config, gmt_format);
2520 if (config->gmt_format == NULL) {
2521 DEBUG(0, ("talloc_strdup() failed\n"));
2526 config->use_sscanf = lp_parm_bool(SNUM(handle->conn),
2527 "shadow", "sscanf", false);
2529 config->use_localtime = lp_parm_bool(SNUM(handle->conn),
2530 "shadow", "localtime",
2533 snapdir = lp_parm_const_string(SNUM(handle->conn),
2534 "shadow", "snapdir",
2536 config->snapdir = talloc_strdup(config, snapdir);
2537 if (config->snapdir == NULL) {
2538 DEBUG(0, ("talloc_strdup() failed\n"));
2543 snapprefix = lp_parm_const_string(SNUM(handle->conn),
2544 "shadow", "snapprefix",
2546 if (snapprefix != NULL) {
2547 priv->snaps->regex = talloc_zero(priv->snaps, regex_t);
2548 if (priv->snaps->regex == NULL) {
2549 DBG_ERR("talloc_zero() failed\n");
2554 /* pre-compute regex rule for matching pattern later */
2555 ret = regcomp(priv->snaps->regex, snapprefix, 0);
2557 DBG_ERR("Failed to create regex object\n");
2562 delimiter = lp_parm_const_string(SNUM(handle->conn),
2563 "shadow", "delimiter",
2565 if (delimiter != NULL) {
2566 priv->config->delimiter = talloc_strdup(priv->config, delimiter);
2567 if (priv->config->delimiter == NULL) {
2568 DBG_ERR("talloc_strdup() failed\n");
2574 config->snapdirseverywhere = lp_parm_bool(SNUM(handle->conn),
2576 "snapdirseverywhere",
2579 config->crossmountpoints = lp_parm_bool(SNUM(handle->conn),
2580 "shadow", "crossmountpoints",
2583 if (config->crossmountpoints && !config->snapdirseverywhere) {
2584 DBG_WARNING("Warning: 'crossmountpoints' depends on "
2585 "'snapdirseverywhere'. Disabling crossmountpoints.\n");
2588 config->fixinodes = lp_parm_bool(SNUM(handle->conn),
2589 "shadow", "fixinodes",
2592 sort_order = lp_parm_const_string(SNUM(handle->conn),
2593 "shadow", "sort", "desc");
2594 config->sort_order = talloc_strdup(config, sort_order);
2595 if (config->sort_order == NULL) {
2596 DEBUG(0, ("talloc_strdup() failed\n"));
2601 mount_point = lp_parm_const_string(SNUM(handle->conn),
2602 "shadow", "mountpoint", NULL);
2603 if (mount_point != NULL) {
2604 if (mount_point[0] != '/') {
2605 DEBUG(1, (__location__ " Warning: 'mountpoint' is "
2606 "relative ('%s'), but it has to be an "
2607 "absolute path. Ignoring provided value.\n",
2612 p = strstr(handle->conn->connectpath, mount_point);
2613 if (p != handle->conn->connectpath) {
2614 DBG_WARNING("Warning: the share root (%s) is "
2615 "not a subdirectory of the "
2616 "specified mountpoint (%s). "
2617 "Ignoring provided value.\n",
2618 handle->conn->connectpath,
2625 if (mount_point != NULL) {
2626 config->mount_point = talloc_strdup(config, mount_point);
2627 if (config->mount_point == NULL) {
2628 DEBUG(0, (__location__ " talloc_strdup() failed\n"));
2632 config->mount_point = shadow_copy2_find_mount_point(config,
2634 if (config->mount_point == NULL) {
2635 DBG_WARNING("shadow_copy2_find_mount_point "
2636 "of the share root '%s' failed: %s\n",
2637 handle->conn->connectpath, strerror(errno));
2642 basedir = lp_parm_const_string(SNUM(handle->conn),
2643 "shadow", "basedir", NULL);
2645 if (basedir != NULL) {
2646 if (basedir[0] != '/') {
2647 DEBUG(1, (__location__ " Warning: 'basedir' is "
2648 "relative ('%s'), but it has to be an "
2649 "absolute path. Disabling basedir.\n",
2654 p = strstr(basedir, config->mount_point);
2656 DEBUG(1, ("Warning: basedir (%s) is not a "
2657 "subdirectory of the share root's "
2658 "mount point (%s). "
2659 "Disabling basedir\n",
2660 basedir, config->mount_point));
2666 if (config->snapdirseverywhere && basedir != NULL) {
2667 DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
2668 "with 'snapdirseverywhere'. Disabling basedir.\n"));
2672 snapsharepath = lp_parm_const_string(SNUM(handle->conn), "shadow",
2673 "snapsharepath", NULL);
2674 if (snapsharepath != NULL) {
2675 if (snapsharepath[0] == '/') {
2676 DBG_WARNING("Warning: 'snapsharepath' is "
2677 "absolute ('%s'), but it has to be a "
2678 "relative path. Disabling snapsharepath.\n",
2680 snapsharepath = NULL;
2682 if (config->snapdirseverywhere && snapsharepath != NULL) {
2683 DBG_WARNING("Warning: 'snapsharepath' is incompatible "
2684 "with 'snapdirseverywhere'. Disabling "
2685 "snapsharepath.\n");
2686 snapsharepath = NULL;
2690 if (basedir != NULL && snapsharepath != NULL) {
2691 DBG_WARNING("Warning: 'snapsharepath' is incompatible with "
2692 "'basedir'. Disabling snapsharepath\n");
2693 snapsharepath = NULL;
2696 if (snapsharepath != NULL) {
2697 config->rel_connectpath = talloc_strdup(config, snapsharepath);
2698 if (config->rel_connectpath == NULL) {
2699 DBG_ERR("talloc_strdup() failed\n");
2705 if (basedir == NULL) {
2706 basedir = config->mount_point;
2709 if (config->rel_connectpath == NULL &&
2710 strlen(basedir) < strlen(handle->conn->connectpath)) {
2711 config->rel_connectpath = talloc_strdup(config,
2712 handle->conn->connectpath + strlen(basedir));
2713 if (config->rel_connectpath == NULL) {
2714 DEBUG(0, ("talloc_strdup() failed\n"));
2720 if (config->snapdir[0] == '/') {
2721 config->snapdir_absolute = true;
2723 if (config->snapdirseverywhere == true) {
2724 DEBUG(1, (__location__ " Warning: An absolute snapdir "
2725 "is incompatible with 'snapdirseverywhere', "
2726 "setting 'snapdirseverywhere' to false.\n"));
2727 config->snapdirseverywhere = false;
2730 if (config->crossmountpoints == true) {
2731 DEBUG(1, (__location__ " Warning: 'crossmountpoints' "
2732 "is not supported with an absolute snapdir. "
2733 "Disabling it.\n"));
2734 config->crossmountpoints = false;
2737 config->snapshot_basepath = config->snapdir;
2739 config->snapshot_basepath = talloc_asprintf(config, "%s/%s",
2740 config->mount_point, config->snapdir);
2741 if (config->snapshot_basepath == NULL) {
2742 DEBUG(0, ("talloc_asprintf() failed\n"));
2748 trim_string(config->mount_point, NULL, "/");
2749 trim_string(config->rel_connectpath, "/", "/");
2750 trim_string(config->snapdir, NULL, "/");
2751 trim_string(config->snapshot_basepath, NULL, "/");
2753 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
2754 " share root: '%s'\n"
2755 " mountpoint: '%s'\n"
2756 " rel share root: '%s'\n"
2758 " snapprefix: '%s'\n"
2759 " delimiter: '%s'\n"
2760 " snapshot base path: '%s'\n"
2763 " snapdirs everywhere: %s\n"
2764 " cross mountpoints: %s\n"
2768 handle->conn->connectpath,
2769 config->mount_point,
2770 config->rel_connectpath,
2774 config->snapshot_basepath,
2776 config->use_sscanf ? "yes" : "no",
2777 config->snapdirseverywhere ? "yes" : "no",
2778 config->crossmountpoints ? "yes" : "no",
2779 config->fixinodes ? "yes" : "no",
2784 SMB_VFS_HANDLE_SET_DATA(handle, priv,
2785 NULL, struct shadow_copy2_private,
2791 static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
2792 .connect_fn = shadow_copy2_connect,
2793 .opendir_fn = shadow_copy2_opendir,
2794 .disk_free_fn = shadow_copy2_disk_free,
2795 .get_quota_fn = shadow_copy2_get_quota,
2796 .rename_fn = shadow_copy2_rename,
2797 .link_fn = shadow_copy2_link,
2798 .symlink_fn = shadow_copy2_symlink,
2799 .stat_fn = shadow_copy2_stat,
2800 .lstat_fn = shadow_copy2_lstat,
2801 .fstat_fn = shadow_copy2_fstat,
2802 .open_fn = shadow_copy2_open,
2803 .unlink_fn = shadow_copy2_unlink,
2804 .chmod_fn = shadow_copy2_chmod,
2805 .chown_fn = shadow_copy2_chown,
2806 .chdir_fn = shadow_copy2_chdir,
2807 .ntimes_fn = shadow_copy2_ntimes,
2808 .readlink_fn = shadow_copy2_readlink,
2809 .mknod_fn = shadow_copy2_mknod,
2810 .realpath_fn = shadow_copy2_realpath,
2811 .get_nt_acl_fn = shadow_copy2_get_nt_acl,
2812 .fget_nt_acl_fn = shadow_copy2_fget_nt_acl,
2813 .get_shadow_copy_data_fn = shadow_copy2_get_shadow_copy_data,
2814 .mkdir_fn = shadow_copy2_mkdir,
2815 .rmdir_fn = shadow_copy2_rmdir,
2816 .getxattr_fn = shadow_copy2_getxattr,
2817 .listxattr_fn = shadow_copy2_listxattr,
2818 .removexattr_fn = shadow_copy2_removexattr,
2819 .setxattr_fn = shadow_copy2_setxattr,
2820 .chmod_acl_fn = shadow_copy2_chmod_acl,
2821 .chflags_fn = shadow_copy2_chflags,
2822 .get_real_filename_fn = shadow_copy2_get_real_filename,
2823 .connectpath_fn = shadow_copy2_connectpath,
2826 NTSTATUS vfs_shadow_copy2_init(void);
2827 NTSTATUS vfs_shadow_copy2_init(void)
2829 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2830 "shadow_copy2", &vfs_shadow_copy2_fns);