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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "libcli/raw/libcliraw.h"
25 #include "libcli/smb2/smb2.h"
26 #include "libcli/smb2/smb2_calls.h"
27
28 /*
29 send a getinfo request
30 */
smb2_getinfo_send(struct smb2_tree * tree,struct smb2_getinfo * io)31 struct smb2_request *smb2_getinfo_send(struct smb2_tree *tree, struct smb2_getinfo *io)
32 {
33 struct smb2_request *req;
34
35 req = smb2_request_init_tree(tree, SMB2_OP_GETINFO, 0x28, False, 0);
36 if (req == NULL) return NULL;
37
38 /* this seems to be a bug, they use 0x29 but only send 0x28 bytes */
39 SSVAL(req->out.body, 0x00, 0x29);
40
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.flags2);
47 smb2_push_handle(req->out.body+0x18, &io->in.file.handle);
48
49 smb2_transport_send(req);
50
51 return req;
52 }
53
54
55 /*
56 recv a getinfo reply
57 */
smb2_getinfo_recv(struct smb2_request * req,TALLOC_CTX * mem_ctx,struct smb2_getinfo * io)58 NTSTATUS smb2_getinfo_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
59 struct smb2_getinfo *io)
60 {
61 NTSTATUS status;
62
63 if (!smb2_request_receive(req) ||
64 smb2_request_is_error(req)) {
65 return smb2_request_destroy(req);
66 }
67
68 SMB2_CHECK_PACKET_RECV(req, 0x08, True);
69
70 status = smb2_pull_o16s16_blob(&req->in, mem_ctx, req->in.body+0x02, &io->out.blob);
71 if (!NT_STATUS_IS_OK(status)) {
72 return status;
73 }
74
75 return smb2_request_destroy(req);
76 }
77
78 /*
79 sync getinfo request
80 */
smb2_getinfo(struct smb2_tree * tree,TALLOC_CTX * mem_ctx,struct smb2_getinfo * io)81 NTSTATUS smb2_getinfo(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
82 struct smb2_getinfo *io)
83 {
84 struct smb2_request *req = smb2_getinfo_send(tree, io);
85 return smb2_getinfo_recv(req, mem_ctx, io);
86 }
87
88
89 /*
90 map a generic info level to a SMB2 info level
91 */
smb2_getinfo_map_level(uint16_t level,uint8_t class)92 uint16_t smb2_getinfo_map_level(uint16_t level, uint8_t class)
93 {
94 if (class == SMB2_GETINFO_FILE &&
95 level == RAW_FILEINFO_SEC_DESC) {
96 return SMB2_GETINFO_SECURITY;
97 }
98 if ((level & 0xFF) == class) {
99 return level;
100 } else if (level > 1000) {
101 return ((level-1000)<<8) | class;
102 }
103 DEBUG(0,("Unable to map SMB2 info level 0x%04x of class %d\n", level, class));
104 return 0;
105 }
106
107 /*
108 level specific getinfo call - async send
109 */
smb2_getinfo_file_send(struct smb2_tree * tree,union smb_fileinfo * io)110 struct smb2_request *smb2_getinfo_file_send(struct smb2_tree *tree, union smb_fileinfo *io)
111 {
112 struct smb2_getinfo b;
113 uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FILE);
114
115 if (smb2_level == 0) {
116 return NULL;
117 }
118
119 ZERO_STRUCT(b);
120 b.in.max_response_size = 0x10000;
121 b.in.file.handle = io->generic.in.file.handle;
122 b.in.level = smb2_level;
123
124 if (io->generic.level == RAW_FILEINFO_SEC_DESC) {
125 b.in.flags = io->query_secdesc.in.secinfo_flags;
126 }
127 if (io->generic.level == RAW_FILEINFO_SMB2_ALL_EAS) {
128 b.in.flags2 = io->all_eas.in.continue_flags;
129 }
130
131 return smb2_getinfo_send(tree, &b);
132 }
133
134 /*
135 recv a getinfo reply and parse the level info
136 */
smb2_getinfo_file_recv(struct smb2_request * req,TALLOC_CTX * mem_ctx,union smb_fileinfo * io)137 NTSTATUS smb2_getinfo_file_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
138 union smb_fileinfo *io)
139 {
140 struct smb2_getinfo b;
141 NTSTATUS status;
142
143 status = smb2_getinfo_recv(req, mem_ctx, &b);
144 NT_STATUS_NOT_OK_RETURN(status);
145
146 status = smb_raw_fileinfo_passthru_parse(&b.out.blob, mem_ctx, io->generic.level, io);
147 data_blob_free(&b.out.blob);
148
149 return status;
150 }
151
152 /*
153 level specific getinfo call
154 */
smb2_getinfo_file(struct smb2_tree * tree,TALLOC_CTX * mem_ctx,union smb_fileinfo * io)155 NTSTATUS smb2_getinfo_file(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
156 union smb_fileinfo *io)
157 {
158 struct smb2_request *req = smb2_getinfo_file_send(tree, io);
159 return smb2_getinfo_file_recv(req, mem_ctx, io);
160 }
161
162
163 /*
164 level specific getinfo call - async send
165 */
smb2_getinfo_fs_send(struct smb2_tree * tree,union smb_fsinfo * io)166 struct smb2_request *smb2_getinfo_fs_send(struct smb2_tree *tree, union smb_fsinfo *io)
167 {
168 struct smb2_getinfo b;
169 uint16_t smb2_level = smb2_getinfo_map_level(io->generic.level, SMB2_GETINFO_FS);
170
171 if (smb2_level == 0) {
172 return NULL;
173 }
174
175 ZERO_STRUCT(b);
176 b.in.max_response_size = 0x10000;
177 b.in.file.handle = io->generic.handle;
178 b.in.level = smb2_level;
179
180 return smb2_getinfo_send(tree, &b);
181 }
182
183 /*
184 recv a getinfo reply and parse the level info
185 */
smb2_getinfo_fs_recv(struct smb2_request * req,TALLOC_CTX * mem_ctx,union smb_fsinfo * io)186 NTSTATUS smb2_getinfo_fs_recv(struct smb2_request *req, TALLOC_CTX *mem_ctx,
187 union smb_fsinfo *io)
188 {
189 struct smb2_getinfo b;
190 NTSTATUS status;
191
192 status = smb2_getinfo_recv(req, mem_ctx, &b);
193 NT_STATUS_NOT_OK_RETURN(status);
194
195 status = smb_raw_fsinfo_passthru_parse(b.out.blob, mem_ctx, io->generic.level, io);
196 data_blob_free(&b.out.blob);
197
198 return status;
199 }
200
201 /*
202 level specific getinfo call
203 */
smb2_getinfo_fs(struct smb2_tree * tree,TALLOC_CTX * mem_ctx,union smb_fsinfo * io)204 NTSTATUS smb2_getinfo_fs(struct smb2_tree *tree, TALLOC_CTX *mem_ctx,
205 union smb_fsinfo *io)
206 {
207 struct smb2_request *req = smb2_getinfo_fs_send(tree, io);
208 return smb2_getinfo_fs_recv(req, mem_ctx, io);
209 }
210
211