872e20f156c439af8e7d94f49faa266d212be0af
[garming/samba-autobuild/.git] / source4 / libcli / smb2 / smb2_calls.h
1 /* 
2    Unix SMB/CIFS implementation.
3
4    SMB2 client calls 
5
6    Copyright (C) Andrew Tridgell 2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24 struct smb2_negprot {
25         struct {
26                 /* static body buffer 38 (0x26) bytes */
27                 /* uint16_t buffer_code;  0x24 (why?) */
28                 uint16_t unknown1;    /* 0x0001 */
29                 uint8_t  unknown2[32]; /* all zero */
30                 uint16_t unknown3; /* 0x00000 */
31         } in;
32         struct {
33                 /* static body buffer 64 (0x40) bytes */
34                 /* uint16_t buffer_code;  0x41 = 0x40 + 1 */
35                 uint16_t _pad;
36                 uint32_t unknown2; /* 0x06 */
37                 uint8_t  sessid[16];
38                 uint32_t unknown3; /* 0x0d */
39                 uint16_t unknown4; /* 0x00 */
40                 uint32_t unknown5; /* 0x01 */
41                 uint32_t unknown6; /* 0x01 */
42                 uint16_t unknown7; /* 0x01 */
43                 NTTIME   current_time;
44                 NTTIME   boot_time;
45                 /* uint16_t secblob_ofs */
46                 /* uint16_t secblob_size */
47                 uint32_t unknown9; /* 0x204d4c20 */
48
49                 /* dynamic body buffer */
50                 DATA_BLOB secblob;
51         } out;
52 };
53
54 struct smb2_session_setup {
55         struct {
56                 /* static body buffer 16 (0x10) bytes */
57                 /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
58                 uint16_t _pad;
59                 uint32_t unknown2; /* 0xF */
60                 uint32_t unknown3; /* 0x00 */
61                 /* uint16_t secblob_ofs */
62                 /* uint16_t secblob_size */
63
64                 /* dynamic body */
65                 DATA_BLOB secblob;
66         } in;
67         struct {
68                 /* static body buffer 8 (0x08) bytes */
69                 /* uint16_t buffer_code; 0x09 = 0x08 +1 */
70                 uint16_t _pad;
71                 /* uint16_t secblob_ofs */
72                 /* uint16_t secblob_size */
73
74                 /* dynamic body */
75                 DATA_BLOB secblob;
76
77                 /* extracted from the SMB2 header */
78                 uint64_t uid;
79         } out;
80 };
81
82 struct smb2_tree_connect {
83         struct {
84                 /* static body buffer 8 (0x08) bytes */
85                 /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
86                 uint16_t unknown1; /* 0x0000 */
87                 /* uint16_t path_ofs */
88                 /* uint16_t path_size */
89
90                 /* dynamic body */
91                 const char *path; /* as non-terminated UTF-16 on the wire */
92         } in;
93         struct {
94                 /* static body buffer 16 (0x10) bytes */
95                 /* uint16_t buffer_code;  0x10 */
96                 uint16_t unknown1; /* 0x02 */
97                 uint32_t unknown2; /* 0x00 */
98                 uint32_t unknown3; /* 0x00 */
99                 uint32_t access_mask;
100
101                 /* extracted from the SMB2 header */
102                 uint32_t tid;
103         } out;
104 };
105
106 /*
107   file handles in SMB2 are 16 bytes
108 */
109 struct smb2_handle {
110         uint64_t data[2];
111 };
112
113
114 #define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
115 #define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
116 #define SMB2_CREATE_FLAG_GRANT_OPLOCK             0x0001
117 #define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK   0x0080
118
119 struct smb2_create {
120         struct {
121                 /* static body buffer 56 (0x38) bytes */
122                 /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
123                 uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
124                 uint32_t unknown2;
125                 uint32_t unknown3[4];
126                 uint32_t access_mask;
127
128                 uint32_t file_attr;
129                 uint32_t share_access;
130                 uint32_t open_disposition;
131                 uint32_t create_options;
132
133                 /* uint16_t fname_ofs */
134                 /* uint16_t fname_size */
135                 /* uint32_t blob_ofs; */
136                 /* uint32_t blob_size; */
137
138                 /* dynamic body */
139                 const char *fname;
140
141                 DATA_BLOB blob;
142         } in;
143
144         struct {
145                 /* static body buffer 88 (0x58) bytes */
146                 /* uint16_t buffer_code;  0x59 = 0x58 + 1 */
147                 uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
148                 uint32_t create_action;
149                 NTTIME   create_time;
150                 NTTIME   access_time;
151                 NTTIME   write_time;
152                 NTTIME   change_time;
153                 uint64_t alloc_size;
154                 uint64_t size;
155                 uint32_t file_attr;
156                 uint32_t _pad;
157                 struct smb2_handle handle;
158                 /* uint32_t blob_ofs; */
159                 /* uint32_t blob_size; */
160
161                 /* dynamic body */
162                 DATA_BLOB blob;
163         } out;
164 };
165
166
167 #define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
168
169 struct smb2_close {
170         struct {
171                 /* static body buffer 24 (0x18) bytes */
172                 /* uint16_t buffer_code;  0x18 */
173                 uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
174                 uint32_t _pad;
175                 struct smb2_handle handle;
176         } in;
177
178         struct {
179                 /* static body buffer 60 (0x3C) bytes */
180                 /* uint16_t buffer_code;  0x3C */
181                 uint16_t flags;
182                 uint32_t _pad;
183                 NTTIME   create_time;
184                 NTTIME   access_time;
185                 NTTIME   write_time;
186                 NTTIME   change_time;
187                 uint64_t alloc_size;
188                 uint64_t size;
189                 uint32_t file_attr;
190         } out;
191 };
192
193 /* fs information levels */
194 #define SMB2_GETINFO_FS_VOLUME_INFO     0x0102
195 #define SMB2_GETINFO_FS_SIZE_INFO       0x0302
196 #define SMB2_GETINFO_FS_DEVICE_INFO     0x0402
197 #define SMB2_GETINFO_FS_ATTRIBUTE_INFO  0x0502
198 #define SMB2_GETINFO_FS_QUOTA_INFO      0x0602
199 #define SMB2_GETINFO_FS_FULL_SIZE_INFO  0x0702
200 #define SMB2_GETINFO_FS_OBJECTID_INFO   0x0802
201
202 /* class 3 levels */
203 #define SMB2_GETINFO_SECURITY           0x0003
204
205 /* file information levels */
206 #define SMB2_GETINFO_FILE_BASIC_INFO    0x0401
207 #define SMB2_GETINFO_FILE_SIZE_INFO     0x0501
208 #define SMB2_GETINFO_FILE_ID            0x0601
209 #define SMB2_GETINFO_FILE_EA_SIZE       0x0701
210 #define SMB2_GETINFO_FILE_ACCESS_INFO   0x0801
211 #define SMB2_GETINFO_FILE_0E            0x0e01
212 #define SMB2_GETINFO_FILE_ALL_EAS       0x0f01
213 #define SMB2_GETINFO_FILE_10            0x1001
214 #define SMB2_GETINFO_FILE_11            0x1101
215 #define SMB2_GETINFO_FILE_ALL_INFO      0x1201
216 #define SMB2_GETINFO_FILE_SHORT_INFO    0x1501
217 #define SMB2_GETINFO_FILE_STREAM_INFO   0x1601
218 #define SMB2_GETINFO_FILE_EOF_INFO      0x1c01
219 #define SMB2_GETINFO_FILE_STANDARD_INFO 0x2201
220 #define SMB2_GETINFO_FILE_ATTRIB_INFO   0x2301
221
222
223 struct smb2_getinfo {
224         struct {
225                 /* static body buffer 40 (0x28) bytes */
226                 /* uint16_t buffer_code;  0x29 = 0x28 + 1 (why???) */
227                 uint16_t level;
228                 uint32_t max_response_size;
229                 uint32_t unknown1;
230                 uint32_t flags; /* level specific */
231                 uint32_t unknown3;
232                 uint32_t unknown4;
233                 struct smb2_handle handle;
234         } in;
235
236         struct {
237                 /* static body buffer 8 (0x08) bytes */
238                 /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
239                 /* uint16_t blob_ofs; */
240                 /* uint16_t blob_size; */
241
242                 /* dynamic body */
243                 DATA_BLOB blob;
244         } out;
245 };
246
247 union smb2_fileinfo {
248         struct {
249                 NTTIME   create_time;
250                 NTTIME   access_time;
251                 NTTIME   write_time;
252                 NTTIME   change_time;
253                 uint32_t file_attr;
254                 uint32_t unknown;
255         } basic_info;
256
257         struct {
258                 uint64_t alloc_size;
259                 uint64_t size;
260                 uint32_t nlink;
261                 uint8_t  delete_pending;
262                 uint8_t  directory;
263         } size_info;
264
265         struct {
266                 uint64_t file_id;
267         } file_id;
268
269         struct {
270                 uint32_t ea_size;
271         } ea_size;
272
273         struct {
274                 uint32_t access_mask;
275         } access_info;
276
277         struct {
278                 uint32_t unknown1;
279                 uint32_t unknown2;
280         } unknown0e;
281
282         struct smb_ea_list all_eas;
283
284         struct {
285                 uint32_t unknown;
286         } unknown10;
287
288         struct {
289                 uint32_t unknown;
290         } unknown11;
291
292         struct {
293                 NTTIME   create_time;
294                 NTTIME   access_time;
295                 NTTIME   write_time;
296                 NTTIME   change_time;
297                 uint32_t file_attr;
298                 uint32_t unknown1;
299                 uint64_t alloc_size;
300                 uint64_t size;
301                 uint32_t nlink;
302                 uint8_t  delete_pending;
303                 uint8_t  directory;
304                 /* uint16_t _pad; */
305                 uint64_t file_id;
306                 uint32_t ea_size;
307                 uint32_t access_mask;
308                 uint64_t unknown5;
309                 uint64_t unknown6;
310                 const char *fname;
311         } all_info;
312
313         struct {
314                 const char *short_name;
315         } short_info;
316
317         struct stream_information stream_info;
318
319         struct {
320                 uint64_t size;
321                 uint64_t unknown;
322         } eof_info;
323
324         struct {
325                 NTTIME   create_time;
326                 NTTIME   access_time;
327                 NTTIME   write_time;
328                 NTTIME   change_time;
329                 uint64_t alloc_size;
330                 uint64_t size;
331                 uint32_t file_attr;
332                 uint32_t unknown;
333         } standard_info;
334
335         struct {
336                 uint32_t file_attr;
337                 uint32_t unknown;
338         } attrib_info;
339
340         struct {
341                 struct security_descriptor *sd;
342         } security;
343 };
344
345
346 struct smb2_write {
347         struct {
348                 /* static body buffer 48 (0x30) bytes */
349                 /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
350                 /* uint16_t data_ofs; */
351                 /* uint32_t data_size; */
352                 uint64_t offset;
353                 struct smb2_handle handle;
354                 uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */
355                 uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */
356
357                 /* dynamic body */
358                 DATA_BLOB data;
359         } in;
360
361         struct {
362                 /* static body buffer 17 (0x11) bytes */
363                 /* uint16_t buffer_code;  0x11 */
364                 uint16_t _pad;
365                 uint32_t nwritten;
366                 uint64_t unknown1; /* 0x0000000000000000 */
367                 uint8_t _bug;
368         } out;
369 };
370
371 struct smb2_read {
372         struct {
373                 /* static body buffer 48 (0x30) bytes */
374                 /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
375                 uint16_t _pad;
376                 uint32_t length;
377                 uint64_t offset;
378                 struct smb2_handle handle;
379                 uint64_t unknown1; /* 0x0000000000000000 */
380                 uint64_t unknown2; /* 0x0000000000000000 */
381                 uint8_t _bug;
382         } in;
383
384         struct {
385                 /* static body buffer 16 (0x10) bytes */
386                 /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
387                 /* uint16_t data_ofs; */
388                 /* uint32_t data_size; */
389                 uint64_t unknown1; /* 0x0000000000000000 */
390
391                 /* dynamic body */
392                 DATA_BLOB data;
393         } out;
394 };