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