s3: VFS: Change SMB_VFS_MKNOD to use const struct smb_filename * instead of const...
[Samba.git] / source3 / modules / vfs_shadow_copy2.c
blob1fb492ba71eb7aaf1bbbd8deaa121ba93a43d6f0
1 /*
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.
33 #include "includes.h"
34 #include "smbd/smbd.h"
35 #include "system/filesys.h"
36 #include "include/ntioctl.h"
37 #include "util_tdb.h"
38 #include "lib/util_path.h"
40 struct shadow_copy2_config {
41 char *gmt_format;
42 bool use_sscanf;
43 bool use_localtime;
44 char *snapdir;
45 char *delimiter;
46 bool snapdirseverywhere;
47 bool crossmountpoints;
48 bool fixinodes;
49 char *sort_order;
50 bool snapdir_absolute;
51 char *mount_point;
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 {
58 char *snapname;
59 char *time_fmt;
60 struct shadow_copy2_snapentry *next;
61 struct shadow_copy2_snapentry *prev;
64 struct shadow_copy2_snaplist_info {
65 struct shadow_copy2_snapentry *snaplist; /* snapshot list */
66 regex_t *regex; /* Regex to filter snaps */
67 time_t fetch_time; /* snaplist update time */
72 * shadow_copy2 private structure. This structure will be
73 * used to keep module specific information
75 struct shadow_copy2_private {
76 struct shadow_copy2_config *config;
77 struct shadow_copy2_snaplist_info *snaps;
78 char *shadow_cwd; /* Absolute $cwd path. */
79 /* Absolute connectpath - can vary depending on $cwd. */
80 char *shadow_connectpath;
81 /* malloc'ed realpath return. */
82 char *shadow_realpath;
85 static int shadow_copy2_get_shadow_copy_data(
86 vfs_handle_struct *handle, files_struct *fsp,
87 struct shadow_copy_data *shadow_copy2_data,
88 bool labels);
90 /**
91 *This function will create a new snapshot list entry and
92 * return to the caller. This entry will also be added to
93 * the global snapshot list.
95 * @param[in] priv shadow_copy2 specific data structure
96 * @return Newly created snapshot entry or NULL on failure
98 static struct shadow_copy2_snapentry *shadow_copy2_create_snapentry(
99 struct shadow_copy2_private *priv)
101 struct shadow_copy2_snapentry *tmpentry = NULL;
103 tmpentry = talloc_zero(priv->snaps, struct shadow_copy2_snapentry);
104 if (tmpentry == NULL) {
105 DBG_ERR("talloc_zero() failed\n");
106 errno = ENOMEM;
107 return NULL;
110 DLIST_ADD(priv->snaps->snaplist, tmpentry);
112 return tmpentry;
116 *This function will delete the entire snaplist and reset
117 * priv->snaps->snaplist to NULL.
119 * @param[in] priv shadow_copye specific data structure
121 static void shadow_copy2_delete_snaplist(struct shadow_copy2_private *priv)
123 struct shadow_copy2_snapentry *tmp = NULL;
125 while ((tmp = priv->snaps->snaplist) != NULL) {
126 DLIST_REMOVE(priv->snaps->snaplist, tmp);
127 talloc_free(tmp);
132 * Given a timestamp this function searches the global snapshot list
133 * and returns the complete snapshot directory name saved in the entry.
135 * @param[in] priv shadow_copy2 specific structure
136 * @param[in] timestamp timestamp corresponding to one of the snapshot
137 * @param[out] snap_str buffer to copy the actual snapshot name
138 * @param[in] len length of snap_str buffer
140 * @return Length of actual snapshot name, and -1 on failure
142 static ssize_t shadow_copy2_saved_snapname(struct shadow_copy2_private *priv,
143 struct tm *timestamp,
144 char *snap_str, size_t len)
146 ssize_t snaptime_len = -1;
147 struct shadow_copy2_snapentry *entry = NULL;
149 snaptime_len = strftime(snap_str, len, GMT_FORMAT, timestamp);
150 if (snaptime_len == 0) {
151 DBG_ERR("strftime failed\n");
152 return -1;
155 snaptime_len = -1;
157 for (entry = priv->snaps->snaplist; entry; entry = entry->next) {
158 if (strcmp(entry->time_fmt, snap_str) == 0) {
159 snaptime_len = snprintf(snap_str, len, "%s",
160 entry->snapname);
161 return snaptime_len;
165 snap_str[0] = 0;
166 return snaptime_len;
171 * This function will check if snaplist is updated or not. If snaplist
172 * is empty then it will create a new list. Each time snaplist is updated
173 * the time is recorded. If the snapshot time is greater than the snaplist
174 * update time then chances are we are working on an older list. Then discard
175 * the old list and fetch a new snaplist.
177 * @param[in] handle VFS handle struct
178 * @param[in] snap_time time of snapshot
180 * @return true if the list is updated else false
182 static bool shadow_copy2_update_snaplist(struct vfs_handle_struct *handle,
183 time_t snap_time)
185 int ret = -1;
186 bool snaplist_updated = false;
187 struct files_struct fsp = {0};
188 struct smb_filename smb_fname = {0};
189 double seconds = 0.0;
190 struct shadow_copy2_private *priv = NULL;
192 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
193 return false);
195 seconds = difftime(snap_time, priv->snaps->fetch_time);
198 * Fetch the snapshot list if either the snaplist is empty or the
199 * required snapshot time is greater than the last fetched snaplist
200 * time.
202 if (seconds > 0 || (priv->snaps->snaplist == NULL)) {
203 smb_fname.base_name = discard_const_p(char, ".");
204 fsp.fsp_name = &smb_fname;
206 ret = shadow_copy2_get_shadow_copy_data(handle, &fsp,
207 NULL, false);
208 if (ret == 0) {
209 snaplist_updated = true;
210 } else {
211 DBG_ERR("Failed to get shadow copy data\n");
216 return snaplist_updated;
219 static bool shadow_copy2_find_slashes(TALLOC_CTX *mem_ctx, const char *str,
220 size_t **poffsets,
221 unsigned *pnum_offsets)
223 unsigned num_offsets;
224 size_t *offsets;
225 const char *p;
227 num_offsets = 0;
229 p = str;
230 while ((p = strchr(p, '/')) != NULL) {
231 num_offsets += 1;
232 p += 1;
235 offsets = talloc_array(mem_ctx, size_t, num_offsets);
236 if (offsets == NULL) {
237 return false;
240 p = str;
241 num_offsets = 0;
242 while ((p = strchr(p, '/')) != NULL) {
243 offsets[num_offsets] = p-str;
244 num_offsets += 1;
245 p += 1;
248 *poffsets = offsets;
249 *pnum_offsets = num_offsets;
250 return true;
254 * Given a timestamp, build the posix level GMT-tag string
255 * based on the configurable format.
257 static ssize_t shadow_copy2_posix_gmt_string(struct vfs_handle_struct *handle,
258 time_t snapshot,
259 char *snaptime_string,
260 size_t len)
262 struct tm snap_tm;
263 ssize_t snaptime_len;
264 struct shadow_copy2_config *config;
265 struct shadow_copy2_private *priv;
267 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
268 return 0);
270 config = priv->config;
272 if (config->use_sscanf) {
273 snaptime_len = snprintf(snaptime_string,
274 len,
275 config->gmt_format,
276 (unsigned long)snapshot);
277 if (snaptime_len <= 0) {
278 DEBUG(10, ("snprintf failed\n"));
279 return -1;
281 } else {
282 if (config->use_localtime) {
283 if (localtime_r(&snapshot, &snap_tm) == 0) {
284 DEBUG(10, ("gmtime_r failed\n"));
285 return -1;
287 } else {
288 if (gmtime_r(&snapshot, &snap_tm) == 0) {
289 DEBUG(10, ("gmtime_r failed\n"));
290 return -1;
294 if (priv->snaps->regex != NULL) {
295 snaptime_len = shadow_copy2_saved_snapname(priv,
296 &snap_tm, snaptime_string, len);
297 if (snaptime_len >= 0)
298 return snaptime_len;
301 * If we fail to find the snapshot name, chances are
302 * that we have not updated our snaplist. Make sure the
303 * snaplist is updated.
305 if (!shadow_copy2_update_snaplist(handle, snapshot)) {
306 DBG_DEBUG("shadow_copy2_update_snaplist "
307 "failed\n");
308 return -1;
311 return shadow_copy2_saved_snapname(priv,
312 &snap_tm, snaptime_string, len);
315 snaptime_len = strftime(snaptime_string,
316 len,
317 config->gmt_format,
318 &snap_tm);
319 if (snaptime_len == 0) {
320 DEBUG(10, ("strftime failed\n"));
321 return -1;
325 return snaptime_len;
329 * Given a timestamp, build the string to insert into a path
330 * as a path component for creating the local path to the
331 * snapshot at the given timestamp of the input path.
333 * In the case of a parallel snapdir (specified with an
334 * absolute path), this is the inital portion of the
335 * local path of any snapshot file. The complete path is
336 * obtained by appending the portion of the file's path
337 * below the share root's mountpoint.
339 static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx,
340 struct vfs_handle_struct *handle,
341 time_t snapshot)
343 fstring snaptime_string;
344 ssize_t snaptime_len = 0;
345 char *result = NULL;
346 struct shadow_copy2_config *config;
347 struct shadow_copy2_private *priv;
349 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
350 return NULL);
352 config = priv->config;
354 snaptime_len = shadow_copy2_posix_gmt_string(handle,
355 snapshot,
356 snaptime_string,
357 sizeof(snaptime_string));
358 if (snaptime_len <= 0) {
359 return NULL;
362 if (config->snapdir_absolute) {
363 result = talloc_asprintf(mem_ctx, "%s/%s",
364 config->snapdir, snaptime_string);
365 } else {
366 result = talloc_asprintf(mem_ctx, "/%s/%s",
367 config->snapdir, snaptime_string);
369 if (result == NULL) {
370 DEBUG(1, (__location__ " talloc_asprintf failed\n"));
373 return result;
377 * Build the posix snapshot path for the connection
378 * at the given timestamp, i.e. the absolute posix path
379 * that contains the snapshot for this file system.
381 * This only applies to classical case, i.e. not
382 * to the "snapdirseverywhere" mode.
384 static char *shadow_copy2_snapshot_path(TALLOC_CTX *mem_ctx,
385 struct vfs_handle_struct *handle,
386 time_t snapshot)
388 fstring snaptime_string;
389 ssize_t snaptime_len = 0;
390 char *result = NULL;
391 struct shadow_copy2_private *priv;
393 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
394 return NULL);
396 snaptime_len = shadow_copy2_posix_gmt_string(handle,
397 snapshot,
398 snaptime_string,
399 sizeof(snaptime_string));
400 if (snaptime_len <= 0) {
401 return NULL;
404 result = talloc_asprintf(mem_ctx, "%s/%s",
405 priv->config->snapshot_basepath, snaptime_string);
406 if (result == NULL) {
407 DEBUG(1, (__location__ " talloc_asprintf failed\n"));
410 return result;
413 static char *make_path_absolute(TALLOC_CTX *mem_ctx,
414 struct shadow_copy2_private *priv,
415 const char *name)
417 char *newpath = NULL;
418 char *abs_path = NULL;
420 if (name[0] != '/') {
421 newpath = talloc_asprintf(mem_ctx,
422 "%s/%s",
423 priv->shadow_cwd,
424 name);
425 if (newpath == NULL) {
426 return NULL;
428 name = newpath;
430 abs_path = canonicalize_absolute_path(mem_ctx, name);
431 TALLOC_FREE(newpath);
432 return abs_path;
435 /* Return a $cwd-relative path. */
436 static bool make_relative_path(const char *cwd, char *abs_path)
438 size_t cwd_len = strlen(cwd);
439 size_t abs_len = strlen(abs_path);
441 if (abs_len < cwd_len) {
442 return false;
444 if (memcmp(abs_path, cwd, cwd_len) != 0) {
445 return false;
447 /* The cwd_len != 1 case is for $cwd == '/' */
448 if (cwd_len != 1 &&
449 abs_path[cwd_len] != '/' &&
450 abs_path[cwd_len] != '\0')
452 return false;
454 if (abs_path[cwd_len] == '/') {
455 cwd_len++;
457 memmove(abs_path, &abs_path[cwd_len], abs_len + 1 - cwd_len);
458 return true;
461 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
462 const char *name,
463 char *gmt, size_t gmt_len);
466 * Check if an incoming filename is already a snapshot converted pathname.
468 * If so, it returns the pathname truncated at the snapshot point which
469 * will be used as the connectpath.
472 static int check_for_converted_path(TALLOC_CTX *mem_ctx,
473 struct vfs_handle_struct *handle,
474 struct shadow_copy2_private *priv,
475 char *abs_path,
476 bool *ppath_already_converted,
477 char **pconnectpath)
479 size_t snapdirlen = 0;
480 char *p = strstr_m(abs_path, priv->config->snapdir);
481 char *q = NULL;
482 char *connect_path = NULL;
483 char snapshot[GMT_NAME_LEN+1];
485 *ppath_already_converted = false;
487 if (p == NULL) {
488 /* Must at least contain shadow:snapdir. */
489 return 0;
492 if (priv->config->snapdir[0] == '/' &&
493 p != abs_path) {
494 /* Absolute shadow:snapdir must be at the start. */
495 return 0;
498 snapdirlen = strlen(priv->config->snapdir);
499 if (p[snapdirlen] != '/') {
500 /* shadow:snapdir must end as a separate component. */
501 return 0;
504 if (p > abs_path && p[-1] != '/') {
505 /* shadow:snapdir must start as a separate component. */
506 return 0;
509 p += snapdirlen;
510 p++; /* Move past the / */
513 * Need to return up to the next path
514 * component after the time.
515 * This will be used as the connectpath.
517 q = strchr(p, '/');
518 if (q == NULL) {
520 * No next path component.
521 * Use entire string.
523 connect_path = talloc_strdup(mem_ctx,
524 abs_path);
525 } else {
526 connect_path = talloc_strndup(mem_ctx,
527 abs_path,
528 q - abs_path);
530 if (connect_path == NULL) {
531 return ENOMEM;
535 * Point p at the same offset in connect_path as
536 * it is in abs_path.
539 p = &connect_path[p - abs_path];
542 * Now ensure there is a time string at p.
543 * The SMB-format @GMT-token string is returned
544 * in snapshot.
547 if (!shadow_copy2_snapshot_to_gmt(handle,
549 snapshot,
550 sizeof(snapshot))) {
551 TALLOC_FREE(connect_path);
552 return 0;
555 if (pconnectpath != NULL) {
556 *pconnectpath = connect_path;
559 *ppath_already_converted = true;
561 DBG_DEBUG("path |%s| is already converted. "
562 "connect path = |%s|\n",
563 abs_path,
564 connect_path);
566 return 0;
570 * This function does two things.
572 * 1). Checks if an incoming filename is already a
573 * snapshot converted pathname.
574 * If so, it returns the pathname truncated
575 * at the snapshot point which will be used
576 * as the connectpath, and then does an early return.
578 * 2). Checks if an incoming filename contains an
579 * SMB-layer @GMT- style timestamp.
580 * If so, it strips the timestamp, and returns
581 * both the timestamp and the stripped path
582 * (making it cwd-relative).
585 static bool shadow_copy2_strip_snapshot_internal(TALLOC_CTX *mem_ctx,
586 struct vfs_handle_struct *handle,
587 const char *orig_name,
588 time_t *ptimestamp,
589 char **pstripped,
590 char **psnappath)
592 struct tm tm;
593 time_t timestamp = 0;
594 const char *p;
595 char *q;
596 char *stripped = NULL;
597 size_t rest_len, dst_len;
598 struct shadow_copy2_private *priv;
599 ptrdiff_t len_before_gmt;
600 const char *name = orig_name;
601 char *abs_path = NULL;
602 bool ret = true;
603 bool already_converted = false;
604 int err = 0;
606 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
607 return false);
609 DEBUG(10, (__location__ ": enter path '%s'\n", name));
611 abs_path = make_path_absolute(mem_ctx, priv, name);
612 if (abs_path == NULL) {
613 ret = false;
614 goto out;
616 name = abs_path;
618 DEBUG(10, (__location__ ": abs path '%s'\n", name));
620 err = check_for_converted_path(mem_ctx,
621 handle,
622 priv,
623 abs_path,
624 &already_converted,
625 psnappath);
626 if (err != 0) {
627 /* error in conversion. */
628 ret = false;
629 goto out;
632 if (already_converted) {
633 goto out;
637 * From here we're only looking to strip an
638 * SMB-layer @GMT- token.
641 p = strstr_m(name, "@GMT-");
642 if (p == NULL) {
643 DEBUG(11, ("@GMT not found\n"));
644 goto out;
646 if ((p > name) && (p[-1] != '/')) {
647 /* the GMT-token does not start a path-component */
648 DEBUG(10, ("not at start, p=%p, name=%p, p[-1]=%d\n",
649 p, name, (int)p[-1]));
650 goto out;
653 len_before_gmt = p - name;
655 q = strptime(p, GMT_FORMAT, &tm);
656 if (q == NULL) {
657 DEBUG(10, ("strptime failed\n"));
658 goto out;
660 tm.tm_isdst = -1;
661 timestamp = timegm(&tm);
662 if (timestamp == (time_t)-1) {
663 DEBUG(10, ("timestamp==-1\n"));
664 goto out;
666 if (q[0] == '\0') {
668 * The name consists of only the GMT token or the GMT
669 * token is at the end of the path. XP seems to send
670 * @GMT- at the end under certain circumstances even
671 * with a path prefix.
673 if (pstripped != NULL) {
674 if (len_before_gmt > 1) {
676 * There is a path (and not only a slash)
677 * before the @GMT-. Remove the trailing
678 * slash character.
680 len_before_gmt -= 1;
682 stripped = talloc_strndup(mem_ctx, name,
683 len_before_gmt);
684 if (stripped == NULL) {
685 ret = false;
686 goto out;
688 if (orig_name[0] != '/') {
689 if (make_relative_path(priv->shadow_cwd,
690 stripped) == false) {
691 DEBUG(10, (__location__ ": path '%s' "
692 "doesn't start with cwd '%s'\n",
693 stripped, priv->shadow_cwd));
694 ret = false;
695 errno = ENOENT;
696 goto out;
699 *pstripped = stripped;
701 *ptimestamp = timestamp;
702 goto out;
704 if (q[0] != '/') {
706 * It is not a complete path component, i.e. the path
707 * component continues after the gmt-token.
709 DEBUG(10, ("q[0] = %d\n", (int)q[0]));
710 goto out;
712 q += 1;
714 rest_len = strlen(q);
715 dst_len = len_before_gmt + rest_len;
717 if (pstripped != NULL) {
718 stripped = talloc_array(mem_ctx, char, dst_len+1);
719 if (stripped == NULL) {
720 ret = false;
721 goto out;
723 if (p > name) {
724 memcpy(stripped, name, len_before_gmt);
726 if (rest_len > 0) {
727 memcpy(stripped + len_before_gmt, q, rest_len);
729 stripped[dst_len] = '\0';
730 if (orig_name[0] != '/') {
731 if (make_relative_path(priv->shadow_cwd,
732 stripped) == false) {
733 DEBUG(10, (__location__ ": path '%s' "
734 "doesn't start with cwd '%s'\n",
735 stripped, priv->shadow_cwd));
736 ret = false;
737 errno = ENOENT;
738 goto out;
741 *pstripped = stripped;
743 *ptimestamp = timestamp;
744 ret = true;
746 out:
747 TALLOC_FREE(abs_path);
748 return ret;
751 static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx,
752 struct vfs_handle_struct *handle,
753 const char *orig_name,
754 time_t *ptimestamp,
755 char **pstripped)
757 return shadow_copy2_strip_snapshot_internal(mem_ctx,
758 handle,
759 orig_name,
760 ptimestamp,
761 pstripped,
762 NULL);
765 static char *shadow_copy2_find_mount_point(TALLOC_CTX *mem_ctx,
766 vfs_handle_struct *handle)
768 char *path = talloc_strdup(mem_ctx, handle->conn->connectpath);
769 dev_t dev;
770 struct stat st;
771 char *p;
773 if (stat(path, &st) != 0) {
774 talloc_free(path);
775 return NULL;
778 dev = st.st_dev;
780 while ((p = strrchr(path, '/')) && p > path) {
781 *p = 0;
782 if (stat(path, &st) != 0) {
783 talloc_free(path);
784 return NULL;
786 if (st.st_dev != dev) {
787 *p = '/';
788 break;
792 return path;
796 * Convert from a name as handed in via the SMB layer
797 * and a timestamp into the local path of the snapshot
798 * of the provided file at the provided time.
799 * Also return the path in the snapshot corresponding
800 * to the file's share root.
802 static char *shadow_copy2_do_convert(TALLOC_CTX *mem_ctx,
803 struct vfs_handle_struct *handle,
804 const char *name, time_t timestamp,
805 size_t *snaproot_len)
807 struct smb_filename converted_fname;
808 char *result = NULL;
809 size_t *slashes = NULL;
810 unsigned num_slashes;
811 char *path = NULL;
812 size_t pathlen;
813 char *insert = NULL;
814 char *converted = NULL;
815 size_t insertlen, connectlen = 0;
816 int saved_errno = 0;
817 int i;
818 size_t min_offset;
819 struct shadow_copy2_config *config;
820 struct shadow_copy2_private *priv;
821 size_t in_share_offset = 0;
823 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
824 return NULL);
826 config = priv->config;
828 DEBUG(10, ("converting '%s'\n", name));
830 if (!config->snapdirseverywhere) {
831 int ret;
832 char *snapshot_path;
834 snapshot_path = shadow_copy2_snapshot_path(talloc_tos(),
835 handle,
836 timestamp);
837 if (snapshot_path == NULL) {
838 goto fail;
841 if (config->rel_connectpath == NULL) {
842 converted = talloc_asprintf(mem_ctx, "%s/%s",
843 snapshot_path, name);
844 } else {
845 converted = talloc_asprintf(mem_ctx, "%s/%s/%s",
846 snapshot_path,
847 config->rel_connectpath,
848 name);
850 if (converted == NULL) {
851 goto fail;
854 ZERO_STRUCT(converted_fname);
855 converted_fname.base_name = converted;
857 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
858 DEBUG(10, ("Trying[not snapdirseverywhere] %s: %d (%s)\n",
859 converted,
860 ret, ret == 0 ? "ok" : strerror(errno)));
861 if (ret == 0) {
862 DEBUG(10, ("Found %s\n", converted));
863 result = converted;
864 converted = NULL;
865 if (snaproot_len != NULL) {
866 *snaproot_len = strlen(snapshot_path);
867 if (config->rel_connectpath != NULL) {
868 *snaproot_len +=
869 strlen(config->rel_connectpath) + 1;
872 goto fail;
873 } else {
874 errno = ENOENT;
875 goto fail;
877 /* never reached ... */
880 connectlen = strlen(handle->conn->connectpath);
881 if (name[0] == 0) {
882 path = talloc_strdup(mem_ctx, handle->conn->connectpath);
883 } else {
884 path = talloc_asprintf(
885 mem_ctx, "%s/%s", handle->conn->connectpath, name);
887 if (path == NULL) {
888 errno = ENOMEM;
889 goto fail;
891 pathlen = talloc_get_size(path)-1;
893 if (!shadow_copy2_find_slashes(talloc_tos(), path,
894 &slashes, &num_slashes)) {
895 goto fail;
898 insert = shadow_copy2_insert_string(talloc_tos(), handle, timestamp);
899 if (insert == NULL) {
900 goto fail;
902 insertlen = talloc_get_size(insert)-1;
905 * Note: We deliberatly don't expensively initialize the
906 * array with talloc_zero here: Putting zero into
907 * converted[pathlen+insertlen] below is sufficient, because
908 * in the following for loop, the insert string is inserted
909 * at various slash places. So the memory up to position
910 * pathlen+insertlen will always be initialized when the
911 * converted string is used.
913 converted = talloc_array(mem_ctx, char, pathlen + insertlen + 1);
914 if (converted == NULL) {
915 goto fail;
918 if (path[pathlen-1] != '/') {
920 * Append a fake slash to find the snapshot root
922 size_t *tmp;
923 tmp = talloc_realloc(talloc_tos(), slashes,
924 size_t, num_slashes+1);
925 if (tmp == NULL) {
926 goto fail;
928 slashes = tmp;
929 slashes[num_slashes] = pathlen;
930 num_slashes += 1;
933 min_offset = 0;
935 if (!config->crossmountpoints) {
936 min_offset = strlen(config->mount_point);
939 memcpy(converted, path, pathlen+1);
940 converted[pathlen+insertlen] = '\0';
942 ZERO_STRUCT(converted_fname);
943 converted_fname.base_name = converted;
945 for (i = num_slashes-1; i>=0; i--) {
946 int ret;
947 size_t offset;
949 offset = slashes[i];
951 if (offset < min_offset) {
952 errno = ENOENT;
953 goto fail;
956 if (offset >= connectlen) {
957 in_share_offset = offset;
960 memcpy(converted+offset, insert, insertlen);
962 offset += insertlen;
963 memcpy(converted+offset, path + slashes[i],
964 pathlen - slashes[i]);
966 ret = SMB_VFS_NEXT_LSTAT(handle, &converted_fname);
968 DEBUG(10, ("Trying[snapdirseverywhere] %s: %d (%s)\n",
969 converted,
970 ret, ret == 0 ? "ok" : strerror(errno)));
971 if (ret == 0) {
972 /* success */
973 if (snaproot_len != NULL) {
974 *snaproot_len = in_share_offset + insertlen;
976 break;
978 if (errno == ENOTDIR) {
980 * This is a valid condition: We appended the
981 * .snaphots/@GMT.. to a file name. Just try
982 * with the upper levels.
984 continue;
986 if (errno != ENOENT) {
987 /* Other problem than "not found" */
988 goto fail;
992 if (i >= 0) {
994 * Found something
996 DEBUG(10, ("Found %s\n", converted));
997 result = converted;
998 converted = NULL;
999 } else {
1000 errno = ENOENT;
1002 fail:
1003 if (result == NULL) {
1004 saved_errno = errno;
1006 TALLOC_FREE(converted);
1007 TALLOC_FREE(insert);
1008 TALLOC_FREE(slashes);
1009 TALLOC_FREE(path);
1010 if (saved_errno != 0) {
1011 errno = saved_errno;
1013 return result;
1017 * Convert from a name as handed in via the SMB layer
1018 * and a timestamp into the local path of the snapshot
1019 * of the provided file at the provided time.
1021 static char *shadow_copy2_convert(TALLOC_CTX *mem_ctx,
1022 struct vfs_handle_struct *handle,
1023 const char *name, time_t timestamp)
1025 return shadow_copy2_do_convert(mem_ctx, handle, name, timestamp, NULL);
1029 modify a sbuf return to ensure that inodes in the shadow directory
1030 are different from those in the main directory
1032 static void convert_sbuf(vfs_handle_struct *handle, const char *fname,
1033 SMB_STRUCT_STAT *sbuf)
1035 struct shadow_copy2_private *priv;
1037 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1038 return);
1040 if (priv->config->fixinodes) {
1041 /* some snapshot systems, like GPFS, return the name
1042 device:inode for the snapshot files as the current
1043 files. That breaks the 'restore' button in the shadow copy
1044 GUI, as the client gets a sharing violation.
1046 This is a crude way of allowing both files to be
1047 open at once. It has a slight chance of inode
1048 number collision, but I can't see a better approach
1049 without significant VFS changes
1051 TDB_DATA key = { .dptr = discard_const_p(uint8_t, fname),
1052 .dsize = strlen(fname) };
1053 uint32_t shash;
1055 shash = tdb_jenkins_hash(&key) & 0xFF000000;
1056 if (shash == 0) {
1057 shash = 1;
1059 sbuf->st_ex_ino ^= shash;
1063 static DIR *shadow_copy2_opendir(vfs_handle_struct *handle,
1064 const struct smb_filename *smb_fname,
1065 const char *mask,
1066 uint32_t attr)
1068 time_t timestamp = 0;
1069 char *stripped = NULL;
1070 DIR *ret;
1071 int saved_errno = 0;
1072 char *conv;
1073 struct smb_filename *conv_smb_fname = NULL;
1075 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1076 handle,
1077 smb_fname->base_name,
1078 &timestamp,
1079 &stripped)) {
1080 return NULL;
1082 if (timestamp == 0) {
1083 return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
1085 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1086 TALLOC_FREE(stripped);
1087 if (conv == NULL) {
1088 return NULL;
1090 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1091 conv,
1092 NULL,
1093 NULL,
1094 smb_fname->flags);
1095 if (conv_smb_fname == NULL) {
1096 TALLOC_FREE(conv);
1097 return NULL;
1099 ret = SMB_VFS_NEXT_OPENDIR(handle, conv_smb_fname, mask, attr);
1100 if (ret == NULL) {
1101 saved_errno = errno;
1103 TALLOC_FREE(conv);
1104 TALLOC_FREE(conv_smb_fname);
1105 if (saved_errno != 0) {
1106 errno = saved_errno;
1108 return ret;
1111 static int shadow_copy2_rename(vfs_handle_struct *handle,
1112 const struct smb_filename *smb_fname_src,
1113 const struct smb_filename *smb_fname_dst)
1115 time_t timestamp_src = 0;
1116 time_t timestamp_dst = 0;
1117 char *snappath_src = NULL;
1118 char *snappath_dst = NULL;
1120 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle,
1121 smb_fname_src->base_name,
1122 &timestamp_src, NULL, &snappath_src)) {
1123 return -1;
1125 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle,
1126 smb_fname_dst->base_name,
1127 &timestamp_dst, NULL, &snappath_dst)) {
1128 return -1;
1130 if (timestamp_src != 0) {
1131 errno = EXDEV;
1132 return -1;
1134 if (timestamp_dst != 0) {
1135 errno = EROFS;
1136 return -1;
1139 * Don't allow rename on already converted paths.
1141 if (snappath_src != NULL) {
1142 errno = EXDEV;
1143 return -1;
1145 if (snappath_dst != NULL) {
1146 errno = EROFS;
1147 return -1;
1149 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
1152 static int shadow_copy2_symlink(vfs_handle_struct *handle,
1153 const char *oldname, const char *newname)
1155 time_t timestamp_old = 0;
1156 time_t timestamp_new = 0;
1157 char *snappath_old = NULL;
1158 char *snappath_new = NULL;
1160 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, oldname,
1161 &timestamp_old, NULL, &snappath_old)) {
1162 return -1;
1164 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, newname,
1165 &timestamp_new, NULL, &snappath_new)) {
1166 return -1;
1168 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1169 errno = EROFS;
1170 return -1;
1173 * Don't allow symlinks on already converted paths.
1175 if ((snappath_old != NULL) || (snappath_new != NULL)) {
1176 errno = EROFS;
1177 return -1;
1179 return SMB_VFS_NEXT_SYMLINK(handle, oldname, newname);
1182 static int shadow_copy2_link(vfs_handle_struct *handle,
1183 const char *oldname, const char *newname)
1185 time_t timestamp_old = 0;
1186 time_t timestamp_new = 0;
1187 char *snappath_old = NULL;
1188 char *snappath_new = NULL;
1190 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, oldname,
1191 &timestamp_old, NULL, &snappath_old)) {
1192 return -1;
1194 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, newname,
1195 &timestamp_new, NULL, &snappath_new)) {
1196 return -1;
1198 if ((timestamp_old != 0) || (timestamp_new != 0)) {
1199 errno = EROFS;
1200 return -1;
1203 * Don't allow links on already converted paths.
1205 if ((snappath_old != NULL) || (snappath_new != NULL)) {
1206 errno = EROFS;
1207 return -1;
1209 return SMB_VFS_NEXT_LINK(handle, oldname, newname);
1212 static int shadow_copy2_stat(vfs_handle_struct *handle,
1213 struct smb_filename *smb_fname)
1215 time_t timestamp = 0;
1216 char *stripped = NULL;
1217 char *tmp;
1218 int saved_errno = 0;
1219 int ret;
1221 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1222 smb_fname->base_name,
1223 &timestamp, &stripped)) {
1224 return -1;
1226 if (timestamp == 0) {
1227 return SMB_VFS_NEXT_STAT(handle, smb_fname);
1230 tmp = smb_fname->base_name;
1231 smb_fname->base_name = shadow_copy2_convert(
1232 talloc_tos(), handle, stripped, timestamp);
1233 TALLOC_FREE(stripped);
1235 if (smb_fname->base_name == NULL) {
1236 smb_fname->base_name = tmp;
1237 return -1;
1240 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
1241 if (ret == -1) {
1242 saved_errno = errno;
1245 TALLOC_FREE(smb_fname->base_name);
1246 smb_fname->base_name = tmp;
1248 if (ret == 0) {
1249 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1251 if (saved_errno != 0) {
1252 errno = saved_errno;
1254 return ret;
1257 static int shadow_copy2_lstat(vfs_handle_struct *handle,
1258 struct smb_filename *smb_fname)
1260 time_t timestamp = 0;
1261 char *stripped = NULL;
1262 char *tmp;
1263 int saved_errno = 0;
1264 int ret;
1266 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1267 smb_fname->base_name,
1268 &timestamp, &stripped)) {
1269 return -1;
1271 if (timestamp == 0) {
1272 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1275 tmp = smb_fname->base_name;
1276 smb_fname->base_name = shadow_copy2_convert(
1277 talloc_tos(), handle, stripped, timestamp);
1278 TALLOC_FREE(stripped);
1280 if (smb_fname->base_name == NULL) {
1281 smb_fname->base_name = tmp;
1282 return -1;
1285 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1286 if (ret == -1) {
1287 saved_errno = errno;
1290 TALLOC_FREE(smb_fname->base_name);
1291 smb_fname->base_name = tmp;
1293 if (ret == 0) {
1294 convert_sbuf(handle, smb_fname->base_name, &smb_fname->st);
1296 if (saved_errno != 0) {
1297 errno = saved_errno;
1299 return ret;
1302 static int shadow_copy2_fstat(vfs_handle_struct *handle, files_struct *fsp,
1303 SMB_STRUCT_STAT *sbuf)
1305 time_t timestamp = 0;
1306 int ret;
1308 ret = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1309 if (ret == -1) {
1310 return ret;
1312 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1313 fsp->fsp_name->base_name,
1314 &timestamp, NULL)) {
1315 return 0;
1317 if (timestamp != 0) {
1318 convert_sbuf(handle, fsp->fsp_name->base_name, sbuf);
1320 return 0;
1323 static int shadow_copy2_open(vfs_handle_struct *handle,
1324 struct smb_filename *smb_fname, files_struct *fsp,
1325 int flags, mode_t mode)
1327 time_t timestamp = 0;
1328 char *stripped = NULL;
1329 char *tmp;
1330 int saved_errno = 0;
1331 int ret;
1333 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1334 smb_fname->base_name,
1335 &timestamp, &stripped)) {
1336 return -1;
1338 if (timestamp == 0) {
1339 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1342 tmp = smb_fname->base_name;
1343 smb_fname->base_name = shadow_copy2_convert(
1344 talloc_tos(), handle, stripped, timestamp);
1345 TALLOC_FREE(stripped);
1347 if (smb_fname->base_name == NULL) {
1348 smb_fname->base_name = tmp;
1349 return -1;
1352 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
1353 if (ret == -1) {
1354 saved_errno = errno;
1357 TALLOC_FREE(smb_fname->base_name);
1358 smb_fname->base_name = tmp;
1360 if (saved_errno != 0) {
1361 errno = saved_errno;
1363 return ret;
1366 static int shadow_copy2_unlink(vfs_handle_struct *handle,
1367 const struct smb_filename *smb_fname)
1369 time_t timestamp = 0;
1370 char *stripped = NULL;
1371 int saved_errno = 0;
1372 int ret;
1373 struct smb_filename *conv;
1375 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1376 smb_fname->base_name,
1377 &timestamp, &stripped)) {
1378 return -1;
1380 if (timestamp == 0) {
1381 return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1383 conv = cp_smb_filename(talloc_tos(), smb_fname);
1384 if (conv == NULL) {
1385 errno = ENOMEM;
1386 return -1;
1388 conv->base_name = shadow_copy2_convert(
1389 conv, handle, stripped, timestamp);
1390 TALLOC_FREE(stripped);
1391 if (conv->base_name == NULL) {
1392 return -1;
1394 ret = SMB_VFS_NEXT_UNLINK(handle, conv);
1395 if (ret == -1) {
1396 saved_errno = errno;
1398 TALLOC_FREE(conv);
1399 if (saved_errno != 0) {
1400 errno = saved_errno;
1402 return ret;
1405 static int shadow_copy2_chmod(vfs_handle_struct *handle,
1406 const struct smb_filename *smb_fname,
1407 mode_t mode)
1409 time_t timestamp = 0;
1410 char *stripped = NULL;
1411 int saved_errno = 0;
1412 int ret;
1413 char *conv = NULL;
1414 struct smb_filename *conv_smb_fname;
1416 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1417 handle,
1418 smb_fname->base_name,
1419 &timestamp,
1420 &stripped)) {
1421 return -1;
1423 if (timestamp == 0) {
1424 TALLOC_FREE(stripped);
1425 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1427 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1428 TALLOC_FREE(stripped);
1429 if (conv == NULL) {
1430 return -1;
1432 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1433 conv,
1434 NULL,
1435 NULL,
1436 smb_fname->flags);
1437 if (conv_smb_fname == NULL) {
1438 TALLOC_FREE(conv);
1439 errno = ENOMEM;
1440 return -1;
1443 ret = SMB_VFS_NEXT_CHMOD(handle, conv_smb_fname, mode);
1444 if (ret == -1) {
1445 saved_errno = errno;
1447 TALLOC_FREE(conv);
1448 TALLOC_FREE(conv_smb_fname);
1449 if (saved_errno != 0) {
1450 errno = saved_errno;
1452 return ret;
1455 static int shadow_copy2_chown(vfs_handle_struct *handle,
1456 const struct smb_filename *smb_fname,
1457 uid_t uid,
1458 gid_t gid)
1460 time_t timestamp = 0;
1461 char *stripped = NULL;
1462 int saved_errno = 0;
1463 int ret;
1464 char *conv = NULL;
1465 struct smb_filename *conv_smb_fname = NULL;
1467 if (!shadow_copy2_strip_snapshot(talloc_tos(),
1468 handle,
1469 smb_fname->base_name,
1470 &timestamp,
1471 &stripped)) {
1472 return -1;
1474 if (timestamp == 0) {
1475 return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1477 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1478 TALLOC_FREE(stripped);
1479 if (conv == NULL) {
1480 return -1;
1482 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1483 conv,
1484 NULL,
1485 NULL,
1486 smb_fname->flags);
1487 if (conv_smb_fname == NULL) {
1488 TALLOC_FREE(conv);
1489 errno = ENOMEM;
1490 return -1;
1492 ret = SMB_VFS_NEXT_CHOWN(handle, conv_smb_fname, uid, gid);
1493 if (ret == -1) {
1494 saved_errno = errno;
1496 TALLOC_FREE(conv);
1497 TALLOC_FREE(conv_smb_fname);
1498 if (saved_errno != 0) {
1499 errno = saved_errno;
1501 return ret;
1504 static void store_cwd_data(vfs_handle_struct *handle,
1505 const char *connectpath)
1507 struct shadow_copy2_private *priv = NULL;
1508 char *cwd = NULL;
1510 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1511 return);
1513 TALLOC_FREE(priv->shadow_cwd);
1514 cwd = SMB_VFS_NEXT_GETWD(handle);
1515 if (cwd == NULL) {
1516 smb_panic("getwd failed\n");
1518 DBG_DEBUG("shadow cwd = %s\n", cwd);
1519 priv->shadow_cwd = talloc_strdup(priv, cwd);
1520 SAFE_FREE(cwd);
1521 if (priv->shadow_cwd == NULL) {
1522 smb_panic("talloc failed\n");
1524 TALLOC_FREE(priv->shadow_connectpath);
1525 if (connectpath) {
1526 DBG_DEBUG("shadow conectpath = %s\n", connectpath);
1527 priv->shadow_connectpath = talloc_strdup(priv, connectpath);
1528 if (priv->shadow_connectpath == NULL) {
1529 smb_panic("talloc failed\n");
1534 static int shadow_copy2_chdir(vfs_handle_struct *handle,
1535 const char *fname)
1537 time_t timestamp = 0;
1538 char *stripped = NULL;
1539 char *snappath = NULL;
1540 int ret = -1;
1541 int saved_errno = 0;
1542 char *conv = NULL;
1543 size_t rootpath_len = 0;
1545 if (!shadow_copy2_strip_snapshot_internal(talloc_tos(), handle, fname,
1546 &timestamp, &stripped, &snappath)) {
1547 return -1;
1549 if (stripped != NULL) {
1550 conv = shadow_copy2_do_convert(talloc_tos(),
1551 handle,
1552 stripped,
1553 timestamp,
1554 &rootpath_len);
1555 TALLOC_FREE(stripped);
1556 if (conv == NULL) {
1557 return -1;
1559 fname = conv;
1562 ret = SMB_VFS_NEXT_CHDIR(handle, fname);
1563 if (ret == -1) {
1564 saved_errno = errno;
1567 if (ret == 0) {
1568 if (conv != NULL && rootpath_len != 0) {
1569 conv[rootpath_len] = '\0';
1570 } else if (snappath != 0) {
1571 TALLOC_FREE(conv);
1572 conv = snappath;
1574 store_cwd_data(handle, conv);
1577 TALLOC_FREE(stripped);
1578 TALLOC_FREE(conv);
1580 if (saved_errno != 0) {
1581 errno = saved_errno;
1583 return ret;
1586 static int shadow_copy2_ntimes(vfs_handle_struct *handle,
1587 const struct smb_filename *smb_fname,
1588 struct smb_file_time *ft)
1590 time_t timestamp = 0;
1591 char *stripped = NULL;
1592 int saved_errno = 0;
1593 int ret;
1594 struct smb_filename *conv;
1596 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1597 smb_fname->base_name,
1598 &timestamp, &stripped)) {
1599 return -1;
1601 if (timestamp == 0) {
1602 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1604 conv = cp_smb_filename(talloc_tos(), smb_fname);
1605 if (conv == NULL) {
1606 errno = ENOMEM;
1607 return -1;
1609 conv->base_name = shadow_copy2_convert(
1610 conv, handle, stripped, timestamp);
1611 TALLOC_FREE(stripped);
1612 if (conv->base_name == NULL) {
1613 return -1;
1615 ret = SMB_VFS_NEXT_NTIMES(handle, conv, ft);
1616 if (ret == -1) {
1617 saved_errno = errno;
1619 TALLOC_FREE(conv);
1620 if (saved_errno != 0) {
1621 errno = saved_errno;
1623 return ret;
1626 static int shadow_copy2_readlink(vfs_handle_struct *handle,
1627 const char *fname, char *buf, size_t bufsiz)
1629 time_t timestamp = 0;
1630 char *stripped = NULL;
1631 int saved_errno = 0;
1632 int ret;
1633 char *conv;
1635 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1636 &timestamp, &stripped)) {
1637 return -1;
1639 if (timestamp == 0) {
1640 return SMB_VFS_NEXT_READLINK(handle, fname, buf, bufsiz);
1642 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1643 TALLOC_FREE(stripped);
1644 if (conv == NULL) {
1645 return -1;
1647 ret = SMB_VFS_NEXT_READLINK(handle, conv, buf, bufsiz);
1648 if (ret == -1) {
1649 saved_errno = errno;
1651 TALLOC_FREE(conv);
1652 if (saved_errno != 0) {
1653 errno = saved_errno;
1655 return ret;
1658 static int shadow_copy2_mknod(vfs_handle_struct *handle,
1659 const struct smb_filename *smb_fname,
1660 mode_t mode,
1661 SMB_DEV_T dev)
1663 time_t timestamp = 0;
1664 char *stripped = NULL;
1665 int saved_errno = 0;
1666 int ret;
1667 struct smb_filename *conv = NULL;
1669 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
1670 smb_fname->base_name,
1671 &timestamp, &stripped)) {
1672 return -1;
1674 if (timestamp == 0) {
1675 return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
1677 conv = cp_smb_filename(talloc_tos(), smb_fname);
1678 if (conv == NULL) {
1679 errno = ENOMEM;
1680 return -1;
1682 conv->base_name = shadow_copy2_convert(
1683 conv, handle, stripped, timestamp);
1684 TALLOC_FREE(stripped);
1685 if (conv->base_name == NULL) {
1686 return -1;
1688 ret = SMB_VFS_NEXT_MKNOD(handle, conv, mode, dev);
1689 if (ret == -1) {
1690 saved_errno = errno;
1692 TALLOC_FREE(conv);
1693 if (saved_errno != 0) {
1694 errno = saved_errno;
1696 return ret;
1699 static char *shadow_copy2_realpath(vfs_handle_struct *handle,
1700 const char *fname)
1702 time_t timestamp = 0;
1703 char *stripped = NULL;
1704 char *tmp = NULL;
1705 char *result = NULL;
1706 int saved_errno = 0;
1708 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
1709 &timestamp, &stripped)) {
1710 goto done;
1712 if (timestamp == 0) {
1713 return SMB_VFS_NEXT_REALPATH(handle, fname);
1716 tmp = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
1717 if (tmp == NULL) {
1718 goto done;
1721 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
1723 done:
1724 if (result == NULL) {
1725 saved_errno = errno;
1727 TALLOC_FREE(tmp);
1728 TALLOC_FREE(stripped);
1729 if (saved_errno != 0) {
1730 errno = saved_errno;
1732 return result;
1736 * Check whether a given directory contains a
1737 * snapshot directory as direct subdirectory.
1738 * If yes, return the path of the snapshot-subdir,
1739 * otherwise return NULL.
1741 static char *have_snapdir(struct vfs_handle_struct *handle,
1742 const char *path)
1744 struct smb_filename smb_fname;
1745 int ret;
1746 struct shadow_copy2_private *priv;
1748 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1749 return NULL);
1751 ZERO_STRUCT(smb_fname);
1752 smb_fname.base_name = talloc_asprintf(talloc_tos(), "%s/%s",
1753 path, priv->config->snapdir);
1754 if (smb_fname.base_name == NULL) {
1755 return NULL;
1758 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1759 if ((ret == 0) && (S_ISDIR(smb_fname.st.st_ex_mode))) {
1760 return smb_fname.base_name;
1762 TALLOC_FREE(smb_fname.base_name);
1763 return NULL;
1766 static bool check_access_snapdir(struct vfs_handle_struct *handle,
1767 const char *path)
1769 struct smb_filename smb_fname;
1770 int ret;
1771 NTSTATUS status;
1773 ZERO_STRUCT(smb_fname);
1774 smb_fname.base_name = talloc_asprintf(talloc_tos(),
1775 "%s",
1776 path);
1777 if (smb_fname.base_name == NULL) {
1778 return false;
1781 ret = SMB_VFS_NEXT_STAT(handle, &smb_fname);
1782 if (ret != 0 || !S_ISDIR(smb_fname.st.st_ex_mode)) {
1783 TALLOC_FREE(smb_fname.base_name);
1784 return false;
1787 status = smbd_check_access_rights(handle->conn,
1788 &smb_fname,
1789 false,
1790 SEC_DIR_LIST);
1791 if (!NT_STATUS_IS_OK(status)) {
1792 DEBUG(0,("user does not have list permission "
1793 "on snapdir %s\n",
1794 smb_fname.base_name));
1795 TALLOC_FREE(smb_fname.base_name);
1796 return false;
1798 TALLOC_FREE(smb_fname.base_name);
1799 return true;
1803 * Find the snapshot directory (if any) for the given
1804 * filename (which is relative to the share).
1806 static const char *shadow_copy2_find_snapdir(TALLOC_CTX *mem_ctx,
1807 struct vfs_handle_struct *handle,
1808 struct smb_filename *smb_fname)
1810 char *path, *p;
1811 const char *snapdir;
1812 struct shadow_copy2_config *config;
1813 struct shadow_copy2_private *priv;
1815 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1816 return NULL);
1818 config = priv->config;
1821 * If the non-snapdisrseverywhere mode, we should not search!
1823 if (!config->snapdirseverywhere) {
1824 return config->snapshot_basepath;
1827 path = talloc_asprintf(mem_ctx, "%s/%s",
1828 handle->conn->connectpath,
1829 smb_fname->base_name);
1830 if (path == NULL) {
1831 return NULL;
1834 snapdir = have_snapdir(handle, path);
1835 if (snapdir != NULL) {
1836 TALLOC_FREE(path);
1837 return snapdir;
1840 while ((p = strrchr(path, '/')) && (p > path)) {
1842 p[0] = '\0';
1844 snapdir = have_snapdir(handle, path);
1845 if (snapdir != NULL) {
1846 TALLOC_FREE(path);
1847 return snapdir;
1850 TALLOC_FREE(path);
1851 return NULL;
1854 static bool shadow_copy2_snapshot_to_gmt(vfs_handle_struct *handle,
1855 const char *name,
1856 char *gmt, size_t gmt_len)
1858 struct tm timestamp;
1859 time_t timestamp_t;
1860 unsigned long int timestamp_long;
1861 const char *fmt;
1862 struct shadow_copy2_config *config;
1863 struct shadow_copy2_private *priv;
1864 char *tmpstr = NULL;
1865 char *tmp = NULL;
1866 bool converted = false;
1867 int ret = -1;
1869 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1870 return NULL);
1872 config = priv->config;
1874 fmt = config->gmt_format;
1877 * If regex is provided, then we will have to parse the
1878 * filename which will contain both the prefix and the time format.
1879 * e.g. <prefix><delimiter><time_format>
1881 if (priv->snaps->regex != NULL) {
1882 tmpstr = talloc_strdup(talloc_tos(), name);
1883 /* point "name" to the time format */
1884 name = strstr(name, priv->config->delimiter);
1885 if (name == NULL) {
1886 goto done;
1888 /* Extract the prefix */
1889 tmp = strstr(tmpstr, priv->config->delimiter);
1890 if (tmp == NULL) {
1891 goto done;
1893 *tmp = '\0';
1895 /* Parse regex */
1896 ret = regexec(priv->snaps->regex, tmpstr, 0, NULL, 0);
1897 if (ret) {
1898 DBG_DEBUG("shadow_copy2_snapshot_to_gmt: "
1899 "no regex match for %s\n", tmpstr);
1900 goto done;
1904 ZERO_STRUCT(timestamp);
1905 if (config->use_sscanf) {
1906 if (sscanf(name, fmt, &timestamp_long) != 1) {
1907 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1908 "no sscanf match %s: %s\n",
1909 fmt, name));
1910 goto done;
1912 timestamp_t = timestamp_long;
1913 gmtime_r(&timestamp_t, &timestamp);
1914 } else {
1915 if (strptime(name, fmt, &timestamp) == NULL) {
1916 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: "
1917 "no match %s: %s\n",
1918 fmt, name));
1919 goto done;
1921 DEBUG(10, ("shadow_copy2_snapshot_to_gmt: match %s: %s\n",
1922 fmt, name));
1924 if (config->use_localtime) {
1925 timestamp.tm_isdst = -1;
1926 timestamp_t = mktime(&timestamp);
1927 gmtime_r(&timestamp_t, &timestamp);
1931 strftime(gmt, gmt_len, GMT_FORMAT, &timestamp);
1932 converted = true;
1934 done:
1935 TALLOC_FREE(tmpstr);
1936 return converted;
1939 static int shadow_copy2_label_cmp_asc(const void *x, const void *y)
1941 return strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1944 static int shadow_copy2_label_cmp_desc(const void *x, const void *y)
1946 return -strncmp((const char *)x, (const char *)y, sizeof(SHADOW_COPY_LABEL));
1950 sort the shadow copy data in ascending or descending order
1952 static void shadow_copy2_sort_data(vfs_handle_struct *handle,
1953 struct shadow_copy_data *shadow_copy2_data)
1955 int (*cmpfunc)(const void *, const void *);
1956 const char *sort;
1957 struct shadow_copy2_private *priv;
1959 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
1960 return);
1962 sort = priv->config->sort_order;
1963 if (sort == NULL) {
1964 return;
1967 if (strcmp(sort, "asc") == 0) {
1968 cmpfunc = shadow_copy2_label_cmp_asc;
1969 } else if (strcmp(sort, "desc") == 0) {
1970 cmpfunc = shadow_copy2_label_cmp_desc;
1971 } else {
1972 return;
1975 if (shadow_copy2_data && shadow_copy2_data->num_volumes > 0 &&
1976 shadow_copy2_data->labels)
1978 TYPESAFE_QSORT(shadow_copy2_data->labels,
1979 shadow_copy2_data->num_volumes,
1980 cmpfunc);
1984 static int shadow_copy2_get_shadow_copy_data(
1985 vfs_handle_struct *handle, files_struct *fsp,
1986 struct shadow_copy_data *shadow_copy2_data,
1987 bool labels)
1989 DIR *p;
1990 const char *snapdir;
1991 struct smb_filename *snapdir_smb_fname = NULL;
1992 struct dirent *d;
1993 TALLOC_CTX *tmp_ctx = talloc_stackframe();
1994 struct shadow_copy2_private *priv = NULL;
1995 struct shadow_copy2_snapentry *tmpentry = NULL;
1996 bool get_snaplist = false;
1997 bool access_granted = false;
1998 int ret = -1;
2000 snapdir = shadow_copy2_find_snapdir(tmp_ctx, handle, fsp->fsp_name);
2001 if (snapdir == NULL) {
2002 DEBUG(0,("shadow:snapdir not found for %s in get_shadow_copy_data\n",
2003 handle->conn->connectpath));
2004 errno = EINVAL;
2005 goto done;
2008 access_granted = check_access_snapdir(handle, snapdir);
2009 if (!access_granted) {
2010 DEBUG(0,("access denied on listing snapdir %s\n", snapdir));
2011 errno = EACCES;
2012 goto done;
2015 snapdir_smb_fname = synthetic_smb_fname(talloc_tos(),
2016 snapdir,
2017 NULL,
2018 NULL,
2019 fsp->fsp_name->flags);
2020 if (snapdir_smb_fname == NULL) {
2021 errno = ENOMEM;
2022 goto done;
2025 p = SMB_VFS_NEXT_OPENDIR(handle, snapdir_smb_fname, NULL, 0);
2027 if (!p) {
2028 DEBUG(2,("shadow_copy2: SMB_VFS_NEXT_OPENDIR() failed for '%s'"
2029 " - %s\n", snapdir, strerror(errno)));
2030 errno = ENOSYS;
2031 goto done;
2034 if (shadow_copy2_data != NULL) {
2035 shadow_copy2_data->num_volumes = 0;
2036 shadow_copy2_data->labels = NULL;
2039 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
2040 goto done);
2043 * Normally this function is called twice once with labels = false and
2044 * then with labels = true. When labels is false it will return the
2045 * number of volumes so that the caller can allocate memory for that
2046 * many labels. Therefore to eliminate snaplist both the times it is
2047 * good to check if labels is set or not.
2049 * shadow_copy2_data is NULL when we only want to update the list and
2050 * don't want any labels.
2052 if ((priv->snaps->regex != NULL) && (labels || shadow_copy2_data == NULL)) {
2053 get_snaplist = true;
2054 /* Reset the global snaplist */
2055 shadow_copy2_delete_snaplist(priv);
2057 /* Set the current time as snaplist update time */
2058 time(&(priv->snaps->fetch_time));
2061 while ((d = SMB_VFS_NEXT_READDIR(handle, p, NULL))) {
2062 char snapshot[GMT_NAME_LEN+1];
2063 SHADOW_COPY_LABEL *tlabels;
2066 * ignore names not of the right form in the snapshot
2067 * directory
2069 if (!shadow_copy2_snapshot_to_gmt(
2070 handle, d->d_name,
2071 snapshot, sizeof(snapshot))) {
2073 DEBUG(6, ("shadow_copy2_get_shadow_copy_data: "
2074 "ignoring %s\n", d->d_name));
2075 continue;
2077 DEBUG(6,("shadow_copy2_get_shadow_copy_data: %s -> %s\n",
2078 d->d_name, snapshot));
2080 if (get_snaplist) {
2082 * Create a snap entry for each successful
2083 * pattern match.
2085 tmpentry = shadow_copy2_create_snapentry(priv);
2086 if (tmpentry == NULL) {
2087 DBG_ERR("talloc_zero() failed\n");
2088 goto done;
2090 tmpentry->snapname = talloc_strdup(tmpentry, d->d_name);
2091 tmpentry->time_fmt = talloc_strdup(tmpentry, snapshot);
2094 if (shadow_copy2_data == NULL) {
2095 continue;
2098 if (!labels) {
2099 /* the caller doesn't want the labels */
2100 shadow_copy2_data->num_volumes++;
2101 continue;
2104 tlabels = talloc_realloc(shadow_copy2_data,
2105 shadow_copy2_data->labels,
2106 SHADOW_COPY_LABEL,
2107 shadow_copy2_data->num_volumes+1);
2108 if (tlabels == NULL) {
2109 DEBUG(0,("shadow_copy2: out of memory\n"));
2110 SMB_VFS_NEXT_CLOSEDIR(handle, p);
2111 goto done;
2114 strlcpy(tlabels[shadow_copy2_data->num_volumes], snapshot,
2115 sizeof(*tlabels));
2117 shadow_copy2_data->num_volumes++;
2118 shadow_copy2_data->labels = tlabels;
2121 SMB_VFS_NEXT_CLOSEDIR(handle,p);
2123 shadow_copy2_sort_data(handle, shadow_copy2_data);
2124 ret = 0;
2126 done:
2127 TALLOC_FREE(tmp_ctx);
2128 return ret;
2131 static NTSTATUS shadow_copy2_fget_nt_acl(vfs_handle_struct *handle,
2132 struct files_struct *fsp,
2133 uint32_t security_info,
2134 TALLOC_CTX *mem_ctx,
2135 struct security_descriptor **ppdesc)
2137 time_t timestamp = 0;
2138 char *stripped = NULL;
2139 NTSTATUS status;
2140 char *conv;
2141 struct smb_filename *smb_fname = NULL;
2143 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle,
2144 fsp->fsp_name->base_name,
2145 &timestamp, &stripped)) {
2146 return map_nt_error_from_unix(errno);
2148 if (timestamp == 0) {
2149 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2150 mem_ctx,
2151 ppdesc);
2153 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2154 TALLOC_FREE(stripped);
2155 if (conv == NULL) {
2156 return map_nt_error_from_unix(errno);
2158 smb_fname = synthetic_smb_fname(talloc_tos(),
2159 conv,
2160 NULL,
2161 NULL,
2162 fsp->fsp_name->flags);
2163 if (smb_fname == NULL) {
2164 TALLOC_FREE(conv);
2165 return NT_STATUS_NO_MEMORY;
2168 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2169 mem_ctx, ppdesc);
2170 TALLOC_FREE(conv);
2171 TALLOC_FREE(smb_fname);
2172 return status;
2175 static NTSTATUS shadow_copy2_get_nt_acl(vfs_handle_struct *handle,
2176 const struct smb_filename *smb_fname,
2177 uint32_t security_info,
2178 TALLOC_CTX *mem_ctx,
2179 struct security_descriptor **ppdesc)
2181 time_t timestamp = 0;
2182 char *stripped = NULL;
2183 NTSTATUS status;
2184 char *conv;
2185 struct smb_filename *conv_smb_fname = NULL;
2187 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2188 handle,
2189 smb_fname->base_name,
2190 &timestamp,
2191 &stripped)) {
2192 return map_nt_error_from_unix(errno);
2194 if (timestamp == 0) {
2195 return SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2196 mem_ctx, ppdesc);
2198 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2199 TALLOC_FREE(stripped);
2200 if (conv == NULL) {
2201 return map_nt_error_from_unix(errno);
2203 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2204 conv,
2205 NULL,
2206 NULL,
2207 smb_fname->flags);
2208 if (conv_smb_fname == NULL) {
2209 TALLOC_FREE(conv);
2210 return NT_STATUS_NO_MEMORY;
2212 status = SMB_VFS_NEXT_GET_NT_ACL(handle, conv_smb_fname, security_info,
2213 mem_ctx, ppdesc);
2214 TALLOC_FREE(conv);
2215 TALLOC_FREE(conv_smb_fname);
2216 return status;
2219 static int shadow_copy2_mkdir(vfs_handle_struct *handle,
2220 const struct smb_filename *smb_fname,
2221 mode_t mode)
2223 time_t timestamp = 0;
2224 char *stripped = NULL;
2225 int saved_errno = 0;
2226 int ret;
2227 char *conv;
2228 struct smb_filename *conv_smb_fname = NULL;
2230 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2231 handle,
2232 smb_fname->base_name,
2233 &timestamp,
2234 &stripped)) {
2235 return -1;
2237 if (timestamp == 0) {
2238 return SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
2240 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2241 TALLOC_FREE(stripped);
2242 if (conv == NULL) {
2243 return -1;
2245 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2246 conv,
2247 NULL,
2248 NULL,
2249 smb_fname->flags);
2250 if (conv_smb_fname == NULL) {
2251 TALLOC_FREE(conv);
2252 return -1;
2254 ret = SMB_VFS_NEXT_MKDIR(handle, conv_smb_fname, mode);
2255 if (ret == -1) {
2256 saved_errno = errno;
2258 TALLOC_FREE(conv);
2259 TALLOC_FREE(conv_smb_fname);
2260 if (saved_errno != 0) {
2261 errno = saved_errno;
2263 return ret;
2266 static int shadow_copy2_rmdir(vfs_handle_struct *handle,
2267 const struct smb_filename *smb_fname)
2269 time_t timestamp = 0;
2270 char *stripped = NULL;
2271 int saved_errno = 0;
2272 int ret;
2273 char *conv;
2274 struct smb_filename *conv_smb_fname = NULL;
2276 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2277 handle,
2278 smb_fname->base_name,
2279 &timestamp,
2280 &stripped)) {
2281 return -1;
2283 if (timestamp == 0) {
2284 return SMB_VFS_NEXT_RMDIR(handle, smb_fname);
2286 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2287 TALLOC_FREE(stripped);
2288 if (conv == NULL) {
2289 return -1;
2291 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2292 conv,
2293 NULL,
2294 NULL,
2295 smb_fname->flags);
2296 if (conv_smb_fname == NULL) {
2297 TALLOC_FREE(conv);
2298 return -1;
2300 ret = SMB_VFS_NEXT_RMDIR(handle, conv_smb_fname);
2301 if (ret == -1) {
2302 saved_errno = errno;
2304 TALLOC_FREE(conv_smb_fname);
2305 TALLOC_FREE(conv);
2306 if (saved_errno != 0) {
2307 errno = saved_errno;
2309 return ret;
2312 static int shadow_copy2_chflags(vfs_handle_struct *handle, const char *fname,
2313 unsigned int flags)
2315 time_t timestamp = 0;
2316 char *stripped = NULL;
2317 int saved_errno = 0;
2318 int ret;
2319 char *conv;
2321 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2322 &timestamp, &stripped)) {
2323 return -1;
2325 if (timestamp == 0) {
2326 return SMB_VFS_NEXT_CHFLAGS(handle, fname, flags);
2328 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2329 TALLOC_FREE(stripped);
2330 if (conv == NULL) {
2331 return -1;
2333 ret = SMB_VFS_NEXT_CHFLAGS(handle, conv, flags);
2334 if (ret == -1) {
2335 saved_errno = errno;
2337 TALLOC_FREE(conv);
2338 if (saved_errno != 0) {
2339 errno = saved_errno;
2341 return ret;
2344 static ssize_t shadow_copy2_getxattr(vfs_handle_struct *handle,
2345 const struct smb_filename *smb_fname,
2346 const char *aname,
2347 void *value,
2348 size_t size)
2350 time_t timestamp = 0;
2351 char *stripped = NULL;
2352 ssize_t ret;
2353 int saved_errno = 0;
2354 char *conv;
2355 struct smb_filename *conv_smb_fname = NULL;
2357 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2358 handle,
2359 smb_fname->base_name,
2360 &timestamp,
2361 &stripped)) {
2362 return -1;
2364 if (timestamp == 0) {
2365 return SMB_VFS_NEXT_GETXATTR(handle, smb_fname, aname, value,
2366 size);
2368 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2369 TALLOC_FREE(stripped);
2370 if (conv == NULL) {
2371 return -1;
2374 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2375 conv,
2376 NULL,
2377 NULL,
2378 smb_fname->flags);
2379 if (conv_smb_fname == NULL) {
2380 TALLOC_FREE(conv);
2381 return -1;
2384 ret = SMB_VFS_NEXT_GETXATTR(handle, conv_smb_fname, aname, value, size);
2385 if (ret == -1) {
2386 saved_errno = errno;
2388 TALLOC_FREE(conv_smb_fname);
2389 TALLOC_FREE(conv);
2390 if (saved_errno != 0) {
2391 errno = saved_errno;
2393 return ret;
2396 static ssize_t shadow_copy2_listxattr(struct vfs_handle_struct *handle,
2397 const struct smb_filename *smb_fname,
2398 char *list, size_t size)
2400 time_t timestamp = 0;
2401 char *stripped = NULL;
2402 ssize_t ret;
2403 int saved_errno = 0;
2404 char *conv;
2405 struct smb_filename *conv_smb_fname = NULL;
2407 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2408 handle,
2409 smb_fname->base_name,
2410 &timestamp,
2411 &stripped)) {
2412 return -1;
2414 if (timestamp == 0) {
2415 return SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2417 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2418 TALLOC_FREE(stripped);
2419 if (conv == NULL) {
2420 return -1;
2422 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2423 conv,
2424 NULL,
2425 NULL,
2426 smb_fname->flags);
2427 if (conv_smb_fname == NULL) {
2428 TALLOC_FREE(conv);
2429 return -1;
2431 ret = SMB_VFS_NEXT_LISTXATTR(handle, conv_smb_fname, list, size);
2432 if (ret == -1) {
2433 saved_errno = errno;
2435 TALLOC_FREE(conv_smb_fname);
2436 TALLOC_FREE(conv);
2437 if (saved_errno != 0) {
2438 errno = saved_errno;
2440 return ret;
2443 static int shadow_copy2_removexattr(vfs_handle_struct *handle,
2444 const struct smb_filename *smb_fname,
2445 const char *aname)
2447 time_t timestamp = 0;
2448 char *stripped = NULL;
2449 int saved_errno = 0;
2450 int ret;
2451 char *conv;
2452 struct smb_filename *conv_smb_fname = NULL;
2454 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2455 handle,
2456 smb_fname->base_name,
2457 &timestamp,
2458 &stripped)) {
2459 return -1;
2461 if (timestamp == 0) {
2462 return SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, aname);
2464 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2465 TALLOC_FREE(stripped);
2466 if (conv == NULL) {
2467 return -1;
2469 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2470 conv,
2471 NULL,
2472 NULL,
2473 smb_fname->flags);
2474 if (conv_smb_fname == NULL) {
2475 TALLOC_FREE(conv);
2476 return -1;
2478 ret = SMB_VFS_NEXT_REMOVEXATTR(handle, conv_smb_fname, aname);
2479 if (ret == -1) {
2480 saved_errno = errno;
2482 TALLOC_FREE(conv_smb_fname);
2483 TALLOC_FREE(conv);
2484 if (saved_errno != 0) {
2485 errno = saved_errno;
2487 return ret;
2490 static int shadow_copy2_setxattr(struct vfs_handle_struct *handle,
2491 const struct smb_filename *smb_fname,
2492 const char *aname, const void *value,
2493 size_t size, int flags)
2495 time_t timestamp = 0;
2496 char *stripped = NULL;
2497 ssize_t ret;
2498 int saved_errno = 0;
2499 char *conv;
2500 struct smb_filename *conv_smb_fname = NULL;
2502 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2503 handle,
2504 smb_fname->base_name,
2505 &timestamp,
2506 &stripped)) {
2507 return -1;
2509 if (timestamp == 0) {
2510 return SMB_VFS_NEXT_SETXATTR(handle, smb_fname,
2511 aname, value, size, flags);
2513 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2514 TALLOC_FREE(stripped);
2515 if (conv == NULL) {
2516 return -1;
2518 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2519 conv,
2520 NULL,
2521 NULL,
2522 smb_fname->flags);
2523 if (conv_smb_fname == NULL) {
2524 TALLOC_FREE(conv);
2525 return -1;
2527 ret = SMB_VFS_NEXT_SETXATTR(handle, conv_smb_fname,
2528 aname, value, size, flags);
2529 if (ret == -1) {
2530 saved_errno = errno;
2532 TALLOC_FREE(conv_smb_fname);
2533 TALLOC_FREE(conv);
2534 if (saved_errno != 0) {
2535 errno = saved_errno;
2537 return ret;
2540 static int shadow_copy2_chmod_acl(vfs_handle_struct *handle,
2541 const struct smb_filename *smb_fname,
2542 mode_t mode)
2544 time_t timestamp = 0;
2545 char *stripped = NULL;
2546 ssize_t ret;
2547 int saved_errno = 0;
2548 char *conv = NULL;
2549 struct smb_filename *conv_smb_fname = NULL;
2551 if (!shadow_copy2_strip_snapshot(talloc_tos(),
2552 handle,
2553 smb_fname->base_name,
2554 &timestamp,
2555 &stripped)) {
2556 return -1;
2558 if (timestamp == 0) {
2559 return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
2561 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2562 TALLOC_FREE(stripped);
2563 if (conv == NULL) {
2564 return -1;
2566 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2567 conv,
2568 NULL,
2569 NULL,
2570 smb_fname->flags);
2571 if (conv_smb_fname == NULL) {
2572 TALLOC_FREE(conv);
2573 errno = ENOMEM;
2574 return -1;
2576 ret = SMB_VFS_NEXT_CHMOD_ACL(handle, conv_smb_fname, mode);
2577 if (ret == -1) {
2578 saved_errno = errno;
2580 TALLOC_FREE(conv);
2581 TALLOC_FREE(conv_smb_fname);
2582 if (saved_errno != 0) {
2583 errno = saved_errno;
2585 return ret;
2588 static int shadow_copy2_get_real_filename(struct vfs_handle_struct *handle,
2589 const char *path,
2590 const char *name,
2591 TALLOC_CTX *mem_ctx,
2592 char **found_name)
2594 time_t timestamp = 0;
2595 char *stripped = NULL;
2596 ssize_t ret;
2597 int saved_errno = 0;
2598 char *conv;
2600 DEBUG(10, ("shadow_copy2_get_real_filename called for path=[%s], "
2601 "name=[%s]\n", path, name));
2603 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2604 &timestamp, &stripped)) {
2605 DEBUG(10, ("shadow_copy2_strip_snapshot failed\n"));
2606 return -1;
2608 if (timestamp == 0) {
2609 DEBUG(10, ("timestamp == 0\n"));
2610 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
2611 mem_ctx, found_name);
2613 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2614 TALLOC_FREE(stripped);
2615 if (conv == NULL) {
2616 DEBUG(10, ("shadow_copy2_convert failed\n"));
2617 return -1;
2619 DEBUG(10, ("Calling NEXT_GET_REAL_FILE_NAME for conv=[%s], "
2620 "name=[%s]\n", conv, name));
2621 ret = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, conv, name,
2622 mem_ctx, found_name);
2623 DEBUG(10, ("NEXT_REAL_FILE_NAME returned %d\n", (int)ret));
2624 if (ret == -1) {
2625 saved_errno = errno;
2627 TALLOC_FREE(conv);
2628 if (saved_errno != 0) {
2629 errno = saved_errno;
2631 return ret;
2634 static const char *shadow_copy2_connectpath(struct vfs_handle_struct *handle,
2635 const char *fname)
2637 time_t timestamp = 0;
2638 char *stripped = NULL;
2639 char *tmp = NULL;
2640 char *result = NULL;
2641 char *parent_dir = NULL;
2642 int saved_errno = 0;
2643 size_t rootpath_len = 0;
2644 struct shadow_copy2_private *priv = NULL;
2646 SMB_VFS_HANDLE_GET_DATA(handle, priv, struct shadow_copy2_private,
2647 return NULL);
2649 DBG_DEBUG("Calc connect path for [%s]\n", fname);
2651 if (priv->shadow_connectpath != NULL) {
2652 DBG_DEBUG("cached connect path is [%s]\n",
2653 priv->shadow_connectpath);
2654 return priv->shadow_connectpath;
2657 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, fname,
2658 &timestamp, &stripped)) {
2659 goto done;
2661 if (timestamp == 0) {
2662 return SMB_VFS_NEXT_CONNECTPATH(handle, fname);
2665 tmp = shadow_copy2_do_convert(talloc_tos(), handle, stripped, timestamp,
2666 &rootpath_len);
2667 if (tmp == NULL) {
2668 if (errno != ENOENT) {
2669 goto done;
2673 * If the converted path does not exist, and converting
2674 * the parent yields something that does exist, then
2675 * this path refers to something that has not been
2676 * created yet, relative to the parent path.
2677 * The snapshot finding is relative to the parent.
2678 * (usually snapshots are read/only but this is not
2679 * necessarily true).
2680 * This code also covers getting a wildcard in the
2681 * last component, because this function is called
2682 * prior to sanitizing the path, and in SMB1 we may
2683 * get wildcards in path names.
2685 if (!parent_dirname(talloc_tos(), stripped, &parent_dir,
2686 NULL)) {
2687 errno = ENOMEM;
2688 goto done;
2691 tmp = shadow_copy2_do_convert(talloc_tos(), handle, parent_dir,
2692 timestamp, &rootpath_len);
2693 if (tmp == NULL) {
2694 goto done;
2698 DBG_DEBUG("converted path is [%s] root path is [%.*s]\n", tmp,
2699 (int)rootpath_len, tmp);
2701 tmp[rootpath_len] = '\0';
2702 result = SMB_VFS_NEXT_REALPATH(handle, tmp);
2703 if (result == NULL) {
2704 goto done;
2708 * SMB_VFS_NEXT_REALPATH returns a malloc'ed string.
2709 * Don't leak memory.
2711 SAFE_FREE(priv->shadow_realpath);
2712 priv->shadow_realpath = result;
2714 DBG_DEBUG("connect path is [%s]\n", result);
2716 done:
2717 if (result == NULL) {
2718 saved_errno = errno;
2720 TALLOC_FREE(tmp);
2721 TALLOC_FREE(stripped);
2722 TALLOC_FREE(parent_dir);
2723 if (saved_errno != 0) {
2724 errno = saved_errno;
2726 return result;
2729 static uint64_t shadow_copy2_disk_free(vfs_handle_struct *handle,
2730 const char *path, uint64_t *bsize,
2731 uint64_t *dfree, uint64_t *dsize)
2733 time_t timestamp = 0;
2734 char *stripped = NULL;
2735 ssize_t ret;
2736 int saved_errno = 0;
2737 char *conv;
2739 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path,
2740 &timestamp, &stripped)) {
2741 return -1;
2743 if (timestamp == 0) {
2744 return SMB_VFS_NEXT_DISK_FREE(handle, path,
2745 bsize, dfree, dsize);
2748 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2749 TALLOC_FREE(stripped);
2750 if (conv == NULL) {
2751 return -1;
2754 ret = SMB_VFS_NEXT_DISK_FREE(handle, conv, bsize, dfree, dsize);
2756 if (ret == -1) {
2757 saved_errno = errno;
2759 TALLOC_FREE(conv);
2760 if (saved_errno != 0) {
2761 errno = saved_errno;
2764 return ret;
2767 static int shadow_copy2_get_quota(vfs_handle_struct *handle, const char *path,
2768 enum SMB_QUOTA_TYPE qtype, unid_t id,
2769 SMB_DISK_QUOTA *dq)
2771 time_t timestamp = 0;
2772 char *stripped = NULL;
2773 int ret;
2774 int saved_errno = 0;
2775 char *conv;
2777 if (!shadow_copy2_strip_snapshot(talloc_tos(), handle, path, &timestamp,
2778 &stripped)) {
2779 return -1;
2781 if (timestamp == 0) {
2782 return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
2785 conv = shadow_copy2_convert(talloc_tos(), handle, stripped, timestamp);
2786 TALLOC_FREE(stripped);
2787 if (conv == NULL) {
2788 return -1;
2791 ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv, qtype, id, dq);
2793 if (ret == -1) {
2794 saved_errno = errno;
2796 TALLOC_FREE(conv);
2797 if (saved_errno != 0) {
2798 errno = saved_errno;
2801 return ret;
2804 static int shadow_copy2_private_destructor(struct shadow_copy2_private *priv)
2806 SAFE_FREE(priv->shadow_realpath);
2807 return 0;
2810 static int shadow_copy2_connect(struct vfs_handle_struct *handle,
2811 const char *service, const char *user)
2813 struct shadow_copy2_config *config;
2814 struct shadow_copy2_private *priv;
2815 int ret;
2816 const char *snapdir;
2817 const char *snapprefix = NULL;
2818 const char *delimiter;
2819 const char *gmt_format;
2820 const char *sort_order;
2821 const char *basedir = NULL;
2822 const char *snapsharepath = NULL;
2823 const char *mount_point;
2825 DEBUG(10, (__location__ ": cnum[%u], connectpath[%s]\n",
2826 (unsigned)handle->conn->cnum,
2827 handle->conn->connectpath));
2829 ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
2830 if (ret < 0) {
2831 return ret;
2834 priv = talloc_zero(handle->conn, struct shadow_copy2_private);
2835 if (priv == NULL) {
2836 DBG_ERR("talloc_zero() failed\n");
2837 errno = ENOMEM;
2838 return -1;
2841 talloc_set_destructor(priv, shadow_copy2_private_destructor);
2843 priv->snaps = talloc_zero(priv, struct shadow_copy2_snaplist_info);
2844 if (priv->snaps == NULL) {
2845 DBG_ERR("talloc_zero() failed\n");
2846 errno = ENOMEM;
2847 return -1;
2850 config = talloc_zero(priv, struct shadow_copy2_config);
2851 if (config == NULL) {
2852 DEBUG(0, ("talloc_zero() failed\n"));
2853 errno = ENOMEM;
2854 return -1;
2857 priv->config = config;
2859 gmt_format = lp_parm_const_string(SNUM(handle->conn),
2860 "shadow", "format",
2861 GMT_FORMAT);
2862 config->gmt_format = talloc_strdup(config, gmt_format);
2863 if (config->gmt_format == NULL) {
2864 DEBUG(0, ("talloc_strdup() failed\n"));
2865 errno = ENOMEM;
2866 return -1;
2869 /* config->gmt_format must not contain a path separator. */
2870 if (strchr(config->gmt_format, '/') != NULL) {
2871 DEBUG(0, ("shadow:format %s must not contain a /"
2872 "character. Unable to initialize module.\n",
2873 config->gmt_format));
2874 errno = EINVAL;
2875 return -1;
2878 config->use_sscanf = lp_parm_bool(SNUM(handle->conn),
2879 "shadow", "sscanf", false);
2881 config->use_localtime = lp_parm_bool(SNUM(handle->conn),
2882 "shadow", "localtime",
2883 false);
2885 snapdir = lp_parm_const_string(SNUM(handle->conn),
2886 "shadow", "snapdir",
2887 ".snapshots");
2888 config->snapdir = talloc_strdup(config, snapdir);
2889 if (config->snapdir == NULL) {
2890 DEBUG(0, ("talloc_strdup() failed\n"));
2891 errno = ENOMEM;
2892 return -1;
2895 snapprefix = lp_parm_const_string(SNUM(handle->conn),
2896 "shadow", "snapprefix",
2897 NULL);
2898 if (snapprefix != NULL) {
2899 priv->snaps->regex = talloc_zero(priv->snaps, regex_t);
2900 if (priv->snaps->regex == NULL) {
2901 DBG_ERR("talloc_zero() failed\n");
2902 errno = ENOMEM;
2903 return -1;
2906 /* pre-compute regex rule for matching pattern later */
2907 ret = regcomp(priv->snaps->regex, snapprefix, 0);
2908 if (ret) {
2909 DBG_ERR("Failed to create regex object\n");
2910 return -1;
2914 delimiter = lp_parm_const_string(SNUM(handle->conn),
2915 "shadow", "delimiter",
2916 "_GMT");
2917 if (delimiter != NULL) {
2918 priv->config->delimiter = talloc_strdup(priv->config, delimiter);
2919 if (priv->config->delimiter == NULL) {
2920 DBG_ERR("talloc_strdup() failed\n");
2921 errno = ENOMEM;
2922 return -1;
2926 config->snapdirseverywhere = lp_parm_bool(SNUM(handle->conn),
2927 "shadow",
2928 "snapdirseverywhere",
2929 false);
2931 config->crossmountpoints = lp_parm_bool(SNUM(handle->conn),
2932 "shadow", "crossmountpoints",
2933 false);
2935 if (config->crossmountpoints && !config->snapdirseverywhere) {
2936 DBG_WARNING("Warning: 'crossmountpoints' depends on "
2937 "'snapdirseverywhere'. Disabling crossmountpoints.\n");
2940 config->fixinodes = lp_parm_bool(SNUM(handle->conn),
2941 "shadow", "fixinodes",
2942 false);
2944 sort_order = lp_parm_const_string(SNUM(handle->conn),
2945 "shadow", "sort", "desc");
2946 config->sort_order = talloc_strdup(config, sort_order);
2947 if (config->sort_order == NULL) {
2948 DEBUG(0, ("talloc_strdup() failed\n"));
2949 errno = ENOMEM;
2950 return -1;
2953 mount_point = lp_parm_const_string(SNUM(handle->conn),
2954 "shadow", "mountpoint", NULL);
2955 if (mount_point != NULL) {
2956 if (mount_point[0] != '/') {
2957 DEBUG(1, (__location__ " Warning: 'mountpoint' is "
2958 "relative ('%s'), but it has to be an "
2959 "absolute path. Ignoring provided value.\n",
2960 mount_point));
2961 mount_point = NULL;
2962 } else {
2963 char *p;
2964 p = strstr(handle->conn->connectpath, mount_point);
2965 if (p != handle->conn->connectpath) {
2966 DBG_WARNING("Warning: the share root (%s) is "
2967 "not a subdirectory of the "
2968 "specified mountpoint (%s). "
2969 "Ignoring provided value.\n",
2970 handle->conn->connectpath,
2971 mount_point);
2972 mount_point = NULL;
2977 if (mount_point != NULL) {
2978 config->mount_point = talloc_strdup(config, mount_point);
2979 if (config->mount_point == NULL) {
2980 DEBUG(0, (__location__ " talloc_strdup() failed\n"));
2981 return -1;
2983 } else {
2984 config->mount_point = shadow_copy2_find_mount_point(config,
2985 handle);
2986 if (config->mount_point == NULL) {
2987 DBG_WARNING("shadow_copy2_find_mount_point "
2988 "of the share root '%s' failed: %s\n",
2989 handle->conn->connectpath, strerror(errno));
2990 return -1;
2994 basedir = lp_parm_const_string(SNUM(handle->conn),
2995 "shadow", "basedir", NULL);
2997 if (basedir != NULL) {
2998 if (basedir[0] != '/') {
2999 DEBUG(1, (__location__ " Warning: 'basedir' is "
3000 "relative ('%s'), but it has to be an "
3001 "absolute path. Disabling basedir.\n",
3002 basedir));
3003 basedir = NULL;
3004 } else {
3005 char *p;
3006 p = strstr(basedir, config->mount_point);
3007 if (p != basedir) {
3008 DEBUG(1, ("Warning: basedir (%s) is not a "
3009 "subdirectory of the share root's "
3010 "mount point (%s). "
3011 "Disabling basedir\n",
3012 basedir, config->mount_point));
3013 basedir = NULL;
3018 if (config->snapdirseverywhere && basedir != NULL) {
3019 DEBUG(1, (__location__ " Warning: 'basedir' is incompatible "
3020 "with 'snapdirseverywhere'. Disabling basedir.\n"));
3021 basedir = NULL;
3024 snapsharepath = lp_parm_const_string(SNUM(handle->conn), "shadow",
3025 "snapsharepath", NULL);
3026 if (snapsharepath != NULL) {
3027 if (snapsharepath[0] == '/') {
3028 DBG_WARNING("Warning: 'snapsharepath' is "
3029 "absolute ('%s'), but it has to be a "
3030 "relative path. Disabling snapsharepath.\n",
3031 snapsharepath);
3032 snapsharepath = NULL;
3034 if (config->snapdirseverywhere && snapsharepath != NULL) {
3035 DBG_WARNING("Warning: 'snapsharepath' is incompatible "
3036 "with 'snapdirseverywhere'. Disabling "
3037 "snapsharepath.\n");
3038 snapsharepath = NULL;
3042 if (basedir != NULL && snapsharepath != NULL) {
3043 DBG_WARNING("Warning: 'snapsharepath' is incompatible with "
3044 "'basedir'. Disabling snapsharepath\n");
3045 snapsharepath = NULL;
3048 if (snapsharepath != NULL) {
3049 config->rel_connectpath = talloc_strdup(config, snapsharepath);
3050 if (config->rel_connectpath == NULL) {
3051 DBG_ERR("talloc_strdup() failed\n");
3052 errno = ENOMEM;
3053 return -1;
3057 if (basedir == NULL) {
3058 basedir = config->mount_point;
3061 if (config->rel_connectpath == NULL &&
3062 strlen(basedir) < strlen(handle->conn->connectpath)) {
3063 config->rel_connectpath = talloc_strdup(config,
3064 handle->conn->connectpath + strlen(basedir));
3065 if (config->rel_connectpath == NULL) {
3066 DEBUG(0, ("talloc_strdup() failed\n"));
3067 errno = ENOMEM;
3068 return -1;
3072 if (config->snapdir[0] == '/') {
3073 config->snapdir_absolute = true;
3075 if (config->snapdirseverywhere == true) {
3076 DEBUG(1, (__location__ " Warning: An absolute snapdir "
3077 "is incompatible with 'snapdirseverywhere', "
3078 "setting 'snapdirseverywhere' to false.\n"));
3079 config->snapdirseverywhere = false;
3082 if (config->crossmountpoints == true) {
3083 DEBUG(1, (__location__ " Warning: 'crossmountpoints' "
3084 "is not supported with an absolute snapdir. "
3085 "Disabling it.\n"));
3086 config->crossmountpoints = false;
3089 config->snapshot_basepath = config->snapdir;
3090 } else {
3091 config->snapshot_basepath = talloc_asprintf(config, "%s/%s",
3092 config->mount_point, config->snapdir);
3093 if (config->snapshot_basepath == NULL) {
3094 DEBUG(0, ("talloc_asprintf() failed\n"));
3095 errno = ENOMEM;
3096 return -1;
3100 trim_string(config->mount_point, NULL, "/");
3101 trim_string(config->rel_connectpath, "/", "/");
3102 trim_string(config->snapdir, NULL, "/");
3103 trim_string(config->snapshot_basepath, NULL, "/");
3105 DEBUG(10, ("shadow_copy2_connect: configuration:\n"
3106 " share root: '%s'\n"
3107 " mountpoint: '%s'\n"
3108 " rel share root: '%s'\n"
3109 " snapdir: '%s'\n"
3110 " snapprefix: '%s'\n"
3111 " delimiter: '%s'\n"
3112 " snapshot base path: '%s'\n"
3113 " format: '%s'\n"
3114 " use sscanf: %s\n"
3115 " snapdirs everywhere: %s\n"
3116 " cross mountpoints: %s\n"
3117 " fix inodes: %s\n"
3118 " sort order: %s\n"
3120 handle->conn->connectpath,
3121 config->mount_point,
3122 config->rel_connectpath,
3123 config->snapdir,
3124 snapprefix,
3125 config->delimiter,
3126 config->snapshot_basepath,
3127 config->gmt_format,
3128 config->use_sscanf ? "yes" : "no",
3129 config->snapdirseverywhere ? "yes" : "no",
3130 config->crossmountpoints ? "yes" : "no",
3131 config->fixinodes ? "yes" : "no",
3132 config->sort_order
3136 SMB_VFS_HANDLE_SET_DATA(handle, priv,
3137 NULL, struct shadow_copy2_private,
3138 return -1);
3140 return 0;
3143 static struct vfs_fn_pointers vfs_shadow_copy2_fns = {
3144 .connect_fn = shadow_copy2_connect,
3145 .opendir_fn = shadow_copy2_opendir,
3146 .disk_free_fn = shadow_copy2_disk_free,
3147 .get_quota_fn = shadow_copy2_get_quota,
3148 .rename_fn = shadow_copy2_rename,
3149 .link_fn = shadow_copy2_link,
3150 .symlink_fn = shadow_copy2_symlink,
3151 .stat_fn = shadow_copy2_stat,
3152 .lstat_fn = shadow_copy2_lstat,
3153 .fstat_fn = shadow_copy2_fstat,
3154 .open_fn = shadow_copy2_open,
3155 .unlink_fn = shadow_copy2_unlink,
3156 .chmod_fn = shadow_copy2_chmod,
3157 .chown_fn = shadow_copy2_chown,
3158 .chdir_fn = shadow_copy2_chdir,
3159 .ntimes_fn = shadow_copy2_ntimes,
3160 .readlink_fn = shadow_copy2_readlink,
3161 .mknod_fn = shadow_copy2_mknod,
3162 .realpath_fn = shadow_copy2_realpath,
3163 .get_nt_acl_fn = shadow_copy2_get_nt_acl,
3164 .fget_nt_acl_fn = shadow_copy2_fget_nt_acl,
3165 .get_shadow_copy_data_fn = shadow_copy2_get_shadow_copy_data,
3166 .mkdir_fn = shadow_copy2_mkdir,
3167 .rmdir_fn = shadow_copy2_rmdir,
3168 .getxattr_fn = shadow_copy2_getxattr,
3169 .listxattr_fn = shadow_copy2_listxattr,
3170 .removexattr_fn = shadow_copy2_removexattr,
3171 .setxattr_fn = shadow_copy2_setxattr,
3172 .chmod_acl_fn = shadow_copy2_chmod_acl,
3173 .chflags_fn = shadow_copy2_chflags,
3174 .get_real_filename_fn = shadow_copy2_get_real_filename,
3175 .connectpath_fn = shadow_copy2_connectpath,
3178 NTSTATUS vfs_shadow_copy2_init(TALLOC_CTX *);
3179 NTSTATUS vfs_shadow_copy2_init(TALLOC_CTX *ctx)
3181 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
3182 "shadow_copy2", &vfs_shadow_copy2_fns);