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