2 * Module for snapshot IO using snapper
4 * Copyright (C) David Disseldorp 2012-2014
6 * Portions taken from vfs_shadow_copy2.c:
7 * Copyright (C) Andrew Tridgell 2007
8 * Copyright (C) Ed Plese 2009
9 * Copyright (C) Volker Lendecke 2011
10 * Copyright (C) Christian Ambach 2011
11 * Copyright (C) Michael Adam 2013
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
27 #include <dbus/dbus.h>
28 #ifdef HAVE_LINUX_IOCTL_H
29 #include <linux/ioctl.h>
31 #include <sys/ioctl.h>
35 #include "include/ntioctl.h"
36 #include "include/smb.h"
37 #include "system/filesys.h"
38 #include "smbd/smbd.h"
39 #include "lib/util/tevent_ntstatus.h"
41 #define SNAPPER_SIG_LIST_SNAPS_RSP "a(uquxussa{ss})"
42 #define SNAPPER_SIG_LIST_CONFS_RSP "a(ssa{ss})"
43 #define SNAPPER_SIG_CREATE_SNAP_RSP "u"
44 #define SNAPPER_SIG_DEL_SNAPS_RSP ""
45 #define SNAPPER_SIG_STRING_DICT "{ss}"
60 uint32_t num_user_data;
61 struct snapper_dict *user_data;
68 struct snapper_dict *attrs;
72 const char *snapper_err_str;
74 } snapper_err_map[] = {
75 { "error.no_permissions", NT_STATUS_ACCESS_DENIED },
78 static NTSTATUS snapper_err_ntstatus_map(const char *snapper_err_str)
82 if (snapper_err_str == NULL) {
83 return NT_STATUS_UNSUCCESSFUL;
85 for (i = 0; i < ARRAY_SIZE(snapper_err_map); i++) {
86 if (!strcmp(snapper_err_map[i].snapper_err_str,
88 return snapper_err_map[i].status;
91 DEBUG(2, ("no explicit mapping for dbus error: %s\n", snapper_err_str));
93 return NT_STATUS_UNSUCCESSFUL;
97 * Strings are UTF-8. Other characters must be encoded hexadecimal as "\x??".
98 * As a consequence "\" must be encoded as "\\".
100 static NTSTATUS snapper_dbus_str_encode(TALLOC_CTX *mem_ctx, const char *in_str,
109 if (in_str == NULL) {
110 return NT_STATUS_INVALID_PARAMETER;
113 in_len = strlen(in_str);
115 /* output can be max 4 times the length of @in_str, +1 for terminator */
116 out_len = (in_len * 4) + 1;
118 out_str = talloc_array(mem_ctx, char, out_len);
119 if (out_str == NULL) {
120 return NT_STATUS_NO_MEMORY;
124 for (i = 0; i < in_len; i++) {
127 if (in_str[i] == '\\') {
128 pushed = snprintf(out_str + out_off, out_len - out_off,
130 } else if ((unsigned char)in_str[i] > 127) {
131 pushed = snprintf(out_str + out_off, out_len - out_off,
132 "\\x%02x", (unsigned char)in_str[i]);
134 /* regular character */
135 *(out_str + out_off) = in_str[i];
136 pushed = sizeof(char);
138 if (pushed >= out_len - out_off) {
139 /* truncated, should never happen */
140 talloc_free(out_str);
141 return NT_STATUS_INTERNAL_ERROR;
146 *(out_str + out_off) = '\0';
152 static NTSTATUS snapper_dbus_str_decode(TALLOC_CTX *mem_ctx, const char *in_str,
161 if (in_str == NULL) {
162 return NT_STATUS_INVALID_PARAMETER;
165 in_len = strlen(in_str);
167 /* output cannot be larger than input, +1 for terminator */
168 out_len = in_len + 1;
170 out_str = talloc_array(mem_ctx, char, out_len);
171 if (out_str == NULL) {
172 return NT_STATUS_NO_MEMORY;
176 for (i = 0; i < in_len; i++) {
179 unsigned int non_ascii_byte;
181 if (in_str[i] != '\\') {
182 out_str[out_off] = in_str[i];
188 if (in_str[i] == '\\') {
189 out_str[out_off] = '\\';
192 } else if (in_str[i] != 'x') {
193 goto err_invalid_src_encoding;
196 /* non-ASCII, encoded as two hex chars */
197 for (j = 0; j < 2; j++) {
199 if ((in_str[i] == '\0') || !isxdigit(in_str[i])) {
200 goto err_invalid_src_encoding;
202 hex_buf[j] = in_str[i];
206 sscanf(hex_buf, "%x", &non_ascii_byte);
207 out_str[out_off] = (unsigned char)non_ascii_byte;
211 out_str[out_off] = '\0';
215 err_invalid_src_encoding:
216 DEBUG(0, ("invalid encoding %s\n", in_str));
217 return NT_STATUS_INVALID_PARAMETER;
220 static DBusConnection *snapper_dbus_conn_create(void)
223 DBusConnection *dconn;
225 dbus_error_init(&err);
228 * Always create a new DBus connection, to ensure snapperd detects the
229 * correct client [E]UID. With dbus_bus_get() it does not!
231 dconn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err);
232 if (dbus_error_is_set(&err)) {
233 DEBUG(0, ("dbus connection error: %s\n", err.message));
234 dbus_error_free(&err);
240 /* dbus_bus_get_private() sets exit-on-disconnect by default, undo it */
241 dbus_connection_set_exit_on_disconnect(dconn, false);
246 static void snapper_dbus_conn_destroy(DBusConnection *dconn)
249 DEBUG(2, ("attempt to destroy NULL dbus connection\n"));
253 dbus_connection_close(dconn);
254 dbus_connection_unref(dconn);
258 * send the message @send_msg over the dbus and wait for a response, return the
259 * responsee via @recv_msg_out.
260 * @send_msg is not freed, dbus_message_unref() must be handled by the caller.
262 static NTSTATUS snapper_dbus_msg_xchng(DBusConnection *dconn,
263 DBusMessage *send_msg,
264 DBusMessage **recv_msg_out)
266 DBusPendingCall *pending;
267 DBusMessage *recv_msg;
269 /* send message and get a handle for a reply */
270 if (!dbus_connection_send_with_reply(dconn, send_msg, &pending, -1)) {
271 return NT_STATUS_NO_MEMORY;
273 if (NULL == pending) {
274 DEBUG(0, ("dbus msg send failed\n"));
275 return NT_STATUS_UNSUCCESSFUL;
278 dbus_connection_flush(dconn);
280 /* block until we receive a reply */
281 dbus_pending_call_block(pending);
283 /* get the reply message */
284 recv_msg = dbus_pending_call_steal_reply(pending);
285 if (recv_msg == NULL) {
286 DEBUG(0, ("Reply Null\n"));
287 return NT_STATUS_UNSUCCESSFUL;
289 /* free the pending message handle */
290 dbus_pending_call_unref(pending);
291 *recv_msg_out = recv_msg;
296 static NTSTATUS snapper_type_check(DBusMessageIter *iter,
299 int type = dbus_message_iter_get_arg_type(iter);
300 if (type != expected_type) {
301 DEBUG(0, ("got type %d, expecting %d\n",
302 type, expected_type));
303 return NT_STATUS_INVALID_PARAMETER;
309 static NTSTATUS snapper_type_check_get(DBusMessageIter *iter,
314 status = snapper_type_check(iter, expected_type);
315 if (!NT_STATUS_IS_OK(status)) {
319 dbus_message_iter_get_basic(iter, val);
324 static NTSTATUS snapper_dict_unpack(TALLOC_CTX *mem_ctx,
325 DBusMessageIter *iter,
326 struct snapper_dict *dict_out)
330 DBusMessageIter dct_iter;
334 status = snapper_type_check(iter, DBUS_TYPE_DICT_ENTRY);
335 if (!NT_STATUS_IS_OK(status)) {
338 dbus_message_iter_recurse(iter, &dct_iter);
340 status = snapper_type_check_get(&dct_iter, DBUS_TYPE_STRING,
342 if (!NT_STATUS_IS_OK(status)) {
345 status = snapper_dbus_str_decode(mem_ctx, key_encoded, &dict_out->key);
346 if (!NT_STATUS_IS_OK(status)) {
350 dbus_message_iter_next(&dct_iter);
351 status = snapper_type_check_get(&dct_iter, DBUS_TYPE_STRING,
353 if (!NT_STATUS_IS_OK(status)) {
354 talloc_free(dict_out->key);
357 status = snapper_dbus_str_decode(mem_ctx, val_encoded, &dict_out->val);
358 if (!NT_STATUS_IS_OK(status)) {
359 talloc_free(dict_out->key);
366 static void snapper_dict_array_print(uint32_t num_dicts,
367 struct snapper_dict *dicts)
371 for (i = 0; i < num_dicts; i++) {
372 DEBUG(10, ("dict (key: %s, val: %s)\n",
373 dicts[i].key, dicts[i].val));
377 static NTSTATUS snapper_dict_array_unpack(TALLOC_CTX *mem_ctx,
378 DBusMessageIter *iter,
379 uint32_t *num_dicts_out,
380 struct snapper_dict **dicts_out)
383 DBusMessageIter array_iter;
385 struct snapper_dict *dicts = NULL;
387 status = snapper_type_check(iter, DBUS_TYPE_ARRAY);
388 if (!NT_STATUS_IS_OK(status)) {
391 dbus_message_iter_recurse(iter, &array_iter);
394 while (dbus_message_iter_get_arg_type(&array_iter)
395 != DBUS_TYPE_INVALID) {
397 dicts = talloc_realloc(mem_ctx, dicts, struct snapper_dict,
402 status = snapper_dict_unpack(mem_ctx, &array_iter,
403 &dicts[num_dicts - 1]);
404 if (!NT_STATUS_IS_OK(status)) {
408 dbus_message_iter_next(&array_iter);
411 *num_dicts_out = num_dicts;
417 static NTSTATUS snapper_list_confs_pack(DBusMessage **req_msg_out)
421 msg = dbus_message_new_method_call("org.opensuse.Snapper",
422 "/org/opensuse/Snapper",
423 "org.opensuse.Snapper",
426 DEBUG(0, ("null msg\n"));
427 return NT_STATUS_NO_MEMORY;
430 /* no arguments to append */
436 static NTSTATUS snapper_conf_unpack(TALLOC_CTX *mem_ctx,
437 DBusMessageIter *iter,
438 struct snapper_conf *conf_out)
441 DBusMessageIter st_iter;
445 status = snapper_type_check(iter, DBUS_TYPE_STRUCT);
446 if (!NT_STATUS_IS_OK(status)) {
449 dbus_message_iter_recurse(iter, &st_iter);
451 status = snapper_type_check_get(&st_iter, DBUS_TYPE_STRING,
453 if (!NT_STATUS_IS_OK(status)) {
457 status = snapper_dbus_str_decode(mem_ctx, name_encoded,
459 if (!NT_STATUS_IS_OK(status)) {
463 dbus_message_iter_next(&st_iter);
464 status = snapper_type_check_get(&st_iter, DBUS_TYPE_STRING,
466 if (!NT_STATUS_IS_OK(status)) {
467 talloc_free(conf_out->name);
471 status = snapper_dbus_str_decode(mem_ctx, mnt_encoded,
473 if (!NT_STATUS_IS_OK(status)) {
474 talloc_free(conf_out->name);
478 dbus_message_iter_next(&st_iter);
479 status = snapper_dict_array_unpack(mem_ctx, &st_iter,
480 &conf_out->num_attrs,
482 if (!NT_STATUS_IS_OK(status)) {
483 talloc_free(conf_out->mnt);
484 talloc_free(conf_out->name);
491 static struct snapper_conf *snapper_conf_array_base_find(int32_t num_confs,
492 struct snapper_conf *confs,
497 for (i = 0; i < num_confs; i++) {
498 if (strcmp(confs[i].mnt, base) == 0) {
499 DEBUG(5, ("found snapper conf %s for path %s\n",
500 confs[i].name, base));
504 DEBUG(5, ("config for base %s not found\n", base));
509 static void snapper_conf_array_print(int32_t num_confs,
510 struct snapper_conf *confs)
514 for (i = 0; i < num_confs; i++) {
515 DEBUG(10, ("name: %s, mnt: %s\n",
516 confs[i].name, confs[i].mnt));
517 snapper_dict_array_print(confs[i].num_attrs, confs[i].attrs);
521 static NTSTATUS snapper_conf_array_unpack(TALLOC_CTX *mem_ctx,
522 DBusMessageIter *iter,
523 uint32_t *num_confs_out,
524 struct snapper_conf **confs_out)
528 struct snapper_conf *confs = NULL;
529 DBusMessageIter array_iter;
532 status = snapper_type_check(iter, DBUS_TYPE_ARRAY);
533 if (!NT_STATUS_IS_OK(status)) {
536 dbus_message_iter_recurse(iter, &array_iter);
539 while (dbus_message_iter_get_arg_type(&array_iter)
540 != DBUS_TYPE_INVALID) {
542 confs = talloc_realloc(mem_ctx, confs, struct snapper_conf,
547 status = snapper_conf_unpack(confs, &array_iter,
548 &confs[num_confs - 1]);
549 if (!NT_STATUS_IS_OK(status)) {
553 dbus_message_iter_next(&array_iter);
556 *num_confs_out = num_confs;
562 static NTSTATUS snapper_list_confs_unpack(TALLOC_CTX *mem_ctx,
563 DBusConnection *dconn,
564 DBusMessage *rsp_msg,
565 uint32_t *num_confs_out,
566 struct snapper_conf **confs_out)
569 DBusMessageIter iter;
572 struct snapper_conf *confs;
575 msg_type = dbus_message_get_type(rsp_msg);
576 if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
577 const char *err_str = dbus_message_get_error_name(rsp_msg);
578 DEBUG(0, ("list_confs error response: %s\n", err_str));
579 return snapper_err_ntstatus_map(err_str);
582 if (msg_type != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
583 DEBUG(0, ("unexpected list_confs ret type: %d\n",
585 return NT_STATUS_INVALID_PARAMETER;
588 sig = dbus_message_get_signature(rsp_msg);
590 || (strcmp(sig, SNAPPER_SIG_LIST_CONFS_RSP) != 0)) {
591 DEBUG(0, ("bad list confs response sig: %s, expected: %s\n",
592 (sig ? sig : "NULL"), SNAPPER_SIG_LIST_CONFS_RSP));
593 return NT_STATUS_INVALID_PARAMETER;
596 if (!dbus_message_iter_init(rsp_msg, &iter)) {
597 /* FIXME return empty? */
598 DEBUG(0, ("Message has no arguments!\n"));
599 return NT_STATUS_INVALID_PARAMETER;
602 status = snapper_conf_array_unpack(mem_ctx, &iter, &num_confs, &confs);
603 if (!NT_STATUS_IS_OK(status)) {
604 DEBUG(0, ("failed to unpack conf array\n"));
608 snapper_conf_array_print(num_confs, confs);
610 *num_confs_out = num_confs;
616 static NTSTATUS snapper_list_snaps_pack(TALLOC_CTX *mem_ctx,
618 DBusMessage **req_msg_out)
621 DBusMessageIter args;
625 msg = dbus_message_new_method_call("org.opensuse.Snapper", /* target for the method call */
626 "/org/opensuse/Snapper", /* object to call on */
627 "org.opensuse.Snapper", /* interface to call on */
628 "ListSnapshots"); /* method name */
630 DEBUG(0, ("failed to create list snaps message\n"));
631 return NT_STATUS_NO_MEMORY;
634 status = snapper_dbus_str_encode(mem_ctx, snapper_conf, &conf_encoded);
635 if (!NT_STATUS_IS_OK(status)) {
636 dbus_message_unref(msg);
640 /* append arguments */
641 dbus_message_iter_init_append(msg, &args);
642 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
644 talloc_free(conf_encoded);
645 dbus_message_unref(msg);
646 return NT_STATUS_NO_MEMORY;
654 static NTSTATUS snapper_snap_struct_unpack(TALLOC_CTX *mem_ctx,
655 DBusMessageIter *iter,
656 struct snapper_snap *snap_out)
659 DBusMessageIter st_iter;
661 char *cleanup_encoded;
663 status = snapper_type_check(iter, DBUS_TYPE_STRUCT);
664 if (!NT_STATUS_IS_OK(status)) {
667 dbus_message_iter_recurse(iter, &st_iter);
669 status = snapper_type_check_get(&st_iter, DBUS_TYPE_UINT32,
671 if (!NT_STATUS_IS_OK(status)) {
675 dbus_message_iter_next(&st_iter);
676 status = snapper_type_check_get(&st_iter, DBUS_TYPE_UINT16,
678 if (!NT_STATUS_IS_OK(status)) {
682 dbus_message_iter_next(&st_iter);
683 status = snapper_type_check_get(&st_iter, DBUS_TYPE_UINT32,
685 if (!NT_STATUS_IS_OK(status)) {
689 dbus_message_iter_next(&st_iter);
690 status = snapper_type_check_get(&st_iter, DBUS_TYPE_INT64,
692 if (!NT_STATUS_IS_OK(status)) {
696 dbus_message_iter_next(&st_iter);
697 status = snapper_type_check_get(&st_iter, DBUS_TYPE_UINT32,
698 &snap_out->creator_uid);
699 if (!NT_STATUS_IS_OK(status)) {
703 dbus_message_iter_next(&st_iter);
704 status = snapper_type_check_get(&st_iter, DBUS_TYPE_STRING,
706 if (!NT_STATUS_IS_OK(status)) {
710 status = snapper_dbus_str_decode(mem_ctx, desc_encoded,
712 if (!NT_STATUS_IS_OK(status)) {
716 dbus_message_iter_next(&st_iter);
717 status = snapper_type_check_get(&st_iter, DBUS_TYPE_STRING,
719 if (!NT_STATUS_IS_OK(status)) {
720 talloc_free(snap_out->desc);
724 status = snapper_dbus_str_decode(mem_ctx, cleanup_encoded,
726 if (!NT_STATUS_IS_OK(status)) {
727 talloc_free(snap_out->desc);
731 dbus_message_iter_next(&st_iter);
732 status = snapper_dict_array_unpack(mem_ctx, &st_iter,
733 &snap_out->num_user_data,
734 &snap_out->user_data);
735 if (!NT_STATUS_IS_OK(status)) {
736 talloc_free(snap_out->cleanup);
737 talloc_free(snap_out->desc);
744 static void snapper_snap_array_print(int32_t num_snaps,
745 struct snapper_snap *snaps)
749 for (i = 0; i < num_snaps; i++) {
750 DEBUG(10, ("id: %u, "
757 (unsigned int)snaps[i].id,
758 (unsigned int)snaps[i].type,
759 (unsigned int)snaps[i].pre_id,
760 (long int)snaps[i].time,
761 (unsigned int)snaps[i].creator_uid,
764 snapper_dict_array_print(snaps[i].num_user_data,
769 static NTSTATUS snapper_snap_array_unpack(TALLOC_CTX *mem_ctx,
770 DBusMessageIter *iter,
771 uint32_t *num_snaps_out,
772 struct snapper_snap **snaps_out)
776 struct snapper_snap *snaps = NULL;
777 DBusMessageIter array_iter;
780 status = snapper_type_check(iter, DBUS_TYPE_ARRAY);
781 if (!NT_STATUS_IS_OK(status)) {
784 dbus_message_iter_recurse(iter, &array_iter);
787 while (dbus_message_iter_get_arg_type(&array_iter)
788 != DBUS_TYPE_INVALID) {
790 snaps = talloc_realloc(mem_ctx, snaps, struct snapper_snap,
795 status = snapper_snap_struct_unpack(snaps, &array_iter,
796 &snaps[num_snaps - 1]);
797 if (!NT_STATUS_IS_OK(status)) {
801 dbus_message_iter_next(&array_iter);
804 *num_snaps_out = num_snaps;
810 static NTSTATUS snapper_list_snaps_unpack(TALLOC_CTX *mem_ctx,
811 DBusMessage *rsp_msg,
812 uint32_t *num_snaps_out,
813 struct snapper_snap **snaps_out)
816 DBusMessageIter iter;
819 struct snapper_snap *snaps;
822 msg_type = dbus_message_get_type(rsp_msg);
823 if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
824 const char *err_str = dbus_message_get_error_name(rsp_msg);
825 DEBUG(0, ("list_snaps error response: %s\n", err_str));
826 return snapper_err_ntstatus_map(err_str);
829 if (msg_type != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
830 DEBUG(0,("unexpected list_snaps ret type: %d\n",
832 return NT_STATUS_INVALID_PARAMETER;
835 sig = dbus_message_get_signature(rsp_msg);
837 || (strcmp(sig, SNAPPER_SIG_LIST_SNAPS_RSP) != 0)) {
838 DEBUG(0, ("bad list snaps response sig: %s, "
840 (sig ? sig : "NULL"),
841 SNAPPER_SIG_LIST_SNAPS_RSP));
842 return NT_STATUS_INVALID_PARAMETER;
845 /* read the parameters */
846 if (!dbus_message_iter_init(rsp_msg, &iter)) {
847 DEBUG(0, ("response has no arguments!\n"));
848 return NT_STATUS_INVALID_PARAMETER;
851 status = snapper_snap_array_unpack(mem_ctx, &iter, &num_snaps, &snaps);
852 if (!NT_STATUS_IS_OK(status)) {
853 DEBUG(0, ("failed to unpack snap array\n"));
854 return NT_STATUS_INVALID_PARAMETER;
857 snapper_snap_array_print(num_snaps, snaps);
859 *num_snaps_out = num_snaps;
865 static NTSTATUS snapper_create_snap_pack(TALLOC_CTX *mem_ctx,
866 const char *snapper_conf,
868 uint32_t num_user_data,
869 struct snapper_dict *user_data,
870 DBusMessage **req_msg_out)
873 DBusMessageIter args;
874 DBusMessageIter array_iter;
875 DBusMessageIter struct_iter;
876 const char *empty = "";
883 DEBUG(10, ("CreateSingleSnapshot: %s, %s, %s, num user %u\n",
884 snapper_conf, desc, empty, num_user_data));
886 enc_ctx = talloc_new(mem_ctx);
887 if (enc_ctx == NULL) {
888 return NT_STATUS_NO_MEMORY;
891 msg = dbus_message_new_method_call("org.opensuse.Snapper",
892 "/org/opensuse/Snapper",
893 "org.opensuse.Snapper",
894 "CreateSingleSnapshot");
896 DEBUG(0, ("failed to create req msg\n"));
897 talloc_free(enc_ctx);
898 return NT_STATUS_NO_MEMORY;
901 status = snapper_dbus_str_encode(enc_ctx, snapper_conf, &str_encoded);
902 if (!NT_STATUS_IS_OK(status)) {
903 dbus_message_unref(msg);
904 talloc_free(enc_ctx);
908 /* append arguments */
909 dbus_message_iter_init_append(msg, &args);
910 ok = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
913 dbus_message_unref(msg);
914 talloc_free(enc_ctx);
915 return NT_STATUS_NO_MEMORY;
918 status = snapper_dbus_str_encode(enc_ctx, desc, &str_encoded);
919 if (!NT_STATUS_IS_OK(status)) {
920 dbus_message_unref(msg);
921 talloc_free(enc_ctx);
925 ok = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
928 dbus_message_unref(msg);
929 talloc_free(enc_ctx);
930 return NT_STATUS_NO_MEMORY;
933 /* cleanup - no need to encode empty string */
934 ok = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
937 dbus_message_unref(msg);
938 talloc_free(enc_ctx);
939 return NT_STATUS_NO_MEMORY;
942 ok = dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY,
943 SNAPPER_SIG_STRING_DICT,
946 dbus_message_unref(msg);
947 talloc_free(enc_ctx);
948 return NT_STATUS_NO_MEMORY;
951 for (i = 0; i < num_user_data; i++) {
952 ok = dbus_message_iter_open_container(&array_iter,
953 DBUS_TYPE_DICT_ENTRY,
956 dbus_message_unref(msg);
957 talloc_free(enc_ctx);
958 return NT_STATUS_NO_MEMORY;
961 status = snapper_dbus_str_encode(enc_ctx, user_data[i].key,
963 if (!NT_STATUS_IS_OK(status)) {
964 dbus_message_unref(msg);
965 talloc_free(enc_ctx);
969 ok = dbus_message_iter_append_basic(&struct_iter,
973 dbus_message_unref(msg);
974 talloc_free(enc_ctx);
975 return NT_STATUS_NO_MEMORY;
978 status = snapper_dbus_str_encode(enc_ctx, user_data[i].val,
980 if (!NT_STATUS_IS_OK(status)) {
981 dbus_message_unref(msg);
982 talloc_free(enc_ctx);
986 ok = dbus_message_iter_append_basic(&struct_iter,
990 dbus_message_unref(msg);
991 talloc_free(enc_ctx);
992 return NT_STATUS_NO_MEMORY;
995 ok = dbus_message_iter_close_container(&array_iter, &struct_iter);
997 dbus_message_unref(msg);
998 talloc_free(enc_ctx);
999 return NT_STATUS_NO_MEMORY;
1003 ok = dbus_message_iter_close_container(&args, &array_iter);
1005 dbus_message_unref(msg);
1006 talloc_free(enc_ctx);
1007 return NT_STATUS_NO_MEMORY;
1012 return NT_STATUS_OK;
1015 static NTSTATUS snapper_create_snap_unpack(DBusConnection *conn,
1016 DBusMessage *rsp_msg,
1017 uint32_t *snap_id_out)
1020 DBusMessageIter iter;
1025 msg_type = dbus_message_get_type(rsp_msg);
1026 if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
1027 const char *err_str = dbus_message_get_error_name(rsp_msg);
1028 DEBUG(0, ("create snap error response: %s, euid %d egid %d\n",
1029 err_str, geteuid(), getegid()));
1030 return snapper_err_ntstatus_map(err_str);
1033 if (msg_type != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
1034 DEBUG(0, ("unexpected create snap ret type: %d\n",
1036 return NT_STATUS_INVALID_PARAMETER;
1039 sig = dbus_message_get_signature(rsp_msg);
1041 || (strcmp(sig, SNAPPER_SIG_CREATE_SNAP_RSP) != 0)) {
1042 DEBUG(0, ("bad create snap response sig: %s, expected: %s\n",
1043 (sig ? sig : "NULL"), SNAPPER_SIG_CREATE_SNAP_RSP));
1044 return NT_STATUS_INVALID_PARAMETER;
1047 /* read the parameters */
1048 if (!dbus_message_iter_init(rsp_msg, &iter)) {
1049 DEBUG(0, ("response has no arguments!\n"));
1050 return NT_STATUS_INVALID_PARAMETER;
1053 status = snapper_type_check_get(&iter, DBUS_TYPE_UINT32, &snap_id);
1054 if (!NT_STATUS_IS_OK(status)) {
1057 *snap_id_out = snap_id;
1059 return NT_STATUS_OK;
1062 static NTSTATUS snapper_del_snap_pack(TALLOC_CTX *mem_ctx,
1063 const char *snapper_conf,
1065 DBusMessage **req_msg_out)
1068 DBusMessageIter args;
1069 DBusMessageIter array_iter;
1074 msg = dbus_message_new_method_call("org.opensuse.Snapper",
1075 "/org/opensuse/Snapper",
1076 "org.opensuse.Snapper",
1079 DEBUG(0, ("failed to create req msg\n"));
1080 return NT_STATUS_NO_MEMORY;
1083 status = snapper_dbus_str_encode(mem_ctx, snapper_conf, &conf_encoded);
1084 if (!NT_STATUS_IS_OK(status)) {
1085 dbus_message_unref(msg);
1089 /* append arguments */
1090 dbus_message_iter_init_append(msg, &args);
1091 ok = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
1094 talloc_free(conf_encoded);
1095 dbus_message_unref(msg);
1096 return NT_STATUS_NO_MEMORY;
1099 ok = dbus_message_iter_open_container(&args, DBUS_TYPE_ARRAY,
1100 DBUS_TYPE_UINT32_AS_STRING,
1103 talloc_free(conf_encoded);
1104 dbus_message_unref(msg);
1105 return NT_STATUS_NO_MEMORY;
1108 ok = dbus_message_iter_append_basic(&array_iter,
1112 talloc_free(conf_encoded);
1113 dbus_message_unref(msg);
1114 return NT_STATUS_NO_MEMORY;
1117 dbus_message_iter_close_container(&args, &array_iter);
1120 return NT_STATUS_OK;
1123 static NTSTATUS snapper_del_snap_unpack(DBusConnection *conn,
1124 DBusMessage *rsp_msg)
1129 msg_type = dbus_message_get_type(rsp_msg);
1130 if (msg_type == DBUS_MESSAGE_TYPE_ERROR) {
1131 const char *err_str = dbus_message_get_error_name(rsp_msg);
1132 DEBUG(0, ("del snap error response: %s\n", err_str));
1133 return snapper_err_ntstatus_map(err_str);
1136 if (msg_type != DBUS_MESSAGE_TYPE_METHOD_RETURN) {
1137 DEBUG(0, ("unexpected del snap ret type: %d\n",
1139 return NT_STATUS_INVALID_PARAMETER;
1142 sig = dbus_message_get_signature(rsp_msg);
1144 || (strcmp(sig, SNAPPER_SIG_DEL_SNAPS_RSP) != 0)) {
1145 DEBUG(0, ("bad create snap response sig: %s, expected: %s\n",
1146 (sig ? sig : "NULL"), SNAPPER_SIG_DEL_SNAPS_RSP));
1147 return NT_STATUS_INVALID_PARAMETER;
1150 /* no parameters in response */
1152 return NT_STATUS_OK;
1155 static NTSTATUS snapper_list_snaps_at_time_pack(TALLOC_CTX *mem_ctx,
1156 const char *snapper_conf,
1159 DBusMessage **req_msg_out)
1162 DBusMessageIter args;
1166 msg = dbus_message_new_method_call("org.opensuse.Snapper",
1167 "/org/opensuse/Snapper",
1168 "org.opensuse.Snapper",
1169 "ListSnapshotsAtTime");
1171 DEBUG(0, ("failed to create list snaps message\n"));
1172 return NT_STATUS_NO_MEMORY;
1175 status = snapper_dbus_str_encode(mem_ctx, snapper_conf, &conf_encoded);
1176 if (!NT_STATUS_IS_OK(status)) {
1177 dbus_message_unref(msg);
1181 dbus_message_iter_init_append(msg, &args);
1182 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING,
1184 talloc_free(conf_encoded);
1185 dbus_message_unref(msg);
1186 return NT_STATUS_NO_MEMORY;
1189 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT64,
1191 talloc_free(conf_encoded);
1192 dbus_message_unref(msg);
1193 return NT_STATUS_NO_MEMORY;
1196 if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_INT64,
1198 talloc_free(conf_encoded);
1199 dbus_message_unref(msg);
1200 return NT_STATUS_NO_MEMORY;
1205 return NT_STATUS_OK;
1207 /* no snapper_list_snaps_at_time_unpack, use snapper_list_snaps_unpack */
1210 * Determine the snapper snapshot id given a path.
1211 * Ideally this should be determined via a lookup.
1213 static NTSTATUS snapper_snap_path_to_id(TALLOC_CTX *mem_ctx,
1214 const char *snap_path,
1215 uint32_t *snap_id_out)
1222 path_dup = talloc_strdup(mem_ctx, snap_path);
1223 if (path_dup == NULL) {
1224 return NT_STATUS_NO_MEMORY;
1227 /* trim trailing '/' */
1228 str_idx = path_dup + strlen(path_dup) - 1;
1229 while (*str_idx == '/') {
1234 str_idx = strrchr(path_dup, '/');
1235 if ((str_idx == NULL)
1236 || (strcmp(str_idx + 1, "snapshot") != 0)) {
1237 talloc_free(path_dup);
1238 return NT_STATUS_INVALID_PARAMETER;
1241 while (*str_idx == '/') {
1246 str_idx = strrchr(path_dup, '/');
1247 if (str_idx == NULL) {
1248 talloc_free(path_dup);
1249 return NT_STATUS_INVALID_PARAMETER;
1253 snap_id = smb_strtoul(str_idx, NULL, 10, &error, SMB_STR_STANDARD);
1255 talloc_free(path_dup);
1256 return NT_STATUS_INVALID_PARAMETER;
1259 talloc_free(path_dup);
1260 *snap_id_out = snap_id;
1261 return NT_STATUS_OK;
1265 * Determine the snapper snapshot path given an id and base.
1266 * Ideally this should be determined via a lookup.
1268 static NTSTATUS snapper_snap_id_to_path(TALLOC_CTX *mem_ctx,
1269 const char *base_path,
1271 char **snap_path_out)
1275 snap_path = talloc_asprintf(mem_ctx, "%s/.snapshots/%u/snapshot",
1276 base_path, snap_id);
1277 if (snap_path == NULL) {
1278 return NT_STATUS_NO_MEMORY;
1281 *snap_path_out = snap_path;
1282 return NT_STATUS_OK;
1285 static NTSTATUS snapper_get_conf_call(TALLOC_CTX *mem_ctx,
1286 DBusConnection *dconn,
1288 char **conf_name_out,
1289 char **base_path_out)
1292 DBusMessage *req_msg;
1293 DBusMessage *rsp_msg;
1294 uint32_t num_confs = 0;
1295 struct snapper_conf *confs = NULL;
1296 struct snapper_conf *conf;
1300 status = snapper_list_confs_pack(&req_msg);
1301 if (!NT_STATUS_IS_OK(status)) {
1305 status = snapper_dbus_msg_xchng(dconn, req_msg, &rsp_msg);
1306 if (!NT_STATUS_IS_OK(status)) {
1310 status = snapper_list_confs_unpack(mem_ctx, dconn, rsp_msg,
1311 &num_confs, &confs);
1312 if (!NT_STATUS_IS_OK(status)) {
1317 * for now we only support shares where the path directly corresponds
1318 * to a snapper configuration.
1320 conf = snapper_conf_array_base_find(num_confs, confs,
1323 status = NT_STATUS_NOT_SUPPORTED;
1324 goto err_array_free;
1327 conf_name = talloc_strdup(mem_ctx, conf->name);
1328 if (conf_name == NULL) {
1329 status = NT_STATUS_NO_MEMORY;
1330 goto err_array_free;
1332 base_path = talloc_strdup(mem_ctx, conf->mnt);
1333 if (base_path == NULL) {
1334 status = NT_STATUS_NO_MEMORY;
1335 goto err_conf_name_free;
1339 dbus_message_unref(rsp_msg);
1340 dbus_message_unref(req_msg);
1342 *conf_name_out = conf_name;
1343 *base_path_out = base_path;
1345 return NT_STATUS_OK;
1348 talloc_free(conf_name);
1352 dbus_message_unref(rsp_msg);
1354 dbus_message_unref(req_msg);
1360 * Check whether a path can be shadow copied. Return the base volume, allowing
1361 * the caller to determine if multiple paths lie on the same base volume.
1363 static NTSTATUS snapper_snap_check_path(struct vfs_handle_struct *handle,
1364 TALLOC_CTX *mem_ctx,
1365 const char *service_path,
1369 DBusConnection *dconn;
1373 dconn = snapper_dbus_conn_create();
1374 if (dconn == NULL) {
1375 return NT_STATUS_UNSUCCESSFUL;
1378 status = snapper_get_conf_call(mem_ctx, dconn, service_path,
1379 &conf_name, &base_path);
1380 if (!NT_STATUS_IS_OK(status)) {
1381 goto err_conn_close;
1384 talloc_free(conf_name);
1385 *base_volume = base_path;
1386 snapper_dbus_conn_destroy(dconn);
1388 return NT_STATUS_OK;
1391 snapper_dbus_conn_destroy(dconn);
1395 static NTSTATUS snapper_create_snap_call(TALLOC_CTX *mem_ctx,
1396 DBusConnection *dconn,
1397 const char *conf_name,
1398 const char *base_path,
1399 const char *snap_desc,
1400 uint32_t num_user_data,
1401 struct snapper_dict *user_data,
1402 char **snap_path_out)
1405 DBusMessage *req_msg;
1406 DBusMessage *rsp_msg;
1407 uint32_t snap_id = 0;
1410 status = snapper_create_snap_pack(mem_ctx,
1416 if (!NT_STATUS_IS_OK(status)) {
1420 status = snapper_dbus_msg_xchng(dconn, req_msg, &rsp_msg);
1421 if (!NT_STATUS_IS_OK(status)) {
1425 status = snapper_create_snap_unpack(dconn, rsp_msg, &snap_id);
1426 if (!NT_STATUS_IS_OK(status)) {
1430 status = snapper_snap_id_to_path(mem_ctx, base_path, snap_id,
1432 if (!NT_STATUS_IS_OK(status)) {
1436 dbus_message_unref(rsp_msg);
1437 dbus_message_unref(req_msg);
1439 DEBUG(6, ("created new snapshot %u at %s\n", snap_id, snap_path));
1440 *snap_path_out = snap_path;
1442 return NT_STATUS_OK;
1445 dbus_message_unref(rsp_msg);
1447 dbus_message_unref(req_msg);
1452 static NTSTATUS snapper_snap_create(struct vfs_handle_struct *handle,
1453 TALLOC_CTX *mem_ctx,
1454 const char *base_volume,
1460 DBusConnection *dconn;
1464 char *snap_path = NULL;
1465 TALLOC_CTX *tmp_ctx;
1467 tmp_ctx = talloc_new(mem_ctx);
1468 if (tmp_ctx == NULL) {
1469 return NT_STATUS_NO_MEMORY;
1472 dconn = snapper_dbus_conn_create();
1473 if (dconn == NULL) {
1474 talloc_free(tmp_ctx);
1475 return NT_STATUS_UNSUCCESSFUL;
1478 status = snapper_get_conf_call(tmp_ctx, dconn, base_volume,
1479 &conf_name, &base_path);
1480 if (!NT_STATUS_IS_OK(status)) {
1481 snapper_dbus_conn_destroy(dconn);
1482 talloc_free(tmp_ctx);
1486 status = snapper_create_snap_call(tmp_ctx, dconn,
1487 conf_name, base_path,
1488 "Snapshot created by Samba",
1491 if (!NT_STATUS_IS_OK(status)) {
1492 snapper_dbus_conn_destroy(dconn);
1493 talloc_free(tmp_ctx);
1497 snapper_dbus_conn_destroy(dconn);
1498 *_base_path = talloc_steal(mem_ctx, base_path);
1499 *_snap_path = talloc_steal(mem_ctx, snap_path);
1500 talloc_free(tmp_ctx);
1502 return NT_STATUS_OK;
1505 static NTSTATUS snapper_delete_snap_call(TALLOC_CTX *mem_ctx,
1506 DBusConnection *dconn,
1507 const char *conf_name,
1511 DBusMessage *req_msg = NULL;
1512 DBusMessage *rsp_msg;
1514 status = snapper_del_snap_pack(mem_ctx, conf_name, snap_id, &req_msg);
1515 if (!NT_STATUS_IS_OK(status)) {
1519 status = snapper_dbus_msg_xchng(dconn, req_msg, &rsp_msg);
1520 if (!NT_STATUS_IS_OK(status)) {
1524 status = snapper_del_snap_unpack(dconn, rsp_msg);
1525 if (!NT_STATUS_IS_OK(status)) {
1529 dbus_message_unref(rsp_msg);
1530 dbus_message_unref(req_msg);
1532 DEBUG(6, ("deleted snapshot %u\n", snap_id));
1534 return NT_STATUS_OK;
1537 dbus_message_unref(rsp_msg);
1539 dbus_message_unref(req_msg);
1544 static NTSTATUS snapper_snap_delete(struct vfs_handle_struct *handle,
1545 TALLOC_CTX *mem_ctx,
1549 DBusConnection *dconn;
1552 char *snap_base_path;
1554 TALLOC_CTX *tmp_ctx;
1556 tmp_ctx = talloc_new(mem_ctx);
1557 if (tmp_ctx == NULL) {
1558 return NT_STATUS_NO_MEMORY;
1561 dconn = snapper_dbus_conn_create();
1562 if (dconn == NULL) {
1563 talloc_free(tmp_ctx);
1564 return NT_STATUS_UNSUCCESSFUL;
1567 status = snapper_get_conf_call(tmp_ctx, dconn, base_path,
1568 &conf_name, &snap_base_path);
1569 if (!NT_STATUS_IS_OK(status)) {
1570 snapper_dbus_conn_destroy(dconn);
1571 talloc_free(tmp_ctx);
1575 status = snapper_snap_path_to_id(tmp_ctx, snap_path, &snap_id);
1576 if (!NT_STATUS_IS_OK(status)) {
1577 snapper_dbus_conn_destroy(dconn);
1578 talloc_free(tmp_ctx);
1582 status = snapper_delete_snap_call(tmp_ctx, dconn, conf_name, snap_id);
1583 if (!NT_STATUS_IS_OK(status)) {
1584 snapper_dbus_conn_destroy(dconn);
1585 talloc_free(tmp_ctx);
1589 snapper_dbus_conn_destroy(dconn);
1590 talloc_free(tmp_ctx);
1592 return NT_STATUS_OK;
1595 /* sc_data used as parent talloc context for all labels */
1596 static int snapper_get_shadow_copy_data(struct vfs_handle_struct *handle,
1597 struct files_struct *fsp,
1598 struct shadow_copy_data *sc_data,
1601 DBusConnection *dconn;
1602 TALLOC_CTX *tmp_ctx;
1606 DBusMessage *req_msg = NULL;
1607 DBusMessage *rsp_msg;
1609 struct snapper_snap *snaps;
1613 tmp_ctx = talloc_new(sc_data);
1614 if (tmp_ctx == NULL) {
1615 status = NT_STATUS_NO_MEMORY;
1619 dconn = snapper_dbus_conn_create();
1620 if (dconn == NULL) {
1621 status = NT_STATUS_UNSUCCESSFUL;
1622 goto err_mem_ctx_free;
1625 if (fsp->conn->connectpath == NULL) {
1626 status = NT_STATUS_INVALID_PARAMETER;
1630 status = snapper_get_conf_call(tmp_ctx, dconn,
1631 fsp->conn->connectpath,
1634 if (!NT_STATUS_IS_OK(status)) {
1638 status = snapper_list_snaps_pack(tmp_ctx, conf_name, &req_msg);
1639 if (!NT_STATUS_IS_OK(status)) {
1643 status = snapper_dbus_msg_xchng(dconn, req_msg, &rsp_msg);
1644 if (!NT_STATUS_IS_OK(status)) {
1648 status = snapper_list_snaps_unpack(tmp_ctx, rsp_msg,
1649 &num_snaps, &snaps);
1650 if (!NT_STATUS_IS_OK(status)) {
1653 /* we should always get at least one snapshot (current) */
1654 if (num_snaps == 0) {
1655 DEBUG(1, ("zero snapshots in snap list response\n"));
1656 status = NT_STATUS_UNSUCCESSFUL;
1660 /* subtract 1, (current) snapshot is not returned */
1661 sc_data->num_volumes = num_snaps - 1;
1662 sc_data->labels = NULL;
1664 if ((labels == false) || (sc_data->num_volumes == 0)) {
1665 /* tokens need not be added to the labels array */
1669 sc_data->labels = talloc_array(sc_data, SHADOW_COPY_LABEL,
1670 sc_data->num_volumes);
1671 if (sc_data->labels == NULL) {
1672 status = NT_STATUS_NO_MEMORY;
1676 /* start at end for decending order, do not include 0 (current) */
1678 for (i = num_snaps - 1; i > 0; i--) {
1679 char *lbl = sc_data->labels[lbl_off++];
1680 struct tm gmt_snap_time;
1684 tm_ret = gmtime_r((time_t *)&snaps[i].time, &gmt_snap_time);
1685 if (tm_ret == NULL) {
1686 status = NT_STATUS_UNSUCCESSFUL;
1687 goto err_labels_free;
1689 str_sz = strftime(lbl, sizeof(SHADOW_COPY_LABEL),
1690 "@GMT-%Y.%m.%d-%H.%M.%S", &gmt_snap_time);
1692 status = NT_STATUS_UNSUCCESSFUL;
1693 goto err_labels_free;
1698 talloc_free(tmp_ctx);
1699 dbus_message_unref(rsp_msg);
1700 dbus_message_unref(req_msg);
1701 snapper_dbus_conn_destroy(dconn);
1706 TALLOC_FREE(sc_data->labels);
1708 dbus_message_unref(rsp_msg);
1710 dbus_message_unref(req_msg);
1712 snapper_dbus_conn_destroy(dconn);
1714 talloc_free(tmp_ctx);
1716 errno = map_errno_from_nt_status(status);
1720 static bool snapper_gmt_strip_snapshot(TALLOC_CTX *mem_ctx,
1721 struct vfs_handle_struct *handle,
1731 size_t rest_len, dst_len;
1732 ptrdiff_t len_before_gmt;
1734 p = strstr_m(name, "@GMT-");
1738 if ((p > name) && (p[-1] != '/')) {
1741 len_before_gmt = p - name;
1742 q = strptime(p, GMT_FORMAT, &tm);
1747 timestamp = timegm(&tm);
1748 if (timestamp == (time_t)-1) {
1753 * The name consists of only the GMT token or the GMT
1754 * token is at the end of the path. XP seems to send
1755 * @GMT- at the end under certain circumstances even
1756 * with a path prefix.
1758 if (pstripped != NULL) {
1759 if (len_before_gmt > 0) {
1761 * There is a slash before
1762 * the @GMT-. Remove it.
1764 len_before_gmt -= 1;
1766 stripped = talloc_strndup(mem_ctx, name,
1768 if (stripped == NULL) {
1771 *pstripped = stripped;
1773 *ptimestamp = timestamp;
1778 * It is not a complete path component, i.e. the path
1779 * component continues after the gmt-token.
1785 rest_len = strlen(q);
1786 dst_len = len_before_gmt + rest_len;
1788 if (pstripped != NULL) {
1789 stripped = talloc_array(mem_ctx, char, dst_len+1);
1790 if (stripped == NULL) {
1795 memcpy(stripped, name, len_before_gmt);
1798 memcpy(stripped + len_before_gmt, q, rest_len);
1800 stripped[dst_len] = '\0';
1801 *pstripped = stripped;
1803 *ptimestamp = timestamp;
1810 static NTSTATUS snapper_get_snap_at_time_call(TALLOC_CTX *mem_ctx,
1811 DBusConnection *dconn,
1812 const char *conf_name,
1813 const char *base_path,
1815 char **snap_path_out)
1818 DBusMessage *req_msg = NULL;
1819 DBusMessage *rsp_msg;
1821 struct snapper_snap *snaps;
1824 status = snapper_list_snaps_at_time_pack(mem_ctx,
1829 if (!NT_STATUS_IS_OK(status)) {
1833 status = snapper_dbus_msg_xchng(dconn, req_msg, &rsp_msg);
1834 if (!NT_STATUS_IS_OK(status)) {
1838 status = snapper_list_snaps_unpack(mem_ctx, rsp_msg,
1839 &num_snaps, &snaps);
1840 if (!NT_STATUS_IS_OK(status)) {
1844 if (num_snaps == 0) {
1845 DEBUG(4, ("no snapshots found with time: %lu\n",
1846 (unsigned long)snaptime));
1847 status = NT_STATUS_INVALID_PARAMETER;
1848 goto err_snap_array_free;
1849 } else if (num_snaps > 0) {
1850 DEBUG(4, ("got %u snapshots for single time %lu, using top\n",
1851 num_snaps, (unsigned long)snaptime));
1854 status = snapper_snap_id_to_path(mem_ctx, base_path, snaps[0].id,
1856 if (!NT_STATUS_IS_OK(status)) {
1857 goto err_snap_array_free;
1860 *snap_path_out = snap_path;
1861 err_snap_array_free:
1864 dbus_message_unref(rsp_msg);
1866 dbus_message_unref(req_msg);
1871 static NTSTATUS snapper_snap_path_expand(struct connection_struct *conn,
1872 TALLOC_CTX *mem_ctx,
1874 char **snap_dir_out)
1876 DBusConnection *dconn;
1880 char *snap_path = NULL;
1882 dconn = snapper_dbus_conn_create();
1883 if (dconn == NULL) {
1884 status = NT_STATUS_UNSUCCESSFUL;
1888 if (conn->connectpath == NULL) {
1889 status = NT_STATUS_INVALID_PARAMETER;
1893 status = snapper_get_conf_call(mem_ctx, dconn,
1897 if (!NT_STATUS_IS_OK(status)) {
1901 status = snapper_get_snap_at_time_call(mem_ctx, dconn,
1902 conf_name, base_path, snap_time,
1904 if (!NT_STATUS_IS_OK(status)) {
1905 goto err_conf_name_free;
1908 /* confirm snapshot path is nested under base path */
1909 if (strncmp(snap_path, base_path, strlen(base_path)) != 0) {
1910 status = NT_STATUS_INVALID_PARAMETER;
1911 goto err_snap_path_free;
1914 talloc_free(conf_name);
1915 talloc_free(base_path);
1916 snapper_dbus_conn_destroy(dconn);
1917 *snap_dir_out = snap_path;
1919 return NT_STATUS_OK;
1922 talloc_free(snap_path);
1924 talloc_free(conf_name);
1925 talloc_free(base_path);
1927 snapper_dbus_conn_destroy(dconn);
1932 static char *snapper_gmt_convert(TALLOC_CTX *mem_ctx,
1933 struct vfs_handle_struct *handle,
1934 const char *name, time_t timestamp)
1936 char *snap_path = NULL;
1941 status = snapper_snap_path_expand(handle->conn, mem_ctx, timestamp,
1943 if (!NT_STATUS_IS_OK(status)) {
1944 errno = map_errno_from_nt_status(status);
1948 path = talloc_asprintf(mem_ctx, "%s/%s", snap_path, name);
1951 goto err_snap_path_free;
1954 DEBUG(10, ("converted %s/%s @ time to %s\n",
1955 handle->conn->connectpath, name, path));
1959 saved_errno = errno;
1960 talloc_free(snap_path);
1961 errno = saved_errno;
1966 static DIR *snapper_gmt_opendir(vfs_handle_struct *handle,
1967 const struct smb_filename *smb_fname,
1976 struct smb_filename *conv_smb_fname = NULL;
1978 if (!snapper_gmt_strip_snapshot(talloc_tos(),
1980 smb_fname->base_name,
1985 if (timestamp == 0) {
1986 return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
1988 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
1989 TALLOC_FREE(stripped);
1993 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
1998 if (conv_smb_fname == NULL) {
2004 ret = SMB_VFS_NEXT_OPENDIR(handle, conv_smb_fname, mask, attr);
2005 saved_errno = errno;
2007 TALLOC_FREE(conv_smb_fname);
2008 errno = saved_errno;
2012 static int snapper_gmt_renameat(vfs_handle_struct *handle,
2013 files_struct *srcfsp,
2014 const struct smb_filename *smb_fname_src,
2015 files_struct *dstfsp,
2016 const struct smb_filename *smb_fname_dst)
2018 time_t timestamp_src, timestamp_dst;
2020 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2021 smb_fname_src->base_name,
2022 ×tamp_src, NULL)) {
2025 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2026 smb_fname_dst->base_name,
2027 ×tamp_dst, NULL)) {
2030 if (timestamp_src != 0) {
2034 if (timestamp_dst != 0) {
2038 return SMB_VFS_NEXT_RENAMEAT(handle,
2046 static int snapper_gmt_symlink(vfs_handle_struct *handle,
2047 const char *link_contents,
2048 const struct smb_filename *new_smb_fname)
2050 time_t timestamp_old = 0;
2051 time_t timestamp_new = 0;
2053 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2060 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2062 new_smb_fname->base_name,
2067 if ((timestamp_old != 0) || (timestamp_new != 0)) {
2071 return SMB_VFS_NEXT_SYMLINK(handle, link_contents, new_smb_fname);
2074 static int snapper_gmt_linkat(vfs_handle_struct *handle,
2075 files_struct *srcfsp,
2076 const struct smb_filename *old_smb_fname,
2077 files_struct *dstfsp,
2078 const struct smb_filename *new_smb_fname,
2081 time_t timestamp_old = 0;
2082 time_t timestamp_new = 0;
2084 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2086 old_smb_fname->base_name,
2091 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2093 new_smb_fname->base_name,
2098 if ((timestamp_old != 0) || (timestamp_new != 0)) {
2102 return SMB_VFS_NEXT_LINKAT(handle,
2110 static int snapper_gmt_stat(vfs_handle_struct *handle,
2111 struct smb_filename *smb_fname)
2114 char *stripped, *tmp;
2115 int ret, saved_errno;
2117 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2118 smb_fname->base_name,
2119 ×tamp, &stripped)) {
2122 if (timestamp == 0) {
2123 return SMB_VFS_NEXT_STAT(handle, smb_fname);
2126 tmp = smb_fname->base_name;
2127 smb_fname->base_name = snapper_gmt_convert(talloc_tos(), handle,
2128 stripped, timestamp);
2129 TALLOC_FREE(stripped);
2131 if (smb_fname->base_name == NULL) {
2132 smb_fname->base_name = tmp;
2136 ret = SMB_VFS_NEXT_STAT(handle, smb_fname);
2137 saved_errno = errno;
2139 TALLOC_FREE(smb_fname->base_name);
2140 smb_fname->base_name = tmp;
2142 errno = saved_errno;
2146 static int snapper_gmt_lstat(vfs_handle_struct *handle,
2147 struct smb_filename *smb_fname)
2150 char *stripped, *tmp;
2151 int ret, saved_errno;
2153 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2154 smb_fname->base_name,
2155 ×tamp, &stripped)) {
2158 if (timestamp == 0) {
2159 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
2162 tmp = smb_fname->base_name;
2163 smb_fname->base_name = snapper_gmt_convert(talloc_tos(), handle,
2164 stripped, timestamp);
2165 TALLOC_FREE(stripped);
2167 if (smb_fname->base_name == NULL) {
2168 smb_fname->base_name = tmp;
2172 ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
2173 saved_errno = errno;
2175 TALLOC_FREE(smb_fname->base_name);
2176 smb_fname->base_name = tmp;
2178 errno = saved_errno;
2182 static int snapper_gmt_open(vfs_handle_struct *handle,
2183 struct smb_filename *smb_fname, files_struct *fsp,
2184 int flags, mode_t mode)
2187 char *stripped, *tmp;
2188 int ret, saved_errno;
2190 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2191 smb_fname->base_name,
2192 ×tamp, &stripped)) {
2195 if (timestamp == 0) {
2196 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2199 tmp = smb_fname->base_name;
2200 smb_fname->base_name = snapper_gmt_convert(talloc_tos(), handle,
2201 stripped, timestamp);
2202 TALLOC_FREE(stripped);
2204 if (smb_fname->base_name == NULL) {
2205 smb_fname->base_name = tmp;
2209 ret = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2210 saved_errno = errno;
2212 TALLOC_FREE(smb_fname->base_name);
2213 smb_fname->base_name = tmp;
2215 errno = saved_errno;
2219 static int snapper_gmt_unlink(vfs_handle_struct *handle,
2220 const struct smb_filename *smb_fname)
2222 time_t timestamp = 0;
2224 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2225 smb_fname->base_name,
2226 ×tamp, NULL)) {
2229 if (timestamp != 0) {
2233 return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
2236 static int snapper_gmt_chmod(vfs_handle_struct *handle,
2237 const struct smb_filename *smb_fname,
2240 time_t timestamp = 0;
2242 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2244 smb_fname->base_name,
2249 if (timestamp != 0) {
2253 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
2256 static int snapper_gmt_chown(vfs_handle_struct *handle,
2257 const struct smb_filename *smb_fname,
2261 time_t timestamp = 0;
2263 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2265 smb_fname->base_name,
2270 if (timestamp != 0) {
2274 return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
2277 static int snapper_gmt_chdir(vfs_handle_struct *handle,
2278 const struct smb_filename *smb_fname)
2280 time_t timestamp = 0;
2281 char *stripped = NULL;
2283 int saved_errno = 0;
2285 struct smb_filename *conv_smb_fname = NULL;
2287 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2289 smb_fname->base_name,
2294 if (timestamp == 0) {
2295 return SMB_VFS_NEXT_CHDIR(handle, smb_fname);
2297 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2298 TALLOC_FREE(stripped);
2302 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2307 if (conv_smb_fname == NULL) {
2312 ret = SMB_VFS_NEXT_CHDIR(handle, conv_smb_fname);
2314 saved_errno = errno;
2317 TALLOC_FREE(conv_smb_fname);
2318 if (saved_errno != 0) {
2319 errno = saved_errno;
2324 static int snapper_gmt_ntimes(vfs_handle_struct *handle,
2325 const struct smb_filename *smb_fname,
2326 struct smb_file_time *ft)
2328 time_t timestamp = 0;
2330 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2331 smb_fname->base_name,
2332 ×tamp, NULL)) {
2335 if (timestamp != 0) {
2339 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
2342 static int snapper_gmt_readlink(vfs_handle_struct *handle,
2343 const struct smb_filename *smb_fname,
2347 time_t timestamp = 0;
2348 char *stripped = NULL;
2350 int saved_errno = 0;
2351 struct smb_filename *conv = NULL;
2353 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2354 smb_fname->base_name,
2355 ×tamp, &stripped)) {
2358 if (timestamp == 0) {
2359 return SMB_VFS_NEXT_READLINK(handle, smb_fname, buf, bufsiz);
2361 conv = cp_smb_filename(talloc_tos(), smb_fname);
2363 TALLOC_FREE(stripped);
2367 conv->base_name = snapper_gmt_convert(conv, handle,
2368 stripped, timestamp);
2369 TALLOC_FREE(stripped);
2370 if (conv->base_name == NULL) {
2373 ret = SMB_VFS_NEXT_READLINK(handle, conv, buf, bufsiz);
2375 saved_errno = errno;
2378 if (saved_errno != 0) {
2379 errno = saved_errno;
2384 static int snapper_gmt_readlinkat(vfs_handle_struct *handle,
2385 files_struct *dirfsp,
2386 const struct smb_filename *smb_fname,
2390 time_t timestamp = 0;
2391 char *stripped = NULL;
2393 int saved_errno = 0;
2394 struct smb_filename *conv = NULL;
2396 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2397 smb_fname->base_name,
2398 ×tamp, &stripped)) {
2401 if (timestamp == 0) {
2402 return SMB_VFS_NEXT_READLINKAT(handle,
2408 conv = cp_smb_filename(talloc_tos(), smb_fname);
2410 TALLOC_FREE(stripped);
2414 conv->base_name = snapper_gmt_convert(conv, handle,
2415 stripped, timestamp);
2416 TALLOC_FREE(stripped);
2417 if (conv->base_name == NULL) {
2420 ret = SMB_VFS_NEXT_READLINKAT(handle,
2426 saved_errno = errno;
2429 if (saved_errno != 0) {
2430 errno = saved_errno;
2435 static int snapper_gmt_mknodat(vfs_handle_struct *handle,
2436 files_struct *dirfsp,
2437 const struct smb_filename *smb_fname,
2441 time_t timestamp = (time_t)0;
2443 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2444 smb_fname->base_name,
2445 ×tamp, NULL)) {
2448 if (timestamp != 0) {
2452 return SMB_VFS_NEXT_MKNODAT(handle,
2459 static struct smb_filename *snapper_gmt_realpath(vfs_handle_struct *handle,
2461 const struct smb_filename *smb_fname)
2463 time_t timestamp = 0;
2464 char *stripped = NULL;
2465 struct smb_filename *result_fname = NULL;
2466 struct smb_filename *conv_smb_fname = NULL;
2467 int saved_errno = 0;
2469 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2470 smb_fname->base_name,
2471 ×tamp, &stripped)) {
2474 if (timestamp == 0) {
2475 return SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
2478 conv_smb_fname = cp_smb_filename(talloc_tos(), smb_fname);
2479 if (conv_smb_fname == NULL) {
2482 conv_smb_fname->base_name = snapper_gmt_convert(conv_smb_fname, handle,
2483 stripped, timestamp);
2484 if (conv_smb_fname->base_name == NULL) {
2488 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, conv_smb_fname);
2491 if (result_fname == NULL) {
2492 saved_errno = errno;
2494 TALLOC_FREE(conv_smb_fname);
2495 TALLOC_FREE(stripped);
2496 if (saved_errno != 0) {
2497 errno = saved_errno;
2499 return result_fname;
2502 static NTSTATUS snapper_gmt_fget_nt_acl(vfs_handle_struct *handle,
2503 struct files_struct *fsp,
2504 uint32_t security_info,
2505 TALLOC_CTX *mem_ctx,
2506 struct security_descriptor **ppdesc)
2512 struct smb_filename *smb_fname = NULL;
2514 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2515 fsp->fsp_name->base_name,
2516 ×tamp, &stripped)) {
2517 return map_nt_error_from_unix(errno);
2519 if (timestamp == 0) {
2520 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
2524 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2525 TALLOC_FREE(stripped);
2527 return map_nt_error_from_unix(errno);
2530 smb_fname = synthetic_smb_fname(talloc_tos(),
2534 fsp->fsp_name->flags);
2536 if (smb_fname == NULL) {
2537 return NT_STATUS_NO_MEMORY;
2540 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2542 TALLOC_FREE(smb_fname);
2546 static NTSTATUS snapper_gmt_get_nt_acl(vfs_handle_struct *handle,
2547 const struct smb_filename *fname,
2548 uint32_t security_info,
2549 TALLOC_CTX *mem_ctx,
2550 struct security_descriptor **ppdesc)
2556 struct smb_filename *smb_fname = NULL;
2558 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname->base_name,
2559 ×tamp, &stripped)) {
2560 return map_nt_error_from_unix(errno);
2562 if (timestamp == 0) {
2563 return SMB_VFS_NEXT_GET_NT_ACL(handle, fname, security_info,
2566 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2567 TALLOC_FREE(stripped);
2569 return map_nt_error_from_unix(errno);
2571 smb_fname = synthetic_smb_fname(talloc_tos(),
2577 if (smb_fname == NULL) {
2578 return NT_STATUS_NO_MEMORY;
2581 status = SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname, security_info,
2583 TALLOC_FREE(smb_fname);
2587 static int snapper_gmt_mkdir(vfs_handle_struct *handle,
2588 const struct smb_filename *fname,
2591 time_t timestamp = 0;
2593 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname->base_name,
2594 ×tamp, NULL)) {
2597 if (timestamp != 0) {
2601 return SMB_VFS_NEXT_MKDIR(handle, fname, mode);
2604 static int snapper_gmt_rmdir(vfs_handle_struct *handle,
2605 const struct smb_filename *fname)
2607 time_t timestamp = 0;
2609 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, fname->base_name,
2610 ×tamp, NULL)) {
2613 if (timestamp != 0) {
2617 return SMB_VFS_NEXT_RMDIR(handle, fname);
2620 static int snapper_gmt_chflags(vfs_handle_struct *handle,
2621 const struct smb_filename *smb_fname,
2624 time_t timestamp = 0;
2626 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2627 smb_fname->base_name, ×tamp, NULL)) {
2630 if (timestamp != 0) {
2634 return SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
2637 static ssize_t snapper_gmt_getxattr(vfs_handle_struct *handle,
2638 const struct smb_filename *smb_fname,
2643 time_t timestamp = 0;
2644 char *stripped = NULL;
2646 int saved_errno = 0;
2648 struct smb_filename *conv_smb_fname = NULL;
2650 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2652 smb_fname->base_name,
2657 if (timestamp == 0) {
2658 return SMB_VFS_NEXT_GETXATTR(handle, smb_fname, aname, value,
2661 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2662 TALLOC_FREE(stripped);
2666 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2672 if (conv_smb_fname == NULL) {
2676 ret = SMB_VFS_NEXT_GETXATTR(handle, conv_smb_fname, aname, value, size);
2678 saved_errno = errno;
2680 TALLOC_FREE(conv_smb_fname);
2682 if (saved_errno != 0) {
2683 errno = saved_errno;
2688 static ssize_t snapper_gmt_listxattr(struct vfs_handle_struct *handle,
2689 const struct smb_filename *smb_fname,
2690 char *list, size_t size)
2692 time_t timestamp = 0;
2693 char *stripped = NULL;
2695 int saved_errno = 0;
2697 struct smb_filename *conv_smb_fname = NULL;
2699 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2701 smb_fname->base_name,
2706 if (timestamp == 0) {
2707 return SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
2709 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2710 TALLOC_FREE(stripped);
2714 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2720 if (conv_smb_fname == NULL) {
2724 ret = SMB_VFS_NEXT_LISTXATTR(handle, conv_smb_fname, list, size);
2726 saved_errno = errno;
2728 TALLOC_FREE(conv_smb_fname);
2730 if (saved_errno != 0) {
2731 errno = saved_errno;
2736 static int snapper_gmt_removexattr(vfs_handle_struct *handle,
2737 const struct smb_filename *smb_fname,
2740 time_t timestamp = 0;
2742 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2744 smb_fname->base_name,
2749 if (timestamp != 0) {
2753 return SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, aname);
2756 static int snapper_gmt_setxattr(struct vfs_handle_struct *handle,
2757 const struct smb_filename *smb_fname,
2758 const char *aname, const void *value,
2759 size_t size, int flags)
2761 time_t timestamp = 0;
2763 if (!snapper_gmt_strip_snapshot(talloc_tos(),
2765 smb_fname->base_name,
2770 if (timestamp != 0) {
2774 return SMB_VFS_NEXT_SETXATTR(handle, smb_fname,
2775 aname, value, size, flags);
2778 static int snapper_gmt_get_real_filename(struct vfs_handle_struct *handle,
2781 TALLOC_CTX *mem_ctx,
2790 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, path,
2791 ×tamp, &stripped)) {
2794 if (timestamp == 0) {
2795 return SMB_VFS_NEXT_GET_REAL_FILENAME(handle, path, name,
2796 mem_ctx, found_name);
2798 if (stripped[0] == '\0') {
2799 *found_name = talloc_strdup(mem_ctx, name);
2800 if (*found_name == NULL) {
2806 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2807 TALLOC_FREE(stripped);
2811 ret = SMB_VFS_NEXT_GET_REAL_FILENAME(handle, conv, name,
2812 mem_ctx, found_name);
2813 saved_errno = errno;
2815 errno = saved_errno;
2819 static uint64_t snapper_gmt_disk_free(vfs_handle_struct *handle,
2820 const struct smb_filename *smb_fname,
2825 time_t timestamp = 0;
2826 char *stripped = NULL;
2828 int saved_errno = 0;
2830 struct smb_filename *conv_smb_fname = NULL;
2832 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2833 smb_fname->base_name, ×tamp, &stripped)) {
2834 return (uint64_t)-1;
2836 if (timestamp == 0) {
2837 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname,
2838 bsize, dfree, dsize);
2841 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2842 TALLOC_FREE(stripped);
2844 return (uint64_t)-1;
2846 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2851 if (conv_smb_fname == NULL) {
2854 return (uint64_t)-1;
2857 ret = SMB_VFS_NEXT_DISK_FREE(handle, conv_smb_fname,
2858 bsize, dfree, dsize);
2860 if (ret == (uint64_t)-1) {
2861 saved_errno = errno;
2863 TALLOC_FREE(conv_smb_fname);
2864 if (saved_errno != 0) {
2865 errno = saved_errno;
2870 static int snapper_gmt_get_quota(vfs_handle_struct *handle,
2871 const struct smb_filename *smb_fname,
2872 enum SMB_QUOTA_TYPE qtype,
2876 time_t timestamp = 0;
2877 char *stripped = NULL;
2879 int saved_errno = 0;
2881 struct smb_filename *conv_smb_fname = NULL;
2883 if (!snapper_gmt_strip_snapshot(talloc_tos(), handle,
2884 smb_fname->base_name, ×tamp, &stripped)) {
2887 if (timestamp == 0) {
2888 return SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, dq);
2891 conv = snapper_gmt_convert(talloc_tos(), handle, stripped, timestamp);
2892 TALLOC_FREE(stripped);
2896 conv_smb_fname = synthetic_smb_fname(talloc_tos(),
2902 if (conv_smb_fname == NULL) {
2907 ret = SMB_VFS_NEXT_GET_QUOTA(handle, conv_smb_fname, qtype, id, dq);
2910 saved_errno = errno;
2912 TALLOC_FREE(conv_smb_fname);
2913 if (saved_errno != 0) {
2914 errno = saved_errno;
2920 static struct vfs_fn_pointers snapper_fns = {
2921 .snap_check_path_fn = snapper_snap_check_path,
2922 .snap_create_fn = snapper_snap_create,
2923 .snap_delete_fn = snapper_snap_delete,
2924 .get_shadow_copy_data_fn = snapper_get_shadow_copy_data,
2925 .opendir_fn = snapper_gmt_opendir,
2926 .disk_free_fn = snapper_gmt_disk_free,
2927 .get_quota_fn = snapper_gmt_get_quota,
2928 .renameat_fn = snapper_gmt_renameat,
2929 .linkat_fn = snapper_gmt_linkat,
2930 .symlink_fn = snapper_gmt_symlink,
2931 .stat_fn = snapper_gmt_stat,
2932 .lstat_fn = snapper_gmt_lstat,
2933 .open_fn = snapper_gmt_open,
2934 .unlink_fn = snapper_gmt_unlink,
2935 .chmod_fn = snapper_gmt_chmod,
2936 .chown_fn = snapper_gmt_chown,
2937 .chdir_fn = snapper_gmt_chdir,
2938 .ntimes_fn = snapper_gmt_ntimes,
2939 .readlink_fn = snapper_gmt_readlink,
2940 .readlinkat_fn = snapper_gmt_readlinkat,
2941 .mknodat_fn = snapper_gmt_mknodat,
2942 .realpath_fn = snapper_gmt_realpath,
2943 .get_nt_acl_fn = snapper_gmt_get_nt_acl,
2944 .fget_nt_acl_fn = snapper_gmt_fget_nt_acl,
2945 .mkdir_fn = snapper_gmt_mkdir,
2946 .rmdir_fn = snapper_gmt_rmdir,
2947 .getxattr_fn = snapper_gmt_getxattr,
2948 .getxattrat_send_fn = vfs_not_implemented_getxattrat_send,
2949 .getxattrat_recv_fn = vfs_not_implemented_getxattrat_recv,
2950 .listxattr_fn = snapper_gmt_listxattr,
2951 .removexattr_fn = snapper_gmt_removexattr,
2952 .setxattr_fn = snapper_gmt_setxattr,
2953 .chflags_fn = snapper_gmt_chflags,
2954 .get_real_filename_fn = snapper_gmt_get_real_filename,
2958 NTSTATUS vfs_snapper_init(TALLOC_CTX *ctx)
2960 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
2961 "snapper", &snapper_fns);