| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | SMB2 client getinfo calls
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) Andrew Tridgell 2005
|
|---|
| 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/smb2/smb2.h"
|
|---|
| 26 | #include "libcli/smb2/smb2_calls.h"
|
|---|
| 27 |
|
|---|
| 28 | /*
|
|---|
| 29 | send a getinfo request
|
|---|
| 30 | */
|
|---|
| 31 | struct smb2_request *smb2_getinfo_send(struct smb2_tree *tree, struct smb2_getinfo *io)
|
|---|
| 32 | {
|
|---|
| 33 | struct smb2_request *req;
|
|---|
| 34 | NTSTATUS status;
|
|---|
| 35 |
|
|---|
| 36 | req = smb2_request_init_tree(tree, SMB2_OP_GETINFO, 0x28, true,
|
|---|
| 37 | io->in.blob.length);
|
|---|
| 38 | if (req == NULL) return NULL;
|
|---|
| 39 |
|
|---|
| 40 | SCVAL(req->out.body, 0x02, io->in.info_type);
|
|---|
| 41 | SCVAL(req->out.body, 0x03, io->in.info_class);
|
|---|
| 42 | SIVAL(req->out.body, 0x04, io->in.output_buffer_length);
|
|---|
| 43 | SIVAL(req->out.body, 0x0C, io->in.reserved);
|
|---|
| 44 | SIVAL(req->out.body, 0x08, io->in.input_buffer_length);
|
|---|
| 45 | SIVAL(req->out.body, 0x10, io->in.additional_information);
|
|---|
| 46 | SIVAL(req->out.body, 0x14, io->in.getinfo_flags);
|
|---|
| 47 | smb2_push_handle(req->out.body+0x18, &io->in.file.handle);
|
|---|
| 48 |
|
|---|
| 49 | /* this blob is used for quota queries */
|
|---|
| 50 | status = smb2_push_o32s32_blob(&req->out, 0x08, io->in.blob);
|
|---|
| 51 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 52 | talloc_free(req);
|
|---|
| 53 | return NULL;
|
|---|
| 54 | }
|
|---|
| 55 | smb2_transport_send(req);
|
|---|
| 56 |
|
|---|
| 57 | return req;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 | /*
|
|---|
| 62 | recv a getinfo reply
|
|---|
| 63 | */
|
|---|
| 64 | NTSTATUS smb2_getinfo_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
|
|---|
| 65 | struct smb2_getinfo *io)
|
|---|
| 66 | {
|
|---|
| 67 | NTSTATUS status;
|
|---|
| 68 |
|
|---|
| 69 | if (!smb2_request_receive(req) ||
|
|---|
| 70 | smb2_request_is_error(req)) {
|
|---|
| 71 | return smb2_request_destroy(req);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | SMB2_CHECK_PACKET_RECV(req, 0x08, true);
|
|---|
| 75 |
|
|---|
| 76 | status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.blob);
|
|---|
| 77 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 78 | return status;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | return smb2_request_destroy(req);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | /*
|
|---|
| 85 | sync getinfo request
|
|---|
| 86 | */
|
|---|
| 87 | NTSTATUS smb2_getinfo(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
|
|---|
| 88 | struct smb2_getinfo *io)
|
|---|
| 89 | {
|
|---|
| 90 | struct smb2_request *req = smb2_getinfo_send(tree, io);
|
|---|
| 91 | return smb2_getinfo_recv(req, mem_ctx, io);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 | /*
|
|---|
| 96 | map a generic info level to a SMB2 info level
|
|---|
| 97 | */
|
|---|
| 98 | uint16_t smb2_getinfo_map_level(uint16_t level, uint8_t info_class)
|
|---|
| 99 | {
|
|---|
| 100 | if (info_class == SMB2_GETINFO_FILE &&
|
|---|
| 101 | level == RAW_FILEINFO_SEC_DESC) {
|
|---|
| 102 | return SMB2_GETINFO_SECURITY;
|
|---|
| 103 | }
|
|---|
| 104 | if ((level & 0xFF) == info_class) {
|
|---|
| 105 | return level;
|
|---|
| 106 | } else if (level > 1000) {
|
|---|
| 107 | return ((level-1000)<<8) | info_class;
|
|---|
| 108 | }
|
|---|
| 109 | DEBUG(0,("Unable to map SMB2 info level 0x%04x of class %d\n",
|
|---|
| 110 | level, info_class));
|
|---|
| 111 | return 0;
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | /*
|
|---|
| 115 | level specific getinfo call - async send
|
|---|
| 116 | */
|
|---|
| 117 | struct smb2_request *smb2_getinfo_file_send(struct smb2_tree *tree, union smb_fileinfo *io)
|
|---|
| 118 | {
|
|---|
| 119 | struct smb2_getinfo b;
|
|---|
| 120 | uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FILE);
|
|---|
| 121 |
|
|---|
| 122 | if (smb2_level == 0) {
|
|---|
| 123 | return NULL;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | ZERO_STRUCT(b);
|
|---|
| 127 | b.in.info_type = smb2_level & 0xFF;
|
|---|
| 128 | b.in.info_class = smb2_level >> 8;
|
|---|
| 129 | b.in.output_buffer_length = 0x10000;
|
|---|
| 130 | b.in.input_buffer_length = 0;
|
|---|
| 131 | b.in.file.handle = io->generic.in.file.handle;
|
|---|
| 132 |
|
|---|
| 133 | if (io->generic.level == RAW_FILEINFO_SEC_DESC) {
|
|---|
| 134 | b.in.additional_information = io->query_secdesc.in.secinfo_flags;
|
|---|
| 135 | }
|
|---|
| 136 | if (io->generic.level == RAW_FILEINFO_SMB2_ALL_EAS) {
|
|---|
| 137 | b.in.getinfo_flags = io->all_eas.in.continue_flags;
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | return smb2_getinfo_send(tree, &b);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | /*
|
|---|
| 144 | recv a getinfo reply and parse the level info
|
|---|
| 145 | */
|
|---|
| 146 | NTSTATUS smb2_getinfo_file_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
|
|---|
| 147 | union smb_fileinfo *io)
|
|---|
| 148 | {
|
|---|
| 149 | struct smb2_getinfo b;
|
|---|
| 150 | NTSTATUS status;
|
|---|
| 151 |
|
|---|
| 152 | status = smb2_getinfo_recv(req, mem_ctx, &b);
|
|---|
| 153 | NT_STATUS_NOT_OK_RETURN(status);
|
|---|
| 154 |
|
|---|
| 155 | status = smb_raw_fileinfo_passthru_parse(&b.out.blob, mem_ctx, io->generic.level, io);
|
|---|
| 156 | data_blob_free(&b.out.blob);
|
|---|
| 157 |
|
|---|
| 158 | return status;
|
|---|
| 159 | }
|
|---|
| 160 |
|
|---|
| 161 | /*
|
|---|
| 162 | level specific getinfo call
|
|---|
| 163 | */
|
|---|
| 164 | NTSTATUS smb2_getinfo_file(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
|
|---|
| 165 | union smb_fileinfo *io)
|
|---|
| 166 | {
|
|---|
| 167 | struct smb2_request *req = smb2_getinfo_file_send(tree, io);
|
|---|
| 168 | return smb2_getinfo_file_recv(req, mem_ctx, io);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 | /*
|
|---|
| 173 | level specific getinfo call - async send
|
|---|
| 174 | */
|
|---|
| 175 | struct smb2_request *smb2_getinfo_fs_send(struct smb2_tree *tree, union smb_fsinfo *io)
|
|---|
| 176 | {
|
|---|
| 177 | struct smb2_getinfo b;
|
|---|
| 178 | uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FS);
|
|---|
| 179 |
|
|---|
| 180 | if (smb2_level == 0) {
|
|---|
| 181 | return NULL;
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | ZERO_STRUCT(b);
|
|---|
| 185 | b.in.output_buffer_length = 0x10000;
|
|---|
| 186 | b.in.file.handle = io->generic.handle;
|
|---|
| 187 | b.in.info_type = smb2_level & 0xFF;
|
|---|
| 188 | b.in.info_class = smb2_level >> 8;
|
|---|
| 189 |
|
|---|
| 190 | return smb2_getinfo_send(tree, &b);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | /*
|
|---|
| 194 | recv a getinfo reply and parse the level info
|
|---|
| 195 | */
|
|---|
| 196 | NTSTATUS smb2_getinfo_fs_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
|
|---|
| 197 | union smb_fsinfo *io)
|
|---|
| 198 | {
|
|---|
| 199 | struct smb2_getinfo b;
|
|---|
| 200 | NTSTATUS status;
|
|---|
| 201 |
|
|---|
| 202 | status = smb2_getinfo_recv(req, mem_ctx, &b);
|
|---|
| 203 | NT_STATUS_NOT_OK_RETURN(status);
|
|---|
| 204 |
|
|---|
| 205 | status = smb_raw_fsinfo_passthru_parse(b.out.blob, mem_ctx, io->generic.level, io);
|
|---|
| 206 | data_blob_free(&b.out.blob);
|
|---|
| 207 |
|
|---|
| 208 | return status;
|
|---|
| 209 | }
|
|---|
| 210 |
|
|---|
| 211 | /*
|
|---|
| 212 | level specific getinfo call
|
|---|
| 213 | */
|
|---|
| 214 | NTSTATUS smb2_getinfo_fs(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
|
|---|
| 215 | union smb_fsinfo *io)
|
|---|
| 216 | {
|
|---|
| 217 | struct smb2_request *req = smb2_getinfo_fs_send(tree, io);
|
|---|
| 218 | return smb2_getinfo_fs_recv(req, mem_ctx, io);
|
|---|
| 219 | }
|
|---|
| 220 |
|
|---|