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