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