2 Unix SMB/CIFS implementation.
4 SMB2 client getinfo calls
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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/>.
23 #include "libcli/raw/libcliraw.h"
24 #include "libcli/smb2/smb2.h"
25 #include "libcli/smb2/smb2_calls.h"
28 send a getinfo request
30 struct smb2_request *smb2_getinfo_send(struct smb2_tree *tree, struct smb2_getinfo *io)
32 struct smb2_request *req;
35 req = smb2_request_init_tree(tree, SMB2_OP_GETINFO, 0x28, true,
37 if (req == NULL) return NULL;
39 SCVAL(req->out.body, 0x02, io->in.info_type);
40 SCVAL(req->out.body, 0x03, io->in.info_class);
41 SIVAL(req->out.body, 0x04, io->in.output_buffer_length);
42 SIVAL(req->out.body, 0x0C, io->in.reserved);
43 SIVAL(req->out.body, 0x08, io->in.input_buffer_length);
44 SIVAL(req->out.body, 0x10, io->in.additional_information);
45 SIVAL(req->out.body, 0x14, io->in.getinfo_flags);
46 smb2_push_handle(req->out.body+0x18, &io->in.file.handle);
48 /* this blob is used for quota queries */
49 status = smb2_push_o32s32_blob(&req->out, 0x08, io->in.blob);
50 if (!NT_STATUS_IS_OK(status)) {
54 smb2_transport_send(req);
63 NTSTATUS smb2_getinfo_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
64 struct smb2_getinfo *io)
68 if (!smb2_request_receive(req) ||
69 smb2_request_is_error(req)) {
70 return smb2_request_destroy(req);
73 SMB2_CHECK_PACKET_RECV(req, 0x08, true);
75 status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.blob);
76 if (!NT_STATUS_IS_OK(status)) {
80 return smb2_request_destroy(req);
86 NTSTATUS smb2_getinfo(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
87 struct smb2_getinfo *io)
89 struct smb2_request *req = smb2_getinfo_send(tree, io);
90 return smb2_getinfo_recv(req, mem_ctx, io);
95 map a generic info level to a SMB2 info level
97 uint16_t smb2_getinfo_map_level(uint16_t level, uint8_t class)
99 if (class == SMB2_GETINFO_FILE &&
100 level == RAW_FILEINFO_SEC_DESC) {
101 return SMB2_GETINFO_SECURITY;
103 if ((level & 0xFF) == class) {
105 } else if (level > 1000) {
106 return ((level-1000)<<8) | class;
108 DEBUG(0,("Unable to map SMB2 info level 0x%04x of class %d\n", level, class));
113 level specific getinfo call - async send
115 struct smb2_request *smb2_getinfo_file_send(struct smb2_tree *tree, union smb_fileinfo *io)
117 struct smb2_getinfo b;
118 uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FILE);
120 if (smb2_level == 0) {
125 b.in.info_type = smb2_level & 0xFF;
126 b.in.info_class = smb2_level >> 8;
127 b.in.output_buffer_length = 0x10000;
128 b.in.input_buffer_length = 0;
129 b.in.file.handle = io->generic.in.file.handle;
131 if (io->generic.level == RAW_FILEINFO_SEC_DESC) {
132 b.in.additional_information = io->query_secdesc.in.secinfo_flags;
134 if (io->generic.level == RAW_FILEINFO_SMB2_ALL_EAS) {
135 b.in.getinfo_flags = io->all_eas.in.continue_flags;
138 return smb2_getinfo_send(tree, &b);
142 recv a getinfo reply and parse the level info
144 NTSTATUS smb2_getinfo_file_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
145 union smb_fileinfo *io)
147 struct smb2_getinfo b;
150 status = smb2_getinfo_recv(req, mem_ctx, &b);
151 NT_STATUS_NOT_OK_RETURN(status);
153 status = smb_raw_fileinfo_passthru_parse(&b.out.blob, mem_ctx, io->generic.level, io);
154 data_blob_free(&b.out.blob);
160 level specific getinfo call
162 NTSTATUS smb2_getinfo_file(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
163 union smb_fileinfo *io)
165 struct smb2_request *req = smb2_getinfo_file_send(tree, io);
166 return smb2_getinfo_file_recv(req, mem_ctx, io);
171 level specific getinfo call - async send
173 struct smb2_request *smb2_getinfo_fs_send(struct smb2_tree *tree, union smb_fsinfo *io)
175 struct smb2_getinfo b;
176 uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FS);
178 if (smb2_level == 0) {
183 b.in.output_buffer_length = 0x10000;
184 b.in.file.handle = io->generic.handle;
185 b.in.info_type = smb2_level & 0xFF;
186 b.in.info_class = smb2_level >> 8;
188 return smb2_getinfo_send(tree, &b);
192 recv a getinfo reply and parse the level info
194 NTSTATUS smb2_getinfo_fs_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
195 union smb_fsinfo *io)
197 struct smb2_getinfo b;
200 status = smb2_getinfo_recv(req, mem_ctx, &b);
201 NT_STATUS_NOT_OK_RETURN(status);
203 status = smb_raw_fsinfo_passthru_parse(b.out.blob, mem_ctx, io->generic.level, io);
204 data_blob_free(&b.out.blob);
210 level specific getinfo call
212 NTSTATUS smb2_getinfo_fs(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
213 union smb_fsinfo *io)
215 struct smb2_request *req = smb2_getinfo_fs_send(tree, io);
216 return smb2_getinfo_fs_recv(req, mem_ctx, io);