1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
|
/*
Unix SMB/CIFS implementation.
RAW_QFS_* operations
Copyright (C) Andrew Tridgell 2003
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "includes.h"
#include "libcli/raw/libcliraw.h"
#include "libcli/raw/raw_proto.h"
#include "librpc/gen_ndr/ndr_misc.h"
/****************************************************************************
Query FS Info - SMBdskattr call (async send)
****************************************************************************/
static struct smbcli_request *smb_raw_dskattr_send(struct smbcli_tree *tree,
union smb_fsinfo *fsinfo)
{
struct smbcli_request *req;
req = smbcli_request_setup(tree, SMBdskattr, 0, 0);
if (req == NULL) {
return NULL;
}
if (!smbcli_request_send(req)) {
smbcli_request_destroy(req);
return NULL;
}
return req;
}
/****************************************************************************
Query FS Info - SMBdskattr call (async recv)
****************************************************************************/
static NTSTATUS smb_raw_dskattr_recv(struct smbcli_request *req,
union smb_fsinfo *fsinfo)
{
if (!smbcli_request_receive(req) ||
smbcli_request_is_error(req)) {
goto failed;
}
SMBCLI_CHECK_WCT(req, 5);
fsinfo->dskattr.out.units_total = SVAL(req->in.vwv, VWV(0));
fsinfo->dskattr.out.blocks_per_unit = SVAL(req->in.vwv, VWV(1));
fsinfo->dskattr.out.block_size = SVAL(req->in.vwv, VWV(2));
fsinfo->dskattr.out.units_free = SVAL(req->in.vwv, VWV(3));
failed:
return smbcli_request_destroy(req);
}
/****************************************************************************
RAW_QFS_ trans2 interface via blobs (async send)
****************************************************************************/
static struct smbcli_request *smb_raw_qfsinfo_send(struct smbcli_tree *tree,
TALLOC_CTX *mem_ctx,
uint16_t info_level)
{
struct smb_trans2 tp;
uint16_t setup = TRANSACT2_QFSINFO;
tp.in.max_setup = 0;
tp.in.flags = 0;
tp.in.timeout = 0;
tp.in.setup_count = 1;
tp.in.max_param = 0;
tp.in.max_data = 0xFFFF;
tp.in.setup = &setup;
tp.in.data = data_blob(NULL, 0);
tp.in.timeout = 0;
tp.in.params = data_blob_talloc(mem_ctx, NULL, 2);
if (!tp.in.params.data) {
return NULL;
}
SSVAL(tp.in.params.data, 0, info_level);
return smb_raw_trans2_send(tree, &tp);
}
/****************************************************************************
RAW_QFS_ trans2 interface via blobs (async recv)
****************************************************************************/
static NTSTATUS smb_raw_qfsinfo_blob_recv(struct smbcli_request *req,
TALLOC_CTX *mem_ctx,
DATA_BLOB *blob)
{
struct smb_trans2 tp;
NTSTATUS status;
status = smb_raw_trans2_recv(req, mem_ctx, &tp);
if (NT_STATUS_IS_OK(status)) {
(*blob) = tp.out.data;
}
return status;
}
/* local macros to make the code more readable */
#define QFS_CHECK_MIN_SIZE(size) if (blob.length < (size)) { \
DEBUG(1,("Unexpected QFS reply size %d for level %u - expected min of %d\n", \
(int)blob.length, fsinfo->generic.level, (size))); \
status = NT_STATUS_INFO_LENGTH_MISMATCH; \
goto failed; \
}
#define QFS_CHECK_SIZE(size) if (blob.length != (size)) { \
DEBUG(1,("Unexpected QFS reply size %d for level %u - expected %d\n", \
(int)blob.length, fsinfo->generic.level, (size))); \
status = NT_STATUS_INFO_LENGTH_MISMATCH; \
goto failed; \
}
/****************************************************************************
Query FSInfo raw interface (async send)
****************************************************************************/
struct smbcli_request *smb_raw_fsinfo_send(struct smbcli_tree *tree,
TALLOC_CTX *mem_ctx,
union smb_fsinfo *fsinfo)
{
uint16_t info_level;
/* handle the only non-trans2 call separately */
if (fsinfo->generic.level == RAW_QFS_DSKATTR) {
return smb_raw_dskattr_send(tree, fsinfo);
}
if (fsinfo->generic.level >= RAW_QFS_GENERIC) {
return NULL;
}
/* the headers map the trans2 levels direct to info levels */
info_level = (uint16_t)fsinfo->generic.level;
return smb_raw_qfsinfo_send(tree, mem_ctx, info_level);
}
/*
parse the fsinfo 'passthru' level replies
*/
NTSTATUS smb_raw_fsinfo_passthru_parse(DATA_BLOB blob, TALLOC_CTX *mem_ctx,
enum smb_fsinfo_level level,
union smb_fsinfo *fsinfo)
{
NTSTATUS status = NT_STATUS_OK;
int i;
/* parse the results */
switch (level) {
case RAW_QFS_VOLUME_INFORMATION:
QFS_CHECK_MIN_SIZE(18);
fsinfo->volume_info.out.create_time = smbcli_pull_nttime(blob.data, 0);
fsinfo->volume_info.out.serial_number = IVAL(blob.data, 8);
smbcli_blob_pull_string(NULL, mem_ctx, &blob,
&fsinfo->volume_info.out.volume_name,
12, 18, STR_UNICODE);
break;
case RAW_QFS_SIZE_INFORMATION:
QFS_CHECK_SIZE(24);
fsinfo->size_info.out.total_alloc_units = BVAL(blob.data, 0);
fsinfo->size_info.out.avail_alloc_units = BVAL(blob.data, 8);
fsinfo->size_info.out.sectors_per_unit = IVAL(blob.data, 16);
fsinfo->size_info.out.bytes_per_sector = IVAL(blob.data, 20);
break;
case RAW_QFS_DEVICE_INFORMATION:
QFS_CHECK_SIZE(8);
fsinfo->device_info.out.device_type = IVAL(blob.data, 0);
fsinfo->device_info.out.characteristics = IVAL(blob.data, 4);
break;
case RAW_QFS_ATTRIBUTE_INFORMATION:
QFS_CHECK_MIN_SIZE(12);
fsinfo->attribute_info.out.fs_attr = IVAL(blob.data, 0);
fsinfo->attribute_info.out.max_file_component_length = IVAL(blob.data, 4);
smbcli_blob_pull_string(NULL, mem_ctx, &blob,
&fsinfo->attribute_info.out.fs_type,
8, 12, STR_UNICODE);
break;
case RAW_QFS_QUOTA_INFORMATION:
QFS_CHECK_SIZE(48);
fsinfo->quota_information.out.unknown[0] = BVAL(blob.data, 0);
fsinfo->quota_information.out.unknown[1] = BVAL(blob.data, 8);
fsinfo->quota_information.out.unknown[2] = BVAL(blob.data, 16);
fsinfo->quota_information.out.quota_soft = BVAL(blob.data, 24);
fsinfo->quota_information.out.quota_hard = BVAL(blob.data, 32);
fsinfo->quota_information.out.quota_flags = BVAL(blob.data, 40);
break;
case RAW_QFS_FULL_SIZE_INFORMATION:
QFS_CHECK_SIZE(32);
fsinfo->full_size_information.out.total_alloc_units = BVAL(blob.data, 0);
fsinfo->full_size_information.out.call_avail_alloc_units = BVAL(blob.data, 8);
fsinfo->full_size_information.out.actual_avail_alloc_units = BVAL(blob.data, 16);
fsinfo->full_size_information.out.sectors_per_unit = IVAL(blob.data, 24);
fsinfo->full_size_information.out.bytes_per_sector = IVAL(blob.data, 28);
break;
case RAW_QFS_OBJECTID_INFORMATION: {
DATA_BLOB b2 = data_blob_const(blob.data, MIN(16, blob.length));
QFS_CHECK_SIZE(64);
status = GUID_from_ndr_blob(&b2, &fsinfo->objectid_information.out.guid);
NT_STATUS_NOT_OK_RETURN(status);
for (i=0;i<6;i++) {
fsinfo->objectid_information.out.unknown[i] = BVAL(blob.data, 16 + i*8);
}
break;
case RAW_QFS_SECTOR_SIZE_INFORMATION:
QFS_CHECK_SIZE(28);
fsinfo->sector_size_info.out.logical_bytes_per_sector
= IVAL(blob.data, 0);
fsinfo->sector_size_info.out.phys_bytes_per_sector_atomic
= IVAL(blob.data, 4);
fsinfo->sector_size_info.out.phys_bytes_per_sector_perf
= IVAL(blob.data, 8);
fsinfo->sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic
= IVAL(blob.data, 12);
fsinfo->sector_size_info.out.flags = IVAL(blob.data, 16);
fsinfo->sector_size_info.out.byte_off_sector_align
= IVAL(blob.data, 20);
fsinfo->sector_size_info.out.byte_off_partition_align
= IVAL(blob.data, 24);
break;
}
default:
status = NT_STATUS_INVALID_INFO_CLASS;
}
failed:
return status;
}
/****************************************************************************
Query FSInfo raw interface (async recv)
****************************************************************************/
NTSTATUS smb_raw_fsinfo_recv(struct smbcli_request *req,
TALLOC_CTX *mem_ctx,
union smb_fsinfo *fsinfo)
{
DATA_BLOB blob;
NTSTATUS status;
struct smbcli_session *session = req?req->session:NULL;
if (fsinfo->generic.level == RAW_QFS_DSKATTR) {
return smb_raw_dskattr_recv(req, fsinfo);
}
status = smb_raw_qfsinfo_blob_recv(req, mem_ctx, &blob);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
/* parse the results */
switch (fsinfo->generic.level) {
case RAW_QFS_GENERIC:
case RAW_QFS_DSKATTR:
/* handled above */
break;
case RAW_QFS_ALLOCATION:
QFS_CHECK_SIZE(18);
fsinfo->allocation.out.fs_id = IVAL(blob.data, 0);
fsinfo->allocation.out.sectors_per_unit = IVAL(blob.data, 4);
fsinfo->allocation.out.total_alloc_units = IVAL(blob.data, 8);
fsinfo->allocation.out.avail_alloc_units = IVAL(blob.data, 12);
fsinfo->allocation.out.bytes_per_sector = SVAL(blob.data, 16);
break;
case RAW_QFS_VOLUME:
QFS_CHECK_MIN_SIZE(5);
fsinfo->volume.out.serial_number = IVAL(blob.data, 0);
smbcli_blob_pull_string(session, mem_ctx, &blob,
&fsinfo->volume.out.volume_name,
4, 5, STR_LEN8BIT | STR_NOALIGN);
break;
case RAW_QFS_VOLUME_INFO:
case RAW_QFS_VOLUME_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_VOLUME_INFORMATION, fsinfo);
case RAW_QFS_SIZE_INFO:
case RAW_QFS_SIZE_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_SIZE_INFORMATION, fsinfo);
case RAW_QFS_DEVICE_INFO:
case RAW_QFS_DEVICE_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_DEVICE_INFORMATION, fsinfo);
case RAW_QFS_ATTRIBUTE_INFO:
case RAW_QFS_ATTRIBUTE_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_ATTRIBUTE_INFORMATION, fsinfo);
case RAW_QFS_UNIX_INFO:
QFS_CHECK_SIZE(12);
fsinfo->unix_info.out.major_version = SVAL(blob.data, 0);
fsinfo->unix_info.out.minor_version = SVAL(blob.data, 2);
fsinfo->unix_info.out.capability = SVAL(blob.data, 4);
break;
case RAW_QFS_QUOTA_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_QUOTA_INFORMATION, fsinfo);
case RAW_QFS_FULL_SIZE_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_FULL_SIZE_INFORMATION, fsinfo);
case RAW_QFS_OBJECTID_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_OBJECTID_INFORMATION, fsinfo);
case RAW_QFS_SECTOR_SIZE_INFORMATION:
return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
RAW_QFS_SECTOR_SIZE_INFORMATION, fsinfo);
}
failed:
return status;
}
/****************************************************************************
Query FSInfo raw interface (sync interface)
****************************************************************************/
_PUBLIC_ NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree,
TALLOC_CTX *mem_ctx,
union smb_fsinfo *fsinfo)
{
struct smbcli_request *req = smb_raw_fsinfo_send(tree, mem_ctx, fsinfo);
return smb_raw_fsinfo_recv(req, mem_ctx, fsinfo);
}
/****************************************************************************
Set FSInfo raw interface (async recv)
****************************************************************************/
static NTSTATUS smb_raw_setfsinfo_recv(struct smbcli_request *req,
TALLOC_CTX *mem_ctx,
union smb_setfsinfo *set_fsinfo)
{
DATA_BLOB blob = data_blob_null;
NTSTATUS status;
if (set_fsinfo->generic.level != RAW_SETFS_UNIX_INFO) {
return NT_STATUS_INVALID_PARAMETER;
}
status = smb_raw_qfsinfo_blob_recv(req, mem_ctx, &blob);
data_blob_free(&blob);
return status;
}
/****************************************************************************
Set FSInfo raw interface (async send)
****************************************************************************/
static struct smbcli_request *smb_raw_setfsinfo_send(struct smbcli_tree *tree,
TALLOC_CTX *mem_ctx,
union smb_setfsinfo *set_fsinfo)
{
struct smb_trans2 tp;
uint16_t info_level;
uint16_t setup = TRANSACT2_SETFSINFO;
if (set_fsinfo->generic.level != RAW_SETFS_UNIX_INFO) {
return NULL;
}
tp.in.max_setup = 0;
tp.in.flags = 0;
tp.in.timeout = 0;
tp.in.setup_count = 1;
tp.in.max_param = 0;
tp.in.max_data = 0xFFFF;
tp.in.setup = &setup;
tp.in.timeout = 0;
tp.in.params = data_blob_talloc(mem_ctx, NULL, 4);
if (!tp.in.params.data) {
return NULL;
}
info_level = (uint16_t)set_fsinfo->generic.level;
SSVAL(tp.in.params.data, 0, 0);
SSVAL(tp.in.params.data, 2, info_level);
tp.in.data = data_blob_talloc(mem_ctx, NULL, 12);
if (!tp.in.data.data) {
return NULL;
}
SSVAL(tp.in.data.data, 0, set_fsinfo->unix_info.in.major_version);
SSVAL(tp.in.data.data, 2, set_fsinfo->unix_info.in.minor_version);
SBVAL(tp.in.data.data, 4, set_fsinfo->unix_info.in.capability);
return smb_raw_trans2_send(tree, &tp);
}
/****************************************************************************
Set FSInfo raw interface (sync interface)
****************************************************************************/
_PUBLIC_ NTSTATUS smb_raw_setfsinfo(struct smbcli_tree *tree,
TALLOC_CTX *mem_ctx,
union smb_setfsinfo *set_fsinfo)
{
struct smbcli_request *req = smb_raw_setfsinfo_send(tree, mem_ctx, set_fsinfo);
return smb_raw_setfsinfo_recv(req, mem_ctx, set_fsinfo);
}
|