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