| 1 | /* | 
|---|
| 2 | Unix SMB/CIFS implementation. | 
|---|
| 3 |  | 
|---|
| 4 | shadow copy file operations | 
|---|
| 5 |  | 
|---|
| 6 | Copyright (C) Andrew Tridgell 2007 | 
|---|
| 7 |  | 
|---|
| 8 | This program is free software; you can redistribute it and/or modify | 
|---|
| 9 | it under the terms of the GNU General Public License as published by | 
|---|
| 10 | the Free Software Foundation; either version 3 of the License, or | 
|---|
| 11 | (at your option) any later version. | 
|---|
| 12 |  | 
|---|
| 13 | This program is distributed in the hope that it will be useful, | 
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 16 | GNU General Public License for more details. | 
|---|
| 17 |  | 
|---|
| 18 | You should have received a copy of the GNU General Public License | 
|---|
| 19 | along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
|---|
| 20 | */ | 
|---|
| 21 |  | 
|---|
| 22 | #include "includes.h" | 
|---|
| 23 | #include "libcli/raw/libcliraw.h" | 
|---|
| 24 | #include "libcli/raw/raw_proto.h" | 
|---|
| 25 | #include "libcli/raw/ioctl.h" | 
|---|
| 26 |  | 
|---|
| 27 | /* | 
|---|
| 28 | get shadow volume data | 
|---|
| 29 | */ | 
|---|
| 30 | _PUBLIC_ NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, | 
|---|
| 31 | TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info) | 
|---|
| 32 | { | 
|---|
| 33 | union smb_ioctl nt; | 
|---|
| 34 | NTSTATUS status; | 
|---|
| 35 | DATA_BLOB blob; | 
|---|
| 36 | uint32_t dlength; | 
|---|
| 37 | int i; | 
|---|
| 38 | uint32_t ofs; | 
|---|
| 39 |  | 
|---|
| 40 | nt.ntioctl.level        = RAW_IOCTL_NTIOCTL; | 
|---|
| 41 | nt.ntioctl.in.function  = FSCTL_GET_SHADOW_COPY_DATA; | 
|---|
| 42 | nt.ntioctl.in.file.fnum = info->in.file.fnum; | 
|---|
| 43 | nt.ntioctl.in.fsctl     = true; | 
|---|
| 44 | nt.ntioctl.in.filter    = 0; | 
|---|
| 45 | nt.ntioctl.in.max_data  = info->in.max_data; | 
|---|
| 46 | nt.ntioctl.in.blob      = data_blob(NULL, 0); | 
|---|
| 47 |  | 
|---|
| 48 | status = smb_raw_ioctl(tree, mem_ctx, &nt); | 
|---|
| 49 | if (!NT_STATUS_IS_OK(status)) { | 
|---|
| 50 | return status; | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | blob = nt.ntioctl.out.blob; | 
|---|
| 54 |  | 
|---|
| 55 | if (blob.length < 12) { | 
|---|
| 56 | return NT_STATUS_INVALID_NETWORK_RESPONSE; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | info->out.num_volumes = IVAL(blob.data, 0); | 
|---|
| 60 | info->out.num_names   = IVAL(blob.data, 4); | 
|---|
| 61 | dlength               = IVAL(blob.data, 8); | 
|---|
| 62 | if (dlength > blob.length - 12) { | 
|---|
| 63 | return NT_STATUS_INVALID_NETWORK_RESPONSE; | 
|---|
| 64 | } | 
|---|
| 65 |  | 
|---|
| 66 | info->out.names = talloc_array(mem_ctx, const char *, info->out.num_names); | 
|---|
| 67 | NT_STATUS_HAVE_NO_MEMORY(info->out.names); | 
|---|
| 68 |  | 
|---|
| 69 | ofs = 12; | 
|---|
| 70 | for (i=0;i<info->out.num_names;i++) { | 
|---|
| 71 | size_t len; | 
|---|
| 72 | len = smbcli_blob_pull_ucs2(info->out.names, | 
|---|
| 73 | &blob, &info->out.names[i], | 
|---|
| 74 | blob.data+ofs, -1, STR_TERMINATE); | 
|---|
| 75 | if (len == 0) { | 
|---|
| 76 | return NT_STATUS_INVALID_NETWORK_RESPONSE; | 
|---|
| 77 | } | 
|---|
| 78 | ofs += len; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | return status; | 
|---|
| 82 | } | 
|---|