r15756: handle RAW_OPEN_SMB2
[kai/samba.git] / source4 / 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                         /* static body buffer 16 (0x10) bytes */
376                         /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
377                         uint16_t _pad;
378                         uint32_t unknown2; /* 0xF */
379                         uint32_t unknown3; /* 0x00 */
380                         /* uint16_t secblob_ofs */
381                         /* uint16_t secblob_size */
382
383                         /* dynamic body */
384                         DATA_BLOB secblob;
385                 } in;
386                 struct {
387                         /* static body buffer 8 (0x08) bytes */
388                         /* uint16_t buffer_code; 0x09 = 0x08 +1 */
389                         uint16_t _pad;
390                         /* uint16_t secblob_ofs */
391                         /* uint16_t secblob_size */
392
393                         /* dynamic body */
394                         DATA_BLOB secblob;
395
396                         /* extracted from the SMB2 header */
397                         uint64_t uid;
398                 } out;
399         } smb2;
400 };
401
402 /* Note that the specified enum values are identical to the actual info-levels used
403  * on the wire.
404  */
405 enum smb_fileinfo_level {
406                      RAW_FILEINFO_GENERIC                    = 0xF000, 
407                      RAW_FILEINFO_GETATTR,                   /* SMBgetatr */
408                      RAW_FILEINFO_GETATTRE,                  /* SMBgetattrE */
409                      RAW_FILEINFO_SEC_DESC,                  /* NT_TRANSACT_QUERY_SECURITY_DESC */
410                      RAW_FILEINFO_STANDARD                   = SMB_QFILEINFO_STANDARD,
411                      RAW_FILEINFO_EA_SIZE                    = SMB_QFILEINFO_EA_SIZE,
412                      RAW_FILEINFO_EA_LIST                    = SMB_QFILEINFO_EA_LIST,
413                      RAW_FILEINFO_ALL_EAS                    = SMB_QFILEINFO_ALL_EAS,
414                      RAW_FILEINFO_IS_NAME_VALID              = SMB_QFILEINFO_IS_NAME_VALID,
415                      RAW_FILEINFO_BASIC_INFO                 = SMB_QFILEINFO_BASIC_INFO, 
416                      RAW_FILEINFO_STANDARD_INFO              = SMB_QFILEINFO_STANDARD_INFO,
417                      RAW_FILEINFO_EA_INFO                    = SMB_QFILEINFO_EA_INFO,
418                      RAW_FILEINFO_NAME_INFO                  = SMB_QFILEINFO_NAME_INFO, 
419                      RAW_FILEINFO_ALL_INFO                   = SMB_QFILEINFO_ALL_INFO,
420                      RAW_FILEINFO_ALT_NAME_INFO              = SMB_QFILEINFO_ALT_NAME_INFO,
421                      RAW_FILEINFO_STREAM_INFO                = SMB_QFILEINFO_STREAM_INFO,
422                      RAW_FILEINFO_COMPRESSION_INFO           = SMB_QFILEINFO_COMPRESSION_INFO,
423                      RAW_FILEINFO_UNIX_BASIC                 = SMB_QFILEINFO_UNIX_BASIC,
424                      RAW_FILEINFO_UNIX_LINK                  = SMB_QFILEINFO_UNIX_LINK,
425                      RAW_FILEINFO_BASIC_INFORMATION          = SMB_QFILEINFO_BASIC_INFORMATION,
426                      RAW_FILEINFO_STANDARD_INFORMATION       = SMB_QFILEINFO_STANDARD_INFORMATION,
427                      RAW_FILEINFO_INTERNAL_INFORMATION       = SMB_QFILEINFO_INTERNAL_INFORMATION,
428                      RAW_FILEINFO_EA_INFORMATION             = SMB_QFILEINFO_EA_INFORMATION,
429                      RAW_FILEINFO_ACCESS_INFORMATION         = SMB_QFILEINFO_ACCESS_INFORMATION,
430                      RAW_FILEINFO_NAME_INFORMATION           = SMB_QFILEINFO_NAME_INFORMATION,
431                      RAW_FILEINFO_POSITION_INFORMATION       = SMB_QFILEINFO_POSITION_INFORMATION,
432                      RAW_FILEINFO_MODE_INFORMATION           = SMB_QFILEINFO_MODE_INFORMATION,
433                      RAW_FILEINFO_ALIGNMENT_INFORMATION      = SMB_QFILEINFO_ALIGNMENT_INFORMATION,
434                      RAW_FILEINFO_ALL_INFORMATION            = SMB_QFILEINFO_ALL_INFORMATION,
435                      RAW_FILEINFO_ALT_NAME_INFORMATION       = SMB_QFILEINFO_ALT_NAME_INFORMATION,
436                      RAW_FILEINFO_STREAM_INFORMATION         = SMB_QFILEINFO_STREAM_INFORMATION,
437                      RAW_FILEINFO_COMPRESSION_INFORMATION    = SMB_QFILEINFO_COMPRESSION_INFORMATION,
438                      RAW_FILEINFO_NETWORK_OPEN_INFORMATION   = SMB_QFILEINFO_NETWORK_OPEN_INFORMATION,
439                      RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION  = SMB_QFILEINFO_ATTRIBUTE_TAG_INFORMATION,
440                      /* SMB2 specific levels */
441                      RAW_FILEINFO_SMB2_ALL_EAS               = 0x0f01,
442                      RAW_FILEINFO_SMB2_ALL_INFORMATION       = 0x1201
443 };
444
445 /* union used in qfileinfo() and qpathinfo() backend calls */
446 union smb_fileinfo {
447         /* generic interface:
448          * matches RAW_FILEINFO_GENERIC */
449         struct {
450                 enum smb_fileinfo_level level;
451                 struct {
452                         union smb_handle_or_path file;
453                 } in;
454                 struct {
455                         uint32_t attrib;
456                         uint32_t ea_size;
457                         uint_t num_eas;
458                         struct ea_struct {
459                                 uint8_t flags;
460                                 struct smb_wire_string name;
461                                 DATA_BLOB value;
462                         } *eas;         
463                         NTTIME create_time;
464                         NTTIME access_time;
465                         NTTIME write_time;
466                         NTTIME change_time;
467                         uint64_t alloc_size;
468                         uint64_t size;
469                         uint32_t nlink;
470                         struct smb_wire_string fname;   
471                         struct smb_wire_string alt_fname;       
472                         uint8_t delete_pending;
473                         uint8_t directory;
474                         uint64_t compressed_size;
475                         uint16_t format;
476                         uint8_t unit_shift;
477                         uint8_t chunk_shift;
478                         uint8_t cluster_shift;
479                         uint64_t file_id;
480                         uint32_t access_flags; /* seen 0x001f01ff from w2k3 */
481                         uint64_t position;
482                         uint32_t mode;
483                         uint32_t alignment_requirement;
484                         uint32_t reparse_tag;
485                         uint_t num_streams;
486                         struct stream_struct {
487                                 uint64_t size;
488                                 uint64_t alloc_size;
489                                 struct smb_wire_string stream_name;
490                         } *streams;
491                 } out;
492         } generic;
493
494
495         /* SMBgetatr interface:
496          * matches RAW_FILEINFO_GETATTR */
497         struct {
498                 enum smb_fileinfo_level level;
499                 struct {
500                         union smb_handle_or_path file;
501                 } in;
502                 struct {
503                         uint16_t attrib;
504                         uint32_t size;
505                         time_t write_time;
506                 } out;
507         } getattr;
508
509         /* SMBgetattrE and  RAW_FILEINFO_STANDARD interface */
510         struct {
511                 enum smb_fileinfo_level level;
512                 struct {
513                         union smb_handle_or_path file;
514                 } in;
515                 struct {
516                         time_t create_time;
517                         time_t access_time;
518                         time_t write_time;
519                         uint32_t size;
520                         uint32_t alloc_size;
521                         uint16_t attrib;
522                 } out;
523         } getattre, standard;
524
525         /* trans2 RAW_FILEINFO_EA_SIZE interface */
526         struct {
527                 enum smb_fileinfo_level level;
528                 struct {
529                         union smb_handle_or_path file;
530                 } in;
531                 struct {
532                         time_t create_time;
533                         time_t access_time;
534                         time_t write_time;
535                         uint32_t size;
536                         uint32_t alloc_size;
537                         uint16_t attrib;
538                         uint32_t ea_size;
539                 } out;
540         } ea_size;
541
542         /* trans2 RAW_FILEINFO_EA_LIST interface */
543         struct {
544                 enum smb_fileinfo_level level;
545                 struct {
546                         union smb_handle_or_path file;
547                         uint_t num_names;
548                         struct ea_name {
549                                 struct smb_wire_string name;
550                         } *ea_names;    
551                 } in;   
552
553                 struct smb_ea_list {
554                         uint_t num_eas;
555                         struct ea_struct *eas;
556                 } out;
557         } ea_list;
558
559         /* trans2 RAW_FILEINFO_ALL_EAS and RAW_FILEINFO_FULL_EA_INFORMATION interfaces */
560         struct {
561                 enum smb_fileinfo_level level;
562                 struct {
563                         union smb_handle_or_path file;
564                         /* SMB2 only - SMB2_CONTINUE_FLAG_* */
565                         uint8_t continue_flags;
566                 } in;
567                 struct smb_ea_list out;
568         } all_eas;
569
570         /* trans2 qpathinfo RAW_FILEINFO_IS_NAME_VALID interface 
571            only valid for a QPATHNAME call - no returned data */
572         struct {
573                 enum smb_fileinfo_level level;
574                 struct {
575                         union smb_handle_or_path file;
576                 } in;
577         } is_name_valid;
578
579         /* RAW_FILEINFO_BASIC_INFO and RAW_FILEINFO_BASIC_INFORMATION interfaces */
580         struct {
581                 enum smb_fileinfo_level level;
582                 struct {
583                         union smb_handle_or_path file;
584                 } in;
585                 struct {
586                         NTTIME create_time;
587                         NTTIME access_time;
588                         NTTIME write_time;
589                         NTTIME change_time;
590                         uint32_t attrib;
591                 } out;
592         } basic_info;
593                 
594
595         /* RAW_FILEINFO_STANDARD_INFO and RAW_FILEINFO_STANDARD_INFORMATION interfaces */
596         struct {
597                 enum smb_fileinfo_level level;
598                 struct {
599                         union smb_handle_or_path file;
600                 } in;
601                 struct {
602                         uint64_t alloc_size;
603                         uint64_t size;
604                         uint32_t nlink;
605                         BOOL delete_pending;
606                         BOOL directory;
607                 } out;
608         } standard_info;
609         
610         /* RAW_FILEINFO_EA_INFO and RAW_FILEINFO_EA_INFORMATION interfaces */
611         struct {
612                 enum smb_fileinfo_level level;
613                 struct {
614                         union smb_handle_or_path file;
615                 } in;
616                 struct {
617                         uint32_t ea_size;
618                 } out;
619         } ea_info;
620
621         /* RAW_FILEINFO_NAME_INFO and RAW_FILEINFO_NAME_INFORMATION interfaces */
622         struct {
623                 enum smb_fileinfo_level level;
624                 struct {
625                         union smb_handle_or_path file;
626                 } in;
627                 struct {
628                         struct smb_wire_string fname;
629                 } out;
630         } name_info;
631
632         /* RAW_FILEINFO_ALL_INFO and RAW_FILEINFO_ALL_INFORMATION interfaces */
633         struct {
634                 enum smb_fileinfo_level level;
635                 struct {
636                         union smb_handle_or_path file;
637                 } in;
638                 struct {
639                         NTTIME create_time;
640                         NTTIME access_time;
641                         NTTIME write_time;
642                         NTTIME change_time;
643                         uint32_t attrib;
644                         uint64_t alloc_size;
645                         uint64_t size;
646                         uint32_t nlink;
647                         uint8_t delete_pending;
648                         uint8_t directory;
649                         uint32_t ea_size;
650                         struct smb_wire_string fname;
651                 } out;
652         } all_info;     
653
654         /* RAW_FILEINFO_SMB2_ALL_INFORMATION interface */
655         struct {
656                 enum smb_fileinfo_level level;
657                 struct {
658                         union smb_handle_or_path file;
659                 } in;
660                 struct {
661                         NTTIME   create_time;
662                         NTTIME   access_time;
663                         NTTIME   write_time;
664                         NTTIME   change_time;
665                         uint32_t attrib;
666                         uint32_t unknown1;
667                         uint64_t alloc_size;
668                         uint64_t size;
669                         uint32_t nlink;
670                         uint8_t  delete_pending;
671                         uint8_t  directory;
672                         /* uint16_t _pad; */
673                         uint64_t file_id;
674                         uint32_t ea_size;
675                         uint32_t access_mask;
676                         uint64_t position;
677                         uint64_t mode;
678                         struct smb_wire_string fname;
679                 } out;
680         } all_info2;
681
682         /* RAW_FILEINFO_ALT_NAME_INFO and RAW_FILEINFO_ALT_NAME_INFORMATION interfaces */
683         struct {
684                 enum smb_fileinfo_level level;
685                 struct {
686                         union smb_handle_or_path file;
687                 } in;
688                 struct {
689                         struct smb_wire_string fname;
690                 } out;
691         } alt_name_info;
692
693         /* RAW_FILEINFO_STREAM_INFO and RAW_FILEINFO_STREAM_INFORMATION interfaces */
694         struct {
695                 enum smb_fileinfo_level level;
696                 struct {
697                         union smb_handle_or_path file;
698                 } in;
699                 struct stream_information {
700                         uint_t num_streams;
701                         struct stream_struct *streams;
702                 } out;
703         } stream_info;
704         
705         /* RAW_FILEINFO_COMPRESSION_INFO and RAW_FILEINFO_COMPRESSION_INFORMATION interfaces */
706         struct {
707                 enum smb_fileinfo_level level;
708                 struct {
709                         union smb_handle_or_path file;
710                 } in;
711                 struct {
712                         uint64_t compressed_size;
713                         uint16_t format;
714                         uint8_t unit_shift;
715                         uint8_t chunk_shift;
716                         uint8_t cluster_shift;
717                 } out;
718         } compression_info;
719
720         /* RAW_FILEINFO_UNIX_BASIC interface */
721         struct {
722                 enum smb_fileinfo_level level;
723                 struct {
724                         union smb_handle_or_path file;
725                 } in;
726                 struct {
727                         uint64_t end_of_file;
728                         uint64_t num_bytes;
729                         NTTIME status_change_time;
730                         NTTIME access_time;
731                         NTTIME change_time;
732                         uint64_t uid;
733                         uint64_t gid;
734                         uint32_t file_type;
735                         uint64_t dev_major;
736                         uint64_t dev_minor;
737                         uint64_t unique_id;
738                         uint64_t permissions;
739                         uint64_t nlink;
740                 } out;
741         } unix_basic_info;
742
743         /* RAW_FILEINFO_UNIX_LINK interface */
744         struct {
745                 enum smb_fileinfo_level level;
746                 struct {
747                         union smb_handle_or_path file;
748                 } in;
749                 struct {
750                         struct smb_wire_string link_dest;
751                 } out;
752         } unix_link_info;
753
754         /* RAW_FILEINFO_INTERNAL_INFORMATION interface */
755         struct {
756                 enum smb_fileinfo_level level;
757                 struct {
758                         union smb_handle_or_path file;
759                 } in;
760                 struct {
761                         uint64_t file_id;
762                 } out;
763         } internal_information;
764
765         /* RAW_FILEINFO_ACCESS_INFORMATION interface */
766         struct {
767                 enum smb_fileinfo_level level;
768                 struct {
769                         union smb_handle_or_path file;
770                 } in;
771                 struct {
772                         uint32_t access_flags;
773                 } out;
774         } access_information;
775
776         /* RAW_FILEINFO_POSITION_INFORMATION interface */
777         struct {
778                 enum smb_fileinfo_level level;
779                 struct {
780                         union smb_handle_or_path file;
781                 } in;
782                 struct {
783                         uint64_t position;
784                 } out;
785         } position_information;
786
787         /* RAW_FILEINFO_MODE_INFORMATION interface */
788         struct {
789                 enum smb_fileinfo_level level;
790                 struct {
791                         union smb_handle_or_path file;
792                 } in;
793                 struct {
794                         uint32_t mode;
795                 } out;
796         } mode_information;
797
798         /* RAW_FILEINFO_ALIGNMENT_INFORMATION interface */
799         struct {
800                 enum smb_fileinfo_level level;
801                 struct {
802                         union smb_handle_or_path file;
803                 } in;
804                 struct {
805                         uint32_t alignment_requirement;
806                 } out;
807         } alignment_information;
808
809         /* RAW_FILEINFO_NETWORK_OPEN_INFORMATION interface */
810         struct {
811                 enum smb_fileinfo_level level;
812                 struct {
813                         union smb_handle_or_path file;
814                 } in;
815                 struct {
816                         NTTIME create_time;
817                         NTTIME access_time;
818                         NTTIME write_time;
819                         NTTIME change_time;
820                         uint64_t alloc_size;
821                         uint64_t size;
822                         uint32_t attrib;
823                 } out;
824         } network_open_information;
825
826
827         /* RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION interface */
828         struct {
829                 enum smb_fileinfo_level level;
830                 struct {
831                         union smb_handle_or_path file;
832                 } in;
833                 struct {
834                         uint32_t attrib;
835                         uint32_t reparse_tag;
836                 } out;
837         } attribute_tag_information;
838
839         /* RAW_FILEINFO_SEC_DESC */
840         struct {
841                 enum smb_fileinfo_level level;
842                 struct {
843                         union smb_handle_or_path file;
844                         uint32_t secinfo_flags;
845                 } in;
846                 struct {
847                         struct security_descriptor *sd;
848                 } out;
849         } query_secdesc;
850 };
851
852
853 enum smb_setfileinfo_level {
854         RAW_SFILEINFO_GENERIC                 = 0xF000, 
855         RAW_SFILEINFO_SETATTR,                /* SMBsetatr */
856         RAW_SFILEINFO_SETATTRE,               /* SMBsetattrE */
857         RAW_SFILEINFO_SEC_DESC,               /* NT_TRANSACT_SET_SECURITY_DESC */
858         RAW_SFILEINFO_STANDARD                = SMB_SFILEINFO_STANDARD,
859         RAW_SFILEINFO_EA_SET                  = SMB_SFILEINFO_EA_SET,
860         RAW_SFILEINFO_BASIC_INFO              = SMB_SFILEINFO_BASIC_INFO,
861         RAW_SFILEINFO_DISPOSITION_INFO        = SMB_SFILEINFO_DISPOSITION_INFO,
862         RAW_SFILEINFO_ALLOCATION_INFO         = SMB_SFILEINFO_ALLOCATION_INFO,
863         RAW_SFILEINFO_END_OF_FILE_INFO        = SMB_SFILEINFO_END_OF_FILE_INFO,
864         RAW_SFILEINFO_UNIX_BASIC              = SMB_SFILEINFO_UNIX_BASIC,
865         RAW_SFILEINFO_UNIX_LINK               = SMB_SFILEINFO_UNIX_LINK,
866         RAW_SFILEINFO_UNIX_HLINK              = SMB_SFILEINFO_UNIX_HLINK,
867         RAW_SFILEINFO_BASIC_INFORMATION       = SMB_SFILEINFO_BASIC_INFORMATION,
868         RAW_SFILEINFO_RENAME_INFORMATION      = SMB_SFILEINFO_RENAME_INFORMATION,
869         RAW_SFILEINFO_DISPOSITION_INFORMATION = SMB_SFILEINFO_DISPOSITION_INFORMATION,
870         RAW_SFILEINFO_POSITION_INFORMATION    = SMB_SFILEINFO_POSITION_INFORMATION,
871         RAW_SFILEINFO_MODE_INFORMATION        = SMB_SFILEINFO_MODE_INFORMATION,
872         RAW_SFILEINFO_ALLOCATION_INFORMATION  = SMB_SFILEINFO_ALLOCATION_INFORMATION,
873         RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION,
874         RAW_SFILEINFO_1023                    = SMB_SFILEINFO_1023,
875         RAW_SFILEINFO_1025                    = SMB_SFILEINFO_1025,
876         RAW_SFILEINFO_1029                    = SMB_SFILEINFO_1029,
877         RAW_SFILEINFO_1032                    = SMB_SFILEINFO_1032,
878         RAW_SFILEINFO_1039                    = SMB_SFILEINFO_1039,
879         RAW_SFILEINFO_1040                    = SMB_SFILEINFO_1040
880 };
881
882 /* union used in setfileinfo() and setpathinfo() calls */
883 union smb_setfileinfo {
884         /* generic interface */
885         struct {
886                 enum smb_setfileinfo_level level;
887                 struct {
888                         union smb_handle_or_path file;
889                 } in;
890         } generic;
891
892         /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */
893         struct {
894                 enum smb_setfileinfo_level level;
895                 struct {
896                         union smb_handle_or_path file;
897                         uint16_t attrib;
898                         time_t write_time;
899                 } in;
900         } setattr;
901
902         /* RAW_SFILEINFO_SETATTRE (SMBsetattrE) interface - only via setfileinfo() 
903            also RAW_SFILEINFO_STANDARD */
904         struct {
905                 enum smb_setfileinfo_level level;
906                 struct {
907                         union smb_handle_or_path file;
908                         time_t create_time;
909                         time_t access_time;
910                         time_t write_time;
911                         /* notice that size, alloc_size and attrib are not settable,
912                            unlike the corresponding qfileinfo level */
913                 } in;
914         } setattre, standard;
915
916         /* RAW_SFILEINFO_EA_SET interface */
917         struct {
918                 enum smb_setfileinfo_level level;
919                 struct {
920                         union smb_handle_or_path file;
921                         uint_t num_eas;
922                         struct ea_struct *eas;                  
923                 } in;
924         } ea_set;
925
926         /* RAW_SFILEINFO_BASIC_INFO and
927            RAW_SFILEINFO_BASIC_INFORMATION interfaces */
928         struct {
929                 enum smb_setfileinfo_level level;
930                 struct {
931                         union smb_handle_or_path file;
932                         NTTIME create_time;
933                         NTTIME access_time;
934                         NTTIME write_time;
935                         NTTIME change_time;
936                         uint32_t attrib;
937                 } in;
938         } basic_info;
939
940         /* RAW_SFILEINFO_DISPOSITION_INFO and 
941            RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */
942         struct {
943                 enum smb_setfileinfo_level level;
944                 struct {
945                         union smb_handle_or_path file;
946                         BOOL delete_on_close;
947                 } in;
948         } disposition_info;
949
950         /* RAW_SFILEINFO_ALLOCATION_INFO and 
951            RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */
952         struct {
953                 enum smb_setfileinfo_level level;
954                 struct {
955                         union smb_handle_or_path file;
956                         /* w2k3 rounds this up to nearest 4096 */
957                         uint64_t alloc_size;
958                 } in;
959         } allocation_info;
960         
961         /* RAW_SFILEINFO_END_OF_FILE_INFO and 
962            RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */
963         struct {
964                 enum smb_setfileinfo_level level;
965                 struct {
966                         union smb_handle_or_path file;
967                         uint64_t size;
968                 } in;
969         } end_of_file_info;
970
971         /* RAW_SFILEINFO_RENAME_INFORMATION interface */
972         struct {
973                 enum smb_setfileinfo_level level;
974                 struct {
975                         union smb_handle_or_path file;
976                         uint8_t overwrite;
977                         uint32_t root_fid;
978                         const char *new_name;
979                 } in;
980         } rename_information;
981
982         /* RAW_SFILEINFO_POSITION_INFORMATION interface */
983         struct {
984                 enum smb_setfileinfo_level level;
985                 struct {
986                         union smb_handle_or_path file;
987                         uint64_t position;
988                 } in;
989         } position_information;
990
991         /* RAW_SFILEINFO_MODE_INFORMATION interface */
992         struct {
993                 enum smb_setfileinfo_level level;
994                 struct {
995                         union smb_handle_or_path file;
996                         /* valid values seem to be 0, 2, 4 and 6 */
997                         uint32_t mode;
998                 } in;
999         } mode_information;
1000
1001
1002
1003         /* RAW_SFILEINFO_UNIX_BASIC interface */
1004         struct {
1005                 enum smb_setfileinfo_level level;
1006                 struct {
1007                         union smb_handle_or_path file;
1008                         uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */
1009                         uint64_t end_of_file;
1010                         uint64_t num_bytes;
1011                         NTTIME status_change_time;
1012                         NTTIME access_time;
1013                         NTTIME change_time;
1014                         uint64_t uid;
1015                         uint64_t gid;
1016                         uint32_t file_type;
1017                         uint64_t dev_major;
1018                         uint64_t dev_minor;
1019                         uint64_t unique_id;
1020                         uint64_t permissions;
1021                         uint64_t nlink;
1022                 } in;
1023         } unix_basic;
1024         
1025         /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */
1026         struct {
1027                 enum smb_setfileinfo_level level;
1028                 struct {
1029                         union smb_handle_or_path file;
1030                         const char *link_dest;
1031                 } in;
1032         } unix_link, unix_hlink;
1033
1034         /* RAW_FILEINFO_SET_SEC_DESC */
1035         struct {
1036                 enum smb_setfileinfo_level level;
1037                 struct {
1038                         union smb_handle_or_path file;
1039                         uint32_t secinfo_flags;
1040                         struct security_descriptor *sd;
1041                 } in;
1042         } set_secdesc;
1043 };
1044
1045
1046 enum smb_fsinfo_level {
1047                    RAW_QFS_GENERIC                        = 0xF000, 
1048                    RAW_QFS_DSKATTR,                         /* SMBdskattr */
1049                    RAW_QFS_ALLOCATION                     = SMB_QFS_ALLOCATION,
1050                    RAW_QFS_VOLUME                         = SMB_QFS_VOLUME,
1051                    RAW_QFS_VOLUME_INFO                    = SMB_QFS_VOLUME_INFO,
1052                    RAW_QFS_SIZE_INFO                      = SMB_QFS_SIZE_INFO,
1053                    RAW_QFS_DEVICE_INFO                    = SMB_QFS_DEVICE_INFO,
1054                    RAW_QFS_ATTRIBUTE_INFO                 = SMB_QFS_ATTRIBUTE_INFO,
1055                    RAW_QFS_UNIX_INFO                      = SMB_QFS_UNIX_INFO,
1056                    RAW_QFS_VOLUME_INFORMATION             = SMB_QFS_VOLUME_INFORMATION,
1057                    RAW_QFS_SIZE_INFORMATION               = SMB_QFS_SIZE_INFORMATION,
1058                    RAW_QFS_DEVICE_INFORMATION             = SMB_QFS_DEVICE_INFORMATION,
1059                    RAW_QFS_ATTRIBUTE_INFORMATION          = SMB_QFS_ATTRIBUTE_INFORMATION,
1060                    RAW_QFS_QUOTA_INFORMATION              = SMB_QFS_QUOTA_INFORMATION,
1061                    RAW_QFS_FULL_SIZE_INFORMATION          = SMB_QFS_FULL_SIZE_INFORMATION,
1062                    RAW_QFS_OBJECTID_INFORMATION           = SMB_QFS_OBJECTID_INFORMATION};
1063
1064
1065 /* union for fsinfo() backend call. Note that there are no in
1066    structures, as this call only contains out parameters */
1067 union smb_fsinfo {
1068         /* generic interface */
1069         struct {
1070                 enum smb_fsinfo_level level;
1071                 struct smb2_handle handle; /* only for smb2 */
1072
1073                 struct {
1074                         uint32_t block_size;
1075                         uint64_t blocks_total;
1076                         uint64_t blocks_free;
1077                         uint32_t fs_id;
1078                         NTTIME create_time;
1079                         uint32_t serial_number;
1080                         uint32_t fs_attr;
1081                         uint32_t max_file_component_length;
1082                         uint32_t device_type;
1083                         uint32_t device_characteristics;
1084                         uint64_t quota_soft;
1085                         uint64_t quota_hard;
1086                         uint64_t quota_flags;
1087                         struct GUID guid;
1088                         char *volume_name;
1089                         char *fs_type;
1090                 } out;
1091         } generic;
1092
1093         /* SMBdskattr interface */
1094         struct {
1095                 enum smb_fsinfo_level level;
1096
1097                 struct {
1098                         uint16_t units_total;
1099                         uint16_t blocks_per_unit;
1100                         uint16_t block_size;
1101                         uint16_t units_free;
1102                 } out;
1103         } dskattr;
1104
1105         /* trans2 RAW_QFS_ALLOCATION interface */
1106         struct {
1107                 enum smb_fsinfo_level level;
1108
1109                 struct {
1110                         uint32_t fs_id;
1111                         uint32_t sectors_per_unit;
1112                         uint32_t total_alloc_units;
1113                         uint32_t avail_alloc_units;
1114                         uint16_t bytes_per_sector;
1115                 } out;
1116         } allocation;
1117
1118         /* TRANS2 RAW_QFS_VOLUME interface */
1119         struct {
1120                 enum smb_fsinfo_level level;
1121
1122                 struct {
1123                         uint32_t serial_number;
1124                         struct smb_wire_string volume_name;
1125                 } out;
1126         } volume;
1127
1128         /* TRANS2 RAW_QFS_VOLUME_INFO and RAW_QFS_VOLUME_INFORMATION interfaces */
1129         struct {
1130                 enum smb_fsinfo_level level;
1131                 struct smb2_handle handle; /* only for smb2 */
1132
1133                 struct {
1134                         NTTIME create_time;
1135                         uint32_t serial_number;
1136                         struct smb_wire_string volume_name;
1137                 } out;
1138         } volume_info;
1139
1140         /* trans2 RAW_QFS_SIZE_INFO and RAW_QFS_SIZE_INFORMATION interfaces */
1141         struct {
1142                 enum smb_fsinfo_level level;
1143                 struct smb2_handle handle; /* only for smb2 */
1144
1145                 struct {
1146                         uint64_t total_alloc_units;
1147                         uint64_t avail_alloc_units; /* maps to call_avail_alloc_units */
1148                         uint32_t sectors_per_unit;
1149                         uint32_t bytes_per_sector;
1150                 } out;
1151         } size_info;
1152
1153         /* TRANS2 RAW_QFS_DEVICE_INFO and RAW_QFS_DEVICE_INFORMATION interfaces */
1154         struct {
1155                 enum smb_fsinfo_level level;
1156                 struct smb2_handle handle; /* only for smb2 */
1157
1158                 struct {
1159                         uint32_t device_type;
1160                         uint32_t characteristics;
1161                 } out;
1162         } device_info;
1163
1164
1165         /* TRANS2 RAW_QFS_ATTRIBUTE_INFO and RAW_QFS_ATTRIBUTE_INFORMATION interfaces */
1166         struct {
1167                 enum smb_fsinfo_level level;
1168                 struct smb2_handle handle; /* only for smb2 */
1169
1170                 struct {
1171                         uint32_t fs_attr;
1172                         uint32_t max_file_component_length;
1173                         struct smb_wire_string fs_type;
1174                 } out;
1175         } attribute_info;
1176
1177
1178         /* TRANS2 RAW_QFS_UNIX_INFO interface */
1179         struct {
1180                 enum smb_fsinfo_level level;
1181
1182                 struct {
1183                         uint16_t major_version;
1184                         uint16_t minor_version;
1185                         uint64_t capability;
1186                 } out;
1187         } unix_info;
1188
1189         /* trans2 RAW_QFS_QUOTA_INFORMATION interface */
1190         struct {
1191                 enum smb_fsinfo_level level;
1192                 struct smb2_handle handle; /* only for smb2 */
1193
1194                 struct {
1195                         uint64_t unknown[3];
1196                         uint64_t quota_soft;
1197                         uint64_t quota_hard;
1198                         uint64_t quota_flags;
1199                 } out;
1200         } quota_information;    
1201
1202         /* trans2 RAW_QFS_FULL_SIZE_INFORMATION interface */
1203         struct {
1204                 enum smb_fsinfo_level level;
1205                 struct smb2_handle handle; /* only for smb2 */
1206
1207                 struct {
1208                         uint64_t total_alloc_units;
1209                         uint64_t call_avail_alloc_units;
1210                         uint64_t actual_avail_alloc_units;
1211                         uint32_t sectors_per_unit;
1212                         uint32_t bytes_per_sector;
1213                 } out;
1214         } full_size_information;
1215
1216         /* trans2 RAW_QFS_OBJECTID_INFORMATION interface */
1217         struct {
1218                 enum smb_fsinfo_level level;
1219                 struct smb2_handle handle; /* only for smb2 */
1220
1221                 struct {
1222                         struct GUID  guid;
1223                         uint64_t unknown[6];
1224                 } out;
1225         } objectid_information; 
1226 };
1227
1228
1229
1230 enum smb_open_level {
1231         RAW_OPEN_OPEN,
1232         RAW_OPEN_OPENX, 
1233         RAW_OPEN_MKNEW,
1234         RAW_OPEN_CREATE, 
1235         RAW_OPEN_CTEMP,
1236         RAW_OPEN_SPLOPEN,
1237         RAW_OPEN_NTCREATEX,
1238         RAW_OPEN_T2OPEN,
1239         RAW_OPEN_NTTRANS_CREATE, 
1240         RAW_OPEN_OPENX_READX,
1241         RAW_OPEN_SMB2
1242 };
1243
1244 /* the generic interface is defined to be equal to the NTCREATEX interface */
1245 #define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX
1246
1247 /* union for open() backend call */
1248 union smb_open {
1249 /* 
1250  * because the *.out.file structs are not aligned to the same offset for each level
1251  * we provide a hepler macro that should be used to find the current smb_handle structure
1252  */
1253 #define SMB_OPEN_OUT_FILE(op, file) do { \
1254         switch (op->generic.level) { \
1255         case RAW_OPEN_OPEN: \
1256                 file = &op->openold.out.file; \
1257                 break; \
1258         case RAW_OPEN_OPENX: \
1259                 file = &op->openx.out.file; \
1260                 break; \
1261         case RAW_OPEN_MKNEW: \
1262                 file = &op->mknew.out.file; \
1263                 break; \
1264         case RAW_OPEN_CREATE: \
1265                 file = &op->create.out.file; \
1266                 break; \
1267         case RAW_OPEN_CTEMP: \
1268                 file = &op->ctemp.out.file; \
1269                 break; \
1270         case RAW_OPEN_SPLOPEN: \
1271                 file = &op->splopen.out.file; \
1272                 break; \
1273         case RAW_OPEN_NTCREATEX: \
1274                 file = &op->ntcreatex.out.file; \
1275                 break; \
1276         case RAW_OPEN_T2OPEN: \
1277                 file = &op->t2open.out.file; \
1278                 break; \
1279         case RAW_OPEN_NTTRANS_CREATE: \
1280                 file = &op->nttrans.out.file; \
1281                 break; \
1282         case RAW_OPEN_OPENX_READX: \
1283                 file = &op->openxreadx.out.file; \
1284                 break; \
1285         case RAW_OPEN_SMB2: \
1286                 file = &op->smb2.out.file; \
1287                 break; \
1288         default: \
1289                 /* this must be a programmer error */ \
1290                 file = NULL; \
1291                 break; \
1292         } \
1293 } while (0)
1294         /* SMBNTCreateX interface */
1295         struct {
1296                 enum smb_open_level level;
1297                 struct {
1298                         uint32_t flags;
1299                         uint32_t root_fid;
1300                         uint32_t access_mask;
1301                         uint64_t alloc_size;
1302                         uint32_t file_attr;
1303                         uint32_t share_access;
1304                         uint32_t open_disposition;
1305                         uint32_t create_options;
1306                         uint32_t impersonation;
1307                         uint8_t  security_flags;
1308                         /* NOTE: fname can also be a pointer to a
1309                          uint64_t file_id if create_options has the
1310                          NTCREATEX_OPTIONS_OPEN_BY_FILE_ID flag set */
1311                         const char *fname;
1312
1313                         /* these last 2 elements are only used in the
1314                            NTTRANS varient of the call */
1315                         struct security_descriptor *sec_desc;
1316                         struct smb_ea_list *ea_list;
1317                 } in;
1318                 struct {
1319                         union smb_handle file;
1320                         uint8_t oplock_level;
1321                         uint32_t create_action;
1322                         NTTIME create_time;
1323                         NTTIME access_time;
1324                         NTTIME write_time;
1325                         NTTIME change_time;
1326                         uint32_t attrib;
1327                         uint64_t alloc_size;
1328                         uint64_t size;
1329                         uint16_t file_type;
1330                         uint16_t ipc_state;
1331                         uint8_t  is_directory;
1332                 } out;
1333         } ntcreatex, nttrans, generic;
1334
1335         /* TRANS2_OPEN interface */
1336         struct {
1337                 enum smb_open_level level;
1338                 struct {
1339                         uint16_t flags;
1340                         uint16_t open_mode;
1341                         uint16_t search_attrs;
1342                         uint16_t file_attrs;
1343                         time_t write_time;
1344                         uint16_t open_func;
1345                         uint32_t size;
1346                         uint32_t timeout;
1347                         const char *fname;
1348                         uint_t num_eas;
1349                         struct ea_struct *eas;                  
1350                 } in;
1351                 struct {
1352                         union smb_handle file;
1353                         uint16_t attrib;
1354                         time_t write_time;
1355                         uint32_t size;
1356                         uint16_t access;
1357                         uint16_t ftype;
1358                         uint16_t devstate;
1359                         uint16_t action;
1360                         uint32_t file_id;
1361                 } out;
1362         } t2open;
1363
1364         /* SMBopen interface */
1365         struct {
1366                 enum smb_open_level level;
1367                 struct {
1368                         uint16_t open_mode;
1369                         uint16_t search_attrs;
1370                         const char *fname;
1371                 } in;
1372                 struct {
1373                         union smb_handle file;
1374                         uint16_t attrib;
1375                         time_t write_time;
1376                         uint32_t size;
1377                         uint16_t rmode;
1378                 } out;
1379         } openold;
1380
1381         /* SMBopenX interface */
1382         struct {
1383                 enum smb_open_level level;
1384                 struct {
1385                         uint16_t flags;
1386                         uint16_t open_mode;
1387                         uint16_t search_attrs; /* not honoured by win2003 */
1388                         uint16_t file_attrs;
1389                         time_t write_time; /* not honoured by win2003 */
1390                         uint16_t open_func;
1391                         uint32_t size; /* note that this sets the
1392                                         initial file size, not
1393                                         just allocation size */
1394                         uint32_t timeout; /* not honoured by win2003 */
1395                         const char *fname;
1396                 } in;
1397                 struct {
1398                         union smb_handle file;
1399                         uint16_t attrib;
1400                         time_t write_time;
1401                         uint32_t size;
1402                         uint16_t access;
1403                         uint16_t ftype;
1404                         uint16_t devstate;
1405                         uint16_t action;
1406                         uint32_t unique_fid;
1407                         uint32_t access_mask;
1408                         uint32_t unknown;
1409                 } out;
1410         } openx;
1411
1412         /* SMBmknew interface */
1413         struct {
1414                 enum smb_open_level level;
1415                 struct {
1416                         uint16_t attrib;
1417                         time_t write_time;
1418                         const char *fname;
1419                 } in;
1420                 struct {
1421                         union smb_handle file;
1422                 } out;
1423         } mknew, create;
1424
1425         /* SMBctemp interface */
1426         struct {
1427                 enum smb_open_level level;
1428                 struct {
1429                         uint16_t attrib;
1430                         time_t write_time;
1431                         const char *directory;
1432                 } in;
1433                 struct {
1434                         union smb_handle file;
1435                         /* temp name, relative to directory */
1436                         char *name; 
1437                 } out;
1438         } ctemp;
1439
1440         /* SMBsplopen interface */
1441         struct {
1442                 enum smb_open_level level;
1443                 struct {
1444                         uint16_t setup_length;
1445                         uint16_t mode;
1446                         const char *ident;
1447                 } in;
1448                 struct {
1449                         union smb_handle file;
1450                 } out;
1451         } splopen;
1452
1453
1454         /* chained OpenX/ReadX interface */
1455         struct {
1456                 enum smb_open_level level;
1457                 struct {
1458                         uint16_t flags;
1459                         uint16_t open_mode;
1460                         uint16_t search_attrs; /* not honoured by win2003 */
1461                         uint16_t file_attrs;
1462                         time_t write_time; /* not honoured by win2003 */
1463                         uint16_t open_func;
1464                         uint32_t size; /* note that this sets the
1465                                         initial file size, not
1466                                         just allocation size */
1467                         uint32_t timeout; /* not honoured by win2003 */
1468                         const char *fname;
1469
1470                         /* readx part */
1471                         uint64_t offset;
1472                         uint16_t mincnt;
1473                         uint32_t maxcnt;
1474                         uint16_t remaining;
1475                 } in;
1476                 struct {
1477                         union smb_handle file;
1478                         uint16_t attrib;
1479                         time_t write_time;
1480                         uint32_t size;
1481                         uint16_t access;
1482                         uint16_t ftype;
1483                         uint16_t devstate;
1484                         uint16_t action;
1485                         uint32_t unique_fid;
1486                         uint32_t access_mask;
1487                         uint32_t unknown;
1488                         
1489                         /* readx part */
1490                         uint8_t *data;
1491                         uint16_t remaining;
1492                         uint16_t compaction_mode;
1493                         uint16_t nread;
1494                 } out;
1495         } openxreadx;
1496
1497 #define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
1498 #define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
1499 #define SMB2_CREATE_FLAG_GRANT_OPLOCK             0x0001
1500 #define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK   0x0080
1501
1502         /* SMB2 Create */
1503         struct smb2_create {
1504                 enum smb_open_level level;
1505                 struct {
1506                         /* static body buffer 56 (0x38) bytes */
1507                         /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
1508                         uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
1509                         uint32_t impersonation;
1510                         uint32_t unknown3[4];
1511                         uint32_t access_mask;
1512
1513                         uint32_t file_attr;
1514                         uint32_t share_access;
1515                         uint32_t open_disposition;
1516                         uint32_t create_options;
1517
1518                         /* uint16_t fname_ofs */
1519                         /* uint16_t fname_size */
1520                         /* uint32_t blob_ofs; */
1521                         /* uint32_t blob_size; */
1522
1523                         /* dynamic body */
1524                         const char *fname;
1525
1526                         /* optional list of extended attributes */
1527                         struct smb_ea_list eas;
1528                 } in;
1529                 struct {
1530                         union smb_handle file;
1531
1532                         /* static body buffer 88 (0x58) bytes */
1533                         /* uint16_t buffer_code;  0x59 = 0x58 + 1 */
1534                         uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
1535                         uint32_t create_action;
1536                         NTTIME   create_time;
1537                         NTTIME   access_time;
1538                         NTTIME   write_time;
1539                         NTTIME   change_time;
1540                         uint64_t alloc_size;
1541                         uint64_t size;
1542                         uint32_t file_attr;
1543                         uint32_t _pad;
1544                         /* struct smb2_handle handle;*/
1545                         /* uint32_t blob_ofs; */
1546                         /* uint32_t blob_size; */
1547
1548                         /* dynamic body */
1549                         DATA_BLOB blob;
1550                 } out;
1551         } smb2;
1552 };
1553
1554
1555
1556 enum smb_read_level {
1557         RAW_READ_READBRAW,
1558         RAW_READ_LOCKREAD,
1559         RAW_READ_READ,
1560         RAW_READ_READX,
1561         RAW_READ_SMB2
1562 };
1563
1564 #define RAW_READ_GENERIC RAW_READ_READX
1565
1566 /* union for read() backend call 
1567
1568    note that .infoX.out.data will be allocated before the backend is
1569    called. It will be big enough to hold the maximum size asked for
1570 */
1571 union smb_read {
1572         /* SMBreadX (and generic) interface */
1573         struct {
1574                 enum smb_read_level level;
1575                 struct {
1576                         union smb_handle file;
1577                         uint64_t offset;
1578                         uint16_t mincnt;
1579                         uint32_t maxcnt;
1580                         uint16_t remaining;
1581                         BOOL read_for_execute;
1582                 } in;
1583                 struct {
1584                         uint8_t *data;
1585                         uint16_t remaining;
1586                         uint16_t compaction_mode;
1587                         uint16_t nread;
1588                 } out;
1589         } readx, generic;
1590
1591         /* SMBreadbraw interface */
1592         struct {
1593                 enum smb_read_level level;
1594                 struct {
1595                         union smb_handle file;
1596                         uint64_t offset;
1597                         uint16_t  maxcnt;
1598                         uint16_t  mincnt;
1599                         uint32_t  timeout;
1600                 } in;
1601                 struct {
1602                         uint8_t *data;
1603                         uint32_t nread;
1604                 } out;
1605         } readbraw;
1606
1607
1608         /* SMBlockandread interface */
1609         struct {
1610                 enum smb_read_level level;
1611                 struct {
1612                         union smb_handle file;
1613                         uint16_t count;
1614                         uint32_t offset;
1615                         uint16_t remaining;
1616                 } in;
1617                 struct {
1618                         uint8_t *data;
1619                         uint16_t nread;
1620                 } out;
1621         } lockread;
1622
1623         /* SMBread interface */
1624         struct {
1625                 enum smb_read_level level;
1626                 struct {
1627                         union smb_handle file;
1628                         uint16_t count;
1629                         uint32_t offset;
1630                         uint16_t remaining;
1631                 } in;
1632                 struct {
1633                         uint8_t *data;
1634                         uint16_t nread;
1635                 } out;
1636         } read;
1637
1638         /* SMB2 Read */
1639         struct smb2_read {
1640                 enum smb_read_level level;
1641                 struct {
1642                         union smb_handle file;
1643
1644                         /* static body buffer 48 (0x30) bytes */
1645                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1646                         uint16_t _pad;
1647                         uint32_t length;
1648                         uint64_t offset;
1649                         /* struct smb2_handle handle; */
1650                         uint64_t unknown1; /* 0x0000000000000000 */
1651                         uint64_t unknown2; /* 0x0000000000000000 */
1652                         uint8_t _bug;
1653                 } in;
1654                 struct {
1655                         /* static body buffer 16 (0x10) bytes */
1656                         /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
1657                         /* uint16_t data_ofs; */
1658                         /* uint32_t data_size; */
1659                         uint64_t unknown1; /* 0x0000000000000000 */
1660
1661                         /* dynamic body */
1662                         DATA_BLOB data;
1663                 } out;
1664         } smb2;
1665 };
1666
1667
1668 enum smb_write_level {
1669         RAW_WRITE_WRITEUNLOCK,
1670         RAW_WRITE_WRITE,
1671         RAW_WRITE_WRITEX,
1672         RAW_WRITE_WRITECLOSE,
1673         RAW_WRITE_SPLWRITE,
1674         RAW_WRITE_SMB2
1675 };
1676
1677 #define RAW_WRITE_GENERIC RAW_WRITE_WRITEX
1678
1679 /* union for write() backend call 
1680 */
1681 union smb_write {
1682         /* SMBwriteX interface */
1683         struct {
1684                 enum smb_write_level level;
1685                 struct {
1686                         union smb_handle file;
1687                         uint64_t offset;
1688                         uint16_t wmode;
1689                         uint16_t remaining;
1690                         uint32_t count;
1691                         const uint8_t *data;
1692                 } in;
1693                 struct {
1694                         uint32_t nwritten;
1695                         uint16_t remaining;
1696                 } out;
1697         } writex, generic;
1698
1699         /* SMBwriteunlock interface */
1700         struct {
1701                 enum smb_write_level level;
1702                 struct {
1703                         union smb_handle file;
1704                         uint16_t count;
1705                         uint32_t offset;
1706                         uint16_t remaining;
1707                         const uint8_t *data;
1708                 } in;
1709                 struct {
1710                         uint32_t nwritten;
1711                 } out;
1712         } writeunlock;
1713
1714         /* SMBwrite interface */
1715         struct {
1716                 enum smb_write_level level;
1717                 struct {
1718                         union smb_handle file;
1719                         uint16_t count;
1720                         uint32_t offset;
1721                         uint16_t remaining;
1722                         const uint8_t *data;
1723                 } in;
1724                 struct {
1725                         uint16_t nwritten;
1726                 } out;
1727         } write;
1728
1729         /* SMBwriteclose interface */
1730         struct {
1731                 enum smb_write_level level;
1732                 struct {
1733                         union smb_handle file;
1734                         uint16_t count;
1735                         uint32_t offset;
1736                         time_t mtime;
1737                         const uint8_t *data;
1738                 } in;
1739                 struct {
1740                         uint16_t nwritten;
1741                 } out;
1742         } writeclose;
1743
1744         /* SMBsplwrite interface */
1745         struct {
1746                 enum smb_write_level level;
1747                 struct {
1748                         union smb_handle file;
1749                         uint16_t count;
1750                         const uint8_t *data;
1751                 } in;
1752         } splwrite;
1753
1754         /* SMB2 Write */
1755         struct smb2_write {
1756                 enum smb_write_level level;
1757                 struct {
1758                         union smb_handle file;
1759
1760                         /* static body buffer 48 (0x30) bytes */
1761                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1762                         /* uint16_t data_ofs; */
1763                         /* uint32_t data_size; */
1764                         uint64_t offset;
1765                         /* struct smb2_handle handle; */
1766                         uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */
1767                         uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */
1768
1769                         /* dynamic body */
1770                         DATA_BLOB data;
1771                 } in;
1772                 struct {
1773                         /* static body buffer 17 (0x11) bytes */
1774                         /* uint16_t buffer_code;  0x11 */
1775                         uint16_t _pad;
1776                         uint32_t nwritten;
1777                         uint64_t unknown1; /* 0x0000000000000000 */
1778                         uint8_t _bug;
1779                 } out;
1780         } smb2;
1781 };
1782
1783
1784 enum smb_lock_level {RAW_LOCK_LOCK, RAW_LOCK_UNLOCK, RAW_LOCK_LOCKX};
1785
1786 /* the generic interface is defined to be equal to the lockingX interface */
1787 #define RAW_LOCK_GENERIC RAW_LOCK_LOCKX
1788
1789 /* union for lock() backend call 
1790 */
1791 union smb_lock {
1792         /* SMBlockingX (and generic) interface */
1793         struct {
1794                 enum smb_lock_level level;
1795                 struct {
1796                         union smb_handle file;
1797                         uint16_t mode;
1798                         uint32_t timeout;
1799                         uint16_t ulock_cnt;
1800                         uint16_t lock_cnt;
1801                         struct smb_lock_entry {
1802                                 uint16_t pid;
1803                                 uint64_t offset;
1804                                 uint64_t count;
1805                         } *locks; /* unlocks are first in the arrray */
1806                 } in;
1807         } lockx, generic;
1808
1809         /* SMBlock and SMBunlock interface */
1810         struct {
1811                 enum smb_lock_level level;
1812                 struct {
1813                         union smb_handle file;
1814                         uint32_t count;
1815                         uint32_t offset;
1816                 } in;
1817         } lock, unlock;
1818 };
1819
1820
1821 enum smb_close_level {
1822         RAW_CLOSE_CLOSE,
1823         RAW_CLOSE_SPLCLOSE,
1824         RAW_CLOSE_SMB2
1825 };
1826
1827 #define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE
1828
1829 /*
1830   union for close() backend call
1831 */
1832 union smb_close {
1833         /* SMBclose (and generic) interface */
1834         struct {
1835                 enum smb_close_level level;
1836                 struct {
1837                         union smb_handle file;
1838                         time_t write_time;
1839                 } in;
1840         } close, generic;
1841
1842         /* SMBsplclose interface - empty! */
1843         struct {
1844                 enum smb_close_level level;
1845                 struct {
1846                         union smb_handle file;
1847                 } in;
1848         } splclose;
1849
1850         /* SMB2 Close */
1851         struct smb2_close {
1852                 enum smb_close_level level;
1853                 struct {
1854                         union smb_handle file;
1855
1856                         /* static body buffer 24 (0x18) bytes */
1857                         /* uint16_t buffer_code;  0x18 */
1858 #define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
1859                         uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
1860                         uint32_t _pad;
1861                 } in;
1862                 struct {
1863                         /* static body buffer 60 (0x3C) bytes */
1864                         /* uint16_t buffer_code;  0x3C */
1865                         uint16_t flags;
1866                         uint32_t _pad;
1867                         NTTIME   create_time;
1868                         NTTIME   access_time;
1869                         NTTIME   write_time;
1870                         NTTIME   change_time;
1871                         uint64_t alloc_size;
1872                         uint64_t size;
1873                         uint32_t file_attr;
1874                 } out;
1875         } smb2;
1876 };
1877
1878
1879 enum smb_lpq_level {RAW_LPQ_GENERIC, RAW_LPQ_RETQ};
1880
1881 /*
1882   union for lpq() backend
1883 */
1884 union smb_lpq {
1885         /* generic interface */
1886         struct {
1887                 enum smb_lpq_level level;
1888
1889         } generic;
1890
1891
1892         /* SMBsplretq interface */
1893         struct {
1894                 enum smb_lpq_level level;
1895
1896                 struct {
1897                         uint16_t maxcount;
1898                         uint16_t startidx;
1899                 } in;
1900                 struct {
1901                         uint16_t count;
1902                         uint16_t restart_idx;
1903                         struct {
1904                                 time_t time;
1905                                 uint8_t status;
1906                                 uint16_t job;
1907                                 uint32_t size;
1908                                 char *user;
1909                         } *queue;
1910                 } out;
1911         } retq;
1912 };
1913
1914 enum smb_ioctl_level {
1915         RAW_IOCTL_IOCTL,
1916         RAW_IOCTL_NTIOCTL,
1917         RAW_IOCTL_SMB2
1918 };
1919
1920 /*
1921   union for ioctl() backend
1922 */
1923 union smb_ioctl {
1924         /* generic interface */
1925         struct {
1926                 enum smb_ioctl_level level;
1927                 struct {
1928                         union smb_handle file;
1929                 } in;
1930         } generic;
1931
1932         /* struct for SMBioctl */
1933         struct {
1934                 enum smb_ioctl_level level;
1935                 struct {
1936                         union smb_handle file;
1937                         uint32_t request;
1938                 } in;
1939                 struct {
1940                         DATA_BLOB blob;
1941                 } out;
1942         } ioctl;
1943
1944
1945         /* struct for NT ioctl call */
1946         struct {
1947                 enum smb_ioctl_level level;
1948                 struct {
1949                         union smb_handle file;
1950                         uint32_t function;
1951                         BOOL fsctl;
1952                         uint8_t filter;
1953                         uint32_t max_data;
1954                         DATA_BLOB blob;
1955                 } in;
1956                 struct {
1957                         DATA_BLOB blob;
1958                 } out;
1959         } ntioctl;
1960
1961         /* SMB2 Ioctl */
1962         struct smb2_ioctl {
1963                 enum smb_ioctl_level level;
1964                 struct {
1965                         union smb_handle file;
1966
1967                         /* static body buffer 56 (0x38) bytes */
1968                         /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
1969                         uint16_t _pad;
1970                         uint32_t function;
1971                         /*struct smb2_handle handle;*/
1972                         /* uint32_t out_ofs; */
1973                         /* uint32_t out_size; */
1974                         uint32_t unknown2;
1975                         /* uint32_t in_ofs; */
1976                         /* uint32_t in_size; */
1977                         uint32_t max_response_size;
1978                         uint64_t flags;
1979
1980                         /* dynamic body */
1981                         DATA_BLOB out;
1982                         DATA_BLOB in;
1983                 } in;
1984                 struct {
1985                         union smb_handle file;
1986
1987                         /* static body buffer 48 (0x30) bytes */
1988                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1989                         uint16_t _pad;
1990                         uint32_t function;
1991                         /* struct smb2_handle handle; */
1992                         /* uint32_t in_ofs; */
1993                         /* uint32_t in_size; */
1994                         /* uint32_t out_ofs; */
1995                         /* uint32_t out_size; */
1996                         uint32_t unknown2;
1997                         uint32_t unknown3;
1998
1999                         /* dynamic body */
2000                         DATA_BLOB in;
2001                         DATA_BLOB out;
2002                 } out;
2003         } smb2;
2004 };
2005
2006 enum smb_flush_level {
2007         RAW_FLUSH_FLUSH,
2008         RAW_FLUSH_ALL,
2009         RAW_FLUSH_SMB2
2010 };
2011
2012 union smb_flush {
2013         /* struct for SMBflush */
2014         struct {
2015                 enum smb_flush_level level;
2016                 struct {
2017                         union smb_handle file;
2018                 } in;
2019         } flush, generic;
2020
2021         /* SMBflush with 0xFFFF wildcard fnum */
2022         struct {
2023                 enum smb_flush_level level;
2024         } flush_all;
2025
2026         /* SMB2 Flush */
2027         struct smb2_flush {
2028                 enum smb_flush_level level;
2029                 struct {
2030                         union smb_handle file;
2031                         uint32_t unknown;
2032                 } in;
2033         } smb2;
2034 };
2035
2036 /* struct for SMBcopy */
2037 struct smb_copy {
2038         struct {
2039                 uint16_t tid2;
2040                 uint16_t ofun;
2041                 uint16_t flags;
2042                 const char *path1;
2043                 const char *path2;
2044         } in;
2045         struct {
2046                 uint16_t count;
2047         } out;
2048 };
2049
2050
2051 /* struct for transact/transact2 call */
2052 struct smb_trans2 {
2053         struct {
2054                 uint16_t max_param;
2055                 uint16_t max_data;
2056                 uint8_t  max_setup;
2057                 uint16_t flags;
2058                 uint32_t timeout;
2059                 uint8_t  setup_count;
2060                 uint16_t *setup;
2061                 const char *trans_name; /* SMBtrans only */
2062                 DATA_BLOB params;
2063                 DATA_BLOB data;
2064         } in;
2065
2066         struct {
2067                 uint8_t  setup_count;
2068                 uint16_t *setup;
2069                 DATA_BLOB params;
2070                 DATA_BLOB data;
2071         } out;
2072 };
2073
2074 /* struct for nttransact2 call */
2075 struct smb_nttrans {
2076         struct {
2077                 uint8_t  max_setup;
2078                 uint32_t max_param;
2079                 uint32_t max_data;
2080                 uint32_t setup_count;
2081                 uint16_t function;
2082                 uint16_t *setup;
2083                 DATA_BLOB params;
2084                 DATA_BLOB data;
2085         } in;
2086
2087         struct {
2088                 uint8_t  setup_count;
2089                 uint16_t *setup;
2090                 DATA_BLOB params;
2091                 DATA_BLOB data;
2092         } out;
2093 };
2094
2095
2096 /* struct for nttrans change notify call */
2097 struct smb_notify {
2098         struct {
2099                 union smb_handle file;
2100                 uint32_t buffer_size;
2101                 uint32_t completion_filter;
2102                 BOOL recursive;
2103         } in;
2104
2105         struct {
2106                 uint32_t num_changes;
2107                 struct notify_changes {
2108                         uint32_t action;
2109                         struct smb_wire_string name;
2110                 } *changes;
2111         } out;
2112 };
2113
2114 enum smb_search_level {RAW_SEARCH_GENERIC                 = 0xF000, 
2115                        RAW_SEARCH_SEARCH,                 /* SMBsearch */ 
2116                        RAW_SEARCH_FFIRST,                 /* SMBffirst */ 
2117                        RAW_SEARCH_FUNIQUE,                /* SMBfunique */
2118                        RAW_SEARCH_SMB2,                   /* SMB2 Find */
2119                        RAW_SEARCH_STANDARD                = SMB_FIND_STANDARD,
2120                        RAW_SEARCH_EA_SIZE                 = SMB_FIND_EA_SIZE,
2121                        RAW_SEARCH_EA_LIST                 = SMB_FIND_EA_LIST,
2122                        RAW_SEARCH_DIRECTORY_INFO          = SMB_FIND_DIRECTORY_INFO,
2123                        RAW_SEARCH_FULL_DIRECTORY_INFO     = SMB_FIND_FULL_DIRECTORY_INFO,
2124                        RAW_SEARCH_NAME_INFO               = SMB_FIND_NAME_INFO,
2125                        RAW_SEARCH_BOTH_DIRECTORY_INFO     = SMB_FIND_BOTH_DIRECTORY_INFO,
2126                        RAW_SEARCH_ID_FULL_DIRECTORY_INFO  = SMB_FIND_ID_FULL_DIRECTORY_INFO,
2127                        RAW_SEARCH_ID_BOTH_DIRECTORY_INFO  = SMB_FIND_ID_BOTH_DIRECTORY_INFO,
2128                        RAW_SEARCH_UNIX_INFO               = SMB_FIND_UNIX_INFO};
2129
2130         
2131 /* union for file search */
2132 union smb_search_first {
2133         struct {
2134                 enum smb_search_level level;
2135         } generic;
2136         
2137         /* search (old) findfirst interface. 
2138            Also used for ffirst and funique. */
2139         struct {
2140                 enum smb_search_level level;
2141         
2142                 struct {
2143                         uint16_t max_count;
2144                         uint16_t search_attrib;
2145                         const char *pattern;
2146                 } in;
2147                 struct {
2148                         int16_t count;
2149                 } out;
2150         } search_first;
2151
2152         /* trans2 findfirst interface */
2153         struct {
2154                 enum smb_search_level level;
2155                 
2156                 struct {
2157                         uint16_t search_attrib;
2158                         uint16_t max_count;
2159                         uint16_t flags;
2160                         uint32_t storage_type;
2161                         const char *pattern;
2162
2163                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2164                         uint_t num_names;
2165                         struct ea_name *ea_names;
2166                 } in;
2167                 struct {
2168                         uint16_t handle;
2169                         uint16_t count;
2170                         uint16_t end_of_search;
2171                 } out;
2172         } t2ffirst;
2173
2174 /*
2175   SMB2 uses different level numbers for the same old SMB search levels
2176 */
2177 #define SMB2_FIND_DIRECTORY_INFO         0x01
2178 #define SMB2_FIND_FULL_DIRECTORY_INFO    0x02
2179 #define SMB2_FIND_BOTH_DIRECTORY_INFO    0x03
2180 #define SMB2_FIND_NAME_INFO              0x0C
2181 #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25
2182 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26
2183         /* SMB2 Find */
2184         struct smb2_find {
2185                 enum smb_search_level level;
2186                 struct {
2187                         union smb_handle file;
2188
2189                         /* static body buffer 32 (0x20) bytes */
2190                         /* uint16_t buffer_code;  0x21 = 0x20 + 1 */
2191                         uint8_t level;
2192                         uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */
2193                         uint32_t unknown; /* perhaps a continue token? */
2194                         /* struct smb2_handle handle; */
2195                         /* uint16_t pattern_ofs; */
2196                         /* uint32_t pattern_size; */
2197                         uint32_t max_response_size;
2198         
2199                         /* dynamic body */
2200                         const char *pattern;
2201                 } in;
2202                 struct {
2203                         /* static body buffer 8 (0x08) bytes */
2204                         /* uint16_t buffer_code;  0x08 */
2205                         /* uint16_t blob_ofs; */
2206                         /* uint32_t blob_size; */
2207
2208                         /* dynamic body */
2209                         DATA_BLOB blob;
2210                 } out;
2211         } smb2;
2212 };
2213
2214 /* union for file search continue */
2215 union smb_search_next {
2216         struct {
2217                 enum smb_search_level level;
2218         } generic;
2219
2220         /* search (old) findnext interface. Also used
2221            for ffirst when continuing */
2222         struct {
2223                 enum smb_search_level level;
2224         
2225                 struct {
2226                         uint16_t max_count;
2227                         uint16_t search_attrib;
2228                         struct smb_search_id {
2229                                 uint8_t reserved;
2230                                 char name[11];
2231                                 uint8_t handle;
2232                                 uint32_t server_cookie;
2233                                 uint32_t client_cookie;
2234                         } id;
2235                 } in;
2236                 struct {
2237                         uint16_t count;
2238                 } out;
2239         } search_next;
2240         
2241         /* trans2 findnext interface */
2242         struct {
2243                 enum smb_search_level level;
2244                 
2245                 struct {
2246                         uint16_t handle;
2247                         uint16_t max_count;
2248                         uint32_t resume_key;
2249                         uint16_t flags;
2250                         const char *last_name;
2251
2252                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2253                         uint_t num_names;
2254                         struct ea_name *ea_names;
2255                 } in;
2256                 struct {
2257                         uint16_t count;
2258                         uint16_t end_of_search;
2259                 } out;
2260         } t2fnext;
2261 };
2262
2263 /* union for search reply file data */
2264 union smb_search_data {
2265         /* search (old) findfirst */
2266         struct {
2267                 uint16_t attrib;
2268                 time_t write_time;
2269                 uint32_t size;
2270                 struct smb_search_id id;
2271                 const char *name;
2272         } search;
2273         
2274         /* trans2 findfirst RAW_SEARCH_STANDARD level */
2275         struct {
2276                 uint32_t resume_key;
2277                 time_t create_time;
2278                 time_t access_time;
2279                 time_t write_time;
2280                 uint32_t size;
2281                 uint32_t alloc_size;
2282                 uint16_t attrib;
2283                 struct smb_wire_string name;
2284         } standard;
2285
2286         /* trans2 findfirst RAW_SEARCH_EA_SIZE level */
2287         struct {
2288                 uint32_t resume_key;
2289                 time_t create_time;
2290                 time_t access_time;
2291                 time_t write_time;
2292                 uint32_t size;
2293                 uint32_t alloc_size;
2294                 uint16_t attrib;
2295                 uint32_t ea_size;
2296                 struct smb_wire_string name;
2297         } ea_size;
2298
2299         /* trans2 findfirst RAW_SEARCH_EA_LIST level */
2300         struct {
2301                 uint32_t resume_key;
2302                 time_t create_time;
2303                 time_t access_time;
2304                 time_t write_time;
2305                 uint32_t size;
2306                 uint32_t alloc_size;
2307                 uint16_t attrib;
2308                 struct smb_ea_list eas;
2309                 struct smb_wire_string name;
2310         } ea_list;
2311
2312         /* RAW_SEARCH_DIRECTORY_INFO interface */
2313         struct {
2314                 uint32_t file_index;
2315                 NTTIME create_time;
2316                 NTTIME access_time;
2317                 NTTIME write_time;
2318                 NTTIME change_time;
2319                 uint64_t  size;
2320                 uint64_t  alloc_size;
2321                 uint32_t   attrib;
2322                 struct smb_wire_string name;
2323         } directory_info;
2324
2325         /* RAW_SEARCH_FULL_DIRECTORY_INFO interface */
2326         struct {
2327                 uint32_t file_index;
2328                 NTTIME create_time;
2329                 NTTIME access_time;
2330                 NTTIME write_time;
2331                 NTTIME change_time;
2332                 uint64_t  size;
2333                 uint64_t  alloc_size;
2334                 uint32_t   attrib;
2335                 uint32_t   ea_size;
2336                 struct smb_wire_string name;
2337         } full_directory_info;
2338
2339         /* RAW_SEARCH_NAME_INFO interface */
2340         struct {
2341                 uint32_t file_index;
2342                 struct smb_wire_string name;
2343         } name_info;
2344
2345         /* RAW_SEARCH_BOTH_DIRECTORY_INFO interface */
2346         struct {
2347                 uint32_t file_index;
2348                 NTTIME create_time;
2349                 NTTIME access_time;
2350                 NTTIME write_time;
2351                 NTTIME change_time;
2352                 uint64_t  size;
2353                 uint64_t  alloc_size;
2354                 uint32_t   attrib;
2355                 uint32_t   ea_size;
2356                 struct smb_wire_string short_name;
2357                 struct smb_wire_string name;
2358         } both_directory_info;
2359
2360         /* RAW_SEARCH_ID_FULL_DIRECTORY_INFO interface */
2361         struct {
2362                 uint32_t file_index;
2363                 NTTIME create_time;
2364                 NTTIME access_time;
2365                 NTTIME write_time;
2366                 NTTIME change_time;
2367                 uint64_t size;
2368                 uint64_t alloc_size;
2369                 uint32_t attrib;
2370                 uint32_t ea_size;
2371                 uint64_t file_id;
2372                 struct smb_wire_string name;
2373         } id_full_directory_info;
2374
2375         /* RAW_SEARCH_ID_BOTH_DIRECTORY_INFO interface */
2376         struct {
2377                 uint32_t file_index;
2378                 NTTIME create_time;
2379                 NTTIME access_time;
2380                 NTTIME write_time;
2381                 NTTIME change_time;
2382                 uint64_t size;
2383                 uint64_t alloc_size;
2384                 uint32_t  attrib;
2385                 uint32_t  ea_size;
2386                 uint64_t file_id;
2387                 struct smb_wire_string short_name;
2388                 struct smb_wire_string name;
2389         } id_both_directory_info;
2390
2391         /* RAW_SEARCH_UNIX_INFO interface */
2392         struct {
2393                 uint32_t file_index;
2394                 uint64_t size;
2395                 uint64_t alloc_size;
2396                 NTTIME status_change_time;
2397                 NTTIME access_time;
2398                 NTTIME change_time;
2399                 uint64_t uid;
2400                 uint64_t gid;
2401                 uint32_t file_type;
2402                 uint64_t dev_major;
2403                 uint64_t dev_minor;
2404                 uint64_t unique_id;
2405                 uint64_t permissions;
2406                 uint64_t nlink;         
2407                 const char *name;
2408         } unix_info;
2409 };
2410
2411
2412 enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE};
2413
2414 /* union for file search close */
2415 union smb_search_close {
2416         struct {
2417                 enum smb_search_close_level level;
2418         } generic;
2419
2420         /* SMBfclose (old search) interface */
2421         struct {
2422                 enum smb_search_close_level level;
2423         
2424                 struct {
2425                         /* max_count and search_attrib are not used, but are present */
2426                         uint16_t max_count;
2427                         uint16_t search_attrib;
2428                         struct smb_search_id id;
2429                 } in;
2430         } fclose;
2431         
2432         /* SMBfindclose interface */
2433         struct {
2434                 enum smb_search_close_level level;
2435                 
2436                 struct {
2437                         uint16_t handle;
2438                 } in;
2439         } findclose;
2440 };
2441
2442 #endif /* __LIBCLI_RAW_INTERFACES_H__ */