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