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
,
89 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
,
253 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 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
567 "file_attributes = 0x%x, share_access = 0x%x, "
568 "create_disposition = 0x%x create_options = 0x%x "
569 "root_dir_fid = 0x%x, fname = %s\n",
571 (unsigned int)access_mask
,
572 (unsigned int)file_attributes
,
573 (unsigned int)share_access
,
574 (unsigned int)create_disposition
,
575 (unsigned int)create_options
,
576 (unsigned int)root_dir_fid
,
580 * we need to remove ignored bits when they come directly from the client
581 * because we reuse some of them for internal stuff
583 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
586 * If it's an IPC, use the pipe handler.
590 if (lp_nt_pipe_support()) {
591 do_ntcreate_pipe_open(conn
, req
);
594 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
598 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
599 if (oplock_request
) {
600 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
604 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
605 case_state
= set_posix_case_semantics(ctx
, conn
);
607 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
612 if (root_dir_fid
!= 0) {
613 char *new_fname
= NULL
;
615 status
= get_relative_fid_filename(conn
,
620 if (!NT_STATUS_IS_OK(status
)) {
621 reply_nterror(req
, status
);
627 ucf_flags
= filename_create_ucf_flags(req
, create_disposition
);
628 if (ucf_flags
& UCF_GMT_PATHNAME
) {
629 extract_snapshot_token(fname
, &twrp
);
631 status
= filename_convert_dirfsp(
632 ctx
, conn
, fname
, ucf_flags
, twrp
, &dirfsp
, &smb_fname
);
634 TALLOC_FREE(case_state
);
636 if (!NT_STATUS_IS_OK(status
)) {
637 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
639 NT_STATUS_PATH_NOT_COVERED
,
643 reply_nterror(req
, status
);
648 * Bug #6898 - clients using Windows opens should
649 * never be able to set this attribute into the
652 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
654 status
= SMB_VFS_CREATE_FILE(
658 smb_fname
, /* fname */
659 access_mask
, /* access_mask */
660 share_access
, /* share_access */
661 create_disposition
, /* create_disposition*/
662 create_options
, /* create_options */
663 file_attributes
, /* file_attributes */
664 oplock_request
, /* oplock_request */
666 allocation_size
, /* allocation_size */
667 0, /* private_flags */
672 NULL
, NULL
); /* create context */
674 if (!NT_STATUS_IS_OK(status
)) {
675 if (open_was_deferred(req
->xconn
, req
->mid
)) {
676 /* We have re-scheduled this call, no error. */
679 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
680 bool ok
= defer_smb1_sharing_violation(req
);
685 reply_openerror(req
, status
);
689 /* Ensure we're pointing at the correct stat struct. */
690 smb_fname
= fsp
->fsp_name
;
693 * If the caller set the extended oplock request bit
694 * and we granted one (by whatever means) - set the
695 * correct bit for extended oplock reply.
698 if (oplock_request
&&
699 (lp_fake_oplocks(SNUM(conn
))
700 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
703 * Exclusive oplock granted
706 if (flags
& REQUEST_BATCH_OPLOCK
) {
707 oplock_granted
= BATCH_OPLOCK_RETURN
;
709 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
711 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
712 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
714 oplock_granted
= NO_OPLOCK_RETURN
;
717 file_len
= smb_fname
->st
.st_ex_size
;
719 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
720 /* This is very strange. We
721 * return 50 words, but only set
722 * the wcnt to 42 ? It's definitely
723 * what happens on the wire....
725 reply_smb1_outbuf(req
, 50, 0);
726 SCVAL(req
->outbuf
,smb_wct
,42);
728 reply_smb1_outbuf(req
, 34, 0);
731 SSVAL(req
->outbuf
, smb_vwv0
, 0xff); /* andx chain ends */
732 SSVAL(req
->outbuf
, smb_vwv1
, 0); /* no andx offset */
734 p
= (char *)req
->outbuf
+ smb_vwv2
;
736 SCVAL(p
, 0, oplock_granted
);
739 SSVAL(p
,0,fsp
->fnum
);
741 if ((create_disposition
== FILE_SUPERSEDE
)
742 && (info
== FILE_WAS_OVERWRITTEN
)) {
743 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
749 fattr
= fdos_mode(fsp
);
751 fattr
= FILE_ATTRIBUTE_NORMAL
;
755 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
756 a_timespec
= smb_fname
->st
.st_ex_atime
;
757 m_timespec
= smb_fname
->st
.st_ex_mtime
;
758 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
760 if (lp_dos_filetime_resolution(SNUM(conn
))) {
761 dos_filetime_timespec(&create_timespec
);
762 dos_filetime_timespec(&a_timespec
);
763 dos_filetime_timespec(&m_timespec
);
764 dos_filetime_timespec(&c_timespec
);
767 put_long_date_full_timespec(conn
->ts_res
, p
, &create_timespec
); /* create time. */
769 put_long_date_full_timespec(conn
->ts_res
, p
, &a_timespec
); /* access time */
771 put_long_date_full_timespec(conn
->ts_res
, p
, &m_timespec
); /* write time */
773 put_long_date_full_timespec(conn
->ts_res
, p
, &c_timespec
); /* change time */
775 SIVAL(p
,0,fattr
); /* File Attributes. */
777 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
779 SOFF_T(p
,0,file_len
);
781 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
782 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
783 unsigned int num_streams
= 0;
784 struct stream_struct
*streams
= NULL
;
786 if (lp_ea_support(SNUM(conn
))) {
787 size_t num_names
= 0;
788 /* Do we have any EA's ? */
789 status
= get_ea_names_from_fsp(
790 ctx
, smb_fname
->fsp
, NULL
, &num_names
);
791 if (NT_STATUS_IS_OK(status
) && num_names
) {
792 file_status
&= ~NO_EAS
;
796 status
= vfs_fstreaminfo(smb_fname
->fsp
, ctx
,
797 &num_streams
, &streams
);
798 /* There is always one stream, ::$DATA. */
799 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
800 file_status
&= ~NO_SUBSTREAMS
;
802 TALLOC_FREE(streams
);
803 SSVAL(p
,2,file_status
);
806 SCVAL(p
,0,fsp
->fsp_flags
.is_directory
? 1 : 0);
808 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
811 if (fsp
->fsp_flags
.is_directory
||
812 fsp
->fsp_flags
.can_write
||
813 can_write_to_fsp(fsp
))
815 perms
= FILE_GENERIC_ALL
;
817 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
822 DEBUG(5,("reply_ntcreate_and_X: %s, open name = %s\n",
823 fsp_fnum_dbg(fsp
), smb_fname_str_dbg(smb_fname
)));
826 END_PROFILE(SMBntcreateX
);
830 /****************************************************************************
831 Reply to a NT_TRANSACT_CREATE call to open a pipe.
832 ****************************************************************************/
834 static void do_nt_transact_create_pipe(connection_struct
*conn
,
835 struct smb_request
*req
,
836 uint16_t **ppsetup
, uint32_t setup_count
,
837 char **ppparams
, uint32_t parameter_count
,
838 char **ppdata
, uint32_t data_count
)
841 char *params
= *ppparams
;
842 uint16_t pnum
= FNUM_FIELD_INVALID
;
847 TALLOC_CTX
*ctx
= talloc_tos();
850 * Ensure minimum number of parameters sent.
853 if(parameter_count
< 54) {
854 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
855 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
859 flags
= IVAL(params
,0);
861 if (req
->posix_pathnames
) {
862 srvstr_get_path_posix(ctx
,
880 if (!NT_STATUS_IS_OK(status
)) {
881 reply_nterror(req
, status
);
885 nt_open_pipe(fname
, conn
, req
, &pnum
);
892 /* Realloc the size of parameters and data we will return */
893 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
894 /* Extended response is 32 more byyes. */
899 params
= nttrans_realloc(ppparams
, param_len
);
901 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
906 SCVAL(p
,0,NO_OPLOCK_RETURN
);
911 SIVAL(p
,0,FILE_WAS_OPENED
);
915 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
918 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
920 SSVAL(p
,2, 0x5FF); /* ? */
923 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
925 SIVAL(p
,0,FILE_GENERIC_ALL
);
927 * For pipes W2K3 seems to return
929 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
931 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
934 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
936 /* Send the required number of replies */
937 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
942 /****************************************************************************
943 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
944 ****************************************************************************/
946 static void call_nt_transact_create(connection_struct
*conn
,
947 struct smb_request
*req
,
948 uint16_t **ppsetup
, uint32_t setup_count
,
949 char **ppparams
, uint32_t parameter_count
,
950 char **ppdata
, uint32_t data_count
,
951 uint32_t max_data_count
)
953 struct smb_filename
*smb_fname
= NULL
;
955 char *params
= *ppparams
;
956 char *data
= *ppdata
;
957 /* Breakout the oplock request bits so we can set the reply bits separately. */
961 struct files_struct
*dirfsp
= NULL
;
962 files_struct
*fsp
= NULL
;
965 uint32_t access_mask
;
966 uint32_t file_attributes
;
967 uint32_t share_access
;
968 uint32_t create_disposition
;
969 uint32_t create_options
;
971 struct security_descriptor
*sd
= NULL
;
973 uint16_t root_dir_fid
;
974 struct timespec create_timespec
;
975 struct timespec c_timespec
;
976 struct timespec a_timespec
;
977 struct timespec m_timespec
;
978 struct ea_list
*ea_list
= NULL
;
981 uint64_t allocation_size
;
983 uint8_t oplock_granted
;
984 struct case_semantics_state
*case_state
= NULL
;
987 TALLOC_CTX
*ctx
= talloc_tos();
989 DEBUG(5,("call_nt_transact_create\n"));
992 * If it's an IPC, use the pipe handler.
996 if (lp_nt_pipe_support()) {
997 do_nt_transact_create_pipe(
999 ppsetup
, setup_count
,
1000 ppparams
, parameter_count
,
1001 ppdata
, data_count
);
1004 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1009 * Ensure minimum number of parameters sent.
1012 if(parameter_count
< 54) {
1013 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1014 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1018 flags
= IVAL(params
,0);
1019 access_mask
= IVAL(params
,8);
1020 file_attributes
= IVAL(params
,20);
1021 share_access
= IVAL(params
,24);
1022 create_disposition
= IVAL(params
,28);
1023 create_options
= IVAL(params
,32);
1024 sd_len
= IVAL(params
,36);
1025 ea_len
= IVAL(params
,40);
1026 root_dir_fid
= (uint16_t)IVAL(params
,4);
1027 allocation_size
= BVAL(params
,12);
1030 * we need to remove ignored bits when they come directly from the client
1031 * because we reuse some of them for internal stuff
1033 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1035 if (req
->posix_pathnames
) {
1036 srvstr_get_path_posix(ctx
,
1045 srvstr_get_path(ctx
,
1054 if (!NT_STATUS_IS_OK(status
)) {
1055 reply_nterror(req
, status
);
1059 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1060 case_state
= set_posix_case_semantics(ctx
, conn
);
1062 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1067 if (root_dir_fid
!= 0) {
1068 char *new_fname
= NULL
;
1070 status
= get_relative_fid_filename(conn
,
1075 if (!NT_STATUS_IS_OK(status
)) {
1076 reply_nterror(req
, status
);
1082 ucf_flags
= filename_create_ucf_flags(req
, create_disposition
);
1083 if (ucf_flags
& UCF_GMT_PATHNAME
) {
1084 extract_snapshot_token(fname
, &twrp
);
1086 status
= filename_convert_dirfsp(ctx
,
1094 TALLOC_FREE(case_state
);
1096 if (!NT_STATUS_IS_OK(status
)) {
1097 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1098 reply_botherror(req
,
1099 NT_STATUS_PATH_NOT_COVERED
,
1100 ERRSRV
, ERRbadpath
);
1103 reply_nterror(req
, status
);
1107 /* Ensure the data_len is correct for the sd and ea values given. */
1108 if ((ea_len
+ sd_len
> data_count
)
1109 || (ea_len
> data_count
) || (sd_len
> data_count
)
1110 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1111 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
1112 "%u, data_count = %u\n", (unsigned int)ea_len
,
1113 (unsigned int)sd_len
, (unsigned int)data_count
));
1114 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1119 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1122 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
1124 if (!NT_STATUS_IS_OK(status
)) {
1125 DEBUG(10, ("call_nt_transact_create: "
1126 "unmarshall_sec_desc failed: %s\n",
1127 nt_errstr(status
)));
1128 reply_nterror(req
, status
);
1134 if (!lp_ea_support(SNUM(conn
))) {
1135 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1136 "EA's not supported.\n",
1137 (unsigned int)ea_len
));
1138 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1143 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1144 "too small (should be more than 10)\n",
1145 (unsigned int)ea_len
));
1146 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1150 /* We have already checked that ea_len <= data_count here. */
1151 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
1153 if (ea_list
== NULL
) {
1154 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1158 if (!req
->posix_pathnames
&&
1159 ea_list_has_invalid_name(ea_list
)) {
1160 /* Realloc the size of parameters and data we will return */
1161 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1162 /* Extended response is 32 more bytes. */
1167 params
= nttrans_realloc(ppparams
, param_len
);
1168 if(params
== NULL
) {
1169 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1173 memset(params
, '\0', param_len
);
1174 send_nt_replies(conn
, req
, STATUS_INVALID_EA_NAME
,
1175 params
, param_len
, NULL
, 0);
1180 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1181 if (oplock_request
) {
1182 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1187 * Bug #6898 - clients using Windows opens should
1188 * never be able to set this attribute into the
1191 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1193 status
= SMB_VFS_CREATE_FILE(
1196 dirfsp
, /* dirfsp */
1197 smb_fname
, /* fname */
1198 access_mask
, /* access_mask */
1199 share_access
, /* share_access */
1200 create_disposition
, /* create_disposition*/
1201 create_options
, /* create_options */
1202 file_attributes
, /* file_attributes */
1203 oplock_request
, /* oplock_request */
1205 allocation_size
, /* allocation_size */
1206 0, /* private_flags */
1208 ea_list
, /* ea_list */
1211 NULL
, NULL
); /* create context */
1213 if(!NT_STATUS_IS_OK(status
)) {
1214 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1215 /* We have re-scheduled this call, no error. */
1218 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
1219 bool ok
= defer_smb1_sharing_violation(req
);
1224 reply_openerror(req
, status
);
1228 /* Ensure we're pointing at the correct stat struct. */
1229 TALLOC_FREE(smb_fname
);
1230 smb_fname
= fsp
->fsp_name
;
1233 * If the caller set the extended oplock request bit
1234 * and we granted one (by whatever means) - set the
1235 * correct bit for extended oplock reply.
1238 if (oplock_request
&&
1239 (lp_fake_oplocks(SNUM(conn
))
1240 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1243 * Exclusive oplock granted
1246 if (flags
& REQUEST_BATCH_OPLOCK
) {
1247 oplock_granted
= BATCH_OPLOCK_RETURN
;
1249 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1251 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1252 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1254 oplock_granted
= NO_OPLOCK_RETURN
;
1257 file_len
= smb_fname
->st
.st_ex_size
;
1259 /* Realloc the size of parameters and data we will return */
1260 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1261 /* Extended response is 32 more byyes. */
1266 params
= nttrans_realloc(ppparams
, param_len
);
1267 if(params
== NULL
) {
1268 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1273 SCVAL(p
, 0, oplock_granted
);
1276 SSVAL(p
,0,fsp
->fnum
);
1278 if ((create_disposition
== FILE_SUPERSEDE
)
1279 && (info
== FILE_WAS_OVERWRITTEN
)) {
1280 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1286 fattr
= fdos_mode(fsp
);
1288 fattr
= FILE_ATTRIBUTE_NORMAL
;
1292 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1293 a_timespec
= smb_fname
->st
.st_ex_atime
;
1294 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1295 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1297 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1298 dos_filetime_timespec(&create_timespec
);
1299 dos_filetime_timespec(&a_timespec
);
1300 dos_filetime_timespec(&m_timespec
);
1301 dos_filetime_timespec(&c_timespec
);
1304 put_long_date_full_timespec(conn
->ts_res
, p
, &create_timespec
); /* create time. */
1306 put_long_date_full_timespec(conn
->ts_res
, p
, &a_timespec
); /* access time */
1308 put_long_date_full_timespec(conn
->ts_res
, p
, &m_timespec
); /* write time */
1310 put_long_date_full_timespec(conn
->ts_res
, p
, &c_timespec
); /* change time */
1312 SIVAL(p
,0,fattr
); /* File Attributes. */
1314 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1316 SOFF_T(p
,0,file_len
);
1318 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1319 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
1320 unsigned int num_streams
= 0;
1321 struct stream_struct
*streams
= NULL
;
1323 if (lp_ea_support(SNUM(conn
))) {
1324 size_t num_names
= 0;
1325 /* Do we have any EA's ? */
1326 status
= get_ea_names_from_fsp(
1327 ctx
, smb_fname
->fsp
, NULL
, &num_names
);
1328 if (NT_STATUS_IS_OK(status
) && num_names
) {
1329 file_status
&= ~NO_EAS
;
1333 status
= vfs_fstreaminfo(smb_fname
->fsp
, ctx
,
1334 &num_streams
, &streams
);
1335 /* There is always one stream, ::$DATA. */
1336 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
1337 file_status
&= ~NO_SUBSTREAMS
;
1339 TALLOC_FREE(streams
);
1340 SSVAL(p
,2,file_status
);
1343 SCVAL(p
,0,fsp
->fsp_flags
.is_directory
? 1 : 0);
1345 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1348 if (fsp
->fsp_flags
.is_directory
||
1349 fsp
->fsp_flags
.can_write
||
1350 can_write_to_fsp(fsp
))
1352 perms
= FILE_GENERIC_ALL
;
1354 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1359 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1360 smb_fname_str_dbg(smb_fname
)));
1362 /* Send the required number of replies */
1363 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1368 /****************************************************************************
1369 Reply to a NT CANCEL request.
1370 conn POINTER CAN BE NULL HERE !
1371 ****************************************************************************/
1373 void reply_ntcancel(struct smb_request
*req
)
1375 struct smbXsrv_connection
*xconn
= req
->xconn
;
1376 struct smbd_server_connection
*sconn
= req
->sconn
;
1380 * Go through and cancel any pending change notifies.
1383 START_PROFILE(SMBntcancel
);
1384 smb1_srv_cancel_sign_response(xconn
);
1385 found
= remove_pending_change_notify_requests_by_mid(sconn
, req
->mid
);
1387 smbd_smb1_brl_finish_by_mid(sconn
, req
->mid
);
1390 DEBUG(3,("reply_ntcancel: cancel called on mid = %llu.\n",
1391 (unsigned long long)req
->mid
));
1393 END_PROFILE(SMBntcancel
);
1397 /****************************************************************************
1398 Reply to a NT rename request.
1399 ****************************************************************************/
1401 void reply_ntrename(struct smb_request
*req
)
1403 connection_struct
*conn
= req
->conn
;
1404 struct files_struct
*src_dirfsp
= NULL
;
1405 struct smb_filename
*smb_fname_old
= NULL
;
1406 struct files_struct
*dst_dirfsp
= NULL
;
1407 struct smb_filename
*smb_fname_new
= NULL
;
1408 char *oldname
= NULL
;
1409 char *newname
= NULL
;
1410 const char *dst_original_lcomp
= NULL
;
1414 uint32_t ucf_flags_src
= ucf_flags_from_smb_request(req
);
1415 NTTIME src_twrp
= 0;
1416 uint32_t ucf_flags_dst
= ucf_flags_from_smb_request(req
);
1417 NTTIME dst_twrp
= 0;
1418 uint16_t rename_type
;
1419 TALLOC_CTX
*ctx
= talloc_tos();
1420 bool stream_rename
= false;
1422 START_PROFILE(SMBntrename
);
1425 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1429 attrs
= SVAL(req
->vwv
+0, 0);
1430 rename_type
= SVAL(req
->vwv
+1, 0);
1432 p
= (const char *)req
->buf
+ 1;
1433 p
+= srvstr_get_path_req(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1435 if (!NT_STATUS_IS_OK(status
)) {
1436 reply_nterror(req
, status
);
1440 if (!req
->posix_pathnames
&& ms_has_wild(oldname
)) {
1441 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1446 p
+= srvstr_get_path_req(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1448 if (!NT_STATUS_IS_OK(status
)) {
1449 reply_nterror(req
, status
);
1453 if (!req
->posix_pathnames
&& ms_has_wild(newname
)) {
1454 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1458 if (!req
->posix_pathnames
) {
1459 /* The newname must begin with a ':' if the
1460 oldname contains a ':'. */
1461 if (strchr_m(oldname
, ':')) {
1462 if (newname
[0] != ':') {
1463 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1466 stream_rename
= true;
1470 if (ucf_flags_src
& UCF_GMT_PATHNAME
) {
1471 extract_snapshot_token(oldname
, &src_twrp
);
1473 status
= filename_convert_dirfsp(ctx
,
1480 if (!NT_STATUS_IS_OK(status
)) {
1481 if (NT_STATUS_EQUAL(status
,
1482 NT_STATUS_PATH_NOT_COVERED
)) {
1483 reply_botherror(req
,
1484 NT_STATUS_PATH_NOT_COVERED
,
1485 ERRSRV
, ERRbadpath
);
1488 reply_nterror(req
, status
);
1492 if (stream_rename
) {
1494 * No point in calling filename_convert()
1495 * on a raw stream name. It can never find
1496 * the file anyway. Use the same logic as
1497 * SMB2_FILE_RENAME_INFORMATION_INTERNAL
1498 * and generate smb_fname_new directly.
1500 smb_fname_new
= synthetic_smb_fname(talloc_tos(),
1501 smb_fname_old
->base_name
,
1504 smb_fname_old
->twrp
,
1505 smb_fname_old
->flags
);
1506 if (smb_fname_new
== NULL
) {
1507 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1511 if (ucf_flags_dst
& UCF_GMT_PATHNAME
) {
1512 extract_snapshot_token(newname
,
1515 status
= filename_convert_dirfsp(ctx
,
1522 if (!NT_STATUS_IS_OK(status
)) {
1523 if (NT_STATUS_EQUAL(status
,
1524 NT_STATUS_PATH_NOT_COVERED
)) {
1525 reply_botherror(req
,
1526 NT_STATUS_PATH_NOT_COVERED
,
1527 ERRSRV
, ERRbadpath
);
1530 reply_nterror(req
, status
);
1535 /* Get the last component of the destination for rename_internals(). */
1536 dst_original_lcomp
= get_original_lcomp(ctx
,
1540 if (dst_original_lcomp
== NULL
) {
1541 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1546 DEBUG(3,("reply_ntrename: %s -> %s\n",
1547 smb_fname_str_dbg(smb_fname_old
),
1548 smb_fname_str_dbg(smb_fname_new
)));
1550 switch(rename_type
) {
1551 case RENAME_FLAG_RENAME
:
1552 status
= rename_internals(ctx
,
1564 case RENAME_FLAG_HARD_LINK
:
1565 status
= hardlink_internals(ctx
,
1574 case RENAME_FLAG_COPY
:
1575 status
= copy_internals(ctx
,
1584 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1585 status
= NT_STATUS_INVALID_PARAMETER
;
1588 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1592 if (!NT_STATUS_IS_OK(status
)) {
1593 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1594 /* We have re-scheduled this call. */
1597 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
1598 bool ok
= defer_smb1_sharing_violation(req
);
1604 reply_nterror(req
, status
);
1608 reply_smb1_outbuf(req
, 0, 0);
1610 END_PROFILE(SMBntrename
);
1614 /****************************************************************************
1615 Reply to a notify change - queue the request and
1616 don't allow a directory to be opened.
1617 ****************************************************************************/
1619 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1620 NTSTATUS error_code
,
1621 uint8_t *buf
, size_t len
)
1623 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1626 static void call_nt_transact_notify_change(connection_struct
*conn
,
1627 struct smb_request
*req
,
1629 uint32_t setup_count
,
1631 uint32_t parameter_count
,
1632 char **ppdata
, uint32_t data_count
,
1633 uint32_t max_data_count
,
1634 uint32_t max_param_count
)
1636 uint16_t *setup
= *ppsetup
;
1642 if(setup_count
< 6) {
1643 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1647 fsp
= file_fsp(req
, SVAL(setup
,4));
1648 filter
= IVAL(setup
, 0);
1649 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1651 DEBUG(3,("call_nt_transact_notify_change\n"));
1654 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1659 char *filter_string
;
1661 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1662 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1666 DEBUG(3,("call_nt_transact_notify_change: notify change "
1667 "called on %s, filter = %s, recursive = %d\n",
1668 fsp_str_dbg(fsp
), filter_string
, recursive
));
1670 TALLOC_FREE(filter_string
);
1673 if((!fsp
->fsp_flags
.is_directory
) || (conn
!= fsp
->conn
)) {
1674 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1678 if (fsp
->notify
== NULL
) {
1680 status
= change_notify_create(fsp
,
1684 if (!NT_STATUS_IS_OK(status
)) {
1685 DEBUG(10, ("change_notify_create returned %s\n",
1686 nt_errstr(status
)));
1687 reply_nterror(req
, status
);
1692 if (change_notify_fsp_has_changes(fsp
)) {
1695 * We've got changes pending, respond immediately
1699 * TODO: write a torture test to check the filtering behaviour
1703 change_notify_reply(req
,
1707 smbd_smb1_notify_reply
);
1710 * change_notify_reply() above has independently sent its
1717 * No changes pending, queue the request
1720 status
= change_notify_add_request(req
,
1724 smbd_smb1_notify_reply
);
1725 if (!NT_STATUS_IS_OK(status
)) {
1726 reply_nterror(req
, status
);
1731 /****************************************************************************
1732 Reply to an NT transact rename command.
1733 ****************************************************************************/
1735 static void call_nt_transact_rename(connection_struct
*conn
,
1736 struct smb_request
*req
,
1737 uint16_t **ppsetup
, uint32_t setup_count
,
1738 char **ppparams
, uint32_t parameter_count
,
1739 char **ppdata
, uint32_t data_count
,
1740 uint32_t max_data_count
)
1742 char *params
= *ppparams
;
1743 char *new_name
= NULL
;
1744 files_struct
*fsp
= NULL
;
1746 TALLOC_CTX
*ctx
= talloc_tos();
1748 if(parameter_count
< 5) {
1749 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1753 fsp
= file_fsp(req
, SVAL(params
, 0));
1754 if (!check_fsp(conn
, req
, fsp
)) {
1757 if (req
->posix_pathnames
) {
1758 srvstr_get_path_posix(ctx
,
1763 parameter_count
- 4,
1767 srvstr_get_path(ctx
,
1772 parameter_count
- 4,
1777 if (!NT_STATUS_IS_OK(status
)) {
1778 reply_nterror(req
, status
);
1783 * W2K3 ignores this request as the RAW-RENAME test
1784 * demonstrates, so we do.
1786 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1788 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1789 fsp_str_dbg(fsp
), new_name
));
1794 /****************************************************************************
1795 SMB1 reply to query a security descriptor.
1796 ****************************************************************************/
1798 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1799 struct smb_request
*req
,
1801 uint32_t setup_count
,
1803 uint32_t parameter_count
,
1805 uint32_t data_count
,
1806 uint32_t max_data_count
)
1808 char *params
= *ppparams
;
1809 char *data
= *ppdata
;
1811 uint32_t security_info_wanted
;
1812 files_struct
*fsp
= NULL
;
1814 uint8_t *marshalled_sd
= NULL
;
1816 if(parameter_count
< 8) {
1817 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1821 fsp
= file_fsp(req
, SVAL(params
,0));
1823 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1827 security_info_wanted
= IVAL(params
,4);
1829 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1830 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
1831 (unsigned int)security_info_wanted
));
1833 params
= nttrans_realloc(ppparams
, 4);
1834 if(params
== NULL
) {
1835 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1840 * Get the permissions to return.
1843 status
= smbd_do_query_security_desc(conn
,
1846 security_info_wanted
&
1847 SMB_SUPPORTED_SECINFO_FLAGS
,
1852 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
1853 SIVAL(params
,0,(uint32_t)sd_size
);
1854 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1855 params
, 4, NULL
, 0);
1859 if (!NT_STATUS_IS_OK(status
)) {
1860 reply_nterror(req
, status
);
1864 SMB_ASSERT(sd_size
> 0);
1866 SIVAL(params
,0,(uint32_t)sd_size
);
1868 if (max_data_count
< sd_size
) {
1869 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1870 params
, 4, NULL
, 0);
1875 * Allocate the data we will return.
1878 data
= nttrans_realloc(ppdata
, sd_size
);
1880 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1884 memcpy(data
, marshalled_sd
, sd_size
);
1886 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1891 /****************************************************************************
1892 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1893 ****************************************************************************/
1895 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1896 struct smb_request
*req
,
1898 uint32_t setup_count
,
1900 uint32_t parameter_count
,
1902 uint32_t data_count
,
1903 uint32_t max_data_count
)
1905 char *params
= *ppparams
;
1906 char *data
= *ppdata
;
1907 files_struct
*fsp
= NULL
;
1908 uint32_t security_info_sent
= 0;
1911 if(parameter_count
< 8) {
1912 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1916 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1917 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1921 if (!CAN_WRITE(fsp
->conn
)) {
1922 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1926 if(!lp_nt_acl_support(SNUM(conn
))) {
1930 security_info_sent
= IVAL(params
,4);
1932 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1933 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
1935 if (data_count
== 0) {
1936 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1940 status
= set_sd_blob(fsp
, (uint8_t *)data
, data_count
,
1941 security_info_sent
& SMB_SUPPORTED_SECINFO_FLAGS
);
1942 if (!NT_STATUS_IS_OK(status
)) {
1943 reply_nterror(req
, status
);
1948 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1952 /****************************************************************************
1954 ****************************************************************************/
1956 static void call_nt_transact_ioctl(connection_struct
*conn
,
1957 struct smb_request
*req
,
1958 uint16_t **ppsetup
, uint32_t setup_count
,
1959 char **ppparams
, uint32_t parameter_count
,
1960 char **ppdata
, uint32_t data_count
,
1961 uint32_t max_data_count
)
1969 char *out_data
= NULL
;
1970 uint32_t out_data_len
= 0;
1971 char *pdata
= *ppdata
;
1972 TALLOC_CTX
*ctx
= talloc_tos();
1974 if (setup_count
!= 8) {
1975 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1976 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1980 function
= IVAL(*ppsetup
, 0);
1981 fidnum
= SVAL(*ppsetup
, 4);
1982 isFSctl
= CVAL(*ppsetup
, 6);
1983 compfilter
= CVAL(*ppsetup
, 7);
1985 DEBUG(10, ("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1986 function
, fidnum
, isFSctl
, compfilter
));
1988 fsp
=file_fsp(req
, fidnum
);
1991 * We don't really implement IOCTLs, especially on files.
1994 DEBUG(10, ("isFSctl: 0x%02X indicates IOCTL, not FSCTL!\n",
1996 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2000 /* Has to be for an open file! */
2001 if (!check_fsp_open(conn
, req
, fsp
)) {
2005 SMB_PERFCOUNT_SET_IOCTL(&req
->pcd
, function
);
2008 * out_data might be allocated by the VFS module, but talloc should be
2009 * used, and should be cleaned up when the request ends.
2011 status
= SMB_VFS_FSCTL(fsp
,
2017 (uint8_t **)&out_data
,
2020 if (!NT_STATUS_IS_OK(status
)) {
2021 reply_nterror(req
, status
);
2023 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, out_data
, out_data_len
);
2028 #ifdef HAVE_SYS_QUOTAS
2029 /****************************************************************************
2030 Reply to get user quota
2031 ****************************************************************************/
2033 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2034 struct smb_request
*req
,
2036 uint32_t setup_count
,
2038 uint32_t parameter_count
,
2040 uint32_t data_count
,
2041 uint32_t max_data_count
)
2043 const struct loadparm_substitution
*lp_sub
=
2044 loadparm_s3_global_substitution();
2045 NTSTATUS nt_status
= NT_STATUS_OK
;
2046 char *params
= *ppparams
;
2047 char *pdata
= *ppdata
;
2050 files_struct
*fsp
= NULL
;
2051 DATA_BLOB blob
= data_blob_null
;
2052 struct nttrans_query_quota_params info
= {0};
2053 enum ndr_err_code err
;
2054 TALLOC_CTX
*tmp_ctx
= NULL
;
2055 uint32_t resp_len
= 0;
2056 uint8_t *resp_data
= 0;
2058 tmp_ctx
= talloc_init("ntquota_list");
2060 nt_status
= NT_STATUS_NO_MEMORY
;
2065 if (get_current_uid(conn
) != sec_initial_uid()) {
2066 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2067 "[%s]\n", lp_servicename(talloc_tos(), lp_sub
, SNUM(conn
)),
2068 conn
->session_info
->unix_info
->unix_name
));
2069 nt_status
= NT_STATUS_ACCESS_DENIED
;
2073 blob
.data
= (uint8_t*)params
;
2074 blob
.length
= parameter_count
;
2076 err
= ndr_pull_struct_blob(&blob
, tmp_ctx
, &info
,
2077 (ndr_pull_flags_fn_t
)ndr_pull_nttrans_query_quota_params
);
2079 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2080 DEBUG(0,("TRANSACT_GET_USER_QUOTA: failed to pull "
2081 "query_quota_params."));
2082 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2085 DBG_DEBUG("info.return_single_entry = %u, info.restart_scan = %u, "
2086 "info.sid_list_length = %u, info.start_sid_length = %u, "
2087 "info.start_sid_offset = %u\n",
2088 (unsigned int)info
.return_single_entry
,
2089 (unsigned int)info
.restart_scan
,
2090 (unsigned int)info
.sid_list_length
,
2091 (unsigned int)info
.start_sid_length
,
2092 (unsigned int)info
.start_sid_offset
);
2094 /* set blob to point at data for further parsing */
2095 blob
.data
= (uint8_t*)pdata
;
2096 blob
.length
= data_count
;
2098 * Although MS-SMB ref is ambiguous here, a microsoft client will
2099 * only ever send a start sid (as part of a list) with
2100 * sid_list_length & start_sid_offset both set to the actual list
2101 * length. Note: Only a single result is returned in this case
2102 * In the case where either start_sid_offset or start_sid_length
2103 * are set alone or if both set (but have different values) then
2104 * it seems windows will return a number of entries from the start
2105 * of the list of users with quotas set. This behaviour is undocumented
2106 * and windows clients do not send messages of that type. As such we
2107 * currently will reject these requests.
2109 if (info
.start_sid_length
2110 || (info
.sid_list_length
!= info
.start_sid_offset
)) {
2111 DBG_ERR("TRANSACT_GET_USER_QUOTA: unsupported single or "
2112 "compound sid format\n");
2113 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2117 /* maybe we can check the quota_fnum */
2118 fsp
= file_fsp(req
, info
.fid
);
2119 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2120 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2121 nt_status
= NT_STATUS_INVALID_HANDLE
;
2124 nt_status
= smbd_do_query_getinfo_quota(tmp_ctx
,
2127 info
.return_single_entry
,
2128 info
.sid_list_length
,
2133 if (!NT_STATUS_IS_OK(nt_status
)) {
2134 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2137 nt_status
= NT_STATUS_OK
;
2141 params
= nttrans_realloc(ppparams
, param_len
);
2142 if(params
== NULL
) {
2143 nt_status
= NT_STATUS_NO_MEMORY
;
2147 data_len
= resp_len
;
2148 SIVAL(params
, 0, data_len
);
2149 pdata
= nttrans_realloc(ppdata
, data_len
);
2150 memcpy(pdata
, resp_data
, data_len
);
2152 TALLOC_FREE(tmp_ctx
);
2153 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2157 TALLOC_FREE(tmp_ctx
);
2158 reply_nterror(req
, nt_status
);
2161 /****************************************************************************
2162 Reply to set user quota
2163 ****************************************************************************/
2165 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2166 struct smb_request
*req
,
2168 uint32_t setup_count
,
2170 uint32_t parameter_count
,
2172 uint32_t data_count
,
2173 uint32_t max_data_count
)
2175 const struct loadparm_substitution
*lp_sub
=
2176 loadparm_s3_global_substitution();
2177 char *params
= *ppparams
;
2178 char *pdata
= *ppdata
;
2179 int data_len
=0,param_len
=0;
2180 SMB_NTQUOTA_STRUCT qt
;
2181 struct file_quota_information info
= {0};
2182 enum ndr_err_code err
;
2185 files_struct
*fsp
= NULL
;
2186 TALLOC_CTX
*ctx
= NULL
;
2187 NTSTATUS status
= NT_STATUS_OK
;
2191 if (get_current_uid(conn
) != sec_initial_uid()) {
2192 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2193 "[%s]\n", lp_servicename(talloc_tos(), lp_sub
, SNUM(conn
)),
2194 conn
->session_info
->unix_info
->unix_name
));
2195 status
= NT_STATUS_ACCESS_DENIED
;
2200 * Ensure minimum number of parameters sent.
2203 if (parameter_count
< 2) {
2204 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2205 status
= NT_STATUS_INVALID_PARAMETER
;
2209 /* maybe we can check the quota_fnum */
2210 fsp
= file_fsp(req
, SVAL(params
,0));
2211 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2212 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2213 status
= NT_STATUS_INVALID_HANDLE
;
2217 ctx
= talloc_init("set_user_quota");
2219 status
= NT_STATUS_NO_MEMORY
;
2222 inblob
.data
= (uint8_t*)pdata
;
2223 inblob
.length
= data_count
;
2225 err
= ndr_pull_struct_blob(
2229 (ndr_pull_flags_fn_t
)ndr_pull_file_quota_information
);
2231 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2232 DEBUG(0,("TRANSACT_SET_USER_QUOTA: failed to pull "
2233 "file_quota_information\n"));
2234 status
= NT_STATUS_INVALID_PARAMETER
;
2237 qt
.usedspace
= info
.quota_used
;
2239 qt
.softlim
= info
.quota_threshold
;
2241 qt
.hardlim
= info
.quota_limit
;
2245 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2246 status
= NT_STATUS_INTERNAL_ERROR
;
2250 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2256 reply_nterror(req
, status
);
2258 #endif /* HAVE_SYS_QUOTAS */
2260 static void handle_nttrans(connection_struct
*conn
,
2261 struct trans_state
*state
,
2262 struct smb_request
*req
)
2264 if (get_Protocol() >= PROTOCOL_NT1
) {
2265 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2266 SSVAL(discard_const_p(uint8_t, req
->inbuf
),smb_flg2
,req
->flags2
);
2270 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2272 /* Now we must call the relevant NT_TRANS function */
2273 switch(state
->call
) {
2274 case NT_TRANSACT_CREATE
:
2276 START_PROFILE(NT_transact_create
);
2277 call_nt_transact_create(
2279 &state
->setup
, state
->setup_count
,
2280 &state
->param
, state
->total_param
,
2281 &state
->data
, state
->total_data
,
2282 state
->max_data_return
);
2283 END_PROFILE(NT_transact_create
);
2287 case NT_TRANSACT_IOCTL
:
2289 START_PROFILE(NT_transact_ioctl
);
2290 call_nt_transact_ioctl(
2292 &state
->setup
, state
->setup_count
,
2293 &state
->param
, state
->total_param
,
2294 &state
->data
, state
->total_data
,
2295 state
->max_data_return
);
2296 END_PROFILE(NT_transact_ioctl
);
2300 case NT_TRANSACT_SET_SECURITY_DESC
:
2302 START_PROFILE(NT_transact_set_security_desc
);
2303 call_nt_transact_set_security_desc(
2305 &state
->setup
, state
->setup_count
,
2306 &state
->param
, state
->total_param
,
2307 &state
->data
, state
->total_data
,
2308 state
->max_data_return
);
2309 END_PROFILE(NT_transact_set_security_desc
);
2313 case NT_TRANSACT_NOTIFY_CHANGE
:
2315 START_PROFILE(NT_transact_notify_change
);
2316 call_nt_transact_notify_change(
2318 &state
->setup
, state
->setup_count
,
2319 &state
->param
, state
->total_param
,
2320 &state
->data
, state
->total_data
,
2321 state
->max_data_return
,
2322 state
->max_param_return
);
2323 END_PROFILE(NT_transact_notify_change
);
2327 case NT_TRANSACT_RENAME
:
2329 START_PROFILE(NT_transact_rename
);
2330 call_nt_transact_rename(
2332 &state
->setup
, state
->setup_count
,
2333 &state
->param
, state
->total_param
,
2334 &state
->data
, state
->total_data
,
2335 state
->max_data_return
);
2336 END_PROFILE(NT_transact_rename
);
2340 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2342 START_PROFILE(NT_transact_query_security_desc
);
2343 call_nt_transact_query_security_desc(
2345 &state
->setup
, state
->setup_count
,
2346 &state
->param
, state
->total_param
,
2347 &state
->data
, state
->total_data
,
2348 state
->max_data_return
);
2349 END_PROFILE(NT_transact_query_security_desc
);
2353 #ifdef HAVE_SYS_QUOTAS
2354 case NT_TRANSACT_GET_USER_QUOTA
:
2356 START_PROFILE(NT_transact_get_user_quota
);
2357 call_nt_transact_get_user_quota(
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_get_user_quota
);
2367 case NT_TRANSACT_SET_USER_QUOTA
:
2369 START_PROFILE(NT_transact_set_user_quota
);
2370 call_nt_transact_set_user_quota(
2372 &state
->setup
, state
->setup_count
,
2373 &state
->param
, state
->total_param
,
2374 &state
->data
, state
->total_data
,
2375 state
->max_data_return
);
2376 END_PROFILE(NT_transact_set_user_quota
);
2379 #endif /* HAVE_SYS_QUOTAS */
2382 /* Error in request */
2383 DEBUG(0,("handle_nttrans: Unknown request %d in "
2384 "nttrans call\n", state
->call
));
2385 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2391 /****************************************************************************
2392 Reply to a SMBNTtrans.
2393 ****************************************************************************/
2395 void reply_nttrans(struct smb_request
*req
)
2397 connection_struct
*conn
= req
->conn
;
2402 uint16_t function_code
;
2404 struct trans_state
*state
;
2406 START_PROFILE(SMBnttrans
);
2408 if (req
->wct
< 19) {
2409 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2410 END_PROFILE(SMBnttrans
);
2414 pscnt
= IVAL(req
->vwv
+9, 1);
2415 psoff
= IVAL(req
->vwv
+11, 1);
2416 dscnt
= IVAL(req
->vwv
+13, 1);
2417 dsoff
= IVAL(req
->vwv
+15, 1);
2418 function_code
= SVAL(req
->vwv
+18, 0);
2420 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2421 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2422 END_PROFILE(SMBnttrans
);
2426 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2427 if (!NT_STATUS_IS_OK(result
)) {
2428 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2429 reply_nterror(req
, result
);
2430 END_PROFILE(SMBnttrans
);
2434 if ((state
= talloc(conn
, struct trans_state
)) == NULL
) {
2435 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2436 END_PROFILE(SMBnttrans
);
2440 state
->cmd
= SMBnttrans
;
2442 state
->mid
= req
->mid
;
2443 state
->vuid
= req
->vuid
;
2444 state
->total_data
= IVAL(req
->vwv
+3, 1);
2446 state
->total_param
= IVAL(req
->vwv
+1, 1);
2447 state
->param
= NULL
;
2448 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2449 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2451 /* setup count is in *words* */
2452 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2453 state
->setup
= NULL
;
2454 state
->call
= function_code
;
2456 DEBUG(10, ("num_setup=%u, "
2457 "param_total=%u, this_param=%u, max_param=%u, "
2458 "data_total=%u, this_data=%u, max_data=%u, "
2459 "param_offset=%u, data_offset=%u\n",
2460 (unsigned)state
->setup_count
,
2461 (unsigned)state
->total_param
, (unsigned)pscnt
,
2462 (unsigned)state
->max_param_return
,
2463 (unsigned)state
->total_data
, (unsigned)dscnt
,
2464 (unsigned)state
->max_data_return
,
2465 (unsigned)psoff
, (unsigned)dsoff
));
2468 * All nttrans messages we handle have smb_wct == 19 +
2469 * state->setup_count. Ensure this is so as a sanity check.
2472 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2473 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2474 req
->wct
, 19 + (state
->setup_count
/2)));
2478 /* Don't allow more than 128mb for each value. */
2479 if ((state
->total_data
> (1024*1024*128)) ||
2480 (state
->total_param
> (1024*1024*128))) {
2481 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2482 END_PROFILE(SMBnttrans
);
2486 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2489 if (state
->total_data
) {
2491 if (smb_buffer_oob(state
->total_data
, 0, dscnt
)
2492 || smb_buffer_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
2496 /* Can't use talloc here, the core routines do realloc on the
2497 * params and data. */
2498 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2499 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2500 "bytes !\n", (unsigned int)state
->total_data
));
2502 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2503 END_PROFILE(SMBnttrans
);
2507 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2510 if (state
->total_param
) {
2512 if (smb_buffer_oob(state
->total_param
, 0, pscnt
)
2513 || smb_buffer_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
2517 /* Can't use talloc here, the core routines do realloc on the
2518 * params and data. */
2519 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2520 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2521 "bytes !\n", (unsigned int)state
->total_param
));
2522 SAFE_FREE(state
->data
);
2524 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2525 END_PROFILE(SMBnttrans
);
2529 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2532 state
->received_data
= dscnt
;
2533 state
->received_param
= pscnt
;
2535 if(state
->setup_count
> 0) {
2536 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2537 state
->setup_count
));
2540 * No overflow possible here, state->setup_count is an
2541 * unsigned int, being filled by a single byte from
2542 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2543 * below is not necessary, it's here to clarify things. The
2544 * validity of req->vwv and req->wct has been checked in
2545 * init_smb1_request already.
2547 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
2551 state
->setup
= (uint16_t *)TALLOC(state
, state
->setup_count
);
2552 if (state
->setup
== NULL
) {
2553 DEBUG(0,("reply_nttrans : Out of memory\n"));
2554 SAFE_FREE(state
->data
);
2555 SAFE_FREE(state
->param
);
2557 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2558 END_PROFILE(SMBnttrans
);
2562 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
2563 dump_data(10, (uint8_t *)state
->setup
, state
->setup_count
);
2566 if ((state
->received_data
== state
->total_data
) &&
2567 (state
->received_param
== state
->total_param
)) {
2568 handle_nttrans(conn
, state
, req
);
2569 SAFE_FREE(state
->param
);
2570 SAFE_FREE(state
->data
);
2572 END_PROFILE(SMBnttrans
);
2576 DLIST_ADD(conn
->pending_trans
, state
);
2578 /* We need to send an interim response then receive the rest
2579 of the parameter/data bytes */
2580 reply_smb1_outbuf(req
, 0, 0);
2581 show_msg((char *)req
->outbuf
);
2582 END_PROFILE(SMBnttrans
);
2587 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2588 SAFE_FREE(state
->data
);
2589 SAFE_FREE(state
->param
);
2591 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2592 END_PROFILE(SMBnttrans
);
2596 /****************************************************************************
2597 Reply to a SMBnttranss
2598 ****************************************************************************/
2600 void reply_nttranss(struct smb_request
*req
)
2602 connection_struct
*conn
= req
->conn
;
2603 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2604 struct trans_state
*state
;
2606 START_PROFILE(SMBnttranss
);
2608 show_msg((const char *)req
->inbuf
);
2610 /* Windows clients expect all replies to
2611 an NT transact secondary (SMBnttranss 0xA1)
2612 to have a command code of NT transact
2613 (SMBnttrans 0xA0). See bug #8989 for details. */
2614 req
->cmd
= SMBnttrans
;
2616 if (req
->wct
< 18) {
2617 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2618 END_PROFILE(SMBnttranss
);
2622 for (state
= conn
->pending_trans
; state
!= NULL
;
2623 state
= state
->next
) {
2624 if (state
->mid
== req
->mid
) {
2629 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2630 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2631 END_PROFILE(SMBnttranss
);
2635 /* Revise state->total_param and state->total_data in case they have
2636 changed downwards */
2637 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
2638 state
->total_param
= IVAL(req
->vwv
+1, 1);
2640 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
2641 state
->total_data
= IVAL(req
->vwv
+3, 1);
2644 pcnt
= IVAL(req
->vwv
+5, 1);
2645 poff
= IVAL(req
->vwv
+7, 1);
2646 pdisp
= IVAL(req
->vwv
+9, 1);
2648 dcnt
= IVAL(req
->vwv
+11, 1);
2649 doff
= IVAL(req
->vwv
+13, 1);
2650 ddisp
= IVAL(req
->vwv
+15, 1);
2652 state
->received_param
+= pcnt
;
2653 state
->received_data
+= dcnt
;
2655 if ((state
->received_data
> state
->total_data
) ||
2656 (state
->received_param
> state
->total_param
))
2660 if (smb_buffer_oob(state
->total_param
, pdisp
, pcnt
)
2661 || smb_buffer_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
2664 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
2668 if (smb_buffer_oob(state
->total_data
, ddisp
, dcnt
)
2669 || smb_buffer_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
2672 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
2675 if ((state
->received_param
< state
->total_param
) ||
2676 (state
->received_data
< state
->total_data
)) {
2677 END_PROFILE(SMBnttranss
);
2681 handle_nttrans(conn
, state
, req
);
2683 DLIST_REMOVE(conn
->pending_trans
, state
);
2684 SAFE_FREE(state
->data
);
2685 SAFE_FREE(state
->param
);
2687 END_PROFILE(SMBnttranss
);
2692 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2693 DLIST_REMOVE(conn
->pending_trans
, state
);
2694 SAFE_FREE(state
->data
);
2695 SAFE_FREE(state
->param
);
2697 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2698 END_PROFILE(SMBnttranss
);