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