tdb: allow reads after prepare commit
[Samba/aatanasov.git] / source3 / smbd / nttrans.c
blob1b981578e321e563752e19118ce0dee619c7d795
1 /*
2 Unix SMB/CIFS implementation.
3 SMB NT transaction handling
4 Copyright (C) Jeremy Allison 1994-2007
5 Copyright (C) Stefan (metze) Metzmacher 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "smbd/globals.h"
24 extern enum protocol_types Protocol;
25 extern const struct generic_mapping file_generic_mapping;
27 static char *nttrans_realloc(char **ptr, size_t size)
29 if (ptr==NULL) {
30 smb_panic("nttrans_realloc() called with NULL ptr");
33 *ptr = (char *)SMB_REALLOC(*ptr, size);
34 if(*ptr == NULL) {
35 return NULL;
37 memset(*ptr,'\0',size);
38 return *ptr;
41 /****************************************************************************
42 Send the required number of replies back.
43 We assume all fields other than the data fields are
44 set correctly for the type of call.
45 HACK ! Always assumes smb_setup field is zero.
46 ****************************************************************************/
48 void send_nt_replies(connection_struct *conn,
49 struct smb_request *req, NTSTATUS nt_error,
50 char *params, int paramsize,
51 char *pdata, int datasize)
53 int data_to_send = datasize;
54 int params_to_send = paramsize;
55 int useable_space;
56 char *pp = params;
57 char *pd = pdata;
58 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
59 int alignment_offset = 3;
60 int data_alignment_offset = 0;
61 struct smbd_server_connection *sconn = smbd_server_conn;
62 int max_send = sconn->smb1.sessions.max_send;
65 * If there genuinely are no parameters or data to send just send
66 * the empty packet.
69 if(params_to_send == 0 && data_to_send == 0) {
70 reply_outbuf(req, 18, 0);
71 if (NT_STATUS_V(nt_error)) {
72 error_packet_set((char *)req->outbuf,
73 0, 0, nt_error,
74 __LINE__,__FILE__);
76 show_msg((char *)req->outbuf);
77 if (!srv_send_smb(smbd_server_fd(),
78 (char *)req->outbuf,
79 true, req->seqnum+1,
80 IS_CONN_ENCRYPTED(conn),
81 &req->pcd)) {
82 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
84 TALLOC_FREE(req->outbuf);
85 return;
89 * When sending params and data ensure that both are nicely aligned.
90 * Only do this alignment when there is also data to send - else
91 * can cause NT redirector problems.
94 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
95 data_alignment_offset = 4 - (params_to_send % 4);
99 * Space is bufsize minus Netbios over TCP header minus SMB header.
100 * The alignment_offset is to align the param bytes on a four byte
101 * boundary (2 bytes for data len, one byte pad).
102 * NT needs this to work correctly.
105 useable_space = max_send - (smb_size
106 + 2 * 18 /* wct */
107 + alignment_offset
108 + data_alignment_offset);
110 if (useable_space < 0) {
111 char *msg = talloc_asprintf(
112 talloc_tos(),
113 "send_nt_replies failed sanity useable_space = %d!!!",
114 useable_space);
115 DEBUG(0, ("%s\n", msg));
116 exit_server_cleanly(msg);
119 while (params_to_send || data_to_send) {
122 * Calculate whether we will totally or partially fill this packet.
125 total_sent_thistime = params_to_send + data_to_send;
128 * We can never send more than useable_space.
131 total_sent_thistime = MIN(total_sent_thistime, useable_space);
133 reply_outbuf(req, 18,
134 total_sent_thistime + alignment_offset
135 + data_alignment_offset);
138 * We might have had SMBnttranss in req->inbuf, fix that.
140 SCVAL(req->outbuf, smb_com, SMBnttrans);
143 * Set total params and data to be sent.
146 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
147 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
150 * Calculate how many parameters and data we can fit into
151 * this packet. Parameters get precedence.
154 params_sent_thistime = MIN(params_to_send,useable_space);
155 data_sent_thistime = useable_space - params_sent_thistime;
156 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
158 SIVAL(req->outbuf, smb_ntr_ParameterCount,
159 params_sent_thistime);
161 if(params_sent_thistime == 0) {
162 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
163 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
164 } else {
166 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
167 * parameter bytes, however the first 4 bytes of outbuf are
168 * the Netbios over TCP header. Thus use smb_base() to subtract
169 * them from the calculation.
172 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
173 ((smb_buf(req->outbuf)+alignment_offset)
174 - smb_base(req->outbuf)));
176 * Absolute displacement of param bytes sent in this packet.
179 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
180 pp - params);
184 * Deal with the data portion.
187 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
189 if(data_sent_thistime == 0) {
190 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
191 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
192 } else {
194 * The offset of the data bytes is the offset of the
195 * parameter bytes plus the number of parameters being sent this time.
198 SIVAL(req->outbuf, smb_ntr_DataOffset,
199 ((smb_buf(req->outbuf)+alignment_offset) -
200 smb_base(req->outbuf))
201 + params_sent_thistime + data_alignment_offset);
202 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
206 * Copy the param bytes into the packet.
209 if(params_sent_thistime) {
210 if (alignment_offset != 0) {
211 memset(smb_buf(req->outbuf), 0,
212 alignment_offset);
214 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
215 params_sent_thistime);
219 * Copy in the data bytes
222 if(data_sent_thistime) {
223 if (data_alignment_offset != 0) {
224 memset((smb_buf(req->outbuf)+alignment_offset+
225 params_sent_thistime), 0,
226 data_alignment_offset);
228 memcpy(smb_buf(req->outbuf)+alignment_offset
229 +params_sent_thistime+data_alignment_offset,
230 pd,data_sent_thistime);
233 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
234 params_sent_thistime, data_sent_thistime, useable_space));
235 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
236 params_to_send, data_to_send, paramsize, datasize));
238 if (NT_STATUS_V(nt_error)) {
239 error_packet_set((char *)req->outbuf,
240 0, 0, nt_error,
241 __LINE__,__FILE__);
244 /* Send the packet */
245 show_msg((char *)req->outbuf);
246 if (!srv_send_smb(smbd_server_fd(),
247 (char *)req->outbuf,
248 true, req->seqnum+1,
249 IS_CONN_ENCRYPTED(conn),
250 &req->pcd)) {
251 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
254 TALLOC_FREE(req->outbuf);
256 pp += params_sent_thistime;
257 pd += data_sent_thistime;
259 params_to_send -= params_sent_thistime;
260 data_to_send -= data_sent_thistime;
263 * Sanity check
266 if(params_to_send < 0 || data_to_send < 0) {
267 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
268 params_to_send, data_to_send));
269 exit_server_cleanly("send_nt_replies: internal error");
274 /****************************************************************************
275 Reply to an NT create and X call on a pipe
276 ****************************************************************************/
278 static void nt_open_pipe(char *fname, connection_struct *conn,
279 struct smb_request *req, int *ppnum)
281 files_struct *fsp;
282 NTSTATUS status;
284 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
286 /* Strip \\ off the name. */
287 fname++;
289 status = open_np_file(req, fname, &fsp);
290 if (!NT_STATUS_IS_OK(status)) {
291 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
292 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
293 ERRDOS, ERRbadpipe);
294 return;
296 reply_nterror(req, status);
297 return;
300 *ppnum = fsp->fnum;
301 return;
304 /****************************************************************************
305 Reply to an NT create and X call for pipes.
306 ****************************************************************************/
308 static void do_ntcreate_pipe_open(connection_struct *conn,
309 struct smb_request *req)
311 char *fname = NULL;
312 int pnum = -1;
313 char *p = NULL;
314 uint32 flags = IVAL(req->vwv+3, 1);
315 TALLOC_CTX *ctx = talloc_tos();
317 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
319 if (!fname) {
320 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
321 ERRDOS, ERRbadpipe);
322 return;
324 nt_open_pipe(fname, conn, req, &pnum);
326 if (req->outbuf) {
327 /* error reply */
328 return;
332 * Deal with pipe return.
335 if (flags & EXTENDED_RESPONSE_REQUIRED) {
336 /* This is very strange. We
337 * return 50 words, but only set
338 * the wcnt to 42 ? It's definately
339 * what happens on the wire....
341 reply_outbuf(req, 50, 0);
342 SCVAL(req->outbuf,smb_wct,42);
343 } else {
344 reply_outbuf(req, 34, 0);
347 p = (char *)req->outbuf + smb_vwv2;
348 p++;
349 SSVAL(p,0,pnum);
350 p += 2;
351 SIVAL(p,0,FILE_WAS_OPENED);
352 p += 4;
353 p += 32;
354 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
355 p += 20;
356 /* File type. */
357 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
358 /* Device state. */
359 SSVAL(p,2, 0x5FF); /* ? */
360 p += 4;
362 if (flags & EXTENDED_RESPONSE_REQUIRED) {
363 p += 25;
364 SIVAL(p,0,FILE_GENERIC_ALL);
366 * For pipes W2K3 seems to return
367 * 0x12019B next.
368 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
370 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
373 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
375 chain_reply(req);
378 /****************************************************************************
379 Reply to an NT create and X call.
380 ****************************************************************************/
382 void reply_ntcreate_and_X(struct smb_request *req)
384 connection_struct *conn = req->conn;
385 struct smb_filename *smb_fname = NULL;
386 char *fname = NULL;
387 uint32 flags;
388 uint32 access_mask;
389 uint32 file_attributes;
390 uint32 share_access;
391 uint32 create_disposition;
392 uint32 create_options;
393 uint16 root_dir_fid;
394 uint64_t allocation_size;
395 /* Breakout the oplock request bits so we can set the
396 reply bits separately. */
397 uint32 fattr=0;
398 SMB_OFF_T file_len = 0;
399 int info = 0;
400 files_struct *fsp = NULL;
401 char *p = NULL;
402 struct timespec create_timespec;
403 struct timespec c_timespec;
404 struct timespec a_timespec;
405 struct timespec m_timespec;
406 struct timespec write_time_ts;
407 NTSTATUS status;
408 int oplock_request;
409 uint8_t oplock_granted = NO_OPLOCK_RETURN;
410 TALLOC_CTX *ctx = talloc_tos();
412 START_PROFILE(SMBntcreateX);
414 if (req->wct < 24) {
415 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
416 return;
419 flags = IVAL(req->vwv+3, 1);
420 access_mask = IVAL(req->vwv+7, 1);
421 file_attributes = IVAL(req->vwv+13, 1);
422 share_access = IVAL(req->vwv+15, 1);
423 create_disposition = IVAL(req->vwv+17, 1);
424 create_options = IVAL(req->vwv+19, 1);
425 root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
427 allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
428 #ifdef LARGE_SMB_OFF_T
429 allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
430 #endif
432 srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
433 STR_TERMINATE, &status);
435 if (!NT_STATUS_IS_OK(status)) {
436 reply_nterror(req, status);
437 goto out;
440 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
441 "file_attributes = 0x%x, share_access = 0x%x, "
442 "create_disposition = 0x%x create_options = 0x%x "
443 "root_dir_fid = 0x%x, fname = %s\n",
444 (unsigned int)flags,
445 (unsigned int)access_mask,
446 (unsigned int)file_attributes,
447 (unsigned int)share_access,
448 (unsigned int)create_disposition,
449 (unsigned int)create_options,
450 (unsigned int)root_dir_fid,
451 fname));
454 * we need to remove ignored bits when they come directly from the client
455 * because we reuse some of them for internal stuff
457 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
460 * If it's an IPC, use the pipe handler.
463 if (IS_IPC(conn)) {
464 if (lp_nt_pipe_support()) {
465 do_ntcreate_pipe_open(conn, req);
466 goto out;
468 reply_doserror(req, ERRDOS, ERRnoaccess);
469 goto out;
472 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
473 if (oplock_request) {
474 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
475 ? BATCH_OPLOCK : 0;
478 status = filename_convert(ctx,
479 conn,
480 req->flags2 & FLAGS2_DFS_PATHNAMES,
481 fname,
483 NULL,
484 &smb_fname);
486 if (!NT_STATUS_IS_OK(status)) {
487 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
488 reply_botherror(req,
489 NT_STATUS_PATH_NOT_COVERED,
490 ERRSRV, ERRbadpath);
491 goto out;
493 reply_nterror(req, status);
494 goto out;
497 status = SMB_VFS_CREATE_FILE(
498 conn, /* conn */
499 req, /* req */
500 root_dir_fid, /* root_dir_fid */
501 smb_fname, /* fname */
502 access_mask, /* access_mask */
503 share_access, /* share_access */
504 create_disposition, /* create_disposition*/
505 create_options, /* create_options */
506 file_attributes, /* file_attributes */
507 oplock_request, /* oplock_request */
508 allocation_size, /* allocation_size */
509 NULL, /* sd */
510 NULL, /* ea_list */
511 &fsp, /* result */
512 &info); /* pinfo */
514 if (!NT_STATUS_IS_OK(status)) {
515 if (open_was_deferred(req->mid)) {
516 /* We have re-scheduled this call, no error. */
517 goto out;
519 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
520 reply_botherror(req, status, ERRDOS, ERRfilexists);
522 else {
523 reply_nterror(req, status);
525 goto out;
528 /* Ensure we're pointing at the correct stat struct. */
529 TALLOC_FREE(smb_fname);
530 smb_fname = fsp->fsp_name;
533 * If the caller set the extended oplock request bit
534 * and we granted one (by whatever means) - set the
535 * correct bit for extended oplock reply.
538 if (oplock_request &&
539 (lp_fake_oplocks(SNUM(conn))
540 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
543 * Exclusive oplock granted
546 if (flags & REQUEST_BATCH_OPLOCK) {
547 oplock_granted = BATCH_OPLOCK_RETURN;
548 } else {
549 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
551 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
552 oplock_granted = LEVEL_II_OPLOCK_RETURN;
553 } else {
554 oplock_granted = NO_OPLOCK_RETURN;
557 file_len = smb_fname->st.st_ex_size;
558 fattr = dos_mode(conn, smb_fname);
559 if (fattr == 0) {
560 fattr = FILE_ATTRIBUTE_NORMAL;
563 if (flags & EXTENDED_RESPONSE_REQUIRED) {
564 /* This is very strange. We
565 * return 50 words, but only set
566 * the wcnt to 42 ? It's definately
567 * what happens on the wire....
569 reply_outbuf(req, 50, 0);
570 SCVAL(req->outbuf,smb_wct,42);
571 } else {
572 reply_outbuf(req, 34, 0);
575 p = (char *)req->outbuf + smb_vwv2;
577 SCVAL(p, 0, oplock_granted);
579 p++;
580 SSVAL(p,0,fsp->fnum);
581 p += 2;
582 if ((create_disposition == FILE_SUPERSEDE)
583 && (info == FILE_WAS_OVERWRITTEN)) {
584 SIVAL(p,0,FILE_WAS_SUPERSEDED);
585 } else {
586 SIVAL(p,0,info);
588 p += 4;
590 /* Deal with other possible opens having a modified
591 write time. JRA. */
592 ZERO_STRUCT(write_time_ts);
593 get_file_infos(fsp->file_id, NULL, &write_time_ts);
594 if (!null_timespec(write_time_ts)) {
595 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
598 /* Create time. */
599 create_timespec = get_create_timespec(conn, fsp, smb_fname);
600 a_timespec = smb_fname->st.st_ex_atime;
601 m_timespec = smb_fname->st.st_ex_mtime;
602 c_timespec = get_change_timespec(conn, fsp, smb_fname);
604 if (lp_dos_filetime_resolution(SNUM(conn))) {
605 dos_filetime_timespec(&create_timespec);
606 dos_filetime_timespec(&a_timespec);
607 dos_filetime_timespec(&m_timespec);
608 dos_filetime_timespec(&c_timespec);
611 put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
612 p += 8;
613 put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
614 p += 8;
615 put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
616 p += 8;
617 put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
618 p += 8;
619 SIVAL(p,0,fattr); /* File Attributes. */
620 p += 4;
621 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
622 p += 8;
623 SOFF_T(p,0,file_len);
624 p += 8;
625 if (flags & EXTENDED_RESPONSE_REQUIRED) {
626 uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
627 size_t num_names = 0;
628 unsigned int num_streams;
629 struct stream_struct *streams = NULL;
631 /* Do we have any EA's ? */
632 status = get_ea_names_from_file(ctx, conn, fsp,
633 smb_fname->base_name, NULL, &num_names);
634 if (NT_STATUS_IS_OK(status) && num_names) {
635 file_status &= ~NO_EAS;
637 status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, ctx,
638 &num_streams, &streams);
639 /* There is always one stream, ::$DATA. */
640 if (NT_STATUS_IS_OK(status) && num_streams > 1) {
641 file_status &= ~NO_SUBSTREAMS;
643 TALLOC_FREE(streams);
644 SSVAL(p,2,file_status);
646 p += 4;
647 SCVAL(p,0,fsp->is_directory ? 1 : 0);
649 if (flags & EXTENDED_RESPONSE_REQUIRED) {
650 uint32 perms = 0;
651 p += 25;
652 if (fsp->is_directory ||
653 can_write_to_file(conn, smb_fname)) {
654 perms = FILE_GENERIC_ALL;
655 } else {
656 perms = FILE_GENERIC_READ|FILE_EXECUTE;
658 SIVAL(p,0,perms);
661 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
662 fsp->fnum, smb_fname_str_dbg(smb_fname)));
664 chain_reply(req);
665 out:
666 END_PROFILE(SMBntcreateX);
667 return;
670 /****************************************************************************
671 Reply to a NT_TRANSACT_CREATE call to open a pipe.
672 ****************************************************************************/
674 static void do_nt_transact_create_pipe(connection_struct *conn,
675 struct smb_request *req,
676 uint16 **ppsetup, uint32 setup_count,
677 char **ppparams, uint32 parameter_count,
678 char **ppdata, uint32 data_count)
680 char *fname = NULL;
681 char *params = *ppparams;
682 int pnum = -1;
683 char *p = NULL;
684 NTSTATUS status;
685 size_t param_len;
686 uint32 flags;
687 TALLOC_CTX *ctx = talloc_tos();
690 * Ensure minimum number of parameters sent.
693 if(parameter_count < 54) {
694 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
695 reply_doserror(req, ERRDOS, ERRnoaccess);
696 return;
699 flags = IVAL(params,0);
701 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
702 parameter_count-53, STR_TERMINATE,
703 &status);
704 if (!NT_STATUS_IS_OK(status)) {
705 reply_nterror(req, status);
706 return;
709 nt_open_pipe(fname, conn, req, &pnum);
711 if (req->outbuf) {
712 /* Error return */
713 return;
716 /* Realloc the size of parameters and data we will return */
717 if (flags & EXTENDED_RESPONSE_REQUIRED) {
718 /* Extended response is 32 more byyes. */
719 param_len = 101;
720 } else {
721 param_len = 69;
723 params = nttrans_realloc(ppparams, param_len);
724 if(params == NULL) {
725 reply_doserror(req, ERRDOS, ERRnomem);
726 return;
729 p = params;
730 SCVAL(p,0,NO_OPLOCK_RETURN);
732 p += 2;
733 SSVAL(p,0,pnum);
734 p += 2;
735 SIVAL(p,0,FILE_WAS_OPENED);
736 p += 8;
738 p += 32;
739 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
740 p += 20;
741 /* File type. */
742 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
743 /* Device state. */
744 SSVAL(p,2, 0x5FF); /* ? */
745 p += 4;
747 if (flags & EXTENDED_RESPONSE_REQUIRED) {
748 p += 25;
749 SIVAL(p,0,FILE_GENERIC_ALL);
751 * For pipes W2K3 seems to return
752 * 0x12019B next.
753 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
755 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
758 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
760 /* Send the required number of replies */
761 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
763 return;
766 /****************************************************************************
767 Internal fn to set security descriptors.
768 ****************************************************************************/
770 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
771 uint32 security_info_sent)
773 SEC_DESC *psd = NULL;
774 NTSTATUS status;
776 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
777 return NT_STATUS_OK;
780 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
782 if (!NT_STATUS_IS_OK(status)) {
783 return status;
786 if (psd->owner_sid == NULL) {
787 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
789 if (psd->group_sid == NULL) {
790 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
793 /* Convert all the generic bits. */
794 security_acl_map_generic(psd->dacl, &file_generic_mapping);
795 security_acl_map_generic(psd->sacl, &file_generic_mapping);
797 if (DEBUGLEVEL >= 10) {
798 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
799 NDR_PRINT_DEBUG(security_descriptor, psd);
802 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
804 TALLOC_FREE(psd);
806 return status;
809 /****************************************************************************
810 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
811 ****************************************************************************/
813 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
815 struct ea_list *ea_list_head = NULL;
816 size_t offset = 0;
818 if (data_size < 4) {
819 return NULL;
822 while (offset + 4 <= data_size) {
823 size_t next_offset = IVAL(pdata,offset);
824 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
826 if (!eal) {
827 return NULL;
830 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
831 if (next_offset == 0) {
832 break;
834 offset += next_offset;
837 return ea_list_head;
840 /****************************************************************************
841 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
842 ****************************************************************************/
844 static void call_nt_transact_create(connection_struct *conn,
845 struct smb_request *req,
846 uint16 **ppsetup, uint32 setup_count,
847 char **ppparams, uint32 parameter_count,
848 char **ppdata, uint32 data_count,
849 uint32 max_data_count)
851 struct smb_filename *smb_fname = NULL;
852 char *fname = NULL;
853 char *params = *ppparams;
854 char *data = *ppdata;
855 /* Breakout the oplock request bits so we can set the reply bits separately. */
856 uint32 fattr=0;
857 SMB_OFF_T file_len = 0;
858 int info = 0;
859 files_struct *fsp = NULL;
860 char *p = NULL;
861 uint32 flags;
862 uint32 access_mask;
863 uint32 file_attributes;
864 uint32 share_access;
865 uint32 create_disposition;
866 uint32 create_options;
867 uint32 sd_len;
868 struct security_descriptor *sd = NULL;
869 uint32 ea_len;
870 uint16 root_dir_fid;
871 struct timespec create_timespec;
872 struct timespec c_timespec;
873 struct timespec a_timespec;
874 struct timespec m_timespec;
875 struct timespec write_time_ts;
876 struct ea_list *ea_list = NULL;
877 NTSTATUS status;
878 size_t param_len;
879 uint64_t allocation_size;
880 int oplock_request;
881 uint8_t oplock_granted;
882 TALLOC_CTX *ctx = talloc_tos();
884 DEBUG(5,("call_nt_transact_create\n"));
887 * If it's an IPC, use the pipe handler.
890 if (IS_IPC(conn)) {
891 if (lp_nt_pipe_support()) {
892 do_nt_transact_create_pipe(
893 conn, req,
894 ppsetup, setup_count,
895 ppparams, parameter_count,
896 ppdata, data_count);
897 goto out;
899 reply_doserror(req, ERRDOS, ERRnoaccess);
900 goto out;
904 * Ensure minimum number of parameters sent.
907 if(parameter_count < 54) {
908 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
909 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
910 goto out;
913 flags = IVAL(params,0);
914 access_mask = IVAL(params,8);
915 file_attributes = IVAL(params,20);
916 share_access = IVAL(params,24);
917 create_disposition = IVAL(params,28);
918 create_options = IVAL(params,32);
919 sd_len = IVAL(params,36);
920 ea_len = IVAL(params,40);
921 root_dir_fid = (uint16)IVAL(params,4);
922 allocation_size = (uint64_t)IVAL(params,12);
923 #ifdef LARGE_SMB_OFF_T
924 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
925 #endif
928 * we need to remove ignored bits when they come directly from the client
929 * because we reuse some of them for internal stuff
931 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
933 /* Ensure the data_len is correct for the sd and ea values given. */
934 if ((ea_len + sd_len > data_count)
935 || (ea_len > data_count) || (sd_len > data_count)
936 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
937 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
938 "%u, data_count = %u\n", (unsigned int)ea_len,
939 (unsigned int)sd_len, (unsigned int)data_count));
940 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
941 goto out;
944 if (sd_len) {
945 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
946 sd_len));
948 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
949 &sd);
950 if (!NT_STATUS_IS_OK(status)) {
951 DEBUG(10, ("call_nt_transact_create: "
952 "unmarshall_sec_desc failed: %s\n",
953 nt_errstr(status)));
954 reply_nterror(req, status);
955 goto out;
959 if (ea_len) {
960 if (!lp_ea_support(SNUM(conn))) {
961 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
962 "EA's not supported.\n",
963 (unsigned int)ea_len));
964 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
965 goto out;
968 if (ea_len < 10) {
969 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
970 "too small (should be more than 10)\n",
971 (unsigned int)ea_len ));
972 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
973 goto out;
976 /* We have already checked that ea_len <= data_count here. */
977 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
978 ea_len);
979 if (ea_list == NULL) {
980 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
981 goto out;
985 srvstr_get_path(ctx, params, req->flags2, &fname,
986 params+53, parameter_count-53,
987 STR_TERMINATE, &status);
988 if (!NT_STATUS_IS_OK(status)) {
989 reply_nterror(req, status);
990 goto out;
993 status = filename_convert(ctx,
994 conn,
995 req->flags2 & FLAGS2_DFS_PATHNAMES,
996 fname,
998 NULL,
999 &smb_fname);
1001 if (!NT_STATUS_IS_OK(status)) {
1002 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1003 reply_botherror(req,
1004 NT_STATUS_PATH_NOT_COVERED,
1005 ERRSRV, ERRbadpath);
1006 goto out;
1008 reply_nterror(req, status);
1009 goto out;
1012 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1013 if (oplock_request) {
1014 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
1015 ? BATCH_OPLOCK : 0;
1018 status = SMB_VFS_CREATE_FILE(
1019 conn, /* conn */
1020 req, /* req */
1021 root_dir_fid, /* root_dir_fid */
1022 smb_fname, /* fname */
1023 access_mask, /* access_mask */
1024 share_access, /* share_access */
1025 create_disposition, /* create_disposition*/
1026 create_options, /* create_options */
1027 file_attributes, /* file_attributes */
1028 oplock_request, /* oplock_request */
1029 allocation_size, /* allocation_size */
1030 sd, /* sd */
1031 ea_list, /* ea_list */
1032 &fsp, /* result */
1033 &info); /* pinfo */
1035 if(!NT_STATUS_IS_OK(status)) {
1036 if (open_was_deferred(req->mid)) {
1037 /* We have re-scheduled this call, no error. */
1038 return;
1040 reply_openerror(req, status);
1041 goto out;
1044 /* Ensure we're pointing at the correct stat struct. */
1045 TALLOC_FREE(smb_fname);
1046 smb_fname = fsp->fsp_name;
1049 * If the caller set the extended oplock request bit
1050 * and we granted one (by whatever means) - set the
1051 * correct bit for extended oplock reply.
1054 if (oplock_request &&
1055 (lp_fake_oplocks(SNUM(conn))
1056 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1059 * Exclusive oplock granted
1062 if (flags & REQUEST_BATCH_OPLOCK) {
1063 oplock_granted = BATCH_OPLOCK_RETURN;
1064 } else {
1065 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1067 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1068 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1069 } else {
1070 oplock_granted = NO_OPLOCK_RETURN;
1073 file_len = smb_fname->st.st_ex_size;
1074 fattr = dos_mode(conn, smb_fname);
1075 if (fattr == 0) {
1076 fattr = FILE_ATTRIBUTE_NORMAL;
1079 /* Realloc the size of parameters and data we will return */
1080 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1081 /* Extended response is 32 more byyes. */
1082 param_len = 101;
1083 } else {
1084 param_len = 69;
1086 params = nttrans_realloc(ppparams, param_len);
1087 if(params == NULL) {
1088 reply_doserror(req, ERRDOS, ERRnomem);
1089 goto out;
1092 p = params;
1093 SCVAL(p, 0, oplock_granted);
1095 p += 2;
1096 SSVAL(p,0,fsp->fnum);
1097 p += 2;
1098 if ((create_disposition == FILE_SUPERSEDE)
1099 && (info == FILE_WAS_OVERWRITTEN)) {
1100 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1101 } else {
1102 SIVAL(p,0,info);
1104 p += 8;
1106 /* Deal with other possible opens having a modified
1107 write time. JRA. */
1108 ZERO_STRUCT(write_time_ts);
1109 get_file_infos(fsp->file_id, NULL, &write_time_ts);
1110 if (!null_timespec(write_time_ts)) {
1111 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
1114 /* Create time. */
1115 create_timespec = get_create_timespec(conn, fsp, smb_fname);
1116 a_timespec = smb_fname->st.st_ex_atime;
1117 m_timespec = smb_fname->st.st_ex_mtime;
1118 c_timespec = get_change_timespec(conn, fsp, smb_fname);
1120 if (lp_dos_filetime_resolution(SNUM(conn))) {
1121 dos_filetime_timespec(&create_timespec);
1122 dos_filetime_timespec(&a_timespec);
1123 dos_filetime_timespec(&m_timespec);
1124 dos_filetime_timespec(&c_timespec);
1127 put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
1128 p += 8;
1129 put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
1130 p += 8;
1131 put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
1132 p += 8;
1133 put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
1134 p += 8;
1135 SIVAL(p,0,fattr); /* File Attributes. */
1136 p += 4;
1137 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1138 p += 8;
1139 SOFF_T(p,0,file_len);
1140 p += 8;
1141 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1142 SSVAL(p,2,0x7);
1144 p += 4;
1145 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1147 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1148 uint32 perms = 0;
1149 p += 25;
1150 if (fsp->is_directory ||
1151 can_write_to_file(conn, smb_fname)) {
1152 perms = FILE_GENERIC_ALL;
1153 } else {
1154 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1156 SIVAL(p,0,perms);
1159 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1160 smb_fname_str_dbg(smb_fname)));
1162 /* Send the required number of replies */
1163 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1164 out:
1165 return;
1168 /****************************************************************************
1169 Reply to a NT CANCEL request.
1170 conn POINTER CAN BE NULL HERE !
1171 ****************************************************************************/
1173 void reply_ntcancel(struct smb_request *req)
1176 * Go through and cancel any pending change notifies.
1179 START_PROFILE(SMBntcancel);
1180 srv_cancel_sign_response(smbd_server_conn);
1181 remove_pending_change_notify_requests_by_mid(req->mid);
1182 remove_pending_lock_requests_by_mid(req->mid);
1184 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1186 END_PROFILE(SMBntcancel);
1187 return;
1190 /****************************************************************************
1191 Copy a file.
1192 ****************************************************************************/
1194 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1195 connection_struct *conn,
1196 struct smb_request *req,
1197 struct smb_filename *smb_fname_src,
1198 struct smb_filename *smb_fname_dst,
1199 uint32 attrs)
1201 files_struct *fsp1,*fsp2;
1202 uint32 fattr;
1203 int info;
1204 SMB_OFF_T ret=-1;
1205 NTSTATUS status = NT_STATUS_OK;
1206 char *parent;
1208 if (!CAN_WRITE(conn)) {
1209 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1210 goto out;
1213 /* Source must already exist. */
1214 if (!VALID_STAT(smb_fname_src->st)) {
1215 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1216 goto out;
1219 /* Ensure attributes match. */
1220 fattr = dos_mode(conn, smb_fname_src);
1221 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1222 status = NT_STATUS_NO_SUCH_FILE;
1223 goto out;
1226 /* Disallow if dst file already exists. */
1227 if (VALID_STAT(smb_fname_dst->st)) {
1228 status = NT_STATUS_OBJECT_NAME_COLLISION;
1229 goto out;
1232 /* No links from a directory. */
1233 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1234 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1235 goto out;
1238 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1239 smb_fname_str_dbg(smb_fname_src),
1240 smb_fname_str_dbg(smb_fname_dst)));
1242 status = SMB_VFS_CREATE_FILE(
1243 conn, /* conn */
1244 req, /* req */
1245 0, /* root_dir_fid */
1246 smb_fname_src, /* fname */
1247 FILE_READ_DATA, /* access_mask */
1248 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1249 FILE_SHARE_DELETE),
1250 FILE_OPEN, /* create_disposition*/
1251 0, /* create_options */
1252 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1253 NO_OPLOCK, /* oplock_request */
1254 0, /* allocation_size */
1255 NULL, /* sd */
1256 NULL, /* ea_list */
1257 &fsp1, /* result */
1258 &info); /* pinfo */
1260 if (!NT_STATUS_IS_OK(status)) {
1261 goto out;
1264 status = SMB_VFS_CREATE_FILE(
1265 conn, /* conn */
1266 req, /* req */
1267 0, /* root_dir_fid */
1268 smb_fname_dst, /* fname */
1269 FILE_WRITE_DATA, /* access_mask */
1270 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1271 FILE_SHARE_DELETE),
1272 FILE_CREATE, /* create_disposition*/
1273 0, /* create_options */
1274 fattr, /* file_attributes */
1275 NO_OPLOCK, /* oplock_request */
1276 0, /* allocation_size */
1277 NULL, /* sd */
1278 NULL, /* ea_list */
1279 &fsp2, /* result */
1280 &info); /* pinfo */
1282 if (!NT_STATUS_IS_OK(status)) {
1283 close_file(NULL, fsp1, ERROR_CLOSE);
1284 goto out;
1287 if (smb_fname_src->st.st_ex_size) {
1288 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1292 * As we are opening fsp1 read-only we only expect
1293 * an error on close on fsp2 if we are out of space.
1294 * Thus we don't look at the error return from the
1295 * close of fsp1.
1297 close_file(NULL, fsp1, NORMAL_CLOSE);
1299 /* Ensure the modtime is set correctly on the destination file. */
1300 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1302 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1304 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1305 creates the file. This isn't the correct thing to do in the copy
1306 case. JRA */
1307 if (!parent_dirname(talloc_tos(), smb_fname_dst->base_name, &parent,
1308 NULL)) {
1309 status = NT_STATUS_NO_MEMORY;
1310 goto out;
1312 file_set_dosmode(conn, smb_fname_dst, fattr, parent, false);
1313 TALLOC_FREE(parent);
1315 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1316 status = NT_STATUS_DISK_FULL;
1317 goto out;
1319 out:
1320 if (!NT_STATUS_IS_OK(status)) {
1321 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1322 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1323 smb_fname_str_dbg(smb_fname_dst)));
1326 return status;
1329 /****************************************************************************
1330 Reply to a NT rename request.
1331 ****************************************************************************/
1333 void reply_ntrename(struct smb_request *req)
1335 connection_struct *conn = req->conn;
1336 struct smb_filename *smb_fname_old = NULL;
1337 struct smb_filename *smb_fname_new = NULL;
1338 char *oldname = NULL;
1339 char *newname = NULL;
1340 const char *p;
1341 NTSTATUS status;
1342 bool src_has_wcard = False;
1343 bool dest_has_wcard = False;
1344 uint32 attrs;
1345 uint32_t ucf_flags_src = 0;
1346 uint32_t ucf_flags_dst = 0;
1347 uint16 rename_type;
1348 TALLOC_CTX *ctx = talloc_tos();
1350 START_PROFILE(SMBntrename);
1352 if (req->wct < 4) {
1353 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1354 goto out;
1357 attrs = SVAL(req->vwv+0, 0);
1358 rename_type = SVAL(req->vwv+1, 0);
1360 p = (const char *)req->buf + 1;
1361 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1362 &status, &src_has_wcard);
1363 if (!NT_STATUS_IS_OK(status)) {
1364 reply_nterror(req, status);
1365 goto out;
1368 if (ms_has_wild(oldname)) {
1369 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1370 goto out;
1373 p++;
1374 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1375 &status, &dest_has_wcard);
1376 if (!NT_STATUS_IS_OK(status)) {
1377 reply_nterror(req, status);
1378 goto out;
1381 /* The newname must begin with a ':' if the oldname contains a ':'. */
1382 if (strchr_m(oldname, ':') && (newname[0] != ':')) {
1383 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1384 goto out;
1388 * If this is a rename operation, allow wildcards and save the
1389 * destination's last component.
1391 if (rename_type == RENAME_FLAG_RENAME) {
1392 ucf_flags_src = UCF_COND_ALLOW_WCARD_LCOMP;
1393 ucf_flags_dst = UCF_COND_ALLOW_WCARD_LCOMP | UCF_SAVE_LCOMP;
1396 /* rename_internals() calls unix_convert(), so don't call it here. */
1397 status = filename_convert(ctx, conn,
1398 req->flags2 & FLAGS2_DFS_PATHNAMES,
1399 oldname,
1400 ucf_flags_src,
1401 NULL,
1402 &smb_fname_old);
1403 if (!NT_STATUS_IS_OK(status)) {
1404 if (NT_STATUS_EQUAL(status,
1405 NT_STATUS_PATH_NOT_COVERED)) {
1406 reply_botherror(req,
1407 NT_STATUS_PATH_NOT_COVERED,
1408 ERRSRV, ERRbadpath);
1409 goto out;
1411 reply_nterror(req, status);
1412 goto out;
1415 status = filename_convert(ctx, conn,
1416 req->flags2 & FLAGS2_DFS_PATHNAMES,
1417 newname,
1418 ucf_flags_dst,
1419 &dest_has_wcard,
1420 &smb_fname_new);
1421 if (!NT_STATUS_IS_OK(status)) {
1422 if (NT_STATUS_EQUAL(status,
1423 NT_STATUS_PATH_NOT_COVERED)) {
1424 reply_botherror(req,
1425 NT_STATUS_PATH_NOT_COVERED,
1426 ERRSRV, ERRbadpath);
1427 goto out;
1429 reply_nterror(req, status);
1430 goto out;
1433 DEBUG(3,("reply_ntrename: %s -> %s\n",
1434 smb_fname_str_dbg(smb_fname_old),
1435 smb_fname_str_dbg(smb_fname_new)));
1437 switch(rename_type) {
1438 case RENAME_FLAG_RENAME:
1439 status = rename_internals(ctx, conn, req,
1440 smb_fname_old, smb_fname_new,
1441 attrs, False, src_has_wcard,
1442 dest_has_wcard,
1443 DELETE_ACCESS);
1444 break;
1445 case RENAME_FLAG_HARD_LINK:
1446 if (src_has_wcard || dest_has_wcard) {
1447 /* No wildcards. */
1448 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1449 } else {
1450 status = hardlink_internals(ctx, conn,
1451 smb_fname_old,
1452 smb_fname_new);
1454 break;
1455 case RENAME_FLAG_COPY:
1456 if (src_has_wcard || dest_has_wcard) {
1457 /* No wildcards. */
1458 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1459 } else {
1460 status = copy_internals(ctx, conn, req,
1461 smb_fname_old,
1462 smb_fname_new,
1463 attrs);
1465 break;
1466 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1467 status = NT_STATUS_INVALID_PARAMETER;
1468 break;
1469 default:
1470 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1471 break;
1474 if (!NT_STATUS_IS_OK(status)) {
1475 if (open_was_deferred(req->mid)) {
1476 /* We have re-scheduled this call. */
1477 goto out;
1480 reply_nterror(req, status);
1481 goto out;
1484 reply_outbuf(req, 0, 0);
1485 out:
1486 END_PROFILE(SMBntrename);
1487 return;
1490 /****************************************************************************
1491 Reply to a notify change - queue the request and
1492 don't allow a directory to be opened.
1493 ****************************************************************************/
1495 static void smbd_smb1_notify_reply(struct smb_request *req,
1496 NTSTATUS error_code,
1497 uint8_t *buf, size_t len)
1499 send_nt_replies(req->conn, req, error_code, (char *)buf, len, NULL, 0);
1502 static void call_nt_transact_notify_change(connection_struct *conn,
1503 struct smb_request *req,
1504 uint16 **ppsetup,
1505 uint32 setup_count,
1506 char **ppparams,
1507 uint32 parameter_count,
1508 char **ppdata, uint32 data_count,
1509 uint32 max_data_count,
1510 uint32 max_param_count)
1512 uint16 *setup = *ppsetup;
1513 files_struct *fsp;
1514 uint32 filter;
1515 NTSTATUS status;
1516 bool recursive;
1518 if(setup_count < 6) {
1519 reply_doserror(req, ERRDOS, ERRbadfunc);
1520 return;
1523 fsp = file_fsp(req, SVAL(setup,4));
1524 filter = IVAL(setup, 0);
1525 recursive = (SVAL(setup, 6) != 0) ? True : False;
1527 DEBUG(3,("call_nt_transact_notify_change\n"));
1529 if(!fsp) {
1530 reply_doserror(req, ERRDOS, ERRbadfid);
1531 return;
1535 char *filter_string;
1537 if (!(filter_string = notify_filter_string(NULL, filter))) {
1538 reply_nterror(req,NT_STATUS_NO_MEMORY);
1539 return;
1542 DEBUG(3,("call_nt_transact_notify_change: notify change "
1543 "called on %s, filter = %s, recursive = %d\n",
1544 fsp_str_dbg(fsp), filter_string, recursive));
1546 TALLOC_FREE(filter_string);
1549 if((!fsp->is_directory) || (conn != fsp->conn)) {
1550 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1551 return;
1554 if (fsp->notify == NULL) {
1556 status = change_notify_create(fsp, filter, recursive);
1558 if (!NT_STATUS_IS_OK(status)) {
1559 DEBUG(10, ("change_notify_create returned %s\n",
1560 nt_errstr(status)));
1561 reply_nterror(req, status);
1562 return;
1566 if (fsp->notify->num_changes != 0) {
1569 * We've got changes pending, respond immediately
1573 * TODO: write a torture test to check the filtering behaviour
1574 * here.
1577 change_notify_reply(fsp->conn, req,
1578 NT_STATUS_OK,
1579 max_param_count,
1580 fsp->notify,
1581 smbd_smb1_notify_reply);
1584 * change_notify_reply() above has independently sent its
1585 * results
1587 return;
1591 * No changes pending, queue the request
1594 status = change_notify_add_request(req,
1595 max_param_count,
1596 filter,
1597 recursive, fsp,
1598 smbd_smb1_notify_reply);
1599 if (!NT_STATUS_IS_OK(status)) {
1600 reply_nterror(req, status);
1602 return;
1605 /****************************************************************************
1606 Reply to an NT transact rename command.
1607 ****************************************************************************/
1609 static void call_nt_transact_rename(connection_struct *conn,
1610 struct smb_request *req,
1611 uint16 **ppsetup, uint32 setup_count,
1612 char **ppparams, uint32 parameter_count,
1613 char **ppdata, uint32 data_count,
1614 uint32 max_data_count)
1616 char *params = *ppparams;
1617 char *new_name = NULL;
1618 files_struct *fsp = NULL;
1619 bool dest_has_wcard = False;
1620 NTSTATUS status;
1621 TALLOC_CTX *ctx = talloc_tos();
1623 if(parameter_count < 5) {
1624 reply_doserror(req, ERRDOS, ERRbadfunc);
1625 return;
1628 fsp = file_fsp(req, SVAL(params, 0));
1629 if (!check_fsp(conn, req, fsp)) {
1630 return;
1632 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1633 parameter_count - 4,
1634 STR_TERMINATE, &status, &dest_has_wcard);
1635 if (!NT_STATUS_IS_OK(status)) {
1636 reply_nterror(req, status);
1637 return;
1641 * W2K3 ignores this request as the RAW-RENAME test
1642 * demonstrates, so we do.
1644 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1646 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1647 fsp_str_dbg(fsp), new_name));
1649 return;
1652 /******************************************************************************
1653 Fake up a completely empty SD.
1654 *******************************************************************************/
1656 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1658 size_t sd_size;
1660 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1661 if(!*ppsd) {
1662 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1663 return NT_STATUS_NO_MEMORY;
1666 return NT_STATUS_OK;
1669 /****************************************************************************
1670 Reply to query a security descriptor.
1671 ****************************************************************************/
1673 static void call_nt_transact_query_security_desc(connection_struct *conn,
1674 struct smb_request *req,
1675 uint16 **ppsetup,
1676 uint32 setup_count,
1677 char **ppparams,
1678 uint32 parameter_count,
1679 char **ppdata,
1680 uint32 data_count,
1681 uint32 max_data_count)
1683 char *params = *ppparams;
1684 char *data = *ppdata;
1685 SEC_DESC *psd = NULL;
1686 size_t sd_size;
1687 uint32 security_info_wanted;
1688 files_struct *fsp = NULL;
1689 NTSTATUS status;
1690 DATA_BLOB blob;
1692 if(parameter_count < 8) {
1693 reply_doserror(req, ERRDOS, ERRbadfunc);
1694 return;
1697 fsp = file_fsp(req, SVAL(params,0));
1698 if(!fsp) {
1699 reply_doserror(req, ERRDOS, ERRbadfid);
1700 return;
1703 security_info_wanted = IVAL(params,4);
1705 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1706 "info_wanted = 0x%x\n", fsp_str_dbg(fsp),
1707 (unsigned int)security_info_wanted));
1709 params = nttrans_realloc(ppparams, 4);
1710 if(params == NULL) {
1711 reply_doserror(req, ERRDOS, ERRnomem);
1712 return;
1716 * Get the permissions to return.
1719 if (!lp_nt_acl_support(SNUM(conn))) {
1720 status = get_null_nt_acl(talloc_tos(), &psd);
1721 } else {
1722 status = SMB_VFS_FGET_NT_ACL(
1723 fsp, security_info_wanted, &psd);
1725 if (!NT_STATUS_IS_OK(status)) {
1726 reply_nterror(req, status);
1727 return;
1730 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1731 * present in the reply to match Windows behavior */
1732 if (psd->sacl == NULL &&
1733 security_info_wanted & SACL_SECURITY_INFORMATION)
1734 psd->type |= SEC_DESC_SACL_PRESENT;
1735 if (psd->dacl == NULL &&
1736 security_info_wanted & DACL_SECURITY_INFORMATION)
1737 psd->type |= SEC_DESC_DACL_PRESENT;
1739 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1741 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1743 if (DEBUGLEVEL >= 10) {
1744 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
1745 fsp_str_dbg(fsp)));
1746 NDR_PRINT_DEBUG(security_descriptor, psd);
1749 SIVAL(params,0,(uint32)sd_size);
1751 if (max_data_count < sd_size) {
1752 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1753 params, 4, *ppdata, 0);
1754 return;
1758 * Allocate the data we will point this at.
1761 data = nttrans_realloc(ppdata, sd_size);
1762 if(data == NULL) {
1763 reply_doserror(req, ERRDOS, ERRnomem);
1764 return;
1767 status = marshall_sec_desc(talloc_tos(), psd,
1768 &blob.data, &blob.length);
1770 if (!NT_STATUS_IS_OK(status)) {
1771 reply_nterror(req, status);
1772 return;
1775 SMB_ASSERT(sd_size == blob.length);
1776 memcpy(data, blob.data, sd_size);
1778 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1780 return;
1783 /****************************************************************************
1784 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1785 ****************************************************************************/
1787 static void call_nt_transact_set_security_desc(connection_struct *conn,
1788 struct smb_request *req,
1789 uint16 **ppsetup,
1790 uint32 setup_count,
1791 char **ppparams,
1792 uint32 parameter_count,
1793 char **ppdata,
1794 uint32 data_count,
1795 uint32 max_data_count)
1797 char *params= *ppparams;
1798 char *data = *ppdata;
1799 files_struct *fsp = NULL;
1800 uint32 security_info_sent = 0;
1801 NTSTATUS status;
1803 if(parameter_count < 8) {
1804 reply_doserror(req, ERRDOS, ERRbadfunc);
1805 return;
1808 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1809 reply_doserror(req, ERRDOS, ERRbadfid);
1810 return;
1813 if(!lp_nt_acl_support(SNUM(conn))) {
1814 goto done;
1817 security_info_sent = IVAL(params,4);
1819 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1820 fsp_str_dbg(fsp), (unsigned int)security_info_sent));
1822 if (data_count == 0) {
1823 reply_doserror(req, ERRDOS, ERRnoaccess);
1824 return;
1827 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1829 if (!NT_STATUS_IS_OK(status)) {
1830 reply_nterror(req, status);
1831 return;
1834 done:
1835 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1836 return;
1839 /****************************************************************************
1840 Reply to NT IOCTL
1841 ****************************************************************************/
1843 static void call_nt_transact_ioctl(connection_struct *conn,
1844 struct smb_request *req,
1845 uint16 **ppsetup, uint32 setup_count,
1846 char **ppparams, uint32 parameter_count,
1847 char **ppdata, uint32 data_count,
1848 uint32 max_data_count)
1850 uint32 function;
1851 uint16 fidnum;
1852 files_struct *fsp;
1853 uint8 isFSctl;
1854 uint8 compfilter;
1855 char *pdata = *ppdata;
1857 if (setup_count != 8) {
1858 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1859 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1860 return;
1863 function = IVAL(*ppsetup, 0);
1864 fidnum = SVAL(*ppsetup, 4);
1865 isFSctl = CVAL(*ppsetup, 6);
1866 compfilter = CVAL(*ppsetup, 7);
1868 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1869 function, fidnum, isFSctl, compfilter));
1871 fsp=file_fsp(req, fidnum);
1872 /* this check is done in each implemented function case for now
1873 because I don't want to break anything... --metze
1874 FSP_BELONGS_CONN(fsp,conn);*/
1876 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1878 switch (function) {
1879 case FSCTL_SET_SPARSE:
1880 /* pretend this succeeded - tho strictly we should
1881 mark the file sparse (if the local fs supports it)
1882 so we can know if we need to pre-allocate or not */
1884 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1885 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1886 return;
1888 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1890 unsigned char objid[16];
1892 /* This should return the object-id on this file.
1893 * I think I'll make this be the inode+dev. JRA.
1896 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1898 if (!fsp_belongs_conn(conn, req, fsp)) {
1899 return;
1902 data_count = 64;
1903 pdata = nttrans_realloc(ppdata, data_count);
1904 if (pdata == NULL) {
1905 reply_nterror(req, NT_STATUS_NO_MEMORY);
1906 return;
1909 /* For backwards compatibility only store the dev/inode. */
1910 push_file_id_16(pdata, &fsp->file_id);
1911 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1912 push_file_id_16(pdata+32, &fsp->file_id);
1913 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1914 pdata, data_count);
1915 return;
1918 case FSCTL_GET_REPARSE_POINT:
1919 /* pretend this fail - my winXP does it like this
1920 * --metze
1923 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1924 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1925 return;
1927 case FSCTL_SET_REPARSE_POINT:
1928 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1929 * --metze
1932 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1933 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1934 return;
1936 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1939 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1940 * and return their volume names. If max_data_count is 16, then it is just
1941 * asking for the number of volumes and length of the combined names.
1943 * pdata is the data allocated by our caller, but that uses
1944 * total_data_count (which is 0 in our case) rather than max_data_count.
1945 * Allocate the correct amount and return the pointer to let
1946 * it be deallocated when we return.
1948 SHADOW_COPY_DATA *shadow_data = NULL;
1949 TALLOC_CTX *shadow_mem_ctx = NULL;
1950 bool labels = False;
1951 uint32 labels_data_count = 0;
1952 uint32 i;
1953 char *cur_pdata;
1955 if (!fsp_belongs_conn(conn, req, fsp)) {
1956 return;
1959 if (max_data_count < 16) {
1960 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1961 max_data_count));
1962 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1963 return;
1966 if (max_data_count > 16) {
1967 labels = True;
1970 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1971 if (shadow_mem_ctx == NULL) {
1972 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1973 reply_nterror(req, NT_STATUS_NO_MEMORY);
1974 return;
1977 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
1978 if (shadow_data == NULL) {
1979 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1980 talloc_destroy(shadow_mem_ctx);
1981 reply_nterror(req, NT_STATUS_NO_MEMORY);
1982 return;
1985 shadow_data->mem_ctx = shadow_mem_ctx;
1988 * Call the VFS routine to actually do the work.
1990 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1991 talloc_destroy(shadow_data->mem_ctx);
1992 if (errno == ENOSYS) {
1993 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1994 conn->connectpath));
1995 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1996 return;
1997 } else {
1998 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1999 conn->connectpath));
2000 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
2001 return;
2005 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2007 if (!labels) {
2008 data_count = 16;
2009 } else {
2010 data_count = 12+labels_data_count+4;
2013 if (max_data_count<data_count) {
2014 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2015 max_data_count,data_count));
2016 talloc_destroy(shadow_data->mem_ctx);
2017 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2018 return;
2021 pdata = nttrans_realloc(ppdata, data_count);
2022 if (pdata == NULL) {
2023 talloc_destroy(shadow_data->mem_ctx);
2024 reply_nterror(req, NT_STATUS_NO_MEMORY);
2025 return;
2028 cur_pdata = pdata;
2030 /* num_volumes 4 bytes */
2031 SIVAL(pdata,0,shadow_data->num_volumes);
2033 if (labels) {
2034 /* num_labels 4 bytes */
2035 SIVAL(pdata,4,shadow_data->num_volumes);
2038 /* needed_data_count 4 bytes */
2039 SIVAL(pdata,8,labels_data_count);
2041 cur_pdata+=12;
2043 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2044 shadow_data->num_volumes, fsp_str_dbg(fsp)));
2045 if (labels && shadow_data->labels) {
2046 for (i=0;i<shadow_data->num_volumes;i++) {
2047 srvstr_push(pdata, req->flags2,
2048 cur_pdata, shadow_data->labels[i],
2049 2*sizeof(SHADOW_COPY_LABEL),
2050 STR_UNICODE|STR_TERMINATE);
2051 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2052 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2056 talloc_destroy(shadow_data->mem_ctx);
2058 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2059 pdata, data_count);
2061 return;
2064 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2066 /* pretend this succeeded -
2068 * we have to send back a list with all files owned by this SID
2070 * but I have to check that --metze
2072 DOM_SID sid;
2073 uid_t uid;
2074 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2076 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2078 if (!fsp_belongs_conn(conn, req, fsp)) {
2079 return;
2082 /* unknown 4 bytes: this is not the length of the sid :-( */
2083 /*unknown = IVAL(pdata,0);*/
2085 sid_parse(pdata+4,sid_len,&sid);
2086 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2088 if (!sid_to_uid(&sid, &uid)) {
2089 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2090 sid_string_dbg(&sid),
2091 (unsigned long)sid_len));
2092 uid = (-1);
2095 /* we can take a look at the find source :-)
2097 * find ./ -uid $uid -name '*' is what we need here
2100 * and send 4bytes len and then NULL terminated unicode strings
2101 * for each file
2103 * but I don't know how to deal with the paged results
2104 * (maybe we can hang the result anywhere in the fsp struct)
2106 * we don't send all files at once
2107 * and at the next we should *not* start from the beginning,
2108 * so we have to cache the result
2110 * --metze
2113 /* this works for now... */
2114 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2115 return;
2117 default:
2118 if (!logged_ioctl_message) {
2119 logged_ioctl_message = true; /* Only print this once... */
2120 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2121 function));
2125 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2129 #ifdef HAVE_SYS_QUOTAS
2130 /****************************************************************************
2131 Reply to get user quota
2132 ****************************************************************************/
2134 static void call_nt_transact_get_user_quota(connection_struct *conn,
2135 struct smb_request *req,
2136 uint16 **ppsetup,
2137 uint32 setup_count,
2138 char **ppparams,
2139 uint32 parameter_count,
2140 char **ppdata,
2141 uint32 data_count,
2142 uint32 max_data_count)
2144 NTSTATUS nt_status = NT_STATUS_OK;
2145 char *params = *ppparams;
2146 char *pdata = *ppdata;
2147 char *entry;
2148 int data_len=0,param_len=0;
2149 int qt_len=0;
2150 int entry_len = 0;
2151 files_struct *fsp = NULL;
2152 uint16 level = 0;
2153 size_t sid_len;
2154 DOM_SID sid;
2155 bool start_enum = True;
2156 SMB_NTQUOTA_STRUCT qt;
2157 SMB_NTQUOTA_LIST *tmp_list;
2158 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2160 ZERO_STRUCT(qt);
2162 /* access check */
2163 if (conn->server_info->utok.uid != 0) {
2164 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2165 "[%s]\n", lp_servicename(SNUM(conn)),
2166 conn->server_info->unix_name));
2167 reply_doserror(req, ERRDOS, ERRnoaccess);
2168 return;
2172 * Ensure minimum number of parameters sent.
2175 if (parameter_count < 4) {
2176 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2177 reply_doserror(req, ERRDOS, ERRinvalidparam);
2178 return;
2181 /* maybe we can check the quota_fnum */
2182 fsp = file_fsp(req, SVAL(params,0));
2183 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2184 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2185 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2186 return;
2189 /* the NULL pointer checking for fsp->fake_file_handle->pd
2190 * is done by CHECK_NTQUOTA_HANDLE_OK()
2192 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2194 level = SVAL(params,2);
2196 /* unknown 12 bytes leading in params */
2198 switch (level) {
2199 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2200 /* seems that we should continue with the enum here --metze */
2202 if (qt_handle->quota_list!=NULL &&
2203 qt_handle->tmp_list==NULL) {
2205 /* free the list */
2206 free_ntquota_list(&(qt_handle->quota_list));
2208 /* Realloc the size of parameters and data we will return */
2209 param_len = 4;
2210 params = nttrans_realloc(ppparams, param_len);
2211 if(params == NULL) {
2212 reply_doserror(req, ERRDOS, ERRnomem);
2213 return;
2216 data_len = 0;
2217 SIVAL(params,0,data_len);
2219 break;
2222 start_enum = False;
2224 case TRANSACT_GET_USER_QUOTA_LIST_START:
2226 if (qt_handle->quota_list==NULL &&
2227 qt_handle->tmp_list==NULL) {
2228 start_enum = True;
2231 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2232 reply_doserror(req, ERRSRV, ERRerror);
2233 return;
2236 /* Realloc the size of parameters and data we will return */
2237 param_len = 4;
2238 params = nttrans_realloc(ppparams, param_len);
2239 if(params == NULL) {
2240 reply_doserror(req, ERRDOS, ERRnomem);
2241 return;
2244 /* we should not trust the value in max_data_count*/
2245 max_data_count = MIN(max_data_count,2048);
2247 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2248 if(pdata == NULL) {
2249 reply_doserror(req, ERRDOS, ERRnomem);
2250 return;
2253 entry = pdata;
2255 /* set params Size of returned Quota Data 4 bytes*/
2256 /* but set it later when we know it */
2258 /* for each entry push the data */
2260 if (start_enum) {
2261 qt_handle->tmp_list = qt_handle->quota_list;
2264 tmp_list = qt_handle->tmp_list;
2266 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2267 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2269 sid_len = ndr_size_dom_sid(
2270 &tmp_list->quotas->sid, NULL, 0);
2271 entry_len = 40 + sid_len;
2273 /* nextoffset entry 4 bytes */
2274 SIVAL(entry,0,entry_len);
2276 /* then the len of the SID 4 bytes */
2277 SIVAL(entry,4,sid_len);
2279 /* unknown data 8 bytes uint64_t */
2280 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2282 /* the used disk space 8 bytes uint64_t */
2283 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2285 /* the soft quotas 8 bytes uint64_t */
2286 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2288 /* the hard quotas 8 bytes uint64_t */
2289 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2291 /* and now the SID */
2292 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2295 qt_handle->tmp_list = tmp_list;
2297 /* overwrite the offset of the last entry */
2298 SIVAL(entry-entry_len,0,0);
2300 data_len = 4+qt_len;
2301 /* overwrite the params quota_data_len */
2302 SIVAL(params,0,data_len);
2304 break;
2306 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2308 /* unknown 4 bytes IVAL(pdata,0) */
2310 if (data_count < 8) {
2311 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2312 reply_doserror(req, ERRDOS, ERRunknownlevel);
2313 return;
2316 sid_len = IVAL(pdata,4);
2317 /* Ensure this is less than 1mb. */
2318 if (sid_len > (1024*1024)) {
2319 reply_doserror(req, ERRDOS, ERRnomem);
2320 return;
2323 if (data_count < 8+sid_len) {
2324 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2325 reply_doserror(req, ERRDOS, ERRunknownlevel);
2326 return;
2329 data_len = 4+40+sid_len;
2331 if (max_data_count < data_len) {
2332 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2333 max_data_count, data_len));
2334 param_len = 4;
2335 SIVAL(params,0,data_len);
2336 data_len = 0;
2337 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2338 break;
2341 sid_parse(pdata+8,sid_len,&sid);
2343 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2344 ZERO_STRUCT(qt);
2346 * we have to return zero's in all fields
2347 * instead of returning an error here
2348 * --metze
2352 /* Realloc the size of parameters and data we will return */
2353 param_len = 4;
2354 params = nttrans_realloc(ppparams, param_len);
2355 if(params == NULL) {
2356 reply_doserror(req, ERRDOS, ERRnomem);
2357 return;
2360 pdata = nttrans_realloc(ppdata, data_len);
2361 if(pdata == NULL) {
2362 reply_doserror(req, ERRDOS, ERRnomem);
2363 return;
2366 entry = pdata;
2368 /* set params Size of returned Quota Data 4 bytes*/
2369 SIVAL(params,0,data_len);
2371 /* nextoffset entry 4 bytes */
2372 SIVAL(entry,0,0);
2374 /* then the len of the SID 4 bytes */
2375 SIVAL(entry,4,sid_len);
2377 /* unknown data 8 bytes uint64_t */
2378 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2380 /* the used disk space 8 bytes uint64_t */
2381 SBIG_UINT(entry,16,qt.usedspace);
2383 /* the soft quotas 8 bytes uint64_t */
2384 SBIG_UINT(entry,24,qt.softlim);
2386 /* the hard quotas 8 bytes uint64_t */
2387 SBIG_UINT(entry,32,qt.hardlim);
2389 /* and now the SID */
2390 sid_linearize(entry+40, sid_len, &sid);
2392 break;
2394 default:
2395 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2396 reply_doserror(req, ERRSRV, ERRerror);
2397 return;
2398 break;
2401 send_nt_replies(conn, req, nt_status, params, param_len,
2402 pdata, data_len);
2405 /****************************************************************************
2406 Reply to set user quota
2407 ****************************************************************************/
2409 static void call_nt_transact_set_user_quota(connection_struct *conn,
2410 struct smb_request *req,
2411 uint16 **ppsetup,
2412 uint32 setup_count,
2413 char **ppparams,
2414 uint32 parameter_count,
2415 char **ppdata,
2416 uint32 data_count,
2417 uint32 max_data_count)
2419 char *params = *ppparams;
2420 char *pdata = *ppdata;
2421 int data_len=0,param_len=0;
2422 SMB_NTQUOTA_STRUCT qt;
2423 size_t sid_len;
2424 DOM_SID sid;
2425 files_struct *fsp = NULL;
2427 ZERO_STRUCT(qt);
2429 /* access check */
2430 if (conn->server_info->utok.uid != 0) {
2431 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2432 "[%s]\n", lp_servicename(SNUM(conn)),
2433 conn->server_info->unix_name));
2434 reply_doserror(req, ERRDOS, ERRnoaccess);
2435 return;
2439 * Ensure minimum number of parameters sent.
2442 if (parameter_count < 2) {
2443 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2444 reply_doserror(req, ERRDOS, ERRinvalidparam);
2445 return;
2448 /* maybe we can check the quota_fnum */
2449 fsp = file_fsp(req, SVAL(params,0));
2450 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2451 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2452 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2453 return;
2456 if (data_count < 40) {
2457 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2458 reply_doserror(req, ERRDOS, ERRunknownlevel);
2459 return;
2462 /* offset to next quota record.
2463 * 4 bytes IVAL(pdata,0)
2464 * unused here...
2467 /* sid len */
2468 sid_len = IVAL(pdata,4);
2470 if (data_count < 40+sid_len) {
2471 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2472 reply_doserror(req, ERRDOS, ERRunknownlevel);
2473 return;
2476 /* unknown 8 bytes in pdata
2477 * maybe its the change time in NTTIME
2480 /* the used space 8 bytes (uint64_t)*/
2481 qt.usedspace = (uint64_t)IVAL(pdata,16);
2482 #ifdef LARGE_SMB_OFF_T
2483 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2484 #else /* LARGE_SMB_OFF_T */
2485 if ((IVAL(pdata,20) != 0)&&
2486 ((qt.usedspace != 0xFFFFFFFF)||
2487 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2488 /* more than 32 bits? */
2489 reply_doserror(req, ERRDOS, ERRunknownlevel);
2490 return;
2492 #endif /* LARGE_SMB_OFF_T */
2494 /* the soft quotas 8 bytes (uint64_t)*/
2495 qt.softlim = (uint64_t)IVAL(pdata,24);
2496 #ifdef LARGE_SMB_OFF_T
2497 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2498 #else /* LARGE_SMB_OFF_T */
2499 if ((IVAL(pdata,28) != 0)&&
2500 ((qt.softlim != 0xFFFFFFFF)||
2501 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2502 /* more than 32 bits? */
2503 reply_doserror(req, ERRDOS, ERRunknownlevel);
2504 return;
2506 #endif /* LARGE_SMB_OFF_T */
2508 /* the hard quotas 8 bytes (uint64_t)*/
2509 qt.hardlim = (uint64_t)IVAL(pdata,32);
2510 #ifdef LARGE_SMB_OFF_T
2511 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2512 #else /* LARGE_SMB_OFF_T */
2513 if ((IVAL(pdata,36) != 0)&&
2514 ((qt.hardlim != 0xFFFFFFFF)||
2515 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2516 /* more than 32 bits? */
2517 reply_doserror(req, ERRDOS, ERRunknownlevel);
2518 return;
2520 #endif /* LARGE_SMB_OFF_T */
2522 sid_parse(pdata+40,sid_len,&sid);
2523 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2525 /* 44 unknown bytes left... */
2527 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2528 reply_doserror(req, ERRSRV, ERRerror);
2529 return;
2532 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2533 pdata, data_len);
2535 #endif /* HAVE_SYS_QUOTAS */
2537 static void handle_nttrans(connection_struct *conn,
2538 struct trans_state *state,
2539 struct smb_request *req)
2541 if (Protocol >= PROTOCOL_NT1) {
2542 req->flags2 |= 0x40; /* IS_LONG_NAME */
2543 SSVAL(req->inbuf,smb_flg2,req->flags2);
2547 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2549 /* Now we must call the relevant NT_TRANS function */
2550 switch(state->call) {
2551 case NT_TRANSACT_CREATE:
2553 START_PROFILE(NT_transact_create);
2554 call_nt_transact_create(
2555 conn, req,
2556 &state->setup, state->setup_count,
2557 &state->param, state->total_param,
2558 &state->data, state->total_data,
2559 state->max_data_return);
2560 END_PROFILE(NT_transact_create);
2561 break;
2564 case NT_TRANSACT_IOCTL:
2566 START_PROFILE(NT_transact_ioctl);
2567 call_nt_transact_ioctl(
2568 conn, req,
2569 &state->setup, state->setup_count,
2570 &state->param, state->total_param,
2571 &state->data, state->total_data,
2572 state->max_data_return);
2573 END_PROFILE(NT_transact_ioctl);
2574 break;
2577 case NT_TRANSACT_SET_SECURITY_DESC:
2579 START_PROFILE(NT_transact_set_security_desc);
2580 call_nt_transact_set_security_desc(
2581 conn, req,
2582 &state->setup, state->setup_count,
2583 &state->param, state->total_param,
2584 &state->data, state->total_data,
2585 state->max_data_return);
2586 END_PROFILE(NT_transact_set_security_desc);
2587 break;
2590 case NT_TRANSACT_NOTIFY_CHANGE:
2592 START_PROFILE(NT_transact_notify_change);
2593 call_nt_transact_notify_change(
2594 conn, req,
2595 &state->setup, state->setup_count,
2596 &state->param, state->total_param,
2597 &state->data, state->total_data,
2598 state->max_data_return,
2599 state->max_param_return);
2600 END_PROFILE(NT_transact_notify_change);
2601 break;
2604 case NT_TRANSACT_RENAME:
2606 START_PROFILE(NT_transact_rename);
2607 call_nt_transact_rename(
2608 conn, req,
2609 &state->setup, state->setup_count,
2610 &state->param, state->total_param,
2611 &state->data, state->total_data,
2612 state->max_data_return);
2613 END_PROFILE(NT_transact_rename);
2614 break;
2617 case NT_TRANSACT_QUERY_SECURITY_DESC:
2619 START_PROFILE(NT_transact_query_security_desc);
2620 call_nt_transact_query_security_desc(
2621 conn, req,
2622 &state->setup, state->setup_count,
2623 &state->param, state->total_param,
2624 &state->data, state->total_data,
2625 state->max_data_return);
2626 END_PROFILE(NT_transact_query_security_desc);
2627 break;
2630 #ifdef HAVE_SYS_QUOTAS
2631 case NT_TRANSACT_GET_USER_QUOTA:
2633 START_PROFILE(NT_transact_get_user_quota);
2634 call_nt_transact_get_user_quota(
2635 conn, req,
2636 &state->setup, state->setup_count,
2637 &state->param, state->total_param,
2638 &state->data, state->total_data,
2639 state->max_data_return);
2640 END_PROFILE(NT_transact_get_user_quota);
2641 break;
2644 case NT_TRANSACT_SET_USER_QUOTA:
2646 START_PROFILE(NT_transact_set_user_quota);
2647 call_nt_transact_set_user_quota(
2648 conn, req,
2649 &state->setup, state->setup_count,
2650 &state->param, state->total_param,
2651 &state->data, state->total_data,
2652 state->max_data_return);
2653 END_PROFILE(NT_transact_set_user_quota);
2654 break;
2656 #endif /* HAVE_SYS_QUOTAS */
2658 default:
2659 /* Error in request */
2660 DEBUG(0,("handle_nttrans: Unknown request %d in "
2661 "nttrans call\n", state->call));
2662 reply_doserror(req, ERRSRV, ERRerror);
2663 return;
2665 return;
2668 /****************************************************************************
2669 Reply to a SMBNTtrans.
2670 ****************************************************************************/
2672 void reply_nttrans(struct smb_request *req)
2674 connection_struct *conn = req->conn;
2675 uint32_t pscnt;
2676 uint32_t psoff;
2677 uint32_t dscnt;
2678 uint32_t dsoff;
2679 uint16 function_code;
2680 NTSTATUS result;
2681 struct trans_state *state;
2683 START_PROFILE(SMBnttrans);
2685 if (req->wct < 19) {
2686 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2687 END_PROFILE(SMBnttrans);
2688 return;
2691 pscnt = IVAL(req->vwv+9, 1);
2692 psoff = IVAL(req->vwv+11, 1);
2693 dscnt = IVAL(req->vwv+13, 1);
2694 dsoff = IVAL(req->vwv+15, 1);
2695 function_code = SVAL(req->vwv+18, 0);
2697 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2698 reply_doserror(req, ERRSRV, ERRaccess);
2699 END_PROFILE(SMBnttrans);
2700 return;
2703 result = allow_new_trans(conn->pending_trans, req->mid);
2704 if (!NT_STATUS_IS_OK(result)) {
2705 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2706 reply_nterror(req, result);
2707 END_PROFILE(SMBnttrans);
2708 return;
2711 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2712 reply_doserror(req, ERRSRV, ERRaccess);
2713 END_PROFILE(SMBnttrans);
2714 return;
2717 state->cmd = SMBnttrans;
2719 state->mid = req->mid;
2720 state->vuid = req->vuid;
2721 state->total_data = IVAL(req->vwv+3, 1);
2722 state->data = NULL;
2723 state->total_param = IVAL(req->vwv+1, 1);
2724 state->param = NULL;
2725 state->max_data_return = IVAL(req->vwv+7, 1);
2726 state->max_param_return = IVAL(req->vwv+5, 1);
2728 /* setup count is in *words* */
2729 state->setup_count = 2*CVAL(req->vwv+17, 1);
2730 state->setup = NULL;
2731 state->call = function_code;
2733 DEBUG(10, ("num_setup=%u, "
2734 "param_total=%u, this_param=%u, max_param=%u, "
2735 "data_total=%u, this_data=%u, max_data=%u, "
2736 "param_offset=%u, data_offset=%u\n",
2737 (unsigned)state->setup_count,
2738 (unsigned)state->total_param, (unsigned)pscnt,
2739 (unsigned)state->max_param_return,
2740 (unsigned)state->total_data, (unsigned)dscnt,
2741 (unsigned)state->max_data_return,
2742 (unsigned)psoff, (unsigned)dsoff));
2745 * All nttrans messages we handle have smb_wct == 19 +
2746 * state->setup_count. Ensure this is so as a sanity check.
2749 if(req->wct != 19 + (state->setup_count/2)) {
2750 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2751 req->wct, 19 + (state->setup_count/2)));
2752 goto bad_param;
2755 /* Don't allow more than 128mb for each value. */
2756 if ((state->total_data > (1024*1024*128)) ||
2757 (state->total_param > (1024*1024*128))) {
2758 reply_doserror(req, ERRDOS, ERRnomem);
2759 END_PROFILE(SMBnttrans);
2760 return;
2763 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2764 goto bad_param;
2766 if (state->total_data) {
2768 if (trans_oob(state->total_data, 0, dscnt)
2769 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2770 goto bad_param;
2773 /* Can't use talloc here, the core routines do realloc on the
2774 * params and data. */
2775 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2776 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2777 "bytes !\n", (unsigned int)state->total_data));
2778 TALLOC_FREE(state);
2779 reply_doserror(req, ERRDOS, ERRnomem);
2780 END_PROFILE(SMBnttrans);
2781 return;
2784 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2787 if (state->total_param) {
2789 if (trans_oob(state->total_param, 0, pscnt)
2790 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2791 goto bad_param;
2794 /* Can't use talloc here, the core routines do realloc on the
2795 * params and data. */
2796 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2797 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2798 "bytes !\n", (unsigned int)state->total_param));
2799 SAFE_FREE(state->data);
2800 TALLOC_FREE(state);
2801 reply_doserror(req, ERRDOS, ERRnomem);
2802 END_PROFILE(SMBnttrans);
2803 return;
2806 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2809 state->received_data = dscnt;
2810 state->received_param = pscnt;
2812 if(state->setup_count > 0) {
2813 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2814 state->setup_count));
2817 * No overflow possible here, state->setup_count is an
2818 * unsigned int, being filled by a single byte from
2819 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2820 * below is not necessary, it's here to clarify things. The
2821 * validity of req->vwv and req->wct has been checked in
2822 * init_smb_request already.
2824 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2825 goto bad_param;
2828 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2829 if (state->setup == NULL) {
2830 DEBUG(0,("reply_nttrans : Out of memory\n"));
2831 SAFE_FREE(state->data);
2832 SAFE_FREE(state->param);
2833 TALLOC_FREE(state);
2834 reply_doserror(req, ERRDOS, ERRnomem);
2835 END_PROFILE(SMBnttrans);
2836 return;
2839 memcpy(state->setup, req->vwv+19, state->setup_count);
2840 dump_data(10, (uint8 *)state->setup, state->setup_count);
2843 if ((state->received_data == state->total_data) &&
2844 (state->received_param == state->total_param)) {
2845 handle_nttrans(conn, state, req);
2846 SAFE_FREE(state->param);
2847 SAFE_FREE(state->data);
2848 TALLOC_FREE(state);
2849 END_PROFILE(SMBnttrans);
2850 return;
2853 DLIST_ADD(conn->pending_trans, state);
2855 /* We need to send an interim response then receive the rest
2856 of the parameter/data bytes */
2857 reply_outbuf(req, 0, 0);
2858 show_msg((char *)req->outbuf);
2859 END_PROFILE(SMBnttrans);
2860 return;
2862 bad_param:
2864 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2865 SAFE_FREE(state->data);
2866 SAFE_FREE(state->param);
2867 TALLOC_FREE(state);
2868 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2869 END_PROFILE(SMBnttrans);
2870 return;
2873 /****************************************************************************
2874 Reply to a SMBnttranss
2875 ****************************************************************************/
2877 void reply_nttranss(struct smb_request *req)
2879 connection_struct *conn = req->conn;
2880 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2881 struct trans_state *state;
2883 START_PROFILE(SMBnttranss);
2885 show_msg((char *)req->inbuf);
2887 if (req->wct < 18) {
2888 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2889 END_PROFILE(SMBnttranss);
2890 return;
2893 for (state = conn->pending_trans; state != NULL;
2894 state = state->next) {
2895 if (state->mid == req->mid) {
2896 break;
2900 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2901 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2902 END_PROFILE(SMBnttranss);
2903 return;
2906 /* Revise state->total_param and state->total_data in case they have
2907 changed downwards */
2908 if (IVAL(req->vwv+1, 1) < state->total_param) {
2909 state->total_param = IVAL(req->vwv+1, 1);
2911 if (IVAL(req->vwv+3, 1) < state->total_data) {
2912 state->total_data = IVAL(req->vwv+3, 1);
2915 pcnt = IVAL(req->vwv+5, 1);
2916 poff = IVAL(req->vwv+7, 1);
2917 pdisp = IVAL(req->vwv+9, 1);
2919 dcnt = IVAL(req->vwv+11, 1);
2920 doff = IVAL(req->vwv+13, 1);
2921 ddisp = IVAL(req->vwv+15, 1);
2923 state->received_param += pcnt;
2924 state->received_data += dcnt;
2926 if ((state->received_data > state->total_data) ||
2927 (state->received_param > state->total_param))
2928 goto bad_param;
2930 if (pcnt) {
2931 if (trans_oob(state->total_param, pdisp, pcnt)
2932 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2933 goto bad_param;
2935 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2938 if (dcnt) {
2939 if (trans_oob(state->total_data, ddisp, dcnt)
2940 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2941 goto bad_param;
2943 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2946 if ((state->received_param < state->total_param) ||
2947 (state->received_data < state->total_data)) {
2948 END_PROFILE(SMBnttranss);
2949 return;
2952 handle_nttrans(conn, state, req);
2954 DLIST_REMOVE(conn->pending_trans, state);
2955 SAFE_FREE(state->data);
2956 SAFE_FREE(state->param);
2957 TALLOC_FREE(state);
2958 END_PROFILE(SMBnttranss);
2959 return;
2961 bad_param:
2963 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2964 DLIST_REMOVE(conn->pending_trans, state);
2965 SAFE_FREE(state->data);
2966 SAFE_FREE(state->param);
2967 TALLOC_FREE(state);
2968 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2969 END_PROFILE(SMBnttranss);
2970 return;