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