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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
29 send a getinfo request
31 struct smb2_request *smb2_getinfo_send(struct smb2_tree *tree, struct smb2_getinfo *io)
33 struct smb2_request *req;
35 req = smb2_request_init_tree(tree, SMB2_OP_GETINFO, 0x28, 0);
36 if (req == NULL) return NULL;
38 /* this seems to be a bug, they use 0x29 but only send 0x28 bytes */
39 SSVAL(req->out.body, 0x00, 0x29);
41 SSVAL(req->out.body, 0x02, io->in.level);
42 SIVAL(req->out.body, 0x04, io->in.max_response_size);
43 SIVAL(req->out.body, 0x08, io->in.unknown1);
44 SIVAL(req->out.body, 0x0C, io->in.unknown2);
45 SIVAL(req->out.body, 0x10, io->in.flags);
46 SIVAL(req->out.body, 0x14, io->in.unknown4);
47 smb2_push_handle(req->out.body+0x18, &io->in.handle);
49 smb2_transport_send(req);
58 NTSTATUS smb2_getinfo_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
59 struct smb2_getinfo *io)
63 if (!smb2_request_receive(req) ||
64 smb2_request_is_error(req)) {
65 return smb2_request_destroy(req);
68 SMB2_CHECK_PACKET_RECV(req, 0x08, True);
70 status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.blob);
71 if (!NT_STATUS_IS_OK(status)) {
75 return smb2_request_destroy(req);
81 NTSTATUS smb2_getinfo(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
82 struct smb2_getinfo *io)
84 struct smb2_request *req = smb2_getinfo_send(tree, io);
85 return smb2_getinfo_recv(req, mem_ctx, io);
90 map a generic info level to a SMB2 info level
92 uint16_t smb2_getinfo_map_level(uint16_t level, uint8_t class)
94 if ((level & 0xFF) == class) {
96 } else if (level > 1000) {
97 return ((level-1000)<<8) | class;
99 DEBUG(0,("Unable to map SMB2 info level 0x%04x of class %d\n", level, class));
104 level specific getinfo call - async send
106 struct smb2_request *smb2_getinfo_file_send(struct smb2_tree *tree, union smb_fileinfo *io)
108 struct smb2_getinfo b;
109 uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FILE);
111 if (smb2_level == 0) {
116 b.in.max_response_size = 0x10000;
117 b.in.handle = io->generic.in.handle;
118 b.in.level = smb2_level;
120 if (io->generic.level == RAW_FILEINFO_SEC_DESC) {
121 b.in.flags = io->query_secdesc.secinfo_flags;
124 return smb2_getinfo_send(tree, &b);
128 recv a getinfo reply and parse the level info
130 NTSTATUS smb2_getinfo_file_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
131 union smb_fileinfo *io)
133 struct smb2_getinfo b;
136 status = smb2_getinfo_recv(req, mem_ctx, &b);
137 NT_STATUS_NOT_OK_RETURN(status);
139 status = smb_raw_fileinfo_passthru_parse(&b.out.blob, mem_ctx, io->generic.level, io);
140 data_blob_free(&b.out.blob);
146 level specific getinfo call
148 NTSTATUS smb2_getinfo_file(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
149 union smb_fileinfo *io)
151 struct smb2_request *req = smb2_getinfo_file_send(tree, io);
152 return smb2_getinfo_file_recv(req, mem_ctx, io);
157 level specific getinfo call - async send
159 struct smb2_request *smb2_getinfo_fs_send(struct smb2_tree *tree, union smb_fsinfo *io)
161 struct smb2_getinfo b;
162 uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FS);
164 if (smb2_level == 0) {
169 b.in.max_response_size = 0x10000;
170 b.in.handle = io->generic.handle;
171 b.in.level = smb2_level;
173 return smb2_getinfo_send(tree, &b);
177 recv a getinfo reply and parse the level info
179 NTSTATUS smb2_getinfo_fs_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
180 union smb_fsinfo *io)
182 struct smb2_getinfo b;
185 status = smb2_getinfo_recv(req, mem_ctx, &b);
186 NT_STATUS_NOT_OK_RETURN(status);
188 status = smb_raw_fsinfo_passthru_parse(b.out.blob, mem_ctx, io->generic.level, io);
189 data_blob_free(&b.out.blob);
195 level specific getinfo call
197 NTSTATUS smb2_getinfo_fs(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
198 union smb_fsinfo *io)
200 struct smb2_request *req = smb2_getinfo_fs_send(tree, io);
201 return smb2_getinfo_fs_recv(req, mem_ctx, io);