Merge branch 'v4-0-test' of ssh://git.samba.org/data/git/samba into 4-0-local
[sfrench/samba-autobuild/.git] / source4 / smb_server / smb2 / fileio.c
1 /* 
2    Unix SMB2 implementation.
3    
4    Copyright (C) Stefan Metzmacher      2005
5    
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10    
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15    
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "libcli/smb2/smb2.h"
22 #include "libcli/smb2/smb2_calls.h"
23 #include "smb_server/smb_server.h"
24 #include "smb_server/service_smb_proto.h"
25 #include "smb_server/smb2/smb2_server.h"
26 #include "ntvfs/ntvfs.h"
27 #include "param/param.h"
28 #include "libcli/raw/libcliraw.h"
29 #include "libcli/raw/raw_proto.h"
30 #include "librpc/gen_ndr/ndr_security.h"
31
32 static void smb2srv_create_send(struct ntvfs_request *ntvfs)
33 {
34         struct smb2srv_request *req;
35         union smb_open *io;
36         DATA_BLOB blob;
37
38         SMB2SRV_CHECK_ASYNC_STATUS(io, union smb_open);
39
40         /* setup the blobs we should give in the reply */
41         if (io->smb2.out.maximal_access != 0) {
42                 uint32_t data[2];
43                 SIVAL(data, 0, 0);
44                 SIVAL(data, 4, io->smb2.out.maximal_access);
45                 SMB2SRV_CHECK(smb2_create_blob_add(req, &io->smb2.out.blobs,
46                                                    SMB2_CREATE_TAG_MXAC, 
47                                                    data_blob_const(data, 8)));
48         }
49         
50
51         SMB2SRV_CHECK(smb2_create_blob_push(req, &blob, io->smb2.out.blobs));
52         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x58, true, blob.length));
53
54         SCVAL(req->out.body,    0x02,   io->smb2.out.oplock_level);
55         SCVAL(req->out.body,    0x03,   io->smb2.out.reserved);
56         SIVAL(req->out.body,    0x04,   io->smb2.out.create_action);
57         SBVAL(req->out.body,    0x08,   io->smb2.out.create_time);
58         SBVAL(req->out.body,    0x10,   io->smb2.out.access_time);
59         SBVAL(req->out.body,    0x18,   io->smb2.out.write_time);
60         SBVAL(req->out.body,    0x20,   io->smb2.out.change_time);
61         SBVAL(req->out.body,    0x28,   io->smb2.out.alloc_size);
62         SBVAL(req->out.body,    0x30,   io->smb2.out.size);
63         SIVAL(req->out.body,    0x38,   io->smb2.out.file_attr);
64         SIVAL(req->out.body,    0x3C,   io->smb2.out.reserved2);
65         smb2srv_push_handle(req->out.body, 0x40, io->smb2.out.file.ntvfs);
66         SMB2SRV_CHECK(smb2_push_o32s32_blob(&req->out, 0x50, blob));
67
68         /* also setup the chained file handle */
69         req->chained_file_handle = req->_chained_file_handle;
70         smb2srv_push_handle(req->chained_file_handle, 0, io->smb2.out.file.ntvfs);
71
72         smb2srv_send_reply(req);
73 }
74
75 void smb2srv_create_recv(struct smb2srv_request *req)
76 {
77         union smb_open *io;
78         DATA_BLOB blob;
79         int i;
80
81         SMB2SRV_CHECK_BODY_SIZE(req, 0x38, true);
82         SMB2SRV_TALLOC_IO_PTR(io, union smb_open);
83         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_create_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
84
85         ZERO_STRUCT(io->smb2.in);
86         io->smb2.level                  = RAW_OPEN_SMB2;
87         io->smb2.in.security_flags      = CVAL(req->in.body, 0x02);
88         io->smb2.in.oplock_level        = CVAL(req->in.body, 0x03);
89         io->smb2.in.impersonation_level = IVAL(req->in.body, 0x04);
90         io->smb2.in.create_flags        = BVAL(req->in.body, 0x08);
91         io->smb2.in.reserved            = BVAL(req->in.body, 0x10);
92         io->smb2.in.desired_access      = IVAL(req->in.body, 0x18);
93         io->smb2.in.file_attributes     = IVAL(req->in.body, 0x1C);
94         io->smb2.in.share_access        = IVAL(req->in.body, 0x20);
95         io->smb2.in.create_disposition  = IVAL(req->in.body, 0x24);
96         io->smb2.in.create_options      = IVAL(req->in.body, 0x28);
97         SMB2SRV_CHECK(smb2_pull_o16s16_string(&req->in, io, req->in.body+0x2C, &io->smb2.in.fname));
98         SMB2SRV_CHECK(smb2_pull_o32s32_blob(&req->in, io, req->in.body+0x30, &blob));
99         SMB2SRV_CHECK(smb2_create_blob_parse(io, blob, &io->smb2.in.blobs));
100
101         /* interpret the parsed tags that a server needs to respond to */
102         for (i=0;i<io->smb2.in.blobs.num_blobs;i++) {
103                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_EXTA) == 0) {
104                         SMB2SRV_CHECK(ea_pull_list_chained(&io->smb2.in.blobs.blobs[i].data, io, 
105                                                            &io->smb2.in.eas.num_eas,
106                                                            &io->smb2.in.eas.eas));
107                 }
108                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_SECD) == 0) {
109                         enum ndr_err_code ndr_err;
110                         io->smb2.in.sec_desc = talloc(io, struct security_descriptor);
111                         if (io->smb2.in.sec_desc == NULL) {
112                                 smb2srv_send_error(req,  NT_STATUS_NO_MEMORY);
113                                 return;
114                         }
115                         ndr_err = ndr_pull_struct_blob(&io->smb2.in.blobs.blobs[i].data, io, NULL,
116                                                        io->smb2.in.sec_desc,
117                                                        (ndr_pull_flags_fn_t)ndr_pull_security_descriptor);
118                         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
119                                 smb2srv_send_error(req,  ndr_map_error2ntstatus(ndr_err));
120                                 return;
121                         }
122                 }
123                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_DHNQ) == 0) {
124                         io->smb2.in.durable_open = true;
125                 }
126                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_DHNC) == 0) {
127                         if (io->smb2.in.blobs.blobs[i].data.length != 16) {
128                                 smb2srv_send_error(req,  NT_STATUS_INVALID_PARAMETER);
129                                 return;                         
130                         }
131                         io->smb2.in.durable_handle = talloc(io, struct smb2_handle);
132                         if (io->smb2.in.durable_handle == NULL) {
133                                 smb2srv_send_error(req,  NT_STATUS_NO_MEMORY);
134                                 return;
135                         }
136                         smb2_pull_handle(io->smb2.in.blobs.blobs[i].data.data, io->smb2.in.durable_handle);
137                 }
138                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_ALSI) == 0) {
139                         if (io->smb2.in.blobs.blobs[i].data.length != 8) {
140                                 smb2srv_send_error(req,  NT_STATUS_INVALID_PARAMETER);
141                                 return;                         
142                         }
143                         io->smb2.in.alloc_size = BVAL(io->smb2.in.blobs.blobs[i].data.data, 0);
144                 }
145                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_MXAC) == 0) {
146                         io->smb2.in.query_maximal_access = true;
147                 }
148                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_TWRP) == 0) {
149                         if (io->smb2.in.blobs.blobs[i].data.length != 8) {
150                                 smb2srv_send_error(req,  NT_STATUS_INVALID_PARAMETER);
151                                 return;                         
152                         }
153                         io->smb2.in.timewarp = BVAL(io->smb2.in.blobs.blobs[i].data.data, 0);                   
154                 }
155                 if (strcmp(io->smb2.in.blobs.blobs[i].tag, SMB2_CREATE_TAG_QFID) == 0) {
156                         io->smb2.in.query_on_disk_id = true;
157                 }
158         }
159                 
160         /* the VFS backend does not yet handle NULL filenames */
161         if (io->smb2.in.fname == NULL) {
162                 io->smb2.in.fname = "";
163         }
164
165         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_open(req->ntvfs, io));
166 }
167
168 static void smb2srv_close_send(struct ntvfs_request *ntvfs)
169 {
170         struct smb2srv_request *req;
171         union smb_close *io;
172
173         SMB2SRV_CHECK_ASYNC_STATUS(io, union smb_close);
174         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x3C, false, 0));
175
176         SSVAL(req->out.body,    0x02,   io->smb2.out.flags);
177         SIVAL(req->out.body,    0x04,   io->smb2.out._pad);
178         SBVAL(req->out.body,    0x08,   io->smb2.out.create_time);
179         SBVAL(req->out.body,    0x10,   io->smb2.out.access_time);
180         SBVAL(req->out.body,    0x18,   io->smb2.out.write_time);
181         SBVAL(req->out.body,    0x20,   io->smb2.out.change_time);
182         SBVAL(req->out.body,    0x28,   io->smb2.out.alloc_size);
183         SBVAL(req->out.body,    0x30,   io->smb2.out.size);
184         SIVAL(req->out.body,    0x38,   io->smb2.out.file_attr);
185
186         smb2srv_send_reply(req);
187 }
188
189 void smb2srv_close_recv(struct smb2srv_request *req)
190 {
191         union smb_close *io;
192
193         SMB2SRV_CHECK_BODY_SIZE(req, 0x18, false);
194         SMB2SRV_TALLOC_IO_PTR(io, union smb_close);
195         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_close_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
196
197         io->smb2.level                  = RAW_CLOSE_SMB2;
198         io->smb2.in.flags               = SVAL(req->in.body, 0x02);
199         io->smb2.in._pad                = IVAL(req->in.body, 0x04);
200         io->smb2.in.file.ntvfs          = smb2srv_pull_handle(req, req->in.body, 0x08);
201
202         SMB2SRV_CHECK_FILE_HANDLE(io->smb2.in.file.ntvfs);
203         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_close(req->ntvfs, io));
204 }
205
206 static void smb2srv_flush_send(struct ntvfs_request *ntvfs)
207 {
208         struct smb2srv_request *req;
209         union smb_flush *io;
210
211         SMB2SRV_CHECK_ASYNC_STATUS(io, union smb_flush);
212         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x04, false, 0));
213
214         SSVAL(req->out.body,    0x02,   io->smb2.out.reserved);
215
216         smb2srv_send_reply(req);
217 }
218
219 void smb2srv_flush_recv(struct smb2srv_request *req)
220 {
221         union smb_flush *io;
222
223         SMB2SRV_CHECK_BODY_SIZE(req, 0x18, false);
224         SMB2SRV_TALLOC_IO_PTR(io, union smb_flush);
225         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_flush_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
226
227         io->smb2.level                  = RAW_FLUSH_SMB2;
228         io->smb2.in.reserved1           = SVAL(req->in.body, 0x02);
229         io->smb2.in.reserved2           = IVAL(req->in.body, 0x04);
230         io->smb2.in.file.ntvfs          = smb2srv_pull_handle(req, req->in.body, 0x08);
231
232         SMB2SRV_CHECK_FILE_HANDLE(io->smb2.in.file.ntvfs);
233         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_flush(req->ntvfs, io));
234 }
235
236 static void smb2srv_read_send(struct ntvfs_request *ntvfs)
237 {
238         struct smb2srv_request *req;
239         union smb_read *io;
240
241         SMB2SRV_CHECK_ASYNC_STATUS(io, union smb_read);
242         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x10, true, io->smb2.out.data.length));
243
244         /* TODO: avoid the memcpy */
245         SMB2SRV_CHECK(smb2_push_o16s32_blob(&req->out, 0x02, io->smb2.out.data));
246         SIVAL(req->out.body,    0x08,   io->smb2.out.remaining);
247         SIVAL(req->out.body,    0x0C,   io->smb2.out.reserved);
248
249         smb2srv_send_reply(req);
250 }
251
252 void smb2srv_read_recv(struct smb2srv_request *req)
253 {
254         union smb_read *io;
255
256         SMB2SRV_CHECK_BODY_SIZE(req, 0x30, true);
257         SMB2SRV_TALLOC_IO_PTR(io, union smb_read);
258         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_read_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
259
260         io->smb2.level                  = RAW_READ_SMB2;
261         io->smb2.in._pad                = SVAL(req->in.body, 0x02);
262         io->smb2.in.length              = IVAL(req->in.body, 0x04);
263         io->smb2.in.offset              = BVAL(req->in.body, 0x08);
264         io->smb2.in.file.ntvfs          = smb2srv_pull_handle(req, req->in.body, 0x10);
265         io->smb2.in.min_count           = IVAL(req->in.body, 0x20);
266         io->smb2.in.channel             = IVAL(req->in.body, 0x24);
267         io->smb2.in.remaining           = IVAL(req->in.body, 0x28);
268         io->smb2.in.channel_offset      = SVAL(req->in.body, 0x2C);
269         io->smb2.in.channel_length      = SVAL(req->in.body, 0x2E);
270
271         SMB2SRV_CHECK_FILE_HANDLE(io->smb2.in.file.ntvfs);
272
273         /* preallocate the buffer for the backends */
274         io->smb2.out.data = data_blob_talloc(io, NULL, io->smb2.in.length);
275         if (io->smb2.out.data.length != io->smb2.in.length) {
276                 SMB2SRV_CHECK(NT_STATUS_NO_MEMORY);
277         }
278
279         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_read(req->ntvfs, io));
280 }
281
282 static void smb2srv_write_send(struct ntvfs_request *ntvfs)
283 {
284         struct smb2srv_request *req;
285         union smb_write *io;
286
287         SMB2SRV_CHECK_ASYNC_STATUS(io, union smb_write);
288         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x10, true, 0));
289
290         SSVAL(req->out.body,    0x02,   io->smb2.out._pad);
291         SIVAL(req->out.body,    0x04,   io->smb2.out.nwritten);
292         SBVAL(req->out.body,    0x08,   io->smb2.out.unknown1);
293
294         smb2srv_send_reply(req);
295 }
296
297 void smb2srv_write_recv(struct smb2srv_request *req)
298 {
299         union smb_write *io;
300
301         SMB2SRV_CHECK_BODY_SIZE(req, 0x30, true);
302         SMB2SRV_TALLOC_IO_PTR(io, union smb_write);
303         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_write_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
304
305         /* TODO: avoid the memcpy */
306         io->smb2.level                  = RAW_WRITE_SMB2;
307         SMB2SRV_CHECK(smb2_pull_o16s32_blob(&req->in, io, req->in.body+0x02, &io->smb2.in.data));
308         io->smb2.in.offset              = BVAL(req->in.body, 0x08);
309         io->smb2.in.file.ntvfs          = smb2srv_pull_handle(req, req->in.body, 0x10);
310         io->smb2.in.unknown1            = BVAL(req->in.body, 0x20);
311         io->smb2.in.unknown2            = BVAL(req->in.body, 0x28);
312
313         SMB2SRV_CHECK_FILE_HANDLE(io->smb2.in.file.ntvfs);
314         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_write(req->ntvfs, io));
315 }
316
317 static void smb2srv_lock_send(struct ntvfs_request *ntvfs)
318 {
319         struct smb2srv_request *req;
320         union smb_lock *io;
321
322         SMB2SRV_CHECK_ASYNC_STATUS_ERR(io, union smb_lock);
323         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x04, false, 0));
324
325         SSVAL(req->out.body,    0x02,   io->smb2.out.reserved);
326
327         smb2srv_send_reply(req);
328 }
329
330 void smb2srv_lock_recv(struct smb2srv_request *req)
331 {
332         union smb_lock *io;
333         int i;
334
335         SMB2SRV_CHECK_BODY_SIZE(req, 0x30, false);
336         SMB2SRV_TALLOC_IO_PTR(io, union smb_lock);
337         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_lock_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
338
339         io->smb2.level                  = RAW_LOCK_SMB2;
340         io->smb2.in.lock_count          = SVAL(req->in.body, 0x02);
341         io->smb2.in.reserved            = IVAL(req->in.body, 0x04);
342         io->smb2.in.file.ntvfs          = smb2srv_pull_handle(req, req->in.body, 0x08);
343         if (req->in.body_size < 24 + 24*(uint64_t)io->smb2.in.lock_count) {
344                 DEBUG(0,("%s: lock buffer too small\n", __location__));
345                 smb2srv_send_error(req,  NT_STATUS_FOOBAR);
346                 return;
347         }
348         io->smb2.in.locks = talloc_array(io, struct smb2_lock_element, 
349                                          io->smb2.in.lock_count);
350         if (io->smb2.in.locks == NULL) {
351                 smb2srv_send_error(req, NT_STATUS_NO_MEMORY);
352                 return;
353         }
354
355         for (i=0;i<io->smb2.in.lock_count;i++) {
356                 io->smb2.in.locks[i].offset     = BVAL(req->in.body, 24 + i*24);
357                 io->smb2.in.locks[i].length     = BVAL(req->in.body, 32 + i*24);
358                 io->smb2.in.locks[i].flags      = IVAL(req->in.body, 40 + i*24);
359                 io->smb2.in.locks[i].reserved   = IVAL(req->in.body, 44 + i*24);
360         }
361
362         SMB2SRV_CHECK_FILE_HANDLE(io->smb2.in.file.ntvfs);
363         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_lock(req->ntvfs, io));
364 }
365
366 static void smb2srv_ioctl_send(struct ntvfs_request *ntvfs)
367 {
368         struct smb2srv_request *req;
369         union smb_ioctl *io;
370
371         SMB2SRV_CHECK_ASYNC_STATUS_ERR(io, union smb_ioctl);
372         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x30, true, 0));
373
374         SSVAL(req->out.body,    0x02,   io->smb2.out._pad);
375         SIVAL(req->out.body,    0x04,   io->smb2.out.function);
376         if (io->smb2.level == RAW_IOCTL_SMB2_NO_HANDLE) {
377                 struct smb2_handle h;
378                 h.data[0] = UINT64_MAX;
379                 h.data[1] = UINT64_MAX;
380                 smb2_push_handle(req->out.body + 0x08, &h);
381         } else {
382                 smb2srv_push_handle(req->out.body, 0x08,io->smb2.in.file.ntvfs);
383         }
384         SMB2SRV_CHECK(smb2_push_o32s32_blob(&req->out, 0x18, io->smb2.out.in));
385         SMB2SRV_CHECK(smb2_push_o32s32_blob(&req->out, 0x20, io->smb2.out.out));
386         SIVAL(req->out.body,    0x28,   io->smb2.out.unknown2);
387         SIVAL(req->out.body,    0x2C,   io->smb2.out.unknown3);
388
389         smb2srv_send_reply(req);
390 }
391
392 void smb2srv_ioctl_recv(struct smb2srv_request *req)
393 {
394         union smb_ioctl *io;
395         struct smb2_handle h;
396
397         SMB2SRV_CHECK_BODY_SIZE(req, 0x38, true);
398         SMB2SRV_TALLOC_IO_PTR(io, union smb_ioctl);
399         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_ioctl_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
400
401         /* TODO: avoid the memcpy */
402         io->smb2.in._pad                = SVAL(req->in.body, 0x02);
403         io->smb2.in.function            = IVAL(req->in.body, 0x04);
404         /* file handle ... */
405         SMB2SRV_CHECK(smb2_pull_o32s32_blob(&req->in, io, req->in.body+0x18, &io->smb2.in.out));
406         io->smb2.in.unknown2            = IVAL(req->in.body, 0x20);
407         SMB2SRV_CHECK(smb2_pull_o32s32_blob(&req->in, io, req->in.body+0x24, &io->smb2.in.in));
408         io->smb2.in.max_response_size   = IVAL(req->in.body, 0x2C);
409         io->smb2.in.flags               = BVAL(req->in.body, 0x30);
410
411         smb2_pull_handle(req->in.body + 0x08, &h);
412         if (h.data[0] == UINT64_MAX && h.data[1] == UINT64_MAX) {
413                 io->smb2.level          = RAW_IOCTL_SMB2_NO_HANDLE;
414         } else {
415                 io->smb2.level          = RAW_IOCTL_SMB2;
416                 io->smb2.in.file.ntvfs  = smb2srv_pull_handle(req, req->in.body, 0x08);
417                 SMB2SRV_CHECK_FILE_HANDLE(io->smb2.in.file.ntvfs);
418         }
419
420         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_ioctl(req->ntvfs, io));
421 }
422
423 static void smb2srv_notify_send(struct ntvfs_request *ntvfs)
424 {
425         struct smb2srv_request *req;
426         union smb_notify *io;
427         size_t size = 0;
428         int i;
429         uint8_t *p;
430         DATA_BLOB blob = data_blob(NULL, 0);
431
432         SMB2SRV_CHECK_ASYNC_STATUS(io, union smb_notify);
433         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x08, true, 0));
434
435 #define MAX_BYTES_PER_CHAR 3
436         
437         /* work out how big the reply buffer could be */
438         for (i=0;i<io->smb2.out.num_changes;i++) {
439                 size += 12 + 3 + (1+strlen(io->smb2.out.changes[i].name.s)) * MAX_BYTES_PER_CHAR;
440         }
441
442         blob = data_blob_talloc(req, NULL, size);
443         if (size > 0 && !blob.data) {
444                 SMB2SRV_CHECK(NT_STATUS_NO_MEMORY);
445         }
446
447         p = blob.data;
448
449         /* construct the changes buffer */
450         for (i=0;i<io->smb2.out.num_changes;i++) {
451                 uint32_t ofs;
452                 ssize_t len;
453
454                 SIVAL(p, 4, io->smb2.out.changes[i].action);
455                 len = push_string(lp_iconv_convenience(ntvfs->ctx->lp_ctx), p + 12, io->smb2.out.changes[i].name.s, 
456                                   blob.length - (p+12 - blob.data), STR_UNICODE);
457                 SIVAL(p, 8, len);
458
459                 ofs = len + 12;
460
461                 if (ofs & 3) {
462                         int pad = 4 - (ofs & 3);
463                         memset(p+ofs, 0, pad);
464                         ofs += pad;
465                 }
466
467                 if (i == io->smb2.out.num_changes-1) {
468                         SIVAL(p, 0, 0);
469                 } else {
470                         SIVAL(p, 0, ofs);
471                 }
472
473                 p += ofs;
474         }
475
476         blob.length = p - blob.data;
477
478         SMB2SRV_CHECK(smb2_push_o16s32_blob(&req->out, 0x02, blob));
479
480         smb2srv_send_reply(req);
481 }
482
483 void smb2srv_notify_recv(struct smb2srv_request *req)
484 {
485         union smb_notify *io;
486
487         SMB2SRV_CHECK_BODY_SIZE(req, 0x20, false);
488         SMB2SRV_TALLOC_IO_PTR(io, union smb_notify);
489         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_notify_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
490
491         io->smb2.level                  = RAW_NOTIFY_SMB2;
492         io->smb2.in.recursive           = SVAL(req->in.body, 0x02);
493         io->smb2.in.buffer_size         = IVAL(req->in.body, 0x04);
494         io->smb2.in.file.ntvfs          = smb2srv_pull_handle(req, req->in.body, 0x08);
495         io->smb2.in.completion_filter   = IVAL(req->in.body, 0x18);
496         io->smb2.in.unknown             = BVAL(req->in.body, 0x1C);
497
498         SMB2SRV_CHECK_FILE_HANDLE(io->smb2.in.file.ntvfs);
499         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_notify(req->ntvfs, io));
500 }
501
502 static void smb2srv_break_send(struct ntvfs_request *ntvfs)
503 {
504         struct smb2srv_request *req;
505         union smb_lock *io;
506
507         SMB2SRV_CHECK_ASYNC_STATUS_ERR(io, union smb_lock);
508         SMB2SRV_CHECK(smb2srv_setup_reply(req, 0x18, false, 0));
509
510         SCVAL(req->out.body,    0x02,   io->smb2_break.out.oplock_level);
511         SCVAL(req->out.body,    0x03,   io->smb2_break.out.reserved);
512         SIVAL(req->out.body,    0x04,   io->smb2_break.out.reserved2);
513         smb2srv_push_handle(req->out.body, 0x08,io->smb2_break.out.file.ntvfs);
514
515         smb2srv_send_reply(req);
516 }
517
518 void smb2srv_break_recv(struct smb2srv_request *req)
519 {
520         union smb_lock *io;
521
522         SMB2SRV_CHECK_BODY_SIZE(req, 0x18, false);
523         SMB2SRV_TALLOC_IO_PTR(io, union smb_lock);
524         SMB2SRV_SETUP_NTVFS_REQUEST(smb2srv_break_send, NTVFS_ASYNC_STATE_MAY_ASYNC);
525
526         io->smb2_break.level            = RAW_LOCK_SMB2_BREAK;
527         io->smb2_break.in.oplock_level  = CVAL(req->in.body, 0x02);
528         io->smb2_break.in.reserved      = CVAL(req->in.body, 0x03);
529         io->smb2_break.in.reserved2     = IVAL(req->in.body, 0x04);
530         io->smb2_break.in.file.ntvfs    = smb2srv_pull_handle(req, req->in.body, 0x08);
531
532         SMB2SRV_CHECK_FILE_HANDLE(io->smb2_break.in.file.ntvfs);
533         SMB2SRV_CALL_NTVFS_BACKEND(ntvfs_lock(req->ntvfs, io));
534 }