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/>.
22 #include "system/filesys.h"
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "fake_file.h"
26 #include "../libcli/security/security.h"
27 #include "../librpc/gen_ndr/ndr_security.h"
28 #include "passdb/lookup_sid.h"
30 #include "smbprofile.h"
31 #include "libsmb/libsmb.h"
32 #include "lib/util_ea.h"
33 #include "librpc/gen_ndr/ndr_quota.h"
34 #include "librpc/gen_ndr/ndr_security.h"
36 extern const struct generic_mapping file_generic_mapping
;
38 static char *nttrans_realloc(char **ptr
, size_t size
)
41 smb_panic("nttrans_realloc() called with NULL ptr");
44 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
48 memset(*ptr
,'\0',size
);
52 /****************************************************************************
53 Send the required number of replies back.
54 We assume all fields other than the data fields are
55 set correctly for the type of call.
56 HACK ! Always assumes smb_setup field is zero.
57 ****************************************************************************/
59 static void send_nt_replies(connection_struct
*conn
,
60 struct smb_request
*req
, NTSTATUS nt_error
,
61 char *params
, int paramsize
,
62 char *pdata
, int datasize
)
64 int data_to_send
= datasize
;
65 int params_to_send
= paramsize
;
69 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
70 int alignment_offset
= 1;
71 int data_alignment_offset
= 0;
72 struct smbXsrv_connection
*xconn
= req
->xconn
;
73 int max_send
= xconn
->smb1
.sessions
.max_send
;
76 * If there genuinely are no parameters or data to send just send
80 if(params_to_send
== 0 && data_to_send
== 0) {
81 reply_outbuf(req
, 18, 0);
82 if (NT_STATUS_V(nt_error
)) {
83 error_packet_set((char *)req
->outbuf
,
87 show_msg((char *)req
->outbuf
);
88 if (!srv_send_smb(xconn
,
91 IS_CONN_ENCRYPTED(conn
),
93 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
95 TALLOC_FREE(req
->outbuf
);
100 * When sending params and data ensure that both are nicely aligned.
101 * Only do this alignment when there is also data to send - else
102 * can cause NT redirector problems.
105 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
106 data_alignment_offset
= 4 - (params_to_send
% 4);
110 * Space is bufsize minus Netbios over TCP header minus SMB header.
111 * The alignment_offset is to align the param bytes on a four byte
112 * boundary (2 bytes for data len, one byte pad).
113 * NT needs this to work correctly.
116 useable_space
= max_send
- (smb_size
119 + data_alignment_offset
);
121 if (useable_space
< 0) {
122 char *msg
= talloc_asprintf(
124 "send_nt_replies failed sanity useable_space = %d!!!",
126 DEBUG(0, ("%s\n", msg
));
127 exit_server_cleanly(msg
);
130 while (params_to_send
|| data_to_send
) {
133 * Calculate whether we will totally or partially fill this packet.
136 total_sent_thistime
= params_to_send
+ data_to_send
;
139 * We can never send more than useable_space.
142 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
144 reply_outbuf(req
, 18,
145 total_sent_thistime
+ alignment_offset
146 + data_alignment_offset
);
149 * Set total params and data to be sent.
152 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
153 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
156 * Calculate how many parameters and data we can fit into
157 * this packet. Parameters get precedence.
160 params_sent_thistime
= MIN(params_to_send
,useable_space
);
161 data_sent_thistime
= useable_space
- params_sent_thistime
;
162 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
164 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
165 params_sent_thistime
);
167 if(params_sent_thistime
== 0) {
168 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
169 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
172 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
173 * parameter bytes, however the first 4 bytes of outbuf are
174 * the Netbios over TCP header. Thus use smb_base() to subtract
175 * them from the calculation.
178 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
179 ((smb_buf(req
->outbuf
)+alignment_offset
)
180 - smb_base(req
->outbuf
)));
182 * Absolute displacement of param bytes sent in this packet.
185 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
190 * Deal with the data portion.
193 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
195 if(data_sent_thistime
== 0) {
196 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
197 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
200 * The offset of the data bytes is the offset of the
201 * parameter bytes plus the number of parameters being sent this time.
204 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
205 ((smb_buf(req
->outbuf
)+alignment_offset
) -
206 smb_base(req
->outbuf
))
207 + params_sent_thistime
+ data_alignment_offset
);
208 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
212 * Copy the param bytes into the packet.
215 if(params_sent_thistime
) {
216 if (alignment_offset
!= 0) {
217 memset(smb_buf(req
->outbuf
), 0,
220 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
221 params_sent_thistime
);
225 * Copy in the data bytes
228 if(data_sent_thistime
) {
229 if (data_alignment_offset
!= 0) {
230 memset((smb_buf(req
->outbuf
)+alignment_offset
+
231 params_sent_thistime
), 0,
232 data_alignment_offset
);
234 memcpy(smb_buf(req
->outbuf
)+alignment_offset
235 +params_sent_thistime
+data_alignment_offset
,
236 pd
,data_sent_thistime
);
239 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
240 params_sent_thistime
, data_sent_thistime
, useable_space
));
241 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
242 params_to_send
, data_to_send
, paramsize
, datasize
));
244 if (NT_STATUS_V(nt_error
)) {
245 error_packet_set((char *)req
->outbuf
,
250 /* Send the packet */
251 show_msg((char *)req
->outbuf
);
252 if (!srv_send_smb(xconn
,
255 IS_CONN_ENCRYPTED(conn
),
257 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
260 TALLOC_FREE(req
->outbuf
);
262 pp
+= params_sent_thistime
;
263 pd
+= data_sent_thistime
;
265 params_to_send
-= params_sent_thistime
;
266 data_to_send
-= data_sent_thistime
;
272 if(params_to_send
< 0 || data_to_send
< 0) {
273 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
274 params_to_send
, data_to_send
));
275 exit_server_cleanly("send_nt_replies: internal error");
280 /****************************************************************************
281 Reply to an NT create and X call on a pipe
282 ****************************************************************************/
284 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
285 struct smb_request
*req
, uint16_t *ppnum
)
290 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
292 /* Strip \\ off the name if present. */
293 while (fname
[0] == '\\') {
297 status
= open_np_file(req
, fname
, &fsp
);
298 if (!NT_STATUS_IS_OK(status
)) {
299 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
300 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
304 reply_nterror(req
, status
);
312 /****************************************************************************
313 Reply to an NT create and X call for pipes.
314 ****************************************************************************/
316 static void do_ntcreate_pipe_open(connection_struct
*conn
,
317 struct smb_request
*req
)
320 uint16_t pnum
= FNUM_FIELD_INVALID
;
322 uint32_t flags
= IVAL(req
->vwv
+3, 1);
323 TALLOC_CTX
*ctx
= talloc_tos();
325 srvstr_pull_req_talloc(ctx
, req
, &fname
, req
->buf
, STR_TERMINATE
);
328 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
332 nt_open_pipe(fname
, conn
, req
, &pnum
);
340 * Deal with pipe return.
343 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
344 /* This is very strange. We
345 * return 50 words, but only set
346 * the wcnt to 42 ? It's definitely
347 * what happens on the wire....
349 reply_outbuf(req
, 50, 0);
350 SCVAL(req
->outbuf
,smb_wct
,42);
352 reply_outbuf(req
, 34, 0);
355 SSVAL(req
->outbuf
, smb_vwv0
, 0xff); /* andx chain ends */
356 SSVAL(req
->outbuf
, smb_vwv1
, 0); /* no andx offset */
358 p
= (char *)req
->outbuf
+ smb_vwv2
;
362 SIVAL(p
,0,FILE_WAS_OPENED
);
365 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
368 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
370 SSVAL(p
,2, 0x5FF); /* ? */
373 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
375 SIVAL(p
,0,FILE_GENERIC_ALL
);
377 * For pipes W2K3 seems to return
379 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
381 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
384 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
387 struct case_semantics_state
{
388 connection_struct
*conn
;
391 bool short_case_preserve
;
394 /****************************************************************************
395 Restore case semantics.
396 ****************************************************************************/
398 static int restore_case_semantics(struct case_semantics_state
*state
)
400 state
->conn
->case_sensitive
= state
->case_sensitive
;
401 state
->conn
->case_preserve
= state
->case_preserve
;
402 state
->conn
->short_case_preserve
= state
->short_case_preserve
;
406 /****************************************************************************
408 ****************************************************************************/
410 static struct case_semantics_state
*set_posix_case_semantics(TALLOC_CTX
*mem_ctx
,
411 connection_struct
*conn
)
413 struct case_semantics_state
*result
;
415 if (!(result
= talloc(mem_ctx
, struct case_semantics_state
))) {
420 result
->case_sensitive
= conn
->case_sensitive
;
421 result
->case_preserve
= conn
->case_preserve
;
422 result
->short_case_preserve
= conn
->short_case_preserve
;
425 conn
->case_sensitive
= True
;
426 conn
->case_preserve
= True
;
427 conn
->short_case_preserve
= True
;
429 talloc_set_destructor(result
, restore_case_semantics
);
434 /****************************************************************************
435 Reply to an NT create and X call.
436 ****************************************************************************/
438 void reply_ntcreate_and_X(struct smb_request
*req
)
440 connection_struct
*conn
= req
->conn
;
441 struct smb_filename
*smb_fname
= NULL
;
444 uint32_t access_mask
;
445 uint32_t file_attributes
;
446 uint32_t share_access
;
447 uint32_t create_disposition
;
448 uint32_t create_options
;
449 uint16_t root_dir_fid
;
450 uint64_t allocation_size
;
451 /* Breakout the oplock request bits so we can set the
452 reply bits separately. */
456 files_struct
*fsp
= NULL
;
458 struct timespec create_timespec
;
459 struct timespec c_timespec
;
460 struct timespec a_timespec
;
461 struct timespec m_timespec
;
464 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
465 struct case_semantics_state
*case_state
= NULL
;
467 TALLOC_CTX
*ctx
= talloc_tos();
469 START_PROFILE(SMBntcreateX
);
472 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
476 flags
= IVAL(req
->vwv
+3, 1);
477 access_mask
= IVAL(req
->vwv
+7, 1);
478 file_attributes
= IVAL(req
->vwv
+13, 1);
479 share_access
= IVAL(req
->vwv
+15, 1);
480 create_disposition
= IVAL(req
->vwv
+17, 1);
481 create_options
= IVAL(req
->vwv
+19, 1);
482 root_dir_fid
= (uint16_t)IVAL(req
->vwv
+5, 1);
484 allocation_size
= BVAL(req
->vwv
+9, 1);
486 srvstr_get_path_req(ctx
, req
, &fname
, (const char *)req
->buf
,
487 STR_TERMINATE
, &status
);
489 if (!NT_STATUS_IS_OK(status
)) {
490 reply_nterror(req
, status
);
494 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
495 "file_attributes = 0x%x, share_access = 0x%x, "
496 "create_disposition = 0x%x create_options = 0x%x "
497 "root_dir_fid = 0x%x, fname = %s\n",
499 (unsigned int)access_mask
,
500 (unsigned int)file_attributes
,
501 (unsigned int)share_access
,
502 (unsigned int)create_disposition
,
503 (unsigned int)create_options
,
504 (unsigned int)root_dir_fid
,
508 * we need to remove ignored bits when they come directly from the client
509 * because we reuse some of them for internal stuff
511 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
514 * If it's an IPC, use the pipe handler.
518 if (lp_nt_pipe_support()) {
519 do_ntcreate_pipe_open(conn
, req
);
522 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
526 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
527 if (oplock_request
) {
528 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
532 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
533 case_state
= set_posix_case_semantics(ctx
, conn
);
535 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
540 ucf_flags
= filename_create_ucf_flags(req
, create_disposition
);
541 status
= filename_convert(ctx
,
549 TALLOC_FREE(case_state
);
551 if (!NT_STATUS_IS_OK(status
)) {
552 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
554 NT_STATUS_PATH_NOT_COVERED
,
558 reply_nterror(req
, status
);
563 * Bug #6898 - clients using Windows opens should
564 * never be able to set this attribute into the
567 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
569 status
= SMB_VFS_CREATE_FILE(
572 root_dir_fid
, /* root_dir_fid */
573 smb_fname
, /* fname */
574 access_mask
, /* access_mask */
575 share_access
, /* share_access */
576 create_disposition
, /* create_disposition*/
577 create_options
, /* create_options */
578 file_attributes
, /* file_attributes */
579 oplock_request
, /* oplock_request */
581 allocation_size
, /* allocation_size */
582 0, /* private_flags */
587 NULL
, NULL
); /* create context */
589 if (!NT_STATUS_IS_OK(status
)) {
590 if (open_was_deferred(req
->xconn
, req
->mid
)) {
591 /* We have re-scheduled this call, no error. */
594 reply_openerror(req
, status
);
598 /* Ensure we're pointing at the correct stat struct. */
599 TALLOC_FREE(smb_fname
);
600 smb_fname
= fsp
->fsp_name
;
603 * If the caller set the extended oplock request bit
604 * and we granted one (by whatever means) - set the
605 * correct bit for extended oplock reply.
608 if (oplock_request
&&
609 (lp_fake_oplocks(SNUM(conn
))
610 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
613 * Exclusive oplock granted
616 if (flags
& REQUEST_BATCH_OPLOCK
) {
617 oplock_granted
= BATCH_OPLOCK_RETURN
;
619 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
621 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
622 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
624 oplock_granted
= NO_OPLOCK_RETURN
;
627 file_len
= smb_fname
->st
.st_ex_size
;
629 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
630 /* This is very strange. We
631 * return 50 words, but only set
632 * the wcnt to 42 ? It's definitely
633 * what happens on the wire....
635 reply_outbuf(req
, 50, 0);
636 SCVAL(req
->outbuf
,smb_wct
,42);
638 reply_outbuf(req
, 34, 0);
641 SSVAL(req
->outbuf
, smb_vwv0
, 0xff); /* andx chain ends */
642 SSVAL(req
->outbuf
, smb_vwv1
, 0); /* no andx offset */
644 p
= (char *)req
->outbuf
+ smb_vwv2
;
646 SCVAL(p
, 0, oplock_granted
);
649 SSVAL(p
,0,fsp
->fnum
);
651 if ((create_disposition
== FILE_SUPERSEDE
)
652 && (info
== FILE_WAS_OVERWRITTEN
)) {
653 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
659 fattr
= dos_mode(conn
, smb_fname
);
661 fattr
= FILE_ATTRIBUTE_NORMAL
;
665 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
666 a_timespec
= smb_fname
->st
.st_ex_atime
;
667 m_timespec
= smb_fname
->st
.st_ex_mtime
;
668 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
670 if (lp_dos_filetime_resolution(SNUM(conn
))) {
671 dos_filetime_timespec(&create_timespec
);
672 dos_filetime_timespec(&a_timespec
);
673 dos_filetime_timespec(&m_timespec
);
674 dos_filetime_timespec(&c_timespec
);
677 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
679 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
681 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
683 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
685 SIVAL(p
,0,fattr
); /* File Attributes. */
687 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
689 SOFF_T(p
,0,file_len
);
691 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
692 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
693 unsigned int num_streams
= 0;
694 struct stream_struct
*streams
= NULL
;
696 if (lp_ea_support(SNUM(conn
))) {
697 size_t num_names
= 0;
698 /* Do we have any EA's ? */
699 status
= get_ea_names_from_file(
700 ctx
, conn
, fsp
, smb_fname
, NULL
, &num_names
);
701 if (NT_STATUS_IS_OK(status
) && num_names
) {
702 file_status
&= ~NO_EAS
;
706 status
= vfs_streaminfo(conn
, NULL
, smb_fname
, ctx
,
707 &num_streams
, &streams
);
708 /* There is always one stream, ::$DATA. */
709 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
710 file_status
&= ~NO_SUBSTREAMS
;
712 TALLOC_FREE(streams
);
713 SSVAL(p
,2,file_status
);
716 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
718 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
721 if (fsp
->is_directory
||
723 can_write_to_file(conn
, smb_fname
)) {
724 perms
= FILE_GENERIC_ALL
;
726 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
731 DEBUG(5,("reply_ntcreate_and_X: %s, open name = %s\n",
732 fsp_fnum_dbg(fsp
), smb_fname_str_dbg(smb_fname
)));
735 END_PROFILE(SMBntcreateX
);
739 /****************************************************************************
740 Reply to a NT_TRANSACT_CREATE call to open a pipe.
741 ****************************************************************************/
743 static void do_nt_transact_create_pipe(connection_struct
*conn
,
744 struct smb_request
*req
,
745 uint16_t **ppsetup
, uint32_t setup_count
,
746 char **ppparams
, uint32_t parameter_count
,
747 char **ppdata
, uint32_t data_count
)
750 char *params
= *ppparams
;
751 uint16_t pnum
= FNUM_FIELD_INVALID
;
756 TALLOC_CTX
*ctx
= talloc_tos();
759 * Ensure minimum number of parameters sent.
762 if(parameter_count
< 54) {
763 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
764 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
768 flags
= IVAL(params
,0);
770 if (req
->posix_pathnames
) {
771 srvstr_get_path_posix(ctx
,
789 if (!NT_STATUS_IS_OK(status
)) {
790 reply_nterror(req
, status
);
794 nt_open_pipe(fname
, conn
, req
, &pnum
);
801 /* Realloc the size of parameters and data we will return */
802 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
803 /* Extended response is 32 more byyes. */
808 params
= nttrans_realloc(ppparams
, param_len
);
810 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
815 SCVAL(p
,0,NO_OPLOCK_RETURN
);
820 SIVAL(p
,0,FILE_WAS_OPENED
);
824 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
827 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
829 SSVAL(p
,2, 0x5FF); /* ? */
832 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
834 SIVAL(p
,0,FILE_GENERIC_ALL
);
836 * For pipes W2K3 seems to return
838 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
840 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
843 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
845 /* Send the required number of replies */
846 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
851 /*********************************************************************
852 Windows seems to do canonicalization of inheritance bits. Do the
854 *********************************************************************/
856 static void canonicalize_inheritance_bits(struct security_descriptor
*psd
)
858 bool set_auto_inherited
= false;
861 * We need to filter out the
862 * SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ
863 * bits. If both are set we store SEC_DESC_DACL_AUTO_INHERITED
864 * as this alters whether SEC_ACE_FLAG_INHERITED_ACE is set
865 * when an ACE is inherited. Otherwise we zero these bits out.
868 * http://social.msdn.microsoft.com/Forums/eu/os_fileservices/thread/11f77b68-731e-407d-b1b3-064750716531
873 if ((psd
->type
& (SEC_DESC_DACL_AUTO_INHERITED
|SEC_DESC_DACL_AUTO_INHERIT_REQ
))
874 == (SEC_DESC_DACL_AUTO_INHERITED
|SEC_DESC_DACL_AUTO_INHERIT_REQ
)) {
875 set_auto_inherited
= true;
878 psd
->type
&= ~(SEC_DESC_DACL_AUTO_INHERITED
|SEC_DESC_DACL_AUTO_INHERIT_REQ
);
879 if (set_auto_inherited
) {
880 psd
->type
|= SEC_DESC_DACL_AUTO_INHERITED
;
884 /****************************************************************************
885 Internal fn to set security descriptors.
886 ****************************************************************************/
888 NTSTATUS
set_sd(files_struct
*fsp
, struct security_descriptor
*psd
,
889 uint32_t security_info_sent
)
893 if (!CAN_WRITE(fsp
->conn
)) {
894 return NT_STATUS_ACCESS_DENIED
;
897 if (!lp_nt_acl_support(SNUM(fsp
->conn
))) {
901 if (S_ISLNK(fsp
->fsp_name
->st
.st_ex_mode
)) {
902 DEBUG(10, ("ACL set on symlink %s denied.\n",
904 return NT_STATUS_ACCESS_DENIED
;
907 if (psd
->owner_sid
== NULL
) {
908 security_info_sent
&= ~SECINFO_OWNER
;
910 if (psd
->group_sid
== NULL
) {
911 security_info_sent
&= ~SECINFO_GROUP
;
914 /* Ensure we have at least one thing set. */
915 if ((security_info_sent
& (SECINFO_OWNER
|SECINFO_GROUP
|SECINFO_DACL
|SECINFO_SACL
)) == 0) {
920 /* Ensure we have the rights to do this. */
921 if (security_info_sent
& SECINFO_OWNER
) {
922 if (!(fsp
->access_mask
& SEC_STD_WRITE_OWNER
)) {
923 return NT_STATUS_ACCESS_DENIED
;
927 if (security_info_sent
& SECINFO_GROUP
) {
928 if (!(fsp
->access_mask
& SEC_STD_WRITE_OWNER
)) {
929 return NT_STATUS_ACCESS_DENIED
;
933 if (security_info_sent
& SECINFO_DACL
) {
934 if (!(fsp
->access_mask
& SEC_STD_WRITE_DAC
)) {
935 return NT_STATUS_ACCESS_DENIED
;
937 /* Convert all the generic bits. */
939 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
943 if (security_info_sent
& SECINFO_SACL
) {
944 if (!(fsp
->access_mask
& SEC_FLAG_SYSTEM_SECURITY
)) {
945 return NT_STATUS_ACCESS_DENIED
;
947 /* Convert all the generic bits. */
949 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
953 canonicalize_inheritance_bits(psd
);
955 if (DEBUGLEVEL
>= 10) {
956 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp
)));
957 NDR_PRINT_DEBUG(security_descriptor
, psd
);
960 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
967 /****************************************************************************
968 Internal fn to set security descriptors from a data blob.
969 ****************************************************************************/
971 NTSTATUS
set_sd_blob(files_struct
*fsp
, uint8_t *data
, uint32_t sd_len
,
972 uint32_t security_info_sent
)
974 struct security_descriptor
*psd
= NULL
;
978 return NT_STATUS_INVALID_PARAMETER
;
981 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
983 if (!NT_STATUS_IS_OK(status
)) {
987 return set_sd(fsp
, psd
, security_info_sent
);
990 /****************************************************************************
991 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
992 ****************************************************************************/
994 static void call_nt_transact_create(connection_struct
*conn
,
995 struct smb_request
*req
,
996 uint16_t **ppsetup
, uint32_t setup_count
,
997 char **ppparams
, uint32_t parameter_count
,
998 char **ppdata
, uint32_t data_count
,
999 uint32_t max_data_count
)
1001 struct smb_filename
*smb_fname
= NULL
;
1003 char *params
= *ppparams
;
1004 char *data
= *ppdata
;
1005 /* Breakout the oplock request bits so we can set the reply bits separately. */
1009 files_struct
*fsp
= NULL
;
1012 uint32_t access_mask
;
1013 uint32_t file_attributes
;
1014 uint32_t share_access
;
1015 uint32_t create_disposition
;
1016 uint32_t create_options
;
1018 struct security_descriptor
*sd
= NULL
;
1020 uint16_t root_dir_fid
;
1021 struct timespec create_timespec
;
1022 struct timespec c_timespec
;
1023 struct timespec a_timespec
;
1024 struct timespec m_timespec
;
1025 struct ea_list
*ea_list
= NULL
;
1028 uint64_t allocation_size
;
1030 uint8_t oplock_granted
;
1031 struct case_semantics_state
*case_state
= NULL
;
1033 TALLOC_CTX
*ctx
= talloc_tos();
1035 DEBUG(5,("call_nt_transact_create\n"));
1038 * If it's an IPC, use the pipe handler.
1042 if (lp_nt_pipe_support()) {
1043 do_nt_transact_create_pipe(
1045 ppsetup
, setup_count
,
1046 ppparams
, parameter_count
,
1047 ppdata
, data_count
);
1050 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1055 * Ensure minimum number of parameters sent.
1058 if(parameter_count
< 54) {
1059 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1060 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1064 flags
= IVAL(params
,0);
1065 access_mask
= IVAL(params
,8);
1066 file_attributes
= IVAL(params
,20);
1067 share_access
= IVAL(params
,24);
1068 create_disposition
= IVAL(params
,28);
1069 create_options
= IVAL(params
,32);
1070 sd_len
= IVAL(params
,36);
1071 ea_len
= IVAL(params
,40);
1072 root_dir_fid
= (uint16_t)IVAL(params
,4);
1073 allocation_size
= BVAL(params
,12);
1076 * we need to remove ignored bits when they come directly from the client
1077 * because we reuse some of them for internal stuff
1079 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1081 if (req
->posix_pathnames
) {
1082 srvstr_get_path_posix(ctx
,
1091 srvstr_get_path(ctx
,
1100 if (!NT_STATUS_IS_OK(status
)) {
1101 reply_nterror(req
, status
);
1105 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1106 case_state
= set_posix_case_semantics(ctx
, conn
);
1108 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1113 ucf_flags
= filename_create_ucf_flags(req
, create_disposition
);
1114 status
= filename_convert(ctx
,
1122 TALLOC_FREE(case_state
);
1124 if (!NT_STATUS_IS_OK(status
)) {
1125 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1126 reply_botherror(req
,
1127 NT_STATUS_PATH_NOT_COVERED
,
1128 ERRSRV
, ERRbadpath
);
1131 reply_nterror(req
, status
);
1135 /* Ensure the data_len is correct for the sd and ea values given. */
1136 if ((ea_len
+ sd_len
> data_count
)
1137 || (ea_len
> data_count
) || (sd_len
> data_count
)
1138 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1139 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
1140 "%u, data_count = %u\n", (unsigned int)ea_len
,
1141 (unsigned int)sd_len
, (unsigned int)data_count
));
1142 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1147 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1150 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
1152 if (!NT_STATUS_IS_OK(status
)) {
1153 DEBUG(10, ("call_nt_transact_create: "
1154 "unmarshall_sec_desc failed: %s\n",
1155 nt_errstr(status
)));
1156 reply_nterror(req
, status
);
1162 if (!lp_ea_support(SNUM(conn
))) {
1163 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1164 "EA's not supported.\n",
1165 (unsigned int)ea_len
));
1166 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1171 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1172 "too small (should be more than 10)\n",
1173 (unsigned int)ea_len
));
1174 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1178 /* We have already checked that ea_len <= data_count here. */
1179 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
1181 if (ea_list
== NULL
) {
1182 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1186 if (!req
->posix_pathnames
&&
1187 ea_list_has_invalid_name(ea_list
)) {
1188 /* Realloc the size of parameters and data we will return */
1189 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1190 /* Extended response is 32 more byyes. */
1195 params
= nttrans_realloc(ppparams
, param_len
);
1196 if(params
== NULL
) {
1197 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1201 memset(params
, '\0', param_len
);
1202 send_nt_replies(conn
, req
, STATUS_INVALID_EA_NAME
,
1203 params
, param_len
, NULL
, 0);
1208 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1209 if (oplock_request
) {
1210 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1215 * Bug #6898 - clients using Windows opens should
1216 * never be able to set this attribute into the
1219 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1221 status
= SMB_VFS_CREATE_FILE(
1224 root_dir_fid
, /* root_dir_fid */
1225 smb_fname
, /* fname */
1226 access_mask
, /* access_mask */
1227 share_access
, /* share_access */
1228 create_disposition
, /* create_disposition*/
1229 create_options
, /* create_options */
1230 file_attributes
, /* file_attributes */
1231 oplock_request
, /* oplock_request */
1233 allocation_size
, /* allocation_size */
1234 0, /* private_flags */
1236 ea_list
, /* ea_list */
1239 NULL
, NULL
); /* create context */
1241 if(!NT_STATUS_IS_OK(status
)) {
1242 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1243 /* We have re-scheduled this call, no error. */
1246 reply_openerror(req
, status
);
1250 /* Ensure we're pointing at the correct stat struct. */
1251 TALLOC_FREE(smb_fname
);
1252 smb_fname
= fsp
->fsp_name
;
1255 * If the caller set the extended oplock request bit
1256 * and we granted one (by whatever means) - set the
1257 * correct bit for extended oplock reply.
1260 if (oplock_request
&&
1261 (lp_fake_oplocks(SNUM(conn
))
1262 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1265 * Exclusive oplock granted
1268 if (flags
& REQUEST_BATCH_OPLOCK
) {
1269 oplock_granted
= BATCH_OPLOCK_RETURN
;
1271 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1273 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1274 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1276 oplock_granted
= NO_OPLOCK_RETURN
;
1279 file_len
= smb_fname
->st
.st_ex_size
;
1281 /* Realloc the size of parameters and data we will return */
1282 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1283 /* Extended response is 32 more byyes. */
1288 params
= nttrans_realloc(ppparams
, param_len
);
1289 if(params
== NULL
) {
1290 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1295 SCVAL(p
, 0, oplock_granted
);
1298 SSVAL(p
,0,fsp
->fnum
);
1300 if ((create_disposition
== FILE_SUPERSEDE
)
1301 && (info
== FILE_WAS_OVERWRITTEN
)) {
1302 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1308 fattr
= dos_mode(conn
, smb_fname
);
1310 fattr
= FILE_ATTRIBUTE_NORMAL
;
1314 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1315 a_timespec
= smb_fname
->st
.st_ex_atime
;
1316 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1317 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1319 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1320 dos_filetime_timespec(&create_timespec
);
1321 dos_filetime_timespec(&a_timespec
);
1322 dos_filetime_timespec(&m_timespec
);
1323 dos_filetime_timespec(&c_timespec
);
1326 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
1328 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
1330 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
1332 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
1334 SIVAL(p
,0,fattr
); /* File Attributes. */
1336 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1338 SOFF_T(p
,0,file_len
);
1340 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1341 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
1342 unsigned int num_streams
= 0;
1343 struct stream_struct
*streams
= NULL
;
1345 if (lp_ea_support(SNUM(conn
))) {
1346 size_t num_names
= 0;
1347 /* Do we have any EA's ? */
1348 status
= get_ea_names_from_file(
1349 ctx
, conn
, fsp
, smb_fname
, NULL
, &num_names
);
1350 if (NT_STATUS_IS_OK(status
) && num_names
) {
1351 file_status
&= ~NO_EAS
;
1355 status
= vfs_streaminfo(conn
, NULL
, smb_fname
, ctx
,
1356 &num_streams
, &streams
);
1357 /* There is always one stream, ::$DATA. */
1358 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
1359 file_status
&= ~NO_SUBSTREAMS
;
1361 TALLOC_FREE(streams
);
1362 SSVAL(p
,2,file_status
);
1365 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1367 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1370 if (fsp
->is_directory
||
1372 can_write_to_file(conn
, smb_fname
)) {
1373 perms
= FILE_GENERIC_ALL
;
1375 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1380 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1381 smb_fname_str_dbg(smb_fname
)));
1383 /* Send the required number of replies */
1384 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1389 /****************************************************************************
1390 Reply to a NT CANCEL request.
1391 conn POINTER CAN BE NULL HERE !
1392 ****************************************************************************/
1394 void reply_ntcancel(struct smb_request
*req
)
1396 struct smbXsrv_connection
*xconn
= req
->xconn
;
1397 struct smbd_server_connection
*sconn
= req
->sconn
;
1400 * Go through and cancel any pending change notifies.
1403 START_PROFILE(SMBntcancel
);
1404 srv_cancel_sign_response(xconn
);
1405 remove_pending_change_notify_requests_by_mid(sconn
, req
->mid
);
1406 remove_pending_lock_requests_by_mid_smb1(sconn
, req
->mid
);
1408 DEBUG(3,("reply_ntcancel: cancel called on mid = %llu.\n",
1409 (unsigned long long)req
->mid
));
1411 END_PROFILE(SMBntcancel
);
1415 /****************************************************************************
1417 ****************************************************************************/
1419 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1420 connection_struct
*conn
,
1421 struct smb_request
*req
,
1422 struct smb_filename
*smb_fname_src
,
1423 struct smb_filename
*smb_fname_dst
,
1426 files_struct
*fsp1
,*fsp2
;
1430 NTSTATUS status
= NT_STATUS_OK
;
1433 if (!CAN_WRITE(conn
)) {
1434 status
= NT_STATUS_MEDIA_WRITE_PROTECTED
;
1438 /* Source must already exist. */
1439 if (!VALID_STAT(smb_fname_src
->st
)) {
1440 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1444 /* Ensure attributes match. */
1445 fattr
= dos_mode(conn
, smb_fname_src
);
1446 if ((fattr
& ~attrs
) & (FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
)) {
1447 status
= NT_STATUS_NO_SUCH_FILE
;
1451 /* Disallow if dst file already exists. */
1452 if (VALID_STAT(smb_fname_dst
->st
)) {
1453 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
1457 /* No links from a directory. */
1458 if (S_ISDIR(smb_fname_src
->st
.st_ex_mode
)) {
1459 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
1463 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1464 smb_fname_str_dbg(smb_fname_src
),
1465 smb_fname_str_dbg(smb_fname_dst
)));
1467 status
= SMB_VFS_CREATE_FILE(
1470 0, /* root_dir_fid */
1471 smb_fname_src
, /* fname */
1472 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
|
1473 FILE_READ_EA
, /* access_mask */
1474 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1476 FILE_OPEN
, /* create_disposition*/
1477 0, /* create_options */
1478 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
1479 NO_OPLOCK
, /* oplock_request */
1481 0, /* allocation_size */
1482 0, /* private_flags */
1487 NULL
, NULL
); /* create context */
1489 if (!NT_STATUS_IS_OK(status
)) {
1493 status
= SMB_VFS_CREATE_FILE(
1496 0, /* root_dir_fid */
1497 smb_fname_dst
, /* fname */
1498 FILE_WRITE_DATA
|FILE_WRITE_ATTRIBUTES
|
1499 FILE_WRITE_EA
, /* access_mask */
1500 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1502 FILE_CREATE
, /* create_disposition*/
1503 0, /* create_options */
1504 fattr
, /* file_attributes */
1505 NO_OPLOCK
, /* oplock_request */
1507 0, /* allocation_size */
1508 0, /* private_flags */
1513 NULL
, NULL
); /* create context */
1515 if (!NT_STATUS_IS_OK(status
)) {
1516 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1520 if (smb_fname_src
->st
.st_ex_size
) {
1521 ret
= vfs_transfer_file(fsp1
, fsp2
, smb_fname_src
->st
.st_ex_size
);
1525 * As we are opening fsp1 read-only we only expect
1526 * an error on close on fsp2 if we are out of space.
1527 * Thus we don't look at the error return from the
1530 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1532 /* Ensure the modtime is set correctly on the destination file. */
1533 set_close_write_time(fsp2
, smb_fname_src
->st
.st_ex_mtime
);
1535 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1537 /* Grrr. We have to do this as open_file_ntcreate adds FILE_ATTRIBUTE_ARCHIVE when it
1538 creates the file. This isn't the correct thing to do in the copy
1540 if (!parent_dirname(talloc_tos(), smb_fname_dst
->base_name
, &parent
,
1542 status
= NT_STATUS_NO_MEMORY
;
1545 file_set_dosmode(conn
, smb_fname_dst
, fattr
, parent
, false);
1546 TALLOC_FREE(parent
);
1548 if (ret
< (off_t
)smb_fname_src
->st
.st_ex_size
) {
1549 status
= NT_STATUS_DISK_FULL
;
1553 if (!NT_STATUS_IS_OK(status
)) {
1554 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1555 nt_errstr(status
), smb_fname_str_dbg(smb_fname_src
),
1556 smb_fname_str_dbg(smb_fname_dst
)));
1562 /****************************************************************************
1563 Reply to a NT rename request.
1564 ****************************************************************************/
1566 void reply_ntrename(struct smb_request
*req
)
1568 connection_struct
*conn
= req
->conn
;
1569 struct smb_filename
*smb_fname_old
= NULL
;
1570 struct smb_filename
*smb_fname_new
= NULL
;
1571 char *oldname
= NULL
;
1572 char *newname
= NULL
;
1575 bool src_has_wcard
= False
;
1576 bool dest_has_wcard
= False
;
1578 uint32_t ucf_flags_src
= ucf_flags_from_smb_request(req
);
1579 uint32_t ucf_flags_dst
= ucf_flags_from_smb_request(req
);
1580 uint16_t rename_type
;
1581 TALLOC_CTX
*ctx
= talloc_tos();
1582 bool stream_rename
= false;
1584 START_PROFILE(SMBntrename
);
1587 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1591 attrs
= SVAL(req
->vwv
+0, 0);
1592 rename_type
= SVAL(req
->vwv
+1, 0);
1594 p
= (const char *)req
->buf
+ 1;
1595 p
+= srvstr_get_path_req_wcard(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1596 &status
, &src_has_wcard
);
1597 if (!NT_STATUS_IS_OK(status
)) {
1598 reply_nterror(req
, status
);
1602 if (!req
->posix_pathnames
&& ms_has_wild(oldname
)) {
1603 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1608 p
+= srvstr_get_path_req_wcard(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1609 &status
, &dest_has_wcard
);
1610 if (!NT_STATUS_IS_OK(status
)) {
1611 reply_nterror(req
, status
);
1615 if (!req
->posix_pathnames
) {
1616 /* The newname must begin with a ':' if the
1617 oldname contains a ':'. */
1618 if (strchr_m(oldname
, ':')) {
1619 if (newname
[0] != ':') {
1620 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1623 stream_rename
= true;
1628 * If this is a rename operation, allow wildcards and save the
1629 * destination's last component.
1631 if (rename_type
== RENAME_FLAG_RENAME
) {
1632 ucf_flags_src
|= UCF_COND_ALLOW_WCARD_LCOMP
;
1633 ucf_flags_dst
|= UCF_COND_ALLOW_WCARD_LCOMP
| UCF_SAVE_LCOMP
;
1636 /* rename_internals() calls unix_convert(), so don't call it here. */
1637 status
= filename_convert(ctx
, conn
,
1643 if (!NT_STATUS_IS_OK(status
)) {
1644 if (NT_STATUS_EQUAL(status
,
1645 NT_STATUS_PATH_NOT_COVERED
)) {
1646 reply_botherror(req
,
1647 NT_STATUS_PATH_NOT_COVERED
,
1648 ERRSRV
, ERRbadpath
);
1651 reply_nterror(req
, status
);
1655 status
= filename_convert(ctx
, conn
,
1661 if (!NT_STATUS_IS_OK(status
)) {
1662 if (NT_STATUS_EQUAL(status
,
1663 NT_STATUS_PATH_NOT_COVERED
)) {
1664 reply_botherror(req
,
1665 NT_STATUS_PATH_NOT_COVERED
,
1666 ERRSRV
, ERRbadpath
);
1669 reply_nterror(req
, status
);
1673 if (stream_rename
) {
1674 /* smb_fname_new must be the same as smb_fname_old. */
1675 TALLOC_FREE(smb_fname_new
->base_name
);
1676 smb_fname_new
->base_name
= talloc_strdup(smb_fname_new
,
1677 smb_fname_old
->base_name
);
1678 if (!smb_fname_new
->base_name
) {
1679 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1684 DEBUG(3,("reply_ntrename: %s -> %s\n",
1685 smb_fname_str_dbg(smb_fname_old
),
1686 smb_fname_str_dbg(smb_fname_new
)));
1688 switch(rename_type
) {
1689 case RENAME_FLAG_RENAME
:
1690 status
= rename_internals(ctx
, conn
, req
,
1691 smb_fname_old
, smb_fname_new
,
1692 attrs
, False
, src_has_wcard
,
1696 case RENAME_FLAG_HARD_LINK
:
1697 if (src_has_wcard
|| dest_has_wcard
) {
1699 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1701 status
= hardlink_internals(ctx
, conn
,
1708 case RENAME_FLAG_COPY
:
1709 if (src_has_wcard
|| dest_has_wcard
) {
1711 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1713 status
= copy_internals(ctx
, conn
, req
,
1719 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1720 status
= NT_STATUS_INVALID_PARAMETER
;
1723 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1727 if (!NT_STATUS_IS_OK(status
)) {
1728 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1729 /* We have re-scheduled this call. */
1733 reply_nterror(req
, status
);
1737 reply_outbuf(req
, 0, 0);
1739 END_PROFILE(SMBntrename
);
1743 /****************************************************************************
1744 Reply to a notify change - queue the request and
1745 don't allow a directory to be opened.
1746 ****************************************************************************/
1748 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1749 NTSTATUS error_code
,
1750 uint8_t *buf
, size_t len
)
1752 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1755 static void call_nt_transact_notify_change(connection_struct
*conn
,
1756 struct smb_request
*req
,
1758 uint32_t setup_count
,
1760 uint32_t parameter_count
,
1761 char **ppdata
, uint32_t data_count
,
1762 uint32_t max_data_count
,
1763 uint32_t max_param_count
)
1765 uint16_t *setup
= *ppsetup
;
1771 if(setup_count
< 6) {
1772 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1776 fsp
= file_fsp(req
, SVAL(setup
,4));
1777 filter
= IVAL(setup
, 0);
1778 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1780 DEBUG(3,("call_nt_transact_notify_change\n"));
1783 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1788 char *filter_string
;
1790 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1791 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1795 DEBUG(3,("call_nt_transact_notify_change: notify change "
1796 "called on %s, filter = %s, recursive = %d\n",
1797 fsp_str_dbg(fsp
), filter_string
, recursive
));
1799 TALLOC_FREE(filter_string
);
1802 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1803 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1807 if (fsp
->notify
== NULL
) {
1809 status
= change_notify_create(fsp
, filter
, recursive
);
1811 if (!NT_STATUS_IS_OK(status
)) {
1812 DEBUG(10, ("change_notify_create returned %s\n",
1813 nt_errstr(status
)));
1814 reply_nterror(req
, status
);
1819 if (change_notify_fsp_has_changes(fsp
)) {
1822 * We've got changes pending, respond immediately
1826 * TODO: write a torture test to check the filtering behaviour
1830 change_notify_reply(req
,
1834 smbd_smb1_notify_reply
);
1837 * change_notify_reply() above has independently sent its
1844 * No changes pending, queue the request
1847 status
= change_notify_add_request(req
,
1851 smbd_smb1_notify_reply
);
1852 if (!NT_STATUS_IS_OK(status
)) {
1853 reply_nterror(req
, status
);
1858 /****************************************************************************
1859 Reply to an NT transact rename command.
1860 ****************************************************************************/
1862 static void call_nt_transact_rename(connection_struct
*conn
,
1863 struct smb_request
*req
,
1864 uint16_t **ppsetup
, uint32_t setup_count
,
1865 char **ppparams
, uint32_t parameter_count
,
1866 char **ppdata
, uint32_t data_count
,
1867 uint32_t max_data_count
)
1869 char *params
= *ppparams
;
1870 char *new_name
= NULL
;
1871 files_struct
*fsp
= NULL
;
1872 bool dest_has_wcard
= False
;
1874 TALLOC_CTX
*ctx
= talloc_tos();
1876 if(parameter_count
< 5) {
1877 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1881 fsp
= file_fsp(req
, SVAL(params
, 0));
1882 if (!check_fsp(conn
, req
, fsp
)) {
1885 if (req
->posix_pathnames
) {
1886 srvstr_get_path_wcard_posix(ctx
,
1891 parameter_count
- 4,
1896 srvstr_get_path_wcard(ctx
,
1901 parameter_count
- 4,
1907 if (!NT_STATUS_IS_OK(status
)) {
1908 reply_nterror(req
, status
);
1913 * W2K3 ignores this request as the RAW-RENAME test
1914 * demonstrates, so we do.
1916 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1918 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1919 fsp_str_dbg(fsp
), new_name
));
1924 /******************************************************************************
1925 Fake up a completely empty SD.
1926 *******************************************************************************/
1928 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppsd
)
1932 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1934 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1935 return NT_STATUS_NO_MEMORY
;
1938 return NT_STATUS_OK
;
1941 /****************************************************************************
1942 Reply to query a security descriptor.
1943 Callable from SMB1 and SMB2.
1944 If it returns NT_STATUS_BUFFER_TOO_SMALL, pdata_size is initialized with
1946 ****************************************************************************/
1948 NTSTATUS
smbd_do_query_security_desc(connection_struct
*conn
,
1949 TALLOC_CTX
*mem_ctx
,
1951 uint32_t security_info_wanted
,
1952 uint32_t max_data_count
,
1953 uint8_t **ppmarshalled_sd
,
1957 struct security_descriptor
*psd
= NULL
;
1958 TALLOC_CTX
*frame
= talloc_stackframe();
1961 * Get the permissions to return.
1964 if ((security_info_wanted
& SECINFO_SACL
) &&
1965 !(fsp
->access_mask
& SEC_FLAG_SYSTEM_SECURITY
)) {
1966 DEBUG(10, ("Access to SACL denied.\n"));
1968 return NT_STATUS_ACCESS_DENIED
;
1971 if ((security_info_wanted
& (SECINFO_DACL
|SECINFO_OWNER
|SECINFO_GROUP
)) &&
1972 !(fsp
->access_mask
& SEC_STD_READ_CONTROL
)) {
1973 DEBUG(10, ("Access to DACL, OWNER, or GROUP denied.\n"));
1975 return NT_STATUS_ACCESS_DENIED
;
1978 if (S_ISLNK(fsp
->fsp_name
->st
.st_ex_mode
)) {
1979 DEBUG(10, ("ACL get on symlink %s denied.\n",
1982 return NT_STATUS_ACCESS_DENIED
;
1985 if (security_info_wanted
& (SECINFO_DACL
|SECINFO_OWNER
|
1986 SECINFO_GROUP
|SECINFO_SACL
)) {
1987 /* Don't return SECINFO_LABEL if anything else was
1988 requested. See bug #8458. */
1989 security_info_wanted
&= ~SECINFO_LABEL
;
1992 if (!lp_nt_acl_support(SNUM(conn
))) {
1993 status
= get_null_nt_acl(frame
, &psd
);
1994 } else if (security_info_wanted
& SECINFO_LABEL
) {
1995 /* Like W2K3 return a null object. */
1996 status
= get_null_nt_acl(frame
, &psd
);
1998 status
= SMB_VFS_FGET_NT_ACL(
1999 fsp
, security_info_wanted
, frame
, &psd
);
2001 if (!NT_STATUS_IS_OK(status
)) {
2006 if (!(security_info_wanted
& SECINFO_OWNER
)) {
2007 psd
->owner_sid
= NULL
;
2009 if (!(security_info_wanted
& SECINFO_GROUP
)) {
2010 psd
->group_sid
= NULL
;
2012 if (!(security_info_wanted
& SECINFO_DACL
)) {
2013 psd
->type
&= ~SEC_DESC_DACL_PRESENT
;
2016 if (!(security_info_wanted
& SECINFO_SACL
)) {
2017 psd
->type
&= ~SEC_DESC_SACL_PRESENT
;
2021 /* If the SACL/DACL is NULL, but was requested, we mark that it is
2022 * present in the reply to match Windows behavior */
2023 if (psd
->sacl
== NULL
&&
2024 security_info_wanted
& SECINFO_SACL
)
2025 psd
->type
|= SEC_DESC_SACL_PRESENT
;
2026 if (psd
->dacl
== NULL
&&
2027 security_info_wanted
& SECINFO_DACL
)
2028 psd
->type
|= SEC_DESC_DACL_PRESENT
;
2030 if (security_info_wanted
& SECINFO_LABEL
) {
2031 /* Like W2K3 return a null object. */
2032 psd
->owner_sid
= NULL
;
2033 psd
->group_sid
= NULL
;
2036 psd
->type
&= ~(SEC_DESC_DACL_PRESENT
|SEC_DESC_SACL_PRESENT
);
2039 *psd_size
= ndr_size_security_descriptor(psd
, 0);
2041 DEBUG(3,("smbd_do_query_security_desc: sd_size = %lu.\n",
2042 (unsigned long)*psd_size
));
2044 if (DEBUGLEVEL
>= 10) {
2045 DEBUG(10,("smbd_do_query_security_desc for file %s\n",
2047 NDR_PRINT_DEBUG(security_descriptor
, psd
);
2050 if (max_data_count
< *psd_size
) {
2052 return NT_STATUS_BUFFER_TOO_SMALL
;
2055 status
= marshall_sec_desc(mem_ctx
, psd
,
2056 ppmarshalled_sd
, psd_size
);
2058 if (!NT_STATUS_IS_OK(status
)) {
2064 return NT_STATUS_OK
;
2067 /****************************************************************************
2068 SMB1 reply to query a security descriptor.
2069 ****************************************************************************/
2071 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
2072 struct smb_request
*req
,
2074 uint32_t setup_count
,
2076 uint32_t parameter_count
,
2078 uint32_t data_count
,
2079 uint32_t max_data_count
)
2081 char *params
= *ppparams
;
2082 char *data
= *ppdata
;
2084 uint32_t security_info_wanted
;
2085 files_struct
*fsp
= NULL
;
2087 uint8_t *marshalled_sd
= NULL
;
2089 if(parameter_count
< 8) {
2090 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2094 fsp
= file_fsp(req
, SVAL(params
,0));
2096 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2100 security_info_wanted
= IVAL(params
,4);
2102 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
2103 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
2104 (unsigned int)security_info_wanted
));
2106 params
= nttrans_realloc(ppparams
, 4);
2107 if(params
== NULL
) {
2108 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2113 * Get the permissions to return.
2116 status
= smbd_do_query_security_desc(conn
,
2119 security_info_wanted
&
2120 SMB_SUPPORTED_SECINFO_FLAGS
,
2125 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
2126 SIVAL(params
,0,(uint32_t)sd_size
);
2127 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
2128 params
, 4, NULL
, 0);
2132 if (!NT_STATUS_IS_OK(status
)) {
2133 reply_nterror(req
, status
);
2137 SMB_ASSERT(sd_size
> 0);
2139 SIVAL(params
,0,(uint32_t)sd_size
);
2141 if (max_data_count
< sd_size
) {
2142 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
2143 params
, 4, NULL
, 0);
2148 * Allocate the data we will return.
2151 data
= nttrans_realloc(ppdata
, sd_size
);
2153 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2157 memcpy(data
, marshalled_sd
, sd_size
);
2159 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
2164 /****************************************************************************
2165 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2166 ****************************************************************************/
2168 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
2169 struct smb_request
*req
,
2171 uint32_t setup_count
,
2173 uint32_t parameter_count
,
2175 uint32_t data_count
,
2176 uint32_t max_data_count
)
2178 char *params
= *ppparams
;
2179 char *data
= *ppdata
;
2180 files_struct
*fsp
= NULL
;
2181 uint32_t security_info_sent
= 0;
2184 if(parameter_count
< 8) {
2185 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2189 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
2190 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2194 if (!CAN_WRITE(fsp
->conn
)) {
2195 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2199 if(!lp_nt_acl_support(SNUM(conn
))) {
2203 security_info_sent
= IVAL(params
,4);
2205 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
2206 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
2208 if (data_count
== 0) {
2209 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2213 status
= set_sd_blob(fsp
, (uint8_t *)data
, data_count
,
2214 security_info_sent
& SMB_SUPPORTED_SECINFO_FLAGS
);
2215 if (!NT_STATUS_IS_OK(status
)) {
2216 reply_nterror(req
, status
);
2221 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2225 /****************************************************************************
2227 ****************************************************************************/
2229 static void call_nt_transact_ioctl(connection_struct
*conn
,
2230 struct smb_request
*req
,
2231 uint16_t **ppsetup
, uint32_t setup_count
,
2232 char **ppparams
, uint32_t parameter_count
,
2233 char **ppdata
, uint32_t data_count
,
2234 uint32_t max_data_count
)
2242 char *out_data
= NULL
;
2243 uint32_t out_data_len
= 0;
2244 char *pdata
= *ppdata
;
2245 TALLOC_CTX
*ctx
= talloc_tos();
2247 if (setup_count
!= 8) {
2248 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
2249 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2253 function
= IVAL(*ppsetup
, 0);
2254 fidnum
= SVAL(*ppsetup
, 4);
2255 isFSctl
= CVAL(*ppsetup
, 6);
2256 compfilter
= CVAL(*ppsetup
, 7);
2258 DEBUG(10, ("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2259 function
, fidnum
, isFSctl
, compfilter
));
2261 fsp
=file_fsp(req
, fidnum
);
2264 * We don't really implement IOCTLs, especially on files.
2267 DEBUG(10, ("isFSctl: 0x%02X indicates IOCTL, not FSCTL!\n",
2269 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2273 /* Has to be for an open file! */
2274 if (!check_fsp_open(conn
, req
, fsp
)) {
2278 SMB_PERFCOUNT_SET_IOCTL(&req
->pcd
, function
);
2281 * out_data might be allocated by the VFS module, but talloc should be
2282 * used, and should be cleaned up when the request ends.
2284 status
= SMB_VFS_FSCTL(fsp
,
2290 (uint8_t **)&out_data
,
2293 if (!NT_STATUS_IS_OK(status
)) {
2294 reply_nterror(req
, status
);
2296 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, out_data
, out_data_len
);
2301 #ifdef HAVE_SYS_QUOTAS
2302 static enum ndr_err_code
fill_qtlist_from_sids(TALLOC_CTX
*mem_ctx
,
2303 struct files_struct
*fsp
,
2304 SMB_NTQUOTA_HANDLE
*qt_handle
,
2305 struct dom_sid
*sids
,
2309 TALLOC_CTX
*list_ctx
= NULL
;
2311 list_ctx
= talloc_init("quota_sid_list");
2313 if (list_ctx
== NULL
) {
2314 DBG_ERR("failed to allocate\n");
2315 return NDR_ERR_ALLOC
;
2318 if (qt_handle
->quota_list
!=NULL
) {
2319 free_ntquota_list(&(qt_handle
->quota_list
));
2321 for (i
= 0; i
< elems
; i
++) {
2322 SMB_NTQUOTA_STRUCT qt
;
2323 SMB_NTQUOTA_LIST
*list_item
;
2326 if (!NT_STATUS_IS_OK(vfs_get_ntquota(fsp
,
2327 SMB_USER_QUOTA_TYPE
,
2329 /* non fatal error, return empty item in result */
2335 list_item
= talloc_zero(list_ctx
, SMB_NTQUOTA_LIST
);
2336 if (list_item
== NULL
) {
2337 DBG_ERR("failed to allocate\n");
2338 return NDR_ERR_ALLOC
;
2341 ok
= sid_to_uid(&sids
[i
], &list_item
->uid
);
2343 struct dom_sid_buf buf
;
2344 DBG_WARNING("Could not convert SID %s to uid\n",
2345 dom_sid_str_buf(&sids
[i
], &buf
));
2346 /* No idea what to return here... */
2347 return NDR_ERR_INVALID_POINTER
;
2350 list_item
->quotas
= talloc_zero(list_item
, SMB_NTQUOTA_STRUCT
);
2351 if (list_item
->quotas
== NULL
) {
2352 DBG_ERR("failed to allocate\n");
2353 return NDR_ERR_ALLOC
;
2356 *list_item
->quotas
= qt
;
2357 list_item
->mem_ctx
= list_ctx
;
2358 DLIST_ADD(qt_handle
->quota_list
, list_item
);
2360 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2361 return NDR_ERR_SUCCESS
;
2364 static enum ndr_err_code
extract_sids_from_buf(TALLOC_CTX
*mem_ctx
,
2365 uint32_t sidlistlength
,
2367 struct dom_sid
**sids
,
2372 enum ndr_err_code err
;
2374 struct sid_list_elem
{
2375 struct sid_list_elem
*prev
, *next
;
2379 struct sid_list_elem
*sid_list
= NULL
;
2380 struct sid_list_elem
*iter
= NULL
;
2381 TALLOC_CTX
*list_ctx
= talloc_init("sid_list");
2384 err
= NDR_ERR_ALLOC
;
2391 if (sidlistlength
) {
2392 uint32_t offset
= 0;
2393 struct ndr_pull
*ndr_pull
= NULL
;
2395 if (sidlistlength
> sid_buf
->length
) {
2396 DBG_ERR("sid_list_length 0x%x exceeds "
2397 "available bytes %zx\n",
2400 err
= NDR_ERR_OFFSET
;
2404 struct file_get_quota_info info
;
2405 struct sid_list_elem
*item
= NULL
;
2406 uint32_t new_offset
= 0;
2407 blob
.data
= sid_buf
->data
+ offset
;
2408 blob
.length
= sidlistlength
- offset
;
2409 ndr_pull
= ndr_pull_init_blob(&blob
, list_ctx
);
2412 err
= NDR_ERR_ALLOC
;
2415 err
= ndr_pull_file_get_quota_info(ndr_pull
,
2416 NDR_SCALARS
| NDR_BUFFERS
, &info
);
2417 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2418 DBG_ERR("Failed to pull file_get_quota_info "
2419 "from sidlist buffer\n");
2422 item
= talloc_zero(list_ctx
, struct sid_list_elem
);
2425 err
= NDR_ERR_ALLOC
;
2428 item
->sid
= info
.sid
;
2429 DLIST_ADD(sid_list
, item
);
2431 if (i
== UINT32_MAX
) {
2432 DBG_ERR("Integer overflow\n");
2433 err
= NDR_ERR_ARRAY_SIZE
;
2436 new_offset
= info
.next_entry_offset
;
2438 /* if new_offset == 0 no more sid(s) to read. */
2439 if (new_offset
== 0) {
2444 if ((offset
+ new_offset
) < offset
) {
2445 DBG_ERR("Integer wrap while adding "
2446 "new_offset 0x%x to current "
2447 "buffer offset 0x%x\n",
2448 new_offset
, offset
);
2449 err
= NDR_ERR_OFFSET
;
2453 offset
+= new_offset
;
2455 /* check if new offset is outside buffer boundry. */
2456 if (offset
>= sidlistlength
) {
2457 DBG_ERR("bufsize 0x%x exceeded by "
2458 "new offset 0x%x)\n",
2461 err
= NDR_ERR_OFFSET
;
2465 *sids
= talloc_zero_array(mem_ctx
, struct dom_sid
, i
);
2466 if (*sids
== NULL
) {
2468 err
= NDR_ERR_ALLOC
;
2474 for (iter
= sid_list
, i
= 0; iter
; iter
= iter
->next
, i
++) {
2475 struct dom_sid_buf buf
;
2476 (*sids
)[i
] = iter
->sid
;
2477 DBG_DEBUG("quota SID[%u] %s\n",
2479 dom_sid_str_buf(&iter
->sid
, &buf
));
2482 err
= NDR_ERR_SUCCESS
;
2484 TALLOC_FREE(list_ctx
);
2488 NTSTATUS
smbd_do_query_getinfo_quota(TALLOC_CTX
*mem_ctx
,
2492 uint32_t sid_list_length
,
2494 uint32_t max_data_count
,
2496 uint32_t *p_data_size
)
2499 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2500 SMB_NTQUOTA_LIST
*qt_list
= NULL
;
2501 DATA_BLOB blob
= data_blob_null
;
2502 enum ndr_err_code err
;
2505 (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2507 if (sid_list_length
) {
2508 struct dom_sid
*sids
;
2511 * error check pulled offsets and lengths for wrap and
2512 * exceeding available bytes.
2514 if (sid_list_length
> sid_buf
->length
) {
2515 DBG_ERR("sid_list_length 0x%x exceeds "
2516 "available bytes %zx\n",
2519 return NT_STATUS_INVALID_PARAMETER
;
2522 err
= extract_sids_from_buf(mem_ctx
, sid_list_length
,
2523 sid_buf
, &sids
, &elems
);
2524 if (!NDR_ERR_CODE_IS_SUCCESS(err
) || elems
== 0) {
2525 return NT_STATUS_INVALID_PARAMETER
;
2527 err
= fill_qtlist_from_sids(mem_ctx
,
2532 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2533 return NT_STATUS_INVALID_PARAMETER
;
2535 } else if (restart_scan
) {
2536 if (vfs_get_user_ntquota_list(fsp
,
2537 &(qt_handle
->quota_list
))!=0) {
2538 return NT_STATUS_INTERNAL_ERROR
;
2541 if (qt_handle
->quota_list
!=NULL
&&
2542 qt_handle
->tmp_list
==NULL
) {
2543 free_ntquota_list(&(qt_handle
->quota_list
));
2547 if (restart_scan
!=0 ) {
2548 qt_list
= qt_handle
->quota_list
;
2550 qt_list
= qt_handle
->tmp_list
;
2552 status
= fill_quota_buffer(mem_ctx
, qt_list
,
2556 &qt_handle
->tmp_list
);
2557 if (!NT_STATUS_IS_OK(status
)) {
2560 if (blob
.length
> max_data_count
) {
2561 return NT_STATUS_BUFFER_TOO_SMALL
;
2564 *p_data
= blob
.data
;
2565 *p_data_size
= blob
.length
;
2566 return NT_STATUS_OK
;
2569 /****************************************************************************
2570 Reply to get user quota
2571 ****************************************************************************/
2573 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2574 struct smb_request
*req
,
2576 uint32_t setup_count
,
2578 uint32_t parameter_count
,
2580 uint32_t data_count
,
2581 uint32_t max_data_count
)
2583 NTSTATUS nt_status
= NT_STATUS_OK
;
2584 char *params
= *ppparams
;
2585 char *pdata
= *ppdata
;
2588 files_struct
*fsp
= NULL
;
2589 DATA_BLOB blob
= data_blob_null
;
2590 struct nttrans_query_quota_params info
= {0};
2591 enum ndr_err_code err
;
2592 TALLOC_CTX
*tmp_ctx
= NULL
;
2593 uint32_t resp_len
= 0;
2594 uint8_t *resp_data
= 0;
2596 tmp_ctx
= talloc_init("ntquota_list");
2598 nt_status
= NT_STATUS_NO_MEMORY
;
2603 if (get_current_uid(conn
) != sec_initial_uid()) {
2604 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2605 "[%s]\n", lp_servicename(talloc_tos(), SNUM(conn
)),
2606 conn
->session_info
->unix_info
->unix_name
));
2607 nt_status
= NT_STATUS_ACCESS_DENIED
;
2611 blob
.data
= (uint8_t*)params
;
2612 blob
.length
= parameter_count
;
2614 err
= ndr_pull_struct_blob(&blob
, tmp_ctx
, &info
,
2615 (ndr_pull_flags_fn_t
)ndr_pull_nttrans_query_quota_params
);
2617 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2618 DEBUG(0,("TRANSACT_GET_USER_QUOTA: failed to pull "
2619 "query_quota_params."));
2620 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2623 DBG_DEBUG("info.return_single_entry = %u, info.restart_scan = %u, "
2624 "info.sid_list_length = %u, info.start_sid_length = %u, "
2625 "info.start_sid_offset = %u\n",
2626 (unsigned int)info
.return_single_entry
,
2627 (unsigned int)info
.restart_scan
,
2628 (unsigned int)info
.sid_list_length
,
2629 (unsigned int)info
.start_sid_length
,
2630 (unsigned int)info
.start_sid_offset
);
2632 /* set blob to point at data for further parsing */
2633 blob
.data
= (uint8_t*)pdata
;
2634 blob
.length
= data_count
;
2636 * Although MS-SMB ref is ambiguous here, a microsoft client will
2637 * only ever send a start sid (as part of a list) with
2638 * sid_list_length & start_sid_offset both set to the actual list
2639 * length. Note: Only a single result is returned in this case
2640 * In the case where either start_sid_offset or start_sid_length
2641 * are set alone or if both set (but have different values) then
2642 * it seems windows will return a number of entries from the start
2643 * of the list of users with quotas set. This behaviour is undocumented
2644 * and windows clients do not send messages of that type. As such we
2645 * currently will reject these requests.
2647 if (info
.start_sid_length
2648 || (info
.sid_list_length
!= info
.start_sid_offset
)) {
2649 DBG_ERR("TRANSACT_GET_USER_QUOTA: unsupported single or "
2650 "compound sid format\n");
2651 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2655 /* maybe we can check the quota_fnum */
2656 fsp
= file_fsp(req
, info
.fid
);
2657 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2658 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2659 nt_status
= NT_STATUS_INVALID_HANDLE
;
2662 nt_status
= smbd_do_query_getinfo_quota(tmp_ctx
,
2665 info
.return_single_entry
,
2666 info
.sid_list_length
,
2671 if (!NT_STATUS_IS_OK(nt_status
)) {
2672 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2675 nt_status
= NT_STATUS_OK
;
2679 params
= nttrans_realloc(ppparams
, param_len
);
2680 if(params
== NULL
) {
2681 nt_status
= NT_STATUS_NO_MEMORY
;
2685 data_len
= resp_len
;
2686 SIVAL(params
, 0, data_len
);
2687 pdata
= nttrans_realloc(ppdata
, data_len
);
2688 memcpy(pdata
, resp_data
, data_len
);
2690 TALLOC_FREE(tmp_ctx
);
2691 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2695 TALLOC_FREE(tmp_ctx
);
2696 reply_nterror(req
, nt_status
);
2699 /****************************************************************************
2700 Reply to set user quota
2701 ****************************************************************************/
2703 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2704 struct smb_request
*req
,
2706 uint32_t setup_count
,
2708 uint32_t parameter_count
,
2710 uint32_t data_count
,
2711 uint32_t max_data_count
)
2713 char *params
= *ppparams
;
2714 char *pdata
= *ppdata
;
2715 int data_len
=0,param_len
=0;
2716 SMB_NTQUOTA_STRUCT qt
;
2717 struct file_quota_information info
= {0};
2718 enum ndr_err_code err
;
2721 files_struct
*fsp
= NULL
;
2722 TALLOC_CTX
*ctx
= NULL
;
2723 NTSTATUS status
= NT_STATUS_OK
;
2727 if (get_current_uid(conn
) != sec_initial_uid()) {
2728 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2729 "[%s]\n", lp_servicename(talloc_tos(), SNUM(conn
)),
2730 conn
->session_info
->unix_info
->unix_name
));
2731 status
= NT_STATUS_ACCESS_DENIED
;
2736 * Ensure minimum number of parameters sent.
2739 if (parameter_count
< 2) {
2740 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2741 status
= NT_STATUS_INVALID_PARAMETER
;
2745 /* maybe we can check the quota_fnum */
2746 fsp
= file_fsp(req
, SVAL(params
,0));
2747 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2748 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2749 status
= NT_STATUS_INVALID_HANDLE
;
2753 ctx
= talloc_init("set_user_quota");
2755 status
= NT_STATUS_NO_MEMORY
;
2758 inblob
.data
= (uint8_t*)pdata
;
2759 inblob
.length
= data_count
;
2761 err
= ndr_pull_struct_blob(
2765 (ndr_pull_flags_fn_t
)ndr_pull_file_quota_information
);
2767 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2768 DEBUG(0,("TRANSACT_SET_USER_QUOTA: failed to pull "
2769 "file_quota_information\n"));
2770 status
= NT_STATUS_INVALID_PARAMETER
;
2773 qt
.usedspace
= info
.quota_used
;
2775 qt
.softlim
= info
.quota_threshold
;
2777 qt
.hardlim
= info
.quota_limit
;
2781 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2782 status
= NT_STATUS_INTERNAL_ERROR
;
2786 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2792 reply_nterror(req
, status
);
2794 #endif /* HAVE_SYS_QUOTAS */
2796 static void handle_nttrans(connection_struct
*conn
,
2797 struct trans_state
*state
,
2798 struct smb_request
*req
)
2800 if (get_Protocol() >= PROTOCOL_NT1
) {
2801 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2802 SSVAL(discard_const_p(uint8_t, req
->inbuf
),smb_flg2
,req
->flags2
);
2806 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2808 /* Now we must call the relevant NT_TRANS function */
2809 switch(state
->call
) {
2810 case NT_TRANSACT_CREATE
:
2812 START_PROFILE(NT_transact_create
);
2813 call_nt_transact_create(
2815 &state
->setup
, state
->setup_count
,
2816 &state
->param
, state
->total_param
,
2817 &state
->data
, state
->total_data
,
2818 state
->max_data_return
);
2819 END_PROFILE(NT_transact_create
);
2823 case NT_TRANSACT_IOCTL
:
2825 START_PROFILE(NT_transact_ioctl
);
2826 call_nt_transact_ioctl(
2828 &state
->setup
, state
->setup_count
,
2829 &state
->param
, state
->total_param
,
2830 &state
->data
, state
->total_data
,
2831 state
->max_data_return
);
2832 END_PROFILE(NT_transact_ioctl
);
2836 case NT_TRANSACT_SET_SECURITY_DESC
:
2838 START_PROFILE(NT_transact_set_security_desc
);
2839 call_nt_transact_set_security_desc(
2841 &state
->setup
, state
->setup_count
,
2842 &state
->param
, state
->total_param
,
2843 &state
->data
, state
->total_data
,
2844 state
->max_data_return
);
2845 END_PROFILE(NT_transact_set_security_desc
);
2849 case NT_TRANSACT_NOTIFY_CHANGE
:
2851 START_PROFILE(NT_transact_notify_change
);
2852 call_nt_transact_notify_change(
2854 &state
->setup
, state
->setup_count
,
2855 &state
->param
, state
->total_param
,
2856 &state
->data
, state
->total_data
,
2857 state
->max_data_return
,
2858 state
->max_param_return
);
2859 END_PROFILE(NT_transact_notify_change
);
2863 case NT_TRANSACT_RENAME
:
2865 START_PROFILE(NT_transact_rename
);
2866 call_nt_transact_rename(
2868 &state
->setup
, state
->setup_count
,
2869 &state
->param
, state
->total_param
,
2870 &state
->data
, state
->total_data
,
2871 state
->max_data_return
);
2872 END_PROFILE(NT_transact_rename
);
2876 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2878 START_PROFILE(NT_transact_query_security_desc
);
2879 call_nt_transact_query_security_desc(
2881 &state
->setup
, state
->setup_count
,
2882 &state
->param
, state
->total_param
,
2883 &state
->data
, state
->total_data
,
2884 state
->max_data_return
);
2885 END_PROFILE(NT_transact_query_security_desc
);
2889 #ifdef HAVE_SYS_QUOTAS
2890 case NT_TRANSACT_GET_USER_QUOTA
:
2892 START_PROFILE(NT_transact_get_user_quota
);
2893 call_nt_transact_get_user_quota(
2895 &state
->setup
, state
->setup_count
,
2896 &state
->param
, state
->total_param
,
2897 &state
->data
, state
->total_data
,
2898 state
->max_data_return
);
2899 END_PROFILE(NT_transact_get_user_quota
);
2903 case NT_TRANSACT_SET_USER_QUOTA
:
2905 START_PROFILE(NT_transact_set_user_quota
);
2906 call_nt_transact_set_user_quota(
2908 &state
->setup
, state
->setup_count
,
2909 &state
->param
, state
->total_param
,
2910 &state
->data
, state
->total_data
,
2911 state
->max_data_return
);
2912 END_PROFILE(NT_transact_set_user_quota
);
2915 #endif /* HAVE_SYS_QUOTAS */
2918 /* Error in request */
2919 DEBUG(0,("handle_nttrans: Unknown request %d in "
2920 "nttrans call\n", state
->call
));
2921 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2927 /****************************************************************************
2928 Reply to a SMBNTtrans.
2929 ****************************************************************************/
2931 void reply_nttrans(struct smb_request
*req
)
2933 connection_struct
*conn
= req
->conn
;
2938 uint16_t function_code
;
2940 struct trans_state
*state
;
2942 START_PROFILE(SMBnttrans
);
2944 if (req
->wct
< 19) {
2945 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2946 END_PROFILE(SMBnttrans
);
2950 pscnt
= IVAL(req
->vwv
+9, 1);
2951 psoff
= IVAL(req
->vwv
+11, 1);
2952 dscnt
= IVAL(req
->vwv
+13, 1);
2953 dsoff
= IVAL(req
->vwv
+15, 1);
2954 function_code
= SVAL(req
->vwv
+18, 0);
2956 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2957 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2958 END_PROFILE(SMBnttrans
);
2962 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2963 if (!NT_STATUS_IS_OK(result
)) {
2964 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2965 reply_nterror(req
, result
);
2966 END_PROFILE(SMBnttrans
);
2970 if ((state
= talloc(conn
, struct trans_state
)) == NULL
) {
2971 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2972 END_PROFILE(SMBnttrans
);
2976 state
->cmd
= SMBnttrans
;
2978 state
->mid
= req
->mid
;
2979 state
->vuid
= req
->vuid
;
2980 state
->total_data
= IVAL(req
->vwv
+3, 1);
2982 state
->total_param
= IVAL(req
->vwv
+1, 1);
2983 state
->param
= NULL
;
2984 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2985 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2987 /* setup count is in *words* */
2988 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2989 state
->setup
= NULL
;
2990 state
->call
= function_code
;
2992 DEBUG(10, ("num_setup=%u, "
2993 "param_total=%u, this_param=%u, max_param=%u, "
2994 "data_total=%u, this_data=%u, max_data=%u, "
2995 "param_offset=%u, data_offset=%u\n",
2996 (unsigned)state
->setup_count
,
2997 (unsigned)state
->total_param
, (unsigned)pscnt
,
2998 (unsigned)state
->max_param_return
,
2999 (unsigned)state
->total_data
, (unsigned)dscnt
,
3000 (unsigned)state
->max_data_return
,
3001 (unsigned)psoff
, (unsigned)dsoff
));
3004 * All nttrans messages we handle have smb_wct == 19 +
3005 * state->setup_count. Ensure this is so as a sanity check.
3008 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
3009 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
3010 req
->wct
, 19 + (state
->setup_count
/2)));
3014 /* Don't allow more than 128mb for each value. */
3015 if ((state
->total_data
> (1024*1024*128)) ||
3016 (state
->total_param
> (1024*1024*128))) {
3017 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3018 END_PROFILE(SMBnttrans
);
3022 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
3025 if (state
->total_data
) {
3027 if (trans_oob(state
->total_data
, 0, dscnt
)
3028 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
3032 /* Can't use talloc here, the core routines do realloc on the
3033 * params and data. */
3034 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
3035 DEBUG(0,("reply_nttrans: data malloc fail for %u "
3036 "bytes !\n", (unsigned int)state
->total_data
));
3038 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3039 END_PROFILE(SMBnttrans
);
3043 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
3046 if (state
->total_param
) {
3048 if (trans_oob(state
->total_param
, 0, pscnt
)
3049 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
3053 /* Can't use talloc here, the core routines do realloc on the
3054 * params and data. */
3055 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
3056 DEBUG(0,("reply_nttrans: param malloc fail for %u "
3057 "bytes !\n", (unsigned int)state
->total_param
));
3058 SAFE_FREE(state
->data
);
3060 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3061 END_PROFILE(SMBnttrans
);
3065 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
3068 state
->received_data
= dscnt
;
3069 state
->received_param
= pscnt
;
3071 if(state
->setup_count
> 0) {
3072 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
3073 state
->setup_count
));
3076 * No overflow possible here, state->setup_count is an
3077 * unsigned int, being filled by a single byte from
3078 * CVAL(req->vwv+13, 0) above. The cast in the comparison
3079 * below is not necessary, it's here to clarify things. The
3080 * validity of req->vwv and req->wct has been checked in
3081 * init_smb_request already.
3083 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
3087 state
->setup
= (uint16_t *)TALLOC(state
, state
->setup_count
);
3088 if (state
->setup
== NULL
) {
3089 DEBUG(0,("reply_nttrans : Out of memory\n"));
3090 SAFE_FREE(state
->data
);
3091 SAFE_FREE(state
->param
);
3093 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3094 END_PROFILE(SMBnttrans
);
3098 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
3099 dump_data(10, (uint8_t *)state
->setup
, state
->setup_count
);
3102 if ((state
->received_data
== state
->total_data
) &&
3103 (state
->received_param
== state
->total_param
)) {
3104 handle_nttrans(conn
, state
, req
);
3105 SAFE_FREE(state
->param
);
3106 SAFE_FREE(state
->data
);
3108 END_PROFILE(SMBnttrans
);
3112 DLIST_ADD(conn
->pending_trans
, state
);
3114 /* We need to send an interim response then receive the rest
3115 of the parameter/data bytes */
3116 reply_outbuf(req
, 0, 0);
3117 show_msg((char *)req
->outbuf
);
3118 END_PROFILE(SMBnttrans
);
3123 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3124 SAFE_FREE(state
->data
);
3125 SAFE_FREE(state
->param
);
3127 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3128 END_PROFILE(SMBnttrans
);
3132 /****************************************************************************
3133 Reply to a SMBnttranss
3134 ****************************************************************************/
3136 void reply_nttranss(struct smb_request
*req
)
3138 connection_struct
*conn
= req
->conn
;
3139 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
3140 struct trans_state
*state
;
3142 START_PROFILE(SMBnttranss
);
3144 show_msg((const char *)req
->inbuf
);
3146 /* Windows clients expect all replies to
3147 an NT transact secondary (SMBnttranss 0xA1)
3148 to have a command code of NT transact
3149 (SMBnttrans 0xA0). See bug #8989 for details. */
3150 req
->cmd
= SMBnttrans
;
3152 if (req
->wct
< 18) {
3153 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3154 END_PROFILE(SMBnttranss
);
3158 for (state
= conn
->pending_trans
; state
!= NULL
;
3159 state
= state
->next
) {
3160 if (state
->mid
== req
->mid
) {
3165 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
3166 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3167 END_PROFILE(SMBnttranss
);
3171 /* Revise state->total_param and state->total_data in case they have
3172 changed downwards */
3173 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
3174 state
->total_param
= IVAL(req
->vwv
+1, 1);
3176 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
3177 state
->total_data
= IVAL(req
->vwv
+3, 1);
3180 pcnt
= IVAL(req
->vwv
+5, 1);
3181 poff
= IVAL(req
->vwv
+7, 1);
3182 pdisp
= IVAL(req
->vwv
+9, 1);
3184 dcnt
= IVAL(req
->vwv
+11, 1);
3185 doff
= IVAL(req
->vwv
+13, 1);
3186 ddisp
= IVAL(req
->vwv
+15, 1);
3188 state
->received_param
+= pcnt
;
3189 state
->received_data
+= dcnt
;
3191 if ((state
->received_data
> state
->total_data
) ||
3192 (state
->received_param
> state
->total_param
))
3196 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
3197 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
3200 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
3204 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
3205 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
3208 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
3211 if ((state
->received_param
< state
->total_param
) ||
3212 (state
->received_data
< state
->total_data
)) {
3213 END_PROFILE(SMBnttranss
);
3217 handle_nttrans(conn
, state
, req
);
3219 DLIST_REMOVE(conn
->pending_trans
, state
);
3220 SAFE_FREE(state
->data
);
3221 SAFE_FREE(state
->param
);
3223 END_PROFILE(SMBnttranss
);
3228 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3229 DLIST_REMOVE(conn
->pending_trans
, state
);
3230 SAFE_FREE(state
->data
);
3231 SAFE_FREE(state
->param
);
3233 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3234 END_PROFILE(SMBnttranss
);