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