Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into nosmbpython
[ab/samba.git/.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                         uint64_t mode;
688                         struct smb_wire_string fname;
689                 } out;
690         } all_info2;
691
692         /* RAW_FILEINFO_ALT_NAME_INFO and RAW_FILEINFO_ALT_NAME_INFORMATION interfaces */
693         struct {
694                 enum smb_fileinfo_level level;
695                 struct {
696                         union smb_handle_or_path file;
697                 } in;
698                 struct {
699                         struct smb_wire_string fname;
700                 } out;
701         } alt_name_info;
702
703         /* RAW_FILEINFO_STREAM_INFO and RAW_FILEINFO_STREAM_INFORMATION interfaces */
704         struct {
705                 enum smb_fileinfo_level level;
706                 struct {
707                         union smb_handle_or_path file;
708                 } in;
709                 struct stream_information {
710                         uint_t num_streams;
711                         struct stream_struct *streams;
712                 } out;
713         } stream_info;
714         
715         /* RAW_FILEINFO_COMPRESSION_INFO and RAW_FILEINFO_COMPRESSION_INFORMATION interfaces */
716         struct {
717                 enum smb_fileinfo_level level;
718                 struct {
719                         union smb_handle_or_path file;
720                 } in;
721                 struct {
722                         uint64_t compressed_size;
723                         uint16_t format;
724                         uint8_t unit_shift;
725                         uint8_t chunk_shift;
726                         uint8_t cluster_shift;
727                 } out;
728         } compression_info;
729
730         /* RAW_FILEINFO_UNIX_BASIC interface */
731         struct {
732                 enum smb_fileinfo_level level;
733                 struct {
734                         union smb_handle_or_path file;
735                 } in;
736                 struct {
737                         uint64_t end_of_file;
738                         uint64_t num_bytes;
739                         NTTIME status_change_time;
740                         NTTIME access_time;
741                         NTTIME change_time;
742                         uint64_t uid;
743                         uint64_t gid;
744                         uint32_t file_type;
745                         uint64_t dev_major;
746                         uint64_t dev_minor;
747                         uint64_t unique_id;
748                         uint64_t permissions;
749                         uint64_t nlink;
750                 } out;
751         } unix_basic_info;
752
753         /* RAW_FILEINFO_UNIX_INFO2 interface */
754         struct {
755                 enum smb_fileinfo_level level;
756                 struct {
757                         union smb_handle_or_path file;
758                 } in;
759                 struct {
760                         uint64_t end_of_file;
761                         uint64_t num_bytes;
762                         NTTIME status_change_time;
763                         NTTIME access_time;
764                         NTTIME change_time;
765                         uint64_t uid;
766                         uint64_t gid;
767                         uint32_t file_type;
768                         uint64_t dev_major;
769                         uint64_t dev_minor;
770                         uint64_t unique_id;
771                         uint64_t permissions;
772                         uint64_t nlink;
773                         NTTIME create_time;
774                         uint32_t file_flags;
775                         uint32_t flags_mask;
776                 } out;
777         } unix_info2;
778
779         /* RAW_FILEINFO_UNIX_LINK interface */
780         struct {
781                 enum smb_fileinfo_level level;
782                 struct {
783                         union smb_handle_or_path file;
784                 } in;
785                 struct {
786                         struct smb_wire_string link_dest;
787                 } out;
788         } unix_link_info;
789
790         /* RAW_FILEINFO_INTERNAL_INFORMATION interface */
791         struct {
792                 enum smb_fileinfo_level level;
793                 struct {
794                         union smb_handle_or_path file;
795                 } in;
796                 struct {
797                         uint64_t file_id;
798                 } out;
799         } internal_information;
800
801         /* RAW_FILEINFO_ACCESS_INFORMATION interface */
802         struct {
803                 enum smb_fileinfo_level level;
804                 struct {
805                         union smb_handle_or_path file;
806                 } in;
807                 struct {
808                         uint32_t access_flags;
809                 } out;
810         } access_information;
811
812         /* RAW_FILEINFO_POSITION_INFORMATION interface */
813         struct {
814                 enum smb_fileinfo_level level;
815                 struct {
816                         union smb_handle_or_path file;
817                 } in;
818                 struct {
819                         uint64_t position;
820                 } out;
821         } position_information;
822
823         /* RAW_FILEINFO_MODE_INFORMATION interface */
824         struct {
825                 enum smb_fileinfo_level level;
826                 struct {
827                         union smb_handle_or_path file;
828                 } in;
829                 struct {
830                         uint32_t mode;
831                 } out;
832         } mode_information;
833
834         /* RAW_FILEINFO_ALIGNMENT_INFORMATION interface */
835         struct {
836                 enum smb_fileinfo_level level;
837                 struct {
838                         union smb_handle_or_path file;
839                 } in;
840                 struct {
841                         uint32_t alignment_requirement;
842                 } out;
843         } alignment_information;
844
845         /* RAW_FILEINFO_NETWORK_OPEN_INFORMATION interface */
846         struct {
847                 enum smb_fileinfo_level level;
848                 struct {
849                         union smb_handle_or_path file;
850                 } in;
851                 struct {
852                         NTTIME create_time;
853                         NTTIME access_time;
854                         NTTIME write_time;
855                         NTTIME change_time;
856                         uint64_t alloc_size;
857                         uint64_t size;
858                         uint32_t attrib;
859                 } out;
860         } network_open_information;
861
862
863         /* RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION interface */
864         struct {
865                 enum smb_fileinfo_level level;
866                 struct {
867                         union smb_handle_or_path file;
868                 } in;
869                 struct {
870                         uint32_t attrib;
871                         uint32_t reparse_tag;
872                 } out;
873         } attribute_tag_information;
874
875         /* RAW_FILEINFO_SEC_DESC */
876         struct {
877                 enum smb_fileinfo_level level;
878                 struct {
879                         union smb_handle_or_path file;
880                         uint32_t secinfo_flags;
881                 } in;
882                 struct {
883                         struct security_descriptor *sd;
884                 } out;
885         } query_secdesc;
886 };
887
888
889 enum smb_setfileinfo_level {
890         RAW_SFILEINFO_GENERIC                 = 0xF000, 
891         RAW_SFILEINFO_SETATTR,                /* SMBsetatr */
892         RAW_SFILEINFO_SETATTRE,               /* SMBsetattrE */
893         RAW_SFILEINFO_SEC_DESC,               /* NT_TRANSACT_SET_SECURITY_DESC */
894         RAW_SFILEINFO_STANDARD                = SMB_SFILEINFO_STANDARD,
895         RAW_SFILEINFO_EA_SET                  = SMB_SFILEINFO_EA_SET,
896         RAW_SFILEINFO_BASIC_INFO              = SMB_SFILEINFO_BASIC_INFO,
897         RAW_SFILEINFO_DISPOSITION_INFO        = SMB_SFILEINFO_DISPOSITION_INFO,
898         RAW_SFILEINFO_ALLOCATION_INFO         = SMB_SFILEINFO_ALLOCATION_INFO,
899         RAW_SFILEINFO_END_OF_FILE_INFO        = SMB_SFILEINFO_END_OF_FILE_INFO,
900         RAW_SFILEINFO_UNIX_BASIC              = SMB_SFILEINFO_UNIX_BASIC,
901         RAW_SFILEINFO_UNIX_INFO2              = SMB_SFILEINFO_UNIX_INFO2,
902         RAW_SFILEINFO_UNIX_LINK               = SMB_SFILEINFO_UNIX_LINK,
903         RAW_SFILEINFO_UNIX_HLINK              = SMB_SFILEINFO_UNIX_HLINK,
904         RAW_SFILEINFO_BASIC_INFORMATION       = SMB_SFILEINFO_BASIC_INFORMATION,
905         RAW_SFILEINFO_RENAME_INFORMATION      = SMB_SFILEINFO_RENAME_INFORMATION,
906         RAW_SFILEINFO_DISPOSITION_INFORMATION = SMB_SFILEINFO_DISPOSITION_INFORMATION,
907         RAW_SFILEINFO_POSITION_INFORMATION    = SMB_SFILEINFO_POSITION_INFORMATION,
908         RAW_SFILEINFO_MODE_INFORMATION        = SMB_SFILEINFO_MODE_INFORMATION,
909         RAW_SFILEINFO_ALLOCATION_INFORMATION  = SMB_SFILEINFO_ALLOCATION_INFORMATION,
910         RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION,
911         RAW_SFILEINFO_1023                    = SMB_SFILEINFO_1023,
912         RAW_SFILEINFO_1025                    = SMB_SFILEINFO_1025,
913         RAW_SFILEINFO_1029                    = SMB_SFILEINFO_1029,
914         RAW_SFILEINFO_1032                    = SMB_SFILEINFO_1032,
915         RAW_SFILEINFO_1039                    = SMB_SFILEINFO_1039,
916         RAW_SFILEINFO_1040                    = SMB_SFILEINFO_1040,
917         
918         /* cope with breakage in SMB2 */
919         RAW_SFILEINFO_RENAME_INFORMATION_SMB2 = SMB_SFILEINFO_RENAME_INFORMATION|0x80000000,
920 };
921
922 /* union used in setfileinfo() and setpathinfo() calls */
923 union smb_setfileinfo {
924         /* generic interface */
925         struct {
926                 enum smb_setfileinfo_level level;
927                 struct {
928                         union smb_handle_or_path file;
929                 } in;
930         } generic;
931
932         /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */
933         struct {
934                 enum smb_setfileinfo_level level;
935                 struct {
936                         union smb_handle_or_path file;
937                         uint16_t attrib;
938                         time_t write_time;
939                 } in;
940         } setattr;
941
942         /* RAW_SFILEINFO_SETATTRE (SMBsetattrE) interface - only via setfileinfo() 
943            also RAW_SFILEINFO_STANDARD */
944         struct {
945                 enum smb_setfileinfo_level level;
946                 struct {
947                         union smb_handle_or_path file;
948                         time_t create_time;
949                         time_t access_time;
950                         time_t write_time;
951                         /* notice that size, alloc_size and attrib are not settable,
952                            unlike the corresponding qfileinfo level */
953                 } in;
954         } setattre, standard;
955
956         /* RAW_SFILEINFO_EA_SET interface */
957         struct {
958                 enum smb_setfileinfo_level level;
959                 struct {
960                         union smb_handle_or_path file;
961                         uint_t num_eas;
962                         struct ea_struct *eas;                  
963                 } in;
964         } ea_set;
965
966         /* RAW_SFILEINFO_BASIC_INFO and
967            RAW_SFILEINFO_BASIC_INFORMATION interfaces */
968         struct {
969                 enum smb_setfileinfo_level level;
970                 struct {
971                         union smb_handle_or_path file;
972                         NTTIME create_time;
973                         NTTIME access_time;
974                         NTTIME write_time;
975                         NTTIME change_time;
976                         uint32_t attrib;
977                 } in;
978         } basic_info;
979
980         /* RAW_SFILEINFO_DISPOSITION_INFO and 
981            RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */
982         struct {
983                 enum smb_setfileinfo_level level;
984                 struct {
985                         union smb_handle_or_path file;
986                         bool delete_on_close;
987                 } in;
988         } disposition_info;
989
990         /* RAW_SFILEINFO_ALLOCATION_INFO and 
991            RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */
992         struct {
993                 enum smb_setfileinfo_level level;
994                 struct {
995                         union smb_handle_or_path file;
996                         /* w2k3 rounds this up to nearest 4096 */
997                         uint64_t alloc_size;
998                 } in;
999         } allocation_info;
1000         
1001         /* RAW_SFILEINFO_END_OF_FILE_INFO and 
1002            RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */
1003         struct {
1004                 enum smb_setfileinfo_level level;
1005                 struct {
1006                         union smb_handle_or_path file;
1007                         uint64_t size;
1008                 } in;
1009         } end_of_file_info;
1010
1011         /* RAW_SFILEINFO_RENAME_INFORMATION interface */
1012         struct {
1013                 enum smb_setfileinfo_level level;
1014                 struct {
1015                         union smb_handle_or_path file;
1016                         uint8_t overwrite;
1017                         uint64_t root_fid;
1018                         const char *new_name;
1019                 } in;
1020         } rename_information;
1021
1022         /* RAW_SFILEINFO_POSITION_INFORMATION interface */
1023         struct {
1024                 enum smb_setfileinfo_level level;
1025                 struct {
1026                         union smb_handle_or_path file;
1027                         uint64_t position;
1028                 } in;
1029         } position_information;
1030
1031         /* RAW_SFILEINFO_MODE_INFORMATION interface */
1032         struct {
1033                 enum smb_setfileinfo_level level;
1034                 struct {
1035                         union smb_handle_or_path file;
1036                         /* valid values seem to be 0, 2, 4 and 6 */
1037                         uint32_t mode;
1038                 } in;
1039         } mode_information;
1040
1041         /* RAW_SFILEINFO_UNIX_BASIC interface */
1042         struct {
1043                 enum smb_setfileinfo_level level;
1044                 struct {
1045                         union smb_handle_or_path file;
1046                         uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */
1047                         uint64_t end_of_file;
1048                         uint64_t num_bytes;
1049                         NTTIME status_change_time;
1050                         NTTIME access_time;
1051                         NTTIME change_time;
1052                         uint64_t uid;
1053                         uint64_t gid;
1054                         uint32_t file_type;
1055                         uint64_t dev_major;
1056                         uint64_t dev_minor;
1057                         uint64_t unique_id;
1058                         uint64_t permissions;
1059                         uint64_t nlink;
1060                 } in;
1061         } unix_basic;
1062
1063         /* RAW_SFILEINFO_UNIX_INFO2 interface */
1064         struct {
1065                 enum smb_setfileinfo_level level;
1066                 struct {
1067                         union smb_handle_or_path file;
1068                         uint64_t end_of_file;
1069                         uint64_t num_bytes;
1070                         NTTIME status_change_time;
1071                         NTTIME access_time;
1072                         NTTIME change_time;
1073                         uint64_t uid;
1074                         uint64_t gid;
1075                         uint32_t file_type;
1076                         uint64_t dev_major;
1077                         uint64_t dev_minor;
1078                         uint64_t unique_id;
1079                         uint64_t permissions;
1080                         uint64_t nlink;
1081                         NTTIME create_time;
1082                         uint32_t file_flags;
1083                         uint32_t flags_mask;
1084                 } in;
1085         } unix_info2;
1086
1087         /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */
1088         struct {
1089                 enum smb_setfileinfo_level level;
1090                 struct {
1091                         union smb_handle_or_path file;
1092                         const char *link_dest;
1093                 } in;
1094         } unix_link, unix_hlink;
1095
1096         /* RAW_FILEINFO_SET_SEC_DESC */
1097         struct {
1098                 enum smb_setfileinfo_level level;
1099                 struct {
1100                         union smb_handle_or_path file;
1101                         uint32_t secinfo_flags;
1102                         struct security_descriptor *sd;
1103                 } in;
1104         } set_secdesc;
1105 };
1106
1107
1108 enum smb_fsinfo_level {
1109                    RAW_QFS_GENERIC                        = 0xF000, 
1110                    RAW_QFS_DSKATTR,                         /* SMBdskattr */
1111                    RAW_QFS_ALLOCATION                     = SMB_QFS_ALLOCATION,
1112                    RAW_QFS_VOLUME                         = SMB_QFS_VOLUME,
1113                    RAW_QFS_VOLUME_INFO                    = SMB_QFS_VOLUME_INFO,
1114                    RAW_QFS_SIZE_INFO                      = SMB_QFS_SIZE_INFO,
1115                    RAW_QFS_DEVICE_INFO                    = SMB_QFS_DEVICE_INFO,
1116                    RAW_QFS_ATTRIBUTE_INFO                 = SMB_QFS_ATTRIBUTE_INFO,
1117                    RAW_QFS_UNIX_INFO                      = SMB_QFS_UNIX_INFO,
1118                    RAW_QFS_VOLUME_INFORMATION             = SMB_QFS_VOLUME_INFORMATION,
1119                    RAW_QFS_SIZE_INFORMATION               = SMB_QFS_SIZE_INFORMATION,
1120                    RAW_QFS_DEVICE_INFORMATION             = SMB_QFS_DEVICE_INFORMATION,
1121                    RAW_QFS_ATTRIBUTE_INFORMATION          = SMB_QFS_ATTRIBUTE_INFORMATION,
1122                    RAW_QFS_QUOTA_INFORMATION              = SMB_QFS_QUOTA_INFORMATION,
1123                    RAW_QFS_FULL_SIZE_INFORMATION          = SMB_QFS_FULL_SIZE_INFORMATION,
1124                    RAW_QFS_OBJECTID_INFORMATION           = SMB_QFS_OBJECTID_INFORMATION};
1125
1126
1127 /* union for fsinfo() backend call. Note that there are no in
1128    structures, as this call only contains out parameters */
1129 union smb_fsinfo {
1130         /* generic interface */
1131         struct {
1132                 enum smb_fsinfo_level level;
1133                 struct smb2_handle handle; /* only for smb2 */
1134
1135                 struct {
1136                         uint32_t block_size;
1137                         uint64_t blocks_total;
1138                         uint64_t blocks_free;
1139                         uint32_t fs_id;
1140                         NTTIME create_time;
1141                         uint32_t serial_number;
1142                         uint32_t fs_attr;
1143                         uint32_t max_file_component_length;
1144                         uint32_t device_type;
1145                         uint32_t device_characteristics;
1146                         uint64_t quota_soft;
1147                         uint64_t quota_hard;
1148                         uint64_t quota_flags;
1149                         struct GUID guid;
1150                         char *volume_name;
1151                         char *fs_type;
1152                 } out;
1153         } generic;
1154
1155         /* SMBdskattr interface */
1156         struct {
1157                 enum smb_fsinfo_level level;
1158
1159                 struct {
1160                         uint16_t units_total;
1161                         uint16_t blocks_per_unit;
1162                         uint16_t block_size;
1163                         uint16_t units_free;
1164                 } out;
1165         } dskattr;
1166
1167         /* trans2 RAW_QFS_ALLOCATION interface */
1168         struct {
1169                 enum smb_fsinfo_level level;
1170
1171                 struct {
1172                         uint32_t fs_id;
1173                         uint32_t sectors_per_unit;
1174                         uint32_t total_alloc_units;
1175                         uint32_t avail_alloc_units;
1176                         uint16_t bytes_per_sector;
1177                 } out;
1178         } allocation;
1179
1180         /* TRANS2 RAW_QFS_VOLUME interface */
1181         struct {
1182                 enum smb_fsinfo_level level;
1183
1184                 struct {
1185                         uint32_t serial_number;
1186                         struct smb_wire_string volume_name;
1187                 } out;
1188         } volume;
1189
1190         /* TRANS2 RAW_QFS_VOLUME_INFO and RAW_QFS_VOLUME_INFORMATION interfaces */
1191         struct {
1192                 enum smb_fsinfo_level level;
1193                 struct smb2_handle handle; /* only for smb2 */
1194
1195                 struct {
1196                         NTTIME create_time;
1197                         uint32_t serial_number;
1198                         struct smb_wire_string volume_name;
1199                 } out;
1200         } volume_info;
1201
1202         /* trans2 RAW_QFS_SIZE_INFO and RAW_QFS_SIZE_INFORMATION interfaces */
1203         struct {
1204                 enum smb_fsinfo_level level;
1205                 struct smb2_handle handle; /* only for smb2 */
1206
1207                 struct {
1208                         uint64_t total_alloc_units;
1209                         uint64_t avail_alloc_units; /* maps to call_avail_alloc_units */
1210                         uint32_t sectors_per_unit;
1211                         uint32_t bytes_per_sector;
1212                 } out;
1213         } size_info;
1214
1215         /* TRANS2 RAW_QFS_DEVICE_INFO and RAW_QFS_DEVICE_INFORMATION interfaces */
1216         struct {
1217                 enum smb_fsinfo_level level;
1218                 struct smb2_handle handle; /* only for smb2 */
1219
1220                 struct {
1221                         uint32_t device_type;
1222                         uint32_t characteristics;
1223                 } out;
1224         } device_info;
1225
1226
1227         /* TRANS2 RAW_QFS_ATTRIBUTE_INFO and RAW_QFS_ATTRIBUTE_INFORMATION interfaces */
1228         struct {
1229                 enum smb_fsinfo_level level;
1230                 struct smb2_handle handle; /* only for smb2 */
1231
1232                 struct {
1233                         uint32_t fs_attr;
1234                         uint32_t max_file_component_length;
1235                         struct smb_wire_string fs_type;
1236                 } out;
1237         } attribute_info;
1238
1239
1240         /* TRANS2 RAW_QFS_UNIX_INFO interface */
1241         struct {
1242                 enum smb_fsinfo_level level;
1243
1244                 struct {
1245                         uint16_t major_version;
1246                         uint16_t minor_version;
1247                         uint64_t capability;
1248                 } out;
1249         } unix_info;
1250
1251         /* trans2 RAW_QFS_QUOTA_INFORMATION interface */
1252         struct {
1253                 enum smb_fsinfo_level level;
1254                 struct smb2_handle handle; /* only for smb2 */
1255
1256                 struct {
1257                         uint64_t unknown[3];
1258                         uint64_t quota_soft;
1259                         uint64_t quota_hard;
1260                         uint64_t quota_flags;
1261                 } out;
1262         } quota_information;    
1263
1264         /* trans2 RAW_QFS_FULL_SIZE_INFORMATION interface */
1265         struct {
1266                 enum smb_fsinfo_level level;
1267                 struct smb2_handle handle; /* only for smb2 */
1268
1269                 struct {
1270                         uint64_t total_alloc_units;
1271                         uint64_t call_avail_alloc_units;
1272                         uint64_t actual_avail_alloc_units;
1273                         uint32_t sectors_per_unit;
1274                         uint32_t bytes_per_sector;
1275                 } out;
1276         } full_size_information;
1277
1278         /* trans2 RAW_QFS_OBJECTID_INFORMATION interface */
1279         struct {
1280                 enum smb_fsinfo_level level;
1281                 struct smb2_handle handle; /* only for smb2 */
1282
1283                 struct {
1284                         struct GUID  guid;
1285                         uint64_t unknown[6];
1286                 } out;
1287         } objectid_information; 
1288 };
1289
1290
1291
1292 enum smb_open_level {
1293         RAW_OPEN_OPEN,
1294         RAW_OPEN_OPENX, 
1295         RAW_OPEN_MKNEW,
1296         RAW_OPEN_CREATE, 
1297         RAW_OPEN_CTEMP,
1298         RAW_OPEN_SPLOPEN,
1299         RAW_OPEN_NTCREATEX,
1300         RAW_OPEN_T2OPEN,
1301         RAW_OPEN_NTTRANS_CREATE, 
1302         RAW_OPEN_OPENX_READX,
1303         RAW_OPEN_SMB2
1304 };
1305
1306 /* the generic interface is defined to be equal to the NTCREATEX interface */
1307 #define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX
1308
1309 /* union for open() backend call */
1310 union smb_open {
1311 /* 
1312  * because the *.out.file structs are not aligned to the same offset for each level
1313  * we provide a hepler macro that should be used to find the current smb_handle structure
1314  */
1315 #define SMB_OPEN_OUT_FILE(op, file) do { \
1316         switch (op->generic.level) { \
1317         case RAW_OPEN_OPEN: \
1318                 file = &op->openold.out.file; \
1319                 break; \
1320         case RAW_OPEN_OPENX: \
1321                 file = &op->openx.out.file; \
1322                 break; \
1323         case RAW_OPEN_MKNEW: \
1324                 file = &op->mknew.out.file; \
1325                 break; \
1326         case RAW_OPEN_CREATE: \
1327                 file = &op->create.out.file; \
1328                 break; \
1329         case RAW_OPEN_CTEMP: \
1330                 file = &op->ctemp.out.file; \
1331                 break; \
1332         case RAW_OPEN_SPLOPEN: \
1333                 file = &op->splopen.out.file; \
1334                 break; \
1335         case RAW_OPEN_NTCREATEX: \
1336                 file = &op->ntcreatex.out.file; \
1337                 break; \
1338         case RAW_OPEN_T2OPEN: \
1339                 file = &op->t2open.out.file; \
1340                 break; \
1341         case RAW_OPEN_NTTRANS_CREATE: \
1342                 file = &op->nttrans.out.file; \
1343                 break; \
1344         case RAW_OPEN_OPENX_READX: \
1345                 file = &op->openxreadx.out.file; \
1346                 break; \
1347         case RAW_OPEN_SMB2: \
1348                 file = &op->smb2.out.file; \
1349                 break; \
1350         default: \
1351                 /* this must be a programmer error */ \
1352                 file = NULL; \
1353                 break; \
1354         } \
1355 } while (0)
1356         /* SMBNTCreateX interface */
1357         struct {
1358                 enum smb_open_level level;
1359                 struct {
1360                         uint32_t flags;
1361                         uint32_t root_fid;
1362                         uint32_t access_mask;
1363                         uint64_t alloc_size;
1364                         uint32_t file_attr;
1365                         uint32_t share_access;
1366                         uint32_t open_disposition;
1367                         uint32_t create_options;
1368                         uint32_t impersonation;
1369                         uint8_t  security_flags;
1370                         /* NOTE: fname can also be a pointer to a
1371                          uint64_t file_id if create_options has the
1372                          NTCREATEX_OPTIONS_OPEN_BY_FILE_ID flag set */
1373                         const char *fname;
1374
1375                         /* these last 2 elements are only used in the
1376                            NTTRANS varient of the call */
1377                         struct security_descriptor *sec_desc;
1378                         struct smb_ea_list *ea_list;
1379                 } in;
1380                 struct {
1381                         union smb_handle file;
1382                         uint8_t oplock_level;
1383                         uint32_t create_action;
1384                         NTTIME create_time;
1385                         NTTIME access_time;
1386                         NTTIME write_time;
1387                         NTTIME change_time;
1388                         uint32_t attrib;
1389                         uint64_t alloc_size;
1390                         uint64_t size;
1391                         uint16_t file_type;
1392                         uint16_t ipc_state;
1393                         uint8_t  is_directory;
1394                 } out;
1395         } ntcreatex, nttrans, generic;
1396
1397         /* TRANS2_OPEN interface */
1398         struct {
1399                 enum smb_open_level level;
1400                 struct {
1401                         uint16_t flags;
1402                         uint16_t open_mode;
1403                         uint16_t search_attrs;
1404                         uint16_t file_attrs;
1405                         time_t write_time;
1406                         uint16_t open_func;
1407                         uint32_t size;
1408                         uint32_t timeout;
1409                         const char *fname;
1410                         uint_t num_eas;
1411                         struct ea_struct *eas;                  
1412                 } in;
1413                 struct {
1414                         union smb_handle file;
1415                         uint16_t attrib;
1416                         time_t write_time;
1417                         uint32_t size;
1418                         uint16_t access;
1419                         uint16_t ftype;
1420                         uint16_t devstate;
1421                         uint16_t action;
1422                         uint32_t file_id;
1423                 } out;
1424         } t2open;
1425
1426         /* SMBopen interface */
1427         struct {
1428                 enum smb_open_level level;
1429                 struct {
1430                         uint16_t open_mode;
1431                         uint16_t search_attrs;
1432                         const char *fname;
1433                 } in;
1434                 struct {
1435                         union smb_handle file;
1436                         uint16_t attrib;
1437                         time_t write_time;
1438                         uint32_t size;
1439                         uint16_t rmode;
1440                 } out;
1441         } openold;
1442
1443         /* SMBopenX interface */
1444         struct {
1445                 enum smb_open_level level;
1446                 struct {
1447                         uint16_t flags;
1448                         uint16_t open_mode;
1449                         uint16_t search_attrs; /* not honoured by win2003 */
1450                         uint16_t file_attrs;
1451                         time_t write_time; /* not honoured by win2003 */
1452                         uint16_t open_func;
1453                         uint32_t size; /* note that this sets the
1454                                         initial file size, not
1455                                         just allocation size */
1456                         uint32_t timeout; /* not honoured by win2003 */
1457                         const char *fname;
1458                 } in;
1459                 struct {
1460                         union smb_handle file;
1461                         uint16_t attrib;
1462                         time_t write_time;
1463                         uint32_t size;
1464                         uint16_t access;
1465                         uint16_t ftype;
1466                         uint16_t devstate;
1467                         uint16_t action;
1468                         uint32_t unique_fid;
1469                         uint32_t access_mask;
1470                         uint32_t unknown;
1471                 } out;
1472         } openx;
1473
1474         /* SMBmknew interface */
1475         struct {
1476                 enum smb_open_level level;
1477                 struct {
1478                         uint16_t attrib;
1479                         time_t write_time;
1480                         const char *fname;
1481                 } in;
1482                 struct {
1483                         union smb_handle file;
1484                 } out;
1485         } mknew, create;
1486
1487         /* SMBctemp interface */
1488         struct {
1489                 enum smb_open_level level;
1490                 struct {
1491                         uint16_t attrib;
1492                         time_t write_time;
1493                         const char *directory;
1494                 } in;
1495                 struct {
1496                         union smb_handle file;
1497                         /* temp name, relative to directory */
1498                         char *name; 
1499                 } out;
1500         } ctemp;
1501
1502         /* SMBsplopen interface */
1503         struct {
1504                 enum smb_open_level level;
1505                 struct {
1506                         uint16_t setup_length;
1507                         uint16_t mode;
1508                         const char *ident;
1509                 } in;
1510                 struct {
1511                         union smb_handle file;
1512                 } out;
1513         } splopen;
1514
1515
1516         /* chained OpenX/ReadX interface */
1517         struct {
1518                 enum smb_open_level level;
1519                 struct {
1520                         uint16_t flags;
1521                         uint16_t open_mode;
1522                         uint16_t search_attrs; /* not honoured by win2003 */
1523                         uint16_t file_attrs;
1524                         time_t write_time; /* not honoured by win2003 */
1525                         uint16_t open_func;
1526                         uint32_t size; /* note that this sets the
1527                                         initial file size, not
1528                                         just allocation size */
1529                         uint32_t timeout; /* not honoured by win2003 */
1530                         const char *fname;
1531
1532                         /* readx part */
1533                         uint64_t offset;
1534                         uint16_t mincnt;
1535                         uint32_t maxcnt;
1536                         uint16_t remaining;
1537                 } in;
1538                 struct {
1539                         union smb_handle file;
1540                         uint16_t attrib;
1541                         time_t write_time;
1542                         uint32_t size;
1543                         uint16_t access;
1544                         uint16_t ftype;
1545                         uint16_t devstate;
1546                         uint16_t action;
1547                         uint32_t unique_fid;
1548                         uint32_t access_mask;
1549                         uint32_t unknown;
1550                         
1551                         /* readx part */
1552                         uint8_t *data;
1553                         uint16_t remaining;
1554                         uint16_t compaction_mode;
1555                         uint16_t nread;
1556                 } out;
1557         } openxreadx;
1558
1559 #define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
1560 #define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
1561 #define SMB2_CREATE_FLAG_GRANT_OPLOCK             0x0001
1562 #define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK   0x0080
1563
1564         /* SMB2 Create */
1565         struct smb2_create {
1566                 enum smb_open_level level;
1567                 struct {
1568                         /* static body buffer 56 (0x38) bytes */
1569                         uint8_t  security_flags;      /* SMB2_SECURITY_* */
1570                         uint8_t  oplock_level;        /* SMB2_OPLOCK_LEVEL_* */
1571                         uint32_t impersonation_level; /* SMB2_IMPERSONATION_* */
1572                         uint64_t create_flags;
1573                         uint64_t reserved;
1574                         uint32_t desired_access;
1575                         uint32_t file_attributes;
1576                         uint32_t share_access; /* NTCREATEX_SHARE_ACCESS_* */
1577                         uint32_t create_disposition; /* NTCREATEX_DISP_* */
1578                         uint32_t create_options; /* NTCREATEX_OPTIONS_* */
1579
1580                         /* uint16_t fname_ofs */
1581                         /* uint16_t fname_size */
1582                         /* uint32_t blob_ofs; */
1583                         /* uint32_t blob_size; */
1584
1585                         /* dynamic body */
1586                         const char *fname;
1587
1588                         /* optional list of extended attributes */
1589                         struct smb_ea_list eas;
1590
1591                         struct smb2_create_blobs {
1592                                 uint32_t num_blobs;
1593                                 struct smb2_create_blob {
1594                                         const char *tag;
1595                                         DATA_BLOB data;
1596                                 } *blobs;
1597                         } blobs;
1598                 } in;
1599                 struct {
1600                         union smb_handle file;
1601
1602                         /* static body buffer 88 (0x58) bytes */
1603                         /* uint16_t buffer_code;  0x59 = 0x58 + 1 */
1604                         uint8_t oplock_level;
1605                         uint8_t reserved;
1606                         uint32_t create_action;
1607                         NTTIME   create_time;
1608                         NTTIME   access_time;
1609                         NTTIME   write_time;
1610                         NTTIME   change_time;
1611                         uint64_t alloc_size;
1612                         uint64_t size;
1613                         uint32_t file_attr;
1614                         uint32_t reserved2;
1615                         /* struct smb2_handle handle;*/
1616                         /* uint32_t blob_ofs; */
1617                         /* uint32_t blob_size; */
1618
1619                         /* dynamic body */
1620                         DATA_BLOB blob;
1621                 } out;
1622         } smb2;
1623 };
1624
1625
1626
1627 enum smb_read_level {
1628         RAW_READ_READBRAW,
1629         RAW_READ_LOCKREAD,
1630         RAW_READ_READ,
1631         RAW_READ_READX,
1632         RAW_READ_SMB2
1633 };
1634
1635 #define RAW_READ_GENERIC RAW_READ_READX
1636
1637 /* union for read() backend call 
1638
1639    note that .infoX.out.data will be allocated before the backend is
1640    called. It will be big enough to hold the maximum size asked for
1641 */
1642 union smb_read {
1643         /* SMBreadX (and generic) interface */
1644         struct {
1645                 enum smb_read_level level;
1646                 struct {
1647                         union smb_handle file;
1648                         uint64_t offset;
1649                         uint16_t mincnt;
1650                         uint32_t maxcnt;
1651                         uint16_t remaining;
1652                         bool read_for_execute;
1653                 } in;
1654                 struct {
1655                         uint8_t *data;
1656                         uint16_t remaining;
1657                         uint16_t compaction_mode;
1658                         uint32_t nread;
1659                 } out;
1660         } readx, generic;
1661
1662         /* SMBreadbraw interface */
1663         struct {
1664                 enum smb_read_level level;
1665                 struct {
1666                         union smb_handle file;
1667                         uint64_t offset;
1668                         uint16_t  maxcnt;
1669                         uint16_t  mincnt;
1670                         uint32_t  timeout;
1671                 } in;
1672                 struct {
1673                         uint8_t *data;
1674                         uint32_t nread;
1675                 } out;
1676         } readbraw;
1677
1678
1679         /* SMBlockandread interface */
1680         struct {
1681                 enum smb_read_level level;
1682                 struct {
1683                         union smb_handle file;
1684                         uint16_t count;
1685                         uint32_t offset;
1686                         uint16_t remaining;
1687                 } in;
1688                 struct {
1689                         uint8_t *data;
1690                         uint16_t nread;
1691                 } out;
1692         } lockread;
1693
1694         /* SMBread interface */
1695         struct {
1696                 enum smb_read_level level;
1697                 struct {
1698                         union smb_handle file;
1699                         uint16_t count;
1700                         uint32_t offset;
1701                         uint16_t remaining;
1702                 } in;
1703                 struct {
1704                         uint8_t *data;
1705                         uint16_t nread;
1706                 } out;
1707         } read;
1708
1709         /* SMB2 Read */
1710         struct smb2_read {
1711                 enum smb_read_level level;
1712                 struct {
1713                         union smb_handle file;
1714
1715                         /* static body buffer 48 (0x30) bytes */
1716                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1717                         uint8_t _pad;
1718                         uint8_t reserved;
1719                         uint32_t length;
1720                         uint64_t offset;
1721                         /* struct smb2_handle handle; */
1722                         uint32_t min_count;
1723                         uint32_t channel;
1724                         uint32_t remaining;
1725                         /* the docs give no indication of what
1726                            these channel variables are for */
1727                         uint16_t channel_offset;
1728                         uint16_t channel_length;
1729                 } in;
1730                 struct {
1731                         /* static body buffer 16 (0x10) bytes */
1732                         /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
1733                         /* uint8_t data_ofs; */
1734                         /* uint8_t reserved; */
1735                         /* uint32_t data_size; */
1736                         uint32_t remaining;
1737                         uint32_t reserved;
1738
1739                         /* dynamic body */
1740                         DATA_BLOB data;
1741                 } out;
1742         } smb2;
1743 };
1744
1745
1746 enum smb_write_level {
1747         RAW_WRITE_WRITEUNLOCK,
1748         RAW_WRITE_WRITE,
1749         RAW_WRITE_WRITEX,
1750         RAW_WRITE_WRITECLOSE,
1751         RAW_WRITE_SPLWRITE,
1752         RAW_WRITE_SMB2
1753 };
1754
1755 #define RAW_WRITE_GENERIC RAW_WRITE_WRITEX
1756
1757 /* union for write() backend call 
1758 */
1759 union smb_write {
1760         /* SMBwriteX interface */
1761         struct {
1762                 enum smb_write_level level;
1763                 struct {
1764                         union smb_handle file;
1765                         uint64_t offset;
1766                         uint16_t wmode;
1767                         uint16_t remaining;
1768                         uint32_t count;
1769                         const uint8_t *data;
1770                 } in;
1771                 struct {
1772                         uint32_t nwritten;
1773                         uint16_t remaining;
1774                 } out;
1775         } writex, generic;
1776
1777         /* SMBwriteunlock interface */
1778         struct {
1779                 enum smb_write_level level;
1780                 struct {
1781                         union smb_handle file;
1782                         uint16_t count;
1783                         uint32_t offset;
1784                         uint16_t remaining;
1785                         const uint8_t *data;
1786                 } in;
1787                 struct {
1788                         uint32_t nwritten;
1789                 } out;
1790         } writeunlock;
1791
1792         /* SMBwrite interface */
1793         struct {
1794                 enum smb_write_level level;
1795                 struct {
1796                         union smb_handle file;
1797                         uint16_t count;
1798                         uint32_t offset;
1799                         uint16_t remaining;
1800                         const uint8_t *data;
1801                 } in;
1802                 struct {
1803                         uint16_t nwritten;
1804                 } out;
1805         } write;
1806
1807         /* SMBwriteclose interface */
1808         struct {
1809                 enum smb_write_level level;
1810                 struct {
1811                         union smb_handle file;
1812                         uint16_t count;
1813                         uint32_t offset;
1814                         time_t mtime;
1815                         const uint8_t *data;
1816                 } in;
1817                 struct {
1818                         uint16_t nwritten;
1819                 } out;
1820         } writeclose;
1821
1822         /* SMBsplwrite interface */
1823         struct {
1824                 enum smb_write_level level;
1825                 struct {
1826                         union smb_handle file;
1827                         uint16_t count;
1828                         const uint8_t *data;
1829                 } in;
1830         } splwrite;
1831
1832         /* SMB2 Write */
1833         struct smb2_write {
1834                 enum smb_write_level level;
1835                 struct {
1836                         union smb_handle file;
1837
1838                         /* static body buffer 48 (0x30) bytes */
1839                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
1840                         /* uint16_t data_ofs; */
1841                         /* uint32_t data_size; */
1842                         uint64_t offset;
1843                         /* struct smb2_handle handle; */
1844                         uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */
1845                         uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */
1846
1847                         /* dynamic body */
1848                         DATA_BLOB data;
1849                 } in;
1850                 struct {
1851                         /* static body buffer 17 (0x11) bytes */
1852                         /* uint16_t buffer_code;  0x11 = 0x10 + 1*/
1853                         uint16_t _pad;
1854                         uint32_t nwritten;
1855                         uint64_t unknown1; /* 0x0000000000000000 */
1856                 } out;
1857         } smb2;
1858 };
1859
1860
1861 enum smb_lock_level {
1862         RAW_LOCK_LOCK,
1863         RAW_LOCK_UNLOCK,
1864         RAW_LOCK_LOCKX,
1865         RAW_LOCK_SMB2,
1866         RAW_LOCK_SMB2_BREAK
1867 };
1868
1869 #define RAW_LOCK_GENERIC RAW_LOCK_LOCKX
1870
1871 /* union for lock() backend call 
1872 */
1873 union smb_lock {
1874         /* SMBlockingX and generic interface */
1875         struct {
1876                 enum smb_lock_level level;
1877                 struct {
1878                         union smb_handle file;
1879                         uint16_t mode;
1880                         uint32_t timeout;
1881                         uint16_t ulock_cnt;
1882                         uint16_t lock_cnt;
1883                         struct smb_lock_entry {
1884                                 uint16_t pid;
1885                                 uint64_t offset;
1886                                 uint64_t count;
1887                         } *locks; /* unlocks are first in the arrray */
1888                 } in;
1889         } generic, lockx;
1890
1891         /* SMBlock and SMBunlock interface */
1892         struct {
1893                 enum smb_lock_level level;
1894                 struct {
1895                         union smb_handle file;
1896                         uint32_t count;
1897                         uint32_t offset;
1898                 } in;
1899         } lock, unlock;
1900
1901         /* SMB2 Lock */
1902         struct smb2_lock {
1903                 enum smb_lock_level level;
1904                 struct {
1905                         union smb_handle file;
1906
1907                         /* static body buffer 48 (0x30) bytes */
1908                         /* uint16_t buffer_code;  0x30 */
1909                         uint16_t lock_count;
1910                         uint32_t reserved;
1911                         /* struct smb2_handle handle; */
1912                         struct smb2_lock_element {
1913                                 uint64_t offset;
1914                                 uint64_t length;
1915 /* these flags are the same as the SMB2 lock flags */
1916 #define SMB2_LOCK_FLAG_NONE             0x00000000
1917 #define SMB2_LOCK_FLAG_SHARED           0x00000001
1918 #define SMB2_LOCK_FLAG_EXCLUSIVE        0x00000002
1919 #define SMB2_LOCK_FLAG_UNLOCK           0x00000004
1920 #define SMB2_LOCK_FLAG_FAIL_IMMEDIATELY 0x00000010
1921                                 uint32_t flags;
1922                                 uint32_t reserved;
1923                         } *locks;
1924                 } in;
1925                 struct {
1926                         /* static body buffer 4 (0x04) bytes */
1927                         /* uint16_t buffer_code;  0x04 */
1928                         uint16_t reserved;
1929                 } out;
1930         } smb2;
1931
1932         /* SMB2 Break */
1933         struct smb2_break {
1934                 enum smb_lock_level level;
1935                 struct {
1936                         union smb_handle file;
1937
1938                         /* static body buffer 24 (0x18) bytes */
1939                         uint8_t oplock_level;
1940                         uint8_t reserved;
1941                         uint32_t reserved2;
1942                         /* struct smb2_handle handle; */
1943                 } in, out;
1944         } smb2_break;
1945 };
1946
1947
1948 enum smb_close_level {
1949         RAW_CLOSE_CLOSE,
1950         RAW_CLOSE_SPLCLOSE,
1951         RAW_CLOSE_SMB2
1952 };
1953
1954 #define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE
1955
1956 /*
1957   union for close() backend call
1958 */
1959 union smb_close {
1960         /* SMBclose (and generic) interface */
1961         struct {
1962                 enum smb_close_level level;
1963                 struct {
1964                         union smb_handle file;
1965                         time_t write_time;
1966                 } in;
1967         } close, generic;
1968
1969         /* SMBsplclose interface - empty! */
1970         struct {
1971                 enum smb_close_level level;
1972                 struct {
1973                         union smb_handle file;
1974                 } in;
1975         } splclose;
1976
1977         /* SMB2 Close */
1978         struct smb2_close {
1979                 enum smb_close_level level;
1980                 struct {
1981                         union smb_handle file;
1982
1983                         /* static body buffer 24 (0x18) bytes */
1984                         /* uint16_t buffer_code;  0x18 */
1985 #define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
1986                         uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
1987                         uint32_t _pad;
1988                 } in;
1989                 struct {
1990                         /* static body buffer 60 (0x3C) bytes */
1991                         /* uint16_t buffer_code;  0x3C */
1992                         uint16_t flags;
1993                         uint32_t _pad;
1994                         NTTIME   create_time;
1995                         NTTIME   access_time;
1996                         NTTIME   write_time;
1997                         NTTIME   change_time;
1998                         uint64_t alloc_size;
1999                         uint64_t size;
2000                         uint32_t file_attr;
2001                 } out;
2002         } smb2;
2003 };
2004
2005
2006 enum smb_lpq_level {RAW_LPQ_GENERIC, RAW_LPQ_RETQ};
2007
2008 /*
2009   union for lpq() backend
2010 */
2011 union smb_lpq {
2012         /* generic interface */
2013         struct {
2014                 enum smb_lpq_level level;
2015
2016         } generic;
2017
2018
2019         /* SMBsplretq interface */
2020         struct {
2021                 enum smb_lpq_level level;
2022
2023                 struct {
2024                         uint16_t maxcount;
2025                         uint16_t startidx;
2026                 } in;
2027                 struct {
2028                         uint16_t count;
2029                         uint16_t restart_idx;
2030                         struct {
2031                                 time_t time;
2032                                 uint8_t status;
2033                                 uint16_t job;
2034                                 uint32_t size;
2035                                 char *user;
2036                         } *queue;
2037                 } out;
2038         } retq;
2039 };
2040
2041 enum smb_ioctl_level {
2042         RAW_IOCTL_IOCTL,
2043         RAW_IOCTL_NTIOCTL,
2044         RAW_IOCTL_SMB2,
2045         RAW_IOCTL_SMB2_NO_HANDLE
2046 };
2047
2048 /*
2049   union for ioctl() backend
2050 */
2051 union smb_ioctl {
2052         /* generic interface */
2053         struct {
2054                 enum smb_ioctl_level level;
2055                 struct {
2056                         union smb_handle file;
2057                 } in;
2058         } generic;
2059
2060         /* struct for SMBioctl */
2061         struct {
2062                 enum smb_ioctl_level level;
2063                 struct {
2064                         union smb_handle file;
2065                         uint32_t request;
2066                 } in;
2067                 struct {
2068                         DATA_BLOB blob;
2069                 } out;
2070         } ioctl;
2071
2072
2073         /* struct for NT ioctl call */
2074         struct {
2075                 enum smb_ioctl_level level;
2076                 struct {
2077                         union smb_handle file;
2078                         uint32_t function;
2079                         bool fsctl;
2080                         uint8_t filter;
2081                         uint32_t max_data;
2082                         DATA_BLOB blob;
2083                 } in;
2084                 struct {
2085                         DATA_BLOB blob;
2086                 } out;
2087         } ntioctl;
2088
2089         /* SMB2 Ioctl */
2090         struct smb2_ioctl {
2091                 enum smb_ioctl_level level;
2092                 struct {
2093                         union smb_handle file;
2094
2095                         /* static body buffer 56 (0x38) bytes */
2096                         /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
2097                         uint16_t _pad;
2098                         uint32_t function;
2099                         /*struct smb2_handle handle;*/
2100                         /* uint32_t out_ofs; */
2101                         /* uint32_t out_size; */
2102                         uint32_t unknown2;
2103                         /* uint32_t in_ofs; */
2104                         /* uint32_t in_size; */
2105                         uint32_t max_response_size;
2106                         uint64_t flags;
2107
2108                         /* dynamic body */
2109                         DATA_BLOB out;
2110                         DATA_BLOB in;
2111                 } in;
2112                 struct {
2113                         union smb_handle file;
2114
2115                         /* static body buffer 48 (0x30) bytes */
2116                         /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
2117                         uint16_t _pad;
2118                         uint32_t function;
2119                         /* struct smb2_handle handle; */
2120                         /* uint32_t in_ofs; */
2121                         /* uint32_t in_size; */
2122                         /* uint32_t out_ofs; */
2123                         /* uint32_t out_size; */
2124                         uint32_t unknown2;
2125                         uint32_t unknown3;
2126
2127                         /* dynamic body */
2128                         DATA_BLOB in;
2129                         DATA_BLOB out;
2130                 } out;
2131         } smb2;
2132 };
2133
2134 enum smb_flush_level {
2135         RAW_FLUSH_FLUSH,
2136         RAW_FLUSH_ALL,
2137         RAW_FLUSH_SMB2
2138 };
2139
2140 union smb_flush {
2141         /* struct for SMBflush */
2142         struct {
2143                 enum smb_flush_level level;
2144                 struct {
2145                         union smb_handle file;
2146                 } in;
2147         } flush, generic;
2148
2149         /* SMBflush with 0xFFFF wildcard fnum */
2150         struct {
2151                 enum smb_flush_level level;
2152         } flush_all;
2153
2154         /* SMB2 Flush */
2155         struct smb2_flush {
2156                 enum smb_flush_level level;
2157                 struct {
2158                         union smb_handle file;
2159                         uint16_t reserved1;
2160                         uint32_t reserved2;
2161                 } in;
2162                 struct {
2163                         uint16_t reserved;
2164                 } out;
2165         } smb2;
2166 };
2167
2168 /* struct for SMBcopy */
2169 struct smb_copy {
2170         struct {
2171                 uint16_t tid2;
2172                 uint16_t ofun;
2173                 uint16_t flags;
2174                 const char *path1;
2175                 const char *path2;
2176         } in;
2177         struct {
2178                 uint16_t count;
2179         } out;
2180 };
2181
2182
2183 /* struct for transact/transact2 call */
2184 struct smb_trans2 {
2185         struct {
2186                 uint16_t max_param;
2187                 uint16_t max_data;
2188                 uint8_t  max_setup;
2189                 uint16_t flags;
2190                 uint32_t timeout;
2191                 uint8_t  setup_count;
2192                 uint16_t *setup;
2193                 const char *trans_name; /* SMBtrans only */
2194                 DATA_BLOB params;
2195                 DATA_BLOB data;
2196         } in;
2197
2198         struct {
2199                 uint8_t  setup_count;
2200                 uint16_t *setup;
2201                 DATA_BLOB params;
2202                 DATA_BLOB data;
2203         } out;
2204 };
2205
2206 /* struct for nttransact2 call */
2207 struct smb_nttrans {
2208         struct {
2209                 uint8_t  max_setup;
2210                 uint32_t max_param;
2211                 uint32_t max_data;
2212                 uint32_t setup_count;
2213                 uint16_t function;
2214                 uint8_t  *setup;
2215                 DATA_BLOB params;
2216                 DATA_BLOB data;
2217         } in;
2218
2219         struct {
2220                 uint8_t  setup_count; /* in units of 16 bit words */
2221                 uint8_t  *setup;
2222                 DATA_BLOB params;
2223                 DATA_BLOB data;
2224         } out;
2225 };
2226
2227 enum smb_notify_level {
2228         RAW_NOTIFY_NTTRANS,
2229         RAW_NOTIFY_SMB2
2230 };
2231
2232 union smb_notify {
2233         /* struct for nttrans change notify call */
2234         struct {
2235                 enum smb_notify_level level;
2236
2237                 struct {
2238                         union smb_handle file;
2239                         uint32_t buffer_size;
2240                         uint32_t completion_filter;
2241                         bool recursive;
2242                 } in;
2243
2244                 struct {
2245                         uint32_t num_changes;
2246                         struct notify_changes {
2247                                 uint32_t action;
2248                                 struct smb_wire_string name;
2249                         } *changes;
2250                 } out;
2251         } nttrans;
2252
2253         struct smb2_notify {
2254                 enum smb_notify_level level;
2255                 
2256                 struct {
2257                         union smb_handle file;
2258                         /* static body buffer 32 (0x20) bytes */
2259                         /* uint16_t buffer_code;  0x32 */
2260                         uint16_t recursive;
2261                         uint32_t buffer_size;
2262                         /*struct  smb2_handle file;*/
2263                         uint32_t completion_filter;
2264                         uint32_t unknown;
2265                 } in;
2266
2267                 struct {
2268                         /* static body buffer 8 (0x08) bytes */
2269                         /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
2270                         /* uint16_t blob_ofs; */
2271                         /* uint16_t blob_size; */
2272
2273                         /* dynamic body */
2274                         /*DATA_BLOB blob;*/
2275
2276                         /* DATA_BLOB content */
2277                         uint32_t num_changes;
2278                         struct notify_changes *changes;
2279                 } out;
2280         } smb2;
2281 };
2282
2283 enum smb_search_level {
2284         RAW_SEARCH_SEARCH,      /* SMBsearch */ 
2285         RAW_SEARCH_FFIRST,      /* SMBffirst */ 
2286         RAW_SEARCH_FUNIQUE,     /* SMBfunique */
2287         RAW_SEARCH_TRANS2,      /* SMBtrans2 */
2288         RAW_SEARCH_SMB2         /* SMB2 Find */
2289 };
2290
2291 enum smb_search_data_level {
2292         RAW_SEARCH_DATA_GENERIC                 = 0x10000, /* only used in the smbcli_ code */
2293         RAW_SEARCH_DATA_SEARCH,
2294         RAW_SEARCH_DATA_STANDARD                = SMB_FIND_STANDARD,
2295         RAW_SEARCH_DATA_EA_SIZE                 = SMB_FIND_EA_SIZE,
2296         RAW_SEARCH_DATA_EA_LIST                 = SMB_FIND_EA_LIST,
2297         RAW_SEARCH_DATA_DIRECTORY_INFO          = SMB_FIND_DIRECTORY_INFO,
2298         RAW_SEARCH_DATA_FULL_DIRECTORY_INFO     = SMB_FIND_FULL_DIRECTORY_INFO,
2299         RAW_SEARCH_DATA_NAME_INFO               = SMB_FIND_NAME_INFO,
2300         RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO     = SMB_FIND_BOTH_DIRECTORY_INFO,
2301         RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO  = SMB_FIND_ID_FULL_DIRECTORY_INFO,
2302         RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO  = SMB_FIND_ID_BOTH_DIRECTORY_INFO,
2303         RAW_SEARCH_DATA_UNIX_INFO               = SMB_FIND_UNIX_INFO,
2304         RAW_SEARCH_DATA_UNIX_INFO2              = SMB_FIND_UNIX_INFO2
2305 };
2306         
2307 /* union for file search */
2308 union smb_search_first {
2309         struct {
2310                 enum smb_search_level level;
2311                 enum smb_search_data_level data_level;
2312         } generic;
2313         
2314         /* search (old) findfirst interface. 
2315            Also used for ffirst and funique. */
2316         struct {
2317                 enum smb_search_level level;
2318                 enum smb_search_data_level data_level;
2319         
2320                 struct {
2321                         uint16_t max_count;
2322                         uint16_t search_attrib;
2323                         const char *pattern;
2324                 } in;
2325                 struct {
2326                         int16_t count;
2327                 } out;
2328         } search_first;
2329
2330         /* trans2 findfirst interface */
2331         struct {
2332                 enum smb_search_level level;
2333                 enum smb_search_data_level data_level;
2334                 
2335                 struct {
2336                         uint16_t search_attrib;
2337                         uint16_t max_count;
2338                         uint16_t flags;
2339                         uint32_t storage_type;
2340                         const char *pattern;
2341
2342                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2343                         uint_t num_names;
2344                         struct ea_name *ea_names;
2345                 } in;
2346                 struct {
2347                         uint16_t handle;
2348                         uint16_t count;
2349                         uint16_t end_of_search;
2350                 } out;
2351         } t2ffirst;
2352
2353 /*
2354   SMB2 uses different level numbers for the same old SMB trans2 search levels
2355 */
2356 #define SMB2_FIND_DIRECTORY_INFO         0x01
2357 #define SMB2_FIND_FULL_DIRECTORY_INFO    0x02
2358 #define SMB2_FIND_BOTH_DIRECTORY_INFO    0x03
2359 #define SMB2_FIND_NAME_INFO              0x0C
2360 #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25
2361 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26
2362
2363 /* flags for SMB2 find */
2364 #define SMB2_CONTINUE_FLAG_RESTART    0x01
2365 #define SMB2_CONTINUE_FLAG_SINGLE     0x02
2366 #define SMB2_CONTINUE_FLAG_INDEX      0x04
2367 #define SMB2_CONTINUE_FLAG_REOPEN     0x10
2368
2369         /* SMB2 Find */
2370         struct smb2_find {
2371                 enum smb_search_level level;
2372                 enum smb_search_data_level data_level;
2373                 struct {
2374                         union smb_handle file;
2375
2376                         /* static body buffer 32 (0x20) bytes */
2377                         /* uint16_t buffer_code;  0x21 = 0x20 + 1 */
2378                         uint8_t level;
2379                         uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */
2380                         uint32_t file_index; 
2381                         /* struct smb2_handle handle; */
2382                         /* uint16_t pattern_ofs; */
2383                         /* uint16_t pattern_size; */
2384                         uint32_t max_response_size;
2385         
2386                         /* dynamic body */
2387                         const char *pattern;
2388                 } in;
2389                 struct {
2390                         /* static body buffer 8 (0x08) bytes */
2391                         /* uint16_t buffer_code;  0x08 */
2392                         /* uint16_t blob_ofs; */
2393                         /* uint32_t blob_size; */
2394
2395                         /* dynamic body */
2396                         DATA_BLOB blob;
2397                 } out;
2398         } smb2;
2399 };
2400
2401 /* union for file search continue */
2402 union smb_search_next {
2403         struct {
2404                 enum smb_search_level level;
2405                 enum smb_search_data_level data_level;
2406         } generic;
2407
2408         /* search (old) findnext interface. Also used
2409            for ffirst when continuing */
2410         struct {
2411                 enum smb_search_level level;
2412                 enum smb_search_data_level data_level;
2413         
2414                 struct {
2415                         uint16_t max_count;
2416                         uint16_t search_attrib;
2417                         struct smb_search_id {
2418                                 uint8_t reserved;
2419                                 char name[11];
2420                                 uint8_t handle;
2421                                 uint32_t server_cookie;
2422                                 uint32_t client_cookie;
2423                         } id;
2424                 } in;
2425                 struct {
2426                         uint16_t count;
2427                 } out;
2428         } search_next;
2429         
2430         /* trans2 findnext interface */
2431         struct {
2432                 enum smb_search_level level;
2433                 enum smb_search_data_level data_level;
2434                 
2435                 struct {
2436                         uint16_t handle;
2437                         uint16_t max_count;
2438                         uint32_t resume_key;
2439                         uint16_t flags;
2440                         const char *last_name;
2441
2442                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
2443                         uint_t num_names;
2444                         struct ea_name *ea_names;
2445                 } in;
2446                 struct {
2447                         uint16_t count;
2448                         uint16_t end_of_search;
2449                 } out;
2450         } t2fnext;
2451
2452         /* SMB2 Find */
2453         struct smb2_find smb2;
2454 };
2455
2456 /* union for search reply file data */
2457 union smb_search_data {
2458         /*
2459          * search (old) findfirst 
2460          * RAW_SEARCH_DATA_SEARCH
2461          */
2462         struct {
2463                 uint16_t attrib;
2464                 time_t write_time;
2465                 uint32_t size;
2466                 struct smb_search_id id;
2467                 const char *name;
2468         } search;
2469
2470         /* trans2 findfirst RAW_SEARCH_DATA_STANDARD level */
2471         struct {
2472                 uint32_t resume_key;
2473                 time_t create_time;
2474                 time_t access_time;
2475                 time_t write_time;
2476                 uint32_t size;
2477                 uint32_t alloc_size;
2478                 uint16_t attrib;
2479                 struct smb_wire_string name;
2480         } standard;
2481
2482         /* trans2 findfirst RAW_SEARCH_DATA_EA_SIZE level */
2483         struct {
2484                 uint32_t resume_key;
2485                 time_t create_time;
2486                 time_t access_time;
2487                 time_t write_time;
2488                 uint32_t size;
2489                 uint32_t alloc_size;
2490                 uint16_t attrib;
2491                 uint32_t ea_size;
2492                 struct smb_wire_string name;
2493         } ea_size;
2494
2495         /* trans2 findfirst RAW_SEARCH_DATA_EA_LIST level */
2496         struct {
2497                 uint32_t resume_key;
2498                 time_t create_time;
2499                 time_t access_time;
2500                 time_t write_time;
2501                 uint32_t size;
2502                 uint32_t alloc_size;
2503                 uint16_t attrib;
2504                 struct smb_ea_list eas;
2505                 struct smb_wire_string name;
2506         } ea_list;
2507
2508         /* RAW_SEARCH_DATA_DIRECTORY_INFO interface */
2509         struct {
2510                 uint32_t file_index;
2511                 NTTIME create_time;
2512                 NTTIME access_time;
2513                 NTTIME write_time;
2514                 NTTIME change_time;
2515                 uint64_t  size;
2516                 uint64_t  alloc_size;
2517                 uint32_t   attrib;
2518                 struct smb_wire_string name;
2519         } directory_info;
2520
2521         /* RAW_SEARCH_DATA_FULL_DIRECTORY_INFO interface */
2522         struct {
2523                 uint32_t file_index;
2524                 NTTIME create_time;
2525                 NTTIME access_time;
2526                 NTTIME write_time;
2527                 NTTIME change_time;
2528                 uint64_t  size;
2529                 uint64_t  alloc_size;
2530                 uint32_t   attrib;
2531                 uint32_t   ea_size;
2532                 struct smb_wire_string name;
2533         } full_directory_info;
2534
2535         /* RAW_SEARCH_DATA_NAME_INFO interface */
2536         struct {
2537                 uint32_t file_index;
2538                 struct smb_wire_string name;
2539         } name_info;
2540
2541         /* RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO interface */
2542         struct {
2543                 uint32_t file_index;
2544                 NTTIME create_time;
2545                 NTTIME access_time;
2546                 NTTIME write_time;
2547                 NTTIME change_time;
2548                 uint64_t  size;
2549                 uint64_t  alloc_size;
2550                 uint32_t   attrib;
2551                 uint32_t   ea_size;
2552                 struct smb_wire_string short_name;
2553                 struct smb_wire_string name;
2554         } both_directory_info;
2555
2556         /* RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO interface */
2557         struct {
2558                 uint32_t file_index;
2559                 NTTIME create_time;
2560                 NTTIME access_time;
2561                 NTTIME write_time;
2562                 NTTIME change_time;
2563                 uint64_t size;
2564                 uint64_t alloc_size;
2565                 uint32_t attrib;
2566                 uint32_t ea_size;
2567                 uint64_t file_id;
2568                 struct smb_wire_string name;
2569         } id_full_directory_info;
2570
2571         /* RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO interface */
2572         struct {
2573                 uint32_t file_index;
2574                 NTTIME create_time;
2575                 NTTIME access_time;
2576                 NTTIME write_time;
2577                 NTTIME change_time;
2578                 uint64_t size;
2579                 uint64_t alloc_size;
2580                 uint32_t  attrib;
2581                 uint32_t  ea_size;
2582                 uint64_t file_id;
2583                 struct smb_wire_string short_name;
2584                 struct smb_wire_string name;
2585         } id_both_directory_info;
2586
2587         /* RAW_SEARCH_DATA_UNIX_INFO interface */
2588         struct {
2589                 uint32_t file_index;
2590                 uint64_t size;
2591                 uint64_t alloc_size;
2592                 NTTIME status_change_time;
2593                 NTTIME access_time;
2594                 NTTIME change_time;
2595                 uint64_t uid;
2596                 uint64_t gid;
2597                 uint32_t file_type;
2598                 uint64_t dev_major;
2599                 uint64_t dev_minor;
2600                 uint64_t unique_id;
2601                 uint64_t permissions;
2602                 uint64_t nlink;         
2603                 const char *name;
2604         } unix_info;
2605
2606         /* RAW_SEARCH_DATA_UNIX_INFO2 interface */
2607         struct {
2608                 uint32_t file_index;
2609                 uint64_t end_of_file;
2610                 uint64_t num_bytes;
2611                 NTTIME status_change_time;
2612                 NTTIME access_time;
2613                 NTTIME change_time;
2614                 uint64_t uid;
2615                 uint64_t gid;
2616                 uint32_t file_type;
2617                 uint64_t dev_major;
2618                 uint64_t dev_minor;
2619                 uint64_t unique_id;
2620                 uint64_t permissions;
2621                 uint64_t nlink;
2622                 NTTIME create_time;
2623                 uint32_t file_flags;
2624                 uint32_t flags_mask;
2625                 struct smb_wire_string name;
2626         } unix_info2;
2627 };
2628
2629 /* Callback function passed to the raw search interface. */
2630 typedef bool (*smbcli_search_callback)(void *private, const union smb_search_data *file);
2631
2632 enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE};
2633
2634 /* union for file search close */
2635 union smb_search_close {
2636         struct {
2637                 enum smb_search_close_level level;
2638         } generic;
2639
2640         /* SMBfclose (old search) interface */
2641         struct {
2642                 enum smb_search_close_level level;
2643         
2644                 struct {
2645                         /* max_count and search_attrib are not used, but are present */
2646                         uint16_t max_count;
2647                         uint16_t search_attrib;
2648                         struct smb_search_id id;
2649                 } in;
2650         } fclose;
2651         
2652         /* SMBfindclose interface */
2653         struct {
2654                 enum smb_search_close_level level;
2655                 
2656                 struct {
2657                         uint16_t handle;
2658                 } in;
2659         } findclose;
2660 };
2661
2662
2663 /*
2664   struct for SMBecho call
2665 */
2666 struct smb_echo {
2667         struct {
2668                 uint16_t repeat_count;
2669                 uint16_t size;
2670                 uint8_t *data;
2671         } in;
2672         struct {
2673                 uint16_t count;
2674                 uint16_t sequence_number;
2675                 uint16_t size;
2676                 uint8_t *data;
2677         } out;
2678 };
2679
2680 /*
2681   struct for shadow copy volumes
2682  */
2683 struct smb_shadow_copy {
2684         struct {
2685                 union smb_handle file;
2686                 uint32_t max_data;
2687         } in;
2688         struct {
2689                 uint32_t num_volumes;
2690                 uint32_t num_names;
2691                 const char **names;
2692         } out;
2693 };
2694
2695 #endif /* __LIBCLI_RAW_INTERFACES_H__ */