r11801: - added basic SMB2 find support
[kai/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 #define SMB2_CREATE_FLAG_REQUEST_OPLOCK           0x0100
107 #define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800
108 #define SMB2_CREATE_FLAG_GRANT_OPLOCK             0x0001
109 #define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK   0x0080
110
111 struct smb2_create {
112         struct {
113                 /* static body buffer 56 (0x38) bytes */
114                 /* uint16_t buffer_code;  0x39 = 0x38 + 1 */
115                 uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
116                 uint32_t unknown2;
117                 uint32_t unknown3[4];
118                 uint32_t access_mask;
119
120                 uint32_t file_attr;
121                 uint32_t share_access;
122                 uint32_t open_disposition;
123                 uint32_t create_options;
124
125                 /* uint16_t fname_ofs */
126                 /* uint16_t fname_size */
127                 /* uint32_t blob_ofs; */
128                 /* uint32_t blob_size; */
129
130                 /* dynamic body */
131                 const char *fname;
132
133                 /* optional list of extended attributes */
134                 struct smb_ea_list eas;
135         } in;
136
137         struct {
138                 /* static body buffer 88 (0x58) bytes */
139                 /* uint16_t buffer_code;  0x59 = 0x58 + 1 */
140                 uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */
141                 uint32_t create_action;
142                 NTTIME   create_time;
143                 NTTIME   access_time;
144                 NTTIME   write_time;
145                 NTTIME   change_time;
146                 uint64_t alloc_size;
147                 uint64_t size;
148                 uint32_t file_attr;
149                 uint32_t _pad;
150                 struct smb2_handle handle;
151                 /* uint32_t blob_ofs; */
152                 /* uint32_t blob_size; */
153
154                 /* dynamic body */
155                 DATA_BLOB blob;
156         } out;
157 };
158
159
160 #define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0)
161
162 struct smb2_close {
163         struct {
164                 /* static body buffer 24 (0x18) bytes */
165                 /* uint16_t buffer_code;  0x18 */
166                 uint16_t flags; /* SMB2_CLOSE_FLAGS_* */
167                 uint32_t _pad;
168                 struct smb2_handle handle;
169         } in;
170
171         struct {
172                 /* static body buffer 60 (0x3C) bytes */
173                 /* uint16_t buffer_code;  0x3C */
174                 uint16_t flags;
175                 uint32_t _pad;
176                 NTTIME   create_time;
177                 NTTIME   access_time;
178                 NTTIME   write_time;
179                 NTTIME   change_time;
180                 uint64_t alloc_size;
181                 uint64_t size;
182                 uint32_t file_attr;
183         } out;
184 };
185
186 /* getinfo classes */
187 #define SMB2_GETINFO_FILE               0x01
188 #define SMB2_GETINFO_FS                 0x02
189 #define SMB2_GETINFO_SECURITY           0x03
190
191 /* flags for RAW_FILEINFO_SMB2_ALL_EAS */
192 #define SMB2_CONTINUE_FLAG_RESTART    0x01
193 #define SMB2_CONTINUE_FLAG_SINGLE     0x02
194
195 /* NOTE! the getinfo fs and file levels exactly match up with the
196    'passthru' SMB levels, which are levels >= 1000. The SMB2 client
197    lib uses the names from the libcli/raw/ library */
198
199 struct smb2_getinfo {
200         struct {
201                 /* static body buffer 40 (0x28) bytes */
202                 /* uint16_t buffer_code;  0x29 = 0x28 + 1 (why???) */
203                 uint16_t level;
204                 uint32_t max_response_size;
205                 uint32_t unknown1;
206                 uint32_t unknown2;
207                 uint32_t flags; /* level specific */
208                 uint32_t flags2; /* used by all_eas level */
209                 struct smb2_handle handle;
210         } in;
211
212         struct {
213                 /* static body buffer 8 (0x08) bytes */
214                 /* uint16_t buffer_code; 0x09 = 0x08 + 1 */
215                 /* uint16_t blob_ofs; */
216                 /* uint16_t blob_size; */
217
218                 /* dynamic body */
219                 DATA_BLOB blob;
220         } out;
221 };
222
223 struct smb2_setinfo {
224         struct {
225                 uint16_t level;
226                 uint32_t flags;
227                 struct smb2_handle handle;
228                 DATA_BLOB blob;
229         } in;
230 };
231
232 struct smb2_write {
233         struct {
234                 /* static body buffer 48 (0x30) bytes */
235                 /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
236                 /* uint16_t data_ofs; */
237                 /* uint32_t data_size; */
238                 uint64_t offset;
239                 struct smb2_handle handle;
240                 uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */
241                 uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */
242
243                 /* dynamic body */
244                 DATA_BLOB data;
245         } in;
246
247         struct {
248                 /* static body buffer 17 (0x11) bytes */
249                 /* uint16_t buffer_code;  0x11 */
250                 uint16_t _pad;
251                 uint32_t nwritten;
252                 uint64_t unknown1; /* 0x0000000000000000 */
253                 uint8_t _bug;
254         } out;
255 };
256
257 struct smb2_read {
258         struct {
259                 /* static body buffer 48 (0x30) bytes */
260                 /* uint16_t buffer_code;  0x31 = 0x30 + 1 */
261                 uint16_t _pad;
262                 uint32_t length;
263                 uint64_t offset;
264                 struct smb2_handle handle;
265                 uint64_t unknown1; /* 0x0000000000000000 */
266                 uint64_t unknown2; /* 0x0000000000000000 */
267                 uint8_t _bug;
268         } in;
269
270         struct {
271                 /* static body buffer 16 (0x10) bytes */
272                 /* uint16_t buffer_code;  0x11 = 0x10 + 1 */
273                 /* uint16_t data_ofs; */
274                 /* uint32_t data_size; */
275                 uint64_t unknown1; /* 0x0000000000000000 */
276
277                 /* dynamic body */
278                 DATA_BLOB data;
279         } out;
280 };
281
282 struct smb2_find {
283         struct {
284                 uint8_t level;
285                 uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */
286                 uint32_t unknown; /* perhaps a continue token? */
287                 struct smb2_handle handle;
288                 uint32_t max_response_size;
289                 const char *pattern;
290         } in;
291
292         struct {
293                 DATA_BLOB blob;
294         } out;
295 };