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