r13654: Move some more stuff out of include/
[ira/wip.git] / source4 / libcli / raw / interfaces.h
1 /* 
2    Unix SMB/CIFS implementation.
3    SMB request interface structures
4    Copyright (C) Andrew Tridgell                        2003
5    Copyright (C) James J Myers 2003 <myersjj@samba.org>
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22
23
24 /* this structure is just a wrapper for a string, the only reason we
25    bother with this is that it allows us to check the length provided
26    on the wire in testsuite test code to ensure that we are
27    terminating names in the same way that win2003 is. The *ONLY* time
28    you should ever look at the 'private_length' field in this
29    structure is inside compliance test code, in all other cases just
30    use the null terminated char* as the definitive definition of the
31    string
32
33    also note that this structure is only used in packets where there
34    is an explicit length provided on the wire (hence the name). That
35    length is placed in 'private_length'. For packets where the length
36    is always determined by NULL or packet termination a normal char*
37    is used in the structure definition.
38  */
39 typedef struct {
40         uint32_t private_length;
41         const char *s;
42 } WIRE_STRING;
43
44
45 /* 
46    use the same structure for dom_sid2 as dom_sid. A dom_sid2 is really
47    just a dom sid, but with the sub_auths represented as a conformant
48    array. As with all in-structure conformant arrays, the array length
49    is placed before the start of the structure. That's what gives rise
50    to the extra num_auths elemenent. We don't want the Samba code to
51    have to bother with such esoteric NDR details, so its easier to just
52    define it as a dom_sid and use pidl magic to make it all work. It
53    just means you need to mark a sid as a "dom_sid2" in the IDL when you
54    know it is of the conformant array variety
55 */
56 #define dom_sid2 dom_sid
57
58 /* same struct as dom_sid but inside a 28 bytes fixed buffer in NDR */
59 #define dom_sid28 dom_sid
60
61
62 /*
63   this header defines the structures and unions used between the SMB
64   parser and the backends.
65 */
66
67 /* struct used for SMBlseek call */
68 struct smb_seek {
69         struct {
70                 uint16_t fnum;
71                 uint16_t mode;
72                 int32_t  offset; /* signed */
73         } in;
74         struct {
75                 int32_t offset;
76         } out;
77 };
78
79
80 /* struct used in unlink() call */
81 struct smb_unlink {
82         struct {
83                 const char *pattern;
84                 uint16_t attrib;
85         } in;
86 };
87
88
89 /* struct used in chkpath() call */
90 struct smb_chkpath {
91         struct {
92                 const char *path;
93         } in;
94 };
95
96 enum smb_mkdir_level {RAW_MKDIR_GENERIC, RAW_MKDIR_MKDIR, RAW_MKDIR_T2MKDIR};
97
98 /* union used in mkdir() call */
99 union smb_mkdir {
100         /* generic level */
101         struct {
102                 enum smb_mkdir_level level;
103         } generic;
104
105         struct {
106                 enum smb_mkdir_level level;
107                 struct {
108                         const char *path;
109                 } in;
110         } mkdir;
111
112         struct {
113                 enum smb_mkdir_level level;
114                 struct {
115                         const char *path;
116                         uint_t num_eas;
117                         struct ea_struct *eas;                  
118                 } in;
119         } t2mkdir;
120 };
121
122 /* struct used in rmdir() call */
123 struct smb_rmdir {
124         struct {
125                 const char *path;
126         } in;
127 };
128
129 /* struct used in rename() call */
130 enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME};
131
132 union smb_rename {
133         struct {
134                 enum smb_rename_level level;
135         } generic;
136
137         /* SMBrename interface */
138         struct {
139                 enum smb_rename_level level;
140
141                 struct {
142                         const char *pattern1;
143                         const char *pattern2;
144                         uint16_t attrib;
145                 } in;
146         } rename;
147
148
149         /* SMBntrename interface */
150         struct {
151                 enum smb_rename_level level;
152
153                 struct {
154                         uint16_t attrib;
155                         uint16_t flags; /* see RENAME_FLAG_* */
156                         uint32_t cluster_size;
157                         const char *old_name;
158                         const char *new_name;
159                 } in;
160         } ntrename;
161 };
162
163 enum smb_tcon_level {RAW_TCON_TCON, RAW_TCON_TCONX};
164
165 /* union used in tree connect call */
166 union smb_tcon {
167         /* generic interface */
168         struct {
169                 enum smb_tcon_level level;
170         } generic;
171
172         /* SMBtcon interface */
173         struct {
174                 enum smb_tcon_level level;
175
176                 struct {
177                         const char *service;
178                         const char *password;
179                         const char *dev;
180                 } in;
181                 struct {
182                         uint16_t max_xmit;
183                         uint16_t tid;
184                 } out;
185         } tcon;
186
187         /* SMBtconX interface */
188         struct {
189                 enum smb_tcon_level level;
190
191                 struct {
192                         uint16_t flags;
193                         DATA_BLOB password;
194                         const char *path;
195                         const char *device;
196                 } in;
197                 struct {
198                         uint16_t options;
199                         char *dev_type;
200                         char *fs_type;
201                         uint16_t tid;
202                 } out;
203         } tconx;
204 };
205
206
207 enum smb_sesssetup_level {RAW_SESSSETUP_OLD, RAW_SESSSETUP_NT1, RAW_SESSSETUP_SPNEGO};
208
209 /* union used in session_setup call */
210 union smb_sesssetup {
211         /* the pre-NT1 interface */
212         struct {
213                 enum smb_sesssetup_level level;
214
215                 struct {
216                         uint16_t bufsize;
217                         uint16_t mpx_max;
218                         uint16_t vc_num;
219                         uint32_t sesskey;
220                         DATA_BLOB password;
221                         const char *user;
222                         const char *domain;
223                         const char *os;
224                         const char *lanman;
225                 } in;
226                 struct {
227                         uint16_t action;
228                         uint16_t vuid;
229                         char *os;
230                         char *lanman;
231                         char *domain;
232                 } out;
233         } old;
234
235         /* the NT1 interface */
236         struct {
237                 enum smb_sesssetup_level level;
238
239                 struct {
240                         uint16_t bufsize;
241                         uint16_t mpx_max;
242                         uint16_t vc_num;
243                         uint32_t sesskey;
244                         uint32_t capabilities;
245                         DATA_BLOB password1;
246                         DATA_BLOB password2;
247                         const char *user;
248                         const char *domain;
249                         const char *os;
250                         const char *lanman;
251                 } in;
252                 struct {
253                         uint16_t action;
254                         uint16_t vuid;
255                         char *os;
256                         char *lanman;
257                         char *domain;
258                 } out;
259         } nt1;
260
261
262         /* the SPNEGO interface */
263         struct {
264                 enum smb_sesssetup_level level;
265
266                 struct {
267                         uint16_t bufsize;
268                         uint16_t mpx_max;
269                         uint16_t vc_num;
270                         uint32_t sesskey;
271                         uint32_t capabilities;
272                         DATA_BLOB secblob;
273                         const char *os;
274                         const char *lanman;
275                         const char *workgroup;
276                 } in;
277                 struct {
278                         uint16_t action;
279                         DATA_BLOB secblob;
280                         char *os;
281                         char *lanman;
282                         char *workgroup;
283                         uint16_t vuid;
284                 } out;
285         } spnego;
286 };
287
288 /* Note that the specified enum values are identical to the actual info-levels used
289  * on the wire.
290  */
291 enum smb_fileinfo_level {
292                      RAW_FILEINFO_GENERIC                    = 0xF000, 
293                      RAW_FILEINFO_GETATTR,                   /* SMBgetatr */
294                      RAW_FILEINFO_GETATTRE,                  /* SMBgetattrE */
295                      RAW_FILEINFO_SEC_DESC,                  /* NT_TRANSACT_QUERY_SECURITY_DESC */
296                      RAW_FILEINFO_STANDARD                   = SMB_QFILEINFO_STANDARD,
297                      RAW_FILEINFO_EA_SIZE                    = SMB_QFILEINFO_EA_SIZE,
298                      RAW_FILEINFO_EA_LIST                    = SMB_QFILEINFO_EA_LIST,
299                      RAW_FILEINFO_ALL_EAS                    = SMB_QFILEINFO_ALL_EAS,
300                      RAW_FILEINFO_IS_NAME_VALID              = SMB_QFILEINFO_IS_NAME_VALID,
301                      RAW_FILEINFO_BASIC_INFO                 = SMB_QFILEINFO_BASIC_INFO, 
302                      RAW_FILEINFO_STANDARD_INFO              = SMB_QFILEINFO_STANDARD_INFO,
303                      RAW_FILEINFO_EA_INFO                    = SMB_QFILEINFO_EA_INFO,
304                      RAW_FILEINFO_NAME_INFO                  = SMB_QFILEINFO_NAME_INFO, 
305                      RAW_FILEINFO_ALL_INFO                   = SMB_QFILEINFO_ALL_INFO,
306                      RAW_FILEINFO_ALT_NAME_INFO              = SMB_QFILEINFO_ALT_NAME_INFO,
307                      RAW_FILEINFO_STREAM_INFO                = SMB_QFILEINFO_STREAM_INFO,
308                      RAW_FILEINFO_COMPRESSION_INFO           = SMB_QFILEINFO_COMPRESSION_INFO,
309                      RAW_FILEINFO_UNIX_BASIC                 = SMB_QFILEINFO_UNIX_BASIC,
310                      RAW_FILEINFO_UNIX_LINK                  = SMB_QFILEINFO_UNIX_LINK,
311                      RAW_FILEINFO_BASIC_INFORMATION          = SMB_QFILEINFO_BASIC_INFORMATION,
312                      RAW_FILEINFO_STANDARD_INFORMATION       = SMB_QFILEINFO_STANDARD_INFORMATION,
313                      RAW_FILEINFO_INTERNAL_INFORMATION       = SMB_QFILEINFO_INTERNAL_INFORMATION,
314                      RAW_FILEINFO_EA_INFORMATION             = SMB_QFILEINFO_EA_INFORMATION,
315                      RAW_FILEINFO_ACCESS_INFORMATION         = SMB_QFILEINFO_ACCESS_INFORMATION,
316                      RAW_FILEINFO_NAME_INFORMATION           = SMB_QFILEINFO_NAME_INFORMATION,
317                      RAW_FILEINFO_POSITION_INFORMATION       = SMB_QFILEINFO_POSITION_INFORMATION,
318                      RAW_FILEINFO_MODE_INFORMATION           = SMB_QFILEINFO_MODE_INFORMATION,
319                      RAW_FILEINFO_ALIGNMENT_INFORMATION      = SMB_QFILEINFO_ALIGNMENT_INFORMATION,
320                      RAW_FILEINFO_ALL_INFORMATION            = SMB_QFILEINFO_ALL_INFORMATION,
321                      RAW_FILEINFO_ALT_NAME_INFORMATION       = SMB_QFILEINFO_ALT_NAME_INFORMATION,
322                      RAW_FILEINFO_STREAM_INFORMATION         = SMB_QFILEINFO_STREAM_INFORMATION,
323                      RAW_FILEINFO_COMPRESSION_INFORMATION    = SMB_QFILEINFO_COMPRESSION_INFORMATION,
324                      RAW_FILEINFO_NETWORK_OPEN_INFORMATION   = SMB_QFILEINFO_NETWORK_OPEN_INFORMATION,
325                      RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION  = SMB_QFILEINFO_ATTRIBUTE_TAG_INFORMATION,
326                      /* SMB2 specific levels */
327                      RAW_FILEINFO_SMB2_ALL_EAS               = 0x0f01,
328                      RAW_FILEINFO_SMB2_ALL_INFORMATION       = 0x1201
329 };
330
331 /*
332   file handles in SMB2 are 16 bytes
333 */
334 struct smb2_handle {
335         uint64_t data[2];
336 };
337
338
339 /* union used in qfileinfo() and qpathinfo() backend calls */
340 union smb_fileinfo {
341         /* generic interface:
342          * matches RAW_FILEINFO_GENERIC */
343         struct {
344                 enum smb_fileinfo_level level;
345
346                 /* each level can be called on either a pathname or a
347                    filename, in either case the return format is
348                    identical 
349                    On SMB2 a 16 byte handle is used 
350                 */
351                 union smb_fileinfo_in {
352                         const char *fname;
353                         uint16_t fnum;
354                         struct smb2_handle handle;
355                 } in;
356                 
357                 struct {
358                         uint32_t attrib;
359                         uint32_t ea_size;
360                         uint_t num_eas;
361                         struct ea_struct {
362                                 uint8_t flags;
363                                 WIRE_STRING name;
364                                 DATA_BLOB value;
365                         } *eas;         
366                         NTTIME create_time;
367                         NTTIME access_time;
368                         NTTIME write_time;
369                         NTTIME change_time;
370                         uint64_t alloc_size;
371                         uint64_t size;
372                         uint32_t nlink;
373                         WIRE_STRING fname;      
374                         WIRE_STRING alt_fname;  
375                         uint8_t delete_pending;
376                         uint8_t directory;
377                         uint64_t compressed_size;
378                         uint16_t format;
379                         uint8_t unit_shift;
380                         uint8_t chunk_shift;
381                         uint8_t cluster_shift;
382                         uint64_t file_id;
383                         uint32_t access_flags; /* seen 0x001f01ff from w2k3 */
384                         uint64_t position;
385                         uint32_t mode;
386                         uint32_t alignment_requirement;
387                         uint32_t reparse_tag;
388                         uint_t num_streams;
389                         struct stream_struct {
390                                 uint64_t size;
391                                 uint64_t alloc_size;
392                                 WIRE_STRING stream_name;
393                         } *streams;
394                 } out;
395         } generic;
396
397
398         /* SMBgetatr interface:
399          * matches RAW_FILEINFO_GETATTR */
400         struct {
401                 enum smb_fileinfo_level level;
402                 union smb_fileinfo_in in;
403
404                 struct {
405                         uint16_t attrib;
406                         uint32_t size;
407                         time_t write_time;
408                 } out;
409         } getattr;
410
411         /* SMBgetattrE and  RAW_FILEINFO_STANDARD interface */
412         struct {
413                 enum smb_fileinfo_level level;
414                 union smb_fileinfo_in in;
415
416                 struct {
417                         time_t create_time;
418                         time_t access_time;
419                         time_t write_time;
420                         uint32_t size;
421                         uint32_t alloc_size;
422                         uint16_t attrib;
423                 } out;
424         } getattre, standard;
425
426         /* trans2 RAW_FILEINFO_EA_SIZE interface */
427         struct {
428                 enum smb_fileinfo_level level;
429                 union smb_fileinfo_in in;
430
431                 struct {
432                         time_t create_time;
433                         time_t access_time;
434                         time_t write_time;
435                         uint32_t size;
436                         uint32_t alloc_size;
437                         uint16_t attrib;
438                         uint32_t ea_size;
439                 } out;
440         } ea_size;
441
442         /* trans2 RAW_FILEINFO_EA_LIST interface */
443         struct {
444                 enum smb_fileinfo_level level;
445                 union smb_fileinfo_in file;
446
447                 struct {
448                         uint_t num_names;
449                         struct ea_name {
450                                 WIRE_STRING name;
451                         } *ea_names;    
452                 } in;   
453
454                 struct smb_ea_list {
455                         uint_t num_eas;
456                         struct ea_struct *eas;
457                 } out;
458         } ea_list;
459
460         /* trans2 RAW_FILEINFO_ALL_EAS and RAW_FILEINFO_FULL_EA_INFORMATION interfaces */
461         struct {
462                 enum smb_fileinfo_level level;
463                 union smb_fileinfo_in in;
464                 uint8_t continue_flags; /* SMB2 only - SMB2_CONTINUE_FLAG_* */
465
466                 struct smb_ea_list out;
467         } all_eas;
468
469         /* trans2 qpathinfo RAW_FILEINFO_IS_NAME_VALID interface 
470            only valid for a QPATHNAME call - no returned data */
471         struct {
472                 enum smb_fileinfo_level level;
473                 union smb_fileinfo_in in;
474         } is_name_valid;
475
476         /* RAW_FILEINFO_BASIC_INFO and RAW_FILEINFO_BASIC_INFORMATION interfaces */
477         struct {
478                 enum smb_fileinfo_level level;
479                 union smb_fileinfo_in in;
480
481                 struct {
482                         NTTIME create_time;
483                         NTTIME access_time;
484                         NTTIME write_time;
485                         NTTIME change_time;
486                         uint32_t attrib;
487                 } out;
488         } basic_info;
489                 
490
491         /* RAW_FILEINFO_STANDARD_INFO and RAW_FILEINFO_STANDARD_INFORMATION interfaces */
492         struct {
493                 enum smb_fileinfo_level level;
494                 union smb_fileinfo_in in;
495
496                 struct {
497                         uint64_t alloc_size;
498                         uint64_t size;
499                         uint32_t nlink;
500                         BOOL delete_pending;
501                         BOOL directory;
502                 } out;
503         } standard_info;
504         
505         /* RAW_FILEINFO_EA_INFO and RAW_FILEINFO_EA_INFORMATION interfaces */
506         struct {
507                 enum smb_fileinfo_level level;
508                 union smb_fileinfo_in in;
509
510                 struct {
511                         uint32_t ea_size;
512                 } out;
513         } ea_info;
514
515         /* RAW_FILEINFO_NAME_INFO and RAW_FILEINFO_NAME_INFORMATION interfaces */
516         struct {
517                 enum smb_fileinfo_level level;
518                 union smb_fileinfo_in in;
519
520                 struct {
521                         WIRE_STRING fname;
522                 } out;
523         } name_info;
524
525         /* RAW_FILEINFO_ALL_INFO and RAW_FILEINFO_ALL_INFORMATION interfaces */
526         struct {
527                 enum smb_fileinfo_level level;
528                 union smb_fileinfo_in in;
529
530                 struct {
531                         NTTIME create_time;
532                         NTTIME access_time;
533                         NTTIME write_time;
534                         NTTIME change_time;
535                         uint32_t attrib;
536                         uint64_t alloc_size;
537                         uint64_t size;
538                         uint32_t nlink;
539                         uint8_t delete_pending;
540                         uint8_t directory;
541                         uint32_t ea_size;
542                         WIRE_STRING fname;
543                 } out;
544         } all_info;     
545
546         /* RAW_FILEINFO_SMB2_ALL_INFORMATION interface */
547         struct {
548                 enum smb_fileinfo_level level;
549                 union smb_fileinfo_in in;
550
551                 struct {
552                         NTTIME   create_time;
553                         NTTIME   access_time;
554                         NTTIME   write_time;
555                         NTTIME   change_time;
556                         uint32_t attrib;
557                         uint32_t unknown1;
558                         uint64_t alloc_size;
559                         uint64_t size;
560                         uint32_t nlink;
561                         uint8_t  delete_pending;
562                         uint8_t  directory;
563                         /* uint16_t _pad; */
564                         uint64_t file_id;
565                         uint32_t ea_size;
566                         uint32_t access_mask;
567                         uint64_t position;
568                         uint64_t mode;
569                         WIRE_STRING fname;
570                 } out;
571         } all_info2;    
572
573         /* RAW_FILEINFO_ALT_NAME_INFO and RAW_FILEINFO_ALT_NAME_INFORMATION interfaces */
574         struct {
575                 enum smb_fileinfo_level level;
576                 union smb_fileinfo_in in;
577
578                 struct {
579                         WIRE_STRING fname;
580                 } out;
581         } alt_name_info;
582
583         /* RAW_FILEINFO_STREAM_INFO and RAW_FILEINFO_STREAM_INFORMATION interfaces */
584         struct {
585                 enum smb_fileinfo_level level;
586                 union smb_fileinfo_in in;
587
588                 struct stream_information {
589                         uint_t num_streams;
590                         struct stream_struct *streams;
591                 } out;
592         } stream_info;
593         
594         /* RAW_FILEINFO_COMPRESSION_INFO and RAW_FILEINFO_COMPRESSION_INFORMATION interfaces */
595         struct {
596                 enum smb_fileinfo_level level;
597                 union smb_fileinfo_in in;
598
599                 struct {
600                         uint64_t compressed_size;
601                         uint16_t format;
602                         uint8_t unit_shift;
603                         uint8_t chunk_shift;
604                         uint8_t cluster_shift;
605                 } out;
606         } compression_info;
607
608         /* RAW_FILEINFO_UNIX_BASIC interface */
609         struct {
610                 enum smb_fileinfo_level level;
611                 union smb_fileinfo_in in;
612
613                 struct {
614                         uint64_t end_of_file;
615                         uint64_t num_bytes;
616                         NTTIME status_change_time;
617                         NTTIME access_time;
618                         NTTIME change_time;
619                         uint64_t uid;
620                         uint64_t gid;
621                         uint32_t file_type;
622                         uint64_t dev_major;
623                         uint64_t dev_minor;
624                         uint64_t unique_id;
625                         uint64_t permissions;
626                         uint64_t nlink;
627                 } out;
628         } unix_basic_info;
629
630         /* RAW_FILEINFO_UNIX_LINK interface */
631         struct {
632                 enum smb_fileinfo_level level;
633                 union smb_fileinfo_in in;
634
635                 struct {
636                         WIRE_STRING link_dest;
637                 } out;
638         } unix_link_info;
639
640         /* RAW_FILEINFO_INTERNAL_INFORMATION interface */
641         struct {
642                 enum smb_fileinfo_level level;
643                 union smb_fileinfo_in in;
644
645                 struct {
646                         uint64_t file_id;
647                 } out;
648         } internal_information;
649
650         /* RAW_FILEINFO_ACCESS_INFORMATION interface */
651         struct {
652                 enum smb_fileinfo_level level;
653                 union smb_fileinfo_in in;
654
655                 struct {
656                         uint32_t access_flags;
657                 } out;
658         } access_information;
659
660         /* RAW_FILEINFO_POSITION_INFORMATION interface */
661         struct {
662                 enum smb_fileinfo_level level;
663                 union smb_fileinfo_in in;
664
665                 struct {
666                         uint64_t position;
667                 } out;
668         } position_information;
669
670         /* RAW_FILEINFO_MODE_INFORMATION interface */
671         struct {
672                 enum smb_fileinfo_level level;
673                 union smb_fileinfo_in in;
674
675                 struct {
676                         uint32_t mode;
677                 } out;
678         } mode_information;
679
680         /* RAW_FILEINFO_ALIGNMENT_INFORMATION interface */
681         struct {
682                 enum smb_fileinfo_level level;
683                 union smb_fileinfo_in in;
684
685                 struct {
686                         uint32_t alignment_requirement;
687                 } out;
688         } alignment_information;
689
690         /* RAW_FILEINFO_NETWORK_OPEN_INFORMATION interface */
691         struct {
692                 enum smb_fileinfo_level level;
693                 union smb_fileinfo_in in;
694
695                 struct {
696                         NTTIME create_time;
697                         NTTIME access_time;
698                         NTTIME write_time;
699                         NTTIME change_time;
700                         uint64_t alloc_size;
701                         uint64_t size;
702                         uint32_t attrib;
703                 } out;
704         } network_open_information;
705
706
707         /* RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION interface */
708         struct {
709                 enum smb_fileinfo_level level;
710                 union smb_fileinfo_in in;
711
712                 struct {
713                         uint32_t attrib;
714                         uint32_t reparse_tag;
715                 } out;
716         } attribute_tag_information;
717
718         /* RAW_FILEINFO_SEC_DESC */
719         struct {
720                 enum smb_fileinfo_level level;
721                 union smb_fileinfo_in in;
722                 uint32_t secinfo_flags;
723                 struct {
724                         struct security_descriptor *sd;
725                 } out;
726         } query_secdesc;
727 };
728
729
730 enum smb_setfileinfo_level {
731         RAW_SFILEINFO_GENERIC                 = 0xF000, 
732         RAW_SFILEINFO_SETATTR,                /* SMBsetatr */
733         RAW_SFILEINFO_SETATTRE,               /* SMBsetattrE */
734         RAW_SFILEINFO_SEC_DESC,               /* NT_TRANSACT_SET_SECURITY_DESC */
735         RAW_SFILEINFO_STANDARD                = SMB_SFILEINFO_STANDARD,
736         RAW_SFILEINFO_EA_SET                  = SMB_SFILEINFO_EA_SET,
737         RAW_SFILEINFO_BASIC_INFO              = SMB_SFILEINFO_BASIC_INFO,
738         RAW_SFILEINFO_DISPOSITION_INFO        = SMB_SFILEINFO_DISPOSITION_INFO,
739         RAW_SFILEINFO_ALLOCATION_INFO         = SMB_SFILEINFO_ALLOCATION_INFO,
740         RAW_SFILEINFO_END_OF_FILE_INFO        = SMB_SFILEINFO_END_OF_FILE_INFO,
741         RAW_SFILEINFO_UNIX_BASIC              = SMB_SFILEINFO_UNIX_BASIC,
742         RAW_SFILEINFO_UNIX_LINK               = SMB_SFILEINFO_UNIX_LINK,
743         RAW_SFILEINFO_UNIX_HLINK              = SMB_SFILEINFO_UNIX_HLINK,
744         RAW_SFILEINFO_BASIC_INFORMATION       = SMB_SFILEINFO_BASIC_INFORMATION,
745         RAW_SFILEINFO_RENAME_INFORMATION      = SMB_SFILEINFO_RENAME_INFORMATION,
746         RAW_SFILEINFO_DISPOSITION_INFORMATION = SMB_SFILEINFO_DISPOSITION_INFORMATION,
747         RAW_SFILEINFO_POSITION_INFORMATION    = SMB_SFILEINFO_POSITION_INFORMATION,
748         RAW_SFILEINFO_MODE_INFORMATION        = SMB_SFILEINFO_MODE_INFORMATION,
749         RAW_SFILEINFO_ALLOCATION_INFORMATION  = SMB_SFILEINFO_ALLOCATION_INFORMATION,
750         RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION,
751         RAW_SFILEINFO_1023                    = SMB_SFILEINFO_1023,
752         RAW_SFILEINFO_1025                    = SMB_SFILEINFO_1025,
753         RAW_SFILEINFO_1029                    = SMB_SFILEINFO_1029,
754         RAW_SFILEINFO_1032                    = SMB_SFILEINFO_1032,
755         RAW_SFILEINFO_1039                    = SMB_SFILEINFO_1039,
756         RAW_SFILEINFO_1040                    = SMB_SFILEINFO_1040
757 };
758
759 /* union used in setfileinfo() and setpathinfo() calls */
760 union smb_setfileinfo {
761         /* generic interface */
762         struct {
763                 enum smb_setfileinfo_level level;
764
765                 /* we are combining setfileinfo and setpathinfo into one 
766                    interface */
767                 union setfileinfo_file {
768                         const char *fname;
769                         uint16_t fnum;
770                         struct smb2_handle handle; /* only for SMB2 */
771                 } file;
772         } generic;
773
774         /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */
775         struct {
776                 enum smb_setfileinfo_level level;
777                 union setfileinfo_file file;
778                 struct {
779                         uint16_t attrib;
780                         time_t write_time;
781                 } in;
782         } setattr;
783
784         /* RAW_SFILEINFO_SETATTRE (SMBsetattrE) interface - only via setfileinfo() 
785            also RAW_SFILEINFO_STANDARD */
786         struct {
787                 enum smb_setfileinfo_level level;
788                 union setfileinfo_file file;
789
790                 struct {
791                         time_t create_time;
792                         time_t access_time;
793                         time_t write_time;
794                         /* notice that size, alloc_size and attrib are not settable,
795                            unlike the corresponding qfileinfo level */
796                 } in;
797         } setattre, standard;
798
799         /* RAW_SFILEINFO_EA_SET interface */
800         struct {
801                 enum smb_setfileinfo_level level;
802                 union setfileinfo_file file;
803                 struct {
804                         uint_t num_eas;
805                         struct ea_struct *eas;                  
806                 } in;
807         } ea_set;
808
809         /* RAW_SFILEINFO_BASIC_INFO and
810            RAW_SFILEINFO_BASIC_INFORMATION interfaces */
811         struct {
812                 enum smb_setfileinfo_level level;
813                 union setfileinfo_file file;
814
815                 struct {
816                         NTTIME create_time;
817                         NTTIME access_time;
818                         NTTIME write_time;
819                         NTTIME change_time;
820                         uint32_t attrib;
821                 } in;
822         } basic_info;
823
824         /* RAW_SFILEINFO_DISPOSITION_INFO and 
825            RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */
826         struct {
827                 enum smb_setfileinfo_level level;
828                 union setfileinfo_file file;
829
830                 struct {
831                         BOOL delete_on_close;
832                 } in;
833         } disposition_info;
834
835         /* RAW_SFILEINFO_ALLOCATION_INFO and 
836            RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */
837         struct {
838                 enum smb_setfileinfo_level level;
839                 union setfileinfo_file file;
840
841                 struct {
842                         /* w2k3 rounds this up to nearest 4096 */
843                         uint64_t alloc_size;
844                 } in;
845         } allocation_info;
846         
847         /* RAW_SFILEINFO_END_OF_FILE_INFO and 
848            RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */
849         struct {
850                 enum smb_setfileinfo_level level;
851                 union setfileinfo_file file;
852
853                 struct {
854                         uint64_t size;
855                 } in;
856         } end_of_file_info;
857
858         /* RAW_SFILEINFO_RENAME_INFORMATION interface */
859         struct {
860                 enum smb_setfileinfo_level level;
861                 union setfileinfo_file file;
862
863                 struct smb_rename_information {
864                         uint8_t overwrite;
865                         uint32_t root_fid;
866                         const char *new_name;
867                 } in;
868         } rename_information;
869
870         /* RAW_SFILEINFO_POSITION_INFORMATION interface */
871         struct {
872                 enum smb_setfileinfo_level level;
873                 union setfileinfo_file file;
874
875                 struct {
876                         uint64_t position;
877                 } in;
878         } position_information;
879
880         /* RAW_SFILEINFO_MODE_INFORMATION interface */
881         struct {
882                 enum smb_setfileinfo_level level;
883                 union setfileinfo_file file;
884
885                 struct {
886                         /* valid values seem to be 0, 2, 4 and 6 */
887                         uint32_t mode;
888                 } in;
889         } mode_information;
890
891
892
893         /* RAW_SFILEINFO_UNIX_BASIC interface */
894         struct {
895                 enum smb_setfileinfo_level level;
896                 union setfileinfo_file file;
897                 struct {
898                         uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */
899                         uint64_t end_of_file;
900                         uint64_t num_bytes;
901                         NTTIME status_change_time;
902                         NTTIME access_time;
903                         NTTIME change_time;
904                         uint64_t uid;
905                         uint64_t gid;
906                         uint32_t file_type;
907                         uint64_t dev_major;
908                         uint64_t dev_minor;
909                         uint64_t unique_id;
910                         uint64_t permissions;
911                         uint64_t nlink;
912                 } in;
913         } unix_basic;
914         
915         /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */
916         struct {
917                 enum smb_setfileinfo_level level;
918                 union setfileinfo_file file;
919                 struct {
920                         const char *link_dest;
921                 } in;
922         } unix_link, unix_hlink;
923
924         /* RAW_FILEINFO_SET_SEC_DESC */
925         struct {
926                 enum smb_setfileinfo_level level;
927                 union setfileinfo_file file;
928                 struct {
929                         uint32_t secinfo_flags;
930                         struct security_descriptor *sd;
931                 } in;
932         } set_secdesc;
933 };
934
935
936 enum smb_fsinfo_level {
937                    RAW_QFS_GENERIC                        = 0xF000, 
938                    RAW_QFS_DSKATTR,                         /* SMBdskattr */
939                    RAW_QFS_ALLOCATION                     = SMB_QFS_ALLOCATION,
940                    RAW_QFS_VOLUME                         = SMB_QFS_VOLUME,
941                    RAW_QFS_VOLUME_INFO                    = SMB_QFS_VOLUME_INFO,
942                    RAW_QFS_SIZE_INFO                      = SMB_QFS_SIZE_INFO,
943                    RAW_QFS_DEVICE_INFO                    = SMB_QFS_DEVICE_INFO,
944                    RAW_QFS_ATTRIBUTE_INFO                 = SMB_QFS_ATTRIBUTE_INFO,
945                    RAW_QFS_UNIX_INFO                      = SMB_QFS_UNIX_INFO,
946                    RAW_QFS_VOLUME_INFORMATION             = SMB_QFS_VOLUME_INFORMATION,
947                    RAW_QFS_SIZE_INFORMATION               = SMB_QFS_SIZE_INFORMATION,
948                    RAW_QFS_DEVICE_INFORMATION             = SMB_QFS_DEVICE_INFORMATION,
949                    RAW_QFS_ATTRIBUTE_INFORMATION          = SMB_QFS_ATTRIBUTE_INFORMATION,
950                    RAW_QFS_QUOTA_INFORMATION              = SMB_QFS_QUOTA_INFORMATION,
951                    RAW_QFS_FULL_SIZE_INFORMATION          = SMB_QFS_FULL_SIZE_INFORMATION,
952                    RAW_QFS_OBJECTID_INFORMATION           = SMB_QFS_OBJECTID_INFORMATION};
953
954
955 /* union for fsinfo() backend call. Note that there are no in
956    structures, as this call only contains out parameters */
957 union smb_fsinfo {
958         /* generic interface */
959         struct {
960                 enum smb_fsinfo_level level;
961                 struct smb2_handle handle; /* only for smb2 */
962
963                 struct {
964                         uint32_t block_size;
965                         uint64_t blocks_total;
966                         uint64_t blocks_free;
967                         uint32_t fs_id;
968                         NTTIME create_time;
969                         uint32_t serial_number;
970                         uint32_t fs_attr;
971                         uint32_t max_file_component_length;
972                         uint32_t device_type;
973                         uint32_t device_characteristics;
974                         uint64_t quota_soft;
975                         uint64_t quota_hard;
976                         uint64_t quota_flags;
977                         struct GUID guid;
978                         char *volume_name;
979                         char *fs_type;
980                 } out;
981         } generic;
982
983         /* SMBdskattr interface */
984         struct {
985                 enum smb_fsinfo_level level;
986
987                 struct {
988                         uint16_t units_total;
989                         uint16_t blocks_per_unit;
990                         uint16_t block_size;
991                         uint16_t units_free;
992                 } out;
993         } dskattr;
994
995         /* trans2 RAW_QFS_ALLOCATION interface */
996         struct {
997                 enum smb_fsinfo_level level;
998
999                 struct {
1000                         uint32_t fs_id;
1001                         uint32_t sectors_per_unit;
1002                         uint32_t total_alloc_units;
1003                         uint32_t avail_alloc_units;
1004                         uint16_t bytes_per_sector;
1005                 } out;
1006         } allocation;
1007
1008         /* TRANS2 RAW_QFS_VOLUME interface */
1009         struct {
1010                 enum smb_fsinfo_level level;
1011
1012                 struct {
1013                         uint32_t serial_number;
1014                         WIRE_STRING volume_name;
1015                 } out;
1016         } volume;
1017
1018         /* TRANS2 RAW_QFS_VOLUME_INFO and RAW_QFS_VOLUME_INFORMATION interfaces */
1019         struct {
1020                 enum smb_fsinfo_level level;
1021                 struct smb2_handle handle; /* only for smb2 */
1022
1023                 struct {
1024                         NTTIME create_time;
1025                         uint32_t serial_number;
1026                         WIRE_STRING volume_name;
1027                 } out;
1028         } volume_info;
1029
1030         /* trans2 RAW_QFS_SIZE_INFO and RAW_QFS_SIZE_INFORMATION interfaces */
1031         struct {
1032                 enum smb_fsinfo_level level;
1033                 struct smb2_handle handle; /* only for smb2 */
1034
1035                 struct {
1036                         uint64_t total_alloc_units;
1037                         uint64_t avail_alloc_units; /* maps to call_avail_alloc_units */
1038                         uint32_t sectors_per_unit;
1039                         uint32_t bytes_per_sector;
1040                 } out;
1041         } size_info;
1042
1043         /* TRANS2 RAW_QFS_DEVICE_INFO and RAW_QFS_DEVICE_INFORMATION interfaces */
1044         struct {
1045                 enum smb_fsinfo_level level;
1046                 struct smb2_handle handle; /* only for smb2 */
1047
1048                 struct {
1049                         uint32_t device_type;
1050                         uint32_t characteristics;
1051                 } out;
1052         } device_info;
1053
1054
1055         /* TRANS2 RAW_QFS_ATTRIBUTE_INFO and RAW_QFS_ATTRIBUTE_INFORMATION interfaces */
1056         struct {
1057                 enum smb_fsinfo_level level;
1058                 struct smb2_handle handle; /* only for smb2 */
1059
1060                 struct {
1061                         uint32_t fs_attr;
1062                         uint32_t max_file_component_length;
1063                         WIRE_STRING fs_type;
1064                 } out;
1065         } attribute_info;
1066
1067
1068         /* TRANS2 RAW_QFS_UNIX_INFO interface */
1069         struct {
1070                 enum smb_fsinfo_level level;
1071
1072                 struct {
1073                         uint16_t major_version;
1074                         uint16_t minor_version;
1075                         uint64_t capability;
1076                 } out;
1077         } unix_info;
1078
1079         /* trans2 RAW_QFS_QUOTA_INFORMATION interface */
1080         struct {
1081                 enum smb_fsinfo_level level;
1082                 struct smb2_handle handle; /* only for smb2 */
1083
1084                 struct {
1085                         uint64_t unknown[3];
1086                         uint64_t quota_soft;
1087                         uint64_t quota_hard;
1088                         uint64_t quota_flags;
1089                 } out;
1090         } quota_information;    
1091
1092         /* trans2 RAW_QFS_FULL_SIZE_INFORMATION interface */
1093         struct {
1094                 enum smb_fsinfo_level level;
1095                 struct smb2_handle handle; /* only for smb2 */
1096
1097                 struct {
1098                         uint64_t total_alloc_units;
1099                         uint64_t call_avail_alloc_units;
1100                         uint64_t actual_avail_alloc_units;
1101                         uint32_t sectors_per_unit;
1102                         uint32_t bytes_per_sector;
1103                 } out;
1104         } full_size_information;
1105
1106         /* trans2 RAW_QFS_OBJECTID_INFORMATION interface */
1107         struct {
1108                 enum smb_fsinfo_level level;
1109                 struct smb2_handle handle; /* only for smb2 */
1110
1111                 struct {
1112                         struct GUID  guid;
1113                         uint64_t unknown[6];
1114                 } out;
1115         } objectid_information; 
1116 };
1117
1118
1119
1120 enum smb_open_level {
1121                  RAW_OPEN_OPEN, RAW_OPEN_OPENX, 
1122                  RAW_OPEN_MKNEW, RAW_OPEN_CREATE, 
1123                  RAW_OPEN_CTEMP, RAW_OPEN_SPLOPEN,
1124                  RAW_OPEN_NTCREATEX, RAW_OPEN_T2OPEN,
1125                  RAW_OPEN_NTTRANS_CREATE, 
1126                  RAW_OPEN_OPENX_READX};
1127
1128 /* the generic interface is defined to be equal to the NTCREATEX interface */
1129 #define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX
1130
1131 /* union for open() backend call */
1132 union smb_open {
1133         /* SMBNTCreateX interface */
1134         struct {
1135                 enum smb_open_level level;
1136
1137                 struct {
1138                         uint32_t flags;
1139                         uint32_t root_fid;
1140                         uint32_t access_mask;
1141                         uint64_t alloc_size;
1142                         uint32_t file_attr;
1143                         uint32_t share_access;
1144                         uint32_t open_disposition;
1145                         uint32_t create_options;
1146                         uint32_t impersonation;
1147                         uint8_t  security_flags;
1148                         /* NOTE: fname can also be a pointer to a
1149                          uint64_t file_id if create_options has the
1150                          NTCREATEX_OPTIONS_OPEN_BY_FILE_ID flag set */
1151                         const char *fname;
1152
1153                         /* these last 2 elements are only used in the
1154                            NTTRANS varient of the call */
1155                         struct security_descriptor *sec_desc;
1156                         struct smb_ea_list *ea_list;
1157                 } in;
1158
1159                 struct {
1160                         uint8_t oplock_level;
1161                         uint16_t fnum;
1162                         uint32_t create_action;
1163                         NTTIME create_time;
1164                         NTTIME access_time;
1165                         NTTIME write_time;
1166                         NTTIME change_time;
1167                         uint32_t attrib;
1168                         uint64_t alloc_size;
1169                         uint64_t size;
1170                         uint16_t file_type;
1171                         uint16_t ipc_state;
1172                         uint8_t  is_directory;
1173                 } out;
1174         } ntcreatex, generic;
1175
1176         /* TRANS2_OPEN interface */
1177         struct {
1178                 enum smb_open_level level;
1179
1180                 struct {
1181                         uint16_t flags;
1182                         uint16_t open_mode;
1183                         uint16_t search_attrs;
1184                         uint16_t file_attrs;
1185                         time_t write_time;
1186                         uint16_t open_func;
1187                         uint32_t size;
1188                         uint32_t timeout;
1189                         const char *fname;
1190                         uint_t num_eas;
1191                         struct ea_struct *eas;                  
1192                 } in;
1193
1194                 struct {
1195                         uint16_t fnum;
1196                         uint16_t attrib;
1197                         time_t write_time;
1198                         uint32_t size;
1199                         uint16_t access;
1200                         uint16_t ftype;
1201                         uint16_t devstate;
1202                         uint16_t action;
1203                         uint32_t file_id;
1204                 } out;
1205         } t2open;
1206
1207         /* SMBopen interface */
1208         struct {
1209                 enum smb_open_level level;
1210
1211                 struct {
1212                         uint16_t open_mode;
1213                         uint16_t search_attrs;
1214                         const char *fname;
1215                 } in;
1216                 struct {
1217                         uint16_t fnum;
1218                         uint16_t attrib;
1219                         time_t write_time;
1220                         uint32_t size;
1221                         uint16_t rmode;
1222                 } out;
1223         } openold;
1224
1225         /* SMBopenX interface */
1226         struct {
1227                 enum smb_open_level level;
1228
1229                 struct {
1230                         uint16_t flags;
1231                         uint16_t open_mode;
1232                         uint16_t search_attrs; /* not honoured by win2003 */
1233                         uint16_t file_attrs;
1234                         time_t write_time; /* not honoured by win2003 */
1235                         uint16_t open_func;
1236                         uint32_t size; /* note that this sets the
1237                                         initial file size, not
1238                                         just allocation size */
1239                         uint32_t timeout; /* not honoured by win2003 */
1240                         const char *fname;
1241                 } in;
1242                 struct {
1243                         uint16_t fnum;
1244                         uint16_t attrib;
1245                         time_t write_time;
1246                         uint32_t size;
1247                         uint16_t access;
1248                         uint16_t ftype;
1249                         uint16_t devstate;
1250                         uint16_t action;
1251                         uint32_t unique_fid;
1252                         uint32_t access_mask;
1253                         uint32_t unknown;
1254                 } out;
1255         } openx;
1256
1257         /* SMBmknew interface */
1258         struct {
1259                 enum smb_open_level level;
1260
1261                 struct {
1262                         uint16_t attrib;
1263                         time_t write_time;
1264                         const char *fname;
1265                 } in;
1266                 struct {
1267                         uint16_t fnum;
1268                 } out;
1269         } mknew, create;
1270
1271         /* SMBctemp interface */
1272         struct {
1273                 enum smb_open_level level;
1274
1275                 struct {
1276                         uint16_t attrib;
1277                         time_t write_time;
1278                         const char *directory;
1279                 } in;
1280                 struct {
1281                         uint16_t fnum;
1282                         /* temp name, relative to directory */
1283                         char *name; 
1284                 } out;
1285         } ctemp;
1286
1287         /* SMBsplopen interface */
1288         struct {
1289                 enum smb_open_level level;
1290
1291                 struct {
1292                         uint16_t setup_length;
1293                         uint16_t mode;
1294                         const char *ident;
1295                 } in;
1296                 struct {
1297                         uint16_t fnum;
1298                 } out;
1299         } splopen;
1300
1301
1302         /* chained OpenX/ReadX interface */
1303         struct {
1304                 enum smb_open_level level;
1305
1306                 struct {
1307                         uint16_t flags;
1308                         uint16_t open_mode;
1309                         uint16_t search_attrs; /* not honoured by win2003 */
1310                         uint16_t file_attrs;
1311                         time_t write_time; /* not honoured by win2003 */
1312                         uint16_t open_func;
1313                         uint32_t size; /* note that this sets the
1314                                         initial file size, not
1315                                         just allocation size */
1316                         uint32_t timeout; /* not honoured by win2003 */
1317                         const char *fname;
1318
1319                         /* readx part */
1320                         uint64_t offset;
1321                         uint16_t mincnt;
1322                         uint32_t maxcnt;
1323                         uint16_t remaining;
1324                 } in;
1325                 struct {
1326                         uint16_t fnum;
1327                         uint16_t attrib;
1328                         time_t write_time;
1329                         uint32_t size;
1330                         uint16_t access;
1331                         uint16_t ftype;
1332                         uint16_t devstate;
1333                         uint16_t action;
1334                         uint32_t unique_fid;
1335                         uint32_t access_mask;
1336                         uint32_t unknown;
1337                         
1338                         /* readx part */
1339                         uint8_t *data;
1340                         uint16_t remaining;
1341                         uint16_t compaction_mode;
1342                         uint16_t nread;
1343                 } out;
1344         } openxreadx;
1345 };
1346
1347
1348
1349 enum smb_read_level {RAW_READ_READBRAW, RAW_READ_LOCKREAD, RAW_READ_READ, RAW_READ_READX};
1350
1351 #define RAW_READ_GENERIC RAW_READ_READX
1352
1353 /* union for read() backend call 
1354
1355    note that .infoX.out.data will be allocated before the backend is
1356    called. It will be big enough to hold the maximum size asked for
1357 */
1358 union smb_read {
1359         /* SMBreadX (and generic) interface */
1360         struct {
1361                 enum smb_read_level level;
1362
1363                 struct {
1364                         uint16_t fnum;
1365                         uint64_t offset;
1366                         uint16_t mincnt;
1367                         uint32_t maxcnt;
1368                         uint16_t remaining;
1369                 } in;
1370                 struct {
1371                         uint8_t *data;
1372                         uint16_t remaining;
1373                         uint16_t compaction_mode;
1374                         uint16_t nread;
1375                 } out;
1376         } readx, generic;
1377
1378         /* SMBreadbraw interface */
1379         struct {
1380                 enum smb_read_level level;
1381
1382                 struct {
1383                         uint16_t fnum;
1384                         uint64_t offset;
1385                         uint16_t  maxcnt;
1386                         uint16_t  mincnt;
1387                         uint32_t  timeout;
1388                 } in;
1389                 struct {
1390                         uint8_t *data;
1391                         uint32_t nread;
1392                 } out;
1393         } readbraw;
1394
1395
1396         /* SMBlockandread interface */
1397         struct {
1398                 enum smb_read_level level;
1399
1400                 struct {
1401                         uint16_t fnum;
1402                         uint16_t count;
1403                         uint32_t offset;
1404                         uint16_t remaining;
1405                 } in;
1406                 struct {
1407                         uint8_t *data;
1408                         uint16_t nread;
1409                 } out;
1410         } lockread;
1411
1412         /* SMBread interface */
1413         struct {
1414                 enum smb_read_level level;
1415
1416                 struct {
1417                         uint16_t fnum;
1418                         uint16_t count;
1419                         uint32_t offset;
1420                         uint16_t remaining;
1421                 } in;
1422                 struct {
1423                         uint8_t *data;
1424                         uint16_t nread;
1425                 } out;
1426         } read;
1427 };
1428
1429
1430 enum smb_write_level {RAW_WRITE_WRITEUNLOCK, RAW_WRITE_WRITE, 
1431                       RAW_WRITE_WRITEX, RAW_WRITE_WRITECLOSE, 
1432                       RAW_WRITE_SPLWRITE};
1433
1434 #define RAW_WRITE_GENERIC RAW_WRITE_WRITEX
1435
1436 /* union for write() backend call 
1437 */
1438 union smb_write {
1439         /* SMBwriteX interface */
1440         struct {
1441                 enum smb_write_level level;
1442
1443                 struct {
1444                         uint16_t fnum;
1445                         uint64_t offset;
1446                         uint16_t wmode;
1447                         uint16_t remaining;
1448                         uint32_t count;
1449                         const uint8_t *data;
1450                 } in;
1451                 struct {
1452                         uint32_t nwritten;
1453                         uint16_t remaining;
1454                 } out;
1455         } writex, generic;
1456
1457         /* SMBwriteunlock interface */
1458         struct {
1459                 enum smb_write_level level;
1460
1461                 struct {
1462                         uint16_t fnum;
1463                         uint16_t count;
1464                         uint32_t offset;
1465                         uint16_t remaining;
1466                         const uint8_t *data;
1467                 } in;
1468                 struct {
1469                         uint32_t nwritten;
1470                 } out;
1471         } writeunlock;
1472
1473         /* SMBwrite interface */
1474         struct {
1475                 enum smb_write_level level;
1476
1477                 struct {
1478                         uint16_t fnum;
1479                         uint16_t count;
1480                         uint32_t offset;
1481                         uint16_t remaining;
1482                         const uint8_t *data;
1483                 } in;
1484                 struct {
1485                         uint16_t nwritten;
1486                 } out;
1487         } write;
1488
1489         /* SMBwriteclose interface */
1490         struct {
1491                 enum smb_write_level level;
1492
1493                 struct {
1494                         uint16_t fnum;
1495                         uint16_t count;
1496                         uint32_t offset;
1497                         time_t mtime;
1498                         const uint8_t *data;
1499                 } in;
1500                 struct {
1501                         uint16_t nwritten;
1502                 } out;
1503         } writeclose;
1504
1505         /* SMBsplwrite interface */
1506         struct {
1507                 enum smb_write_level level;
1508
1509                 struct {
1510                         uint16_t fnum;
1511                         uint16_t count;
1512                         const uint8_t *data;
1513                 } in;
1514         } splwrite;
1515 };
1516
1517
1518 enum smb_lock_level {RAW_LOCK_LOCK, RAW_LOCK_UNLOCK, RAW_LOCK_LOCKX};
1519
1520 /* the generic interface is defined to be equal to the lockingX interface */
1521 #define RAW_LOCK_GENERIC RAW_LOCK_LOCKX
1522
1523 /* union for lock() backend call 
1524 */
1525 union smb_lock {
1526         /* SMBlockingX (and generic) interface */
1527         struct {
1528                 enum smb_lock_level level;
1529
1530                 struct {
1531                         uint16_t fnum;
1532                         uint16_t mode;
1533                         uint32_t timeout;
1534                         uint16_t ulock_cnt;
1535                         uint16_t lock_cnt;
1536                         struct smb_lock_entry {
1537                                 uint16_t pid;
1538                                 uint64_t offset;
1539                                 uint64_t count;
1540                         } *locks; /* unlocks are first in the arrray */
1541                 } in;
1542         } lockx, generic;
1543
1544         /* SMBlock and SMBunlock interface */
1545         struct {
1546                 enum smb_lock_level level;
1547
1548                 struct {
1549                         uint16_t fnum;
1550                         uint32_t count;
1551                         uint32_t offset;
1552                 } in;
1553         } lock, unlock;
1554 };
1555
1556
1557 enum smb_close_level {RAW_CLOSE_CLOSE, RAW_CLOSE_SPLCLOSE};
1558
1559 #define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE
1560
1561 /*
1562   union for close() backend call
1563 */
1564 union smb_close {
1565         /* SMBclose (and generic) interface */
1566         struct {
1567                 enum smb_close_level level;
1568
1569                 struct {
1570                         uint16_t fnum;
1571                         time_t write_time;
1572                 } in;
1573         } close, generic;
1574
1575         /* SMBsplclose interface - empty! */
1576         struct {
1577                 enum smb_close_level level;
1578
1579                 struct {
1580                         uint16_t fnum;
1581                 } in;
1582         } splclose;
1583 };
1584
1585
1586 enum smb_lpq_level {RAW_LPQ_GENERIC, RAW_LPQ_RETQ};
1587
1588 /*
1589   union for lpq() backend
1590 */
1591 union smb_lpq {
1592         /* generic interface */
1593         struct {
1594                 enum smb_lpq_level level;
1595
1596         } generic;
1597
1598
1599         /* SMBsplretq interface */
1600         struct {
1601                 enum smb_lpq_level level;
1602
1603                 struct {
1604                         uint16_t maxcount;
1605                         uint16_t startidx;
1606                 } in;
1607                 struct {
1608                         uint16_t count;
1609                         uint16_t restart_idx;
1610                         struct {
1611                                 time_t time;
1612                                 uint8_t status;
1613                                 uint16_t job;
1614                                 uint32_t size;
1615                                 char *user;
1616                         } *queue;
1617                 } out;
1618         } retq;
1619 };
1620
1621 enum smb_ioctl_level {RAW_IOCTL_IOCTL, RAW_IOCTL_NTIOCTL};
1622
1623 /*
1624   union for ioctl() backend
1625 */
1626 union smb_ioctl {
1627         /* generic interface */
1628         struct {
1629                 enum smb_ioctl_level level;
1630
1631         } generic;
1632
1633         /* struct for SMBioctl */
1634         struct {
1635                 enum smb_ioctl_level level;
1636                 struct {
1637                         uint16_t fnum;
1638                         uint32_t request;
1639                 } in;
1640                 struct {
1641                         DATA_BLOB blob;
1642                 } out;
1643         } ioctl;
1644
1645
1646         /* struct for NT ioctl call */
1647         struct {
1648                 enum smb_ioctl_level level;
1649                 struct {
1650                         uint32_t function;
1651                         uint16_t fnum;
1652                         BOOL fsctl;
1653                         uint8_t filter;
1654                 } in;
1655                 struct {
1656                         DATA_BLOB blob;
1657                 } out;
1658         } ntioctl;
1659 };
1660
1661 /* struct for SMBflush */
1662 struct smb_flush {
1663         struct {
1664                 uint16_t fnum;
1665         } in;
1666 };
1667
1668
1669 /* struct for SMBcopy */
1670 struct smb_copy {
1671         struct {
1672                 uint16_t tid2;
1673                 uint16_t ofun;
1674                 uint16_t flags;
1675                 const char *path1;
1676                 const char *path2;
1677         } in;
1678         struct {
1679                 uint16_t count;
1680         } out;
1681 };
1682
1683
1684 /* struct for transact/transact2 call */
1685 struct smb_trans2 {
1686         struct {
1687                 uint16_t max_param;
1688                 uint16_t max_data;
1689                 uint8_t  max_setup;
1690                 uint16_t flags;
1691                 uint32_t timeout;
1692                 uint8_t  setup_count;
1693                 uint16_t *setup;
1694                 const char *trans_name; /* SMBtrans only */
1695                 DATA_BLOB params;
1696                 DATA_BLOB data;
1697         } in;
1698
1699         struct {
1700                 uint8_t  setup_count;
1701                 uint16_t *setup;
1702                 DATA_BLOB params;
1703                 DATA_BLOB data;
1704         } out;
1705 };
1706
1707 /* struct for nttransact2 call */
1708 struct smb_nttrans {
1709         struct {
1710                 uint8_t  max_setup;
1711                 uint32_t max_param;
1712                 uint32_t max_data;
1713                 uint32_t setup_count;
1714                 uint16_t function;
1715                 uint16_t *setup;
1716                 DATA_BLOB params;
1717                 DATA_BLOB data;
1718         } in;
1719
1720         struct {
1721                 uint8_t  setup_count;
1722                 uint16_t *setup;
1723                 DATA_BLOB params;
1724                 DATA_BLOB data;
1725         } out;
1726 };
1727
1728
1729 /* struct for nttrans change notify call */
1730 struct smb_notify {
1731         struct {
1732                 uint32_t buffer_size;
1733                 uint32_t completion_filter;
1734                 uint16_t fnum;
1735                 BOOL recursive;
1736         } in;
1737
1738         struct {
1739                 uint32_t num_changes;
1740                 struct notify_changes {
1741                         uint32_t action;
1742                         WIRE_STRING name;
1743                 } *changes;
1744         } out;
1745 };
1746
1747
1748 enum smb_search_level {RAW_SEARCH_GENERIC                 = 0xF000, 
1749                        RAW_SEARCH_SEARCH,                 /* SMBsearch */ 
1750                        RAW_SEARCH_FFIRST,                 /* SMBffirst */ 
1751                        RAW_SEARCH_FUNIQUE,                /* SMBfunique */ 
1752                        RAW_SEARCH_STANDARD                = SMB_FIND_STANDARD,
1753                        RAW_SEARCH_EA_SIZE                 = SMB_FIND_EA_SIZE,
1754                        RAW_SEARCH_EA_LIST                 = SMB_FIND_EA_LIST,
1755                        RAW_SEARCH_DIRECTORY_INFO          = SMB_FIND_DIRECTORY_INFO,
1756                        RAW_SEARCH_FULL_DIRECTORY_INFO     = SMB_FIND_FULL_DIRECTORY_INFO,
1757                        RAW_SEARCH_NAME_INFO               = SMB_FIND_NAME_INFO,
1758                        RAW_SEARCH_BOTH_DIRECTORY_INFO     = SMB_FIND_BOTH_DIRECTORY_INFO,
1759                        RAW_SEARCH_ID_FULL_DIRECTORY_INFO  = SMB_FIND_ID_FULL_DIRECTORY_INFO,
1760                        RAW_SEARCH_ID_BOTH_DIRECTORY_INFO  = SMB_FIND_ID_BOTH_DIRECTORY_INFO,
1761                        RAW_SEARCH_UNIX_INFO               = SMB_FIND_UNIX_INFO};
1762
1763         
1764 /* union for file search */
1765 union smb_search_first {
1766         struct {
1767                 enum smb_search_level level;
1768         } generic;
1769         
1770         /* search (old) findfirst interface. 
1771            Also used for ffirst and funique. */
1772         struct {
1773                 enum smb_search_level level;
1774         
1775                 struct {
1776                         uint16_t max_count;
1777                         uint16_t search_attrib;
1778                         const char *pattern;
1779                 } in;
1780                 struct {
1781                         int16_t count;
1782                 } out;
1783         } search_first;
1784
1785         /* trans2 findfirst interface */
1786         struct {
1787                 enum smb_search_level level;
1788                 
1789                 struct {
1790                         uint16_t search_attrib;
1791                         uint16_t max_count;
1792                         uint16_t flags;
1793                         uint32_t storage_type;
1794                         const char *pattern;
1795
1796                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
1797                         uint_t num_names;
1798                         struct ea_name *ea_names;
1799                 } in;
1800                 struct {
1801                         uint16_t handle;
1802                         uint16_t count;
1803                         uint16_t end_of_search;
1804                 } out;
1805         } t2ffirst;
1806 };
1807
1808 /* union for file search continue */
1809 union smb_search_next {
1810         struct {
1811                 enum smb_search_level level;
1812         } generic;
1813
1814         /* search (old) findnext interface. Also used
1815            for ffirst when continuing */
1816         struct {
1817                 enum smb_search_level level;
1818         
1819                 struct {
1820                         uint16_t max_count;
1821                         uint16_t search_attrib;
1822                         struct smb_search_id {
1823                                 uint8_t reserved;
1824                                 char name[11];
1825                                 uint8_t handle;
1826                                 uint32_t server_cookie;
1827                                 uint32_t client_cookie;
1828                         } id;
1829                 } in;
1830                 struct {
1831                         uint16_t count;
1832                 } out;
1833         } search_next;
1834         
1835         /* trans2 findnext interface */
1836         struct {
1837                 enum smb_search_level level;
1838                 
1839                 struct {
1840                         uint16_t handle;
1841                         uint16_t max_count;
1842                         uint32_t resume_key;
1843                         uint16_t flags;
1844                         const char *last_name;
1845
1846                         /* the ea names are only used for RAW_SEARCH_EA_LIST */
1847                         uint_t num_names;
1848                         struct ea_name *ea_names;
1849                 } in;
1850                 struct {
1851                         uint16_t count;
1852                         uint16_t end_of_search;
1853                 } out;
1854         } t2fnext;
1855 };
1856
1857 /* union for search reply file data */
1858 union smb_search_data {
1859         /* search (old) findfirst */
1860         struct {
1861                 uint16_t attrib;
1862                 time_t write_time;
1863                 uint32_t size;
1864                 struct smb_search_id id;
1865                 const char *name;
1866         } search;
1867         
1868         /* trans2 findfirst RAW_SEARCH_STANDARD level */
1869         struct {
1870                 uint32_t resume_key;
1871                 time_t create_time;
1872                 time_t access_time;
1873                 time_t write_time;
1874                 uint32_t size;
1875                 uint32_t alloc_size;
1876                 uint16_t attrib;
1877                 WIRE_STRING name;
1878         } standard;
1879
1880         /* trans2 findfirst RAW_SEARCH_EA_SIZE level */
1881         struct {
1882                 uint32_t resume_key;
1883                 time_t create_time;
1884                 time_t access_time;
1885                 time_t write_time;
1886                 uint32_t size;
1887                 uint32_t alloc_size;
1888                 uint16_t attrib;
1889                 uint32_t ea_size;
1890                 WIRE_STRING name;
1891         } ea_size;
1892
1893         /* trans2 findfirst RAW_SEARCH_EA_LIST level */
1894         struct {
1895                 uint32_t resume_key;
1896                 time_t create_time;
1897                 time_t access_time;
1898                 time_t write_time;
1899                 uint32_t size;
1900                 uint32_t alloc_size;
1901                 uint16_t attrib;
1902                 struct smb_ea_list eas;
1903                 WIRE_STRING name;
1904         } ea_list;
1905
1906         /* RAW_SEARCH_DIRECTORY_INFO interface */
1907         struct {
1908                 uint32_t file_index;
1909                 NTTIME create_time;
1910                 NTTIME access_time;
1911                 NTTIME write_time;
1912                 NTTIME change_time;
1913                 uint64_t  size;
1914                 uint64_t  alloc_size;
1915                 uint32_t   attrib;
1916                 WIRE_STRING name;
1917         } directory_info;
1918
1919         /* RAW_SEARCH_FULL_DIRECTORY_INFO interface */
1920         struct {
1921                 uint32_t file_index;
1922                 NTTIME create_time;
1923                 NTTIME access_time;
1924                 NTTIME write_time;
1925                 NTTIME change_time;
1926                 uint64_t  size;
1927                 uint64_t  alloc_size;
1928                 uint32_t   attrib;
1929                 uint32_t   ea_size;
1930                 WIRE_STRING name;
1931         } full_directory_info;
1932
1933         /* RAW_SEARCH_NAME_INFO interface */
1934         struct {
1935                 uint32_t file_index;
1936                 WIRE_STRING name;
1937         } name_info;
1938
1939         /* RAW_SEARCH_BOTH_DIRECTORY_INFO interface */
1940         struct {
1941                 uint32_t file_index;
1942                 NTTIME create_time;
1943                 NTTIME access_time;
1944                 NTTIME write_time;
1945                 NTTIME change_time;
1946                 uint64_t  size;
1947                 uint64_t  alloc_size;
1948                 uint32_t   attrib;
1949                 uint32_t   ea_size;
1950                 WIRE_STRING short_name;
1951                 WIRE_STRING name;
1952         } both_directory_info;
1953
1954         /* RAW_SEARCH_ID_FULL_DIRECTORY_INFO interface */
1955         struct {
1956                 uint32_t file_index;
1957                 NTTIME create_time;
1958                 NTTIME access_time;
1959                 NTTIME write_time;
1960                 NTTIME change_time;
1961                 uint64_t size;
1962                 uint64_t alloc_size;
1963                 uint32_t attrib;
1964                 uint32_t ea_size;
1965                 uint64_t file_id;
1966                 WIRE_STRING name;
1967         } id_full_directory_info;
1968
1969         /* RAW_SEARCH_ID_BOTH_DIRECTORY_INFO interface */
1970         struct {
1971                 uint32_t file_index;
1972                 NTTIME create_time;
1973                 NTTIME access_time;
1974                 NTTIME write_time;
1975                 NTTIME change_time;
1976                 uint64_t size;
1977                 uint64_t alloc_size;
1978                 uint32_t  attrib;
1979                 uint32_t  ea_size;
1980                 uint64_t file_id;
1981                 WIRE_STRING short_name;
1982                 WIRE_STRING name;
1983         } id_both_directory_info;
1984
1985         /* RAW_SEARCH_UNIX_INFO interface */
1986         struct {
1987                 uint32_t file_index;
1988                 uint64_t size;
1989                 uint64_t alloc_size;
1990                 NTTIME status_change_time;
1991                 NTTIME access_time;
1992                 NTTIME change_time;
1993                 uint64_t uid;
1994                 uint64_t gid;
1995                 uint32_t file_type;
1996                 uint64_t dev_major;
1997                 uint64_t dev_minor;
1998                 uint64_t unique_id;
1999                 uint64_t permissions;
2000                 uint64_t nlink;         
2001                 const char *name;
2002         } unix_info;
2003 };
2004
2005
2006 enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE};
2007
2008 /* union for file search close */
2009 union smb_search_close {
2010         struct {
2011                 enum smb_search_close_level level;
2012         } generic;
2013
2014         /* SMBfclose (old search) interface */
2015         struct {
2016                 enum smb_search_close_level level;
2017         
2018                 struct {
2019                         /* max_count and search_attrib are not used, but are present */
2020                         uint16_t max_count;
2021                         uint16_t search_attrib;
2022                         struct smb_search_id id;
2023                 } in;
2024         } fclose;
2025         
2026         /* SMBfindclose interface */
2027         struct {
2028                 enum smb_search_close_level level;
2029                 
2030                 struct {
2031                         uint16_t handle;
2032                 } in;
2033         } findclose;
2034 };
2035