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