r21206: - a couple more nttrans places were a memcpy() should be used
[samba.git] / source / libcli / raw / interfaces.h
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB request interface structures
4    Copyright (C) Andrew Tridgell                        2003
5    Copyright (C) James J Myers 2003 <myersjj@samba.org>
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef __LIBCLI_RAW_INTERFACES_H__
23 #define __LIBCLI_RAW_INTERFACES_H__
24
25 #include "smb.h" 
26
27 /* this structure is just a wrapper for a string, the only reason we
28    bother with this is that it allows us to check the length provided
29    on the wire in testsuite test code to ensure that we are
30    terminating names in the same way that win2003 is. The *ONLY* time
31    you should ever look at the 'private_length' field in this
32    structure is inside compliance test code, in all other cases just
33    use the null terminated char* as the definitive definition of the
34    string
35
36    also note that this structure is only used in packets where there
37    is an explicit length provided on the wire (hence the name). That
38    length is placed in 'private_length'. For packets where the length
39    is always determined by NULL or packet termination a normal char*
40    is used in the structure definition.
41  */
42 struct smb_wire_string {
43         uint32_t private_length;
44         const char *s;
45 };
46
47 /*
48  * SMB2 uses a 16Byte handle,
49  * (we can maybe use struct GUID later)
50  */
51 struct smb2_handle {
52         uint64_t data[2];
53 };
54
55 struct ntvfs_handle;
56
57 /*
58  * a generic container for file handles or file pathes
59  * for qfileinfo/setfileinfo and qpathinfo/setpathinfo
60 */
61 union smb_handle_or_path {
62         /*
63          * this is used for
64          * the qpathinfo and setpathinfo
65          * calls
66          */
67         const char *path;
68         /*
69          * this is used as file handle in SMB
70          */
71         uint16_t fnum;
72
73         /*
74          * this is used as file handle in SMB2
75          */
76         struct smb2_handle handle;
77
78         /*
79          * this is used as generic file handle for the NTVFS layer
80          */
81         struct ntvfs_handle *ntvfs;
82 };
83
84 /*
85  a generic container for file handles
86 */
87 union smb_handle {
88         /*
89          * this is used as file handle in SMB
90          */
91         uint16_t fnum;
92
93         /*
94          * this is used as file handle in SMB2
95          */
96         struct smb2_handle handle;
97
98         /*
99          * this is used as generic file handle for the NTVFS layer
100          */
101         struct ntvfs_handle *ntvfs;
102 };
103
104 /*
105   this header defines the structures and unions used between the SMB
106   parser and the backends.
107 */
108
109 /* struct used for SMBlseek call */
110 union smb_seek {
111         struct {
112                 struct {
113                         union smb_handle file;
114                         uint16_t mode;
115                         int32_t  offset; /* signed */
116                 } in;
117                 struct {
118                         int32_t offset;
119                 } out;
120         } lseek, generic;
121 };
122
123 /* struct used in unlink() call */
124 union smb_unlink {
125         struct {
126                 struct {
127                         const char *pattern;
128                         uint16_t attrib;
129                 } in;
130         } unlink;
131 };
132
133
134 /* struct used in chkpath() call */
135 union smb_chkpath {
136         struct {
137                 struct {
138                         const char *path;
139                 } in;
140         } chkpath;
141 };
142
143 enum smb_mkdir_level {RAW_MKDIR_GENERIC, RAW_MKDIR_MKDIR, RAW_MKDIR_T2MKDIR};
144
145 /* union used in mkdir() call */
146 union smb_mkdir {
147         /* generic level */
148         struct {
149                 enum smb_mkdir_level level;
150         } generic;
151
152         struct {
153                 enum smb_mkdir_level level;
154                 struct {
155                         const char *path;
156                 } in;
157         } mkdir;
158
159         struct {
160                 enum smb_mkdir_level level;
161                 struct {
162                         const char *path;
163                         uint_t num_eas;
164                         struct ea_struct *eas;                  
165                 } in;
166         } t2mkdir;
167 };
168
169 /* struct used in rmdir() call */
170 struct smb_rmdir {
171         struct {
172                 const char *path;
173         } in;
174 };
175
176 /* struct used in rename() call */
177 enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME};
178
179 union smb_rename {
180         struct {
181                 enum smb_rename_level level;
182         } generic;
183
184         /* SMBrename interface */
185         struct {
186                 enum smb_rename_level level;
187
188                 struct {
189                         const char *pattern1;
190                         const char *pattern2;
191                         uint16_t attrib;
192                 } in;
193         } rename;
194
195
196         /* SMBntrename interface */
197         struct {
198                 enum smb_rename_level level;
199
200                 struct {
201                         uint16_t attrib;
202                         uint16_t flags; /* see RENAME_FLAG_* */
203                         uint32_t cluster_size;
204                         const char *old_name;
205                         const char *new_name;
206                 } in;
207         } ntrename;
208 };
209
210 enum smb_tcon_level {
211         RAW_TCON_TCON,
212         RAW_TCON_TCONX,
213         RAW_TCON_SMB2
214 };
215
216 /* union used in tree connect call */
217 union smb_tcon {
218         /* generic interface */
219         struct {
220                 enum smb_tcon_level level;
221         } generic;
222
223         /* SMBtcon interface */
224         struct {
225                 enum smb_tcon_level level;
226
227                 struct {
228                         const char *service;
229                         const char *password;
230                         const char *dev;
231                 } in;
232                 struct {
233                         uint16_t max_xmit;
234                         uint16_t tid;
235                 } out;
236         } tcon;
237
238         /* SMBtconX interface */
239         struct {
240                 enum smb_tcon_level level;
241
242                 struct {
243                         uint16_t flags;
244                         DATA_BLOB password;
245                         const char *path;
246                         const char *device;
247                 } in;
248                 struct {
249                         uint16_t options;
250                         char *dev_type;
251                         char *fs_type;
252                         uint16_t tid;
253                 } out;
254         } tconx;
255
256         /* SMB2 TreeConnect */
257         struct smb2_tree_connect {
258                 enum smb_tcon_level level;
259
260                 struct {
261                         /* static body buffer 8 (0x08) bytes */
262                         /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
263                         uint16_t unknown1; /* 0x0000 */
264                         /* uint16_t path_ofs */
265                         /* uint16_t path_size */
266         
267                         /* dynamic body */
268                         const char *path; /* as non-terminated UTF-16 on the wire */
269                 } in;
270                 struct {
271                         /* static body buffer 16 (0x10) bytes */
272                         /* uint16_t buffer_code;  0x10 */
273                         uint16_t unknown1; /* 0x02 */
274                         uint32_t unknown2; /* 0x00 */
275                         uint32_t unknown3; /* 0x00 */
276                         uint32_t access_mask;
277         
278                         /* extracted from the SMB2 header */
279                         uint32_t tid;
280                 } out;
281         } smb2;
282 };
283
284
285 enum smb_sesssetup_level {
286         RAW_SESSSETUP_OLD,
287         RAW_SESSSETUP_NT1,
288         RAW_SESSSETUP_SPNEGO,
289         RAW_SESSSETUP_SMB2
290 };
291
292 /* union used in session_setup call */
293 union smb_sesssetup {
294         /* the pre-NT1 interface */
295         struct {
296                 enum smb_sesssetup_level level;
297
298                 struct {
299                         uint16_t bufsize;
300                         uint16_t mpx_max;
301                         uint16_t vc_num;
302                         uint32_t sesskey;
303                         DATA_BLOB password;
304                         const char *user;
305                         const char *domain;
306                         const char *os;
307                         const char *lanman;
308                 } in;
309                 struct {
310                         uint16_t action;
311                         uint16_t vuid;
312                         char *os;
313                         char *lanman;
314                         char *domain;
315                 } out;
316         } old;
317
318         /* the NT1 interface */
319         struct {
320                 enum smb_sesssetup_level level;
321
322                 struct {
323                         uint16_t bufsize;
324                         uint16_t mpx_max;
325                         uint16_t vc_num;
326                         uint32_t sesskey;
327                         uint32_t capabilities;
328                         DATA_BLOB password1;
329                         DATA_BLOB password2;
330                         const char *user;
331                         const char *domain;
332                         const char *os;
333                         const char *lanman;
334                 } in;
335                 struct {
336                         uint16_t action;
337                         uint16_t vuid;
338                         char *os;
339                         char *lanman;
340                         char *domain;
341                 } out;
342         } nt1;
343
344
345         /* the SPNEGO interface */
346         struct {
347                 enum smb_sesssetup_level level;
348
349                 struct {
350                         uint16_t bufsize;
351                         uint16_t mpx_max;
352                         uint16_t vc_num;
353                         uint32_t sesskey;
354                         uint32_t capabilities;
355                         DATA_BLOB secblob;
356                         const char *os;
357                         const char *lanman;
358                         const char *workgroup;
359                 } in;
360                 struct {
361                         uint16_t action;
362                         DATA_BLOB secblob;
363                         char *os;
364                         char *lanman;
365                         char *workgroup;
366                         uint16_t vuid;
367                 } out;
368         } spnego;
369
370         /* SMB2 SessionSetup */
371         struct smb2_session_setup {
372                 enum smb_sesssetup_level level;
373
374                 struct {
375                         /* NOTE: this was 0x11 = 0x10 + 1 in vista-CTP
376                          * and changed in vista-beta2, but both server's
377                          * can handle the 0x18 clients
378                          */
379                         /* static body buffer 24 (0x18) bytes */
380                         /* uint16_t buffer_code;  0x19 = 0x18 + 1 */
381                         uint16_t _pad;
382                         uint32_t unknown2; /* 0x0000000F(vista-CTP) 0x00000007(vista-beta2) */
383                         uint32_t unknown3; /* 0x0000000 */
384                         /* uint16_t secblob_ofs */
385                         /* uint16_t secblob_size */
386                         uint64_t unknown4; /* 0x0000000000000000 only present in vista-beta2 */
387
388                         /* dynamic body */
389                         DATA_BLOB secblob;
390                 } in;
391                 struct {
392                         /* static body buffer 8 (0x08) bytes */
393                         /* uint16_t buffer_code; 0x09 = 0x08 +1 */
394                         uint16_t _pad;
395                         /* uint16_t secblob_ofs */
396                         /* uint16_t secblob_size */
397
398                         /* dynamic body */
399                         DATA_BLOB secblob;
400
401                         /* extracted from the SMB2 header */
402                         uint64_t uid;
403                 } out;
404         } smb2;
405 };
406
407 /* Note that the specified enum values are identical to the actual info-levels used
408  * on the wire.
409  */
410 enum smb_fileinfo_level {
411                      RAW_FILEINFO_GENERIC                    = 0xF000, 
412                      RAW_FILEINFO_GETATTR,                   /* SMBgetatr */
413                      RAW_FILEINFO_GETATTRE,                  /* SMBgetattrE */
414                      RAW_FILEINFO_SEC_DESC,                  /* NT_TRANSACT_QUERY_SECURITY_DESC */
415                      RAW_FILEINFO_STANDARD                   = SMB_QFILEINFO_STANDARD,
416                      RAW_FILEINFO_EA_SIZE                    = SMB_QFILEINFO_EA_SIZE,
417                      RAW_FILEINFO_EA_LIST                    = SMB_QFILEINFO_EA_LIST,
418                      RAW_FILEINFO_ALL_EAS                    = SMB_QFILEINFO_ALL_EAS,
419                      RAW_FILEINFO_IS_NAME_VALID              = SMB_QFILEINFO_IS_NAME_VALID,
420                      RAW_FILEINFO_BASIC_INFO                 = SMB_QFILEINFO_BASIC_INFO, 
421                      RAW_FILEINFO_STANDARD_INFO              = SMB_QFILEINFO_STANDARD_INFO,
422                      RAW_FILEINFO_EA_INFO                    = SMB_QFILEINFO_EA_INFO,
423                      RAW_FILEINFO_NAME_INFO                  = SMB_QFILEINFO_NAME_INFO, 
424                      RAW_FILEINFO_ALL_INFO                   = SMB_QFILEINFO_ALL_INFO,
425                      RAW_FILEINFO_ALT_NAME_INFO              = SMB_QFILEINFO_ALT_NAME_INFO,
426                      RAW_FILEINFO_STREAM_INFO                = SMB_QFILEINFO_STREAM_INFO,
427                      RAW_FILEINFO_COMPRESSION_INFO           = SMB_QFILEINFO_COMPRESSION_INFO,
428                      RAW_FILEINFO_UNIX_BASIC                 = SMB_QFILEINFO_UNIX_BASIC,
429                      RAW_FILEINFO_UNIX_LINK                  = SMB_QFILEINFO_UNIX_LINK,
430                      RAW_FILEINFO_BASIC_INFORMATION          = SMB_QFILEINFO_BASIC_INFORMATION,
431                      RAW_FILEINFO_STANDARD_INFORMATION       = SMB_QFILEINFO_STANDARD_INFORMATION,
432                      RAW_FILEINFO_INTERNAL_INFORMATION       = SMB_QFILEINFO_INTERNAL_INFORMATION,
433                      RAW_FILEINFO_EA_INFORMATION             = SMB_QFILEINFO_EA_INFORMATION,
434                      RAW_FILEINFO_ACCESS_INFORMATION         = SMB_QFILEINFO_ACCESS_INFORMATION,
435                      RAW_FILEINFO_NAME_INFORMATION           = SMB_QFILEINFO_NAME_INFORMATION,
436                      RAW_FILEINFO_POSITION_INFORMATION       = SMB_QFILEINFO_POSITION_INFORMATION,
437                      RAW_FILEINFO_MODE_INFORMATION           = SMB_QFILEINFO_MODE_INFORMATION,
438                      RAW_FILEINFO_ALIGNMENT_INFORMATION      = SMB_QFILEINFO_ALIGNMENT_INFORMATION,
439                      RAW_FILEINFO_ALL_INFORMATION            = SMB_QFILEINFO_ALL_INFORMATION,
440                      RAW_FILEINFO_ALT_NAME_INFORMATION       = SMB_QFILEINFO_ALT_NAME_INFORMATION,
441                      RAW_FILEINFO_STREAM_INFORMATION         = SMB_QFILEINFO_STREAM_INFORMATION,
442                      RAW_FILEINFO_COMPRESSION_INFORMATION    = SMB_QFILEINFO_COMPRESSION_INFORMATION,
443                      RAW_FILEINFO_NETWORK_OPEN_INFORMATION   = SMB_QFILEINFO_NETWORK_OPEN_INFORMATION,
444                      RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION  = SMB_QFILEINFO_ATTRIBUTE_TAG_INFORMATION,
445                      /* SMB2 specific levels */
446                      RAW_FILEINFO_SMB2_ALL_EAS               = 0x0f01,
447                      RAW_FILEINFO_SMB2_ALL_INFORMATION       = 0x1201
448 };
449
450 /* union used in qfileinfo() and qpathinfo() backend calls */
451 union smb_fileinfo {
452         /* generic interface:
453          * matches RAW_FILEINFO_GENERIC */
454         struct {
455                 enum smb_fileinfo_level level;
456                 struct {
457                         union smb_handle_or_path file;
458                 } in;
459                 struct {
460                         uint32_t attrib;
461                         uint32_t ea_size;
462                         uint_t num_eas;
463                         struct ea_struct {
464                                 uint8_t flags;
465                                 struct smb_wire_string name;
466                                 DATA_BLOB value;
467                         } *eas;         
468                         NTTIME create_time;
469                         NTTIME access_time;
470                         NTTIME write_time;
471                         NTTIME change_time;
472                         uint64_t alloc_size;
473                         uint64_t size;
474                         uint32_t nlink;
475                         struct smb_wire_string fname;   
476                         struct smb_wire_string alt_fname;       
477                         uint8_t delete_pending;
478                         uint8_t directory;
479                         uint64_t compressed_size;
480                         uint16_t format;
481                         uint8_t unit_shift;
482                         uint8_t chunk_shift;
483                         uint8_t cluster_shift;
484                         uint64_t file_id;
485                         uint32_t access_flags; /* seen 0x001f01ff from w2k3 */
486                         uint64_t position;
487                         uint32_t mode;
488                         uint32_t alignment_requirement;
489                         uint32_t reparse_tag;
490                         uint_t num_streams;
491                         struct stream_struct {
492                                 uint64_t size;
493                                 uint64_t alloc_size;
494                                 struct smb_wire_string stream_name;
495                         } *streams;
496                 } out;
497         } generic;
498
499
500         /* SMBgetatr interface:
501          * matches RAW_FILEINFO_GETATTR */
502         struct {
503                 enum smb_fileinfo_level level;
504                 struct {
505                         union smb_handle_or_path file;
506                 } in;
507                 struct {
508                         uint16_t attrib;
509                         uint32_t size;
510                         time_t write_time;
511                 } out;
512         } getattr;
513
514         /* SMBgetattrE and  RAW_FILEINFO_STANDARD interface */
515         struct {
516                 enum smb_fileinfo_level level;
517                 struct {
518                         union smb_handle_or_path file;
519                 } in;
520                 struct {
521                         time_t create_time;
522                         time_t access_time;
523                         time_t write_time;
524                         uint32_t size;
525                         uint32_t alloc_size;
526                         uint16_t attrib;
527                 } out;
528         } getattre, standard;
529
530         /* trans2 RAW_FILEINFO_EA_SIZE interface */
531         struct {
532                 enum smb_fileinfo_level level;
533                 struct {
534                         union smb_handle_or_path file;
535                 } in;
536                 struct {
537                         time_t create_time;
538                         time_t access_time;
539                         time_t write_time;
540                         uint32_t size;
541                         uint32_t alloc_size;
542                         uint16_t attrib;
543                         uint32_t ea_size;
544                 } out;
545         } ea_size;
546
547         /* trans2 RAW_FILEINFO_EA_LIST interface */
548         struct {
549                 enum smb_fileinfo_level level;
550                 struct {
551                         union smb_handle_or_path file;
552                         uint_t num_names;
553                         struct ea_name {
554                                 struct smb_wire_string name;
555                         } *ea_names;    
556                 } in;   
557
558                 struct smb_ea_list {
559                         uint_t num_eas;
560                         struct ea_struct *eas;
561                 } out;
562         } ea_list;
563
564         /* trans2 RAW_FILEINFO_ALL_EAS and RAW_FILEINFO_FULL_EA_INFORMATION interfaces */
565         struct {
566                 enum smb_fileinfo_level level;
567                 struct {
568                         union smb_handle_or_path file;
569                         /* SMB2 only - SMB2_CONTINUE_FLAG_* */
570                         uint8_t continue_flags;
571                 } in;
572                 struct smb_ea_list out;
573         } all_eas;
574
575         /* trans2 qpathinfo RAW_FILEINFO_IS_NAME_VALID interface 
576            only valid for a QPATHNAME call - no returned data */
577         struct {
578                 enum smb_fileinfo_level level;
579                 struct {
580                         union smb_handle_or_path file;
581                 } in;
582         } is_name_valid;
583
584         /* RAW_FILEINFO_BASIC_INFO and RAW_FILEINFO_BASIC_INFORMATION interfaces */
585         struct {
586                 enum smb_fileinfo_level level;
587                 struct {
588                         union smb_handle_or_path file;
589                 } in;
590                 struct {
591                         NTTIME create_time;
592                         NTTIME access_time;
593                         NTTIME write_time;
594                         NTTIME change_time;
595                         uint32_t attrib;
596                 } out;
597         } basic_info;
598                 
599
600         /* RAW_FILEINFO_STANDARD_INFO and RAW_FILEINFO_STANDARD_INFORMATION interfaces */
601         struct {
602                 enum smb_fileinfo_level level;
603                 struct {
604                         union smb_handle_or_path file;
605                 } in;
606                 struct {
607                         uint64_t alloc_size;
608                         uint64_t size;
609                         uint32_t nlink;
610                         BOOL delete_pending;
611                         BOOL directory;
612                 } out;
613         } standard_info;
614         
615         /* RAW_FILEINFO_EA_INFO and RAW_FILEINFO_EA_INFORMATION interfaces */
616         struct {
617                 enum smb_fileinfo_level level;
618                 struct {
619                         union smb_handle_or_path file;
620                 } in;
621                 struct {
622                         uint32_t ea_size;
623                 } out;
624         } ea_info;
625
626         /* RAW_FILEINFO_NAME_INFO and RAW_FILEINFO_NAME_INFORMATION interfaces */
627         struct {
628                 enum smb_fileinfo_level level;
629                 struct {
630                         union smb_handle_or_path file;
631                 } in;
632                 struct {
633                         struct smb_wire_string fname;
634                 } out;
635         } name_info;
636
637         /* RAW_FILEINFO_ALL_INFO and RAW_FILEINFO_ALL_INFORMATION interfaces */
638         struct {
639                 enum smb_fileinfo_level level;
640                 struct {
641                         union smb_handle_or_path file;
642                 } in;
643                 struct {
644                         NTTIME create_time;
645                         NTTIME access_time;
646                         NTTIME write_time;
647                         NTTIME change_time;
648                         uint32_t attrib;
649                         uint64_t alloc_size;
650                         uint64_t size;
651                         uint32_t nlink;
652                         uint8_t delete_pending;
653                         uint8_t directory;
654                         uint32_t ea_size;
655                         struct smb_wire_string fname;
656                 } out;
657         } all_info;     
658
659         /* RAW_FILEINFO_SMB2_ALL_INFORMATION interface */
660         struct {
661                 enum smb_fileinfo_level level;
662                 struct {
663                         union smb_handle_or_path file;
664                 } in;
665                 struct {
666                         NTTIME   create_time;
667                         NTTIME   access_time;
668                         NTTIME   write_time;
669                         NTTIME   change_time;
670                         uint32_t attrib;
671                         uint32_t unknown1;
672                         uint64_t alloc_size;
673                         uint64_t size;
674                         uint32_t nlink;
675                         uint8_t  delete_pending;
676                         uint8_t  directory;
677                         /* uint16_t _pad; */
678                         uint64_t file_id;
679                         uint32_t ea_size;
680                         uint32_t access_mask;
681                         uint64_t position;
682                         uint64_t mode;
683                         struct smb_wire_string fname;
684                 } out;
685         } all_info2;
686
687         /* RAW_FILEINFO_ALT_NAME_INFO and RAW_FILEINFO_ALT_NAME_INFORMATION interfaces */
688         struct {
689                 enum smb_fileinfo_level level;
690                 struct {
691                         union smb_handle_or_path file;
692                 } in;
693                 struct {
694                         struct smb_wire_string fname;
695                 } out;
696         } alt_name_info;
697
698         /* RAW_FILEINFO_STREAM_INFO and RAW_FILEINFO_STREAM_INFORMATION interfaces */
699         struct {
700                 enum smb_fileinfo_level level;
701                 struct {
702                         union smb_handle_or_path file;
703                 } in;
704                 struct stream_information {
705                         uint_t num_streams;
706                         struct stream_struct *streams;
707                 } out;
708         } stream_info;
709         
710         /* RAW_FILEINFO_COMPRESSION_INFO and RAW_FILEINFO_COMPRESSION_INFORMATION interfaces */
711         struct {
712                 enum smb_fileinfo_level level;
713                 struct {
714                         union smb_handle_or_path file;
715                 } in;
716                 struct {
717                         uint64_t compressed_size;
718                         uint16_t format;
719                         uint8_t unit_shift;
720                         uint8_t chunk_shift;
721                         uint8_t cluster_shift;
722                 } out;
723         } compression_info;
724
725         /* RAW_FILEINFO_UNIX_BASIC interface */
726         struct {
727                 enum smb_fileinfo_level level;
728                 struct {
729                         union smb_handle_or_path file;
730                 } in;
731                 struct {
732                         uint64_t end_of_file;
733                         uint64_t num_bytes;
734                         NTTIME status_change_time;
735                         NTTIME access_time;
736                         NTTIME change_time;
737                         uint64_t uid;
738                         uint64_t gid;
739                         uint32_t file_type;
740                         uint64_t dev_major;
741                         uint64_t dev_minor;
742                         uint64_t unique_id;
743                         uint64_t permissions;
744                         uint64_t nlink;
745                 } out;
746         } unix_basic_info;
747
748         /* RAW_FILEINFO_UNIX_LINK interface */
749         struct {
750                 enum smb_fileinfo_level level;
751                 struct {
752                         union smb_handle_or_path file;
753                 } in;
754                 struct {
755                         struct smb_wire_string link_dest;
756                 } out;
757         } unix_link_info;
758
759         /* RAW_FILEINFO_INTERNAL_INFORMATION interface */
760         struct {
761                 enum smb_fileinfo_level level;
762                 struct {
763                         union smb_handle_or_path file;
764                 } in;
765                 struct {
766                         uint64_t file_id;
767                 } out;
768         } internal_information;
769
770         /* RAW_FILEINFO_ACCESS_INFORMATION interface */
771         struct {
772                 enum smb_fileinfo_level level;
773                 struct {
774                         union smb_handle_or_path file;
775                 } in;
776                 struct {
777                         uint32_t access_flags;
778                 } out;
779         } access_information;
780
781         /* RAW_FILEINFO_POSITION_INFORMATION interface */
782         struct {
783                 enum smb_fileinfo_level level;
784                 struct {
785                         union smb_handle_or_path file;
786                 } in;
787                 struct {
788                         uint64_t position;
789                 } out;
790         } position_information;
791
792         /* RAW_FILEINFO_MODE_INFORMATION interface */
793         struct {
794                 enum smb_fileinfo_level level;
795                 struct {
796                         union smb_handle_or_path file;
797                 } in;
798                 struct {
799                         uint32_t mode;
800                 } out;
801         } mode_information;
802
803         /* RAW_FILEINFO_ALIGNMENT_INFORMATION interface */
804         struct {
805                 enum smb_fileinfo_level level;
806                 struct {
807                         union smb_handle_or_path file;
808                 } in;
809                 struct {
810                         uint32_t alignment_requirement;
811                 } out;
812         } alignment_information;
813
814         /* RAW_FILEINFO_NETWORK_OPEN_INFORMATION interface */
815         struct {
816                 enum smb_fileinfo_level level;
817                 struct {
818                         union smb_handle_or_path file;
819                 } in;
820                 struct {
821                         NTTIME create_time;
822                         NTTIME access_time;
823                         NTTIME write_time;
824                         NTTIME change_time;
825                         uint64_t alloc_size;
826                         uint64_t size;
827                         uint32_t attrib;
828                 } out;
829         } network_open_information;
830
831
832         /* RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION interface */
833         struct {
834                 enum smb_fileinfo_level level;
835                 struct {
836                         union smb_handle_or_path file;
837                 } in;
838                 struct {
839                         uint32_t attrib;
840                         uint32_t reparse_tag;
841                 } out;
842         } attribute_tag_information;
843
844         /* RAW_FILEINFO_SEC_DESC */
845         struct {
846                 enum smb_fileinfo_level level;
847                 struct {
848                         union smb_handle_or_path file;
849                         uint32_t secinfo_flags;
850                 } in;
851                 struct {
852                         struct security_descriptor *sd;
853                 } out;
854         } query_secdesc;
855 };
856
857
858 enum smb_setfileinfo_level {
859         RAW_SFILEINFO_GENERIC                 = 0xF000, 
860         RAW_SFILEINFO_SETATTR,                /* SMBsetatr */
861         RAW_SFILEINFO_SETATTRE,               /* SMBsetattrE */
862         RAW_SFILEINFO_SEC_DESC,               /* NT_TRANSACT_SET_SECURITY_DESC */
863         RAW_SFILEINFO_STANDARD                = SMB_SFILEINFO_STANDARD,
864         RAW_SFILEINFO_EA_SET                  = SMB_SFILEINFO_EA_SET,
865         RAW_SFILEINFO_BASIC_INFO              = SMB_SFILEINFO_BASIC_INFO,
866         RAW_SFILEINFO_DISPOSITION_INFO        = SMB_SFILEINFO_DISPOSITION_INFO,
867         RAW_SFILEINFO_ALLOCATION_INFO         = SMB_SFILEINFO_ALLOCATION_INFO,
868         RAW_SFILEINFO_END_OF_FILE_INFO        = SMB_SFILEINFO_END_OF_FILE_INFO,
869         RAW_SFILEINFO_UNIX_BASIC              = SMB_SFILEINFO_UNIX_BASIC,
870         RAW_SFILEINFO_UNIX_LINK               = SMB_SFILEINFO_UNIX_LINK,
871         RAW_SFILEINFO_UNIX_HLINK              = SMB_SFILEINFO_UNIX_HLINK,
872         RAW_SFILEINFO_BASIC_INFORMATION       = SMB_SFILEINFO_BASIC_INFORMATION,
873         RAW_SFILEINFO_RENAME_INFORMATION      = SMB_SFILEINFO_RENAME_INFORMATION,
874         RAW_SFILEINFO_DISPOSITION_INFORMATION = SMB_SFILEINFO_DISPOSITION_INFORMATION,
875         RAW_SFILEINFO_POSITION_INFORMATION    = SMB_SFILEINFO_POSITION_INFORMATION,
876         RAW_SFILEINFO_MODE_INFORMATION        = SMB_SFILEINFO_MODE_INFORMATION,
877         RAW_SFILEINFO_ALLOCATION_INFORMATION  = SMB_SFILEINFO_ALLOCATION_INFORMATION,
878         RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION,
879         RAW_SFILEINFO_1023                    = SMB_SFILEINFO_1023,
880         RAW_SFILEINFO_1025                    = SMB_SFILEINFO_1025,
881         RAW_SFILEINFO_1029                    = SMB_SFILEINFO_1029,
882         RAW_SFILEINFO_1032                    = SMB_SFILEINFO_1032,
883         RAW_SFILEINFO_1039                    = SMB_SFILEINFO_1039,
884         RAW_SFILEINFO_1040                    = SMB_SFILEINFO_1040
885 };
886
887 /* union used in setfileinfo() and setpathinfo() calls */
888 union smb_setfileinfo {
889         /* generic interface */
890         struct {
891                 enum smb_setfileinfo_level level;
892                 struct {
893                         union smb_handle_or_path file;
894                 } in;
895         } generic;
896
897         /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */
898         struct {
899                 enum smb_setfileinfo_level level;
900                 struct {
901                         union smb_handle_or_path file;
902                         uint16_t attrib;
903                         time_t write_time;
904                 } in;
905         } setattr;
906
907         /* RAW_SFILEINFO_SETATTRE (SMBsetattrE) interface - only via setfileinfo() 
908            also RAW_SFILEINFO_STANDARD */
909         struct {
910                 enum smb_setfileinfo_level level;
911                 struct {
912                         union smb_handle_or_path file;
913                         time_t create_time;
914                         time_t access_time;
915                         time_t write_time;
916                         /* notice that size, alloc_size and attrib are not settable,
917                            unlike the corresponding qfileinfo level */
918                 } in;
919         } setattre, standard;
920
921         /* RAW_SFILEINFO_EA_SET interface */
922         struct {
923                 enum smb_setfileinfo_level level;
924                 struct {
925                         union smb_handle_or_path file;
926                         uint_t num_eas;
927                         struct ea_struct *eas;                  
928                 } in;
929         } ea_set;
930
931         /* RAW_SFILEINFO_BASIC_INFO and
932            RAW_SFILEINFO_BASIC_INFORMATION interfaces */
933         struct {
934                 enum smb_setfileinfo_level level;
935                 struct {
936                         union smb_handle_or_path file;
937                         NTTIME create_time;
938                         NTTIME access_time;
939                         NTTIME write_time;
940                         NTTIME change_time;
941                         uint32_t attrib;
942                 } in;
943         } basic_info;
944
945         /* RAW_SFILEINFO_DISPOSITION_INFO and 
946            RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */
947         struct {
948                 enum smb_setfileinfo_level level;
949                 struct {
950                         union smb_handle_or_path file;
951                         BOOL delete_on_close;
952                 } in;
953         } disposition_info;
954
955         /* RAW_SFILEINFO_ALLOCATION_INFO and 
956            RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */
957         struct {
958                 enum smb_setfileinfo_level level;
959                 struct {
960                         union smb_handle_or_path file;
961                         /* w2k3 rounds this up to nearest 4096 */
962                         uint64_t alloc_size;
963                 } in;
964         } allocation_info;
965         
966         /* RAW_SFILEINFO_END_OF_FILE_INFO and 
967            RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */
968         struct {
969                 enum smb_setfileinfo_level level;
970                 struct {
971                         union smb_handle_or_path file;
972                         uint64_t size;
973                 } in;
974         } end_of_file_info;
975
976         /* RAW_SFILEINFO_RENAME_INFORMATION interface */
977         struct {
978                 enum smb_setfileinfo_level level;
979                 struct {
980                         union smb_handle_or_path file;
981                         uint8_t overwrite;
982                         uint32_t root_fid;
983                         const char *new_name;
984                 } in;
985         } rename_information;
986
987         /* RAW_SFILEINFO_POSITION_INFORMATION interface */
988         struct {
989                 enum smb_setfileinfo_level level;
990                 struct {
991                         union smb_handle_or_path file;
992                         uint64_t position;
993                 } in;
994         } position_information;
995
996         /* RAW_SFILEINFO_MODE_INFORMATION interface */
997         struct {
998                 enum smb_setfileinfo_level level;
999                 struct {
1000                         union smb_handle_or_path file;
1001                         /* valid values seem to be 0, 2, 4 and 6 */
1002                         uint32_t mode;
1003                 } in;
1004         } mode_information;
1005
1006
1007
1008         /* RAW_SFILEINFO_UNIX_BASIC interface */
1009         struct {
1010                 enum smb_setfileinfo_level level;
1011                 struct {
1012                         union smb_handle_or_path file;
1013                         uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */
1014                         uint64_t end_of_file;
1015                         uint64_t num_bytes;
1016                         NTTIME status_change_time;
1017                         NTTIME access_time;
1018                         NTTIME change_time;
1019                         uint64_t uid;
1020                         uint64_t gid;
1021                         uint32_t file_type;
1022                         uint64_t dev_major;
1023                         uint64_t dev_minor;
1024                         uint64_t unique_id;
1025                         uint64_t permissions;
1026                         uint64_t nlink;
1027                 } in;
1028         } unix_basic;
1029         
1030         /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */
1031         struct {
1032                 enum smb_setfileinfo_level level;
1033                 struct {
1034                         union smb_handle_or_path file;
1035                         const char *link_dest;
1036                 } in;
1037         } unix_link, unix_hlink;
1038
1039         /* RAW_FILEINFO_SET_SEC_DESC */
1040         struct {
1041                 enum smb_setfileinfo_level level;
1042                 struct {
1043                         union smb_handle_or_path file;
1044                         uint32_t secinfo_flags;
1045                         struct security_descriptor *sd;
1046                 } in;
1047         } set_secdesc;
1048 };
1049
1050
1051 enum smb_fsinfo_level {
1052                    RAW_QFS_GENERIC                        = 0xF000, 
1053                    RAW_QFS_DSKATTR,                         /* SMBdskattr */
1054                    RAW_QFS_ALLOCATION                     = SMB_QFS_ALLOCATION,
1055                    RAW_QFS_VOLUME                         = SMB_QFS_VOLUME,
1056                    RAW_QFS_VOLUME_INFO                    = SMB_QFS_VOLUME_INFO,
1057                    RAW_QFS_SIZE_INFO                      = SMB_QFS_SIZE_INFO,
1058                    RAW_QFS_DEVICE_INFO                    = SMB_QFS_DEVICE_INFO,
1059                    RAW_QFS_ATTRIBUTE_INFO                 = SMB_QFS_ATTRIBUTE_INFO,
1060                    RAW_QFS_UNIX_INFO                      = SMB_QFS_UNIX_INFO,
1061                    RAW_QFS_VOLUME_INFORMATION             = SMB_QFS_VOLUME_INFORMATION,
1062                    RAW_QFS_SIZE_INFORMATION               = SMB_QFS_SIZE_INFORMATION,
1063                    RAW_QFS_DEVICE_INFORMATION             = SMB_QFS_DEVICE_INFORMATION,
1064                    RAW_QFS_ATTRIBUTE_INFORMATION          = SMB_QFS_ATTRIBUTE_INFORMATION,
1065                    RAW_QFS_QUOTA_INFORMATION              = SMB_QFS_QUOTA_INFORMATION,
1066                    RAW_QFS_FULL_SIZE_INFORMATION          = SMB_QFS_FULL_SIZE_INFORMATION,
1067                    RAW_QFS_OBJECTID_INFORMATION           = SMB_QFS_OBJECTID_INFORMATION};
1068
1069
1070 /* union for fsinfo() backend call. Note that there are no in
1071    structures, as this call only contains out parameters */
1072 union smb_fsinfo {
1073         /* generic interface */
1074         struct {
1075                 enum smb_fsinfo_level level;
1076                 struct smb2_handle handle; /* only for smb2 */
1077
1078                 struct {
1079                         uint32_t block_size;
1080                         uint64_t blocks_total;
1081                         uint64_t blocks_free;
1082                         uint32_t fs_id;
1083                         NTTIME create_time;
1084                         uint32_t serial_number;
1085                         uint32_t fs_attr;
1086                         uint32_t max_file_component_length;
1087                         uint32_t device_type;
1088                         uint32_t device_characteristics;
1089                         uint64_t quota_soft;
1090                         uint64_t quota_hard;
1091                         uint64_t quota_flags;
1092                         struct GUID guid;
1093                         char *volume_name;
1094                         char *fs_type;
1095                 } out;
1096         } generic;
1097
1098         /* SMBdskattr interface */
1099         struct {
1100                 enum smb_fsinfo_level level;
1101
1102                 struct {
1103                         uint16_t units_total;
1104                         uint16_t blocks_per_unit;
1105                         uint16_t block_size;
1106                         uint16_t units_free;
1107                 } out;
1108         } dskattr;
1109
1110         /* trans2 RAW_QFS_ALLOCATION interface */
1111         struct {
1112                 enum smb_fsinfo_level level;
1113
1114                 struct {
1115                         uint32_t fs_id;
1116                         uint32_t sectors_per_unit;
1117                         uint32_t total_alloc_units;
1118                         uint32_t avail_alloc_units;
1119                         uint16_t bytes_per_sector;
1120                 } out;
1121         } allocation;
1122
1123         /* TRANS2 RAW_QFS_VOLUME interface */
1124         struct {
1125                 enum smb_fsinfo_level level;
1126
1127                 struct {
1128                         uint32_t serial_number;
1129                         struct smb_wire_string volume_name;
1130                 } out;
1131         } volume;
1132
1133         /* TRANS2 RAW_QFS_VOLUME_INFO and RAW_QFS_VOLUME_INFORMATION interfaces */
1134         struct {
1135                 enum smb_fsinfo_level level;
1136                 struct smb2_handle handle; /* only for smb2 */
1137
1138                 struct {
1139                         NTTIME create_time;
1140                         uint32_t serial_number;
1141                         struct smb_wire_string volume_name;
1142                 } out;
1143         } volume_info;
1144
1145         /* trans2 RAW_QFS_SIZE_INFO and RAW_QFS_SIZE_INFORMATION interfaces */
1146         struct {
1147                 enum smb_fsinfo_level level;
1148                 struct smb2_handle handle; /* only for smb2 */
1149
1150                 struct {
1151                         uint64_t total_alloc_units;
1152                         uint64_t avail_alloc_units; /* maps to call_avail_alloc_units */
1153                         uint32_t sectors_per_unit;
1154                         uint32_t bytes_per_sector;
1155                 } out;
1156         } size_info;
1157
1158         /* TRANS2 RAW_QFS_DEVICE_INFO and RAW_QFS_DEVICE_INFORMATION interfaces */
1159         struct {
1160                 enum smb_fsinfo_level level;
1161                 struct smb2_handle handle; /* only for smb2 */
1162
1163                 struct {
1164                         uint32_t device_type;
1165                         uint32_t characteristics;
1166                 } out;
1167         } device_info;
1168
1169
1170         /* TRANS2 RAW_QFS_ATTRIBUTE_INFO and RAW_QFS_ATTRIBUTE_INFORMATION interfaces */
1171         struct {
1172                 enum smb_fsinfo_level level;
1173                 struct smb2_handle handle; /* only for smb2 */
1174
1175                 struct {
1176                         uint32_t fs_attr;
1177                         uint32_t max_file_component_length;
1178                         struct smb_wire_string fs_type;
1179                 } out;
1180         } attribute_info;
1181
1182
1183         /* TRANS2 RAW_QFS_UNIX_INFO interface */
1184         struct {
1185                 enum smb_fsinfo_level level;
1186
1187                 struct {
1188                         uint16_t major_version;
1189                         uint16_t minor_version;
1190                         uint64_t capability;
1191                 } out;
1192         } unix_info;
1193
1194         /* trans2 RAW_QFS_QUOTA_INFORMATION interface */
1195         struct {
1196                 enum smb_fsinfo_level level;
1197                 struct smb2_handle handle; /* only for smb2 */
1198
1199                 struct {
1200                         uint64_t unknown[3];
1201                         uint64_t quota_soft;
1202                         uint64_t quota_hard;
1203                         uint64_t quota_flags;
1204                 } out;
1205         } quota_information;    
1206
1207         /* trans2 RAW_QFS_FULL_SIZE_INFORMATION interface */
1208         struct {
1209                 enum smb_fsinfo_level level;
1210                 struct smb2_handle handle; /* only for smb2 */
1211
1212                 struct {
1213                         uint64_t total_alloc_units;
1214                         uint64_t call_avail_alloc_units;
1215                         uint64_t actual_avail_alloc_units;
1216                         uint32_t sectors_per_unit;
1217                         uint32_t bytes_per_sector;
1218                 } out;
1219         } full_size_information;
1220
1221         /* trans2 RAW_QFS_OBJECTID_INFORMATION interface */
1222         struct {
1223                 enum smb_fsinfo_level level;
1224                 struct smb2_handle handle; /* only for smb2 */
1225
1226                 struct {
1227                         struct GUID  guid;
1228                         uint64_t unknown[6];
1229                 } out;
1230         } objectid_information; 
1231 };
1232
1233
1234
1235 enum smb_open_level {
1236         RAW_OPEN_OPEN,
1237         RAW_OPEN_OPENX, 
1238         RAW_OPEN_MKNEW,
1239         RAW_OPEN_CREATE, 
1240         RAW_OPEN_CTEMP,
1241         RAW_OPEN_SPLOPEN,
1242         RAW_OPEN_NTCREATEX,
1243         RAW_OPEN_T2OPEN,
1244         RAW_OPEN_NTTRANS_CREATE, 
1245         RAW_OPEN_OPENX_READX,
1246         RAW_OPEN_SMB2
1247 };
1248
1249 /* the generic interface is defined to be equal to the NTCREATEX interface */
1250 #define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX
1251
1252 /* union for open() backend call */
1253 union smb_open {
1254 /* 
1255  * because the *.out.file structs are not aligned to the same offset for each level
1256  * we provide a hepler macro that should be used to find the current smb_handle structure
1257  */
1258 #define SMB_OPEN_OUT_FILE(op, file) do { \
1259         switch (op->generic.level) { \
1260         case RAW_OPEN_OPEN: \
1261                 file = &op->openold.out.file; \
1262                 break; \
1263         case RAW_OPEN_OPENX: \
1264                 file = &op->openx.out.file; \
1265                 break; \
1266         case RAW_OPEN_MKNEW: \
1267                 file = &op->mknew.out.file; \
1268                 break; \
1269         case RAW_OPEN_CREATE: \
1270                 file = &op->create.out.file; \
1271                 break; \
1272         case RAW_OPEN_CTEMP: \
1273                 file = &op->ctemp.out.file; \
1274                 break; \
1275         case RAW_OPEN_SPLOPEN: \
1276                 file = &op->splopen.out.file; \
1277                 break; \
1278         case RAW_OPEN_NTCREATEX: \
1279                 file = &op->ntcreatex.out.file; \
1280                 break; \
1281         case RAW_OPEN_T2OPEN: \
1282                 file = &op->t2open.out.file; \
1283                 break; \
1284         case RAW_OPEN_NTTRANS_CREATE: \
1285                 file = &op->nttrans.out.file; \
1286                 break; \
1287         case RAW_OPEN_OPENX_READX: \
1288                 file = &op->openxreadx.out.file; \
1289                 break; \
1290         case RAW_OPEN_SMB2: \
1291                 file = &op->smb2.out.file; \
1292                 break; \
1293         default: \
1294                 /* this must be a programmer error */ \
1295                 file = NULL; \
1296                 break; \
1297         } \
1298 } while (0)
1299         /* SMBNTCreateX interface */
1300         struct {
1301                 enum smb_open_level level;
1302                 struct {
1303                         uint32_t flags;
1304                         uint32_t root_fid;
1305                         uint32_t access_mask;
1306                         uint64_t alloc_size;
1307                         uint32_t file_attr;
1308                         uint32_t share_access;
1309                         uint32_t open_disposition;
1310                         uint32_t create_options;
1311                         uint32_t impersonation;
1312                         uint8_t  security_flags;
1313                         /* NOTE: fname can also be a pointer to a
1314                          uint64_t file_id if create_options has the
1315                          NTCREATEX_OPTIONS_OPEN_BY_FILE_ID flag set */
1316                         const char *fname;
1317
1318                         /* these last 2 elements are only used in the
1319                            NTTRANS varient of the call */
1320                         struct security_descriptor *sec_desc;
1321                         struct smb_ea_list *ea_list;
1322                 } in;
1323                 struct {
1324                         union smb_handle file;
1325                         uint8_t oplock_level;
1326                         uint32_t create_action;
1327                         NTTIME create_time;
1328                         NTTIME access_time;
1329                         NTTIME write_time;
1330                         NTTIME change_time;
1331                         uint32_t attrib;
1332                         uint64_t alloc_size;
1333                         uint64_t size;
1334                         uint16_t file_type;
1335                         uint16_t ipc_state;
1336                         uint8_t  is_directory;
1337                 } out;
1338         } ntcreatex, nttrans, generic;
1339
1340         /* TRANS2_OPEN interface */
1341         struct {
1342                 enum smb_open_level level;
1343                 struct {
1344                         uint16_t flags;
1345                         uint16_t open_mode;
1346                         uint16_t search_attrs;
1347                         uint16_t file_attrs;
1348                         time_t write_time;
1349                         uint16_t open_func;
1350                         uint32_t size;
1351                         uint32_t timeout;
1352                         const char *fname;
1353                         uint_t num_eas;
1354                         struct ea_struct *eas;                  
1355                 } in;
1356                 struct {
1357                         union smb_handle file;
1358                         uint16_t attrib;
1359                         time_t write_time;
1360                         uint32_t size;
1361                         uint16_t access;
1362                         uint16_t ftype;
1363                         uint16_t devstate;
1364                         uint16_t action;
1365                         uint32_t file_id;
1366                 } out;
1367         } t2open;
1368
1369         /* SMBopen interface */
1370         struct {
1371                 enum smb_open_level level;
1372                 struct {
1373                         uint16_t open_mode;
1374                         uint16_t search_attrs;
1375                         const char *fname;
1376                 } in;
1377                 struct {
1378                         union smb_handle file;
1379                         uint16_t attrib;
1380                         time_t write_time;
1381                         uint32_t size;
1382                         uint16_t rmode;
1383                 } out;
1384         } openold;
1385
1386         /* SMBopenX interface */
1387         struct {
1388                 enum smb_open_level level;
1389                 struct {
1390                         uint16_t flags;
1391                         uint16_t open_mode;
1392                         uint16_t search_attrs; /* not honoured by win2003 */
1393                         uint16_t file_attrs;
1394                         time_t write_time; /* not honoured by win2003 */
1395                         uint16_t open_func;
1396                         uint32_t size; /* note that this sets the
1397                                         initial file size, not
1398                                         just allocation size */
1399                         uint32_t timeout; /* not honoured by win2003 */
1400                         const char *fname;
1401                 } in;
1402                 struct {
1403                         union smb_handle file;
1404                         uint16_t attrib;
1405                         time_t write_time;
1406                         uint32_t size;
1407                         uint16_t access;
1408                         uint16_t ftype;
1409                         uint16_t devstate;
1410                         uint16_t action;
1411                         uint32_t unique_fid;
1412                         uint32_t access_mask;
1413                         uint32_t unknown;
1414                 } out;
1415         } openx;
1416
1417         /* SMBmknew interface */
1418         struct {
1419                 enum smb_open_level level;
1420                 struct {
1421                         uint16_t attrib;
1422                         time_t write_time;
1423                         const char *fname;
1424                 } in;
1425                 struct {
1426                         union smb_handle file;
1427                 } out;
1428         } mknew, create;
1429
1430         /* SMBctemp interface */
1431         struct {
1432                 enum smb_open_level level;
1433                 struct {
1434                         uint16_t attrib;
1435                         time_t write_time;
1436                         const char *directory;
1437                 } in;
1438                 struct {
1439                         union smb_handle file;
1440                         /* temp name, relative to directory */
1441                         char *name; 
1442                 } out;
1443         } ctemp;
1444
1445         /* SMBsplopen interface */
1446         struct {
1447                 enum smb_open_level level;
1448                 struct {
1449                         uint16_t setup_length;
1450                         uint16_t mode;
1451                         const char *ident;
1452                 } in;
1453                 struct {
1454                         union smb_handle file;
1455                 } out;
1456         } splopen;
1457
1458
1459         /* chained OpenX/ReadX interface */
1460         struct {
1461                 enum smb_open_level level;
1462                 struct {
1463                         uint16_t flags;
1464                         uint16_t open_mode;
1465                         uint16_t search_attrs; /* not honoured by win2003 */
1466                         uint16_t file_attrs;
1467                         time_t write_time; /* not honoured by win2003 */
1468                         uint16_t open_func;
1469                         uint32_t size; /* note that this sets the
1470                                         initial file size, not
1471                                         just allocation size */
1472                         uint32_t timeout; /* not honoured by win2003 */
1473                         const char *fname;
1474
1475                         /* readx part */
1476                         uint64_t offset;
1477                         uint16_t mincnt;
1478                         uint32_t maxcnt;
1479                         uint16_t remaining;
1480                 } in;
1481                 struct {
1482                         union smb_handle file;
1483                         uint16_t attrib;
1484                         time_t write_time;
1485                         uint32_t size;
1486                         uint16_t access;
1487                         uint16_t ftype;
1488                         uint16_t devstate;
1489                         uint16_t action;
1490                         uint32_t unique_fid;
1491                         uint32_t access_mask;
1492                         uint32_t unknown;
1493                         
1494                         /* readx part */
1495                         uint8_t *data;
1496                         uint16_t remaining;
1497                         uint16_t compaction_mode;
1498                         uint16_t nread;
1499                 } out;
1500         } openxreadx;
1501
1502 #define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
1503 #define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
1504 #define SMB2_CREATE_FLAG_GRANT_OPLOCK             0x0001
1505 #define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK   0x0080
1506
1507         /* SMB2 Create */
1508         struct smb2_create {
1509                 enum smb_open_level level;
1510                 struct {
1511                         /* static body buffer 56 (0x38) bytes */
1512                         /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
1513                         uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
1514                         uint32_t impersonation;
1515                         uint32_t unknown3[4];
1516                         uint32_t access_mask;
1517
1518                         uint32_t file_attr;
1519                         uint32_t share_access;
1520                         uint32_t open_disposition;
1521                         uint32_t create_options;
1522
1523                         /* uint16_t fname_ofs */
1524                         /* uint16_t fname_size */
1525                         /* uint32_t blob_ofs; */
1526                         /* uint32_t blob_size; */
1527
1528                         /* dynamic body */
1529                         const char *fname;
1530
1531                         /* optional list of extended attributes */
1532                         struct smb_ea_list eas;
1533                 } in;
1534                 struct {
1535                         union smb_handle file;
1536
1537                         /* static body buffer 88 (0x58) bytes */
1538                         /* uint16_t buffer_code;  0x59 = 0x58 + 1 */
1539                         uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
1540                         uint32_t create_action;
1541                         NTTIME   create_time;
1542                         NTTIME   access_time;
1543                         NTTIME   write_time;
1544                         NTTIME   change_time;
1545                         uint64_t alloc_size;
1546                         uint64_t size;
1547                         uint32_t file_attr;
1548                         uint32_t _pad;
1549                         /* struct smb2_handle handle;*/
1550                         /* uint32_t blob_ofs; */
1551                         /* uint32_t blob_size; */
1552
1553                         /* dynamic body */
1554                         DATA_BLOB blob;
1555                 } out;
1556         } smb2;
1557 };
1558
1559
1560
1561 enum smb_read_level {
1562         RAW_READ_READBRAW,
1563         RAW_READ_LOCKREAD,
1564         RAW_READ_READ,
1565         RAW_READ_READX,
1566         RAW_READ_SMB2
1567 };
1568
1569 #define RAW_READ_GENERIC RAW_READ_READX
1570
1571 /* union for read() backend call 
1572
1573    note that .infoX.out.data will be allocated before the backend is
1574    called. It will be big enough to hold the maximum size asked for
1575 */
1576 union smb_read {
1577         /* SMBreadX (and generic) interface */
1578         struct {
1579                 enum smb_read_level level;
1580                 struct {
1581                         union smb_handle file;
1582                         uint64_t offset;
1583                         uint16_t mincnt;
1584                         uint32_t maxcnt;
1585                         uint16_t remaining;
1586                         BOOL read_for_execute;
1587                 } in;
1588                 struct {
1589                         uint8_t *data;
1590                         uint16_t remaining;
1591                         uint16_t compaction_mode;
1592                         uint32_t nread;
1593                 } out;
1594         } readx, generic;
1595
1596         /* SMBreadbraw interface */
1597         struct {
1598                 enum smb_read_level level;
1599                 struct {
1600                         union smb_handle file;
1601                         uint64_t offset;
1602                         uint16_t  maxcnt;
1603                         uint16_t  mincnt;
1604                         uint32_t  timeout;
1605                 } in;
1606                 struct {
1607                         uint8_t *data;
1608                         uint32_t nread;
1609                 } out;
1610         } readbraw;
1611
1612
1613         /* SMBlockandread interface */
1614         struct {
1615                 enum smb_read_level level;
1616                 struct {
1617                         union smb_handle file;
1618                         uint16_t count;
1619                         uint32_t offset;
1620                         uint16_t remaining;
1621                 } in;
1622                 struct {
1623                         uint8_t *data;
1624                         uint16_t nread;
1625                 } out;
1626         } lockread;
1627
1628         /* SMBread interface */
1629         struct {
1630                 enum smb_read_level level;
1631                 struct {
1632                         union smb_handle file;
1633                         uint16_t count;
1634                         uint32_t offset;
1635                         uint16_t remaining;
1636                 } in;
1637                 struct {
1638                         uint8_t *data;
1639                         uint16_t nread;
1640                 } out;
1641         } read;
1642
1643         /* SMB2 Read */
1644         struct smb2_read {
1645                 enum smb_read_level level;
1646                 struct {
1647                         union smb_handle file;
1648
1649                         /* static body buffer 48 (0x30) bytes */
1650                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1651                         uint16_t _pad;
1652                         uint32_t length;
1653                         uint64_t offset;
1654                         /* struct smb2_handle handle; */
1655                         uint64_t unknown1; /* 0x0000000000000000 */
1656                         uint64_t unknown2; /* 0x0000000000000000 */
1657                 } in;
1658                 struct {
1659                         /* static body buffer 16 (0x10) bytes */
1660                         /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
1661                         /* uint16_t data_ofs; */
1662                         /* uint32_t data_size; */
1663                         uint64_t unknown1; /* 0x0000000000000000 */
1664
1665                         /* dynamic body */
1666                         DATA_BLOB data;
1667                 } out;
1668         } smb2;
1669 };
1670
1671
1672 enum smb_write_level {
1673         RAW_WRITE_WRITEUNLOCK,
1674         RAW_WRITE_WRITE,
1675         RAW_WRITE_WRITEX,
1676         RAW_WRITE_WRITECLOSE,
1677         RAW_WRITE_SPLWRITE,
1678         RAW_WRITE_SMB2
1679 };
1680
1681 #define RAW_WRITE_GENERIC RAW_WRITE_WRITEX
1682
1683 /* union for write() backend call 
1684 */
1685 union smb_write {
1686         /* SMBwriteX interface */
1687         struct {
1688                 enum smb_write_level level;
1689                 struct {
1690                         union smb_handle file;
1691                         uint64_t offset;
1692                         uint16_t wmode;
1693                         uint16_t remaining;
1694                         uint32_t count;
1695                         const uint8_t *data;
1696                 } in;
1697                 struct {
1698                         uint32_t nwritten;
1699                         uint16_t remaining;
1700                 } out;
1701         } writex, generic;
1702
1703         /* SMBwriteunlock interface */
1704         struct {
1705                 enum smb_write_level level;
1706                 struct {
1707                         union smb_handle file;
1708                         uint16_t count;
1709                         uint32_t offset;
1710                         uint16_t remaining;
1711                         const uint8_t *data;
1712                 } in;
1713                 struct {
1714                         uint32_t nwritten;
1715                 } out;
1716         } writeunlock;
1717
1718         /* SMBwrite interface */
1719         struct {
1720                 enum smb_write_level level;
1721                 struct {
1722                         union smb_handle file;
1723                         uint16_t count;
1724                         uint32_t offset;
1725                         uint16_t remaining;
1726                         const uint8_t *data;
1727                 } in;
1728                 struct {
1729                         uint16_t nwritten;
1730                 } out;
1731         } write;
1732
1733         /* SMBwriteclose interface */
1734         struct {
1735                 enum smb_write_level level;
1736                 struct {
1737                         union smb_handle file;
1738                         uint16_t count;
1739                         uint32_t offset;
1740                         time_t mtime;
1741                         const uint8_t *data;
1742                 } in;
1743                 struct {
1744                         uint16_t nwritten;
1745                 } out;
1746         } writeclose;
1747
1748         /* SMBsplwrite interface */
1749         struct {
1750                 enum smb_write_level level;
1751                 struct {
1752                         union smb_handle file;
1753                         uint16_t count;
1754                         const uint8_t *data;
1755                 } in;
1756         } splwrite;
1757
1758         /* SMB2 Write */
1759         struct smb2_write {
1760                 enum smb_write_level level;
1761                 struct {
1762                         union smb_handle file;
1763
1764                         /* static body buffer 48 (0x30) bytes */
1765                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1766                         /* uint16_t data_ofs; */
1767                         /* uint32_t data_size; */
1768                         uint64_t offset;
1769                         /* struct smb2_handle handle; */
1770                         uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */
1771                         uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */
1772
1773                         /* dynamic body */
1774                         DATA_BLOB data;
1775                 } in;
1776                 struct {
1777                         /* static body buffer 17 (0x11) bytes */
1778                         /* uint16_t buffer_code;  0x11 = 0x10 + 1*/
1779                         uint16_t _pad;
1780                         uint32_t nwritten;
1781                         uint64_t unknown1; /* 0x0000000000000000 */
1782                 } out;
1783         } smb2;
1784 };
1785
1786
1787 enum smb_lock_level {
1788         RAW_LOCK_LOCK,
1789         RAW_LOCK_UNLOCK,
1790         RAW_LOCK_LOCKX,
1791         RAW_LOCK_SMB2
1792 };
1793
1794 /* the generic interface is defined to be equal to the lockingX interface */
1795 #define RAW_LOCK_GENERIC RAW_LOCK_LOCKX
1796
1797 /* union for lock() backend call 
1798 */
1799 union smb_lock {
1800         /* SMBlockingX (and generic) interface */
1801         struct {
1802                 enum smb_lock_level level;
1803                 struct {
1804                         union smb_handle file;
1805                         uint16_t mode;
1806                         uint32_t timeout;
1807                         uint16_t ulock_cnt;
1808                         uint16_t lock_cnt;
1809                         struct smb_lock_entry {
1810                                 uint16_t pid;
1811                                 uint64_t offset;
1812                                 uint64_t count;
1813                         } *locks; /* unlocks are first in the arrray */
1814                 } in;
1815         } lockx, generic;
1816
1817         /* SMBlock and SMBunlock interface */
1818         struct {
1819                 enum smb_lock_level level;
1820                 struct {
1821                         union smb_handle file;
1822                         uint32_t count;
1823                         uint32_t offset;
1824                 } in;
1825         } lock, unlock;
1826
1827         /* SMB2 Lock */
1828         struct smb2_lock {
1829                 enum smb_lock_level level;
1830                 struct {
1831                         union smb_handle file;
1832
1833                         /* static body buffer 48 (0x30) bytes */
1834                         /* uint16_t buffer_code;  0x30 */
1835                         uint16_t unknown1; /* must be 0x0001 */
1836                         uint32_t unknown2;
1837                         /* struct smb2_handle handle; */
1838                         uint64_t offset;
1839                         uint64_t count;
1840                         uint32_t unknown5;
1841 #define SMB2_LOCK_FLAG_NONE     0x00000000
1842 #define SMB2_LOCK_FLAG_EXCLUSIV 0x00000002
1843 #define SMB2_LOCK_FLAG_UNLOCK   0x00000004
1844 #define SMB2_LOCK_FLAGS_MASK    0x00000006
1845                         uint32_t flags; 
1846                 } in;
1847                 struct {
1848                         /* static body buffer 4 (0x04) bytes */
1849                         /* uint16_t buffer_code;  0x04 */
1850                         uint16_t unknown1;
1851                 } out;
1852         } smb2;
1853 };
1854
1855
1856 enum smb_close_level {
1857         RAW_CLOSE_CLOSE,
1858         RAW_CLOSE_SPLCLOSE,
1859         RAW_CLOSE_SMB2
1860 };
1861
1862 #define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE
1863
1864 /*
1865   union for close() backend call
1866 */
1867 union smb_close {
1868         /* SMBclose (and generic) interface */
1869         struct {
1870                 enum smb_close_level level;
1871                 struct {
1872                         union smb_handle file;
1873                         time_t write_time;
1874                 } in;
1875         } close, generic;
1876
1877         /* SMBsplclose interface - empty! */
1878         struct {
1879                 enum smb_close_level level;
1880                 struct {
1881                         union smb_handle file;
1882                 } in;
1883         } splclose;
1884
1885         /* SMB2 Close */
1886         struct smb2_close {
1887                 enum smb_close_level level;
1888                 struct {
1889                         union smb_handle file;
1890
1891                         /* static body buffer 24 (0x18) bytes */
1892                         /* uint16_t buffer_code;  0x18 */
1893 #define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
1894                         uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
1895                         uint32_t _pad;
1896                 } in;
1897                 struct {
1898                         /* static body buffer 60 (0x3C) bytes */
1899                         /* uint16_t buffer_code;  0x3C */
1900                         uint16_t flags;
1901                         uint32_t _pad;
1902                         NTTIME   create_time;
1903                         NTTIME   access_time;
1904                         NTTIME   write_time;
1905                         NTTIME   change_time;
1906                         uint64_t alloc_size;
1907                         uint64_t size;
1908                         uint32_t file_attr;
1909                 } out;
1910         } smb2;
1911 };
1912
1913
1914 enum smb_lpq_level {RAW_LPQ_GENERIC, RAW_LPQ_RETQ};
1915
1916 /*
1917   union for lpq() backend
1918 */
1919 union smb_lpq {
1920         /* generic interface */
1921         struct {
1922                 enum smb_lpq_level level;
1923
1924         } generic;
1925
1926
1927         /* SMBsplretq interface */
1928         struct {
1929                 enum smb_lpq_level level;
1930
1931                 struct {
1932                         uint16_t maxcount;
1933                         uint16_t startidx;
1934                 } in;
1935                 struct {
1936                         uint16_t count;
1937                         uint16_t restart_idx;
1938                         struct {
1939                                 time_t time;
1940                                 uint8_t status;
1941                                 uint16_t job;
1942                                 uint32_t size;
1943                                 char *user;
1944                         } *queue;
1945                 } out;
1946         } retq;
1947 };
1948
1949 enum smb_ioctl_level {
1950         RAW_IOCTL_IOCTL,
1951         RAW_IOCTL_NTIOCTL,
1952         RAW_IOCTL_SMB2,
1953         RAW_IOCTL_SMB2_NO_HANDLE
1954 };
1955
1956 /*
1957   union for ioctl() backend
1958 */
1959 union smb_ioctl {
1960         /* generic interface */
1961         struct {
1962                 enum smb_ioctl_level level;
1963                 struct {
1964                         union smb_handle file;
1965                 } in;
1966         } generic;
1967
1968         /* struct for SMBioctl */
1969         struct {
1970                 enum smb_ioctl_level level;
1971                 struct {
1972                         union smb_handle file;
1973                         uint32_t request;
1974                 } in;
1975                 struct {
1976                         DATA_BLOB blob;
1977                 } out;
1978         } ioctl;
1979
1980
1981         /* struct for NT ioctl call */
1982         struct {
1983                 enum smb_ioctl_level level;
1984                 struct {
1985                         union smb_handle file;
1986                         uint32_t function;
1987                         BOOL fsctl;
1988                         uint8_t filter;
1989                         uint32_t max_data;
1990                         DATA_BLOB blob;
1991                 } in;
1992                 struct {
1993                         DATA_BLOB blob;
1994                 } out;
1995         } ntioctl;
1996
1997         /* SMB2 Ioctl */
1998         struct smb2_ioctl {
1999                 enum smb_ioctl_level level;
2000                 struct {
2001                         union smb_handle file;
2002
2003                         /* static body buffer 56 (0x38) bytes */
2004                         /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
2005                         uint16_t _pad;
2006                         uint32_t function;
2007                         /*struct smb2_handle handle;*/
2008                         /* uint32_t out_ofs; */
2009                         /* uint32_t out_size; */
2010                         uint32_t unknown2;
2011                         /* uint32_t in_ofs; */
2012                         /* uint32_t in_size; */
2013                         uint32_t max_response_size;
2014                         uint64_t flags;
2015
2016                         /* dynamic body */
2017                         DATA_BLOB out;
2018                         DATA_BLOB in;
2019                 } in;
2020                 struct {
2021                         union smb_handle file;
2022
2023                         /* static body buffer 48 (0x30) bytes */
2024                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
2025                         uint16_t _pad;
2026                         uint32_t function;
2027                         /* struct smb2_handle handle; */
2028                         /* uint32_t in_ofs; */
2029                         /* uint32_t in_size; */
2030                         /* uint32_t out_ofs; */
2031                         /* uint32_t out_size; */
2032                         uint32_t unknown2;
2033                         uint32_t unknown3;
2034
2035                         /* dynamic body */
2036                         DATA_BLOB in;
2037                         DATA_BLOB out;
2038                 } out;
2039         } smb2;
2040 };
2041
2042 enum smb_flush_level {
2043         RAW_FLUSH_FLUSH,
2044         RAW_FLUSH_ALL,
2045         RAW_FLUSH_SMB2
2046 };
2047
2048 union smb_flush {
2049         /* struct for SMBflush */
2050         struct {
2051                 enum smb_flush_level level;
2052                 struct {
2053                         union smb_handle file;
2054                 } in;
2055         } flush, generic;
2056
2057         /* SMBflush with 0xFFFF wildcard fnum */
2058         struct {
2059                 enum smb_flush_level level;
2060         } flush_all;
2061
2062         /* SMB2 Flush */
2063         struct smb2_flush {
2064                 enum smb_flush_level level;
2065                 struct {
2066                         union smb_handle file;
2067                         uint32_t unknown;
2068                 } in;
2069         } smb2;
2070 };
2071
2072 /* struct for SMBcopy */
2073 struct smb_copy {
2074         struct {
2075                 uint16_t tid2;
2076                 uint16_t ofun;
2077                 uint16_t flags;
2078                 const char *path1;
2079                 const char *path2;
2080         } in;
2081         struct {
2082                 uint16_t count;
2083         } out;
2084 };
2085
2086
2087 /* struct for transact/transact2 call */
2088 struct smb_trans2 {
2089         struct {
2090                 uint16_t max_param;
2091                 uint16_t max_data;
2092                 uint8_t  max_setup;
2093                 uint16_t flags;
2094                 uint32_t timeout;
2095                 uint8_t  setup_count;
2096                 uint16_t *setup;
2097                 const char *trans_name; /* SMBtrans only */
2098                 DATA_BLOB params;
2099                 DATA_BLOB data;
2100         } in;
2101
2102         struct {
2103                 uint8_t  setup_count;
2104                 uint16_t *setup;
2105                 DATA_BLOB params;
2106                 DATA_BLOB data;
2107         } out;
2108 };
2109
2110 /* struct for nttransact2 call */
2111 struct smb_nttrans {
2112         struct {
2113                 uint8_t  max_setup;
2114                 uint32_t max_param;
2115                 uint32_t max_data;
2116                 uint32_t setup_count;
2117                 uint16_t function;
2118                 uint8_t  *setup;
2119                 DATA_BLOB params;
2120                 DATA_BLOB data;
2121         } in;
2122
2123         struct {
2124                 uint8_t  setup_count; /* in units of 16 bit words */
2125                 uint8_t  *setup;
2126                 DATA_BLOB params;
2127                 DATA_BLOB data;
2128         } out;
2129 };
2130
2131 enum smb_notify_level {
2132         RAW_NOTIFY_NTTRANS,
2133         RAW_NOTIFY_SMB2
2134 };
2135
2136 union smb_notify {
2137         /* struct for nttrans change notify call */
2138         struct {
2139                 enum smb_notify_level level;
2140
2141                 struct {
2142                         union smb_handle file;
2143                         uint32_t buffer_size;
2144                         uint32_t completion_filter;
2145                         BOOL recursive;
2146                 } in;
2147
2148                 struct {
2149                         uint32_t num_changes;
2150                         struct notify_changes {
2151                                 uint32_t action;
2152                                 struct smb_wire_string name;
2153                         } *changes;
2154                 } out;
2155         } nttrans;
2156
2157         struct smb2_notify {
2158                 enum smb_notify_level level;
2159                 
2160                 struct {
2161                         union smb_handle file;
2162                         /* static body buffer 32 (0x20) bytes */
2163                         /* uint16_t buffer_code;  0x32 */
2164                         uint16_t recursive;
2165                         uint32_t buffer_size;
2166                         /*struct  smb2_handle file;*/
2167                         uint32_t completion_filter;
2168                         uint32_t unknown;
2169                 } in;
2170
2171                 struct {
2172                         /* static body buffer 8 (0x08) bytes */
2173                         /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
2174                         /* uint16_t blob_ofs; */
2175                         /* uint16_t blob_size; */
2176
2177                         /* dynamic body */
2178                         /*DATA_BLOB blob;*/
2179
2180                         /* DATA_BLOB content */
2181                         uint32_t num_changes;
2182                         struct notify_changes *changes;
2183                 } out;
2184         } smb2;
2185 };
2186
2187 enum smb_search_level {
2188         RAW_SEARCH_SEARCH,      /* SMBsearch */ 
2189         RAW_SEARCH_FFIRST,      /* SMBffirst */ 
2190         RAW_SEARCH_FUNIQUE,     /* SMBfunique */
2191         RAW_SEARCH_TRANS2,      /* SMBtrans2 */
2192         RAW_SEARCH_SMB2         /* SMB2 Find */
2193 };
2194
2195 enum smb_search_data_level {
2196         RAW_SEARCH_DATA_GENERIC                 = 0x10000, /* only used in the smbcli_ code */
2197         RAW_SEARCH_DATA_SEARCH,
2198         RAW_SEARCH_DATA_STANDARD                = SMB_FIND_STANDARD,
2199         RAW_SEARCH_DATA_EA_SIZE                 = SMB_FIND_EA_SIZE,
2200         RAW_SEARCH_DATA_EA_LIST                 = SMB_FIND_EA_LIST,
2201         RAW_SEARCH_DATA_DIRECTORY_INFO          = SMB_FIND_DIRECTORY_INFO,
2202         RAW_SEARCH_DATA_FULL_DIRECTORY_INFO     = SMB_FIND_FULL_DIRECTORY_INFO,
2203         RAW_SEARCH_DATA_NAME_INFO               = SMB_FIND_NAME_INFO,
2204         RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO     = SMB_FIND_BOTH_DIRECTORY_INFO,
2205         RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO  = SMB_FIND_ID_FULL_DIRECTORY_INFO,
2206         RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO  = SMB_FIND_ID_BOTH_DIRECTORY_INFO,
2207         RAW_SEARCH_DATA_UNIX_INFO               = SMB_FIND_UNIX_INFO
2208 };
2209         
2210 /* union for file search */
2211 union smb_search_first {
2212         struct {
2213                 enum smb_search_level level;
2214                 enum smb_search_data_level data_level;
2215         } generic;
2216         
2217         /* search (old) findfirst interface. 
2218            Also used for ffirst and funique. */
2219         struct {
2220                 enum smb_search_level level;
2221                 enum smb_search_data_level data_level;
2222         
2223                 struct {
2224                         uint16_t max_count;
2225                         uint16_t search_attrib;
2226                         const char *pattern;
2227                 } in;
2228                 struct {
2229                         int16_t count;
2230                 } out;
2231         } search_first;
2232
2233         /* trans2 findfirst interface */
2234         struct {
2235                 enum smb_search_level level;
2236                 enum smb_search_data_level data_level;
2237                 
2238                 struct {
2239                         uint16_t search_attrib;
2240                         uint16_t max_count;
2241                         uint16_t flags;
2242                         uint32_t storage_type;
2243                         const char *pattern;
2244
2245                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2246                         uint_t num_names;
2247                         struct ea_name *ea_names;
2248                 } in;
2249                 struct {
2250                         uint16_t handle;
2251                         uint16_t count;
2252                         uint16_t end_of_search;
2253                 } out;
2254         } t2ffirst;
2255
2256 /*
2257   SMB2 uses different level numbers for the same old SMB trans2 search levels
2258 */
2259 #define SMB2_FIND_DIRECTORY_INFO         0x01
2260 #define SMB2_FIND_FULL_DIRECTORY_INFO    0x02
2261 #define SMB2_FIND_BOTH_DIRECTORY_INFO    0x03
2262 #define SMB2_FIND_NAME_INFO              0x0C
2263 #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25
2264 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26
2265
2266 /* flags for RAW_FILEINFO_SMB2_ALL_EAS */
2267 #define SMB2_CONTINUE_FLAG_RESTART    0x01
2268 #define SMB2_CONTINUE_FLAG_SINGLE     0x02
2269 #define SMB2_CONTINUE_FLAG_NEW        0x10
2270
2271         /* SMB2 Find */
2272         struct smb2_find {
2273                 enum smb_search_level level;
2274                 enum smb_search_data_level data_level;
2275                 struct {
2276                         union smb_handle file;
2277
2278                         /* static body buffer 32 (0x20) bytes */
2279                         /* uint16_t buffer_code;  0x21 = 0x20 + 1 */
2280                         uint8_t level;
2281                         uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */
2282                         uint32_t unknown; /* perhaps a continue token? */
2283                         /* struct smb2_handle handle; */
2284                         /* uint16_t pattern_ofs; */
2285                         /* uint16_t pattern_size; */
2286                         uint32_t max_response_size;
2287         
2288                         /* dynamic body */
2289                         const char *pattern;
2290                 } in;
2291                 struct {
2292                         /* static body buffer 8 (0x08) bytes */
2293                         /* uint16_t buffer_code;  0x08 */
2294                         /* uint16_t blob_ofs; */
2295                         /* uint32_t blob_size; */
2296
2297                         /* dynamic body */
2298                         DATA_BLOB blob;
2299                 } out;
2300         } smb2;
2301 };
2302
2303 /* union for file search continue */
2304 union smb_search_next {
2305         struct {
2306                 enum smb_search_level level;
2307                 enum smb_search_data_level data_level;
2308         } generic;
2309
2310         /* search (old) findnext interface. Also used
2311            for ffirst when continuing */
2312         struct {
2313                 enum smb_search_level level;
2314                 enum smb_search_data_level data_level;
2315         
2316                 struct {
2317                         uint16_t max_count;
2318                         uint16_t search_attrib;
2319                         struct smb_search_id {
2320                                 uint8_t reserved;
2321                                 char name[11];
2322                                 uint8_t handle;
2323                                 uint32_t server_cookie;
2324                                 uint32_t client_cookie;
2325                         } id;
2326                 } in;
2327                 struct {
2328                         uint16_t count;
2329                 } out;
2330         } search_next;
2331         
2332         /* trans2 findnext interface */
2333         struct {
2334                 enum smb_search_level level;
2335                 enum smb_search_data_level data_level;
2336                 
2337                 struct {
2338                         uint16_t handle;
2339                         uint16_t max_count;
2340                         uint32_t resume_key;
2341                         uint16_t flags;
2342                         const char *last_name;
2343
2344                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2345                         uint_t num_names;
2346                         struct ea_name *ea_names;
2347                 } in;
2348                 struct {
2349                         uint16_t count;
2350                         uint16_t end_of_search;
2351                 } out;
2352         } t2fnext;
2353
2354         /* SMB2 Find */
2355         struct smb2_find smb2;
2356 };
2357
2358 /* union for search reply file data */
2359 union smb_search_data {
2360         /*
2361          * search (old) findfirst 
2362          * RAW_SEARCH_DATA_SEARCH
2363          */
2364         struct {
2365                 uint16_t attrib;
2366                 time_t write_time;
2367                 uint32_t size;
2368                 struct smb_search_id id;
2369                 const char *name;
2370         } search;
2371
2372         /* trans2 findfirst RAW_SEARCH_DATA_STANDARD level */
2373         struct {
2374                 uint32_t resume_key;
2375                 time_t create_time;
2376                 time_t access_time;
2377                 time_t write_time;
2378                 uint32_t size;
2379                 uint32_t alloc_size;
2380                 uint16_t attrib;
2381                 struct smb_wire_string name;
2382         } standard;
2383
2384         /* trans2 findfirst RAW_SEARCH_DATA_EA_SIZE level */
2385         struct {
2386                 uint32_t resume_key;
2387                 time_t create_time;
2388                 time_t access_time;
2389                 time_t write_time;
2390                 uint32_t size;
2391                 uint32_t alloc_size;
2392                 uint16_t attrib;
2393                 uint32_t ea_size;
2394                 struct smb_wire_string name;
2395         } ea_size;
2396
2397         /* trans2 findfirst RAW_SEARCH_DATA_EA_LIST level */
2398         struct {
2399                 uint32_t resume_key;
2400                 time_t create_time;
2401                 time_t access_time;
2402                 time_t write_time;
2403                 uint32_t size;
2404                 uint32_t alloc_size;
2405                 uint16_t attrib;
2406                 struct smb_ea_list eas;
2407                 struct smb_wire_string name;
2408         } ea_list;
2409
2410         /* RAW_SEARCH_DATA_DIRECTORY_INFO interface */
2411         struct {
2412                 uint32_t file_index;
2413                 NTTIME create_time;
2414                 NTTIME access_time;
2415                 NTTIME write_time;
2416                 NTTIME change_time;
2417                 uint64_t  size;
2418                 uint64_t  alloc_size;
2419                 uint32_t   attrib;
2420                 struct smb_wire_string name;
2421         } directory_info;
2422
2423         /* RAW_SEARCH_DATA_FULL_DIRECTORY_INFO interface */
2424         struct {
2425                 uint32_t file_index;
2426                 NTTIME create_time;
2427                 NTTIME access_time;
2428                 NTTIME write_time;
2429                 NTTIME change_time;
2430                 uint64_t  size;
2431                 uint64_t  alloc_size;
2432                 uint32_t   attrib;
2433                 uint32_t   ea_size;
2434                 struct smb_wire_string name;
2435         } full_directory_info;
2436
2437         /* RAW_SEARCH_DATA_NAME_INFO interface */
2438         struct {
2439                 uint32_t file_index;
2440                 struct smb_wire_string name;
2441         } name_info;
2442
2443         /* RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO interface */
2444         struct {
2445                 uint32_t file_index;
2446                 NTTIME create_time;
2447                 NTTIME access_time;
2448                 NTTIME write_time;
2449                 NTTIME change_time;
2450                 uint64_t  size;
2451                 uint64_t  alloc_size;
2452                 uint32_t   attrib;
2453                 uint32_t   ea_size;
2454                 struct smb_wire_string short_name;
2455                 struct smb_wire_string name;
2456         } both_directory_info;
2457
2458         /* RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO interface */
2459         struct {
2460                 uint32_t file_index;
2461                 NTTIME create_time;
2462                 NTTIME access_time;
2463                 NTTIME write_time;
2464                 NTTIME change_time;
2465                 uint64_t size;
2466                 uint64_t alloc_size;
2467                 uint32_t attrib;
2468                 uint32_t ea_size;
2469                 uint64_t file_id;
2470                 struct smb_wire_string name;
2471         } id_full_directory_info;
2472
2473         /* RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO interface */
2474         struct {
2475                 uint32_t file_index;
2476                 NTTIME create_time;
2477                 NTTIME access_time;
2478                 NTTIME write_time;
2479                 NTTIME change_time;
2480                 uint64_t size;
2481                 uint64_t alloc_size;
2482                 uint32_t  attrib;
2483                 uint32_t  ea_size;
2484                 uint64_t file_id;
2485                 struct smb_wire_string short_name;
2486                 struct smb_wire_string name;
2487         } id_both_directory_info;
2488
2489         /* RAW_SEARCH_DATA_UNIX_INFO interface */
2490         struct {
2491                 uint32_t file_index;
2492                 uint64_t size;
2493                 uint64_t alloc_size;
2494                 NTTIME status_change_time;
2495                 NTTIME access_time;
2496                 NTTIME change_time;
2497                 uint64_t uid;
2498                 uint64_t gid;
2499                 uint32_t file_type;
2500                 uint64_t dev_major;
2501                 uint64_t dev_minor;
2502                 uint64_t unique_id;
2503                 uint64_t permissions;
2504                 uint64_t nlink;         
2505                 const char *name;
2506         } unix_info;
2507 };
2508
2509
2510 enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE};
2511
2512 /* union for file search close */
2513 union smb_search_close {
2514         struct {
2515                 enum smb_search_close_level level;
2516         } generic;
2517
2518         /* SMBfclose (old search) interface */
2519         struct {
2520                 enum smb_search_close_level level;
2521         
2522                 struct {
2523                         /* max_count and search_attrib are not used, but are present */
2524                         uint16_t max_count;
2525                         uint16_t search_attrib;
2526                         struct smb_search_id id;
2527                 } in;
2528         } fclose;
2529         
2530         /* SMBfindclose interface */
2531         struct {
2532                 enum smb_search_close_level level;
2533                 
2534                 struct {
2535                         uint16_t handle;
2536                 } in;
2537         } findclose;
2538 };
2539
2540 #endif /* __LIBCLI_RAW_INTERFACES_H__ */