r23519: added libcli code for fetching shadow copy information
authorAndrew Tridgell <tridge@samba.org>
Sat, 16 Jun 2007 17:13:42 +0000 (17:13 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:53:23 +0000 (14:53 -0500)
source/libcli/config.mk
source/libcli/raw/interfaces.h
source/libcli/raw/rawrequest.c
source/libcli/raw/rawshadow.c [new file with mode: 0644]

index 74af8185e6f974f90d3e58e742564191a0da5f57..d49fc90ec4a6e17d2486c5ae07d6b6526a86e782 100644 (file)
@@ -147,6 +147,7 @@ OBJ_FILES = raw/rawfile.o \
                raw/rawioctl.o \
                raw/rawacl.o \
                raw/rawdate.o \
-               raw/rawlpq.o
+               raw/rawlpq.o \
+               raw/rawshadow.o
 
 include smb2/config.mk
index 93d8dd2c20a02de29cfe4bbbd61f0aecb74ffa55..210fb1cccfcfec2e1cc03c1179bda3d188f2e8d8 100644 (file)
@@ -2632,4 +2632,19 @@ struct smb_echo {
        } out;
 };
 
+/*
+  struct for shadow copy volumes
+ */
+struct smb_shadow_copy {
+       struct {
+               union smb_handle file;
+               uint32_t max_data;
+       } in;
+       struct {
+               uint32_t num_volumes;
+               uint32_t num_names;
+               const char **names;
+       } out;
+};
+
 #endif /* __LIBCLI_RAW_INTERFACES_H__ */
index 7d1bfdb30d686f0ed545e7177f3713fb227c093f..a0dfe75096a4f7360edfaff7156b39b72f336ffa 100644 (file)
@@ -737,9 +737,9 @@ NTTIME smbcli_pull_nttime(void *base, uint16_t offset)
   on failure zero is returned and *dest is set to NULL, otherwise the number
   of bytes consumed in the blob is returned
 */
-static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx,
-                                   const DATA_BLOB *blob, const char **dest, 
-                                   const uint8_t *src, int byte_len, uint_t flags)
+size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx,
+                            const DATA_BLOB *blob, const char **dest, 
+                            const uint8_t *src, int byte_len, uint_t flags)
 {
        int src_len, src_len2, alignment=0;
        ssize_t ret;
diff --git a/source/libcli/raw/rawshadow.c b/source/libcli/raw/rawshadow.c
new file mode 100644 (file)
index 0000000..428ebc9
--- /dev/null
@@ -0,0 +1,79 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   shadow copy file operations
+
+   Copyright (C) Andrew Tridgell 2007
+   
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "libcli/raw/libcliraw.h"
+#include "libcli/raw/ioctl.h"
+
+/* 
+   get shadow volume data
+*/
+_PUBLIC_ NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, 
+                                     TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info)
+{
+       union smb_ioctl nt;
+       NTSTATUS status;
+       DATA_BLOB blob;
+       uint32_t dlength;
+       int i;
+       uint32_t ofs;
+
+       nt.ntioctl.level        = RAW_IOCTL_NTIOCTL;
+       nt.ntioctl.in.function  = FSCTL_GET_SHADOW_COPY_DATA;
+       nt.ntioctl.in.file.fnum = info->in.file.fnum;
+       nt.ntioctl.in.fsctl     = True;
+       nt.ntioctl.in.filter    = 0;
+       nt.ntioctl.in.max_data  = info->in.max_data;
+       nt.ntioctl.in.blob      = data_blob(NULL, 0);
+
+       status = smb_raw_ioctl(tree, mem_ctx, &nt);
+       
+       blob = nt.ntioctl.out.blob;
+
+       if (blob.length < 12) {
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+       
+       info->out.num_volumes = IVAL(blob.data, 0);
+       info->out.num_names   = IVAL(blob.data, 4);
+       dlength               = IVAL(blob.data, 8);
+       if (dlength > blob.length - 12) {
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
+       }
+
+       info->out.names = talloc_array(mem_ctx, const char *, info->out.num_names);
+       NT_STATUS_HAVE_NO_MEMORY(info->out.names);
+
+       ofs = 12;
+       for (i=0;i<info->out.num_names;i++) {
+               size_t len;
+               len = smbcli_blob_pull_ucs2(info->out.names, 
+                                     &blob, &info->out.names[i],
+                                     blob.data+ofs, -1, STR_TERMINATE);
+               if (len == 0) {
+                       return NT_STATUS_INVALID_NETWORK_RESPONSE;
+               }
+               ofs += len;
+       }
+       
+       return status;
+}