2 Unix SMB/CIFS implementation.
3 Main SMB reply routines
4 Copyright (C) Andrew Tridgell 1992-2003
5 Copyright (C) James J Myers 2003 <myersjj@samba.org>
6 Copyright (C) Stefan Metzmacher 2006
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 3 of the License, or
11 (at your option) any later version.
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.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 This file handles most of the reply_ calls that the server
23 makes to handle specific SMB commands
27 #include "smb_server/smb_server.h"
28 #include "ntvfs/ntvfs.h"
29 #include "librpc/gen_ndr/ndr_nbt.h"
32 /****************************************************************************
33 Reply to a simple request (async send)
34 ****************************************************************************/
35 static void reply_simple_send(struct ntvfs_request
*ntvfs
)
37 struct smbsrv_request
*req
;
39 SMBSRV_CHECK_ASYNC_STATUS_SIMPLE
;
41 smbsrv_setup_reply(req
, 0, 0);
42 smbsrv_send_reply(req
);
46 /****************************************************************************
47 Reply to a tcon (async reply)
48 ****************************************************************************/
49 static void reply_tcon_send(struct ntvfs_request
*ntvfs
)
51 struct smbsrv_request
*req
;
54 SMBSRV_CHECK_ASYNC_STATUS(con
, union smb_tcon
);
57 smbsrv_setup_reply(req
, 2, 0);
59 SSVAL(req
->out
.vwv
, VWV(0), con
->tcon
.out
.max_xmit
);
60 SSVAL(req
->out
.vwv
, VWV(1), con
->tcon
.out
.tid
);
61 SSVAL(req
->out
.hdr
, HDR_TID
, req
->tcon
->tid
);
63 smbsrv_send_reply(req
);
66 /****************************************************************************
68 ****************************************************************************/
69 void smbsrv_reply_tcon(struct smbsrv_request
*req
)
76 SMBSRV_CHECK_WCT(req
, 0);
78 SMBSRV_TALLOC_IO_PTR(con
, union smb_tcon
);
80 con
->tcon
.level
= RAW_TCON_TCON
;
83 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &con
->tcon
.in
.service
, p
, STR_TERMINATE
);
84 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &con
->tcon
.in
.password
, p
, STR_TERMINATE
);
85 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &con
->tcon
.in
.dev
, p
, STR_TERMINATE
);
87 if (!con
->tcon
.in
.service
|| !con
->tcon
.in
.password
|| !con
->tcon
.in
.dev
) {
88 smbsrv_send_error(req
, NT_STATUS_INVALID_PARAMETER
);
92 /* Instantiate backend */
93 status
= smbsrv_tcon_backend(req
, con
);
94 if (!NT_STATUS_IS_OK(status
)) {
95 smbsrv_send_error(req
, status
);
99 SMBSRV_SETUP_NTVFS_REQUEST(reply_tcon_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
101 /* Invoke NTVFS connection hook */
102 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_connect(req
->ntvfs
, con
));
106 /****************************************************************************
107 Reply to a tcon and X (async reply)
108 ****************************************************************************/
109 static void reply_tcon_and_X_send(struct ntvfs_request
*ntvfs
)
111 struct smbsrv_request
*req
;
114 SMBSRV_CHECK_ASYNC_STATUS(con
, union smb_tcon
);
116 /* construct reply - two variants */
117 if (req
->smb_conn
->negotiate
.protocol
< PROTOCOL_NT1
) {
118 smbsrv_setup_reply(req
, 2, 0);
120 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
121 SSVAL(req
->out
.vwv
, VWV(1), 0);
123 req_push_str(req
, NULL
, con
->tconx
.out
.dev_type
, -1, STR_TERMINATE
|STR_ASCII
);
125 smbsrv_setup_reply(req
, 3, 0);
127 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
128 SSVAL(req
->out
.vwv
, VWV(1), 0);
129 SSVAL(req
->out
.vwv
, VWV(2), con
->tconx
.out
.options
);
131 req_push_str(req
, NULL
, con
->tconx
.out
.dev_type
, -1, STR_TERMINATE
|STR_ASCII
);
132 req_push_str(req
, NULL
, con
->tconx
.out
.fs_type
, -1, STR_TERMINATE
);
135 /* set the incoming and outgoing tid to the just created one */
136 SSVAL(req
->in
.hdr
, HDR_TID
, con
->tconx
.out
.tid
);
137 SSVAL(req
->out
.hdr
,HDR_TID
, con
->tconx
.out
.tid
);
139 smbsrv_chain_reply(req
);
142 /****************************************************************************
143 Reply to a tcon and X.
144 ****************************************************************************/
145 void smbsrv_reply_tcon_and_X(struct smbsrv_request
*req
)
152 SMBSRV_TALLOC_IO_PTR(con
, union smb_tcon
);
154 con
->tconx
.level
= RAW_TCON_TCONX
;
157 SMBSRV_CHECK_WCT(req
, 4);
159 con
->tconx
.in
.flags
= SVAL(req
->in
.vwv
, VWV(2));
160 passlen
= SVAL(req
->in
.vwv
, VWV(3));
164 if (!req_pull_blob(&req
->in
.bufinfo
, p
, passlen
, &con
->tconx
.in
.password
)) {
165 smbsrv_send_error(req
, NT_STATUS_ILL_FORMED_PASSWORD
);
170 p
+= req_pull_string(&req
->in
.bufinfo
, &con
->tconx
.in
.path
, p
, -1, STR_TERMINATE
);
171 p
+= req_pull_string(&req
->in
.bufinfo
, &con
->tconx
.in
.device
, p
, -1, STR_ASCII
);
173 if (!con
->tconx
.in
.path
|| !con
->tconx
.in
.device
) {
174 smbsrv_send_error(req
, NT_STATUS_BAD_DEVICE_TYPE
);
178 /* Instantiate backend */
179 status
= smbsrv_tcon_backend(req
, con
);
180 if (!NT_STATUS_IS_OK(status
)) {
181 smbsrv_send_error(req
, status
);
185 SMBSRV_SETUP_NTVFS_REQUEST(reply_tcon_and_X_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
187 /* Invoke NTVFS connection hook */
188 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_connect(req
->ntvfs
, con
));
192 /****************************************************************************
193 Reply to an unknown request
194 ****************************************************************************/
195 void smbsrv_reply_unknown(struct smbsrv_request
*req
)
199 type
= CVAL(req
->in
.hdr
, HDR_COM
);
201 DEBUG(0,("unknown command type %d (0x%X)\n", type
, type
));
203 smbsrv_send_error(req
, NT_STATUS_DOS(ERRSRV
, ERRunknownsmb
));
207 /****************************************************************************
208 Reply to an ioctl (async reply)
209 ****************************************************************************/
210 static void reply_ioctl_send(struct ntvfs_request
*ntvfs
)
212 struct smbsrv_request
*req
;
215 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_ioctl
);
217 /* the +1 is for nicer alignment */
218 smbsrv_setup_reply(req
, 8, io
->ioctl
.out
.blob
.length
+1);
219 SSVAL(req
->out
.vwv
, VWV(1), io
->ioctl
.out
.blob
.length
);
220 SSVAL(req
->out
.vwv
, VWV(5), io
->ioctl
.out
.blob
.length
);
221 SSVAL(req
->out
.vwv
, VWV(6), PTR_DIFF(req
->out
.data
, req
->out
.hdr
) + 1);
223 memcpy(req
->out
.data
+1, io
->ioctl
.out
.blob
.data
, io
->ioctl
.out
.blob
.length
);
225 smbsrv_send_reply(req
);
228 /****************************************************************************
230 ****************************************************************************/
231 void smbsrv_reply_ioctl(struct smbsrv_request
*req
)
236 SMBSRV_CHECK_WCT(req
, 3);
237 SMBSRV_TALLOC_IO_PTR(io
, union smb_ioctl
);
238 SMBSRV_SETUP_NTVFS_REQUEST(reply_ioctl_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
240 io
->ioctl
.level
= RAW_IOCTL_IOCTL
;
241 io
->ioctl
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
242 io
->ioctl
.in
.request
= IVAL(req
->in
.vwv
, VWV(1));
244 SMBSRV_CHECK_FILE_HANDLE_ERROR(io
->ioctl
.in
.file
.ntvfs
,
245 NT_STATUS_DOS(ERRSRV
, ERRerror
));
246 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_ioctl(req
->ntvfs
, io
));
250 /****************************************************************************
252 ****************************************************************************/
253 void smbsrv_reply_chkpth(struct smbsrv_request
*req
)
255 union smb_chkpath
*io
;
257 SMBSRV_TALLOC_IO_PTR(io
, union smb_chkpath
);
258 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
260 req_pull_ascii4(&req
->in
.bufinfo
, &io
->chkpath
.in
.path
, req
->in
.data
, STR_TERMINATE
);
262 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_chkpath(req
->ntvfs
, io
));
265 /****************************************************************************
266 Reply to a getatr (async reply)
267 ****************************************************************************/
268 static void reply_getatr_send(struct ntvfs_request
*ntvfs
)
270 struct smbsrv_request
*req
;
271 union smb_fileinfo
*st
;
273 SMBSRV_CHECK_ASYNC_STATUS(st
, union smb_fileinfo
);
275 /* construct reply */
276 smbsrv_setup_reply(req
, 10, 0);
278 SSVAL(req
->out
.vwv
, VWV(0), st
->getattr
.out
.attrib
);
279 srv_push_dos_date3(req
->smb_conn
, req
->out
.vwv
, VWV(1), st
->getattr
.out
.write_time
);
280 SIVAL(req
->out
.vwv
, VWV(3), st
->getattr
.out
.size
);
282 SMBSRV_VWV_RESERVED(5, 5);
284 smbsrv_send_reply(req
);
288 /****************************************************************************
290 ****************************************************************************/
291 void smbsrv_reply_getatr(struct smbsrv_request
*req
)
293 union smb_fileinfo
*st
;
295 SMBSRV_TALLOC_IO_PTR(st
, union smb_fileinfo
);
296 SMBSRV_SETUP_NTVFS_REQUEST(reply_getatr_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
298 st
->getattr
.level
= RAW_FILEINFO_GETATTR
;
301 req_pull_ascii4(&req
->in
.bufinfo
, &st
->getattr
.in
.file
.path
, req
->in
.data
, STR_TERMINATE
);
302 if (!st
->getattr
.in
.file
.path
) {
303 smbsrv_send_error(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
307 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_qpathinfo(req
->ntvfs
, st
));
311 /****************************************************************************
313 ****************************************************************************/
314 void smbsrv_reply_setatr(struct smbsrv_request
*req
)
316 union smb_setfileinfo
*st
;
319 SMBSRV_CHECK_WCT(req
, 8);
320 SMBSRV_TALLOC_IO_PTR(st
, union smb_setfileinfo
);
321 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
323 st
->setattr
.level
= RAW_SFILEINFO_SETATTR
;
324 st
->setattr
.in
.attrib
= SVAL(req
->in
.vwv
, VWV(0));
325 st
->setattr
.in
.write_time
= srv_pull_dos_date3(req
->smb_conn
, req
->in
.vwv
+ VWV(1));
327 req_pull_ascii4(&req
->in
.bufinfo
, &st
->setattr
.in
.file
.path
, req
->in
.data
, STR_TERMINATE
);
329 if (!st
->setattr
.in
.file
.path
) {
330 smbsrv_send_error(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
334 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_setpathinfo(req
->ntvfs
, st
));
338 /****************************************************************************
339 Reply to a dskattr (async reply)
340 ****************************************************************************/
341 static void reply_dskattr_send(struct ntvfs_request
*ntvfs
)
343 struct smbsrv_request
*req
;
344 union smb_fsinfo
*fs
;
346 SMBSRV_CHECK_ASYNC_STATUS(fs
, union smb_fsinfo
);
348 /* construct reply */
349 smbsrv_setup_reply(req
, 5, 0);
351 SSVAL(req
->out
.vwv
, VWV(0), fs
->dskattr
.out
.units_total
);
352 SSVAL(req
->out
.vwv
, VWV(1), fs
->dskattr
.out
.blocks_per_unit
);
353 SSVAL(req
->out
.vwv
, VWV(2), fs
->dskattr
.out
.block_size
);
354 SSVAL(req
->out
.vwv
, VWV(3), fs
->dskattr
.out
.units_free
);
356 SMBSRV_VWV_RESERVED(4, 1);
358 smbsrv_send_reply(req
);
362 /****************************************************************************
364 ****************************************************************************/
365 void smbsrv_reply_dskattr(struct smbsrv_request
*req
)
367 union smb_fsinfo
*fs
;
369 SMBSRV_TALLOC_IO_PTR(fs
, union smb_fsinfo
);
370 SMBSRV_SETUP_NTVFS_REQUEST(reply_dskattr_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
372 fs
->dskattr
.level
= RAW_QFS_DSKATTR
;
374 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_fsinfo(req
->ntvfs
, fs
));
378 /****************************************************************************
379 Reply to an open (async reply)
380 ****************************************************************************/
381 static void reply_open_send(struct ntvfs_request
*ntvfs
)
383 struct smbsrv_request
*req
;
386 SMBSRV_CHECK_ASYNC_STATUS(oi
, union smb_open
);
388 /* construct reply */
389 smbsrv_setup_reply(req
, 7, 0);
391 smbsrv_push_fnum(req
->out
.vwv
, VWV(0), oi
->openold
.out
.file
.ntvfs
);
392 SSVAL(req
->out
.vwv
, VWV(1), oi
->openold
.out
.attrib
);
393 srv_push_dos_date3(req
->smb_conn
, req
->out
.vwv
, VWV(2), oi
->openold
.out
.write_time
);
394 SIVAL(req
->out
.vwv
, VWV(4), oi
->openold
.out
.size
);
395 SSVAL(req
->out
.vwv
, VWV(6), oi
->openold
.out
.rmode
);
397 smbsrv_send_reply(req
);
400 /****************************************************************************
402 ****************************************************************************/
403 void smbsrv_reply_open(struct smbsrv_request
*req
)
408 SMBSRV_CHECK_WCT(req
, 2);
409 SMBSRV_TALLOC_IO_PTR(oi
, union smb_open
);
410 SMBSRV_SETUP_NTVFS_REQUEST(reply_open_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
412 oi
->openold
.level
= RAW_OPEN_OPEN
;
413 oi
->openold
.in
.open_mode
= SVAL(req
->in
.vwv
, VWV(0));
414 oi
->openold
.in
.search_attrs
= SVAL(req
->in
.vwv
, VWV(1));
416 req_pull_ascii4(&req
->in
.bufinfo
, &oi
->openold
.in
.fname
, req
->in
.data
, STR_TERMINATE
);
418 if (!oi
->openold
.in
.fname
) {
419 smbsrv_send_error(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
423 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_open(req
->ntvfs
, oi
));
427 /****************************************************************************
428 Reply to an open and X (async reply)
429 ****************************************************************************/
430 static void reply_open_and_X_send(struct ntvfs_request
*ntvfs
)
432 struct smbsrv_request
*req
;
435 SMBSRV_CHECK_ASYNC_STATUS(oi
, union smb_open
);
437 /* build the reply */
438 if (oi
->openx
.in
.flags
& OPENX_FLAGS_EXTENDED_RETURN
) {
439 smbsrv_setup_reply(req
, 19, 0);
441 smbsrv_setup_reply(req
, 15, 0);
444 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
445 SSVAL(req
->out
.vwv
, VWV(1), 0);
446 smbsrv_push_fnum(req
->out
.vwv
, VWV(2), oi
->openx
.out
.file
.ntvfs
);
447 SSVAL(req
->out
.vwv
, VWV(3), oi
->openx
.out
.attrib
);
448 srv_push_dos_date3(req
->smb_conn
, req
->out
.vwv
, VWV(4), oi
->openx
.out
.write_time
);
449 SIVAL(req
->out
.vwv
, VWV(6), oi
->openx
.out
.size
);
450 SSVAL(req
->out
.vwv
, VWV(8), oi
->openx
.out
.access
);
451 SSVAL(req
->out
.vwv
, VWV(9), oi
->openx
.out
.ftype
);
452 SSVAL(req
->out
.vwv
, VWV(10),oi
->openx
.out
.devstate
);
453 SSVAL(req
->out
.vwv
, VWV(11),oi
->openx
.out
.action
);
454 SIVAL(req
->out
.vwv
, VWV(12),oi
->openx
.out
.unique_fid
);
455 SSVAL(req
->out
.vwv
, VWV(14),0); /* reserved */
456 if (oi
->openx
.in
.flags
& OPENX_FLAGS_EXTENDED_RETURN
) {
457 SIVAL(req
->out
.vwv
, VWV(15),oi
->openx
.out
.access_mask
);
458 SMBSRV_VWV_RESERVED(17, 2);
461 req
->chained_fnum
= SVAL(req
->out
.vwv
, VWV(2));
463 smbsrv_chain_reply(req
);
467 /****************************************************************************
468 Reply to an open and X.
469 ****************************************************************************/
470 void smbsrv_reply_open_and_X(struct smbsrv_request
*req
)
474 /* parse the request */
475 SMBSRV_CHECK_WCT(req
, 15);
476 SMBSRV_TALLOC_IO_PTR(oi
, union smb_open
);
477 SMBSRV_SETUP_NTVFS_REQUEST(reply_open_and_X_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
479 oi
->openx
.level
= RAW_OPEN_OPENX
;
480 oi
->openx
.in
.flags
= SVAL(req
->in
.vwv
, VWV(2));
481 oi
->openx
.in
.open_mode
= SVAL(req
->in
.vwv
, VWV(3));
482 oi
->openx
.in
.search_attrs
= SVAL(req
->in
.vwv
, VWV(4));
483 oi
->openx
.in
.file_attrs
= SVAL(req
->in
.vwv
, VWV(5));
484 oi
->openx
.in
.write_time
= srv_pull_dos_date3(req
->smb_conn
, req
->in
.vwv
+ VWV(6));
485 oi
->openx
.in
.open_func
= SVAL(req
->in
.vwv
, VWV(8));
486 oi
->openx
.in
.size
= IVAL(req
->in
.vwv
, VWV(9));
487 oi
->openx
.in
.timeout
= IVAL(req
->in
.vwv
, VWV(11));
489 req_pull_ascii4(&req
->in
.bufinfo
, &oi
->openx
.in
.fname
, req
->in
.data
, STR_TERMINATE
);
491 if (!oi
->openx
.in
.fname
) {
492 smbsrv_send_error(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
496 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_open(req
->ntvfs
, oi
));
500 /****************************************************************************
501 Reply to a mknew or a create.
502 ****************************************************************************/
503 static void reply_mknew_send(struct ntvfs_request
*ntvfs
)
505 struct smbsrv_request
*req
;
508 SMBSRV_CHECK_ASYNC_STATUS(oi
, union smb_open
);
510 /* build the reply */
511 smbsrv_setup_reply(req
, 1, 0);
513 smbsrv_push_fnum(req
->out
.vwv
, VWV(0), oi
->mknew
.out
.file
.ntvfs
);
515 smbsrv_send_reply(req
);
519 /****************************************************************************
520 Reply to a mknew or a create.
521 ****************************************************************************/
522 void smbsrv_reply_mknew(struct smbsrv_request
*req
)
526 /* parse the request */
527 SMBSRV_CHECK_WCT(req
, 3);
528 SMBSRV_TALLOC_IO_PTR(oi
, union smb_open
);
529 SMBSRV_SETUP_NTVFS_REQUEST(reply_mknew_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
531 if (CVAL(req
->in
.hdr
, HDR_COM
) == SMBmknew
) {
532 oi
->mknew
.level
= RAW_OPEN_MKNEW
;
534 oi
->mknew
.level
= RAW_OPEN_CREATE
;
536 oi
->mknew
.in
.attrib
= SVAL(req
->in
.vwv
, VWV(0));
537 oi
->mknew
.in
.write_time
= srv_pull_dos_date3(req
->smb_conn
, req
->in
.vwv
+ VWV(1));
539 req_pull_ascii4(&req
->in
.bufinfo
, &oi
->mknew
.in
.fname
, req
->in
.data
, STR_TERMINATE
);
541 if (!oi
->mknew
.in
.fname
) {
542 smbsrv_send_error(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
546 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_open(req
->ntvfs
, oi
));
549 /****************************************************************************
550 Reply to a create temporary file (async reply)
551 ****************************************************************************/
552 static void reply_ctemp_send(struct ntvfs_request
*ntvfs
)
554 struct smbsrv_request
*req
;
557 SMBSRV_CHECK_ASYNC_STATUS(oi
, union smb_open
);
559 /* build the reply */
560 smbsrv_setup_reply(req
, 1, 0);
562 smbsrv_push_fnum(req
->out
.vwv
, VWV(0), oi
->ctemp
.out
.file
.ntvfs
);
564 /* the returned filename is relative to the directory */
565 req_push_str(req
, NULL
, oi
->ctemp
.out
.name
, -1, STR_TERMINATE
| STR_ASCII
);
567 smbsrv_send_reply(req
);
570 /****************************************************************************
571 Reply to a create temporary file.
572 ****************************************************************************/
573 void smbsrv_reply_ctemp(struct smbsrv_request
*req
)
577 /* parse the request */
578 SMBSRV_CHECK_WCT(req
, 3);
579 SMBSRV_TALLOC_IO_PTR(oi
, union smb_open
);
580 SMBSRV_SETUP_NTVFS_REQUEST(reply_ctemp_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
582 oi
->ctemp
.level
= RAW_OPEN_CTEMP
;
583 oi
->ctemp
.in
.attrib
= SVAL(req
->in
.vwv
, VWV(0));
584 oi
->ctemp
.in
.write_time
= srv_pull_dos_date3(req
->smb_conn
, req
->in
.vwv
+ VWV(1));
586 /* the filename is actually a directory name, the server provides a filename
588 req_pull_ascii4(&req
->in
.bufinfo
, &oi
->ctemp
.in
.directory
, req
->in
.data
, STR_TERMINATE
);
590 if (!oi
->ctemp
.in
.directory
) {
591 smbsrv_send_error(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
);
595 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_open(req
->ntvfs
, oi
));
599 /****************************************************************************
601 ****************************************************************************/
602 void smbsrv_reply_unlink(struct smbsrv_request
*req
)
604 union smb_unlink
*unl
;
606 /* parse the request */
607 SMBSRV_CHECK_WCT(req
, 1);
608 SMBSRV_TALLOC_IO_PTR(unl
, union smb_unlink
);
609 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
611 unl
->unlink
.in
.attrib
= SVAL(req
->in
.vwv
, VWV(0));
613 req_pull_ascii4(&req
->in
.bufinfo
, &unl
->unlink
.in
.pattern
, req
->in
.data
, STR_TERMINATE
);
615 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_unlink(req
->ntvfs
, unl
));
619 /****************************************************************************
620 Reply to a readbraw (core+ protocol).
621 this is a strange packet because it doesn't use a standard SMB header in the reply,
622 only the 4 byte NBT header
623 This command must be replied to synchronously
624 ****************************************************************************/
625 void smbsrv_reply_readbraw(struct smbsrv_request
*req
)
630 io
.readbraw
.level
= RAW_READ_READBRAW
;
632 /* there are two variants, one with 10 and one with 8 command words */
633 if (req
->in
.wct
< 8) {
637 io
.readbraw
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
638 io
.readbraw
.in
.offset
= IVAL(req
->in
.vwv
, VWV(1));
639 io
.readbraw
.in
.maxcnt
= SVAL(req
->in
.vwv
, VWV(3));
640 io
.readbraw
.in
.mincnt
= SVAL(req
->in
.vwv
, VWV(4));
641 io
.readbraw
.in
.timeout
= IVAL(req
->in
.vwv
, VWV(5));
643 if (!io
.readbraw
.in
.file
.ntvfs
) {
647 /* the 64 bit variant */
648 if (req
->in
.wct
== 10) {
649 uint32_t offset_high
= IVAL(req
->in
.vwv
, VWV(8));
650 io
.readbraw
.in
.offset
|= (((off_t
)offset_high
) << 32);
653 /* before calling the backend we setup the raw buffer. This
654 * saves a copy later */
655 req
->out
.size
= io
.readbraw
.in
.maxcnt
+ NBT_HDR_SIZE
;
656 req
->out
.buffer
= talloc_size(req
, req
->out
.size
);
657 if (req
->out
.buffer
== NULL
) {
660 SIVAL(req
->out
.buffer
, 0, 0); /* init NBT header */
662 /* tell the backend where to put the data */
663 io
.readbraw
.out
.data
= req
->out
.buffer
+ NBT_HDR_SIZE
;
665 /* prepare the ntvfs request */
666 req
->ntvfs
= ntvfs_request_create(req
->tcon
->ntvfs
, req
,
667 req
->session
->session_info
,
668 SVAL(req
->in
.hdr
,HDR_PID
),
675 /* call the backend */
676 status
= ntvfs_read(req
->ntvfs
, &io
);
677 if (!NT_STATUS_IS_OK(status
)) {
681 req
->out
.size
= io
.readbraw
.out
.nread
+ NBT_HDR_SIZE
;
683 smbsrv_send_reply_nosign(req
);
687 /* any failure in readbraw is equivalent to reading zero bytes */
689 req
->out
.buffer
= talloc_size(req
, req
->out
.size
);
690 SIVAL(req
->out
.buffer
, 0, 0); /* init NBT header */
692 smbsrv_send_reply_nosign(req
);
696 /****************************************************************************
697 Reply to a lockread (async reply)
698 ****************************************************************************/
699 static void reply_lockread_send(struct ntvfs_request
*ntvfs
)
701 struct smbsrv_request
*req
;
704 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_read
);
707 io
->lockread
.out
.nread
= MIN(io
->lockread
.out
.nread
,
708 req_max_data(req
) - 3);
709 req_grow_data(req
, 3 + io
->lockread
.out
.nread
);
711 /* construct reply */
712 SSVAL(req
->out
.vwv
, VWV(0), io
->lockread
.out
.nread
);
713 SMBSRV_VWV_RESERVED(1, 4);
715 SCVAL(req
->out
.data
, 0, SMB_DATA_BLOCK
);
716 SSVAL(req
->out
.data
, 1, io
->lockread
.out
.nread
);
718 smbsrv_send_reply(req
);
722 /****************************************************************************
723 Reply to a lockread (core+ protocol).
724 note that the lock is a write lock, not a read lock!
725 ****************************************************************************/
726 void smbsrv_reply_lockread(struct smbsrv_request
*req
)
731 SMBSRV_CHECK_WCT(req
, 5);
732 SMBSRV_TALLOC_IO_PTR(io
, union smb_read
);
733 SMBSRV_SETUP_NTVFS_REQUEST(reply_lockread_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
735 io
->lockread
.level
= RAW_READ_LOCKREAD
;
736 io
->lockread
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
737 io
->lockread
.in
.count
= SVAL(req
->in
.vwv
, VWV(1));
738 io
->lockread
.in
.offset
= IVAL(req
->in
.vwv
, VWV(2));
739 io
->lockread
.in
.remaining
= SVAL(req
->in
.vwv
, VWV(4));
741 /* setup the reply packet assuming the maximum possible read */
742 smbsrv_setup_reply(req
, 5, 3 + io
->lockread
.in
.count
);
744 /* tell the backend where to put the data */
745 io
->lockread
.out
.data
= req
->out
.data
+ 3;
747 SMBSRV_CHECK_FILE_HANDLE(io
->lockread
.in
.file
.ntvfs
);
748 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_read(req
->ntvfs
, io
));
753 /****************************************************************************
754 Reply to a read (async reply)
755 ****************************************************************************/
756 static void reply_read_send(struct ntvfs_request
*ntvfs
)
758 struct smbsrv_request
*req
;
761 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_read
);
764 io
->read
.out
.nread
= MIN(io
->read
.out
.nread
,
765 req_max_data(req
) - 3);
766 req_grow_data(req
, 3 + io
->read
.out
.nread
);
768 /* construct reply */
769 SSVAL(req
->out
.vwv
, VWV(0), io
->read
.out
.nread
);
770 SMBSRV_VWV_RESERVED(1, 4);
772 SCVAL(req
->out
.data
, 0, SMB_DATA_BLOCK
);
773 SSVAL(req
->out
.data
, 1, io
->read
.out
.nread
);
775 smbsrv_send_reply(req
);
778 /****************************************************************************
780 ****************************************************************************/
781 void smbsrv_reply_read(struct smbsrv_request
*req
)
786 SMBSRV_CHECK_WCT(req
, 5);
787 SMBSRV_TALLOC_IO_PTR(io
, union smb_read
);
788 SMBSRV_SETUP_NTVFS_REQUEST(reply_read_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
790 io
->read
.level
= RAW_READ_READ
;
791 io
->read
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
792 io
->read
.in
.count
= SVAL(req
->in
.vwv
, VWV(1));
793 io
->read
.in
.offset
= IVAL(req
->in
.vwv
, VWV(2));
794 io
->read
.in
.remaining
= SVAL(req
->in
.vwv
, VWV(4));
796 /* setup the reply packet assuming the maximum possible read */
797 smbsrv_setup_reply(req
, 5, 3 + io
->read
.in
.count
);
799 /* tell the backend where to put the data */
800 io
->read
.out
.data
= req
->out
.data
+ 3;
802 SMBSRV_CHECK_FILE_HANDLE(io
->read
.in
.file
.ntvfs
);
803 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_read(req
->ntvfs
, io
));
806 /****************************************************************************
807 Reply to a read and X (async reply)
808 ****************************************************************************/
809 static void reply_read_and_X_send(struct ntvfs_request
*ntvfs
)
811 struct smbsrv_request
*req
;
814 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_read
);
816 /* readx reply packets can be over-sized */
817 req
->control_flags
|= SMBSRV_REQ_CONTROL_LARGE
;
818 if (io
->readx
.in
.maxcnt
!= 0xFFFF &&
819 io
->readx
.in
.mincnt
!= 0xFFFF) {
820 req_grow_data(req
, 1 + io
->readx
.out
.nread
);
821 SCVAL(req
->out
.data
, 0, 0); /* padding */
823 req_grow_data(req
, io
->readx
.out
.nread
);
826 /* construct reply */
827 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
828 SSVAL(req
->out
.vwv
, VWV(1), 0);
829 SSVAL(req
->out
.vwv
, VWV(2), io
->readx
.out
.remaining
);
830 SSVAL(req
->out
.vwv
, VWV(3), io
->readx
.out
.compaction_mode
);
831 SMBSRV_VWV_RESERVED(4, 1);
832 SSVAL(req
->out
.vwv
, VWV(5), io
->readx
.out
.nread
);
833 SSVAL(req
->out
.vwv
, VWV(6), PTR_DIFF(io
->readx
.out
.data
, req
->out
.hdr
));
834 SMBSRV_VWV_RESERVED(7, 5);
836 smbsrv_chain_reply(req
);
839 /****************************************************************************
840 Reply to a read and X.
841 ****************************************************************************/
842 void smbsrv_reply_read_and_X(struct smbsrv_request
*req
)
847 if (req
->in
.wct
!= 12) {
848 SMBSRV_CHECK_WCT(req
, 10);
851 SMBSRV_TALLOC_IO_PTR(io
, union smb_read
);
852 SMBSRV_SETUP_NTVFS_REQUEST(reply_read_and_X_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
854 io
->readx
.level
= RAW_READ_READX
;
855 io
->readx
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(2));
856 io
->readx
.in
.offset
= IVAL(req
->in
.vwv
, VWV(3));
857 io
->readx
.in
.maxcnt
= SVAL(req
->in
.vwv
, VWV(5));
858 io
->readx
.in
.mincnt
= SVAL(req
->in
.vwv
, VWV(6));
859 io
->readx
.in
.remaining
= SVAL(req
->in
.vwv
, VWV(9));
860 if (req
->flags2
& FLAGS2_READ_PERMIT_EXECUTE
) {
861 io
->readx
.in
.read_for_execute
= true;
863 io
->readx
.in
.read_for_execute
= false;
866 if (req
->smb_conn
->negotiate
.client_caps
& CAP_LARGE_READX
) {
867 uint32_t high_part
= IVAL(req
->in
.vwv
, VWV(7));
868 if (high_part
== 1) {
869 io
->readx
.in
.maxcnt
|= high_part
<< 16;
873 /* the 64 bit variant */
874 if (req
->in
.wct
== 12) {
875 uint32_t offset_high
= IVAL(req
->in
.vwv
, VWV(10));
876 io
->readx
.in
.offset
|= (((uint64_t)offset_high
) << 32);
879 /* setup the reply packet assuming the maximum possible read */
880 smbsrv_setup_reply(req
, 12, 1 + io
->readx
.in
.maxcnt
);
882 /* tell the backend where to put the data. Notice the pad byte. */
883 if (io
->readx
.in
.maxcnt
!= 0xFFFF &&
884 io
->readx
.in
.mincnt
!= 0xFFFF) {
885 io
->readx
.out
.data
= req
->out
.data
+ 1;
887 io
->readx
.out
.data
= req
->out
.data
;
890 SMBSRV_CHECK_FILE_HANDLE(io
->readx
.in
.file
.ntvfs
);
891 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_read(req
->ntvfs
, io
));
895 /****************************************************************************
896 Reply to a writebraw (core+ or LANMAN1.0 protocol).
897 ****************************************************************************/
898 void smbsrv_reply_writebraw(struct smbsrv_request
*req
)
900 smbsrv_send_error(req
, NT_STATUS_DOS(ERRSRV
, ERRuseSTD
));
904 /****************************************************************************
905 Reply to a writeunlock (async reply)
906 ****************************************************************************/
907 static void reply_writeunlock_send(struct ntvfs_request
*ntvfs
)
909 struct smbsrv_request
*req
;
912 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_write
);
914 /* construct reply */
915 smbsrv_setup_reply(req
, 1, 0);
917 SSVAL(req
->out
.vwv
, VWV(0), io
->writeunlock
.out
.nwritten
);
919 smbsrv_send_reply(req
);
922 /****************************************************************************
923 Reply to a writeunlock (core+).
924 ****************************************************************************/
925 void smbsrv_reply_writeunlock(struct smbsrv_request
*req
)
929 SMBSRV_CHECK_WCT(req
, 5);
930 SMBSRV_TALLOC_IO_PTR(io
, union smb_write
);
931 SMBSRV_SETUP_NTVFS_REQUEST(reply_writeunlock_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
933 io
->writeunlock
.level
= RAW_WRITE_WRITEUNLOCK
;
934 io
->writeunlock
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
935 io
->writeunlock
.in
.count
= SVAL(req
->in
.vwv
, VWV(1));
936 io
->writeunlock
.in
.offset
= IVAL(req
->in
.vwv
, VWV(2));
937 io
->writeunlock
.in
.remaining
= SVAL(req
->in
.vwv
, VWV(4));
938 io
->writeunlock
.in
.data
= req
->in
.data
+ 3;
940 /* make sure they gave us the data they promised */
941 if (io
->writeunlock
.in
.count
+3 > req
->in
.data_size
) {
942 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
946 /* make sure the data block is big enough */
947 if (SVAL(req
->in
.data
, 1) < io
->writeunlock
.in
.count
) {
948 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
952 SMBSRV_CHECK_FILE_HANDLE(io
->writeunlock
.in
.file
.ntvfs
);
953 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_write(req
->ntvfs
, io
));
958 /****************************************************************************
959 Reply to a write (async reply)
960 ****************************************************************************/
961 static void reply_write_send(struct ntvfs_request
*ntvfs
)
963 struct smbsrv_request
*req
;
966 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_write
);
968 /* construct reply */
969 smbsrv_setup_reply(req
, 1, 0);
971 SSVAL(req
->out
.vwv
, VWV(0), io
->write
.out
.nwritten
);
973 smbsrv_send_reply(req
);
976 /****************************************************************************
978 ****************************************************************************/
979 void smbsrv_reply_write(struct smbsrv_request
*req
)
983 SMBSRV_CHECK_WCT(req
, 5);
984 SMBSRV_TALLOC_IO_PTR(io
, union smb_write
);
985 SMBSRV_SETUP_NTVFS_REQUEST(reply_write_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
987 io
->write
.level
= RAW_WRITE_WRITE
;
988 io
->write
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
989 io
->write
.in
.count
= SVAL(req
->in
.vwv
, VWV(1));
990 io
->write
.in
.offset
= IVAL(req
->in
.vwv
, VWV(2));
991 io
->write
.in
.remaining
= SVAL(req
->in
.vwv
, VWV(4));
992 io
->write
.in
.data
= req
->in
.data
+ 3;
994 /* make sure they gave us the data they promised */
995 if (req_data_oob(&req
->in
.bufinfo
, io
->write
.in
.data
, io
->write
.in
.count
)) {
996 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1000 /* make sure the data block is big enough */
1001 if (SVAL(req
->in
.data
, 1) < io
->write
.in
.count
) {
1002 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1006 SMBSRV_CHECK_FILE_HANDLE(io
->write
.in
.file
.ntvfs
);
1007 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_write(req
->ntvfs
, io
));
1011 /****************************************************************************
1012 Reply to a write and X (async reply)
1013 ****************************************************************************/
1014 static void reply_write_and_X_send(struct ntvfs_request
*ntvfs
)
1016 struct smbsrv_request
*req
;
1017 union smb_write
*io
;
1019 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_write
);
1021 /* construct reply */
1022 smbsrv_setup_reply(req
, 6, 0);
1024 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
1025 SSVAL(req
->out
.vwv
, VWV(1), 0);
1026 SSVAL(req
->out
.vwv
, VWV(2), io
->writex
.out
.nwritten
& 0xFFFF);
1027 SSVAL(req
->out
.vwv
, VWV(3), io
->writex
.out
.remaining
);
1028 SSVAL(req
->out
.vwv
, VWV(4), io
->writex
.out
.nwritten
>> 16);
1029 SMBSRV_VWV_RESERVED(5, 1);
1031 smbsrv_chain_reply(req
);
1034 /****************************************************************************
1035 Reply to a write and X.
1036 ****************************************************************************/
1037 void smbsrv_reply_write_and_X(struct smbsrv_request
*req
)
1039 union smb_write
*io
;
1041 if (req
->in
.wct
!= 14) {
1042 SMBSRV_CHECK_WCT(req
, 12);
1045 SMBSRV_TALLOC_IO_PTR(io
, union smb_write
);
1046 SMBSRV_SETUP_NTVFS_REQUEST(reply_write_and_X_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1048 io
->writex
.level
= RAW_WRITE_WRITEX
;
1049 io
->writex
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(2));
1050 io
->writex
.in
.offset
= IVAL(req
->in
.vwv
, VWV(3));
1051 io
->writex
.in
.wmode
= SVAL(req
->in
.vwv
, VWV(7));
1052 io
->writex
.in
.remaining
= SVAL(req
->in
.vwv
, VWV(8));
1053 io
->writex
.in
.count
= SVAL(req
->in
.vwv
, VWV(10));
1054 io
->writex
.in
.data
= req
->in
.hdr
+ SVAL(req
->in
.vwv
, VWV(11));
1056 if (req
->in
.wct
== 14) {
1057 uint32_t offset_high
= IVAL(req
->in
.vwv
, VWV(12));
1058 uint16_t count_high
= SVAL(req
->in
.vwv
, VWV(9));
1059 io
->writex
.in
.offset
|= (((uint64_t)offset_high
) << 32);
1060 io
->writex
.in
.count
|= ((uint32_t)count_high
) << 16;
1063 /* make sure the data is in bounds */
1064 if (req_data_oob(&req
->in
.bufinfo
, io
->writex
.in
.data
, io
->writex
.in
.count
)) {
1065 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1069 SMBSRV_CHECK_FILE_HANDLE(io
->writex
.in
.file
.ntvfs
);
1070 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_write(req
->ntvfs
, io
));
1074 /****************************************************************************
1075 Reply to a lseek (async reply)
1076 ****************************************************************************/
1077 static void reply_lseek_send(struct ntvfs_request
*ntvfs
)
1079 struct smbsrv_request
*req
;
1082 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_seek
);
1084 /* construct reply */
1085 smbsrv_setup_reply(req
, 2, 0);
1087 SIVALS(req
->out
.vwv
, VWV(0), io
->lseek
.out
.offset
);
1089 smbsrv_send_reply(req
);
1092 /****************************************************************************
1094 ****************************************************************************/
1095 void smbsrv_reply_lseek(struct smbsrv_request
*req
)
1099 SMBSRV_CHECK_WCT(req
, 4);
1100 SMBSRV_TALLOC_IO_PTR(io
, union smb_seek
);
1101 SMBSRV_SETUP_NTVFS_REQUEST(reply_lseek_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1103 io
->lseek
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1104 io
->lseek
.in
.mode
= SVAL(req
->in
.vwv
, VWV(1));
1105 io
->lseek
.in
.offset
= IVALS(req
->in
.vwv
, VWV(2));
1107 SMBSRV_CHECK_FILE_HANDLE(io
->lseek
.in
.file
.ntvfs
);
1108 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_seek(req
->ntvfs
, io
));
1111 /****************************************************************************
1113 ****************************************************************************/
1114 void smbsrv_reply_flush(struct smbsrv_request
*req
)
1116 union smb_flush
*io
;
1120 SMBSRV_CHECK_WCT(req
, 1);
1121 SMBSRV_TALLOC_IO_PTR(io
, union smb_flush
);
1122 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1124 fnum
= SVAL(req
->in
.vwv
, VWV(0));
1125 if (fnum
== 0xFFFF) {
1126 io
->flush_all
.level
= RAW_FLUSH_ALL
;
1128 io
->flush
.level
= RAW_FLUSH_FLUSH
;
1129 io
->flush
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1130 SMBSRV_CHECK_FILE_HANDLE(io
->flush
.in
.file
.ntvfs
);
1133 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_flush(req
->ntvfs
, io
));
1136 /****************************************************************************
1139 Note that this has to deal with closing a directory opened by NT SMB's.
1140 ****************************************************************************/
1141 void smbsrv_reply_close(struct smbsrv_request
*req
)
1143 union smb_close
*io
;
1146 SMBSRV_CHECK_WCT(req
, 3);
1147 SMBSRV_TALLOC_IO_PTR(io
, union smb_close
);
1148 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1150 io
->close
.level
= RAW_CLOSE_CLOSE
;
1151 io
->close
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1152 io
->close
.in
.write_time
= srv_pull_dos_date3(req
->smb_conn
, req
->in
.vwv
+ VWV(1));
1154 SMBSRV_CHECK_FILE_HANDLE(io
->close
.in
.file
.ntvfs
);
1155 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_close(req
->ntvfs
, io
));
1159 /****************************************************************************
1160 Reply to a writeclose (async reply)
1161 ****************************************************************************/
1162 static void reply_writeclose_send(struct ntvfs_request
*ntvfs
)
1164 struct smbsrv_request
*req
;
1165 union smb_write
*io
;
1167 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_write
);
1169 /* construct reply */
1170 smbsrv_setup_reply(req
, 1, 0);
1172 SSVAL(req
->out
.vwv
, VWV(0), io
->write
.out
.nwritten
);
1174 smbsrv_send_reply(req
);
1177 /****************************************************************************
1178 Reply to a writeclose (Core+ protocol).
1179 ****************************************************************************/
1180 void smbsrv_reply_writeclose(struct smbsrv_request
*req
)
1182 union smb_write
*io
;
1184 /* this one is pretty weird - the wct can be 6 or 12 */
1185 if (req
->in
.wct
!= 12) {
1186 SMBSRV_CHECK_WCT(req
, 6);
1189 SMBSRV_TALLOC_IO_PTR(io
, union smb_write
);
1190 SMBSRV_SETUP_NTVFS_REQUEST(reply_writeclose_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1192 io
->writeclose
.level
= RAW_WRITE_WRITECLOSE
;
1193 io
->writeclose
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1194 io
->writeclose
.in
.count
= SVAL(req
->in
.vwv
, VWV(1));
1195 io
->writeclose
.in
.offset
= IVAL(req
->in
.vwv
, VWV(2));
1196 io
->writeclose
.in
.mtime
= srv_pull_dos_date3(req
->smb_conn
, req
->in
.vwv
+ VWV(4));
1197 io
->writeclose
.in
.data
= req
->in
.data
+ 1;
1199 /* make sure they gave us the data they promised */
1200 if (req_data_oob(&req
->in
.bufinfo
, io
->writeclose
.in
.data
, io
->writeclose
.in
.count
)) {
1201 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1205 SMBSRV_CHECK_FILE_HANDLE(io
->writeclose
.in
.file
.ntvfs
);
1206 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_write(req
->ntvfs
, io
));
1209 /****************************************************************************
1211 ****************************************************************************/
1212 void smbsrv_reply_lock(struct smbsrv_request
*req
)
1214 union smb_lock
*lck
;
1217 SMBSRV_CHECK_WCT(req
, 5);
1218 SMBSRV_TALLOC_IO_PTR(lck
, union smb_lock
);
1219 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1221 lck
->lock
.level
= RAW_LOCK_LOCK
;
1222 lck
->lock
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1223 lck
->lock
.in
.count
= IVAL(req
->in
.vwv
, VWV(1));
1224 lck
->lock
.in
.offset
= IVAL(req
->in
.vwv
, VWV(3));
1226 SMBSRV_CHECK_FILE_HANDLE(lck
->lock
.in
.file
.ntvfs
);
1227 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_lock(req
->ntvfs
, lck
));
1231 /****************************************************************************
1233 ****************************************************************************/
1234 void smbsrv_reply_unlock(struct smbsrv_request
*req
)
1236 union smb_lock
*lck
;
1239 SMBSRV_CHECK_WCT(req
, 5);
1240 SMBSRV_TALLOC_IO_PTR(lck
, union smb_lock
);
1241 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1243 lck
->unlock
.level
= RAW_LOCK_UNLOCK
;
1244 lck
->unlock
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1245 lck
->unlock
.in
.count
= IVAL(req
->in
.vwv
, VWV(1));
1246 lck
->unlock
.in
.offset
= IVAL(req
->in
.vwv
, VWV(3));
1248 SMBSRV_CHECK_FILE_HANDLE(lck
->unlock
.in
.file
.ntvfs
);
1249 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_lock(req
->ntvfs
, lck
));
1253 /****************************************************************************
1255 ****************************************************************************/
1256 void smbsrv_reply_tdis(struct smbsrv_request
*req
)
1258 struct smbsrv_handle
*h
, *nh
;
1260 SMBSRV_CHECK_WCT(req
, 0);
1263 * TODO: cancel all pending requests on this tcon
1267 * close all handles on this tcon
1269 for (h
=req
->tcon
->handles
.list
; h
; h
=nh
) {
1274 /* finally destroy the tcon */
1275 talloc_free(req
->tcon
);
1278 smbsrv_setup_reply(req
, 0, 0);
1279 smbsrv_send_reply(req
);
1283 /****************************************************************************
1284 Reply to a echo. This is one of the few calls that is handled directly (the
1285 backends don't see it at all)
1286 ****************************************************************************/
1287 void smbsrv_reply_echo(struct smbsrv_request
*req
)
1292 SMBSRV_CHECK_WCT(req
, 1);
1294 count
= SVAL(req
->in
.vwv
, VWV(0));
1296 smbsrv_setup_reply(req
, 1, req
->in
.data_size
);
1298 memcpy(req
->out
.data
, req
->in
.data
, req
->in
.data_size
);
1300 for (i
=1; i
<= count
;i
++) {
1301 struct smbsrv_request
*this_req
;
1304 this_req
= smbsrv_setup_secondary_request(req
);
1309 SSVAL(this_req
->out
.vwv
, VWV(0), i
);
1310 smbsrv_send_reply(this_req
);
1316 /****************************************************************************
1317 Reply to a printopen (async reply)
1318 ****************************************************************************/
1319 static void reply_printopen_send(struct ntvfs_request
*ntvfs
)
1321 struct smbsrv_request
*req
;
1324 SMBSRV_CHECK_ASYNC_STATUS(oi
, union smb_open
);
1326 /* construct reply */
1327 smbsrv_setup_reply(req
, 1, 0);
1329 smbsrv_push_fnum(req
->out
.vwv
, VWV(0), oi
->openold
.out
.file
.ntvfs
);
1331 smbsrv_send_reply(req
);
1334 /****************************************************************************
1335 Reply to a printopen.
1336 ****************************************************************************/
1337 void smbsrv_reply_printopen(struct smbsrv_request
*req
)
1342 SMBSRV_CHECK_WCT(req
, 2);
1343 SMBSRV_TALLOC_IO_PTR(oi
, union smb_open
);
1344 SMBSRV_SETUP_NTVFS_REQUEST(reply_printopen_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1346 oi
->splopen
.level
= RAW_OPEN_SPLOPEN
;
1347 oi
->splopen
.in
.setup_length
= SVAL(req
->in
.vwv
, VWV(0));
1348 oi
->splopen
.in
.mode
= SVAL(req
->in
.vwv
, VWV(1));
1350 req_pull_ascii4(&req
->in
.bufinfo
, &oi
->splopen
.in
.ident
, req
->in
.data
, STR_TERMINATE
);
1352 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_open(req
->ntvfs
, oi
));
1355 /****************************************************************************
1356 Reply to a printclose.
1357 ****************************************************************************/
1358 void smbsrv_reply_printclose(struct smbsrv_request
*req
)
1360 union smb_close
*io
;
1363 SMBSRV_CHECK_WCT(req
, 3);
1364 SMBSRV_TALLOC_IO_PTR(io
, union smb_close
);
1365 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1367 io
->splclose
.level
= RAW_CLOSE_SPLCLOSE
;
1368 io
->splclose
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1370 SMBSRV_CHECK_FILE_HANDLE(io
->splclose
.in
.file
.ntvfs
);
1371 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_close(req
->ntvfs
, io
));
1374 /****************************************************************************
1375 Reply to a printqueue.
1376 ****************************************************************************/
1377 static void reply_printqueue_send(struct ntvfs_request
*ntvfs
)
1379 struct smbsrv_request
*req
;
1382 const uint_t el_size
= 28;
1384 SMBSRV_CHECK_ASYNC_STATUS(lpq
,union smb_lpq
);
1386 /* construct reply */
1387 smbsrv_setup_reply(req
, 2, 0);
1389 /* truncate the returned list to fit in the negotiated buffer size */
1390 maxcount
= (req_max_data(req
) - 3) / el_size
;
1391 if (maxcount
< lpq
->retq
.out
.count
) {
1392 lpq
->retq
.out
.count
= maxcount
;
1395 /* setup enough space in the reply */
1396 req_grow_data(req
, 3 + el_size
*lpq
->retq
.out
.count
);
1398 /* and fill it in */
1399 SSVAL(req
->out
.vwv
, VWV(0), lpq
->retq
.out
.count
);
1400 SSVAL(req
->out
.vwv
, VWV(1), lpq
->retq
.out
.restart_idx
);
1402 SCVAL(req
->out
.data
, 0, SMB_DATA_BLOCK
);
1403 SSVAL(req
->out
.data
, 1, el_size
*lpq
->retq
.out
.count
);
1405 req
->out
.ptr
= req
->out
.data
+ 3;
1407 for (i
=0;i
<lpq
->retq
.out
.count
;i
++) {
1408 srv_push_dos_date2(req
->smb_conn
, req
->out
.ptr
, 0 , lpq
->retq
.out
.queue
[i
].time
);
1409 SCVAL(req
->out
.ptr
, 4, lpq
->retq
.out
.queue
[i
].status
);
1410 SSVAL(req
->out
.ptr
, 5, lpq
->retq
.out
.queue
[i
].job
);
1411 SIVAL(req
->out
.ptr
, 7, lpq
->retq
.out
.queue
[i
].size
);
1412 SCVAL(req
->out
.ptr
, 11, 0); /* reserved */
1413 req_push_str(req
, req
->out
.ptr
+12, lpq
->retq
.out
.queue
[i
].user
, 16, STR_ASCII
);
1414 req
->out
.ptr
+= el_size
;
1417 smbsrv_send_reply(req
);
1420 /****************************************************************************
1421 Reply to a printqueue.
1422 ****************************************************************************/
1423 void smbsrv_reply_printqueue(struct smbsrv_request
*req
)
1428 SMBSRV_CHECK_WCT(req
, 2);
1429 SMBSRV_TALLOC_IO_PTR(lpq
, union smb_lpq
);
1430 SMBSRV_SETUP_NTVFS_REQUEST(reply_printqueue_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1432 lpq
->retq
.level
= RAW_LPQ_RETQ
;
1433 lpq
->retq
.in
.maxcount
= SVAL(req
->in
.vwv
, VWV(0));
1434 lpq
->retq
.in
.startidx
= SVAL(req
->in
.vwv
, VWV(1));
1436 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_lpq(req
->ntvfs
, lpq
));
1440 /****************************************************************************
1441 Reply to a printwrite.
1442 ****************************************************************************/
1443 void smbsrv_reply_printwrite(struct smbsrv_request
*req
)
1445 union smb_write
*io
;
1448 SMBSRV_CHECK_WCT(req
, 1);
1449 SMBSRV_TALLOC_IO_PTR(io
, union smb_write
);
1450 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1452 if (req
->in
.data_size
< 3) {
1453 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1457 io
->splwrite
.level
= RAW_WRITE_SPLWRITE
;
1458 io
->splwrite
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1459 io
->splwrite
.in
.count
= SVAL(req
->in
.data
, 1);
1460 io
->splwrite
.in
.data
= req
->in
.data
+ 3;
1462 /* make sure they gave us the data they promised */
1463 if (req_data_oob(&req
->in
.bufinfo
, io
->splwrite
.in
.data
, io
->splwrite
.in
.count
)) {
1464 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1468 SMBSRV_CHECK_FILE_HANDLE(io
->splwrite
.in
.file
.ntvfs
);
1469 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_write(req
->ntvfs
, io
));
1473 /****************************************************************************
1475 ****************************************************************************/
1476 void smbsrv_reply_mkdir(struct smbsrv_request
*req
)
1478 union smb_mkdir
*io
;
1480 /* parse the request */
1481 SMBSRV_CHECK_WCT(req
, 0);
1482 SMBSRV_TALLOC_IO_PTR(io
, union smb_mkdir
);
1483 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1485 io
->generic
.level
= RAW_MKDIR_MKDIR
;
1486 req_pull_ascii4(&req
->in
.bufinfo
, &io
->mkdir
.in
.path
, req
->in
.data
, STR_TERMINATE
);
1488 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_mkdir(req
->ntvfs
, io
));
1492 /****************************************************************************
1494 ****************************************************************************/
1495 void smbsrv_reply_rmdir(struct smbsrv_request
*req
)
1497 struct smb_rmdir
*io
;
1499 /* parse the request */
1500 SMBSRV_CHECK_WCT(req
, 0);
1501 SMBSRV_TALLOC_IO_PTR(io
, struct smb_rmdir
);
1502 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1504 req_pull_ascii4(&req
->in
.bufinfo
, &io
->in
.path
, req
->in
.data
, STR_TERMINATE
);
1506 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_rmdir(req
->ntvfs
, io
));
1510 /****************************************************************************
1512 ****************************************************************************/
1513 void smbsrv_reply_mv(struct smbsrv_request
*req
)
1515 union smb_rename
*io
;
1518 /* parse the request */
1519 SMBSRV_CHECK_WCT(req
, 1);
1520 SMBSRV_TALLOC_IO_PTR(io
, union smb_rename
);
1521 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1523 io
->generic
.level
= RAW_RENAME_RENAME
;
1524 io
->rename
.in
.attrib
= SVAL(req
->in
.vwv
, VWV(0));
1527 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &io
->rename
.in
.pattern1
, p
, STR_TERMINATE
);
1528 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &io
->rename
.in
.pattern2
, p
, STR_TERMINATE
);
1530 if (!io
->rename
.in
.pattern1
|| !io
->rename
.in
.pattern2
) {
1531 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1535 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_rename(req
->ntvfs
, io
));
1539 /****************************************************************************
1540 Reply to an NT rename.
1541 ****************************************************************************/
1542 void smbsrv_reply_ntrename(struct smbsrv_request
*req
)
1544 union smb_rename
*io
;
1547 /* parse the request */
1548 SMBSRV_CHECK_WCT(req
, 4);
1549 SMBSRV_TALLOC_IO_PTR(io
, union smb_rename
);
1550 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1552 io
->generic
.level
= RAW_RENAME_NTRENAME
;
1553 io
->ntrename
.in
.attrib
= SVAL(req
->in
.vwv
, VWV(0));
1554 io
->ntrename
.in
.flags
= SVAL(req
->in
.vwv
, VWV(1));
1555 io
->ntrename
.in
.cluster_size
= IVAL(req
->in
.vwv
, VWV(2));
1558 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &io
->ntrename
.in
.old_name
, p
, STR_TERMINATE
);
1559 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &io
->ntrename
.in
.new_name
, p
, STR_TERMINATE
);
1561 if (!io
->ntrename
.in
.old_name
|| !io
->ntrename
.in
.new_name
) {
1562 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1566 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_rename(req
->ntvfs
, io
));
1569 /****************************************************************************
1570 Reply to a file copy (async reply)
1571 ****************************************************************************/
1572 static void reply_copy_send(struct ntvfs_request
*ntvfs
)
1574 struct smbsrv_request
*req
;
1575 struct smb_copy
*cp
;
1577 SMBSRV_CHECK_ASYNC_STATUS(cp
, struct smb_copy
);
1579 /* build the reply */
1580 smbsrv_setup_reply(req
, 1, 0);
1582 SSVAL(req
->out
.vwv
, VWV(0), cp
->out
.count
);
1584 smbsrv_send_reply(req
);
1587 /****************************************************************************
1588 Reply to a file copy.
1589 ****************************************************************************/
1590 void smbsrv_reply_copy(struct smbsrv_request
*req
)
1592 struct smb_copy
*cp
;
1596 SMBSRV_CHECK_WCT(req
, 3);
1597 SMBSRV_TALLOC_IO_PTR(cp
, struct smb_copy
);
1598 SMBSRV_SETUP_NTVFS_REQUEST(reply_copy_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1600 cp
->in
.tid2
= SVAL(req
->in
.vwv
, VWV(0));
1601 cp
->in
.ofun
= SVAL(req
->in
.vwv
, VWV(1));
1602 cp
->in
.flags
= SVAL(req
->in
.vwv
, VWV(2));
1605 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &cp
->in
.path1
, p
, STR_TERMINATE
);
1606 p
+= req_pull_ascii4(&req
->in
.bufinfo
, &cp
->in
.path2
, p
, STR_TERMINATE
);
1608 if (!cp
->in
.path1
|| !cp
->in
.path2
) {
1609 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1613 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_copy(req
->ntvfs
, cp
));
1616 /****************************************************************************
1617 Reply to a lockingX request (async send)
1618 ****************************************************************************/
1619 static void reply_lockingX_send(struct ntvfs_request
*ntvfs
)
1621 struct smbsrv_request
*req
;
1622 union smb_lock
*lck
;
1624 SMBSRV_CHECK_ASYNC_STATUS(lck
, union smb_lock
);
1626 /* if it was an oplock break ack then we only send a reply if
1627 there was an error */
1628 if (lck
->lockx
.in
.ulock_cnt
+ lck
->lockx
.in
.lock_cnt
== 0) {
1633 /* construct reply */
1634 smbsrv_setup_reply(req
, 2, 0);
1636 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
1637 SSVAL(req
->out
.vwv
, VWV(1), 0);
1639 smbsrv_chain_reply(req
);
1643 /****************************************************************************
1644 Reply to a lockingX request.
1645 ****************************************************************************/
1646 void smbsrv_reply_lockingX(struct smbsrv_request
*req
)
1648 union smb_lock
*lck
;
1649 uint_t total_locks
, i
;
1654 SMBSRV_CHECK_WCT(req
, 8);
1655 SMBSRV_TALLOC_IO_PTR(lck
, union smb_lock
);
1656 SMBSRV_SETUP_NTVFS_REQUEST(reply_lockingX_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1658 lck
->lockx
.level
= RAW_LOCK_LOCKX
;
1659 lck
->lockx
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(2));
1660 lck
->lockx
.in
.mode
= SVAL(req
->in
.vwv
, VWV(3));
1661 lck
->lockx
.in
.timeout
= IVAL(req
->in
.vwv
, VWV(4));
1662 lck
->lockx
.in
.ulock_cnt
= SVAL(req
->in
.vwv
, VWV(6));
1663 lck
->lockx
.in
.lock_cnt
= SVAL(req
->in
.vwv
, VWV(7));
1665 total_locks
= lck
->lockx
.in
.ulock_cnt
+ lck
->lockx
.in
.lock_cnt
;
1667 /* there are two variants, one with 64 bit offsets and counts */
1668 if (lck
->lockx
.in
.mode
& LOCKING_ANDX_LARGE_FILES
) {
1674 /* make sure we got the promised data */
1675 if (req_data_oob(&req
->in
.bufinfo
, req
->in
.data
, total_locks
* lck_size
)) {
1676 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1680 /* allocate the locks array */
1682 lck
->lockx
.in
.locks
= talloc_array(req
, struct smb_lock_entry
,
1684 if (lck
->lockx
.in
.locks
== NULL
) {
1685 smbsrv_send_error(req
, NT_STATUS_NO_MEMORY
);
1692 /* construct the locks array */
1693 for (i
=0;i
<total_locks
;i
++) {
1694 uint32_t ofs_high
=0, count_high
=0;
1696 lck
->lockx
.in
.locks
[i
].pid
= SVAL(p
, 0);
1698 if (lck
->lockx
.in
.mode
& LOCKING_ANDX_LARGE_FILES
) {
1699 ofs_high
= IVAL(p
, 4);
1700 lck
->lockx
.in
.locks
[i
].offset
= IVAL(p
, 8);
1701 count_high
= IVAL(p
, 12);
1702 lck
->lockx
.in
.locks
[i
].count
= IVAL(p
, 16);
1704 lck
->lockx
.in
.locks
[i
].offset
= IVAL(p
, 2);
1705 lck
->lockx
.in
.locks
[i
].count
= IVAL(p
, 6);
1707 if (ofs_high
!= 0 || count_high
!= 0) {
1708 lck
->lockx
.in
.locks
[i
].count
|= ((uint64_t)count_high
) << 32;
1709 lck
->lockx
.in
.locks
[i
].offset
|= ((uint64_t)ofs_high
) << 32;
1714 SMBSRV_CHECK_FILE_HANDLE(lck
->lockx
.in
.file
.ntvfs
);
1715 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_lock(req
->ntvfs
, lck
));
1718 /****************************************************************************
1719 Reply to a SMBreadbmpx (read block multiplex) request.
1720 ****************************************************************************/
1721 void smbsrv_reply_readbmpx(struct smbsrv_request
*req
)
1723 /* tell the client to not use a multiplexed read - its too broken to use */
1724 smbsrv_send_error(req
, NT_STATUS_DOS(ERRSRV
, ERRuseSTD
));
1728 /****************************************************************************
1729 Reply to a SMBsetattrE.
1730 ****************************************************************************/
1731 void smbsrv_reply_setattrE(struct smbsrv_request
*req
)
1733 union smb_setfileinfo
*info
;
1736 SMBSRV_CHECK_WCT(req
, 7);
1737 SMBSRV_TALLOC_IO_PTR(info
, union smb_setfileinfo
);
1738 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1740 info
->setattre
.level
= RAW_SFILEINFO_SETATTRE
;
1741 info
->setattre
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1742 info
->setattre
.in
.create_time
= srv_pull_dos_date2(req
->smb_conn
, req
->in
.vwv
+ VWV(1));
1743 info
->setattre
.in
.access_time
= srv_pull_dos_date2(req
->smb_conn
, req
->in
.vwv
+ VWV(3));
1744 info
->setattre
.in
.write_time
= srv_pull_dos_date2(req
->smb_conn
, req
->in
.vwv
+ VWV(5));
1746 SMBSRV_CHECK_FILE_HANDLE(info
->setattre
.in
.file
.ntvfs
);
1747 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_setfileinfo(req
->ntvfs
, info
));
1751 /****************************************************************************
1752 Reply to a SMBwritebmpx (write block multiplex primary) request.
1753 ****************************************************************************/
1754 void smbsrv_reply_writebmpx(struct smbsrv_request
*req
)
1756 smbsrv_send_error(req
, NT_STATUS_DOS(ERRSRV
, ERRuseSTD
));
1760 /****************************************************************************
1761 Reply to a SMBwritebs (write block multiplex secondary) request.
1762 ****************************************************************************/
1763 void smbsrv_reply_writebs(struct smbsrv_request
*req
)
1765 smbsrv_send_error(req
, NT_STATUS_DOS(ERRSRV
, ERRuseSTD
));
1770 /****************************************************************************
1771 Reply to a SMBgetattrE (async reply)
1772 ****************************************************************************/
1773 static void reply_getattrE_send(struct ntvfs_request
*ntvfs
)
1775 struct smbsrv_request
*req
;
1776 union smb_fileinfo
*info
;
1778 SMBSRV_CHECK_ASYNC_STATUS(info
, union smb_fileinfo
);
1781 smbsrv_setup_reply(req
, 11, 0);
1783 srv_push_dos_date2(req
->smb_conn
, req
->out
.vwv
, VWV(0), info
->getattre
.out
.create_time
);
1784 srv_push_dos_date2(req
->smb_conn
, req
->out
.vwv
, VWV(2), info
->getattre
.out
.access_time
);
1785 srv_push_dos_date2(req
->smb_conn
, req
->out
.vwv
, VWV(4), info
->getattre
.out
.write_time
);
1786 SIVAL(req
->out
.vwv
, VWV(6), info
->getattre
.out
.size
);
1787 SIVAL(req
->out
.vwv
, VWV(8), info
->getattre
.out
.alloc_size
);
1788 SSVAL(req
->out
.vwv
, VWV(10), info
->getattre
.out
.attrib
);
1790 smbsrv_send_reply(req
);
1793 /****************************************************************************
1794 Reply to a SMBgetattrE.
1795 ****************************************************************************/
1796 void smbsrv_reply_getattrE(struct smbsrv_request
*req
)
1798 union smb_fileinfo
*info
;
1801 SMBSRV_CHECK_WCT(req
, 1);
1802 SMBSRV_TALLOC_IO_PTR(info
, union smb_fileinfo
);
1803 SMBSRV_SETUP_NTVFS_REQUEST(reply_getattrE_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
1805 info
->getattr
.level
= RAW_FILEINFO_GETATTRE
;
1806 info
->getattr
.in
.file
.ntvfs
= smbsrv_pull_fnum(req
, req
->in
.vwv
, VWV(0));
1808 SMBSRV_CHECK_FILE_HANDLE(info
->getattr
.in
.file
.ntvfs
);
1809 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_qfileinfo(req
->ntvfs
, info
));
1812 void smbsrv_reply_sesssetup_send(struct smbsrv_request
*req
,
1813 union smb_sesssetup
*io
,
1816 switch (io
->old
.level
) {
1817 case RAW_SESSSETUP_OLD
:
1818 if (!NT_STATUS_IS_OK(status
)) {
1819 smbsrv_send_error(req
, status
);
1823 /* construct reply */
1824 smbsrv_setup_reply(req
, 3, 0);
1826 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
1827 SSVAL(req
->out
.vwv
, VWV(1), 0);
1828 SSVAL(req
->out
.vwv
, VWV(2), io
->old
.out
.action
);
1830 SSVAL(req
->out
.hdr
, HDR_UID
, io
->old
.out
.vuid
);
1832 smbsrv_chain_reply(req
);
1835 case RAW_SESSSETUP_NT1
:
1836 if (!NT_STATUS_IS_OK(status
)) {
1837 smbsrv_send_error(req
, status
);
1841 /* construct reply */
1842 smbsrv_setup_reply(req
, 3, 0);
1844 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
1845 SSVAL(req
->out
.vwv
, VWV(1), 0);
1846 SSVAL(req
->out
.vwv
, VWV(2), io
->nt1
.out
.action
);
1848 SSVAL(req
->out
.hdr
, HDR_UID
, io
->nt1
.out
.vuid
);
1850 req_push_str(req
, NULL
, io
->nt1
.out
.os
, -1, STR_TERMINATE
);
1851 req_push_str(req
, NULL
, io
->nt1
.out
.lanman
, -1, STR_TERMINATE
);
1852 req_push_str(req
, NULL
, io
->nt1
.out
.domain
, -1, STR_TERMINATE
);
1854 smbsrv_chain_reply(req
);
1857 case RAW_SESSSETUP_SPNEGO
:
1858 if (!NT_STATUS_IS_OK(status
) &&
1859 !NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1860 smbsrv_send_error(req
, status
);
1864 /* construct reply */
1865 smbsrv_setup_reply(req
, 4, io
->spnego
.out
.secblob
.length
);
1867 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1868 smbsrv_setup_error(req
, status
);
1871 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
1872 SSVAL(req
->out
.vwv
, VWV(1), 0);
1873 SSVAL(req
->out
.vwv
, VWV(2), io
->spnego
.out
.action
);
1874 SSVAL(req
->out
.vwv
, VWV(3), io
->spnego
.out
.secblob
.length
);
1876 SSVAL(req
->out
.hdr
, HDR_UID
, io
->spnego
.out
.vuid
);
1878 memcpy(req
->out
.data
, io
->spnego
.out
.secblob
.data
, io
->spnego
.out
.secblob
.length
);
1879 req_push_str(req
, NULL
, io
->spnego
.out
.os
, -1, STR_TERMINATE
);
1880 req_push_str(req
, NULL
, io
->spnego
.out
.lanman
, -1, STR_TERMINATE
);
1881 req_push_str(req
, NULL
, io
->spnego
.out
.workgroup
, -1, STR_TERMINATE
);
1883 smbsrv_chain_reply(req
);
1886 case RAW_SESSSETUP_SMB2
:
1890 smbsrv_send_error(req
, NT_STATUS_INTERNAL_ERROR
);
1893 /****************************************************************************
1894 reply to an old style session setup command
1895 ****************************************************************************/
1896 static void reply_sesssetup_old(struct smbsrv_request
*req
)
1900 union smb_sesssetup
*io
;
1902 SMBSRV_TALLOC_IO_PTR(io
, union smb_sesssetup
);
1904 io
->old
.level
= RAW_SESSSETUP_OLD
;
1907 io
->old
.in
.bufsize
= SVAL(req
->in
.vwv
, VWV(2));
1908 io
->old
.in
.mpx_max
= SVAL(req
->in
.vwv
, VWV(3));
1909 io
->old
.in
.vc_num
= SVAL(req
->in
.vwv
, VWV(4));
1910 io
->old
.in
.sesskey
= IVAL(req
->in
.vwv
, VWV(5));
1911 passlen
= SVAL(req
->in
.vwv
, VWV(7));
1913 /* check the request isn't malformed */
1914 if (req_data_oob(&req
->in
.bufinfo
, req
->in
.data
, passlen
)) {
1915 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1920 if (!req_pull_blob(&req
->in
.bufinfo
, p
, passlen
, &io
->old
.in
.password
)) {
1921 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1926 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->old
.in
.user
, p
, -1, STR_TERMINATE
);
1927 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->old
.in
.domain
, p
, -1, STR_TERMINATE
);
1928 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->old
.in
.os
, p
, -1, STR_TERMINATE
);
1929 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->old
.in
.lanman
, p
, -1, STR_TERMINATE
);
1931 /* call the generic handler */
1932 smbsrv_sesssetup_backend(req
, io
);
1935 /****************************************************************************
1936 reply to an NT1 style session setup command
1937 ****************************************************************************/
1938 static void reply_sesssetup_nt1(struct smbsrv_request
*req
)
1941 uint16_t passlen1
, passlen2
;
1942 union smb_sesssetup
*io
;
1944 SMBSRV_TALLOC_IO_PTR(io
, union smb_sesssetup
);
1946 io
->nt1
.level
= RAW_SESSSETUP_NT1
;
1949 io
->nt1
.in
.bufsize
= SVAL(req
->in
.vwv
, VWV(2));
1950 io
->nt1
.in
.mpx_max
= SVAL(req
->in
.vwv
, VWV(3));
1951 io
->nt1
.in
.vc_num
= SVAL(req
->in
.vwv
, VWV(4));
1952 io
->nt1
.in
.sesskey
= IVAL(req
->in
.vwv
, VWV(5));
1953 passlen1
= SVAL(req
->in
.vwv
, VWV(7));
1954 passlen2
= SVAL(req
->in
.vwv
, VWV(8));
1955 io
->nt1
.in
.capabilities
= IVAL(req
->in
.vwv
, VWV(11));
1957 /* check the request isn't malformed */
1958 if (req_data_oob(&req
->in
.bufinfo
, req
->in
.data
, passlen1
) ||
1959 req_data_oob(&req
->in
.bufinfo
, req
->in
.data
+ passlen1
, passlen2
)) {
1960 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1965 if (!req_pull_blob(&req
->in
.bufinfo
, p
, passlen1
, &io
->nt1
.in
.password1
)) {
1966 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1970 if (!req_pull_blob(&req
->in
.bufinfo
, p
, passlen2
, &io
->nt1
.in
.password2
)) {
1971 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
1976 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->nt1
.in
.user
, p
, -1, STR_TERMINATE
);
1977 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->nt1
.in
.domain
, p
, -1, STR_TERMINATE
);
1978 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->nt1
.in
.os
, p
, -1, STR_TERMINATE
);
1979 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->nt1
.in
.lanman
, p
, -1, STR_TERMINATE
);
1981 /* call the generic handler */
1982 smbsrv_sesssetup_backend(req
, io
);
1986 /****************************************************************************
1987 reply to an SPNEGO style session setup command
1988 ****************************************************************************/
1989 static void reply_sesssetup_spnego(struct smbsrv_request
*req
)
1993 union smb_sesssetup
*io
;
1995 SMBSRV_TALLOC_IO_PTR(io
, union smb_sesssetup
);
1997 io
->spnego
.level
= RAW_SESSSETUP_SPNEGO
;
2000 io
->spnego
.in
.bufsize
= SVAL(req
->in
.vwv
, VWV(2));
2001 io
->spnego
.in
.mpx_max
= SVAL(req
->in
.vwv
, VWV(3));
2002 io
->spnego
.in
.vc_num
= SVAL(req
->in
.vwv
, VWV(4));
2003 io
->spnego
.in
.sesskey
= IVAL(req
->in
.vwv
, VWV(5));
2004 blob_len
= SVAL(req
->in
.vwv
, VWV(7));
2005 io
->spnego
.in
.capabilities
= IVAL(req
->in
.vwv
, VWV(10));
2008 if (!req_pull_blob(&req
->in
.bufinfo
, p
, blob_len
, &io
->spnego
.in
.secblob
)) {
2009 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
2014 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->spnego
.in
.os
, p
, -1, STR_TERMINATE
);
2015 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->spnego
.in
.lanman
, p
, -1, STR_TERMINATE
);
2016 p
+= req_pull_string(&req
->in
.bufinfo
, &io
->spnego
.in
.workgroup
, p
, -1, STR_TERMINATE
);
2018 /* call the generic handler */
2019 smbsrv_sesssetup_backend(req
, io
);
2023 /****************************************************************************
2024 reply to a session setup command
2025 ****************************************************************************/
2026 void smbsrv_reply_sesssetup(struct smbsrv_request
*req
)
2028 switch (req
->in
.wct
) {
2030 /* a pre-NT1 call */
2031 reply_sesssetup_old(req
);
2035 reply_sesssetup_nt1(req
);
2039 reply_sesssetup_spnego(req
);
2043 /* unsupported variant */
2044 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
2047 /****************************************************************************
2048 Reply to a exit. This closes all files open by a smbpid
2049 ****************************************************************************/
2050 void smbsrv_reply_exit(struct smbsrv_request
*req
)
2052 struct smbsrv_handle_session_item
*i
, *ni
;
2053 struct smbsrv_handle
*h
;
2054 struct smbsrv_tcon
*tcon
;
2057 SMBSRV_CHECK_WCT(req
, 0);
2059 smbpid
= SVAL(req
->in
.hdr
,HDR_PID
);
2061 /* first destroy all handles, which have the same PID as the request */
2062 for (i
=req
->session
->handles
; i
; i
=ni
) {
2065 if (h
->smbpid
!= smbpid
) continue;
2071 * then let the ntvfs backends proxy the call if they want to,
2072 * but we didn't check the return value of the backends,
2073 * as for the SMB client the call succeed
2075 for (tcon
=req
->smb_conn
->smb_tcons
.list
;tcon
;tcon
=tcon
->next
) {
2077 SMBSRV_SETUP_NTVFS_REQUEST(NULL
,0);
2078 ntvfs_exit(req
->ntvfs
);
2079 talloc_free(req
->ntvfs
);
2084 smbsrv_setup_reply(req
, 0, 0);
2085 smbsrv_send_reply(req
);
2088 /****************************************************************************
2089 Reply to a SMBulogoffX.
2090 ****************************************************************************/
2091 void smbsrv_reply_ulogoffX(struct smbsrv_request
*req
)
2093 struct smbsrv_handle_session_item
*i
, *ni
;
2094 struct smbsrv_handle
*h
;
2095 struct smbsrv_tcon
*tcon
;
2097 SMBSRV_CHECK_WCT(req
, 2);
2100 * TODO: cancel all pending requests
2104 /* destroy all handles */
2105 for (i
=req
->session
->handles
; i
; i
=ni
) {
2112 * then let the ntvfs backends proxy the call if they want to,
2113 * but we didn't check the return value of the backends,
2114 * as for the SMB client the call succeed
2116 for (tcon
=req
->smb_conn
->smb_tcons
.list
;tcon
;tcon
=tcon
->next
) {
2118 SMBSRV_SETUP_NTVFS_REQUEST(NULL
,0);
2119 ntvfs_logoff(req
->ntvfs
);
2120 talloc_free(req
->ntvfs
);
2125 talloc_free(req
->session
);
2126 req
->session
= NULL
; /* it is now invalid, don't use on
2127 any chained packets */
2129 smbsrv_setup_reply(req
, 2, 0);
2131 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
2132 SSVAL(req
->out
.vwv
, VWV(1), 0);
2134 smbsrv_chain_reply(req
);
2137 /****************************************************************************
2138 Reply to an SMBfindclose request
2139 ****************************************************************************/
2140 void smbsrv_reply_findclose(struct smbsrv_request
*req
)
2142 union smb_search_close
*io
;
2145 SMBSRV_CHECK_WCT(req
, 1);
2146 SMBSRV_TALLOC_IO_PTR(io
, union smb_search_close
);
2147 SMBSRV_SETUP_NTVFS_REQUEST(reply_simple_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
2149 io
->findclose
.level
= RAW_FINDCLOSE_FINDCLOSE
;
2150 io
->findclose
.in
.handle
= SVAL(req
->in
.vwv
, VWV(0));
2152 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_search_close(req
->ntvfs
, io
));
2155 /****************************************************************************
2156 Reply to an SMBfindnclose request
2157 ****************************************************************************/
2158 void smbsrv_reply_findnclose(struct smbsrv_request
*req
)
2160 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
2164 /****************************************************************************
2165 Reply to an SMBntcreateX request (async send)
2166 ****************************************************************************/
2167 static void reply_ntcreate_and_X_send(struct ntvfs_request
*ntvfs
)
2169 struct smbsrv_request
*req
;
2172 SMBSRV_CHECK_ASYNC_STATUS(io
, union smb_open
);
2174 /* construct reply */
2175 smbsrv_setup_reply(req
, 34, 0);
2177 SSVAL(req
->out
.vwv
, VWV(0), SMB_CHAIN_NONE
);
2178 SSVAL(req
->out
.vwv
, VWV(1), 0);
2179 SCVAL(req
->out
.vwv
, VWV(2), io
->ntcreatex
.out
.oplock_level
);
2181 /* the rest of the parameters are not aligned! */
2182 smbsrv_push_fnum(req
->out
.vwv
, 5, io
->ntcreatex
.out
.file
.ntvfs
);
2183 SIVAL(req
->out
.vwv
, 7, io
->ntcreatex
.out
.create_action
);
2184 push_nttime(req
->out
.vwv
, 11, io
->ntcreatex
.out
.create_time
);
2185 push_nttime(req
->out
.vwv
, 19, io
->ntcreatex
.out
.access_time
);
2186 push_nttime(req
->out
.vwv
, 27, io
->ntcreatex
.out
.write_time
);
2187 push_nttime(req
->out
.vwv
, 35, io
->ntcreatex
.out
.change_time
);
2188 SIVAL(req
->out
.vwv
, 43, io
->ntcreatex
.out
.attrib
);
2189 SBVAL(req
->out
.vwv
, 47, io
->ntcreatex
.out
.alloc_size
);
2190 SBVAL(req
->out
.vwv
, 55, io
->ntcreatex
.out
.size
);
2191 SSVAL(req
->out
.vwv
, 63, io
->ntcreatex
.out
.file_type
);
2192 SSVAL(req
->out
.vwv
, 65, io
->ntcreatex
.out
.ipc_state
);
2193 SCVAL(req
->out
.vwv
, 67, io
->ntcreatex
.out
.is_directory
);
2195 req
->chained_fnum
= SVAL(req
->out
.vwv
, 5);
2197 smbsrv_chain_reply(req
);
2200 /****************************************************************************
2201 Reply to an SMBntcreateX request
2202 ****************************************************************************/
2203 void smbsrv_reply_ntcreate_and_X(struct smbsrv_request
*req
)
2208 /* parse the request */
2209 SMBSRV_CHECK_WCT(req
, 24);
2210 SMBSRV_TALLOC_IO_PTR(io
, union smb_open
);
2211 SMBSRV_SETUP_NTVFS_REQUEST(reply_ntcreate_and_X_send
, NTVFS_ASYNC_STATE_MAY_ASYNC
);
2213 io
->ntcreatex
.level
= RAW_OPEN_NTCREATEX
;
2215 /* notice that the word parameters are not word aligned, so we don't use VWV() */
2216 fname_len
= SVAL(req
->in
.vwv
, 5);
2217 io
->ntcreatex
.in
.flags
= IVAL(req
->in
.vwv
, 7);
2218 io
->ntcreatex
.in
.root_fid
= IVAL(req
->in
.vwv
, 11);
2219 io
->ntcreatex
.in
.access_mask
= IVAL(req
->in
.vwv
, 15);
2220 io
->ntcreatex
.in
.alloc_size
= BVAL(req
->in
.vwv
, 19);
2221 io
->ntcreatex
.in
.file_attr
= IVAL(req
->in
.vwv
, 27);
2222 io
->ntcreatex
.in
.share_access
= IVAL(req
->in
.vwv
, 31);
2223 io
->ntcreatex
.in
.open_disposition
= IVAL(req
->in
.vwv
, 35);
2224 io
->ntcreatex
.in
.create_options
= IVAL(req
->in
.vwv
, 39);
2225 io
->ntcreatex
.in
.impersonation
= IVAL(req
->in
.vwv
, 43);
2226 io
->ntcreatex
.in
.security_flags
= CVAL(req
->in
.vwv
, 47);
2227 io
->ntcreatex
.in
.ea_list
= NULL
;
2228 io
->ntcreatex
.in
.sec_desc
= NULL
;
2229 io
->ntcreatex
.in
.query_maximal_access
= false;
2231 /* we use a couple of bits of the create options internally */
2232 if (io
->ntcreatex
.in
.create_options
& NTCREATEX_OPTIONS_PRIVATE_MASK
) {
2233 smbsrv_send_error(req
, NT_STATUS_INVALID_PARAMETER
);
2237 /* we need a neater way to handle this alignment */
2238 if ((req
->flags2
& FLAGS2_UNICODE_STRINGS
) &&
2239 ucs2_align(req
->in
.buffer
, req
->in
.data
, STR_TERMINATE
|STR_UNICODE
)) {
2243 req_pull_string(&req
->in
.bufinfo
, &io
->ntcreatex
.in
.fname
, req
->in
.data
, fname_len
, STR_TERMINATE
);
2244 if (!io
->ntcreatex
.in
.fname
) {
2245 smbsrv_send_error(req
, NT_STATUS_FOOBAR
);
2249 SMBSRV_CALL_NTVFS_BACKEND(ntvfs_open(req
->ntvfs
, io
));
2253 /****************************************************************************
2254 Reply to an SMBntcancel request
2255 ****************************************************************************/
2256 void smbsrv_reply_ntcancel(struct smbsrv_request
*req
)
2258 struct smbsrv_request
*r
;
2259 uint16_t tid
= SVAL(req
->in
.hdr
,HDR_TID
);
2260 uint16_t uid
= SVAL(req
->in
.hdr
,HDR_UID
);
2261 uint16_t mid
= SVAL(req
->in
.hdr
,HDR_MID
);
2262 uint16_t pid
= SVAL(req
->in
.hdr
,HDR_PID
);
2264 for (r
= req
->smb_conn
->requests
; r
; r
= r
->next
) {
2265 if (tid
!= SVAL(r
->in
.hdr
,HDR_TID
)) continue;
2266 if (uid
!= SVAL(r
->in
.hdr
,HDR_UID
)) continue;
2267 if (mid
!= SVAL(r
->in
.hdr
,HDR_MID
)) continue;
2268 if (pid
!= SVAL(r
->in
.hdr
,HDR_PID
)) continue;
2270 SMBSRV_CHECK(ntvfs_cancel(r
->ntvfs
));
2272 /* NOTE: this request does not generate a reply */
2277 /* TODO: workout the correct error code,
2278 * until we know how the smb signing works
2279 * for ntcancel replies, don't send an error
2281 /*smbsrv_send_error(req, NT_STATUS_FOOBAR);*/
2286 parse the called/calling names from session request
2288 static NTSTATUS
parse_session_request(struct smbsrv_request
*req
)
2293 blob
.data
= req
->in
.buffer
+ 4;
2294 blob
.length
= ascii_len_n((const char *)blob
.data
, req
->in
.size
- PTR_DIFF(blob
.data
, req
->in
.buffer
));
2295 if (blob
.length
== 0) return NT_STATUS_BAD_NETWORK_NAME
;
2297 req
->smb_conn
->negotiate
.called_name
= talloc(req
->smb_conn
, struct nbt_name
);
2298 req
->smb_conn
->negotiate
.calling_name
= talloc(req
->smb_conn
, struct nbt_name
);
2299 if (req
->smb_conn
->negotiate
.called_name
== NULL
||
2300 req
->smb_conn
->negotiate
.calling_name
== NULL
) {
2301 return NT_STATUS_NO_MEMORY
;
2304 status
= nbt_name_from_blob(req
->smb_conn
, &blob
,
2305 req
->smb_conn
->negotiate
.called_name
);
2306 NT_STATUS_NOT_OK_RETURN(status
);
2308 blob
.data
+= blob
.length
;
2309 blob
.length
= ascii_len_n((const char *)blob
.data
, req
->in
.size
- PTR_DIFF(blob
.data
, req
->in
.buffer
));
2310 if (blob
.length
== 0) return NT_STATUS_BAD_NETWORK_NAME
;
2312 status
= nbt_name_from_blob(req
->smb_conn
, &blob
,
2313 req
->smb_conn
->negotiate
.calling_name
);
2314 NT_STATUS_NOT_OK_RETURN(status
);
2316 req
->smb_conn
->negotiate
.done_nbt_session
= true;
2318 return NT_STATUS_OK
;
2323 /****************************************************************************
2324 Reply to a special message - a SMB packet with non zero NBT message type
2325 ****************************************************************************/
2326 void smbsrv_reply_special(struct smbsrv_request
*req
)
2329 uint8_t *buf
= talloc_zero_array(req
, uint8_t, 4);
2331 msg_type
= CVAL(req
->in
.buffer
,0);
2336 case 0x81: /* session request */
2337 if (req
->smb_conn
->negotiate
.done_nbt_session
) {
2338 DEBUG(0,("Warning: ignoring secondary session request\n"));
2345 /* we don't check the status - samba always accepts session
2346 requests for any name */
2347 parse_session_request(req
);
2349 req
->out
.buffer
= buf
;
2351 smbsrv_send_reply_nosign(req
);
2354 case 0x89: /* session keepalive request
2355 (some old clients produce this?) */
2356 SCVAL(buf
, 0, SMBkeepalive
);
2358 req
->out
.buffer
= buf
;
2360 smbsrv_send_reply_nosign(req
);
2364 /* session keepalive - swallow it */
2369 DEBUG(0,("Unexpected NBT session packet (%d)\n", msg_type
));