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