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