summaryrefslogtreecommitdiffstats
path: root/source4/libcli/raw/rawfileinfo.c
blob: 92d31b30ef108aa2b77a36b9b4efa57887d2d7ae (plain)
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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
/* 
   Unix SMB/CIFS implementation.
   client trans2 operations
   Copyright (C) James Myers 2003
   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 2 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, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "includes.h"
#include "libcli/raw/libcliraw.h"

/* local macros to make the code more readable */
#define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \
      DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected min of %d\n", \
	       (int)blob->length, parms->generic.level, (size))); \
      return NT_STATUS_INFO_LENGTH_MISMATCH; \
}
#define FINFO_CHECK_SIZE(size) if (blob->length != (size)) { \
      DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected %d\n", \
	       (int)blob->length, parms->generic.level, (size))); \
      return NT_STATUS_INFO_LENGTH_MISMATCH; \
}

/*
  parse a stream information structure
*/
NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx,
				  struct stream_information *io)
{
	uint32_t ofs = 0;
	io->num_streams = 0;
	io->streams = NULL;

	while (blob.length - ofs >= 24) {
		uint_t n = io->num_streams;
		uint32_t nlen, len;
		ssize_t size;
		void *vstr;
		io->streams = 
			talloc_realloc(mem_ctx, io->streams, struct stream_struct, n+1);
		if (!io->streams) {
			return NT_STATUS_NO_MEMORY;
		}
		nlen                      = IVAL(blob.data, ofs + 0x04);
		io->streams[n].size       = BVAL(blob.data, ofs + 0x08);
		io->streams[n].alloc_size = BVAL(blob.data, ofs + 0x10);
		if (nlen > blob.length - (ofs + 24)) {
			return NT_STATUS_INFO_LENGTH_MISMATCH;
		}
		size = convert_string_talloc(io->streams, CH_UTF16, CH_UNIX,
					     blob.data+ofs+24, nlen, &vstr);
		if (size == -1) {
			return NT_STATUS_ILLEGAL_CHARACTER;
		}
		io->streams[n].stream_name.s = vstr;
		io->streams[n].stream_name.private_length = nlen;
		io->num_streams++;
		len = IVAL(blob.data, ofs);
		if (len > blob.length - ofs) {
			return NT_STATUS_INFO_LENGTH_MISMATCH;
		}
		if (len == 0) break;
		ofs += len;
	}

	return NT_STATUS_OK;
}

/*
  parse the fsinfo 'passthru' level replies
*/
NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, 
					 enum smb_fileinfo_level level,
					 union smb_fileinfo *parms)
{	
	switch (level) {
	case RAW_FILEINFO_BASIC_INFORMATION:
		/* some servers return 40 bytes and some 36. w2k3 return 40, so thats
		   what we should do, but we need to accept 36 */
		if (blob->length != 36) {
			FINFO_CHECK_SIZE(40);
		}
		parms->basic_info.out.create_time = smbcli_pull_nttime(blob->data, 0);
		parms->basic_info.out.access_time = smbcli_pull_nttime(blob->data, 8);
		parms->basic_info.out.write_time  = smbcli_pull_nttime(blob->data, 16);
		parms->basic_info.out.change_time = smbcli_pull_nttime(blob->data, 24);
		parms->basic_info.out.attrib      = IVAL(blob->data, 32);
		return NT_STATUS_OK;

	case RAW_FILEINFO_STANDARD_INFORMATION:
		FINFO_CHECK_SIZE(24);
		parms->standard_info.out.alloc_size =     BVAL(blob->data, 0);
		parms->standard_info.out.size =           BVAL(blob->data, 8);
		parms->standard_info.out.nlink =          IVAL(blob->data, 16);
		parms->standard_info.out.delete_pending = CVAL(blob->data, 20);
		parms->standard_info.out.directory =      CVAL(blob->data, 21);
		return NT_STATUS_OK;

	case RAW_FILEINFO_EA_INFORMATION:
		FINFO_CHECK_SIZE(4);
		parms->ea_info.out.ea_size = IVAL(blob->data, 0);
		return NT_STATUS_OK;

	case RAW_FILEINFO_NAME_INFORMATION:
		FINFO_CHECK_MIN_SIZE(4);
		smbcli_blob_pull_string(NULL, mem_ctx, blob, 
					&parms->name_info.out.fname, 0, 4, STR_UNICODE);
		return NT_STATUS_OK;

	case RAW_FILEINFO_ALL_INFORMATION:
		FINFO_CHECK_MIN_SIZE(72);
		parms->all_info.out.create_time =           smbcli_pull_nttime(blob->data, 0);
		parms->all_info.out.access_time =           smbcli_pull_nttime(blob->data, 8);
		parms->all_info.out.write_time =            smbcli_pull_nttime(blob->data, 16);
		parms->all_info.out.change_time =           smbcli_pull_nttime(blob->data, 24);
		parms->all_info.out.attrib =                IVAL(blob->data, 32);
		parms->all_info.out.alloc_size =            BVAL(blob->data, 40);
		parms->all_info.out.size =                  BVAL(blob->data, 48);
		parms->all_info.out.nlink =                 IVAL(blob->data, 56);
		parms->all_info.out.delete_pending =        CVAL(blob->data, 60);
		parms->all_info.out.directory =             CVAL(blob->data, 61);
#if 1
		parms->all_info.out.ea_size =               IVAL(blob->data, 64);
		smbcli_blob_pull_string(NULL, mem_ctx, blob,
					&parms->all_info.out.fname, 68, 72, STR_UNICODE);
#else
		/* this is what the CIFS spec says - and its totally
		   wrong, but its useful having it here so we can
		   quickly adapt to broken servers when running
		   tests */
		parms->all_info.out.ea_size =               IVAL(blob->data, 72);
		/* access flags 4 bytes at 76
		   current_position 8 bytes at 80
		   mode 4 bytes at 88
		   alignment 4 bytes at 92
		*/
		smbcli_blob_pull_string(NULL, mem_ctx, blob,
					&parms->all_info.out.fname, 96, 100, STR_UNICODE);
#endif
		return NT_STATUS_OK;

	case RAW_FILEINFO_ALT_NAME_INFORMATION:
		FINFO_CHECK_MIN_SIZE(4);
		smbcli_blob_pull_string(NULL, mem_ctx, blob, 
					&parms->alt_name_info.out.fname, 0, 4, STR_UNICODE);
		return NT_STATUS_OK;

	case RAW_FILEINFO_STREAM_INFORMATION:
		return smbcli_parse_stream_info(*blob, mem_ctx, &parms->stream_info.out);

	case RAW_FILEINFO_INTERNAL_INFORMATION:
		FINFO_CHECK_SIZE(8);
		parms->internal_information.out.file_id = BVAL(blob->data, 0);
		return NT_STATUS_OK;

	case RAW_FILEINFO_ACCESS_INFORMATION:
		FINFO_CHECK_SIZE(4);
		parms->access_information.out.access_flags = IVAL(blob->data, 0);
		return NT_STATUS_OK;

	case RAW_FILEINFO_POSITION_INFORMATION:
		FINFO_CHECK_SIZE(8);
		parms->position_information.out.position = BVAL(blob->data, 0);
		return NT_STATUS_OK;

	case RAW_FILEINFO_MODE_INFORMATION:
		FINFO_CHECK_SIZE(4);
		parms->mode_information.out.mode = IVAL(blob->data, 0);
		return NT_STATUS_OK;

	case RAW_FILEINFO_ALIGNMENT_INFORMATION:
		FINFO_CHECK_SIZE(4);
		parms->alignment_information.out.alignment_requirement 
			= IVAL(blob->data, 0);
		return NT_STATUS_OK;

	case RAW_FILEINFO_COMPRESSION_INFORMATION:
		FINFO_CHECK_SIZE(16);
		parms->compression_info.out.compressed_size = BVAL(blob->data,  0);
		parms->compression_info.out.format          = SVAL(blob->data,  8);
		parms->compression_info.out.unit_shift      = CVAL(blob->data, 10);
		parms->compression_info.out.chunk_shift     = CVAL(blob->data, 11);
		parms->compression_info.out.cluster_shift   = CVAL(blob->data, 12);
		/* 3 bytes of padding */
		return NT_STATUS_OK;

	case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:		
		FINFO_CHECK_SIZE(56);
		parms->network_open_information.out.create_time = smbcli_pull_nttime(blob->data,  0);
		parms->network_open_information.out.access_time = smbcli_pull_nttime(blob->data,  8);
		parms->network_open_information.out.write_time =  smbcli_pull_nttime(blob->data, 16);
		parms->network_open_information.out.change_time = smbcli_pull_nttime(blob->data, 24);
		parms->network_open_information.out.alloc_size =             BVAL(blob->data, 32);
		parms->network_open_information.out.size = 	             BVAL(blob->data, 40);
		parms->network_open_information.out.attrib = 	             IVAL(blob->data, 48);
		return NT_STATUS_OK;

	case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
		FINFO_CHECK_SIZE(8);
		parms->attribute_tag_information.out.attrib =      IVAL(blob->data, 0);
		parms->attribute_tag_information.out.reparse_tag = IVAL(blob->data, 4);
		return NT_STATUS_OK;

	case RAW_FILEINFO_SMB2_ALL_EAS:
		FINFO_CHECK_MIN_SIZE(4);
		return ea_pull_list_chained(blob, mem_ctx, 
					    &parms->all_eas.out.num_eas,
					    &parms->all_eas.out.eas);

	case RAW_FILEINFO_SMB2_ALL_INFORMATION:
		FINFO_CHECK_MIN_SIZE(0x64);
		parms->all_info2.out.create_time    = smbcli_pull_nttime(blob->data, 0x00);
		parms->all_info2.out.access_time    = smbcli_pull_nttime(blob->data, 0x08);
		parms->all_info2.out.write_time     = smbcli_pull_nttime(blob->data, 0x10);
		parms->all_info2.out.change_time    = smbcli_pull_nttime(blob->data, 0x18);
		parms->all_info2.out.attrib         = IVAL(blob->data, 0x20);
		parms->all_info2.out.unknown1       = IVAL(blob->data, 0x24);
		parms->all_info2.out.alloc_size     = BVAL(blob->data, 0x28);
		parms->all_info2.out.size           = BVAL(blob->data, 0x30);
		parms->all_info2.out.nlink          = IVAL(blob->data, 0x38);
		parms->all_info2.out.delete_pending = CVAL(blob->data, 0x3C);
		parms->all_info2.out.directory      = CVAL(blob->data, 0x3D);
		parms->all_info2.out.file_id        = BVAL(blob->data, 0x40);
		parms->all_info2.out.ea_size        = IVAL(blob->data, 0x48);
		parms->all_info2.out.access_mask    = IVAL(blob->data, 0x4C);
		parms->all_info2.out.position       = BVAL(blob->data, 0x50);
		parms->all_info2.out.mode           = BVAL(blob->data, 0x58);
		smbcli_blob_pull_string(NULL, mem_ctx, blob,
					&parms->all_info2.out.fname, 0x60, 0x64, STR_UNICODE);
		return NT_STATUS_OK;

	case RAW_FILEINFO_SEC_DESC: {
		struct ndr_pull *ndr;
		NTSTATUS status;
		ndr = ndr_pull_init_blob(blob, mem_ctx);
		if (!ndr) {
			return NT_STATUS_NO_MEMORY;
		}
		parms->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor);
		if (parms->query_secdesc.out.sd == NULL) {
			return NT_STATUS_NO_MEMORY;
		}
		status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, 
						      parms->query_secdesc.out.sd);
		talloc_free(ndr);
		return status;
	}

	default:
		break;
	}

	return NT_STATUS_INVALID_LEVEL;
}


/****************************************************************************
 Handle qfileinfo/qpathinfo trans2 backend.
****************************************************************************/
static NTSTATUS smb_raw_info_backend(struct smbcli_session *session,
				     TALLOC_CTX *mem_ctx,
				     union smb_fileinfo *parms, 
				     DATA_BLOB *blob)
{	
	switch (parms->generic.level) {
	case RAW_FILEINFO_GENERIC:
	case RAW_FILEINFO_GETATTR:
	case RAW_FILEINFO_GETATTRE:
	case RAW_FILEINFO_SEC_DESC:
		/* not handled here */
		return NT_STATUS_INVALID_LEVEL;

	case RAW_FILEINFO_STANDARD:
		FINFO_CHECK_SIZE(22);
		parms->standard.out.create_time = raw_pull_dos_date2(session->transport,
								     blob->data +  0);
		parms->standard.out.access_time = raw_pull_dos_date2(session->transport,
								     blob->data +  4);
		parms->standard.out.write_time =  raw_pull_dos_date2(session->transport,
								     blob->data +  8);
		parms->standard.out.size =        IVAL(blob->data,             12);
		parms->standard.out.alloc_size =  IVAL(blob->data,             16);
		parms->standard.out.attrib =      SVAL(blob->data,             20);
		return NT_STATUS_OK;

	case RAW_FILEINFO_EA_SIZE:
		FINFO_CHECK_SIZE(26);
		parms->ea_size.out.create_time = raw_pull_dos_date2(session->transport,
								    blob->data +  0);
		parms->ea_size.out.access_time = raw_pull_dos_date2(session->transport,
								    blob->data +  4);
		parms->ea_size.out.write_time =  raw_pull_dos_date2(session->transport,
								    blob->data +  8);
		parms->ea_size.out.size =        IVAL(blob->data,             12);
		parms->ea_size.out.alloc_size =  IVAL(blob->data,             16);
		parms->ea_size.out.attrib =      SVAL(blob->data,             20);
		parms->ea_size.out.ea_size =     IVAL(blob->data,             22);
		return NT_STATUS_OK;

	case RAW_FILEINFO_EA_LIST:
		FINFO_CHECK_MIN_SIZE(4);
		return ea_pull_list(blob, mem_ctx, 
				    &parms->ea_list.out.num_eas,
				    &parms->ea_list.out.eas);

	case RAW_FILEINFO_ALL_EAS:
		FINFO_CHECK_MIN_SIZE(4);
		return ea_pull_list(blob, mem_ctx, 
				    &parms->all_eas.out.num_eas,
				    &parms->all_eas.out.eas);

	case RAW_FILEINFO_IS_NAME_VALID:
		/* no data! */
		FINFO_CHECK_SIZE(0);
		return NT_STATUS_OK;

	case RAW_FILEINFO_BASIC_INFO:
	case RAW_FILEINFO_BASIC_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_BASIC_INFORMATION, parms);

	case RAW_FILEINFO_STANDARD_INFO:
	case RAW_FILEINFO_STANDARD_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_STANDARD_INFORMATION, parms);

	case RAW_FILEINFO_EA_INFO:
	case RAW_FILEINFO_EA_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_EA_INFORMATION, parms);

	case RAW_FILEINFO_NAME_INFO:
	case RAW_FILEINFO_NAME_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_NAME_INFORMATION, parms);

	case RAW_FILEINFO_ALL_INFO:
	case RAW_FILEINFO_ALL_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_ALL_INFORMATION, parms);

	case RAW_FILEINFO_ALT_NAME_INFO:
	case RAW_FILEINFO_ALT_NAME_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_ALT_NAME_INFORMATION, parms);

	case RAW_FILEINFO_STREAM_INFO:
	case RAW_FILEINFO_STREAM_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_STREAM_INFORMATION, parms);

	case RAW_FILEINFO_INTERNAL_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_INTERNAL_INFORMATION, parms);

	case RAW_FILEINFO_ACCESS_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_ACCESS_INFORMATION, parms);

	case RAW_FILEINFO_POSITION_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_POSITION_INFORMATION, parms);

	case RAW_FILEINFO_MODE_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_MODE_INFORMATION, parms);

	case RAW_FILEINFO_ALIGNMENT_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_ALIGNMENT_INFORMATION, parms);

	case RAW_FILEINFO_COMPRESSION_INFO:
	case RAW_FILEINFO_COMPRESSION_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_COMPRESSION_INFORMATION, parms);

	case RAW_FILEINFO_UNIX_BASIC:
		FINFO_CHECK_SIZE(100);
		parms->unix_basic_info.out.end_of_file        =            BVAL(blob->data,  0);
		parms->unix_basic_info.out.num_bytes          =            BVAL(blob->data,  8);
		parms->unix_basic_info.out.status_change_time = smbcli_pull_nttime(blob->data, 16);
		parms->unix_basic_info.out.access_time        = smbcli_pull_nttime(blob->data, 24);
		parms->unix_basic_info.out.change_time        = smbcli_pull_nttime(blob->data, 32);
		parms->unix_basic_info.out.uid                =            BVAL(blob->data, 40);
		parms->unix_basic_info.out.gid                =            BVAL(blob->data, 48);
		parms->unix_basic_info.out.file_type          =            IVAL(blob->data, 52);
		parms->unix_basic_info.out.dev_major          =            BVAL(blob->data, 60);
		parms->unix_basic_info.out.dev_minor          =            BVAL(blob->data, 68);
		parms->unix_basic_info.out.unique_id          =            BVAL(blob->data, 76);
		parms->unix_basic_info.out.permissions        =            BVAL(blob->data, 84);
		parms->unix_basic_info.out.nlink              =            BVAL(blob->data, 92);
		return NT_STATUS_OK;

	case RAW_FILEINFO_UNIX_LINK:
		smbcli_blob_pull_string(session, mem_ctx, blob, 
				     &parms->unix_link_info.out.link_dest, 0, 4, STR_UNICODE);
		return NT_STATUS_OK;
		
	case RAW_FILEINFO_NETWORK_OPEN_INFORMATION:		
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_NETWORK_OPEN_INFORMATION, parms);

	case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION, parms);

	case RAW_FILEINFO_SMB2_ALL_INFORMATION:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_SMB2_ALL_INFORMATION, parms);

	case RAW_FILEINFO_SMB2_ALL_EAS:
		return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, 
						       RAW_FILEINFO_SMB2_ALL_EAS, parms);

	}

	return NT_STATUS_INVALID_LEVEL;
}


/****************************************************************************
 Very raw query file info - returns param/data blobs - (async send)
****************************************************************************/
static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tree,
							 uint16_t fnum, 
							 uint16_t info_level,
							 DATA_BLOB data)
{
	struct smb_trans2 tp;
	uint16_t setup = TRANSACT2_QFILEINFO;
	struct smbcli_request *req;
	TALLOC_CTX *mem_ctx = talloc_init("raw_fileinfo");
	
	tp.in.max_setup = 0;
	tp.in.flags = 0; 
	tp.in.timeout = 0;
	tp.in.setup_count = 1;
	tp.in.data = data;
	tp.in.max_param = 2;
	tp.in.max_data = 0xFFFF;
	tp.in.setup = &setup;
	
	tp.in.params = data_blob_talloc(mem_ctx, NULL, 4);
	if (!tp.in.params.data) {
		talloc_free(mem_ctx);
		return NULL;
	}

	SSVAL(tp.in.params.data, 0, fnum);
	SSVAL(tp.in.params.data, 2, info_level);

	req = smb_raw_trans2_send(tree, &tp);

	talloc_free(mem_ctx);

	return req;
}


/****************************************************************************
 Very raw query file info - returns param/data blobs - (async recv)
****************************************************************************/
static NTSTATUS smb_raw_fileinfo_blob_recv(struct smbcli_request *req,
					   TALLOC_CTX *mem_ctx,
					   DATA_BLOB *blob)
{
	struct smb_trans2 tp;
	NTSTATUS status = smb_raw_trans2_recv(req, mem_ctx, &tp);
	if (NT_STATUS_IS_OK(status)) {
		*blob = tp.out.data;
	}
	return status;
}

/****************************************************************************
 Very raw query path info - returns param/data blobs (async send)
****************************************************************************/
static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tree,
							 const char *fname,
							 uint16_t info_level,
							 DATA_BLOB data)
{
	struct smb_trans2 tp;
	uint16_t setup = TRANSACT2_QPATHINFO;
	struct smbcli_request *req;
	TALLOC_CTX *mem_ctx = talloc_init("raw_pathinfo");

	tp.in.max_setup = 0;
	tp.in.flags = 0; 
	tp.in.timeout = 0;
	tp.in.setup_count = 1;
	tp.in.data = data;
	tp.in.max_param = 2;
	tp.in.max_data = 0xFFFF;
	tp.in.setup = &setup;
	
	tp.in.params = data_blob_talloc(mem_ctx, NULL, 6);
	if (!tp.in.params.data) {
		talloc_free(mem_ctx);
		return NULL;
	}

	SSVAL(tp.in.params.data, 0, info_level);
	SIVAL(tp.in.params.data, 2, 0);
	smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params,
			       fname, STR_TERMINATE);
	
	req = smb_raw_trans2_send(tree, &tp);

	talloc_free(mem_ctx);

	return req;
}

/****************************************************************************
 send a SMBgetatr (async send)
****************************************************************************/
static struct smbcli_request *smb_raw_getattr_send(struct smbcli_tree *tree,
						union smb_fileinfo *parms)
{
	struct smbcli_request *req;
	
	req = smbcli_request_setup(tree, SMBgetatr, 0, 0);
	if (!req) return NULL;

	smbcli_req_append_ascii4(req, parms->getattr.in.fname, STR_TERMINATE);
	
	if (!smbcli_request_send(req)) {
		smbcli_request_destroy(req);
		return NULL;
	}

	return req;
}

/****************************************************************************
 send a SMBgetatr (async recv)
****************************************************************************/
static NTSTATUS smb_raw_getattr_recv(struct smbcli_request *req,
				     union smb_fileinfo *parms)
{
	if (!smbcli_request_receive(req) ||
	    smbcli_request_is_error(req)) {
		return smbcli_request_destroy(req);
	}

	SMBCLI_CHECK_WCT(req, 10);
	parms->getattr.out.attrib =     SVAL(req->in.vwv, VWV(0));
	parms->getattr.out.write_time = raw_pull_dos_date3(req->transport,
							   req->in.vwv + VWV(1));
	parms->getattr.out.size =       IVAL(req->in.vwv, VWV(3));

failed:
	return smbcli_request_destroy(req);
}


/****************************************************************************
 Handle SMBgetattrE (async send)
****************************************************************************/
static struct smbcli_request *smb_raw_getattrE_send(struct smbcli_tree *tree,
						 union smb_fileinfo *parms)
{
	struct smbcli_request *req;
	
	req = smbcli_request_setup(tree, SMBgetattrE, 1, 0);
	if (!req) return NULL;
	
	SSVAL(req->out.vwv, VWV(0), parms->getattre.in.fnum);
	if (!smbcli_request_send(req)) {
		smbcli_request_destroy(req);
		return NULL;
	}

	return req;
}

/****************************************************************************
 Handle SMBgetattrE (async send)
****************************************************************************/
static NTSTATUS smb_raw_getattrE_recv(struct smbcli_request *req,
				      union smb_fileinfo *parms)
{
	if (!smbcli_request_receive(req) ||
	    smbcli_request_is_error(req)) {
		return smbcli_request_destroy(req);
	}
	
	SMBCLI_CHECK_WCT(req, 11);
	parms->getattre.out.create_time =   raw_pull_dos_date2(req->transport,
							       req->in.vwv + VWV(0));
	parms->getattre.out.access_time =   raw_pull_dos_date2(req->transport,
							       req->in.vwv + VWV(2));
	parms->getattre.out.write_time  =   raw_pull_dos_date2(req->transport,
							       req->in.vwv + VWV(4));
	parms->getattre.out.size =          IVAL(req->in.vwv,             VWV(6));
	parms->getattre.out.alloc_size =    IVAL(req->in.vwv,             VWV(8));
	parms->getattre.out.attrib =        SVAL(req->in.vwv,             VWV(10));

failed:
	return smbcli_request_destroy(req);
}


/****************************************************************************
 Query file info (async send)
****************************************************************************/
struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree,
					     union smb_fileinfo *parms)
{
	DATA_BLOB data;
	struct smbcli_request *req;

	/* pass off the non-trans2 level to specialised functions */
	if (parms->generic.level == RAW_FILEINFO_GETATTRE) {
		return smb_raw_getattrE_send(tree, parms);
	}
	if (parms->generic.level == RAW_FILEINFO_SEC_DESC) {
		return smb_raw_query_secdesc_send(tree, parms);
	}
	if (parms->generic.level >= RAW_FILEINFO_GENERIC) {
		return NULL;
	}

	data = data_blob(NULL, 0);

	if (parms->generic.level == RAW_FILEINFO_EA_LIST) {
		if (!ea_push_name_list(tree, 
				       &data,
				       parms->ea_list.in.num_names,
				       parms->ea_list.in.ea_names)) {
			return NULL;
		}
	}

	req = smb_raw_fileinfo_blob_send(tree, 
					 parms->generic.in.fnum,
					 parms->generic.level, data);

	data_blob_free(&data);

	return req;
}

/****************************************************************************
 Query file info (async recv)
****************************************************************************/
NTSTATUS smb_raw_fileinfo_recv(struct smbcli_request *req,
			       TALLOC_CTX *mem_ctx,
			       union smb_fileinfo *parms)
{
	DATA_BLOB blob;
	NTSTATUS status;
	struct smbcli_session *session = req?req->session:NULL;

	if (parms->generic.level == RAW_FILEINFO_GETATTRE) {
		return smb_raw_getattrE_recv(req, parms);
	}
	if (parms->generic.level == RAW_FILEINFO_SEC_DESC) {
		return smb_raw_query_secdesc_recv(req, mem_ctx, parms);
	}
	if (parms->generic.level == RAW_FILEINFO_GETATTR) {
		return smb_raw_getattr_recv(req, parms);
	}

	status = smb_raw_fileinfo_blob_recv(req, mem_ctx, &blob);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	return smb_raw_info_backend(session, mem_ctx, parms, &blob);
}

/****************************************************************************
 Query file info (sync interface)
****************************************************************************/
NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree,
			  TALLOC_CTX *mem_ctx,
			  union smb_fileinfo *parms)
{
	struct smbcli_request *req = smb_raw_fileinfo_send(tree, parms);
	return smb_raw_fileinfo_recv(req, mem_ctx, parms);
}

/****************************************************************************
 Query path info (async send)
****************************************************************************/
struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree,
					     union smb_fileinfo *parms)
{
	DATA_BLOB data;
	struct smbcli_request *req;

	if (parms->generic.level == RAW_FILEINFO_GETATTR) {
		return smb_raw_getattr_send(tree, parms);
	}
	if (parms->generic.level >= RAW_FILEINFO_GENERIC) {
		return NULL;
	}
	
	data = data_blob(NULL, 0);

	if (parms->generic.level == RAW_FILEINFO_EA_LIST) {
		if (!ea_push_name_list(tree, 
				       &data,
				       parms->ea_list.in.num_names,
				       parms->ea_list.in.ea_names)) {
			return NULL;
		}
	}

	req = smb_raw_pathinfo_blob_send(tree, parms->generic.in.fname,
					 parms->generic.level, data);
	data_blob_free(&data);

	return req;
}

/****************************************************************************
 Query path info (async recv)
****************************************************************************/
NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req,
			       TALLOC_CTX *mem_ctx,
			       union smb_fileinfo *parms)
{
	/* recv is idential to fileinfo */
	return smb_raw_fileinfo_recv(req, mem_ctx, parms);
}

/****************************************************************************
 Query path info (sync interface)
****************************************************************************/
NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree,
			  TALLOC_CTX *mem_ctx,
			  union smb_fileinfo *parms)
{
	struct smbcli_request *req = smb_raw_pathinfo_send(tree, parms);
	return smb_raw_pathinfo_recv(req, mem_ctx, parms);
}