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 static char *nttrans_realloc(char **ptr
, size_t size
)
39 smb_panic("nttrans_realloc() called with NULL ptr");
42 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
46 memset(*ptr
,'\0',size
);
50 /****************************************************************************
51 Send the required number of replies back.
52 We assume all fields other than the data fields are
53 set correctly for the type of call.
54 HACK ! Always assumes smb_setup field is zero.
55 ****************************************************************************/
57 static void send_nt_replies(connection_struct
*conn
,
58 struct smb_request
*req
, NTSTATUS nt_error
,
59 char *params
, int paramsize
,
60 char *pdata
, int datasize
)
62 int data_to_send
= datasize
;
63 int params_to_send
= paramsize
;
67 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
68 int alignment_offset
= 1;
69 int data_alignment_offset
= 0;
70 struct smbXsrv_connection
*xconn
= req
->xconn
;
71 int max_send
= xconn
->smb1
.sessions
.max_send
;
74 * If there genuinely are no parameters or data to send just send
78 if(params_to_send
== 0 && data_to_send
== 0) {
79 reply_smb1_outbuf(req
, 18, 0);
80 if (NT_STATUS_V(nt_error
)) {
81 error_packet_set((char *)req
->outbuf
,
85 show_msg((char *)req
->outbuf
);
86 if (!smb1_srv_send(xconn
,
90 IS_CONN_ENCRYPTED(conn
))) {
91 exit_server_cleanly("send_nt_replies: smb1_srv_send failed.");
93 TALLOC_FREE(req
->outbuf
);
98 * When sending params and data ensure that both are nicely aligned.
99 * Only do this alignment when there is also data to send - else
100 * can cause NT redirector problems.
103 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
104 data_alignment_offset
= 4 - (params_to_send
% 4);
108 * Space is bufsize minus Netbios over TCP header minus SMB header.
109 * The alignment_offset is to align the param bytes on a four byte
110 * boundary (2 bytes for data len, one byte pad).
111 * NT needs this to work correctly.
114 useable_space
= max_send
- (smb_size
117 + data_alignment_offset
);
119 if (useable_space
< 0) {
120 char *msg
= talloc_asprintf(
122 "send_nt_replies failed sanity useable_space = %d!!!",
124 DEBUG(0, ("%s\n", msg
));
125 exit_server_cleanly(msg
);
128 while (params_to_send
|| data_to_send
) {
131 * Calculate whether we will totally or partially fill this packet.
134 total_sent_thistime
= params_to_send
+ data_to_send
;
137 * We can never send more than useable_space.
140 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
142 reply_smb1_outbuf(req
, 18,
143 total_sent_thistime
+ alignment_offset
144 + data_alignment_offset
);
147 * Set total params and data to be sent.
150 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
151 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
154 * Calculate how many parameters and data we can fit into
155 * this packet. Parameters get precedence.
158 params_sent_thistime
= MIN(params_to_send
,useable_space
);
159 data_sent_thistime
= useable_space
- params_sent_thistime
;
160 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
162 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
163 params_sent_thistime
);
165 if(params_sent_thistime
== 0) {
166 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
167 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
170 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
171 * parameter bytes, however the first 4 bytes of outbuf are
172 * the Netbios over TCP header. Thus use smb_base() to subtract
173 * them from the calculation.
176 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
177 ((smb_buf(req
->outbuf
)+alignment_offset
)
178 - smb_base(req
->outbuf
)));
180 * Absolute displacement of param bytes sent in this packet.
183 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
188 * Deal with the data portion.
191 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
193 if(data_sent_thistime
== 0) {
194 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
195 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
198 * The offset of the data bytes is the offset of the
199 * parameter bytes plus the number of parameters being sent this time.
202 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
203 ((smb_buf(req
->outbuf
)+alignment_offset
) -
204 smb_base(req
->outbuf
))
205 + params_sent_thistime
+ data_alignment_offset
);
206 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
210 * Copy the param bytes into the packet.
213 if(params_sent_thistime
) {
214 if (alignment_offset
!= 0) {
215 memset(smb_buf(req
->outbuf
), 0,
218 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
219 params_sent_thistime
);
223 * Copy in the data bytes
226 if(data_sent_thistime
) {
227 if (data_alignment_offset
!= 0) {
228 memset((smb_buf(req
->outbuf
)+alignment_offset
+
229 params_sent_thistime
), 0,
230 data_alignment_offset
);
232 memcpy(smb_buf(req
->outbuf
)+alignment_offset
233 +params_sent_thistime
+data_alignment_offset
,
234 pd
,data_sent_thistime
);
237 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
238 params_sent_thistime
, data_sent_thistime
, useable_space
));
239 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
240 params_to_send
, data_to_send
, paramsize
, datasize
));
242 if (NT_STATUS_V(nt_error
)) {
243 error_packet_set((char *)req
->outbuf
,
248 /* Send the packet */
249 show_msg((char *)req
->outbuf
);
250 if (!smb1_srv_send(xconn
,
254 IS_CONN_ENCRYPTED(conn
))) {
255 exit_server_cleanly("send_nt_replies: smb1_srv_send failed.");
258 TALLOC_FREE(req
->outbuf
);
260 pp
+= params_sent_thistime
;
261 pd
+= data_sent_thistime
;
263 params_to_send
-= params_sent_thistime
;
264 data_to_send
-= data_sent_thistime
;
270 if(params_to_send
< 0 || data_to_send
< 0) {
271 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
272 params_to_send
, data_to_send
));
273 exit_server_cleanly("send_nt_replies: internal error");
278 /****************************************************************************
279 Reply to an NT create and X call on a pipe
280 ****************************************************************************/
282 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
283 struct smb_request
*req
, uint16_t *ppnum
)
288 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
290 /* Strip \\ off the name if present. */
291 while (fname
[0] == '\\') {
295 status
= open_np_file(req
, fname
, &fsp
);
296 if (!NT_STATUS_IS_OK(status
)) {
297 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
298 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
302 reply_nterror(req
, status
);
310 /****************************************************************************
311 Reply to an NT create and X call for pipes.
312 ****************************************************************************/
314 static void do_ntcreate_pipe_open(connection_struct
*conn
,
315 struct smb_request
*req
)
318 uint16_t pnum
= FNUM_FIELD_INVALID
;
320 uint32_t flags
= IVAL(req
->vwv
+3, 1);
321 TALLOC_CTX
*ctx
= talloc_tos();
323 srvstr_pull_req_talloc(ctx
, req
, &fname
, req
->buf
, STR_TERMINATE
);
326 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
330 nt_open_pipe(fname
, conn
, req
, &pnum
);
338 * Deal with pipe return.
341 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
342 /* This is very strange. We
343 * return 50 words, but only set
344 * the wcnt to 42 ? It's definitely
345 * what happens on the wire....
347 reply_smb1_outbuf(req
, 50, 0);
348 SCVAL(req
->outbuf
,smb_wct
,42);
350 reply_smb1_outbuf(req
, 34, 0);
353 SSVAL(req
->outbuf
, smb_vwv0
, 0xff); /* andx chain ends */
354 SSVAL(req
->outbuf
, smb_vwv1
, 0); /* no andx offset */
356 p
= (char *)req
->outbuf
+ smb_vwv2
;
360 SIVAL(p
,0,FILE_WAS_OPENED
);
363 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
366 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
368 SSVAL(p
,2, 0x5FF); /* ? */
371 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
373 SIVAL(p
,0,FILE_GENERIC_ALL
);
375 * For pipes W2K3 seems to return
377 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
379 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
382 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
385 struct case_semantics_state
{
386 connection_struct
*conn
;
389 bool short_case_preserve
;
392 /****************************************************************************
393 Restore case semantics.
394 ****************************************************************************/
396 static int restore_case_semantics(struct case_semantics_state
*state
)
398 state
->conn
->case_sensitive
= state
->case_sensitive
;
399 state
->conn
->case_preserve
= state
->case_preserve
;
400 state
->conn
->short_case_preserve
= state
->short_case_preserve
;
404 /****************************************************************************
406 ****************************************************************************/
408 static struct case_semantics_state
*set_posix_case_semantics(TALLOC_CTX
*mem_ctx
,
409 connection_struct
*conn
)
411 struct case_semantics_state
*result
;
413 if (!(result
= talloc(mem_ctx
, struct case_semantics_state
))) {
418 result
->case_sensitive
= conn
->case_sensitive
;
419 result
->case_preserve
= conn
->case_preserve
;
420 result
->short_case_preserve
= conn
->short_case_preserve
;
423 conn
->case_sensitive
= True
;
424 conn
->case_preserve
= True
;
425 conn
->short_case_preserve
= True
;
427 talloc_set_destructor(result
, restore_case_semantics
);
433 * Calculate the full path name given a relative fid.
435 static NTSTATUS
get_relative_fid_filename(connection_struct
*conn
,
436 struct smb_request
*req
,
437 uint16_t root_dir_fid
,
441 struct files_struct
*dir_fsp
= NULL
;
442 char *new_path
= NULL
;
444 if (root_dir_fid
== 0 || path
== NULL
) {
445 return NT_STATUS_INTERNAL_ERROR
;
448 dir_fsp
= file_fsp(req
, root_dir_fid
);
449 if (dir_fsp
== NULL
) {
450 return NT_STATUS_INVALID_HANDLE
;
453 if (fsp_is_alternate_stream(dir_fsp
)) {
454 return NT_STATUS_INVALID_HANDLE
;
457 if (!dir_fsp
->fsp_flags
.is_directory
) {
459 * Check to see if this is a mac fork of some kind.
461 if (conn
->fs_capabilities
& FILE_NAMED_STREAMS
) {
464 stream
= strchr_m(path
, ':');
465 if (stream
!= NULL
) {
466 return NT_STATUS_OBJECT_PATH_NOT_FOUND
;
471 * We need to handle the case when we get a relative open
472 * relative to a file and the pathname is blank - this is a
473 * reopen! (hint from demyn plantenberg)
475 return NT_STATUS_INVALID_HANDLE
;
478 if (ISDOT(dir_fsp
->fsp_name
->base_name
)) {
480 * We're at the toplevel dir, the final file name
481 * must not contain ./, as this is filtered out
482 * normally by srvstr_get_path and unix_convert
483 * explicitly rejects paths containing ./.
485 new_path
= talloc_strdup(talloc_tos(), path
);
488 * Copy in the base directory name.
491 new_path
= talloc_asprintf(talloc_tos(),
493 dir_fsp
->fsp_name
->base_name
,
496 if (new_path
== NULL
) {
497 return NT_STATUS_NO_MEMORY
;
500 *path_out
= new_path
;
504 /****************************************************************************
505 Reply to an NT create and X call.
506 ****************************************************************************/
508 void reply_ntcreate_and_X(struct smb_request
*req
)
510 connection_struct
*conn
= req
->conn
;
511 struct files_struct
*dirfsp
= NULL
;
512 struct smb_filename
*smb_fname
= NULL
;
515 uint32_t access_mask
;
516 uint32_t file_attributes
;
517 uint32_t share_access
;
518 uint32_t create_disposition
;
519 uint32_t create_options
;
520 uint16_t root_dir_fid
;
521 uint64_t allocation_size
;
522 /* Breakout the oplock request bits so we can set the
523 reply bits separately. */
527 files_struct
*fsp
= NULL
;
529 struct timespec create_timespec
;
530 struct timespec c_timespec
;
531 struct timespec a_timespec
;
532 struct timespec m_timespec
;
535 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
536 struct case_semantics_state
*case_state
= NULL
;
539 TALLOC_CTX
*ctx
= talloc_tos();
541 START_PROFILE(SMBntcreateX
);
544 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
548 flags
= IVAL(req
->vwv
+3, 1);
549 access_mask
= IVAL(req
->vwv
+7, 1);
550 file_attributes
= IVAL(req
->vwv
+13, 1);
551 share_access
= IVAL(req
->vwv
+15, 1);
552 create_disposition
= IVAL(req
->vwv
+17, 1);
553 create_options
= IVAL(req
->vwv
+19, 1);
554 root_dir_fid
= (uint16_t)IVAL(req
->vwv
+5, 1);
556 allocation_size
= BVAL(req
->vwv
+9, 1);
558 srvstr_get_path_req(ctx
, req
, &fname
, (const char *)req
->buf
,
559 STR_TERMINATE
, &status
);
561 if (!NT_STATUS_IS_OK(status
)) {
562 reply_nterror(req
, status
);
566 DBG_DEBUG("flags = 0x%" PRIx32
", access_mask = 0x%" PRIx32
567 ", file_attributes = 0x%" PRIx32
568 ", share_access = 0x%" PRIx32
569 ", create_disposition = 0x%" PRIx32
570 ", create_options = 0x%" PRIx32
", root_dir_fid = 0x%" PRIx32
582 * we need to remove ignored bits when they come directly from the client
583 * because we reuse some of them for internal stuff
585 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
588 * If it's an IPC, use the pipe handler.
592 if (lp_nt_pipe_support()) {
593 do_ntcreate_pipe_open(conn
, req
);
596 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
600 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
601 if (oplock_request
) {
602 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
606 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
607 case_state
= set_posix_case_semantics(ctx
, conn
);
609 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
614 if (root_dir_fid
!= 0) {
615 char *new_fname
= NULL
;
617 status
= get_relative_fid_filename(conn
,
622 if (!NT_STATUS_IS_OK(status
)) {
623 reply_nterror(req
, status
);
629 ucf_flags
= filename_create_ucf_flags(req
,
632 if (ucf_flags
& UCF_GMT_PATHNAME
) {
633 extract_snapshot_token(fname
, &twrp
);
635 status
= smb1_strip_dfs_path(ctx
, &ucf_flags
, &fname
);
636 if (!NT_STATUS_IS_OK(status
)) {
637 reply_nterror(req
, status
);
641 status
= filename_convert_dirfsp(
642 ctx
, conn
, fname
, ucf_flags
, twrp
, &dirfsp
, &smb_fname
);
644 TALLOC_FREE(case_state
);
646 if (!NT_STATUS_IS_OK(status
)) {
647 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
649 NT_STATUS_PATH_NOT_COVERED
,
653 reply_nterror(req
, status
);
658 * Bug #6898 - clients using Windows opens should
659 * never be able to set this attribute into the
662 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
664 status
= SMB_VFS_CREATE_FILE(
668 smb_fname
, /* fname */
669 access_mask
, /* access_mask */
670 share_access
, /* share_access */
671 create_disposition
, /* create_disposition*/
672 create_options
, /* create_options */
673 file_attributes
, /* file_attributes */
674 oplock_request
, /* oplock_request */
676 allocation_size
, /* allocation_size */
677 0, /* private_flags */
682 NULL
, NULL
); /* create context */
684 if (!NT_STATUS_IS_OK(status
)) {
685 if (open_was_deferred(req
->xconn
, req
->mid
)) {
686 /* We have re-scheduled this call, no error. */
689 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
690 bool ok
= defer_smb1_sharing_violation(req
);
695 reply_openerror(req
, status
);
699 /* Ensure we're pointing at the correct stat struct. */
700 smb_fname
= fsp
->fsp_name
;
703 * If the caller set the extended oplock request bit
704 * and we granted one (by whatever means) - set the
705 * correct bit for extended oplock reply.
708 if (oplock_request
&&
709 (lp_fake_oplocks(SNUM(conn
))
710 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
713 * Exclusive oplock granted
716 if (flags
& REQUEST_BATCH_OPLOCK
) {
717 oplock_granted
= BATCH_OPLOCK_RETURN
;
719 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
721 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
722 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
724 oplock_granted
= NO_OPLOCK_RETURN
;
727 file_len
= smb_fname
->st
.st_ex_size
;
729 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
730 /* This is very strange. We
731 * return 50 words, but only set
732 * the wcnt to 42 ? It's definitely
733 * what happens on the wire....
735 reply_smb1_outbuf(req
, 50, 0);
736 SCVAL(req
->outbuf
,smb_wct
,42);
738 reply_smb1_outbuf(req
, 34, 0);
741 SSVAL(req
->outbuf
, smb_vwv0
, 0xff); /* andx chain ends */
742 SSVAL(req
->outbuf
, smb_vwv1
, 0); /* no andx offset */
744 p
= (char *)req
->outbuf
+ smb_vwv2
;
746 SCVAL(p
, 0, oplock_granted
);
749 SSVAL(p
,0,fsp
->fnum
);
751 if ((create_disposition
== FILE_SUPERSEDE
)
752 && (info
== FILE_WAS_OVERWRITTEN
)) {
753 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
759 fattr
= fdos_mode(fsp
);
761 fattr
= FILE_ATTRIBUTE_NORMAL
;
765 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
766 a_timespec
= smb_fname
->st
.st_ex_atime
;
767 m_timespec
= smb_fname
->st
.st_ex_mtime
;
768 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
770 if (lp_dos_filetime_resolution(SNUM(conn
))) {
771 dos_filetime_timespec(&create_timespec
);
772 dos_filetime_timespec(&a_timespec
);
773 dos_filetime_timespec(&m_timespec
);
774 dos_filetime_timespec(&c_timespec
);
777 put_long_date_full_timespec(conn
->ts_res
, p
, &create_timespec
); /* create time. */
779 put_long_date_full_timespec(conn
->ts_res
, p
, &a_timespec
); /* access time */
781 put_long_date_full_timespec(conn
->ts_res
, p
, &m_timespec
); /* write time */
783 put_long_date_full_timespec(conn
->ts_res
, p
, &c_timespec
); /* change time */
785 SIVAL(p
,0,fattr
); /* File Attributes. */
787 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
789 SOFF_T(p
,0,file_len
);
791 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
792 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
793 unsigned int num_streams
= 0;
794 struct stream_struct
*streams
= NULL
;
796 if (lp_ea_support(SNUM(conn
))) {
797 size_t num_names
= 0;
798 /* Do we have any EA's ? */
799 status
= get_ea_names_from_fsp(
800 ctx
, smb_fname
->fsp
, NULL
, &num_names
);
801 if (NT_STATUS_IS_OK(status
) && num_names
) {
802 file_status
&= ~NO_EAS
;
806 status
= vfs_fstreaminfo(smb_fname
->fsp
, ctx
,
807 &num_streams
, &streams
);
808 /* There is always one stream, ::$DATA. */
809 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
810 file_status
&= ~NO_SUBSTREAMS
;
812 TALLOC_FREE(streams
);
813 SSVAL(p
,2,file_status
);
816 SCVAL(p
,0,fsp
->fsp_flags
.is_directory
? 1 : 0);
818 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
821 if (fsp
->fsp_flags
.is_directory
||
822 fsp
->fsp_flags
.can_write
||
823 can_write_to_fsp(fsp
))
825 perms
= FILE_GENERIC_ALL
;
827 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
832 DEBUG(5,("reply_ntcreate_and_X: %s, open name = %s\n",
833 fsp_fnum_dbg(fsp
), smb_fname_str_dbg(smb_fname
)));
836 END_PROFILE(SMBntcreateX
);
840 /****************************************************************************
841 Reply to a NT_TRANSACT_CREATE call to open a pipe.
842 ****************************************************************************/
844 static void do_nt_transact_create_pipe(connection_struct
*conn
,
845 struct smb_request
*req
,
846 uint16_t **ppsetup
, uint32_t setup_count
,
847 char **ppparams
, uint32_t parameter_count
,
848 char **ppdata
, uint32_t data_count
)
851 char *params
= *ppparams
;
852 uint16_t pnum
= FNUM_FIELD_INVALID
;
857 TALLOC_CTX
*ctx
= talloc_tos();
860 * Ensure minimum number of parameters sent.
863 if(parameter_count
< 54) {
864 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
865 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
869 flags
= IVAL(params
,0);
871 if (req
->posix_pathnames
) {
872 srvstr_get_path_posix(ctx
,
890 if (!NT_STATUS_IS_OK(status
)) {
891 reply_nterror(req
, status
);
895 nt_open_pipe(fname
, conn
, req
, &pnum
);
902 /* Realloc the size of parameters and data we will return */
903 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
904 /* Extended response is 32 more byyes. */
909 params
= nttrans_realloc(ppparams
, param_len
);
911 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
916 SCVAL(p
,0,NO_OPLOCK_RETURN
);
921 SIVAL(p
,0,FILE_WAS_OPENED
);
925 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
928 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
930 SSVAL(p
,2, 0x5FF); /* ? */
933 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
935 SIVAL(p
,0,FILE_GENERIC_ALL
);
937 * For pipes W2K3 seems to return
939 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
941 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
944 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
946 /* Send the required number of replies */
947 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
952 /****************************************************************************
953 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
954 ****************************************************************************/
956 static void call_nt_transact_create(connection_struct
*conn
,
957 struct smb_request
*req
,
958 uint16_t **ppsetup
, uint32_t setup_count
,
959 char **ppparams
, uint32_t parameter_count
,
960 char **ppdata
, uint32_t data_count
,
961 uint32_t max_data_count
)
963 struct smb_filename
*smb_fname
= NULL
;
965 char *params
= *ppparams
;
966 char *data
= *ppdata
;
967 /* Breakout the oplock request bits so we can set the reply bits separately. */
971 struct files_struct
*dirfsp
= NULL
;
972 files_struct
*fsp
= NULL
;
975 uint32_t access_mask
;
976 uint32_t file_attributes
;
977 uint32_t share_access
;
978 uint32_t create_disposition
;
979 uint32_t create_options
;
981 struct security_descriptor
*sd
= NULL
;
983 uint16_t root_dir_fid
;
984 struct timespec create_timespec
;
985 struct timespec c_timespec
;
986 struct timespec a_timespec
;
987 struct timespec m_timespec
;
988 struct ea_list
*ea_list
= NULL
;
991 uint64_t allocation_size
;
993 uint8_t oplock_granted
;
994 struct case_semantics_state
*case_state
= NULL
;
997 TALLOC_CTX
*ctx
= talloc_tos();
999 DEBUG(5,("call_nt_transact_create\n"));
1002 * If it's an IPC, use the pipe handler.
1006 if (lp_nt_pipe_support()) {
1007 do_nt_transact_create_pipe(
1009 ppsetup
, setup_count
,
1010 ppparams
, parameter_count
,
1011 ppdata
, data_count
);
1014 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1019 * Ensure minimum number of parameters sent.
1022 if(parameter_count
< 54) {
1023 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1024 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1028 flags
= IVAL(params
,0);
1029 access_mask
= IVAL(params
,8);
1030 file_attributes
= IVAL(params
,20);
1031 share_access
= IVAL(params
,24);
1032 create_disposition
= IVAL(params
,28);
1033 create_options
= IVAL(params
,32);
1034 sd_len
= IVAL(params
,36);
1035 ea_len
= IVAL(params
,40);
1036 root_dir_fid
= (uint16_t)IVAL(params
,4);
1037 allocation_size
= BVAL(params
,12);
1040 * we need to remove ignored bits when they come directly from the client
1041 * because we reuse some of them for internal stuff
1043 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1045 if (req
->posix_pathnames
) {
1046 srvstr_get_path_posix(ctx
,
1055 srvstr_get_path(ctx
,
1064 if (!NT_STATUS_IS_OK(status
)) {
1065 reply_nterror(req
, status
);
1069 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1070 case_state
= set_posix_case_semantics(ctx
, conn
);
1072 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1077 if (root_dir_fid
!= 0) {
1078 char *new_fname
= NULL
;
1080 status
= get_relative_fid_filename(conn
,
1085 if (!NT_STATUS_IS_OK(status
)) {
1086 reply_nterror(req
, status
);
1092 ucf_flags
= filename_create_ucf_flags(req
,
1095 if (ucf_flags
& UCF_GMT_PATHNAME
) {
1096 extract_snapshot_token(fname
, &twrp
);
1098 status
= smb1_strip_dfs_path(ctx
, &ucf_flags
, &fname
);
1099 if (!NT_STATUS_IS_OK(status
)) {
1100 reply_nterror(req
, status
);
1104 status
= filename_convert_dirfsp(ctx
,
1112 TALLOC_FREE(case_state
);
1114 if (!NT_STATUS_IS_OK(status
)) {
1115 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1116 reply_botherror(req
,
1117 NT_STATUS_PATH_NOT_COVERED
,
1118 ERRSRV
, ERRbadpath
);
1121 reply_nterror(req
, status
);
1125 /* Ensure the data_len is correct for the sd and ea values given. */
1126 if ((ea_len
+ sd_len
> data_count
)
1127 || (ea_len
> data_count
) || (sd_len
> data_count
)
1128 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1129 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
1130 "%u, data_count = %u\n", (unsigned int)ea_len
,
1131 (unsigned int)sd_len
, (unsigned int)data_count
));
1132 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1137 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1140 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
1142 if (!NT_STATUS_IS_OK(status
)) {
1143 DEBUG(10, ("call_nt_transact_create: "
1144 "unmarshall_sec_desc failed: %s\n",
1145 nt_errstr(status
)));
1146 reply_nterror(req
, status
);
1152 if (!lp_ea_support(SNUM(conn
))) {
1153 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1154 "EA's not supported.\n",
1155 (unsigned int)ea_len
));
1156 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1161 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1162 "too small (should be more than 10)\n",
1163 (unsigned int)ea_len
));
1164 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1168 /* We have already checked that ea_len <= data_count here. */
1169 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
1171 if (ea_list
== NULL
) {
1172 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1176 if (!req
->posix_pathnames
&&
1177 ea_list_has_invalid_name(ea_list
)) {
1178 /* Realloc the size of parameters and data we will return */
1179 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1180 /* Extended response is 32 more bytes. */
1185 params
= nttrans_realloc(ppparams
, param_len
);
1186 if(params
== NULL
) {
1187 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1191 memset(params
, '\0', param_len
);
1192 send_nt_replies(conn
, req
, STATUS_INVALID_EA_NAME
,
1193 params
, param_len
, NULL
, 0);
1198 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1199 if (oplock_request
) {
1200 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1205 * Bug #6898 - clients using Windows opens should
1206 * never be able to set this attribute into the
1209 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1211 status
= SMB_VFS_CREATE_FILE(
1214 dirfsp
, /* dirfsp */
1215 smb_fname
, /* fname */
1216 access_mask
, /* access_mask */
1217 share_access
, /* share_access */
1218 create_disposition
, /* create_disposition*/
1219 create_options
, /* create_options */
1220 file_attributes
, /* file_attributes */
1221 oplock_request
, /* oplock_request */
1223 allocation_size
, /* allocation_size */
1224 0, /* private_flags */
1226 ea_list
, /* ea_list */
1229 NULL
, NULL
); /* create context */
1231 if(!NT_STATUS_IS_OK(status
)) {
1232 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1233 /* We have re-scheduled this call, no error. */
1236 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
1237 bool ok
= defer_smb1_sharing_violation(req
);
1242 reply_openerror(req
, status
);
1246 /* Ensure we're pointing at the correct stat struct. */
1247 TALLOC_FREE(smb_fname
);
1248 smb_fname
= fsp
->fsp_name
;
1251 * If the caller set the extended oplock request bit
1252 * and we granted one (by whatever means) - set the
1253 * correct bit for extended oplock reply.
1256 if (oplock_request
&&
1257 (lp_fake_oplocks(SNUM(conn
))
1258 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1261 * Exclusive oplock granted
1264 if (flags
& REQUEST_BATCH_OPLOCK
) {
1265 oplock_granted
= BATCH_OPLOCK_RETURN
;
1267 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1269 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1270 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1272 oplock_granted
= NO_OPLOCK_RETURN
;
1275 file_len
= smb_fname
->st
.st_ex_size
;
1277 /* Realloc the size of parameters and data we will return */
1278 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1279 /* Extended response is 32 more byyes. */
1284 params
= nttrans_realloc(ppparams
, param_len
);
1285 if(params
== NULL
) {
1286 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1291 SCVAL(p
, 0, oplock_granted
);
1294 SSVAL(p
,0,fsp
->fnum
);
1296 if ((create_disposition
== FILE_SUPERSEDE
)
1297 && (info
== FILE_WAS_OVERWRITTEN
)) {
1298 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1304 fattr
= fdos_mode(fsp
);
1306 fattr
= FILE_ATTRIBUTE_NORMAL
;
1310 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1311 a_timespec
= smb_fname
->st
.st_ex_atime
;
1312 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1313 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1315 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1316 dos_filetime_timespec(&create_timespec
);
1317 dos_filetime_timespec(&a_timespec
);
1318 dos_filetime_timespec(&m_timespec
);
1319 dos_filetime_timespec(&c_timespec
);
1322 put_long_date_full_timespec(conn
->ts_res
, p
, &create_timespec
); /* create time. */
1324 put_long_date_full_timespec(conn
->ts_res
, p
, &a_timespec
); /* access time */
1326 put_long_date_full_timespec(conn
->ts_res
, p
, &m_timespec
); /* write time */
1328 put_long_date_full_timespec(conn
->ts_res
, p
, &c_timespec
); /* change time */
1330 SIVAL(p
,0,fattr
); /* File Attributes. */
1332 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1334 SOFF_T(p
,0,file_len
);
1336 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1337 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
1338 unsigned int num_streams
= 0;
1339 struct stream_struct
*streams
= NULL
;
1341 if (lp_ea_support(SNUM(conn
))) {
1342 size_t num_names
= 0;
1343 /* Do we have any EA's ? */
1344 status
= get_ea_names_from_fsp(
1345 ctx
, smb_fname
->fsp
, NULL
, &num_names
);
1346 if (NT_STATUS_IS_OK(status
) && num_names
) {
1347 file_status
&= ~NO_EAS
;
1351 status
= vfs_fstreaminfo(smb_fname
->fsp
, ctx
,
1352 &num_streams
, &streams
);
1353 /* There is always one stream, ::$DATA. */
1354 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
1355 file_status
&= ~NO_SUBSTREAMS
;
1357 TALLOC_FREE(streams
);
1358 SSVAL(p
,2,file_status
);
1361 SCVAL(p
,0,fsp
->fsp_flags
.is_directory
? 1 : 0);
1363 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1366 if (fsp
->fsp_flags
.is_directory
||
1367 fsp
->fsp_flags
.can_write
||
1368 can_write_to_fsp(fsp
))
1370 perms
= FILE_GENERIC_ALL
;
1372 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1377 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1378 smb_fname_str_dbg(smb_fname
)));
1380 /* Send the required number of replies */
1381 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1386 /****************************************************************************
1387 Reply to a NT CANCEL request.
1388 conn POINTER CAN BE NULL HERE !
1389 ****************************************************************************/
1391 void reply_ntcancel(struct smb_request
*req
)
1393 struct smbXsrv_connection
*xconn
= req
->xconn
;
1394 struct smbd_server_connection
*sconn
= req
->sconn
;
1398 * Go through and cancel any pending change notifies.
1401 START_PROFILE(SMBntcancel
);
1402 smb1_srv_cancel_sign_response(xconn
);
1403 found
= remove_pending_change_notify_requests_by_mid(sconn
, req
->mid
);
1405 smbd_smb1_brl_finish_by_mid(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 /****************************************************************************
1416 Reply to a NT rename request.
1417 ****************************************************************************/
1419 void reply_ntrename(struct smb_request
*req
)
1421 connection_struct
*conn
= req
->conn
;
1422 struct files_struct
*src_dirfsp
= NULL
;
1423 struct smb_filename
*smb_fname_old
= NULL
;
1424 struct files_struct
*dst_dirfsp
= NULL
;
1425 struct smb_filename
*smb_fname_new
= NULL
;
1426 char *oldname
= NULL
;
1427 char *newname
= NULL
;
1428 const char *dst_original_lcomp
= NULL
;
1432 uint32_t ucf_flags_src
= ucf_flags_from_smb_request(req
);
1433 NTTIME src_twrp
= 0;
1434 uint32_t ucf_flags_dst
= ucf_flags_from_smb_request(req
);
1435 NTTIME dst_twrp
= 0;
1436 uint16_t rename_type
;
1437 TALLOC_CTX
*ctx
= talloc_tos();
1438 bool stream_rename
= false;
1440 START_PROFILE(SMBntrename
);
1443 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1447 attrs
= SVAL(req
->vwv
+0, 0);
1448 rename_type
= SVAL(req
->vwv
+1, 0);
1450 p
= (const char *)req
->buf
+ 1;
1451 p
+= srvstr_get_path_req(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1453 if (!NT_STATUS_IS_OK(status
)) {
1454 reply_nterror(req
, status
);
1458 if (!req
->posix_pathnames
&& ms_has_wild(oldname
)) {
1459 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1464 p
+= srvstr_get_path_req(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1466 if (!NT_STATUS_IS_OK(status
)) {
1467 reply_nterror(req
, status
);
1471 if (!req
->posix_pathnames
&& ms_has_wild(newname
)) {
1472 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1476 if (!req
->posix_pathnames
) {
1477 /* The newname must begin with a ':' if the
1478 oldname contains a ':'. */
1479 if (strchr_m(oldname
, ':')) {
1480 if (newname
[0] != ':') {
1481 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1484 stream_rename
= true;
1488 if (ucf_flags_src
& UCF_GMT_PATHNAME
) {
1489 extract_snapshot_token(oldname
, &src_twrp
);
1491 status
= smb1_strip_dfs_path(ctx
, &ucf_flags_src
, &oldname
);
1492 if (!NT_STATUS_IS_OK(status
)) {
1493 reply_nterror(req
, status
);
1497 status
= filename_convert_dirfsp(ctx
,
1504 if (!NT_STATUS_IS_OK(status
)) {
1505 if (NT_STATUS_EQUAL(status
,
1506 NT_STATUS_PATH_NOT_COVERED
)) {
1507 reply_botherror(req
,
1508 NT_STATUS_PATH_NOT_COVERED
,
1509 ERRSRV
, ERRbadpath
);
1512 reply_nterror(req
, status
);
1516 if (stream_rename
) {
1518 * No point in calling filename_convert()
1519 * on a raw stream name. It can never find
1520 * the file anyway. Use the same logic as
1521 * SMB2_FILE_RENAME_INFORMATION_INTERNAL
1522 * and generate smb_fname_new directly.
1524 smb_fname_new
= synthetic_smb_fname(talloc_tos(),
1525 smb_fname_old
->base_name
,
1528 smb_fname_old
->twrp
,
1529 smb_fname_old
->flags
);
1530 if (smb_fname_new
== NULL
) {
1531 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1535 if (ucf_flags_dst
& UCF_GMT_PATHNAME
) {
1536 extract_snapshot_token(newname
,
1539 status
= smb1_strip_dfs_path(ctx
, &ucf_flags_dst
, &newname
);
1540 if (!NT_STATUS_IS_OK(status
)) {
1541 reply_nterror(req
, status
);
1544 status
= filename_convert_dirfsp(ctx
,
1551 if (!NT_STATUS_IS_OK(status
)) {
1552 if (NT_STATUS_EQUAL(status
,
1553 NT_STATUS_PATH_NOT_COVERED
)) {
1554 reply_botherror(req
,
1555 NT_STATUS_PATH_NOT_COVERED
,
1556 ERRSRV
, ERRbadpath
);
1559 reply_nterror(req
, status
);
1564 /* Get the last component of the destination for rename_internals(). */
1565 dst_original_lcomp
= get_original_lcomp(ctx
,
1569 if (dst_original_lcomp
== NULL
) {
1570 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1575 DEBUG(3,("reply_ntrename: %s -> %s\n",
1576 smb_fname_str_dbg(smb_fname_old
),
1577 smb_fname_str_dbg(smb_fname_new
)));
1579 switch(rename_type
) {
1580 case RENAME_FLAG_RENAME
:
1581 status
= rename_internals(ctx
,
1592 case RENAME_FLAG_HARD_LINK
:
1593 status
= hardlink_internals(ctx
,
1600 case RENAME_FLAG_COPY
:
1601 status
= copy_internals(ctx
,
1610 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1611 status
= NT_STATUS_INVALID_PARAMETER
;
1614 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1618 if (!NT_STATUS_IS_OK(status
)) {
1619 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1620 /* We have re-scheduled this call. */
1623 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
1624 bool ok
= defer_smb1_sharing_violation(req
);
1630 reply_nterror(req
, status
);
1634 reply_smb1_outbuf(req
, 0, 0);
1636 END_PROFILE(SMBntrename
);
1640 /****************************************************************************
1641 Reply to a notify change - queue the request and
1642 don't allow a directory to be opened.
1643 ****************************************************************************/
1645 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1646 NTSTATUS error_code
,
1647 uint8_t *buf
, size_t len
)
1649 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1652 static void call_nt_transact_notify_change(connection_struct
*conn
,
1653 struct smb_request
*req
,
1655 uint32_t setup_count
,
1657 uint32_t parameter_count
,
1658 char **ppdata
, uint32_t data_count
,
1659 uint32_t max_data_count
,
1660 uint32_t max_param_count
)
1662 uint16_t *setup
= *ppsetup
;
1668 if(setup_count
< 6) {
1669 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1673 fsp
= file_fsp(req
, SVAL(setup
,4));
1674 filter
= IVAL(setup
, 0);
1675 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1677 DEBUG(3,("call_nt_transact_notify_change\n"));
1680 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1684 DBG_NOTICE("notify change called on %s, filter = %s, recursive = %d\n",
1686 notify_filter_string(talloc_tos(), filter
),
1689 if((!fsp
->fsp_flags
.is_directory
) || (conn
!= fsp
->conn
)) {
1690 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1694 if (fsp
->notify
== NULL
) {
1696 status
= change_notify_create(fsp
,
1700 if (!NT_STATUS_IS_OK(status
)) {
1701 DEBUG(10, ("change_notify_create returned %s\n",
1702 nt_errstr(status
)));
1703 reply_nterror(req
, status
);
1708 if (change_notify_fsp_has_changes(fsp
)) {
1711 * We've got changes pending, respond immediately
1715 * TODO: write a torture test to check the filtering behaviour
1719 change_notify_reply(req
,
1723 smbd_smb1_notify_reply
);
1726 * change_notify_reply() above has independently sent its
1733 * No changes pending, queue the request
1736 status
= change_notify_add_request(req
,
1740 smbd_smb1_notify_reply
);
1741 if (!NT_STATUS_IS_OK(status
)) {
1742 reply_nterror(req
, status
);
1747 /****************************************************************************
1748 Reply to an NT transact rename command.
1749 ****************************************************************************/
1751 static void call_nt_transact_rename(connection_struct
*conn
,
1752 struct smb_request
*req
,
1753 uint16_t **ppsetup
, uint32_t setup_count
,
1754 char **ppparams
, uint32_t parameter_count
,
1755 char **ppdata
, uint32_t data_count
,
1756 uint32_t max_data_count
)
1758 char *params
= *ppparams
;
1759 char *new_name
= NULL
;
1760 files_struct
*fsp
= NULL
;
1762 TALLOC_CTX
*ctx
= talloc_tos();
1764 if(parameter_count
< 5) {
1765 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1769 fsp
= file_fsp(req
, SVAL(params
, 0));
1770 if (!check_fsp(conn
, req
, fsp
)) {
1773 if (req
->posix_pathnames
) {
1774 srvstr_get_path_posix(ctx
,
1779 parameter_count
- 4,
1783 srvstr_get_path(ctx
,
1788 parameter_count
- 4,
1793 if (!NT_STATUS_IS_OK(status
)) {
1794 reply_nterror(req
, status
);
1799 * W2K3 ignores this request as the RAW-RENAME test
1800 * demonstrates, so we do.
1802 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1804 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1805 fsp_str_dbg(fsp
), new_name
));
1810 /****************************************************************************
1811 SMB1 reply to query a security descriptor.
1812 ****************************************************************************/
1814 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1815 struct smb_request
*req
,
1817 uint32_t setup_count
,
1819 uint32_t parameter_count
,
1821 uint32_t data_count
,
1822 uint32_t max_data_count
)
1824 char *params
= *ppparams
;
1825 char *data
= *ppdata
;
1827 uint32_t security_info_wanted
;
1828 files_struct
*fsp
= NULL
;
1830 uint8_t *marshalled_sd
= NULL
;
1832 if(parameter_count
< 8) {
1833 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1837 fsp
= file_fsp(req
, SVAL(params
,0));
1839 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1843 security_info_wanted
= IVAL(params
,4);
1845 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1846 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
1847 (unsigned int)security_info_wanted
));
1849 params
= nttrans_realloc(ppparams
, 4);
1850 if(params
== NULL
) {
1851 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1856 * Get the permissions to return.
1859 status
= smbd_do_query_security_desc(conn
,
1862 security_info_wanted
&
1863 SMB_SUPPORTED_SECINFO_FLAGS
,
1868 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
1869 SIVAL(params
,0,(uint32_t)sd_size
);
1870 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1871 params
, 4, NULL
, 0);
1875 if (!NT_STATUS_IS_OK(status
)) {
1876 reply_nterror(req
, status
);
1880 SMB_ASSERT(sd_size
> 0);
1882 SIVAL(params
,0,(uint32_t)sd_size
);
1884 if (max_data_count
< sd_size
) {
1885 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1886 params
, 4, NULL
, 0);
1891 * Allocate the data we will return.
1894 data
= nttrans_realloc(ppdata
, sd_size
);
1896 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1900 memcpy(data
, marshalled_sd
, sd_size
);
1902 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1907 /****************************************************************************
1908 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1909 ****************************************************************************/
1911 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1912 struct smb_request
*req
,
1914 uint32_t setup_count
,
1916 uint32_t parameter_count
,
1918 uint32_t data_count
,
1919 uint32_t max_data_count
)
1921 char *params
= *ppparams
;
1922 char *data
= *ppdata
;
1923 files_struct
*fsp
= NULL
;
1924 uint32_t security_info_sent
= 0;
1927 if(parameter_count
< 8) {
1928 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1932 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1933 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1937 if (!CAN_WRITE(fsp
->conn
)) {
1938 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1942 if(!lp_nt_acl_support(SNUM(conn
))) {
1946 security_info_sent
= IVAL(params
,4);
1948 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1949 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
1951 if (data_count
== 0) {
1952 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1956 status
= set_sd_blob(fsp
, (uint8_t *)data
, data_count
,
1957 security_info_sent
& SMB_SUPPORTED_SECINFO_FLAGS
);
1958 if (!NT_STATUS_IS_OK(status
)) {
1959 reply_nterror(req
, status
);
1964 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1968 /****************************************************************************
1970 ****************************************************************************/
1972 static void call_nt_transact_ioctl(connection_struct
*conn
,
1973 struct smb_request
*req
,
1974 uint16_t **ppsetup
, uint32_t setup_count
,
1975 char **ppparams
, uint32_t parameter_count
,
1976 char **ppdata
, uint32_t data_count
,
1977 uint32_t max_data_count
)
1985 char *out_data
= NULL
;
1986 uint32_t out_data_len
= 0;
1987 char *pdata
= *ppdata
;
1988 TALLOC_CTX
*ctx
= talloc_tos();
1990 if (setup_count
!= 8) {
1991 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1992 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1996 function
= IVAL(*ppsetup
, 0);
1997 fidnum
= SVAL(*ppsetup
, 4);
1998 isFSctl
= CVAL(*ppsetup
, 6);
1999 compfilter
= CVAL(*ppsetup
, 7);
2001 DEBUG(10, ("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2002 function
, fidnum
, isFSctl
, compfilter
));
2004 fsp
=file_fsp(req
, fidnum
);
2007 * We don't really implement IOCTLs, especially on files.
2010 DEBUG(10, ("isFSctl: 0x%02X indicates IOCTL, not FSCTL!\n",
2012 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2016 /* Has to be for an open file! */
2017 if (!check_fsp_open(conn
, req
, fsp
)) {
2022 * out_data might be allocated by the VFS module, but talloc should be
2023 * used, and should be cleaned up when the request ends.
2025 status
= SMB_VFS_FSCTL(fsp
,
2031 (uint8_t **)&out_data
,
2034 if (!NT_STATUS_IS_OK(status
)) {
2035 reply_nterror(req
, status
);
2037 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, out_data
, out_data_len
);
2042 #ifdef HAVE_SYS_QUOTAS
2043 /****************************************************************************
2044 Reply to get user quota
2045 ****************************************************************************/
2047 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2048 struct smb_request
*req
,
2050 uint32_t setup_count
,
2052 uint32_t parameter_count
,
2054 uint32_t data_count
,
2055 uint32_t max_data_count
)
2057 const struct loadparm_substitution
*lp_sub
=
2058 loadparm_s3_global_substitution();
2059 NTSTATUS nt_status
= NT_STATUS_OK
;
2060 char *params
= *ppparams
;
2061 char *pdata
= *ppdata
;
2064 files_struct
*fsp
= NULL
;
2065 DATA_BLOB blob
= data_blob_null
;
2066 struct nttrans_query_quota_params info
= {0};
2067 enum ndr_err_code err
;
2068 TALLOC_CTX
*tmp_ctx
= NULL
;
2069 uint32_t resp_len
= 0;
2070 uint8_t *resp_data
= 0;
2072 tmp_ctx
= talloc_init("ntquota_list");
2074 nt_status
= NT_STATUS_NO_MEMORY
;
2079 if (get_current_uid(conn
) != sec_initial_uid()) {
2080 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2081 "[%s]\n", lp_servicename(talloc_tos(), lp_sub
, SNUM(conn
)),
2082 conn
->session_info
->unix_info
->unix_name
));
2083 nt_status
= NT_STATUS_ACCESS_DENIED
;
2087 blob
.data
= (uint8_t*)params
;
2088 blob
.length
= parameter_count
;
2090 err
= ndr_pull_struct_blob(&blob
, tmp_ctx
, &info
,
2091 (ndr_pull_flags_fn_t
)ndr_pull_nttrans_query_quota_params
);
2093 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2094 DEBUG(0,("TRANSACT_GET_USER_QUOTA: failed to pull "
2095 "query_quota_params.\n"));
2096 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2099 DBG_DEBUG("info.return_single_entry = %u, info.restart_scan = %u, "
2100 "info.sid_list_length = %u, info.start_sid_length = %u, "
2101 "info.start_sid_offset = %u\n",
2102 (unsigned int)info
.return_single_entry
,
2103 (unsigned int)info
.restart_scan
,
2104 (unsigned int)info
.sid_list_length
,
2105 (unsigned int)info
.start_sid_length
,
2106 (unsigned int)info
.start_sid_offset
);
2108 /* set blob to point at data for further parsing */
2109 blob
.data
= (uint8_t*)pdata
;
2110 blob
.length
= data_count
;
2112 * Although MS-SMB ref is ambiguous here, a microsoft client will
2113 * only ever send a start sid (as part of a list) with
2114 * sid_list_length & start_sid_offset both set to the actual list
2115 * length. Note: Only a single result is returned in this case
2116 * In the case where either start_sid_offset or start_sid_length
2117 * are set alone or if both set (but have different values) then
2118 * it seems windows will return a number of entries from the start
2119 * of the list of users with quotas set. This behaviour is undocumented
2120 * and windows clients do not send messages of that type. As such we
2121 * currently will reject these requests.
2123 if (info
.start_sid_length
2124 || (info
.sid_list_length
!= info
.start_sid_offset
)) {
2125 DBG_ERR("TRANSACT_GET_USER_QUOTA: unsupported single or "
2126 "compound sid format\n");
2127 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2131 /* maybe we can check the quota_fnum */
2132 fsp
= file_fsp(req
, info
.fid
);
2133 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2134 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2135 nt_status
= NT_STATUS_INVALID_HANDLE
;
2138 nt_status
= smbd_do_query_getinfo_quota(tmp_ctx
,
2141 info
.return_single_entry
,
2142 info
.sid_list_length
,
2147 if (!NT_STATUS_IS_OK(nt_status
)) {
2148 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2151 nt_status
= NT_STATUS_OK
;
2155 params
= nttrans_realloc(ppparams
, param_len
);
2156 if(params
== NULL
) {
2157 nt_status
= NT_STATUS_NO_MEMORY
;
2161 data_len
= resp_len
;
2162 SIVAL(params
, 0, data_len
);
2163 pdata
= nttrans_realloc(ppdata
, data_len
);
2164 memcpy(pdata
, resp_data
, data_len
);
2166 TALLOC_FREE(tmp_ctx
);
2167 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2171 TALLOC_FREE(tmp_ctx
);
2172 reply_nterror(req
, nt_status
);
2175 /****************************************************************************
2176 Reply to set user quota
2177 ****************************************************************************/
2179 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2180 struct smb_request
*req
,
2182 uint32_t setup_count
,
2184 uint32_t parameter_count
,
2186 uint32_t data_count
,
2187 uint32_t max_data_count
)
2189 const struct loadparm_substitution
*lp_sub
=
2190 loadparm_s3_global_substitution();
2191 char *params
= *ppparams
;
2192 char *pdata
= *ppdata
;
2193 int data_len
=0,param_len
=0;
2194 SMB_NTQUOTA_STRUCT qt
;
2195 struct file_quota_information info
= {0};
2196 enum ndr_err_code err
;
2199 files_struct
*fsp
= NULL
;
2200 TALLOC_CTX
*ctx
= NULL
;
2201 NTSTATUS status
= NT_STATUS_OK
;
2205 if (get_current_uid(conn
) != sec_initial_uid()) {
2206 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2207 "[%s]\n", lp_servicename(talloc_tos(), lp_sub
, SNUM(conn
)),
2208 conn
->session_info
->unix_info
->unix_name
));
2209 status
= NT_STATUS_ACCESS_DENIED
;
2214 * Ensure minimum number of parameters sent.
2217 if (parameter_count
< 2) {
2218 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2219 status
= NT_STATUS_INVALID_PARAMETER
;
2223 /* maybe we can check the quota_fnum */
2224 fsp
= file_fsp(req
, SVAL(params
,0));
2225 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2226 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2227 status
= NT_STATUS_INVALID_HANDLE
;
2231 ctx
= talloc_init("set_user_quota");
2233 status
= NT_STATUS_NO_MEMORY
;
2236 inblob
.data
= (uint8_t*)pdata
;
2237 inblob
.length
= data_count
;
2239 err
= ndr_pull_struct_blob(
2243 (ndr_pull_flags_fn_t
)ndr_pull_file_quota_information
);
2245 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2246 DEBUG(0,("TRANSACT_SET_USER_QUOTA: failed to pull "
2247 "file_quota_information\n"));
2248 status
= NT_STATUS_INVALID_PARAMETER
;
2251 qt
.usedspace
= info
.quota_used
;
2253 qt
.softlim
= info
.quota_threshold
;
2255 qt
.hardlim
= info
.quota_limit
;
2259 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2260 status
= NT_STATUS_INTERNAL_ERROR
;
2264 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2270 reply_nterror(req
, status
);
2272 #endif /* HAVE_SYS_QUOTAS */
2274 static void handle_nttrans(connection_struct
*conn
,
2275 struct trans_state
*state
,
2276 struct smb_request
*req
)
2278 struct smbXsrv_connection
*xconn
= req
->xconn
;
2280 if (xconn
->protocol
>= PROTOCOL_NT1
) {
2281 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2282 SSVAL(discard_const_p(uint8_t, req
->inbuf
),smb_flg2
,req
->flags2
);
2286 /* Now we must call the relevant NT_TRANS function */
2287 switch(state
->call
) {
2288 case NT_TRANSACT_CREATE
:
2290 START_PROFILE(NT_transact_create
);
2291 call_nt_transact_create(
2293 &state
->setup
, state
->setup_count
,
2294 &state
->param
, state
->total_param
,
2295 &state
->data
, state
->total_data
,
2296 state
->max_data_return
);
2297 END_PROFILE(NT_transact_create
);
2301 case NT_TRANSACT_IOCTL
:
2303 START_PROFILE(NT_transact_ioctl
);
2304 call_nt_transact_ioctl(
2306 &state
->setup
, state
->setup_count
,
2307 &state
->param
, state
->total_param
,
2308 &state
->data
, state
->total_data
,
2309 state
->max_data_return
);
2310 END_PROFILE(NT_transact_ioctl
);
2314 case NT_TRANSACT_SET_SECURITY_DESC
:
2316 START_PROFILE(NT_transact_set_security_desc
);
2317 call_nt_transact_set_security_desc(
2319 &state
->setup
, state
->setup_count
,
2320 &state
->param
, state
->total_param
,
2321 &state
->data
, state
->total_data
,
2322 state
->max_data_return
);
2323 END_PROFILE(NT_transact_set_security_desc
);
2327 case NT_TRANSACT_NOTIFY_CHANGE
:
2329 START_PROFILE(NT_transact_notify_change
);
2330 call_nt_transact_notify_change(
2332 &state
->setup
, state
->setup_count
,
2333 &state
->param
, state
->total_param
,
2334 &state
->data
, state
->total_data
,
2335 state
->max_data_return
,
2336 state
->max_param_return
);
2337 END_PROFILE(NT_transact_notify_change
);
2341 case NT_TRANSACT_RENAME
:
2343 START_PROFILE(NT_transact_rename
);
2344 call_nt_transact_rename(
2346 &state
->setup
, state
->setup_count
,
2347 &state
->param
, state
->total_param
,
2348 &state
->data
, state
->total_data
,
2349 state
->max_data_return
);
2350 END_PROFILE(NT_transact_rename
);
2354 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2356 START_PROFILE(NT_transact_query_security_desc
);
2357 call_nt_transact_query_security_desc(
2359 &state
->setup
, state
->setup_count
,
2360 &state
->param
, state
->total_param
,
2361 &state
->data
, state
->total_data
,
2362 state
->max_data_return
);
2363 END_PROFILE(NT_transact_query_security_desc
);
2367 #ifdef HAVE_SYS_QUOTAS
2368 case NT_TRANSACT_GET_USER_QUOTA
:
2370 START_PROFILE(NT_transact_get_user_quota
);
2371 call_nt_transact_get_user_quota(
2373 &state
->setup
, state
->setup_count
,
2374 &state
->param
, state
->total_param
,
2375 &state
->data
, state
->total_data
,
2376 state
->max_data_return
);
2377 END_PROFILE(NT_transact_get_user_quota
);
2381 case NT_TRANSACT_SET_USER_QUOTA
:
2383 START_PROFILE(NT_transact_set_user_quota
);
2384 call_nt_transact_set_user_quota(
2386 &state
->setup
, state
->setup_count
,
2387 &state
->param
, state
->total_param
,
2388 &state
->data
, state
->total_data
,
2389 state
->max_data_return
);
2390 END_PROFILE(NT_transact_set_user_quota
);
2393 #endif /* HAVE_SYS_QUOTAS */
2396 /* Error in request */
2397 DEBUG(0,("handle_nttrans: Unknown request %d in "
2398 "nttrans call\n", state
->call
));
2399 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2405 /****************************************************************************
2406 Reply to a SMBNTtrans.
2407 ****************************************************************************/
2409 void reply_nttrans(struct smb_request
*req
)
2411 connection_struct
*conn
= req
->conn
;
2416 uint16_t function_code
;
2418 struct trans_state
*state
;
2420 START_PROFILE(SMBnttrans
);
2422 if (req
->wct
< 19) {
2423 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2424 END_PROFILE(SMBnttrans
);
2428 pscnt
= IVAL(req
->vwv
+9, 1);
2429 psoff
= IVAL(req
->vwv
+11, 1);
2430 dscnt
= IVAL(req
->vwv
+13, 1);
2431 dsoff
= IVAL(req
->vwv
+15, 1);
2432 function_code
= SVAL(req
->vwv
+18, 0);
2434 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2435 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2436 END_PROFILE(SMBnttrans
);
2440 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2441 if (!NT_STATUS_IS_OK(result
)) {
2442 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2443 reply_nterror(req
, result
);
2444 END_PROFILE(SMBnttrans
);
2448 if ((state
= talloc(conn
, struct trans_state
)) == NULL
) {
2449 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2450 END_PROFILE(SMBnttrans
);
2454 state
->cmd
= SMBnttrans
;
2456 state
->mid
= req
->mid
;
2457 state
->vuid
= req
->vuid
;
2458 state
->total_data
= IVAL(req
->vwv
+3, 1);
2460 state
->total_param
= IVAL(req
->vwv
+1, 1);
2461 state
->param
= NULL
;
2462 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2463 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2465 /* setup count is in *words* */
2466 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2467 state
->setup
= NULL
;
2468 state
->call
= function_code
;
2470 DEBUG(10, ("num_setup=%u, "
2471 "param_total=%u, this_param=%u, max_param=%u, "
2472 "data_total=%u, this_data=%u, max_data=%u, "
2473 "param_offset=%u, data_offset=%u\n",
2474 (unsigned)state
->setup_count
,
2475 (unsigned)state
->total_param
, (unsigned)pscnt
,
2476 (unsigned)state
->max_param_return
,
2477 (unsigned)state
->total_data
, (unsigned)dscnt
,
2478 (unsigned)state
->max_data_return
,
2479 (unsigned)psoff
, (unsigned)dsoff
));
2482 * All nttrans messages we handle have smb_wct == 19 +
2483 * state->setup_count. Ensure this is so as a sanity check.
2486 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2487 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2488 req
->wct
, 19 + (state
->setup_count
/2)));
2492 /* Don't allow more than 128mb for each value. */
2493 if ((state
->total_data
> (1024*1024*128)) ||
2494 (state
->total_param
> (1024*1024*128))) {
2495 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2496 END_PROFILE(SMBnttrans
);
2500 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2503 if (state
->total_data
) {
2505 if (smb_buffer_oob(state
->total_data
, 0, dscnt
)
2506 || smb_buffer_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
2510 /* Can't use talloc here, the core routines do realloc on the
2511 * params and data. */
2512 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2513 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2514 "bytes !\n", (unsigned int)state
->total_data
));
2516 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2517 END_PROFILE(SMBnttrans
);
2521 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2524 if (state
->total_param
) {
2526 if (smb_buffer_oob(state
->total_param
, 0, pscnt
)
2527 || smb_buffer_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
2531 /* Can't use talloc here, the core routines do realloc on the
2532 * params and data. */
2533 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2534 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2535 "bytes !\n", (unsigned int)state
->total_param
));
2536 SAFE_FREE(state
->data
);
2538 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2539 END_PROFILE(SMBnttrans
);
2543 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2546 state
->received_data
= dscnt
;
2547 state
->received_param
= pscnt
;
2549 if(state
->setup_count
> 0) {
2550 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2551 state
->setup_count
));
2554 * No overflow possible here, state->setup_count is an
2555 * unsigned int, being filled by a single byte from
2556 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2557 * below is not necessary, it's here to clarify things. The
2558 * validity of req->vwv and req->wct has been checked in
2559 * init_smb1_request already.
2561 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
2565 state
->setup
= (uint16_t *)TALLOC(state
, state
->setup_count
);
2566 if (state
->setup
== NULL
) {
2567 DEBUG(0,("reply_nttrans : Out of memory\n"));
2568 SAFE_FREE(state
->data
);
2569 SAFE_FREE(state
->param
);
2571 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2572 END_PROFILE(SMBnttrans
);
2576 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
2577 dump_data(10, (uint8_t *)state
->setup
, state
->setup_count
);
2580 if ((state
->received_data
== state
->total_data
) &&
2581 (state
->received_param
== state
->total_param
)) {
2582 handle_nttrans(conn
, state
, req
);
2583 SAFE_FREE(state
->param
);
2584 SAFE_FREE(state
->data
);
2586 END_PROFILE(SMBnttrans
);
2590 DLIST_ADD(conn
->pending_trans
, state
);
2592 /* We need to send an interim response then receive the rest
2593 of the parameter/data bytes */
2594 reply_smb1_outbuf(req
, 0, 0);
2595 show_msg((char *)req
->outbuf
);
2596 END_PROFILE(SMBnttrans
);
2601 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2602 SAFE_FREE(state
->data
);
2603 SAFE_FREE(state
->param
);
2605 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2606 END_PROFILE(SMBnttrans
);
2610 /****************************************************************************
2611 Reply to a SMBnttranss
2612 ****************************************************************************/
2614 void reply_nttranss(struct smb_request
*req
)
2616 connection_struct
*conn
= req
->conn
;
2617 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2618 struct trans_state
*state
;
2620 START_PROFILE(SMBnttranss
);
2622 show_msg((const char *)req
->inbuf
);
2624 /* Windows clients expect all replies to
2625 an NT transact secondary (SMBnttranss 0xA1)
2626 to have a command code of NT transact
2627 (SMBnttrans 0xA0). See bug #8989 for details. */
2628 req
->cmd
= SMBnttrans
;
2630 if (req
->wct
< 18) {
2631 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2632 END_PROFILE(SMBnttranss
);
2636 for (state
= conn
->pending_trans
; state
!= NULL
;
2637 state
= state
->next
) {
2638 if (state
->mid
== req
->mid
) {
2643 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2644 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2645 END_PROFILE(SMBnttranss
);
2649 /* Revise state->total_param and state->total_data in case they have
2650 changed downwards */
2651 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
2652 state
->total_param
= IVAL(req
->vwv
+1, 1);
2654 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
2655 state
->total_data
= IVAL(req
->vwv
+3, 1);
2658 pcnt
= IVAL(req
->vwv
+5, 1);
2659 poff
= IVAL(req
->vwv
+7, 1);
2660 pdisp
= IVAL(req
->vwv
+9, 1);
2662 dcnt
= IVAL(req
->vwv
+11, 1);
2663 doff
= IVAL(req
->vwv
+13, 1);
2664 ddisp
= IVAL(req
->vwv
+15, 1);
2666 state
->received_param
+= pcnt
;
2667 state
->received_data
+= dcnt
;
2669 if ((state
->received_data
> state
->total_data
) ||
2670 (state
->received_param
> state
->total_param
))
2674 if (smb_buffer_oob(state
->total_param
, pdisp
, pcnt
)
2675 || smb_buffer_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
2678 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
2682 if (smb_buffer_oob(state
->total_data
, ddisp
, dcnt
)
2683 || smb_buffer_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
2686 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
2689 if ((state
->received_param
< state
->total_param
) ||
2690 (state
->received_data
< state
->total_data
)) {
2691 END_PROFILE(SMBnttranss
);
2695 handle_nttrans(conn
, state
, req
);
2697 DLIST_REMOVE(conn
->pending_trans
, state
);
2698 SAFE_FREE(state
->data
);
2699 SAFE_FREE(state
->param
);
2701 END_PROFILE(SMBnttranss
);
2706 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2707 DLIST_REMOVE(conn
->pending_trans
, state
);
2708 SAFE_FREE(state
->data
);
2709 SAFE_FREE(state
->param
);
2711 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2712 END_PROFILE(SMBnttranss
);