19d51893a616411c7f211bb3446cee38d91b9728
[samba.git] / source4 / libcli / raw / interfaces.h
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB request interface structures
4    Copyright (C) Andrew Tridgell                        2003
5    Copyright (C) James J Myers 2003 <myersjj@samba.org>
6    Copyright (C) James Peach 2007
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef __LIBCLI_RAW_INTERFACES_H__
23 #define __LIBCLI_RAW_INTERFACES_H__
24
25 #include "smb.h" 
26 #include "librpc/gen_ndr/misc.h" /* for struct GUID */
27
28 /* this structure is just a wrapper for a string, the only reason we
29    bother with this is that it allows us to check the length provided
30    on the wire in testsuite test code to ensure that we are
31    terminating names in the same way that win2003 is. The *ONLY* time
32    you should ever look at the 'private_length' field in this
33    structure is inside compliance test code, in all other cases just
34    use the null terminated char* as the definitive definition of the
35    string
36
37    also note that this structure is only used in packets where there
38    is an explicit length provided on the wire (hence the name). That
39    length is placed in 'private_length'. For packets where the length
40    is always determined by NULL or packet termination a normal char*
41    is used in the structure definition.
42  */
43 struct smb_wire_string {
44         uint32_t private_length;
45         const char *s;
46 };
47
48 /*
49  * SMB2 uses a 16Byte handle,
50  * (we can maybe use struct GUID later)
51  */
52 struct smb2_handle {
53         uint64_t data[2];
54 };
55
56 struct ntvfs_handle;
57
58 /*
59  * a generic container for file handles or file pathes
60  * for qfileinfo/setfileinfo and qpathinfo/setpathinfo
61 */
62 union smb_handle_or_path {
63         /*
64          * this is used for
65          * the qpathinfo and setpathinfo
66          * calls
67          */
68         const char *path;
69         /*
70          * this is used as file handle in SMB
71          */
72         uint16_t fnum;
73
74         /*
75          * this is used as file handle in SMB2
76          */
77         struct smb2_handle handle;
78
79         /*
80          * this is used as generic file handle for the NTVFS layer
81          */
82         struct ntvfs_handle *ntvfs;
83 };
84
85 /*
86  a generic container for file handles
87 */
88 union smb_handle {
89         /*
90          * this is used as file handle in SMB
91          */
92         uint16_t fnum;
93
94         /*
95          * this is used as file handle in SMB2
96          */
97         struct smb2_handle handle;
98
99         /*
100          * this is used as generic file handle for the NTVFS layer
101          */
102         struct ntvfs_handle *ntvfs;
103 };
104
105 /*
106   this header defines the structures and unions used between the SMB
107   parser and the backends.
108 */
109
110 /* struct used for SMBlseek call */
111 union smb_seek {
112         struct {
113                 struct {
114                         union smb_handle file;
115                         uint16_t mode;
116                         int32_t  offset; /* signed */
117                 } in;
118                 struct {
119                         int32_t offset;
120                 } out;
121         } lseek, generic;
122 };
123
124 /* struct used in unlink() call */
125 union smb_unlink {
126         struct {
127                 struct {
128                         const char *pattern;
129                         uint16_t attrib;
130                 } in;
131         } unlink;
132 };
133
134
135 /* struct used in chkpath() call */
136 union smb_chkpath {
137         struct {
138                 struct {
139                         const char *path;
140                 } in;
141         } chkpath;
142 };
143
144 enum smb_mkdir_level {RAW_MKDIR_GENERIC, RAW_MKDIR_MKDIR, RAW_MKDIR_T2MKDIR};
145
146 /* union used in mkdir() call */
147 union smb_mkdir {
148         /* generic level */
149         struct {
150                 enum smb_mkdir_level level;
151         } generic;
152
153         struct {
154                 enum smb_mkdir_level level;
155                 struct {
156                         const char *path;
157                 } in;
158         } mkdir;
159
160         struct {
161                 enum smb_mkdir_level level;
162                 struct {
163                         const char *path;
164                         uint_t num_eas;
165                         struct ea_struct *eas;                  
166                 } in;
167         } t2mkdir;
168 };
169
170 /* struct used in rmdir() call */
171 struct smb_rmdir {
172         struct {
173                 const char *path;
174         } in;
175 };
176
177 /* struct used in rename() call */
178 enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME, 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_MODE_INFORMATION        = SMB_SFILEINFO_MODE_INFORMATION,
910         RAW_SFILEINFO_ALLOCATION_INFORMATION  = SMB_SFILEINFO_ALLOCATION_INFORMATION,
911         RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION,
912         RAW_SFILEINFO_1023                    = SMB_SFILEINFO_1023,
913         RAW_SFILEINFO_1025                    = SMB_SFILEINFO_1025,
914         RAW_SFILEINFO_1029                    = SMB_SFILEINFO_1029,
915         RAW_SFILEINFO_1032                    = SMB_SFILEINFO_1032,
916         RAW_SFILEINFO_1039                    = SMB_SFILEINFO_1039,
917         RAW_SFILEINFO_1040                    = SMB_SFILEINFO_1040,
918         
919         /* cope with breakage in SMB2 */
920         RAW_SFILEINFO_RENAME_INFORMATION_SMB2 = SMB_SFILEINFO_RENAME_INFORMATION|0x80000000,
921 };
922
923 /* union used in setfileinfo() and setpathinfo() calls */
924 union smb_setfileinfo {
925         /* generic interface */
926         struct {
927                 enum smb_setfileinfo_level level;
928                 struct {
929                         union smb_handle_or_path file;
930                 } in;
931         } generic;
932
933         /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */
934         struct {
935                 enum smb_setfileinfo_level level;
936                 struct {
937                         union smb_handle_or_path file;
938                         uint16_t attrib;
939                         time_t write_time;
940                 } in;
941         } setattr;
942
943         /* RAW_SFILEINFO_SETATTRE (SMBsetattrE) interface - only via setfileinfo() 
944            also RAW_SFILEINFO_STANDARD */
945         struct {
946                 enum smb_setfileinfo_level level;
947                 struct {
948                         union smb_handle_or_path file;
949                         time_t create_time;
950                         time_t access_time;
951                         time_t write_time;
952                         /* notice that size, alloc_size and attrib are not settable,
953                            unlike the corresponding qfileinfo level */
954                 } in;
955         } setattre, standard;
956
957         /* RAW_SFILEINFO_EA_SET interface */
958         struct {
959                 enum smb_setfileinfo_level level;
960                 struct {
961                         union smb_handle_or_path file;
962                         uint_t num_eas;
963                         struct ea_struct *eas;                  
964                 } in;
965         } ea_set;
966
967         /* RAW_SFILEINFO_BASIC_INFO and
968            RAW_SFILEINFO_BASIC_INFORMATION interfaces */
969         struct {
970                 enum smb_setfileinfo_level level;
971                 struct {
972                         union smb_handle_or_path file;
973                         NTTIME create_time;
974                         NTTIME access_time;
975                         NTTIME write_time;
976                         NTTIME change_time;
977                         uint32_t attrib;
978                 } in;
979         } basic_info;
980
981         /* RAW_SFILEINFO_DISPOSITION_INFO and 
982            RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */
983         struct {
984                 enum smb_setfileinfo_level level;
985                 struct {
986                         union smb_handle_or_path file;
987                         bool delete_on_close;
988                 } in;
989         } disposition_info;
990
991         /* RAW_SFILEINFO_ALLOCATION_INFO and 
992            RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */
993         struct {
994                 enum smb_setfileinfo_level level;
995                 struct {
996                         union smb_handle_or_path file;
997                         /* w2k3 rounds this up to nearest 4096 */
998                         uint64_t alloc_size;
999                 } in;
1000         } allocation_info;
1001         
1002         /* RAW_SFILEINFO_END_OF_FILE_INFO and 
1003            RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */
1004         struct {
1005                 enum smb_setfileinfo_level level;
1006                 struct {
1007                         union smb_handle_or_path file;
1008                         uint64_t size;
1009                 } in;
1010         } end_of_file_info;
1011
1012         /* RAW_SFILEINFO_RENAME_INFORMATION interface */
1013         struct {
1014                 enum smb_setfileinfo_level level;
1015                 struct {
1016                         union smb_handle_or_path file;
1017                         uint8_t overwrite;
1018                         uint64_t root_fid;
1019                         const char *new_name;
1020                 } in;
1021         } rename_information;
1022
1023         /* RAW_SFILEINFO_POSITION_INFORMATION interface */
1024         struct {
1025                 enum smb_setfileinfo_level level;
1026                 struct {
1027                         union smb_handle_or_path file;
1028                         uint64_t position;
1029                 } in;
1030         } position_information;
1031
1032         /* RAW_SFILEINFO_MODE_INFORMATION interface */
1033         struct {
1034                 enum smb_setfileinfo_level level;
1035                 struct {
1036                         union smb_handle_or_path file;
1037                         /* valid values seem to be 0, 2, 4 and 6 */
1038                         uint32_t mode;
1039                 } in;
1040         } mode_information;
1041
1042         /* RAW_SFILEINFO_UNIX_BASIC interface */
1043         struct {
1044                 enum smb_setfileinfo_level level;
1045                 struct {
1046                         union smb_handle_or_path file;
1047                         uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */
1048                         uint64_t end_of_file;
1049                         uint64_t num_bytes;
1050                         NTTIME status_change_time;
1051                         NTTIME access_time;
1052                         NTTIME change_time;
1053                         uint64_t uid;
1054                         uint64_t gid;
1055                         uint32_t file_type;
1056                         uint64_t dev_major;
1057                         uint64_t dev_minor;
1058                         uint64_t unique_id;
1059                         uint64_t permissions;
1060                         uint64_t nlink;
1061                 } in;
1062         } unix_basic;
1063
1064         /* RAW_SFILEINFO_UNIX_INFO2 interface */
1065         struct {
1066                 enum smb_setfileinfo_level level;
1067                 struct {
1068                         union smb_handle_or_path file;
1069                         uint64_t end_of_file;
1070                         uint64_t num_bytes;
1071                         NTTIME status_change_time;
1072                         NTTIME access_time;
1073                         NTTIME change_time;
1074                         uint64_t uid;
1075                         uint64_t gid;
1076                         uint32_t file_type;
1077                         uint64_t dev_major;
1078                         uint64_t dev_minor;
1079                         uint64_t unique_id;
1080                         uint64_t permissions;
1081                         uint64_t nlink;
1082                         NTTIME create_time;
1083                         uint32_t file_flags;
1084                         uint32_t flags_mask;
1085                 } in;
1086         } unix_info2;
1087
1088         /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */
1089         struct {
1090                 enum smb_setfileinfo_level level;
1091                 struct {
1092                         union smb_handle_or_path file;
1093                         const char *link_dest;
1094                 } in;
1095         } unix_link, unix_hlink;
1096
1097         /* RAW_FILEINFO_SET_SEC_DESC */
1098         struct {
1099                 enum smb_setfileinfo_level level;
1100                 struct {
1101                         union smb_handle_or_path file;
1102                         uint32_t secinfo_flags;
1103                         struct security_descriptor *sd;
1104                 } in;
1105         } set_secdesc;
1106 };
1107
1108
1109 enum smb_fsinfo_level {
1110                    RAW_QFS_GENERIC                        = 0xF000, 
1111                    RAW_QFS_DSKATTR,                         /* SMBdskattr */
1112                    RAW_QFS_ALLOCATION                     = SMB_QFS_ALLOCATION,
1113                    RAW_QFS_VOLUME                         = SMB_QFS_VOLUME,
1114                    RAW_QFS_VOLUME_INFO                    = SMB_QFS_VOLUME_INFO,
1115                    RAW_QFS_SIZE_INFO                      = SMB_QFS_SIZE_INFO,
1116                    RAW_QFS_DEVICE_INFO                    = SMB_QFS_DEVICE_INFO,
1117                    RAW_QFS_ATTRIBUTE_INFO                 = SMB_QFS_ATTRIBUTE_INFO,
1118                    RAW_QFS_UNIX_INFO                      = SMB_QFS_UNIX_INFO,
1119                    RAW_QFS_VOLUME_INFORMATION             = SMB_QFS_VOLUME_INFORMATION,
1120                    RAW_QFS_SIZE_INFORMATION               = SMB_QFS_SIZE_INFORMATION,
1121                    RAW_QFS_DEVICE_INFORMATION             = SMB_QFS_DEVICE_INFORMATION,
1122                    RAW_QFS_ATTRIBUTE_INFORMATION          = SMB_QFS_ATTRIBUTE_INFORMATION,
1123                    RAW_QFS_QUOTA_INFORMATION              = SMB_QFS_QUOTA_INFORMATION,
1124                    RAW_QFS_FULL_SIZE_INFORMATION          = SMB_QFS_FULL_SIZE_INFORMATION,
1125                    RAW_QFS_OBJECTID_INFORMATION           = SMB_QFS_OBJECTID_INFORMATION};
1126
1127
1128 /* union for fsinfo() backend call. Note that there are no in
1129    structures, as this call only contains out parameters */
1130 union smb_fsinfo {
1131         /* generic interface */
1132         struct {
1133                 enum smb_fsinfo_level level;
1134                 struct smb2_handle handle; /* only for smb2 */
1135
1136                 struct {
1137                         uint32_t block_size;
1138                         uint64_t blocks_total;
1139                         uint64_t blocks_free;
1140                         uint32_t fs_id;
1141                         NTTIME create_time;
1142                         uint32_t serial_number;
1143                         uint32_t fs_attr;
1144                         uint32_t max_file_component_length;
1145                         uint32_t device_type;
1146                         uint32_t device_characteristics;
1147                         uint64_t quota_soft;
1148                         uint64_t quota_hard;
1149                         uint64_t quota_flags;
1150                         struct GUID guid;
1151                         char *volume_name;
1152                         char *fs_type;
1153                 } out;
1154         } generic;
1155
1156         /* SMBdskattr interface */
1157         struct {
1158                 enum smb_fsinfo_level level;
1159
1160                 struct {
1161                         uint16_t units_total;
1162                         uint16_t blocks_per_unit;
1163                         uint16_t block_size;
1164                         uint16_t units_free;
1165                 } out;
1166         } dskattr;
1167
1168         /* trans2 RAW_QFS_ALLOCATION interface */
1169         struct {
1170                 enum smb_fsinfo_level level;
1171
1172                 struct {
1173                         uint32_t fs_id;
1174                         uint32_t sectors_per_unit;
1175                         uint32_t total_alloc_units;
1176                         uint32_t avail_alloc_units;
1177                         uint16_t bytes_per_sector;
1178                 } out;
1179         } allocation;
1180
1181         /* TRANS2 RAW_QFS_VOLUME interface */
1182         struct {
1183                 enum smb_fsinfo_level level;
1184
1185                 struct {
1186                         uint32_t serial_number;
1187                         struct smb_wire_string volume_name;
1188                 } out;
1189         } volume;
1190
1191         /* TRANS2 RAW_QFS_VOLUME_INFO and RAW_QFS_VOLUME_INFORMATION interfaces */
1192         struct {
1193                 enum smb_fsinfo_level level;
1194                 struct smb2_handle handle; /* only for smb2 */
1195
1196                 struct {
1197                         NTTIME create_time;
1198                         uint32_t serial_number;
1199                         struct smb_wire_string volume_name;
1200                 } out;
1201         } volume_info;
1202
1203         /* trans2 RAW_QFS_SIZE_INFO and RAW_QFS_SIZE_INFORMATION interfaces */
1204         struct {
1205                 enum smb_fsinfo_level level;
1206                 struct smb2_handle handle; /* only for smb2 */
1207
1208                 struct {
1209                         uint64_t total_alloc_units;
1210                         uint64_t avail_alloc_units; /* maps to call_avail_alloc_units */
1211                         uint32_t sectors_per_unit;
1212                         uint32_t bytes_per_sector;
1213                 } out;
1214         } size_info;
1215
1216         /* TRANS2 RAW_QFS_DEVICE_INFO and RAW_QFS_DEVICE_INFORMATION interfaces */
1217         struct {
1218                 enum smb_fsinfo_level level;
1219                 struct smb2_handle handle; /* only for smb2 */
1220
1221                 struct {
1222                         uint32_t device_type;
1223                         uint32_t characteristics;
1224                 } out;
1225         } device_info;
1226
1227
1228         /* TRANS2 RAW_QFS_ATTRIBUTE_INFO and RAW_QFS_ATTRIBUTE_INFORMATION interfaces */
1229         struct {
1230                 enum smb_fsinfo_level level;
1231                 struct smb2_handle handle; /* only for smb2 */
1232
1233                 struct {
1234                         uint32_t fs_attr;
1235                         uint32_t max_file_component_length;
1236                         struct smb_wire_string fs_type;
1237                 } out;
1238         } attribute_info;
1239
1240
1241         /* TRANS2 RAW_QFS_UNIX_INFO interface */
1242         struct {
1243                 enum smb_fsinfo_level level;
1244
1245                 struct {
1246                         uint16_t major_version;
1247                         uint16_t minor_version;
1248                         uint64_t capability;
1249                 } out;
1250         } unix_info;
1251
1252         /* trans2 RAW_QFS_QUOTA_INFORMATION interface */
1253         struct {
1254                 enum smb_fsinfo_level level;
1255                 struct smb2_handle handle; /* only for smb2 */
1256
1257                 struct {
1258                         uint64_t unknown[3];
1259                         uint64_t quota_soft;
1260                         uint64_t quota_hard;
1261                         uint64_t quota_flags;
1262                 } out;
1263         } quota_information;    
1264
1265         /* trans2 RAW_QFS_FULL_SIZE_INFORMATION interface */
1266         struct {
1267                 enum smb_fsinfo_level level;
1268                 struct smb2_handle handle; /* only for smb2 */
1269
1270                 struct {
1271                         uint64_t total_alloc_units;
1272                         uint64_t call_avail_alloc_units;
1273                         uint64_t actual_avail_alloc_units;
1274                         uint32_t sectors_per_unit;
1275                         uint32_t bytes_per_sector;
1276                 } out;
1277         } full_size_information;
1278
1279         /* trans2 RAW_QFS_OBJECTID_INFORMATION interface */
1280         struct {
1281                 enum smb_fsinfo_level level;
1282                 struct smb2_handle handle; /* only for smb2 */
1283
1284                 struct {
1285                         struct GUID  guid;
1286                         uint64_t unknown[6];
1287                 } out;
1288         } objectid_information; 
1289 };
1290
1291
1292
1293 enum smb_open_level {
1294         RAW_OPEN_OPEN,
1295         RAW_OPEN_OPENX, 
1296         RAW_OPEN_MKNEW,
1297         RAW_OPEN_CREATE, 
1298         RAW_OPEN_CTEMP,
1299         RAW_OPEN_SPLOPEN,
1300         RAW_OPEN_NTCREATEX,
1301         RAW_OPEN_T2OPEN,
1302         RAW_OPEN_NTTRANS_CREATE, 
1303         RAW_OPEN_OPENX_READX,
1304         RAW_OPEN_SMB2
1305 };
1306
1307 /* the generic interface is defined to be equal to the NTCREATEX interface */
1308 #define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX
1309
1310 /* union for open() backend call */
1311 union smb_open {
1312 /* 
1313  * because the *.out.file structs are not aligned to the same offset for each level
1314  * we provide a hepler macro that should be used to find the current smb_handle structure
1315  */
1316 #define SMB_OPEN_OUT_FILE(op, file) do { \
1317         switch (op->generic.level) { \
1318         case RAW_OPEN_OPEN: \
1319                 file = &op->openold.out.file; \
1320                 break; \
1321         case RAW_OPEN_OPENX: \
1322                 file = &op->openx.out.file; \
1323                 break; \
1324         case RAW_OPEN_MKNEW: \
1325                 file = &op->mknew.out.file; \
1326                 break; \
1327         case RAW_OPEN_CREATE: \
1328                 file = &op->create.out.file; \
1329                 break; \
1330         case RAW_OPEN_CTEMP: \
1331                 file = &op->ctemp.out.file; \
1332                 break; \
1333         case RAW_OPEN_SPLOPEN: \
1334                 file = &op->splopen.out.file; \
1335                 break; \
1336         case RAW_OPEN_NTCREATEX: \
1337                 file = &op->ntcreatex.out.file; \
1338                 break; \
1339         case RAW_OPEN_T2OPEN: \
1340                 file = &op->t2open.out.file; \
1341                 break; \
1342         case RAW_OPEN_NTTRANS_CREATE: \
1343                 file = &op->nttrans.out.file; \
1344                 break; \
1345         case RAW_OPEN_OPENX_READX: \
1346                 file = &op->openxreadx.out.file; \
1347                 break; \
1348         case RAW_OPEN_SMB2: \
1349                 file = &op->smb2.out.file; \
1350                 break; \
1351         default: \
1352                 /* this must be a programmer error */ \
1353                 file = NULL; \
1354                 break; \
1355         } \
1356 } while (0)
1357         /* SMBNTCreateX, nttrans and generic interface */
1358         struct {
1359                 enum smb_open_level level;
1360                 struct {
1361                         uint32_t flags;
1362                         uint32_t root_fid;
1363                         uint32_t access_mask;
1364                         uint64_t alloc_size;
1365                         uint32_t file_attr;
1366                         uint32_t share_access;
1367                         uint32_t open_disposition;
1368                         uint32_t create_options;
1369                         uint32_t impersonation;
1370                         uint8_t  security_flags;
1371                         /* NOTE: fname can also be a pointer to a
1372                          uint64_t file_id if create_options has the
1373                          NTCREATEX_OPTIONS_OPEN_BY_FILE_ID flag set */
1374                         const char *fname;
1375
1376                         /* these last 2 elements are only used in the
1377                            NTTRANS varient of the call */
1378                         struct security_descriptor *sec_desc;
1379                         struct smb_ea_list *ea_list;
1380                         
1381                         /* some optional parameters from the SMB2 varient */
1382                         bool query_maximal_access;
1383                 } in;
1384                 struct {
1385                         union smb_handle file;
1386                         uint8_t oplock_level;
1387                         uint32_t create_action;
1388                         NTTIME create_time;
1389                         NTTIME access_time;
1390                         NTTIME write_time;
1391                         NTTIME change_time;
1392                         uint32_t attrib;
1393                         uint64_t alloc_size;
1394                         uint64_t size;
1395                         uint16_t file_type;
1396                         uint16_t ipc_state;
1397                         uint8_t  is_directory;
1398
1399                         /* optional return values matching SMB2 tagged
1400                            values in the call */
1401                         uint32_t maximal_access;
1402                 } out;
1403         } ntcreatex, nttrans, generic;
1404
1405         /* TRANS2_OPEN interface */
1406         struct {
1407                 enum smb_open_level level;
1408                 struct {
1409                         uint16_t flags;
1410                         uint16_t open_mode;
1411                         uint16_t search_attrs;
1412                         uint16_t file_attrs;
1413                         time_t write_time;
1414                         uint16_t open_func;
1415                         uint32_t size;
1416                         uint32_t timeout;
1417                         const char *fname;
1418                         uint_t num_eas;
1419                         struct ea_struct *eas;                  
1420                 } in;
1421                 struct {
1422                         union smb_handle file;
1423                         uint16_t attrib;
1424                         time_t write_time;
1425                         uint32_t size;
1426                         uint16_t access;
1427                         uint16_t ftype;
1428                         uint16_t devstate;
1429                         uint16_t action;
1430                         uint32_t file_id;
1431                 } out;
1432         } t2open;
1433
1434         /* SMBopen interface */
1435         struct {
1436                 enum smb_open_level level;
1437                 struct {
1438                         uint16_t open_mode;
1439                         uint16_t search_attrs;
1440                         const char *fname;
1441                 } in;
1442                 struct {
1443                         union smb_handle file;
1444                         uint16_t attrib;
1445                         time_t write_time;
1446                         uint32_t size;
1447                         uint16_t rmode;
1448                 } out;
1449         } openold;
1450
1451         /* SMBopenX interface */
1452         struct {
1453                 enum smb_open_level level;
1454                 struct {
1455                         uint16_t flags;
1456                         uint16_t open_mode;
1457                         uint16_t search_attrs; /* not honoured by win2003 */
1458                         uint16_t file_attrs;
1459                         time_t write_time; /* not honoured by win2003 */
1460                         uint16_t open_func;
1461                         uint32_t size; /* note that this sets the
1462                                         initial file size, not
1463                                         just allocation size */
1464                         uint32_t timeout; /* not honoured by win2003 */
1465                         const char *fname;
1466                 } in;
1467                 struct {
1468                         union smb_handle file;
1469                         uint16_t attrib;
1470                         time_t write_time;
1471                         uint32_t size;
1472                         uint16_t access;
1473                         uint16_t ftype;
1474                         uint16_t devstate;
1475                         uint16_t action;
1476                         uint32_t unique_fid;
1477                         uint32_t access_mask;
1478                         uint32_t unknown;
1479                 } out;
1480         } openx;
1481
1482         /* SMBmknew interface */
1483         struct {
1484                 enum smb_open_level level;
1485                 struct {
1486                         uint16_t attrib;
1487                         time_t write_time;
1488                         const char *fname;
1489                 } in;
1490                 struct {
1491                         union smb_handle file;
1492                 } out;
1493         } mknew, create;
1494
1495         /* SMBctemp interface */
1496         struct {
1497                 enum smb_open_level level;
1498                 struct {
1499                         uint16_t attrib;
1500                         time_t write_time;
1501                         const char *directory;
1502                 } in;
1503                 struct {
1504                         union smb_handle file;
1505                         /* temp name, relative to directory */
1506                         char *name; 
1507                 } out;
1508         } ctemp;
1509
1510         /* SMBsplopen interface */
1511         struct {
1512                 enum smb_open_level level;
1513                 struct {
1514                         uint16_t setup_length;
1515                         uint16_t mode;
1516                         const char *ident;
1517                 } in;
1518                 struct {
1519                         union smb_handle file;
1520                 } out;
1521         } splopen;
1522
1523
1524         /* chained OpenX/ReadX interface */
1525         struct {
1526                 enum smb_open_level level;
1527                 struct {
1528                         uint16_t flags;
1529                         uint16_t open_mode;
1530                         uint16_t search_attrs; /* not honoured by win2003 */
1531                         uint16_t file_attrs;
1532                         time_t write_time; /* not honoured by win2003 */
1533                         uint16_t open_func;
1534                         uint32_t size; /* note that this sets the
1535                                         initial file size, not
1536                                         just allocation size */
1537                         uint32_t timeout; /* not honoured by win2003 */
1538                         const char *fname;
1539
1540                         /* readx part */
1541                         uint64_t offset;
1542                         uint16_t mincnt;
1543                         uint32_t maxcnt;
1544                         uint16_t remaining;
1545                 } in;
1546                 struct {
1547                         union smb_handle file;
1548                         uint16_t attrib;
1549                         time_t write_time;
1550                         uint32_t size;
1551                         uint16_t access;
1552                         uint16_t ftype;
1553                         uint16_t devstate;
1554                         uint16_t action;
1555                         uint32_t unique_fid;
1556                         uint32_t access_mask;
1557                         uint32_t unknown;
1558                         
1559                         /* readx part */
1560                         uint8_t *data;
1561                         uint16_t remaining;
1562                         uint16_t compaction_mode;
1563                         uint16_t nread;
1564                 } out;
1565         } openxreadx;
1566
1567 #define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
1568 #define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
1569 #define SMB2_CREATE_FLAG_GRANT_OPLOCK             0x0001
1570 #define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK   0x0080
1571
1572         /* SMB2 Create */
1573         struct smb2_create {
1574                 enum smb_open_level level;
1575                 struct {
1576                         /* static body buffer 56 (0x38) bytes */
1577                         uint8_t  security_flags;      /* SMB2_SECURITY_* */
1578                         uint8_t  oplock_level;        /* SMB2_OPLOCK_LEVEL_* */
1579                         uint32_t impersonation_level; /* SMB2_IMPERSONATION_* */
1580                         uint64_t create_flags;
1581                         uint64_t reserved;
1582                         uint32_t desired_access;
1583                         uint32_t file_attributes;
1584                         uint32_t share_access; /* NTCREATEX_SHARE_ACCESS_* */
1585                         uint32_t create_disposition; /* NTCREATEX_DISP_* */
1586                         uint32_t create_options; /* NTCREATEX_OPTIONS_* */
1587
1588                         /* uint16_t fname_ofs */
1589                         /* uint16_t fname_size */
1590                         /* uint32_t blob_ofs; */
1591                         /* uint32_t blob_size; */
1592
1593                         /* dynamic body */
1594                         const char *fname;
1595
1596                         /* now some optional parameters - encoded as tagged blobs */
1597                         struct smb_ea_list eas;
1598                         uint64_t alloc_size;
1599                         struct security_descriptor *sec_desc;
1600                         bool   durable_open;
1601                         struct smb2_handle *durable_handle;
1602                         bool   query_maximal_access;
1603                         NTTIME timewarp;
1604                         bool   query_on_disk_id;
1605                         
1606                         /* and any additional blobs the caller wants */
1607                         struct smb2_create_blobs {
1608                                 uint32_t num_blobs;
1609                                 struct smb2_create_blob {
1610                                         const char *tag;
1611                                         DATA_BLOB data;
1612                                 } *blobs;
1613                         } blobs;
1614                 } in;
1615                 struct {
1616                         union smb_handle file;
1617
1618                         /* static body buffer 88 (0x58) bytes */
1619                         /* uint16_t buffer_code;  0x59 = 0x58 + 1 */
1620                         uint8_t oplock_level;
1621                         uint8_t reserved;
1622                         uint32_t create_action;
1623                         NTTIME   create_time;
1624                         NTTIME   access_time;
1625                         NTTIME   write_time;
1626                         NTTIME   change_time;
1627                         uint64_t alloc_size;
1628                         uint64_t size;
1629                         uint32_t file_attr;
1630                         uint32_t reserved2;
1631                         /* struct smb2_handle handle;*/
1632                         /* uint32_t blob_ofs; */
1633                         /* uint32_t blob_size; */
1634
1635                         /* optional return values matching tagged values in the call */
1636                         uint32_t maximal_access;
1637                         uint8_t on_disk_id[32];
1638
1639                         /* tagged blobs in the reply */
1640                         struct smb2_create_blobs blobs;
1641                 } out;
1642         } smb2;
1643 };
1644
1645
1646
1647 enum smb_read_level {
1648         RAW_READ_READBRAW,
1649         RAW_READ_LOCKREAD,
1650         RAW_READ_READ,
1651         RAW_READ_READX,
1652         RAW_READ_SMB2
1653 };
1654
1655 #define RAW_READ_GENERIC RAW_READ_READX
1656
1657 /* union for read() backend call 
1658
1659    note that .infoX.out.data will be allocated before the backend is
1660    called. It will be big enough to hold the maximum size asked for
1661 */
1662 union smb_read {
1663         /* SMBreadX (and generic) interface */
1664         struct {
1665                 enum smb_read_level level;
1666                 struct {
1667                         union smb_handle file;
1668                         uint64_t offset;
1669                         uint32_t mincnt; /* enforced on SMB2, 16 bit on SMB */
1670                         uint32_t maxcnt;
1671                         uint16_t remaining;
1672                         bool read_for_execute;
1673                 } in;
1674                 struct {
1675                         uint8_t *data;
1676                         uint16_t remaining;
1677                         uint16_t compaction_mode;
1678                         uint32_t nread;
1679                 } out;
1680         } readx, generic;
1681
1682         /* SMBreadbraw interface */
1683         struct {
1684                 enum smb_read_level level;
1685                 struct {
1686                         union smb_handle file;
1687                         uint64_t offset;
1688                         uint16_t  maxcnt;
1689                         uint16_t  mincnt;
1690                         uint32_t  timeout;
1691                 } in;
1692                 struct {
1693                         uint8_t *data;
1694                         uint32_t nread;
1695                 } out;
1696         } readbraw;
1697
1698
1699         /* SMBlockandread interface */
1700         struct {
1701                 enum smb_read_level level;
1702                 struct {
1703                         union smb_handle file;
1704                         uint16_t count;
1705                         uint32_t offset;
1706                         uint16_t remaining;
1707                 } in;
1708                 struct {
1709                         uint8_t *data;
1710                         uint16_t nread;
1711                 } out;
1712         } lockread;
1713
1714         /* SMBread interface */
1715         struct {
1716                 enum smb_read_level level;
1717                 struct {
1718                         union smb_handle file;
1719                         uint16_t count;
1720                         uint32_t offset;
1721                         uint16_t remaining;
1722                 } in;
1723                 struct {
1724                         uint8_t *data;
1725                         uint16_t nread;
1726                 } out;
1727         } read;
1728
1729         /* SMB2 Read */
1730         struct smb2_read {
1731                 enum smb_read_level level;
1732                 struct {
1733                         union smb_handle file;
1734
1735                         /* static body buffer 48 (0x30) bytes */
1736                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1737                         uint8_t _pad;
1738                         uint8_t reserved;
1739                         uint32_t length;
1740                         uint64_t offset;
1741                         /* struct smb2_handle handle; */
1742                         uint32_t min_count;
1743                         uint32_t channel;
1744                         uint32_t remaining;
1745                         /* the docs give no indication of what
1746                            these channel variables are for */
1747                         uint16_t channel_offset;
1748                         uint16_t channel_length;
1749                 } in;
1750                 struct {
1751                         /* static body buffer 16 (0x10) bytes */
1752                         /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
1753                         /* uint8_t data_ofs; */
1754                         /* uint8_t reserved; */
1755                         /* uint32_t data_size; */
1756                         uint32_t remaining;
1757                         uint32_t reserved;
1758
1759                         /* dynamic body */
1760                         DATA_BLOB data;
1761                 } out;
1762         } smb2;
1763 };
1764
1765
1766 enum smb_write_level {
1767         RAW_WRITE_WRITEUNLOCK,
1768         RAW_WRITE_WRITE,
1769         RAW_WRITE_WRITEX,
1770         RAW_WRITE_WRITECLOSE,
1771         RAW_WRITE_SPLWRITE,
1772         RAW_WRITE_SMB2
1773 };
1774
1775 #define RAW_WRITE_GENERIC RAW_WRITE_WRITEX
1776
1777 /* union for write() backend call 
1778 */
1779 union smb_write {
1780         /* SMBwriteX interface */
1781         struct {
1782                 enum smb_write_level level;
1783                 struct {
1784                         union smb_handle file;
1785                         uint64_t offset;
1786                         uint16_t wmode;
1787                         uint16_t remaining;
1788                         uint32_t count;
1789                         const uint8_t *data;
1790                 } in;
1791                 struct {
1792                         uint32_t nwritten;
1793                         uint16_t remaining;
1794                 } out;
1795         } writex, generic;
1796
1797         /* SMBwriteunlock interface */
1798         struct {
1799                 enum smb_write_level level;
1800                 struct {
1801                         union smb_handle file;
1802                         uint16_t count;
1803                         uint32_t offset;
1804                         uint16_t remaining;
1805                         const uint8_t *data;
1806                 } in;
1807                 struct {
1808                         uint32_t nwritten;
1809                 } out;
1810         } writeunlock;
1811
1812         /* SMBwrite interface */
1813         struct {
1814                 enum smb_write_level level;
1815                 struct {
1816                         union smb_handle file;
1817                         uint16_t count;
1818                         uint32_t offset;
1819                         uint16_t remaining;
1820                         const uint8_t *data;
1821                 } in;
1822                 struct {
1823                         uint16_t nwritten;
1824                 } out;
1825         } write;
1826
1827         /* SMBwriteclose interface */
1828         struct {
1829                 enum smb_write_level level;
1830                 struct {
1831                         union smb_handle file;
1832                         uint16_t count;
1833                         uint32_t offset;
1834                         time_t mtime;
1835                         const uint8_t *data;
1836                 } in;
1837                 struct {
1838                         uint16_t nwritten;
1839                 } out;
1840         } writeclose;
1841
1842         /* SMBsplwrite interface */
1843         struct {
1844                 enum smb_write_level level;
1845                 struct {
1846                         union smb_handle file;
1847                         uint16_t count;
1848                         const uint8_t *data;
1849                 } in;
1850         } splwrite;
1851
1852         /* SMB2 Write */
1853         struct smb2_write {
1854                 enum smb_write_level level;
1855                 struct {
1856                         union smb_handle file;
1857
1858                         /* static body buffer 48 (0x30) bytes */
1859                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1860                         /* uint16_t data_ofs; */
1861                         /* uint32_t data_size; */
1862                         uint64_t offset;
1863                         /* struct smb2_handle handle; */
1864                         uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */
1865                         uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */
1866
1867                         /* dynamic body */
1868                         DATA_BLOB data;
1869                 } in;
1870                 struct {
1871                         /* static body buffer 17 (0x11) bytes */
1872                         /* uint16_t buffer_code;  0x11 = 0x10 + 1*/
1873                         uint16_t _pad;
1874                         uint32_t nwritten;
1875                         uint64_t unknown1; /* 0x0000000000000000 */
1876                 } out;
1877         } smb2;
1878 };
1879
1880
1881 enum smb_lock_level {
1882         RAW_LOCK_LOCK,
1883         RAW_LOCK_UNLOCK,
1884         RAW_LOCK_LOCKX,
1885         RAW_LOCK_SMB2,
1886         RAW_LOCK_SMB2_BREAK
1887 };
1888
1889 #define RAW_LOCK_GENERIC RAW_LOCK_LOCKX
1890
1891 /* union for lock() backend call 
1892 */
1893 union smb_lock {
1894         /* SMBlockingX and generic interface */
1895         struct {
1896                 enum smb_lock_level level;
1897                 struct {
1898                         union smb_handle file;
1899                         uint16_t mode;
1900                         uint32_t timeout;
1901                         uint16_t ulock_cnt;
1902                         uint16_t lock_cnt;
1903                         struct smb_lock_entry {
1904                                 uint16_t pid;
1905                                 uint64_t offset;
1906                                 uint64_t count;
1907                         } *locks; /* unlocks are first in the arrray */
1908                 } in;
1909         } generic, lockx;
1910
1911         /* SMBlock and SMBunlock interface */
1912         struct {
1913                 enum smb_lock_level level;
1914                 struct {
1915                         union smb_handle file;
1916                         uint32_t count;
1917                         uint32_t offset;
1918                 } in;
1919         } lock, unlock;
1920
1921         /* SMB2 Lock */
1922         struct smb2_lock {
1923                 enum smb_lock_level level;
1924                 struct {
1925                         union smb_handle file;
1926
1927                         /* static body buffer 48 (0x30) bytes */
1928                         /* uint16_t buffer_code;  0x30 */
1929                         uint16_t lock_count;
1930                         uint32_t reserved;
1931                         /* struct smb2_handle handle; */
1932                         struct smb2_lock_element {
1933                                 uint64_t offset;
1934                                 uint64_t length;
1935 /* these flags are the same as the SMB2 lock flags */
1936 #define SMB2_LOCK_FLAG_NONE             0x00000000
1937 #define SMB2_LOCK_FLAG_SHARED           0x00000001
1938 #define SMB2_LOCK_FLAG_EXCLUSIVE        0x00000002
1939 #define SMB2_LOCK_FLAG_UNLOCK           0x00000004
1940 #define SMB2_LOCK_FLAG_FAIL_IMMEDIATELY 0x00000010
1941 #define SMB2_LOCK_FLAG_ALL_MASK         0x00000017
1942                                 uint32_t flags;
1943                                 uint32_t reserved;
1944                         } *locks;
1945                 } in;
1946                 struct {
1947                         /* static body buffer 4 (0x04) bytes */
1948                         /* uint16_t buffer_code;  0x04 */
1949                         uint16_t reserved;
1950                 } out;
1951         } smb2;
1952
1953         /* SMB2 Break */
1954         struct smb2_break {
1955                 enum smb_lock_level level;
1956                 struct {
1957                         union smb_handle file;
1958
1959                         /* static body buffer 24 (0x18) bytes */
1960                         uint8_t oplock_level;
1961                         uint8_t reserved;
1962                         uint32_t reserved2;
1963                         /* struct smb2_handle handle; */
1964                 } in, out;
1965         } smb2_break;
1966 };
1967
1968
1969 enum smb_close_level {
1970         RAW_CLOSE_CLOSE,
1971         RAW_CLOSE_SPLCLOSE,
1972         RAW_CLOSE_SMB2,
1973         RAW_CLOSE_GENERIC,
1974 };
1975
1976 /*
1977   union for close() backend call
1978 */
1979 union smb_close {
1980         /* generic interface */
1981         struct {
1982                 enum smb_close_level level;
1983                 struct {
1984                         union smb_handle file;
1985                         time_t write_time;
1986 #define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
1987                         uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
1988                 } in;
1989                 struct {
1990                         uint16_t flags;
1991                         NTTIME   create_time;
1992                         NTTIME   access_time;
1993                         NTTIME   write_time;
1994                         NTTIME   change_time;
1995                         uint64_t alloc_size;
1996                         uint64_t size;
1997                         uint32_t file_attr;
1998                 } out;
1999         } generic;
2000
2001         /* SMBclose interface */
2002         struct {
2003                 enum smb_close_level level;
2004                 struct {
2005                         union smb_handle file;
2006                         time_t write_time;
2007                 } in;
2008         } close;
2009
2010         /* SMBsplclose interface - empty! */
2011         struct {
2012                 enum smb_close_level level;
2013                 struct {
2014                         union smb_handle file;
2015                 } in;
2016         } splclose;
2017
2018         /* SMB2 Close */
2019         struct smb2_close {
2020                 enum smb_close_level level;
2021                 struct {
2022                         union smb_handle file;
2023
2024                         /* static body buffer 24 (0x18) bytes */
2025                         /* uint16_t buffer_code;  0x18 */
2026                         uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
2027                         uint32_t _pad;
2028                 } in;
2029                 struct {
2030                         /* static body buffer 60 (0x3C) bytes */
2031                         /* uint16_t buffer_code;  0x3C */
2032                         uint16_t flags;
2033                         uint32_t _pad;
2034                         NTTIME   create_time;
2035                         NTTIME   access_time;
2036                         NTTIME   write_time;
2037                         NTTIME   change_time;
2038                         uint64_t alloc_size;
2039                         uint64_t size;
2040                         uint32_t file_attr;
2041                 } out;
2042         } smb2;
2043 };
2044
2045
2046 enum smb_lpq_level {RAW_LPQ_GENERIC, RAW_LPQ_RETQ};
2047
2048 /*
2049   union for lpq() backend
2050 */
2051 union smb_lpq {
2052         /* generic interface */
2053         struct {
2054                 enum smb_lpq_level level;
2055
2056         } generic;
2057
2058
2059         /* SMBsplretq interface */
2060         struct {
2061                 enum smb_lpq_level level;
2062
2063                 struct {
2064                         uint16_t maxcount;
2065                         uint16_t startidx;
2066                 } in;
2067                 struct {
2068                         uint16_t count;
2069                         uint16_t restart_idx;
2070                         struct {
2071                                 time_t time;
2072                                 uint8_t status;
2073                                 uint16_t job;
2074                                 uint32_t size;
2075                                 char *user;
2076                         } *queue;
2077                 } out;
2078         } retq;
2079 };
2080
2081 enum smb_ioctl_level {
2082         RAW_IOCTL_IOCTL,
2083         RAW_IOCTL_NTIOCTL,
2084         RAW_IOCTL_SMB2,
2085         RAW_IOCTL_SMB2_NO_HANDLE
2086 };
2087
2088 /*
2089   union for ioctl() backend
2090 */
2091 union smb_ioctl {
2092         /* generic interface */
2093         struct {
2094                 enum smb_ioctl_level level;
2095                 struct {
2096                         union smb_handle file;
2097                 } in;
2098         } generic;
2099
2100         /* struct for SMBioctl */
2101         struct {
2102                 enum smb_ioctl_level level;
2103                 struct {
2104                         union smb_handle file;
2105                         uint32_t request;
2106                 } in;
2107                 struct {
2108                         DATA_BLOB blob;
2109                 } out;
2110         } ioctl;
2111
2112
2113         /* struct for NT ioctl call */
2114         struct {
2115                 enum smb_ioctl_level level;
2116                 struct {
2117                         union smb_handle file;
2118                         uint32_t function;
2119                         bool fsctl;
2120                         uint8_t filter;
2121                         uint32_t max_data;
2122                         DATA_BLOB blob;
2123                 } in;
2124                 struct {
2125                         DATA_BLOB blob;
2126                 } out;
2127         } ntioctl;
2128
2129         /* SMB2 Ioctl */
2130         struct smb2_ioctl {
2131                 enum smb_ioctl_level level;
2132                 struct {
2133                         union smb_handle file;
2134
2135                         /* static body buffer 56 (0x38) bytes */
2136                         /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
2137                         uint16_t _pad;
2138                         uint32_t function;
2139                         /*struct smb2_handle handle;*/
2140                         /* uint32_t out_ofs; */
2141                         /* uint32_t out_size; */
2142                         uint32_t unknown2;
2143                         /* uint32_t in_ofs; */
2144                         /* uint32_t in_size; */
2145                         uint32_t max_response_size;
2146                         uint64_t flags;
2147
2148                         /* dynamic body */
2149                         DATA_BLOB out;
2150                         DATA_BLOB in;
2151                 } in;
2152                 struct {
2153                         union smb_handle file;
2154
2155                         /* static body buffer 48 (0x30) bytes */
2156                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
2157                         uint16_t _pad;
2158                         uint32_t function;
2159                         /* struct smb2_handle handle; */
2160                         /* uint32_t in_ofs; */
2161                         /* uint32_t in_size; */
2162                         /* uint32_t out_ofs; */
2163                         /* uint32_t out_size; */
2164                         uint32_t unknown2;
2165                         uint32_t unknown3;
2166
2167                         /* dynamic body */
2168                         DATA_BLOB in;
2169                         DATA_BLOB out;
2170                 } out;
2171         } smb2;
2172 };
2173
2174 enum smb_flush_level {
2175         RAW_FLUSH_FLUSH,
2176         RAW_FLUSH_ALL,
2177         RAW_FLUSH_SMB2
2178 };
2179
2180 union smb_flush {
2181         /* struct for SMBflush */
2182         struct {
2183                 enum smb_flush_level level;
2184                 struct {
2185                         union smb_handle file;
2186                 } in;
2187         } flush, generic;
2188
2189         /* SMBflush with 0xFFFF wildcard fnum */
2190         struct {
2191                 enum smb_flush_level level;
2192         } flush_all;
2193
2194         /* SMB2 Flush */
2195         struct smb2_flush {
2196                 enum smb_flush_level level;
2197                 struct {
2198                         union smb_handle file;
2199                         uint16_t reserved1;
2200                         uint32_t reserved2;
2201                 } in;
2202                 struct {
2203                         uint16_t reserved;
2204                 } out;
2205         } smb2;
2206 };
2207
2208 /* struct for SMBcopy */
2209 struct smb_copy {
2210         struct {
2211                 uint16_t tid2;
2212                 uint16_t ofun;
2213                 uint16_t flags;
2214                 const char *path1;
2215                 const char *path2;
2216         } in;
2217         struct {
2218                 uint16_t count;
2219         } out;
2220 };
2221
2222
2223 /* struct for transact/transact2 call */
2224 struct smb_trans2 {
2225         struct {
2226                 uint16_t max_param;
2227                 uint16_t max_data;
2228                 uint8_t  max_setup;
2229                 uint16_t flags;
2230                 uint32_t timeout;
2231                 uint8_t  setup_count;
2232                 uint16_t *setup;
2233                 const char *trans_name; /* SMBtrans only */
2234                 DATA_BLOB params;
2235                 DATA_BLOB data;
2236         } in;
2237
2238         struct {
2239                 uint8_t  setup_count;
2240                 uint16_t *setup;
2241                 DATA_BLOB params;
2242                 DATA_BLOB data;
2243         } out;
2244 };
2245
2246 /* struct for nttransact2 call */
2247 struct smb_nttrans {
2248         struct {
2249                 uint8_t  max_setup;
2250                 uint32_t max_param;
2251                 uint32_t max_data;
2252                 uint32_t setup_count;
2253                 uint16_t function;
2254                 uint8_t  *setup;
2255                 DATA_BLOB params;
2256                 DATA_BLOB data;
2257         } in;
2258
2259         struct {
2260                 uint8_t  setup_count; /* in units of 16 bit words */
2261                 uint8_t  *setup;
2262                 DATA_BLOB params;
2263                 DATA_BLOB data;
2264         } out;
2265 };
2266
2267 enum smb_notify_level {
2268         RAW_NOTIFY_NTTRANS,
2269         RAW_NOTIFY_SMB2
2270 };
2271
2272 union smb_notify {
2273         /* struct for nttrans change notify call */
2274         struct {
2275                 enum smb_notify_level level;
2276
2277                 struct {
2278                         union smb_handle file;
2279                         uint32_t buffer_size;
2280                         uint32_t completion_filter;
2281                         bool recursive;
2282                 } in;
2283
2284                 struct {
2285                         uint32_t num_changes;
2286                         struct notify_changes {
2287                                 uint32_t action;
2288                                 struct smb_wire_string name;
2289                         } *changes;
2290                 } out;
2291         } nttrans;
2292
2293         struct smb2_notify {
2294                 enum smb_notify_level level;
2295                 
2296                 struct {
2297                         union smb_handle file;
2298                         /* static body buffer 32 (0x20) bytes */
2299                         /* uint16_t buffer_code;  0x32 */
2300                         uint16_t recursive;
2301                         uint32_t buffer_size;
2302                         /*struct  smb2_handle file;*/
2303                         uint32_t completion_filter;
2304                         uint32_t unknown;
2305                 } in;
2306
2307                 struct {
2308                         /* static body buffer 8 (0x08) bytes */
2309                         /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
2310                         /* uint16_t blob_ofs; */
2311                         /* uint16_t blob_size; */
2312
2313                         /* dynamic body */
2314                         /*DATA_BLOB blob;*/
2315
2316                         /* DATA_BLOB content */
2317                         uint32_t num_changes;
2318                         struct notify_changes *changes;
2319                 } out;
2320         } smb2;
2321 };
2322
2323 enum smb_search_level {
2324         RAW_SEARCH_SEARCH,      /* SMBsearch */ 
2325         RAW_SEARCH_FFIRST,      /* SMBffirst */ 
2326         RAW_SEARCH_FUNIQUE,     /* SMBfunique */
2327         RAW_SEARCH_TRANS2,      /* SMBtrans2 */
2328         RAW_SEARCH_SMB2         /* SMB2 Find */
2329 };
2330
2331 enum smb_search_data_level {
2332         RAW_SEARCH_DATA_GENERIC                 = 0x10000, /* only used in the smbcli_ code */
2333         RAW_SEARCH_DATA_SEARCH,
2334         RAW_SEARCH_DATA_STANDARD                = SMB_FIND_STANDARD,
2335         RAW_SEARCH_DATA_EA_SIZE                 = SMB_FIND_EA_SIZE,
2336         RAW_SEARCH_DATA_EA_LIST                 = SMB_FIND_EA_LIST,
2337         RAW_SEARCH_DATA_DIRECTORY_INFO          = SMB_FIND_DIRECTORY_INFO,
2338         RAW_SEARCH_DATA_FULL_DIRECTORY_INFO     = SMB_FIND_FULL_DIRECTORY_INFO,
2339         RAW_SEARCH_DATA_NAME_INFO               = SMB_FIND_NAME_INFO,
2340         RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO     = SMB_FIND_BOTH_DIRECTORY_INFO,
2341         RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO  = SMB_FIND_ID_FULL_DIRECTORY_INFO,
2342         RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO  = SMB_FIND_ID_BOTH_DIRECTORY_INFO,
2343         RAW_SEARCH_DATA_UNIX_INFO               = SMB_FIND_UNIX_INFO,
2344         RAW_SEARCH_DATA_UNIX_INFO2              = SMB_FIND_UNIX_INFO2
2345 };
2346         
2347 /* union for file search */
2348 union smb_search_first {
2349         struct {
2350                 enum smb_search_level level;
2351                 enum smb_search_data_level data_level;
2352         } generic;
2353         
2354         /* search (old) findfirst interface. 
2355            Also used for ffirst and funique. */
2356         struct {
2357                 enum smb_search_level level;
2358                 enum smb_search_data_level data_level;
2359         
2360                 struct {
2361                         uint16_t max_count;
2362                         uint16_t search_attrib;
2363                         const char *pattern;
2364                 } in;
2365                 struct {
2366                         int16_t count;
2367                 } out;
2368         } search_first;
2369
2370         /* trans2 findfirst interface */
2371         struct {
2372                 enum smb_search_level level;
2373                 enum smb_search_data_level data_level;
2374                 
2375                 struct {
2376                         uint16_t search_attrib;
2377                         uint16_t max_count;
2378                         uint16_t flags;
2379                         uint32_t storage_type;
2380                         const char *pattern;
2381
2382                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2383                         uint_t num_names;
2384                         struct ea_name *ea_names;
2385                 } in;
2386                 struct {
2387                         uint16_t handle;
2388                         uint16_t count;
2389                         uint16_t end_of_search;
2390                 } out;
2391         } t2ffirst;
2392
2393 /*
2394   SMB2 uses different level numbers for the same old SMB trans2 search levels
2395 */
2396 #define SMB2_FIND_DIRECTORY_INFO         0x01
2397 #define SMB2_FIND_FULL_DIRECTORY_INFO    0x02
2398 #define SMB2_FIND_BOTH_DIRECTORY_INFO    0x03
2399 #define SMB2_FIND_NAME_INFO              0x0C
2400 #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25
2401 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26
2402
2403 /* flags for SMB2 find */
2404 #define SMB2_CONTINUE_FLAG_RESTART    0x01
2405 #define SMB2_CONTINUE_FLAG_SINGLE     0x02
2406 #define SMB2_CONTINUE_FLAG_INDEX      0x04
2407 #define SMB2_CONTINUE_FLAG_REOPEN     0x10
2408
2409         /* SMB2 Find */
2410         struct smb2_find {
2411                 enum smb_search_level level;
2412                 enum smb_search_data_level data_level;
2413                 struct {
2414                         union smb_handle file;
2415
2416                         /* static body buffer 32 (0x20) bytes */
2417                         /* uint16_t buffer_code;  0x21 = 0x20 + 1 */
2418                         uint8_t level;
2419                         uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */
2420                         uint32_t file_index; 
2421                         /* struct smb2_handle handle; */
2422                         /* uint16_t pattern_ofs; */
2423                         /* uint16_t pattern_size; */
2424                         uint32_t max_response_size;
2425         
2426                         /* dynamic body */
2427                         const char *pattern;
2428                 } in;
2429                 struct {
2430                         /* static body buffer 8 (0x08) bytes */
2431                         /* uint16_t buffer_code;  0x08 */
2432                         /* uint16_t blob_ofs; */
2433                         /* uint32_t blob_size; */
2434
2435                         /* dynamic body */
2436                         DATA_BLOB blob;
2437                 } out;
2438         } smb2;
2439 };
2440
2441 /* union for file search continue */
2442 union smb_search_next {
2443         struct {
2444                 enum smb_search_level level;
2445                 enum smb_search_data_level data_level;
2446         } generic;
2447
2448         /* search (old) findnext interface. Also used
2449            for ffirst when continuing */
2450         struct {
2451                 enum smb_search_level level;
2452                 enum smb_search_data_level data_level;
2453         
2454                 struct {
2455                         uint16_t max_count;
2456                         uint16_t search_attrib;
2457                         struct smb_search_id {
2458                                 uint8_t reserved;
2459                                 char name[11];
2460                                 uint8_t handle;
2461                                 uint32_t server_cookie;
2462                                 uint32_t client_cookie;
2463                         } id;
2464                 } in;
2465                 struct {
2466                         uint16_t count;
2467                 } out;
2468         } search_next;
2469         
2470         /* trans2 findnext interface */
2471         struct {
2472                 enum smb_search_level level;
2473                 enum smb_search_data_level data_level;
2474                 
2475                 struct {
2476                         uint16_t handle;
2477                         uint16_t max_count;
2478                         uint32_t resume_key;
2479                         uint16_t flags;
2480                         const char *last_name;
2481
2482                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2483                         uint_t num_names;
2484                         struct ea_name *ea_names;
2485                 } in;
2486                 struct {
2487                         uint16_t count;
2488                         uint16_t end_of_search;
2489                 } out;
2490         } t2fnext;
2491
2492         /* SMB2 Find */
2493         struct smb2_find smb2;
2494 };
2495
2496 /* union for search reply file data */
2497 union smb_search_data {
2498         /*
2499          * search (old) findfirst 
2500          * RAW_SEARCH_DATA_SEARCH
2501          */
2502         struct {
2503                 uint16_t attrib;
2504                 time_t write_time;
2505                 uint32_t size;
2506                 struct smb_search_id id;
2507                 const char *name;
2508         } search;
2509
2510         /* trans2 findfirst RAW_SEARCH_DATA_STANDARD level */
2511         struct {
2512                 uint32_t resume_key;
2513                 time_t create_time;
2514                 time_t access_time;
2515                 time_t write_time;
2516                 uint32_t size;
2517                 uint32_t alloc_size;
2518                 uint16_t attrib;
2519                 struct smb_wire_string name;
2520         } standard;
2521
2522         /* trans2 findfirst RAW_SEARCH_DATA_EA_SIZE level */
2523         struct {
2524                 uint32_t resume_key;
2525                 time_t create_time;
2526                 time_t access_time;
2527                 time_t write_time;
2528                 uint32_t size;
2529                 uint32_t alloc_size;
2530                 uint16_t attrib;
2531                 uint32_t ea_size;
2532                 struct smb_wire_string name;
2533         } ea_size;
2534
2535         /* trans2 findfirst RAW_SEARCH_DATA_EA_LIST level */
2536         struct {
2537                 uint32_t resume_key;
2538                 time_t create_time;
2539                 time_t access_time;
2540                 time_t write_time;
2541                 uint32_t size;
2542                 uint32_t alloc_size;
2543                 uint16_t attrib;
2544                 struct smb_ea_list eas;
2545                 struct smb_wire_string name;
2546         } ea_list;
2547
2548         /* RAW_SEARCH_DATA_DIRECTORY_INFO interface */
2549         struct {
2550                 uint32_t file_index;
2551                 NTTIME create_time;
2552                 NTTIME access_time;
2553                 NTTIME write_time;
2554                 NTTIME change_time;
2555                 uint64_t  size;
2556                 uint64_t  alloc_size;
2557                 uint32_t   attrib;
2558                 struct smb_wire_string name;
2559         } directory_info;
2560
2561         /* RAW_SEARCH_DATA_FULL_DIRECTORY_INFO interface */
2562         struct {
2563                 uint32_t file_index;
2564                 NTTIME create_time;
2565                 NTTIME access_time;
2566                 NTTIME write_time;
2567                 NTTIME change_time;
2568                 uint64_t  size;
2569                 uint64_t  alloc_size;
2570                 uint32_t   attrib;
2571                 uint32_t   ea_size;
2572                 struct smb_wire_string name;
2573         } full_directory_info;
2574
2575         /* RAW_SEARCH_DATA_NAME_INFO interface */
2576         struct {
2577                 uint32_t file_index;
2578                 struct smb_wire_string name;
2579         } name_info;
2580
2581         /* RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO interface */
2582         struct {
2583                 uint32_t file_index;
2584                 NTTIME create_time;
2585                 NTTIME access_time;
2586                 NTTIME write_time;
2587                 NTTIME change_time;
2588                 uint64_t  size;
2589                 uint64_t  alloc_size;
2590                 uint32_t   attrib;
2591                 uint32_t   ea_size;
2592                 struct smb_wire_string short_name;
2593                 struct smb_wire_string name;
2594         } both_directory_info;
2595
2596         /* RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO interface */
2597         struct {
2598                 uint32_t file_index;
2599                 NTTIME create_time;
2600                 NTTIME access_time;
2601                 NTTIME write_time;
2602                 NTTIME change_time;
2603                 uint64_t size;
2604                 uint64_t alloc_size;
2605                 uint32_t attrib;
2606                 uint32_t ea_size;
2607                 uint64_t file_id;
2608                 struct smb_wire_string name;
2609         } id_full_directory_info;
2610
2611         /* RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO interface */
2612         struct {
2613                 uint32_t file_index;
2614                 NTTIME create_time;
2615                 NTTIME access_time;
2616                 NTTIME write_time;
2617                 NTTIME change_time;
2618                 uint64_t size;
2619                 uint64_t alloc_size;
2620                 uint32_t  attrib;
2621                 uint32_t  ea_size;
2622                 uint64_t file_id;
2623                 struct smb_wire_string short_name;
2624                 struct smb_wire_string name;
2625         } id_both_directory_info;
2626
2627         /* RAW_SEARCH_DATA_UNIX_INFO interface */
2628         struct {
2629                 uint32_t file_index;
2630                 uint64_t size;
2631                 uint64_t alloc_size;
2632                 NTTIME status_change_time;
2633                 NTTIME access_time;
2634                 NTTIME change_time;
2635                 uint64_t uid;
2636                 uint64_t gid;
2637                 uint32_t file_type;
2638                 uint64_t dev_major;
2639                 uint64_t dev_minor;
2640                 uint64_t unique_id;
2641                 uint64_t permissions;
2642                 uint64_t nlink;         
2643                 const char *name;
2644         } unix_info;
2645
2646         /* RAW_SEARCH_DATA_UNIX_INFO2 interface */
2647         struct {
2648                 uint32_t file_index;
2649                 uint64_t end_of_file;
2650                 uint64_t num_bytes;
2651                 NTTIME status_change_time;
2652                 NTTIME access_time;
2653                 NTTIME change_time;
2654                 uint64_t uid;
2655                 uint64_t gid;
2656                 uint32_t file_type;
2657                 uint64_t dev_major;
2658                 uint64_t dev_minor;
2659                 uint64_t unique_id;
2660                 uint64_t permissions;
2661                 uint64_t nlink;
2662                 NTTIME create_time;
2663                 uint32_t file_flags;
2664                 uint32_t flags_mask;
2665                 struct smb_wire_string name;
2666         } unix_info2;
2667 };
2668
2669 /* Callback function passed to the raw search interface. */
2670 typedef bool (*smbcli_search_callback)(void *private, const union smb_search_data *file);
2671
2672 enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE};
2673
2674 /* union for file search close */
2675 union smb_search_close {
2676         struct {
2677                 enum smb_search_close_level level;
2678         } generic;
2679
2680         /* SMBfclose (old search) interface */
2681         struct {
2682                 enum smb_search_close_level level;
2683         
2684                 struct {
2685                         /* max_count and search_attrib are not used, but are present */
2686                         uint16_t max_count;
2687                         uint16_t search_attrib;
2688                         struct smb_search_id id;
2689                 } in;
2690         } fclose;
2691         
2692         /* SMBfindclose interface */
2693         struct {
2694                 enum smb_search_close_level level;
2695                 
2696                 struct {
2697                         uint16_t handle;
2698                 } in;
2699         } findclose;
2700 };
2701
2702
2703 /*
2704   struct for SMBecho call
2705 */
2706 struct smb_echo {
2707         struct {
2708                 uint16_t repeat_count;
2709                 uint16_t size;
2710                 uint8_t *data;
2711         } in;
2712         struct {
2713                 uint16_t count;
2714                 uint16_t sequence_number;
2715                 uint16_t size;
2716                 uint8_t *data;
2717         } out;
2718 };
2719
2720 /*
2721   struct for shadow copy volumes
2722  */
2723 struct smb_shadow_copy {
2724         struct {
2725                 union smb_handle file;
2726                 uint32_t max_data;
2727         } in;
2728         struct {
2729                 uint32_t num_volumes;
2730                 uint32_t num_names;
2731                 const char **names;
2732         } out;
2733 };
2734
2735 #endif /* __LIBCLI_RAW_INTERFACES_H__ */