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