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