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 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
= smb1_strip_dfs_path(ctx
, &ucf_flags
, &fname
);
632 if (!NT_STATUS_IS_OK(status
)) {
633 reply_nterror(req
, status
);
637 status
= filename_convert_dirfsp(
638 ctx
, conn
, fname
, ucf_flags
, twrp
, &dirfsp
, &smb_fname
);
640 TALLOC_FREE(case_state
);
642 if (!NT_STATUS_IS_OK(status
)) {
643 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
645 NT_STATUS_PATH_NOT_COVERED
,
649 reply_nterror(req
, status
);
654 * Bug #6898 - clients using Windows opens should
655 * never be able to set this attribute into the
658 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
660 status
= SMB_VFS_CREATE_FILE(
664 smb_fname
, /* fname */
665 access_mask
, /* access_mask */
666 share_access
, /* share_access */
667 create_disposition
, /* create_disposition*/
668 create_options
, /* create_options */
669 file_attributes
, /* file_attributes */
670 oplock_request
, /* oplock_request */
672 allocation_size
, /* allocation_size */
673 0, /* private_flags */
678 NULL
, NULL
); /* create context */
680 if (!NT_STATUS_IS_OK(status
)) {
681 if (open_was_deferred(req
->xconn
, req
->mid
)) {
682 /* We have re-scheduled this call, no error. */
685 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
686 bool ok
= defer_smb1_sharing_violation(req
);
691 reply_openerror(req
, status
);
695 /* Ensure we're pointing at the correct stat struct. */
696 smb_fname
= fsp
->fsp_name
;
699 * If the caller set the extended oplock request bit
700 * and we granted one (by whatever means) - set the
701 * correct bit for extended oplock reply.
704 if (oplock_request
&&
705 (lp_fake_oplocks(SNUM(conn
))
706 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
709 * Exclusive oplock granted
712 if (flags
& REQUEST_BATCH_OPLOCK
) {
713 oplock_granted
= BATCH_OPLOCK_RETURN
;
715 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
717 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
718 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
720 oplock_granted
= NO_OPLOCK_RETURN
;
723 file_len
= smb_fname
->st
.st_ex_size
;
725 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
726 /* This is very strange. We
727 * return 50 words, but only set
728 * the wcnt to 42 ? It's definitely
729 * what happens on the wire....
731 reply_smb1_outbuf(req
, 50, 0);
732 SCVAL(req
->outbuf
,smb_wct
,42);
734 reply_smb1_outbuf(req
, 34, 0);
737 SSVAL(req
->outbuf
, smb_vwv0
, 0xff); /* andx chain ends */
738 SSVAL(req
->outbuf
, smb_vwv1
, 0); /* no andx offset */
740 p
= (char *)req
->outbuf
+ smb_vwv2
;
742 SCVAL(p
, 0, oplock_granted
);
745 SSVAL(p
,0,fsp
->fnum
);
747 if ((create_disposition
== FILE_SUPERSEDE
)
748 && (info
== FILE_WAS_OVERWRITTEN
)) {
749 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
755 fattr
= fdos_mode(fsp
);
757 fattr
= FILE_ATTRIBUTE_NORMAL
;
761 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
762 a_timespec
= smb_fname
->st
.st_ex_atime
;
763 m_timespec
= smb_fname
->st
.st_ex_mtime
;
764 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
766 if (lp_dos_filetime_resolution(SNUM(conn
))) {
767 dos_filetime_timespec(&create_timespec
);
768 dos_filetime_timespec(&a_timespec
);
769 dos_filetime_timespec(&m_timespec
);
770 dos_filetime_timespec(&c_timespec
);
773 put_long_date_full_timespec(conn
->ts_res
, p
, &create_timespec
); /* create time. */
775 put_long_date_full_timespec(conn
->ts_res
, p
, &a_timespec
); /* access time */
777 put_long_date_full_timespec(conn
->ts_res
, p
, &m_timespec
); /* write time */
779 put_long_date_full_timespec(conn
->ts_res
, p
, &c_timespec
); /* change time */
781 SIVAL(p
,0,fattr
); /* File Attributes. */
783 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
785 SOFF_T(p
,0,file_len
);
787 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
788 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
789 unsigned int num_streams
= 0;
790 struct stream_struct
*streams
= NULL
;
792 if (lp_ea_support(SNUM(conn
))) {
793 size_t num_names
= 0;
794 /* Do we have any EA's ? */
795 status
= get_ea_names_from_fsp(
796 ctx
, smb_fname
->fsp
, NULL
, &num_names
);
797 if (NT_STATUS_IS_OK(status
) && num_names
) {
798 file_status
&= ~NO_EAS
;
802 status
= vfs_fstreaminfo(smb_fname
->fsp
, ctx
,
803 &num_streams
, &streams
);
804 /* There is always one stream, ::$DATA. */
805 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
806 file_status
&= ~NO_SUBSTREAMS
;
808 TALLOC_FREE(streams
);
809 SSVAL(p
,2,file_status
);
812 SCVAL(p
,0,fsp
->fsp_flags
.is_directory
? 1 : 0);
814 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
817 if (fsp
->fsp_flags
.is_directory
||
818 fsp
->fsp_flags
.can_write
||
819 can_write_to_fsp(fsp
))
821 perms
= FILE_GENERIC_ALL
;
823 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
828 DEBUG(5,("reply_ntcreate_and_X: %s, open name = %s\n",
829 fsp_fnum_dbg(fsp
), smb_fname_str_dbg(smb_fname
)));
832 END_PROFILE(SMBntcreateX
);
836 /****************************************************************************
837 Reply to a NT_TRANSACT_CREATE call to open a pipe.
838 ****************************************************************************/
840 static void do_nt_transact_create_pipe(connection_struct
*conn
,
841 struct smb_request
*req
,
842 uint16_t **ppsetup
, uint32_t setup_count
,
843 char **ppparams
, uint32_t parameter_count
,
844 char **ppdata
, uint32_t data_count
)
847 char *params
= *ppparams
;
848 uint16_t pnum
= FNUM_FIELD_INVALID
;
853 TALLOC_CTX
*ctx
= talloc_tos();
856 * Ensure minimum number of parameters sent.
859 if(parameter_count
< 54) {
860 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
861 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
865 flags
= IVAL(params
,0);
867 if (req
->posix_pathnames
) {
868 srvstr_get_path_posix(ctx
,
886 if (!NT_STATUS_IS_OK(status
)) {
887 reply_nterror(req
, status
);
891 nt_open_pipe(fname
, conn
, req
, &pnum
);
898 /* Realloc the size of parameters and data we will return */
899 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
900 /* Extended response is 32 more byyes. */
905 params
= nttrans_realloc(ppparams
, param_len
);
907 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
912 SCVAL(p
,0,NO_OPLOCK_RETURN
);
917 SIVAL(p
,0,FILE_WAS_OPENED
);
921 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
924 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
926 SSVAL(p
,2, 0x5FF); /* ? */
929 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
931 SIVAL(p
,0,FILE_GENERIC_ALL
);
933 * For pipes W2K3 seems to return
935 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
937 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
940 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
942 /* Send the required number of replies */
943 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
948 /****************************************************************************
949 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
950 ****************************************************************************/
952 static void call_nt_transact_create(connection_struct
*conn
,
953 struct smb_request
*req
,
954 uint16_t **ppsetup
, uint32_t setup_count
,
955 char **ppparams
, uint32_t parameter_count
,
956 char **ppdata
, uint32_t data_count
,
957 uint32_t max_data_count
)
959 struct smb_filename
*smb_fname
= NULL
;
961 char *params
= *ppparams
;
962 char *data
= *ppdata
;
963 /* Breakout the oplock request bits so we can set the reply bits separately. */
967 struct files_struct
*dirfsp
= NULL
;
968 files_struct
*fsp
= NULL
;
971 uint32_t access_mask
;
972 uint32_t file_attributes
;
973 uint32_t share_access
;
974 uint32_t create_disposition
;
975 uint32_t create_options
;
977 struct security_descriptor
*sd
= NULL
;
979 uint16_t root_dir_fid
;
980 struct timespec create_timespec
;
981 struct timespec c_timespec
;
982 struct timespec a_timespec
;
983 struct timespec m_timespec
;
984 struct ea_list
*ea_list
= NULL
;
987 uint64_t allocation_size
;
989 uint8_t oplock_granted
;
990 struct case_semantics_state
*case_state
= NULL
;
993 TALLOC_CTX
*ctx
= talloc_tos();
995 DEBUG(5,("call_nt_transact_create\n"));
998 * If it's an IPC, use the pipe handler.
1002 if (lp_nt_pipe_support()) {
1003 do_nt_transact_create_pipe(
1005 ppsetup
, setup_count
,
1006 ppparams
, parameter_count
,
1007 ppdata
, data_count
);
1010 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1015 * Ensure minimum number of parameters sent.
1018 if(parameter_count
< 54) {
1019 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1020 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1024 flags
= IVAL(params
,0);
1025 access_mask
= IVAL(params
,8);
1026 file_attributes
= IVAL(params
,20);
1027 share_access
= IVAL(params
,24);
1028 create_disposition
= IVAL(params
,28);
1029 create_options
= IVAL(params
,32);
1030 sd_len
= IVAL(params
,36);
1031 ea_len
= IVAL(params
,40);
1032 root_dir_fid
= (uint16_t)IVAL(params
,4);
1033 allocation_size
= BVAL(params
,12);
1036 * we need to remove ignored bits when they come directly from the client
1037 * because we reuse some of them for internal stuff
1039 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1041 if (req
->posix_pathnames
) {
1042 srvstr_get_path_posix(ctx
,
1051 srvstr_get_path(ctx
,
1060 if (!NT_STATUS_IS_OK(status
)) {
1061 reply_nterror(req
, status
);
1065 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1066 case_state
= set_posix_case_semantics(ctx
, conn
);
1068 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1073 if (root_dir_fid
!= 0) {
1074 char *new_fname
= NULL
;
1076 status
= get_relative_fid_filename(conn
,
1081 if (!NT_STATUS_IS_OK(status
)) {
1082 reply_nterror(req
, status
);
1088 ucf_flags
= filename_create_ucf_flags(req
, create_disposition
);
1089 if (ucf_flags
& UCF_GMT_PATHNAME
) {
1090 extract_snapshot_token(fname
, &twrp
);
1092 status
= smb1_strip_dfs_path(ctx
, &ucf_flags
, &fname
);
1093 if (!NT_STATUS_IS_OK(status
)) {
1094 reply_nterror(req
, status
);
1098 status
= filename_convert_dirfsp(ctx
,
1106 TALLOC_FREE(case_state
);
1108 if (!NT_STATUS_IS_OK(status
)) {
1109 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1110 reply_botherror(req
,
1111 NT_STATUS_PATH_NOT_COVERED
,
1112 ERRSRV
, ERRbadpath
);
1115 reply_nterror(req
, status
);
1119 /* Ensure the data_len is correct for the sd and ea values given. */
1120 if ((ea_len
+ sd_len
> data_count
)
1121 || (ea_len
> data_count
) || (sd_len
> data_count
)
1122 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1123 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
1124 "%u, data_count = %u\n", (unsigned int)ea_len
,
1125 (unsigned int)sd_len
, (unsigned int)data_count
));
1126 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1131 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1134 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
1136 if (!NT_STATUS_IS_OK(status
)) {
1137 DEBUG(10, ("call_nt_transact_create: "
1138 "unmarshall_sec_desc failed: %s\n",
1139 nt_errstr(status
)));
1140 reply_nterror(req
, status
);
1146 if (!lp_ea_support(SNUM(conn
))) {
1147 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1148 "EA's not supported.\n",
1149 (unsigned int)ea_len
));
1150 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1155 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1156 "too small (should be more than 10)\n",
1157 (unsigned int)ea_len
));
1158 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1162 /* We have already checked that ea_len <= data_count here. */
1163 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
1165 if (ea_list
== NULL
) {
1166 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1170 if (!req
->posix_pathnames
&&
1171 ea_list_has_invalid_name(ea_list
)) {
1172 /* Realloc the size of parameters and data we will return */
1173 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1174 /* Extended response is 32 more bytes. */
1179 params
= nttrans_realloc(ppparams
, param_len
);
1180 if(params
== NULL
) {
1181 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1185 memset(params
, '\0', param_len
);
1186 send_nt_replies(conn
, req
, STATUS_INVALID_EA_NAME
,
1187 params
, param_len
, NULL
, 0);
1192 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1193 if (oplock_request
) {
1194 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1199 * Bug #6898 - clients using Windows opens should
1200 * never be able to set this attribute into the
1203 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1205 status
= SMB_VFS_CREATE_FILE(
1208 dirfsp
, /* dirfsp */
1209 smb_fname
, /* fname */
1210 access_mask
, /* access_mask */
1211 share_access
, /* share_access */
1212 create_disposition
, /* create_disposition*/
1213 create_options
, /* create_options */
1214 file_attributes
, /* file_attributes */
1215 oplock_request
, /* oplock_request */
1217 allocation_size
, /* allocation_size */
1218 0, /* private_flags */
1220 ea_list
, /* ea_list */
1223 NULL
, NULL
); /* create context */
1225 if(!NT_STATUS_IS_OK(status
)) {
1226 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1227 /* We have re-scheduled this call, no error. */
1230 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
1231 bool ok
= defer_smb1_sharing_violation(req
);
1236 reply_openerror(req
, status
);
1240 /* Ensure we're pointing at the correct stat struct. */
1241 TALLOC_FREE(smb_fname
);
1242 smb_fname
= fsp
->fsp_name
;
1245 * If the caller set the extended oplock request bit
1246 * and we granted one (by whatever means) - set the
1247 * correct bit for extended oplock reply.
1250 if (oplock_request
&&
1251 (lp_fake_oplocks(SNUM(conn
))
1252 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1255 * Exclusive oplock granted
1258 if (flags
& REQUEST_BATCH_OPLOCK
) {
1259 oplock_granted
= BATCH_OPLOCK_RETURN
;
1261 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1263 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1264 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1266 oplock_granted
= NO_OPLOCK_RETURN
;
1269 file_len
= smb_fname
->st
.st_ex_size
;
1271 /* Realloc the size of parameters and data we will return */
1272 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1273 /* Extended response is 32 more byyes. */
1278 params
= nttrans_realloc(ppparams
, param_len
);
1279 if(params
== NULL
) {
1280 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1285 SCVAL(p
, 0, oplock_granted
);
1288 SSVAL(p
,0,fsp
->fnum
);
1290 if ((create_disposition
== FILE_SUPERSEDE
)
1291 && (info
== FILE_WAS_OVERWRITTEN
)) {
1292 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1298 fattr
= fdos_mode(fsp
);
1300 fattr
= FILE_ATTRIBUTE_NORMAL
;
1304 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1305 a_timespec
= smb_fname
->st
.st_ex_atime
;
1306 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1307 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1309 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1310 dos_filetime_timespec(&create_timespec
);
1311 dos_filetime_timespec(&a_timespec
);
1312 dos_filetime_timespec(&m_timespec
);
1313 dos_filetime_timespec(&c_timespec
);
1316 put_long_date_full_timespec(conn
->ts_res
, p
, &create_timespec
); /* create time. */
1318 put_long_date_full_timespec(conn
->ts_res
, p
, &a_timespec
); /* access time */
1320 put_long_date_full_timespec(conn
->ts_res
, p
, &m_timespec
); /* write time */
1322 put_long_date_full_timespec(conn
->ts_res
, p
, &c_timespec
); /* change time */
1324 SIVAL(p
,0,fattr
); /* File Attributes. */
1326 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1328 SOFF_T(p
,0,file_len
);
1330 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1331 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
1332 unsigned int num_streams
= 0;
1333 struct stream_struct
*streams
= NULL
;
1335 if (lp_ea_support(SNUM(conn
))) {
1336 size_t num_names
= 0;
1337 /* Do we have any EA's ? */
1338 status
= get_ea_names_from_fsp(
1339 ctx
, smb_fname
->fsp
, NULL
, &num_names
);
1340 if (NT_STATUS_IS_OK(status
) && num_names
) {
1341 file_status
&= ~NO_EAS
;
1345 status
= vfs_fstreaminfo(smb_fname
->fsp
, ctx
,
1346 &num_streams
, &streams
);
1347 /* There is always one stream, ::$DATA. */
1348 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
1349 file_status
&= ~NO_SUBSTREAMS
;
1351 TALLOC_FREE(streams
);
1352 SSVAL(p
,2,file_status
);
1355 SCVAL(p
,0,fsp
->fsp_flags
.is_directory
? 1 : 0);
1357 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1360 if (fsp
->fsp_flags
.is_directory
||
1361 fsp
->fsp_flags
.can_write
||
1362 can_write_to_fsp(fsp
))
1364 perms
= FILE_GENERIC_ALL
;
1366 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1371 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1372 smb_fname_str_dbg(smb_fname
)));
1374 /* Send the required number of replies */
1375 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1380 /****************************************************************************
1381 Reply to a NT CANCEL request.
1382 conn POINTER CAN BE NULL HERE !
1383 ****************************************************************************/
1385 void reply_ntcancel(struct smb_request
*req
)
1387 struct smbXsrv_connection
*xconn
= req
->xconn
;
1388 struct smbd_server_connection
*sconn
= req
->sconn
;
1392 * Go through and cancel any pending change notifies.
1395 START_PROFILE(SMBntcancel
);
1396 smb1_srv_cancel_sign_response(xconn
);
1397 found
= remove_pending_change_notify_requests_by_mid(sconn
, req
->mid
);
1399 smbd_smb1_brl_finish_by_mid(sconn
, req
->mid
);
1402 DEBUG(3,("reply_ntcancel: cancel called on mid = %llu.\n",
1403 (unsigned long long)req
->mid
));
1405 END_PROFILE(SMBntcancel
);
1409 /****************************************************************************
1410 Reply to a NT rename request.
1411 ****************************************************************************/
1413 void reply_ntrename(struct smb_request
*req
)
1415 connection_struct
*conn
= req
->conn
;
1416 struct files_struct
*src_dirfsp
= NULL
;
1417 struct smb_filename
*smb_fname_old
= NULL
;
1418 struct files_struct
*dst_dirfsp
= NULL
;
1419 struct smb_filename
*smb_fname_new
= NULL
;
1420 char *oldname
= NULL
;
1421 char *newname
= NULL
;
1422 const char *dst_original_lcomp
= NULL
;
1426 uint32_t ucf_flags_src
= ucf_flags_from_smb_request(req
);
1427 NTTIME src_twrp
= 0;
1428 uint32_t ucf_flags_dst
= ucf_flags_from_smb_request(req
);
1429 NTTIME dst_twrp
= 0;
1430 uint16_t rename_type
;
1431 TALLOC_CTX
*ctx
= talloc_tos();
1432 bool stream_rename
= false;
1434 START_PROFILE(SMBntrename
);
1437 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1441 attrs
= SVAL(req
->vwv
+0, 0);
1442 rename_type
= SVAL(req
->vwv
+1, 0);
1444 p
= (const char *)req
->buf
+ 1;
1445 p
+= srvstr_get_path_req(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1447 if (!NT_STATUS_IS_OK(status
)) {
1448 reply_nterror(req
, status
);
1452 if (!req
->posix_pathnames
&& ms_has_wild(oldname
)) {
1453 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1458 p
+= srvstr_get_path_req(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1460 if (!NT_STATUS_IS_OK(status
)) {
1461 reply_nterror(req
, status
);
1465 if (!req
->posix_pathnames
&& ms_has_wild(newname
)) {
1466 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1470 if (!req
->posix_pathnames
) {
1471 /* The newname must begin with a ':' if the
1472 oldname contains a ':'. */
1473 if (strchr_m(oldname
, ':')) {
1474 if (newname
[0] != ':') {
1475 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1478 stream_rename
= true;
1482 if (ucf_flags_src
& UCF_GMT_PATHNAME
) {
1483 extract_snapshot_token(oldname
, &src_twrp
);
1485 status
= smb1_strip_dfs_path(ctx
, &ucf_flags_src
, &oldname
);
1486 if (!NT_STATUS_IS_OK(status
)) {
1487 reply_nterror(req
, status
);
1491 status
= filename_convert_dirfsp(ctx
,
1498 if (!NT_STATUS_IS_OK(status
)) {
1499 if (NT_STATUS_EQUAL(status
,
1500 NT_STATUS_PATH_NOT_COVERED
)) {
1501 reply_botherror(req
,
1502 NT_STATUS_PATH_NOT_COVERED
,
1503 ERRSRV
, ERRbadpath
);
1506 reply_nterror(req
, status
);
1510 if (stream_rename
) {
1512 * No point in calling filename_convert()
1513 * on a raw stream name. It can never find
1514 * the file anyway. Use the same logic as
1515 * SMB2_FILE_RENAME_INFORMATION_INTERNAL
1516 * and generate smb_fname_new directly.
1518 smb_fname_new
= synthetic_smb_fname(talloc_tos(),
1519 smb_fname_old
->base_name
,
1522 smb_fname_old
->twrp
,
1523 smb_fname_old
->flags
);
1524 if (smb_fname_new
== NULL
) {
1525 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1529 if (ucf_flags_dst
& UCF_GMT_PATHNAME
) {
1530 extract_snapshot_token(newname
,
1533 status
= smb1_strip_dfs_path(ctx
, &ucf_flags_dst
, &newname
);
1534 if (!NT_STATUS_IS_OK(status
)) {
1535 reply_nterror(req
, status
);
1538 status
= filename_convert_dirfsp(ctx
,
1545 if (!NT_STATUS_IS_OK(status
)) {
1546 if (NT_STATUS_EQUAL(status
,
1547 NT_STATUS_PATH_NOT_COVERED
)) {
1548 reply_botherror(req
,
1549 NT_STATUS_PATH_NOT_COVERED
,
1550 ERRSRV
, ERRbadpath
);
1553 reply_nterror(req
, status
);
1558 /* Get the last component of the destination for rename_internals(). */
1559 dst_original_lcomp
= get_original_lcomp(ctx
,
1563 if (dst_original_lcomp
== NULL
) {
1564 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1569 DEBUG(3,("reply_ntrename: %s -> %s\n",
1570 smb_fname_str_dbg(smb_fname_old
),
1571 smb_fname_str_dbg(smb_fname_new
)));
1573 switch(rename_type
) {
1574 case RENAME_FLAG_RENAME
:
1575 status
= rename_internals(ctx
,
1587 case RENAME_FLAG_HARD_LINK
:
1588 status
= hardlink_internals(ctx
,
1597 case RENAME_FLAG_COPY
:
1598 status
= copy_internals(ctx
,
1607 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1608 status
= NT_STATUS_INVALID_PARAMETER
;
1611 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1615 if (!NT_STATUS_IS_OK(status
)) {
1616 if (open_was_deferred(req
->xconn
, req
->mid
)) {
1617 /* We have re-scheduled this call. */
1620 if (NT_STATUS_EQUAL(status
, NT_STATUS_SHARING_VIOLATION
)) {
1621 bool ok
= defer_smb1_sharing_violation(req
);
1627 reply_nterror(req
, status
);
1631 reply_smb1_outbuf(req
, 0, 0);
1633 END_PROFILE(SMBntrename
);
1637 /****************************************************************************
1638 Reply to a notify change - queue the request and
1639 don't allow a directory to be opened.
1640 ****************************************************************************/
1642 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1643 NTSTATUS error_code
,
1644 uint8_t *buf
, size_t len
)
1646 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1649 static void call_nt_transact_notify_change(connection_struct
*conn
,
1650 struct smb_request
*req
,
1652 uint32_t setup_count
,
1654 uint32_t parameter_count
,
1655 char **ppdata
, uint32_t data_count
,
1656 uint32_t max_data_count
,
1657 uint32_t max_param_count
)
1659 uint16_t *setup
= *ppsetup
;
1665 if(setup_count
< 6) {
1666 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1670 fsp
= file_fsp(req
, SVAL(setup
,4));
1671 filter
= IVAL(setup
, 0);
1672 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1674 DEBUG(3,("call_nt_transact_notify_change\n"));
1677 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1682 char *filter_string
;
1684 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1685 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1689 DEBUG(3,("call_nt_transact_notify_change: notify change "
1690 "called on %s, filter = %s, recursive = %d\n",
1691 fsp_str_dbg(fsp
), filter_string
, recursive
));
1693 TALLOC_FREE(filter_string
);
1696 if((!fsp
->fsp_flags
.is_directory
) || (conn
!= fsp
->conn
)) {
1697 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1701 if (fsp
->notify
== NULL
) {
1703 status
= change_notify_create(fsp
,
1707 if (!NT_STATUS_IS_OK(status
)) {
1708 DEBUG(10, ("change_notify_create returned %s\n",
1709 nt_errstr(status
)));
1710 reply_nterror(req
, status
);
1715 if (change_notify_fsp_has_changes(fsp
)) {
1718 * We've got changes pending, respond immediately
1722 * TODO: write a torture test to check the filtering behaviour
1726 change_notify_reply(req
,
1730 smbd_smb1_notify_reply
);
1733 * change_notify_reply() above has independently sent its
1740 * No changes pending, queue the request
1743 status
= change_notify_add_request(req
,
1747 smbd_smb1_notify_reply
);
1748 if (!NT_STATUS_IS_OK(status
)) {
1749 reply_nterror(req
, status
);
1754 /****************************************************************************
1755 Reply to an NT transact rename command.
1756 ****************************************************************************/
1758 static void call_nt_transact_rename(connection_struct
*conn
,
1759 struct smb_request
*req
,
1760 uint16_t **ppsetup
, uint32_t setup_count
,
1761 char **ppparams
, uint32_t parameter_count
,
1762 char **ppdata
, uint32_t data_count
,
1763 uint32_t max_data_count
)
1765 char *params
= *ppparams
;
1766 char *new_name
= NULL
;
1767 files_struct
*fsp
= NULL
;
1769 TALLOC_CTX
*ctx
= talloc_tos();
1771 if(parameter_count
< 5) {
1772 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1776 fsp
= file_fsp(req
, SVAL(params
, 0));
1777 if (!check_fsp(conn
, req
, fsp
)) {
1780 if (req
->posix_pathnames
) {
1781 srvstr_get_path_posix(ctx
,
1786 parameter_count
- 4,
1790 srvstr_get_path(ctx
,
1795 parameter_count
- 4,
1800 if (!NT_STATUS_IS_OK(status
)) {
1801 reply_nterror(req
, status
);
1806 * W2K3 ignores this request as the RAW-RENAME test
1807 * demonstrates, so we do.
1809 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1811 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1812 fsp_str_dbg(fsp
), new_name
));
1817 /****************************************************************************
1818 SMB1 reply to query a security descriptor.
1819 ****************************************************************************/
1821 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1822 struct smb_request
*req
,
1824 uint32_t setup_count
,
1826 uint32_t parameter_count
,
1828 uint32_t data_count
,
1829 uint32_t max_data_count
)
1831 char *params
= *ppparams
;
1832 char *data
= *ppdata
;
1834 uint32_t security_info_wanted
;
1835 files_struct
*fsp
= NULL
;
1837 uint8_t *marshalled_sd
= NULL
;
1839 if(parameter_count
< 8) {
1840 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1844 fsp
= file_fsp(req
, SVAL(params
,0));
1846 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1850 security_info_wanted
= IVAL(params
,4);
1852 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1853 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
1854 (unsigned int)security_info_wanted
));
1856 params
= nttrans_realloc(ppparams
, 4);
1857 if(params
== NULL
) {
1858 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1863 * Get the permissions to return.
1866 status
= smbd_do_query_security_desc(conn
,
1869 security_info_wanted
&
1870 SMB_SUPPORTED_SECINFO_FLAGS
,
1875 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
1876 SIVAL(params
,0,(uint32_t)sd_size
);
1877 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1878 params
, 4, NULL
, 0);
1882 if (!NT_STATUS_IS_OK(status
)) {
1883 reply_nterror(req
, status
);
1887 SMB_ASSERT(sd_size
> 0);
1889 SIVAL(params
,0,(uint32_t)sd_size
);
1891 if (max_data_count
< sd_size
) {
1892 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1893 params
, 4, NULL
, 0);
1898 * Allocate the data we will return.
1901 data
= nttrans_realloc(ppdata
, sd_size
);
1903 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1907 memcpy(data
, marshalled_sd
, sd_size
);
1909 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1914 /****************************************************************************
1915 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1916 ****************************************************************************/
1918 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1919 struct smb_request
*req
,
1921 uint32_t setup_count
,
1923 uint32_t parameter_count
,
1925 uint32_t data_count
,
1926 uint32_t max_data_count
)
1928 char *params
= *ppparams
;
1929 char *data
= *ppdata
;
1930 files_struct
*fsp
= NULL
;
1931 uint32_t security_info_sent
= 0;
1934 if(parameter_count
< 8) {
1935 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1939 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1940 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1944 if (!CAN_WRITE(fsp
->conn
)) {
1945 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1949 if(!lp_nt_acl_support(SNUM(conn
))) {
1953 security_info_sent
= IVAL(params
,4);
1955 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1956 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
1958 if (data_count
== 0) {
1959 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1963 status
= set_sd_blob(fsp
, (uint8_t *)data
, data_count
,
1964 security_info_sent
& SMB_SUPPORTED_SECINFO_FLAGS
);
1965 if (!NT_STATUS_IS_OK(status
)) {
1966 reply_nterror(req
, status
);
1971 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1975 /****************************************************************************
1977 ****************************************************************************/
1979 static void call_nt_transact_ioctl(connection_struct
*conn
,
1980 struct smb_request
*req
,
1981 uint16_t **ppsetup
, uint32_t setup_count
,
1982 char **ppparams
, uint32_t parameter_count
,
1983 char **ppdata
, uint32_t data_count
,
1984 uint32_t max_data_count
)
1992 char *out_data
= NULL
;
1993 uint32_t out_data_len
= 0;
1994 char *pdata
= *ppdata
;
1995 TALLOC_CTX
*ctx
= talloc_tos();
1997 if (setup_count
!= 8) {
1998 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1999 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2003 function
= IVAL(*ppsetup
, 0);
2004 fidnum
= SVAL(*ppsetup
, 4);
2005 isFSctl
= CVAL(*ppsetup
, 6);
2006 compfilter
= CVAL(*ppsetup
, 7);
2008 DEBUG(10, ("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2009 function
, fidnum
, isFSctl
, compfilter
));
2011 fsp
=file_fsp(req
, fidnum
);
2014 * We don't really implement IOCTLs, especially on files.
2017 DEBUG(10, ("isFSctl: 0x%02X indicates IOCTL, not FSCTL!\n",
2019 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2023 /* Has to be for an open file! */
2024 if (!check_fsp_open(conn
, req
, fsp
)) {
2029 * out_data might be allocated by the VFS module, but talloc should be
2030 * used, and should be cleaned up when the request ends.
2032 status
= SMB_VFS_FSCTL(fsp
,
2038 (uint8_t **)&out_data
,
2041 if (!NT_STATUS_IS_OK(status
)) {
2042 reply_nterror(req
, status
);
2044 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, out_data
, out_data_len
);
2049 #ifdef HAVE_SYS_QUOTAS
2050 /****************************************************************************
2051 Reply to get user quota
2052 ****************************************************************************/
2054 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2055 struct smb_request
*req
,
2057 uint32_t setup_count
,
2059 uint32_t parameter_count
,
2061 uint32_t data_count
,
2062 uint32_t max_data_count
)
2064 const struct loadparm_substitution
*lp_sub
=
2065 loadparm_s3_global_substitution();
2066 NTSTATUS nt_status
= NT_STATUS_OK
;
2067 char *params
= *ppparams
;
2068 char *pdata
= *ppdata
;
2071 files_struct
*fsp
= NULL
;
2072 DATA_BLOB blob
= data_blob_null
;
2073 struct nttrans_query_quota_params info
= {0};
2074 enum ndr_err_code err
;
2075 TALLOC_CTX
*tmp_ctx
= NULL
;
2076 uint32_t resp_len
= 0;
2077 uint8_t *resp_data
= 0;
2079 tmp_ctx
= talloc_init("ntquota_list");
2081 nt_status
= NT_STATUS_NO_MEMORY
;
2086 if (get_current_uid(conn
) != sec_initial_uid()) {
2087 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2088 "[%s]\n", lp_servicename(talloc_tos(), lp_sub
, SNUM(conn
)),
2089 conn
->session_info
->unix_info
->unix_name
));
2090 nt_status
= NT_STATUS_ACCESS_DENIED
;
2094 blob
.data
= (uint8_t*)params
;
2095 blob
.length
= parameter_count
;
2097 err
= ndr_pull_struct_blob(&blob
, tmp_ctx
, &info
,
2098 (ndr_pull_flags_fn_t
)ndr_pull_nttrans_query_quota_params
);
2100 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2101 DEBUG(0,("TRANSACT_GET_USER_QUOTA: failed to pull "
2102 "query_quota_params."));
2103 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2106 DBG_DEBUG("info.return_single_entry = %u, info.restart_scan = %u, "
2107 "info.sid_list_length = %u, info.start_sid_length = %u, "
2108 "info.start_sid_offset = %u\n",
2109 (unsigned int)info
.return_single_entry
,
2110 (unsigned int)info
.restart_scan
,
2111 (unsigned int)info
.sid_list_length
,
2112 (unsigned int)info
.start_sid_length
,
2113 (unsigned int)info
.start_sid_offset
);
2115 /* set blob to point at data for further parsing */
2116 blob
.data
= (uint8_t*)pdata
;
2117 blob
.length
= data_count
;
2119 * Although MS-SMB ref is ambiguous here, a microsoft client will
2120 * only ever send a start sid (as part of a list) with
2121 * sid_list_length & start_sid_offset both set to the actual list
2122 * length. Note: Only a single result is returned in this case
2123 * In the case where either start_sid_offset or start_sid_length
2124 * are set alone or if both set (but have different values) then
2125 * it seems windows will return a number of entries from the start
2126 * of the list of users with quotas set. This behaviour is undocumented
2127 * and windows clients do not send messages of that type. As such we
2128 * currently will reject these requests.
2130 if (info
.start_sid_length
2131 || (info
.sid_list_length
!= info
.start_sid_offset
)) {
2132 DBG_ERR("TRANSACT_GET_USER_QUOTA: unsupported single or "
2133 "compound sid format\n");
2134 nt_status
= NT_STATUS_INVALID_PARAMETER
;
2138 /* maybe we can check the quota_fnum */
2139 fsp
= file_fsp(req
, info
.fid
);
2140 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2141 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2142 nt_status
= NT_STATUS_INVALID_HANDLE
;
2145 nt_status
= smbd_do_query_getinfo_quota(tmp_ctx
,
2148 info
.return_single_entry
,
2149 info
.sid_list_length
,
2154 if (!NT_STATUS_IS_OK(nt_status
)) {
2155 if (!NT_STATUS_EQUAL(nt_status
, NT_STATUS_NO_MORE_ENTRIES
)) {
2158 nt_status
= NT_STATUS_OK
;
2162 params
= nttrans_realloc(ppparams
, param_len
);
2163 if(params
== NULL
) {
2164 nt_status
= NT_STATUS_NO_MEMORY
;
2168 data_len
= resp_len
;
2169 SIVAL(params
, 0, data_len
);
2170 pdata
= nttrans_realloc(ppdata
, data_len
);
2171 memcpy(pdata
, resp_data
, data_len
);
2173 TALLOC_FREE(tmp_ctx
);
2174 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2178 TALLOC_FREE(tmp_ctx
);
2179 reply_nterror(req
, nt_status
);
2182 /****************************************************************************
2183 Reply to set user quota
2184 ****************************************************************************/
2186 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2187 struct smb_request
*req
,
2189 uint32_t setup_count
,
2191 uint32_t parameter_count
,
2193 uint32_t data_count
,
2194 uint32_t max_data_count
)
2196 const struct loadparm_substitution
*lp_sub
=
2197 loadparm_s3_global_substitution();
2198 char *params
= *ppparams
;
2199 char *pdata
= *ppdata
;
2200 int data_len
=0,param_len
=0;
2201 SMB_NTQUOTA_STRUCT qt
;
2202 struct file_quota_information info
= {0};
2203 enum ndr_err_code err
;
2206 files_struct
*fsp
= NULL
;
2207 TALLOC_CTX
*ctx
= NULL
;
2208 NTSTATUS status
= NT_STATUS_OK
;
2212 if (get_current_uid(conn
) != sec_initial_uid()) {
2213 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2214 "[%s]\n", lp_servicename(talloc_tos(), lp_sub
, SNUM(conn
)),
2215 conn
->session_info
->unix_info
->unix_name
));
2216 status
= NT_STATUS_ACCESS_DENIED
;
2221 * Ensure minimum number of parameters sent.
2224 if (parameter_count
< 2) {
2225 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2226 status
= NT_STATUS_INVALID_PARAMETER
;
2230 /* maybe we can check the quota_fnum */
2231 fsp
= file_fsp(req
, SVAL(params
,0));
2232 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2233 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2234 status
= NT_STATUS_INVALID_HANDLE
;
2238 ctx
= talloc_init("set_user_quota");
2240 status
= NT_STATUS_NO_MEMORY
;
2243 inblob
.data
= (uint8_t*)pdata
;
2244 inblob
.length
= data_count
;
2246 err
= ndr_pull_struct_blob(
2250 (ndr_pull_flags_fn_t
)ndr_pull_file_quota_information
);
2252 if (!NDR_ERR_CODE_IS_SUCCESS(err
)) {
2253 DEBUG(0,("TRANSACT_SET_USER_QUOTA: failed to pull "
2254 "file_quota_information\n"));
2255 status
= NT_STATUS_INVALID_PARAMETER
;
2258 qt
.usedspace
= info
.quota_used
;
2260 qt
.softlim
= info
.quota_threshold
;
2262 qt
.hardlim
= info
.quota_limit
;
2266 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2267 status
= NT_STATUS_INTERNAL_ERROR
;
2271 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2277 reply_nterror(req
, status
);
2279 #endif /* HAVE_SYS_QUOTAS */
2281 static void handle_nttrans(connection_struct
*conn
,
2282 struct trans_state
*state
,
2283 struct smb_request
*req
)
2285 struct smbXsrv_connection
*xconn
= req
->xconn
;
2287 if (xconn
->protocol
>= PROTOCOL_NT1
) {
2288 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2289 SSVAL(discard_const_p(uint8_t, req
->inbuf
),smb_flg2
,req
->flags2
);
2293 /* Now we must call the relevant NT_TRANS function */
2294 switch(state
->call
) {
2295 case NT_TRANSACT_CREATE
:
2297 START_PROFILE(NT_transact_create
);
2298 call_nt_transact_create(
2300 &state
->setup
, state
->setup_count
,
2301 &state
->param
, state
->total_param
,
2302 &state
->data
, state
->total_data
,
2303 state
->max_data_return
);
2304 END_PROFILE(NT_transact_create
);
2308 case NT_TRANSACT_IOCTL
:
2310 START_PROFILE(NT_transact_ioctl
);
2311 call_nt_transact_ioctl(
2313 &state
->setup
, state
->setup_count
,
2314 &state
->param
, state
->total_param
,
2315 &state
->data
, state
->total_data
,
2316 state
->max_data_return
);
2317 END_PROFILE(NT_transact_ioctl
);
2321 case NT_TRANSACT_SET_SECURITY_DESC
:
2323 START_PROFILE(NT_transact_set_security_desc
);
2324 call_nt_transact_set_security_desc(
2326 &state
->setup
, state
->setup_count
,
2327 &state
->param
, state
->total_param
,
2328 &state
->data
, state
->total_data
,
2329 state
->max_data_return
);
2330 END_PROFILE(NT_transact_set_security_desc
);
2334 case NT_TRANSACT_NOTIFY_CHANGE
:
2336 START_PROFILE(NT_transact_notify_change
);
2337 call_nt_transact_notify_change(
2339 &state
->setup
, state
->setup_count
,
2340 &state
->param
, state
->total_param
,
2341 &state
->data
, state
->total_data
,
2342 state
->max_data_return
,
2343 state
->max_param_return
);
2344 END_PROFILE(NT_transact_notify_change
);
2348 case NT_TRANSACT_RENAME
:
2350 START_PROFILE(NT_transact_rename
);
2351 call_nt_transact_rename(
2353 &state
->setup
, state
->setup_count
,
2354 &state
->param
, state
->total_param
,
2355 &state
->data
, state
->total_data
,
2356 state
->max_data_return
);
2357 END_PROFILE(NT_transact_rename
);
2361 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2363 START_PROFILE(NT_transact_query_security_desc
);
2364 call_nt_transact_query_security_desc(
2366 &state
->setup
, state
->setup_count
,
2367 &state
->param
, state
->total_param
,
2368 &state
->data
, state
->total_data
,
2369 state
->max_data_return
);
2370 END_PROFILE(NT_transact_query_security_desc
);
2374 #ifdef HAVE_SYS_QUOTAS
2375 case NT_TRANSACT_GET_USER_QUOTA
:
2377 START_PROFILE(NT_transact_get_user_quota
);
2378 call_nt_transact_get_user_quota(
2380 &state
->setup
, state
->setup_count
,
2381 &state
->param
, state
->total_param
,
2382 &state
->data
, state
->total_data
,
2383 state
->max_data_return
);
2384 END_PROFILE(NT_transact_get_user_quota
);
2388 case NT_TRANSACT_SET_USER_QUOTA
:
2390 START_PROFILE(NT_transact_set_user_quota
);
2391 call_nt_transact_set_user_quota(
2393 &state
->setup
, state
->setup_count
,
2394 &state
->param
, state
->total_param
,
2395 &state
->data
, state
->total_data
,
2396 state
->max_data_return
);
2397 END_PROFILE(NT_transact_set_user_quota
);
2400 #endif /* HAVE_SYS_QUOTAS */
2403 /* Error in request */
2404 DEBUG(0,("handle_nttrans: Unknown request %d in "
2405 "nttrans call\n", state
->call
));
2406 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2412 /****************************************************************************
2413 Reply to a SMBNTtrans.
2414 ****************************************************************************/
2416 void reply_nttrans(struct smb_request
*req
)
2418 connection_struct
*conn
= req
->conn
;
2423 uint16_t function_code
;
2425 struct trans_state
*state
;
2427 START_PROFILE(SMBnttrans
);
2429 if (req
->wct
< 19) {
2430 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2431 END_PROFILE(SMBnttrans
);
2435 pscnt
= IVAL(req
->vwv
+9, 1);
2436 psoff
= IVAL(req
->vwv
+11, 1);
2437 dscnt
= IVAL(req
->vwv
+13, 1);
2438 dsoff
= IVAL(req
->vwv
+15, 1);
2439 function_code
= SVAL(req
->vwv
+18, 0);
2441 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2442 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2443 END_PROFILE(SMBnttrans
);
2447 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2448 if (!NT_STATUS_IS_OK(result
)) {
2449 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2450 reply_nterror(req
, result
);
2451 END_PROFILE(SMBnttrans
);
2455 if ((state
= talloc(conn
, struct trans_state
)) == NULL
) {
2456 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2457 END_PROFILE(SMBnttrans
);
2461 state
->cmd
= SMBnttrans
;
2463 state
->mid
= req
->mid
;
2464 state
->vuid
= req
->vuid
;
2465 state
->total_data
= IVAL(req
->vwv
+3, 1);
2467 state
->total_param
= IVAL(req
->vwv
+1, 1);
2468 state
->param
= NULL
;
2469 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2470 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2472 /* setup count is in *words* */
2473 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2474 state
->setup
= NULL
;
2475 state
->call
= function_code
;
2477 DEBUG(10, ("num_setup=%u, "
2478 "param_total=%u, this_param=%u, max_param=%u, "
2479 "data_total=%u, this_data=%u, max_data=%u, "
2480 "param_offset=%u, data_offset=%u\n",
2481 (unsigned)state
->setup_count
,
2482 (unsigned)state
->total_param
, (unsigned)pscnt
,
2483 (unsigned)state
->max_param_return
,
2484 (unsigned)state
->total_data
, (unsigned)dscnt
,
2485 (unsigned)state
->max_data_return
,
2486 (unsigned)psoff
, (unsigned)dsoff
));
2489 * All nttrans messages we handle have smb_wct == 19 +
2490 * state->setup_count. Ensure this is so as a sanity check.
2493 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2494 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2495 req
->wct
, 19 + (state
->setup_count
/2)));
2499 /* Don't allow more than 128mb for each value. */
2500 if ((state
->total_data
> (1024*1024*128)) ||
2501 (state
->total_param
> (1024*1024*128))) {
2502 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2503 END_PROFILE(SMBnttrans
);
2507 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2510 if (state
->total_data
) {
2512 if (smb_buffer_oob(state
->total_data
, 0, dscnt
)
2513 || smb_buffer_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
2517 /* Can't use talloc here, the core routines do realloc on the
2518 * params and data. */
2519 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2520 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2521 "bytes !\n", (unsigned int)state
->total_data
));
2523 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2524 END_PROFILE(SMBnttrans
);
2528 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2531 if (state
->total_param
) {
2533 if (smb_buffer_oob(state
->total_param
, 0, pscnt
)
2534 || smb_buffer_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
2538 /* Can't use talloc here, the core routines do realloc on the
2539 * params and data. */
2540 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2541 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2542 "bytes !\n", (unsigned int)state
->total_param
));
2543 SAFE_FREE(state
->data
);
2545 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2546 END_PROFILE(SMBnttrans
);
2550 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2553 state
->received_data
= dscnt
;
2554 state
->received_param
= pscnt
;
2556 if(state
->setup_count
> 0) {
2557 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2558 state
->setup_count
));
2561 * No overflow possible here, state->setup_count is an
2562 * unsigned int, being filled by a single byte from
2563 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2564 * below is not necessary, it's here to clarify things. The
2565 * validity of req->vwv and req->wct has been checked in
2566 * init_smb1_request already.
2568 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
2572 state
->setup
= (uint16_t *)TALLOC(state
, state
->setup_count
);
2573 if (state
->setup
== NULL
) {
2574 DEBUG(0,("reply_nttrans : Out of memory\n"));
2575 SAFE_FREE(state
->data
);
2576 SAFE_FREE(state
->param
);
2578 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2579 END_PROFILE(SMBnttrans
);
2583 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
2584 dump_data(10, (uint8_t *)state
->setup
, state
->setup_count
);
2587 if ((state
->received_data
== state
->total_data
) &&
2588 (state
->received_param
== state
->total_param
)) {
2589 handle_nttrans(conn
, state
, req
);
2590 SAFE_FREE(state
->param
);
2591 SAFE_FREE(state
->data
);
2593 END_PROFILE(SMBnttrans
);
2597 DLIST_ADD(conn
->pending_trans
, state
);
2599 /* We need to send an interim response then receive the rest
2600 of the parameter/data bytes */
2601 reply_smb1_outbuf(req
, 0, 0);
2602 show_msg((char *)req
->outbuf
);
2603 END_PROFILE(SMBnttrans
);
2608 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2609 SAFE_FREE(state
->data
);
2610 SAFE_FREE(state
->param
);
2612 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2613 END_PROFILE(SMBnttrans
);
2617 /****************************************************************************
2618 Reply to a SMBnttranss
2619 ****************************************************************************/
2621 void reply_nttranss(struct smb_request
*req
)
2623 connection_struct
*conn
= req
->conn
;
2624 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2625 struct trans_state
*state
;
2627 START_PROFILE(SMBnttranss
);
2629 show_msg((const char *)req
->inbuf
);
2631 /* Windows clients expect all replies to
2632 an NT transact secondary (SMBnttranss 0xA1)
2633 to have a command code of NT transact
2634 (SMBnttrans 0xA0). See bug #8989 for details. */
2635 req
->cmd
= SMBnttrans
;
2637 if (req
->wct
< 18) {
2638 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2639 END_PROFILE(SMBnttranss
);
2643 for (state
= conn
->pending_trans
; state
!= NULL
;
2644 state
= state
->next
) {
2645 if (state
->mid
== req
->mid
) {
2650 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2651 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2652 END_PROFILE(SMBnttranss
);
2656 /* Revise state->total_param and state->total_data in case they have
2657 changed downwards */
2658 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
2659 state
->total_param
= IVAL(req
->vwv
+1, 1);
2661 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
2662 state
->total_data
= IVAL(req
->vwv
+3, 1);
2665 pcnt
= IVAL(req
->vwv
+5, 1);
2666 poff
= IVAL(req
->vwv
+7, 1);
2667 pdisp
= IVAL(req
->vwv
+9, 1);
2669 dcnt
= IVAL(req
->vwv
+11, 1);
2670 doff
= IVAL(req
->vwv
+13, 1);
2671 ddisp
= IVAL(req
->vwv
+15, 1);
2673 state
->received_param
+= pcnt
;
2674 state
->received_data
+= dcnt
;
2676 if ((state
->received_data
> state
->total_data
) ||
2677 (state
->received_param
> state
->total_param
))
2681 if (smb_buffer_oob(state
->total_param
, pdisp
, pcnt
)
2682 || smb_buffer_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
2685 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
2689 if (smb_buffer_oob(state
->total_data
, ddisp
, dcnt
)
2690 || smb_buffer_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
2693 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
2696 if ((state
->received_param
< state
->total_param
) ||
2697 (state
->received_data
< state
->total_data
)) {
2698 END_PROFILE(SMBnttranss
);
2702 handle_nttrans(conn
, state
, req
);
2704 DLIST_REMOVE(conn
->pending_trans
, state
);
2705 SAFE_FREE(state
->data
);
2706 SAFE_FREE(state
->param
);
2708 END_PROFILE(SMBnttranss
);
2713 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2714 DLIST_REMOVE(conn
->pending_trans
, state
);
2715 SAFE_FREE(state
->data
);
2716 SAFE_FREE(state
->param
);
2718 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2719 END_PROFILE(SMBnttranss
);