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"
31 #include "smbprofile.h"
32 #include "libsmb/libsmb.h"
34 extern const struct generic_mapping file_generic_mapping
;
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 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 smbd_server_connection
*sconn
= req
->sconn
;
71 int max_send
= sconn
->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_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 (!srv_send_smb(sconn
,
89 IS_CONN_ENCRYPTED(conn
),
91 exit_server_cleanly("send_nt_replies: srv_send_smb 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_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 (!srv_send_smb(sconn
,
253 IS_CONN_ENCRYPTED(conn
),
255 exit_server_cleanly("send_nt_replies: srv_send_smb 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
, int *ppnum
)
288 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
290 /* Strip \\ off the name. */
293 status
= open_np_file(req
, fname
, &fsp
);
294 if (!NT_STATUS_IS_OK(status
)) {
295 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
296 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
300 reply_nterror(req
, status
);
308 /****************************************************************************
309 Reply to an NT create and X call for pipes.
310 ****************************************************************************/
312 static void do_ntcreate_pipe_open(connection_struct
*conn
,
313 struct smb_request
*req
)
318 uint32 flags
= IVAL(req
->vwv
+3, 1);
319 TALLOC_CTX
*ctx
= talloc_tos();
321 srvstr_pull_req_talloc(ctx
, req
, &fname
, req
->buf
, STR_TERMINATE
);
324 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
328 nt_open_pipe(fname
, conn
, req
, &pnum
);
336 * Deal with pipe return.
339 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
340 /* This is very strange. We
341 * return 50 words, but only set
342 * the wcnt to 42 ? It's definately
343 * what happens on the wire....
345 reply_outbuf(req
, 50, 0);
346 SCVAL(req
->outbuf
,smb_wct
,42);
348 reply_outbuf(req
, 34, 0);
351 p
= (char *)req
->outbuf
+ smb_vwv2
;
355 SIVAL(p
,0,FILE_WAS_OPENED
);
358 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
361 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
363 SSVAL(p
,2, 0x5FF); /* ? */
366 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
368 SIVAL(p
,0,FILE_GENERIC_ALL
);
370 * For pipes W2K3 seems to return
372 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
374 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
377 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
382 struct case_semantics_state
{
383 connection_struct
*conn
;
386 bool short_case_preserve
;
389 /****************************************************************************
390 Restore case semantics.
391 ****************************************************************************/
393 static int restore_case_semantics(struct case_semantics_state
*state
)
395 state
->conn
->case_sensitive
= state
->case_sensitive
;
396 state
->conn
->case_preserve
= state
->case_preserve
;
397 state
->conn
->short_case_preserve
= state
->short_case_preserve
;
401 /****************************************************************************
403 ****************************************************************************/
405 static struct case_semantics_state
*set_posix_case_semantics(TALLOC_CTX
*mem_ctx
,
406 connection_struct
*conn
)
408 struct case_semantics_state
*result
;
410 if (!(result
= talloc(mem_ctx
, struct case_semantics_state
))) {
415 result
->case_sensitive
= conn
->case_sensitive
;
416 result
->case_preserve
= conn
->case_preserve
;
417 result
->short_case_preserve
= conn
->short_case_preserve
;
420 conn
->case_sensitive
= True
;
421 conn
->case_preserve
= True
;
422 conn
->short_case_preserve
= True
;
424 talloc_set_destructor(result
, restore_case_semantics
);
429 /****************************************************************************
430 Reply to an NT create and X call.
431 ****************************************************************************/
433 void reply_ntcreate_and_X(struct smb_request
*req
)
435 connection_struct
*conn
= req
->conn
;
436 struct smb_filename
*smb_fname
= NULL
;
440 uint32 file_attributes
;
442 uint32 create_disposition
;
443 uint32 create_options
;
445 uint64_t allocation_size
;
446 /* Breakout the oplock request bits so we can set the
447 reply bits separately. */
449 SMB_OFF_T file_len
= 0;
451 files_struct
*fsp
= NULL
;
453 struct timespec create_timespec
;
454 struct timespec c_timespec
;
455 struct timespec a_timespec
;
456 struct timespec m_timespec
;
457 struct timespec write_time_ts
;
460 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
461 struct case_semantics_state
*case_state
= NULL
;
462 TALLOC_CTX
*ctx
= talloc_tos();
464 START_PROFILE(SMBntcreateX
);
467 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
471 flags
= IVAL(req
->vwv
+3, 1);
472 access_mask
= IVAL(req
->vwv
+7, 1);
473 file_attributes
= IVAL(req
->vwv
+13, 1);
474 share_access
= IVAL(req
->vwv
+15, 1);
475 create_disposition
= IVAL(req
->vwv
+17, 1);
476 create_options
= IVAL(req
->vwv
+19, 1);
477 root_dir_fid
= (uint16
)IVAL(req
->vwv
+5, 1);
479 allocation_size
= BVAL(req
->vwv
+9, 1);
481 srvstr_get_path_req(ctx
, req
, &fname
, (const char *)req
->buf
,
482 STR_TERMINATE
, &status
);
484 if (!NT_STATUS_IS_OK(status
)) {
485 reply_nterror(req
, status
);
489 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
490 "file_attributes = 0x%x, share_access = 0x%x, "
491 "create_disposition = 0x%x create_options = 0x%x "
492 "root_dir_fid = 0x%x, fname = %s\n",
494 (unsigned int)access_mask
,
495 (unsigned int)file_attributes
,
496 (unsigned int)share_access
,
497 (unsigned int)create_disposition
,
498 (unsigned int)create_options
,
499 (unsigned int)root_dir_fid
,
503 * we need to remove ignored bits when they come directly from the client
504 * because we reuse some of them for internal stuff
506 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
509 * If it's an IPC, use the pipe handler.
513 if (lp_nt_pipe_support()) {
514 do_ntcreate_pipe_open(conn
, req
);
517 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
521 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
522 if (oplock_request
) {
523 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
527 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
528 case_state
= set_posix_case_semantics(ctx
, conn
);
530 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
535 status
= filename_convert(ctx
,
537 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
543 TALLOC_FREE(case_state
);
545 if (!NT_STATUS_IS_OK(status
)) {
546 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
548 NT_STATUS_PATH_NOT_COVERED
,
552 reply_nterror(req
, status
);
557 * Bug #6898 - clients using Windows opens should
558 * never be able to set this attribute into the
561 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
563 status
= SMB_VFS_CREATE_FILE(
566 root_dir_fid
, /* root_dir_fid */
567 smb_fname
, /* fname */
568 access_mask
, /* access_mask */
569 share_access
, /* share_access */
570 create_disposition
, /* create_disposition*/
571 create_options
, /* create_options */
572 file_attributes
, /* file_attributes */
573 oplock_request
, /* oplock_request */
574 allocation_size
, /* allocation_size */
575 0, /* private_flags */
581 if (!NT_STATUS_IS_OK(status
)) {
582 if (open_was_deferred(req
->mid
)) {
583 /* We have re-scheduled this call, no error. */
586 reply_openerror(req
, status
);
590 /* Ensure we're pointing at the correct stat struct. */
591 TALLOC_FREE(smb_fname
);
592 smb_fname
= fsp
->fsp_name
;
595 * If the caller set the extended oplock request bit
596 * and we granted one (by whatever means) - set the
597 * correct bit for extended oplock reply.
600 if (oplock_request
&&
601 (lp_fake_oplocks(SNUM(conn
))
602 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
605 * Exclusive oplock granted
608 if (flags
& REQUEST_BATCH_OPLOCK
) {
609 oplock_granted
= BATCH_OPLOCK_RETURN
;
611 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
613 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
614 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
616 oplock_granted
= NO_OPLOCK_RETURN
;
619 file_len
= smb_fname
->st
.st_ex_size
;
621 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
622 /* This is very strange. We
623 * return 50 words, but only set
624 * the wcnt to 42 ? It's definately
625 * what happens on the wire....
627 reply_outbuf(req
, 50, 0);
628 SCVAL(req
->outbuf
,smb_wct
,42);
630 reply_outbuf(req
, 34, 0);
633 p
= (char *)req
->outbuf
+ smb_vwv2
;
635 SCVAL(p
, 0, oplock_granted
);
638 SSVAL(p
,0,fsp
->fnum
);
640 if ((create_disposition
== FILE_SUPERSEDE
)
641 && (info
== FILE_WAS_OVERWRITTEN
)) {
642 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
648 fattr
= dos_mode(conn
, smb_fname
);
650 fattr
= FILE_ATTRIBUTE_NORMAL
;
653 /* Deal with other possible opens having a modified
655 ZERO_STRUCT(write_time_ts
);
656 get_file_infos(fsp
->file_id
, 0, NULL
, &write_time_ts
);
657 if (!null_timespec(write_time_ts
)) {
658 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
662 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
663 a_timespec
= smb_fname
->st
.st_ex_atime
;
664 m_timespec
= smb_fname
->st
.st_ex_mtime
;
665 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
667 if (lp_dos_filetime_resolution(SNUM(conn
))) {
668 dos_filetime_timespec(&create_timespec
);
669 dos_filetime_timespec(&a_timespec
);
670 dos_filetime_timespec(&m_timespec
);
671 dos_filetime_timespec(&c_timespec
);
674 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
676 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
678 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
680 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
682 SIVAL(p
,0,fattr
); /* File Attributes. */
684 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
686 SOFF_T(p
,0,file_len
);
688 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
689 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
690 size_t num_names
= 0;
691 unsigned int num_streams
= 0;
692 struct stream_struct
*streams
= NULL
;
694 /* Do we have any EA's ? */
695 status
= get_ea_names_from_file(ctx
, conn
, fsp
,
696 smb_fname
->base_name
, NULL
, &num_names
);
697 if (NT_STATUS_IS_OK(status
) && num_names
) {
698 file_status
&= ~NO_EAS
;
700 status
= vfs_streaminfo(conn
, NULL
, smb_fname
->base_name
, ctx
,
701 &num_streams
, &streams
);
702 /* There is always one stream, ::$DATA. */
703 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
704 file_status
&= ~NO_SUBSTREAMS
;
706 TALLOC_FREE(streams
);
707 SSVAL(p
,2,file_status
);
710 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
712 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
715 if (fsp
->is_directory
||
716 can_write_to_file(conn
, smb_fname
)) {
717 perms
= FILE_GENERIC_ALL
;
719 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
724 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
725 fsp
->fnum
, smb_fname_str_dbg(smb_fname
)));
729 END_PROFILE(SMBntcreateX
);
733 /****************************************************************************
734 Reply to a NT_TRANSACT_CREATE call to open a pipe.
735 ****************************************************************************/
737 static void do_nt_transact_create_pipe(connection_struct
*conn
,
738 struct smb_request
*req
,
739 uint16
**ppsetup
, uint32 setup_count
,
740 char **ppparams
, uint32 parameter_count
,
741 char **ppdata
, uint32 data_count
)
744 char *params
= *ppparams
;
750 TALLOC_CTX
*ctx
= talloc_tos();
753 * Ensure minimum number of parameters sent.
756 if(parameter_count
< 54) {
757 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
758 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
762 flags
= IVAL(params
,0);
764 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
765 parameter_count
-53, STR_TERMINATE
,
767 if (!NT_STATUS_IS_OK(status
)) {
768 reply_nterror(req
, status
);
772 nt_open_pipe(fname
, conn
, req
, &pnum
);
779 /* Realloc the size of parameters and data we will return */
780 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
781 /* Extended response is 32 more byyes. */
786 params
= nttrans_realloc(ppparams
, param_len
);
788 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
793 SCVAL(p
,0,NO_OPLOCK_RETURN
);
798 SIVAL(p
,0,FILE_WAS_OPENED
);
802 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
805 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
807 SSVAL(p
,2, 0x5FF); /* ? */
810 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
812 SIVAL(p
,0,FILE_GENERIC_ALL
);
814 * For pipes W2K3 seems to return
816 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
818 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
821 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
823 /* Send the required number of replies */
824 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
829 /*********************************************************************
830 Windows seems to do canonicalization of inheritance bits. Do the
832 *********************************************************************/
834 static void canonicalize_inheritance_bits(struct security_descriptor
*psd
)
836 bool set_auto_inherited
= false;
839 * We need to filter out the
840 * SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ
841 * bits. If both are set we store SEC_DESC_DACL_AUTO_INHERITED
842 * as this alters whether SEC_ACE_FLAG_INHERITED_ACE is set
843 * when an ACE is inherited. Otherwise we zero these bits out.
846 * http://social.msdn.microsoft.com/Forums/eu/os_fileservices/thread/11f77b68-731e-407d-b1b3-064750716531
851 if ((psd
->type
& (SEC_DESC_DACL_AUTO_INHERITED
|SEC_DESC_DACL_AUTO_INHERIT_REQ
))
852 == (SEC_DESC_DACL_AUTO_INHERITED
|SEC_DESC_DACL_AUTO_INHERIT_REQ
)) {
853 set_auto_inherited
= true;
856 psd
->type
&= ~(SEC_DESC_DACL_AUTO_INHERITED
|SEC_DESC_DACL_AUTO_INHERIT_REQ
);
857 if (set_auto_inherited
) {
858 psd
->type
|= SEC_DESC_DACL_AUTO_INHERITED
;
862 /****************************************************************************
863 Internal fn to set security descriptors.
864 ****************************************************************************/
866 NTSTATUS
set_sd(files_struct
*fsp
, struct security_descriptor
*psd
,
867 uint32_t security_info_sent
)
871 if (!CAN_WRITE(fsp
->conn
)) {
872 return NT_STATUS_ACCESS_DENIED
;
875 if (!lp_nt_acl_support(SNUM(fsp
->conn
))) {
879 if (psd
->owner_sid
== NULL
) {
880 security_info_sent
&= ~SECINFO_OWNER
;
882 if (psd
->group_sid
== NULL
) {
883 security_info_sent
&= ~SECINFO_GROUP
;
886 /* Ensure we have at least one thing set. */
887 if ((security_info_sent
& (SECINFO_OWNER
|SECINFO_GROUP
|SECINFO_DACL
|SECINFO_SACL
)) == 0) {
892 /* Ensure we have the rights to do this. */
893 if (security_info_sent
& SECINFO_OWNER
) {
894 if (!(fsp
->access_mask
& SEC_STD_WRITE_OWNER
)) {
895 return NT_STATUS_ACCESS_DENIED
;
899 if (security_info_sent
& SECINFO_GROUP
) {
900 if (!(fsp
->access_mask
& SEC_STD_WRITE_OWNER
)) {
901 return NT_STATUS_ACCESS_DENIED
;
905 if (security_info_sent
& SECINFO_DACL
) {
906 if (!(fsp
->access_mask
& SEC_STD_WRITE_DAC
)) {
907 return NT_STATUS_ACCESS_DENIED
;
909 /* Convert all the generic bits. */
911 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
915 if (security_info_sent
& SECINFO_SACL
) {
916 if (!(fsp
->access_mask
& SEC_FLAG_SYSTEM_SECURITY
)) {
917 return NT_STATUS_ACCESS_DENIED
;
919 /* Convert all the generic bits. */
921 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
925 canonicalize_inheritance_bits(psd
);
927 if (DEBUGLEVEL
>= 10) {
928 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp
)));
929 NDR_PRINT_DEBUG(security_descriptor
, psd
);
932 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
939 /****************************************************************************
940 Internal fn to set security descriptors from a data blob.
941 ****************************************************************************/
943 NTSTATUS
set_sd_blob(files_struct
*fsp
, uint8_t *data
, uint32_t sd_len
,
944 uint32_t security_info_sent
)
946 struct security_descriptor
*psd
= NULL
;
950 return NT_STATUS_INVALID_PARAMETER
;
953 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
955 if (!NT_STATUS_IS_OK(status
)) {
959 return set_sd(fsp
, psd
, security_info_sent
);
962 /****************************************************************************
963 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
964 ****************************************************************************/
966 struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
968 struct ea_list
*ea_list_head
= NULL
;
975 while (offset
+ 4 <= data_size
) {
976 size_t next_offset
= IVAL(pdata
,offset
);
977 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
983 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
984 if (next_offset
== 0) {
988 /* Integer wrap protection for the increment. */
989 if (offset
+ next_offset
< offset
) {
993 offset
+= next_offset
;
995 /* Integer wrap protection for while loop. */
996 if (offset
+ 4 < offset
) {
1002 return ea_list_head
;
1005 /****************************************************************************
1006 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1007 ****************************************************************************/
1009 static void call_nt_transact_create(connection_struct
*conn
,
1010 struct smb_request
*req
,
1011 uint16
**ppsetup
, uint32 setup_count
,
1012 char **ppparams
, uint32 parameter_count
,
1013 char **ppdata
, uint32 data_count
,
1014 uint32 max_data_count
)
1016 struct smb_filename
*smb_fname
= NULL
;
1018 char *params
= *ppparams
;
1019 char *data
= *ppdata
;
1020 /* Breakout the oplock request bits so we can set the reply bits separately. */
1022 SMB_OFF_T file_len
= 0;
1024 files_struct
*fsp
= NULL
;
1028 uint32 file_attributes
;
1029 uint32 share_access
;
1030 uint32 create_disposition
;
1031 uint32 create_options
;
1033 struct security_descriptor
*sd
= NULL
;
1035 uint16 root_dir_fid
;
1036 struct timespec create_timespec
;
1037 struct timespec c_timespec
;
1038 struct timespec a_timespec
;
1039 struct timespec m_timespec
;
1040 struct timespec write_time_ts
;
1041 struct ea_list
*ea_list
= NULL
;
1044 uint64_t allocation_size
;
1046 uint8_t oplock_granted
;
1047 struct case_semantics_state
*case_state
= NULL
;
1048 TALLOC_CTX
*ctx
= talloc_tos();
1050 DEBUG(5,("call_nt_transact_create\n"));
1053 * If it's an IPC, use the pipe handler.
1057 if (lp_nt_pipe_support()) {
1058 do_nt_transact_create_pipe(
1060 ppsetup
, setup_count
,
1061 ppparams
, parameter_count
,
1062 ppdata
, data_count
);
1065 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1070 * Ensure minimum number of parameters sent.
1073 if(parameter_count
< 54) {
1074 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1075 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1079 flags
= IVAL(params
,0);
1080 access_mask
= IVAL(params
,8);
1081 file_attributes
= IVAL(params
,20);
1082 share_access
= IVAL(params
,24);
1083 create_disposition
= IVAL(params
,28);
1084 create_options
= IVAL(params
,32);
1085 sd_len
= IVAL(params
,36);
1086 ea_len
= IVAL(params
,40);
1087 root_dir_fid
= (uint16
)IVAL(params
,4);
1088 allocation_size
= BVAL(params
,12);
1091 * we need to remove ignored bits when they come directly from the client
1092 * because we reuse some of them for internal stuff
1094 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1096 /* Ensure the data_len is correct for the sd and ea values given. */
1097 if ((ea_len
+ sd_len
> data_count
)
1098 || (ea_len
> data_count
) || (sd_len
> data_count
)
1099 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1100 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
1101 "%u, data_count = %u\n", (unsigned int)ea_len
,
1102 (unsigned int)sd_len
, (unsigned int)data_count
));
1103 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1108 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1111 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
1113 if (!NT_STATUS_IS_OK(status
)) {
1114 DEBUG(10, ("call_nt_transact_create: "
1115 "unmarshall_sec_desc failed: %s\n",
1116 nt_errstr(status
)));
1117 reply_nterror(req
, status
);
1123 if (!lp_ea_support(SNUM(conn
))) {
1124 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1125 "EA's not supported.\n",
1126 (unsigned int)ea_len
));
1127 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1132 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1133 "too small (should be more than 10)\n",
1134 (unsigned int)ea_len
));
1135 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1139 /* We have already checked that ea_len <= data_count here. */
1140 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
1142 if (ea_list
== NULL
) {
1143 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1148 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
1149 params
+53, parameter_count
-53,
1150 STR_TERMINATE
, &status
);
1151 if (!NT_STATUS_IS_OK(status
)) {
1152 reply_nterror(req
, status
);
1156 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1157 case_state
= set_posix_case_semantics(ctx
, conn
);
1159 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1164 status
= filename_convert(ctx
,
1166 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1172 TALLOC_FREE(case_state
);
1174 if (!NT_STATUS_IS_OK(status
)) {
1175 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1176 reply_botherror(req
,
1177 NT_STATUS_PATH_NOT_COVERED
,
1178 ERRSRV
, ERRbadpath
);
1181 reply_nterror(req
, status
);
1185 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1186 if (oplock_request
) {
1187 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1192 * Bug #6898 - clients using Windows opens should
1193 * never be able to set this attribute into the
1196 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1198 status
= SMB_VFS_CREATE_FILE(
1201 root_dir_fid
, /* root_dir_fid */
1202 smb_fname
, /* fname */
1203 access_mask
, /* access_mask */
1204 share_access
, /* share_access */
1205 create_disposition
, /* create_disposition*/
1206 create_options
, /* create_options */
1207 file_attributes
, /* file_attributes */
1208 oplock_request
, /* oplock_request */
1209 allocation_size
, /* allocation_size */
1210 0, /* private_flags */
1212 ea_list
, /* ea_list */
1216 if(!NT_STATUS_IS_OK(status
)) {
1217 if (open_was_deferred(req
->mid
)) {
1218 /* We have re-scheduled this call, no error. */
1221 reply_openerror(req
, status
);
1225 /* Ensure we're pointing at the correct stat struct. */
1226 TALLOC_FREE(smb_fname
);
1227 smb_fname
= fsp
->fsp_name
;
1230 * If the caller set the extended oplock request bit
1231 * and we granted one (by whatever means) - set the
1232 * correct bit for extended oplock reply.
1235 if (oplock_request
&&
1236 (lp_fake_oplocks(SNUM(conn
))
1237 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1240 * Exclusive oplock granted
1243 if (flags
& REQUEST_BATCH_OPLOCK
) {
1244 oplock_granted
= BATCH_OPLOCK_RETURN
;
1246 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1248 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1249 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1251 oplock_granted
= NO_OPLOCK_RETURN
;
1254 file_len
= smb_fname
->st
.st_ex_size
;
1256 /* Realloc the size of parameters and data we will return */
1257 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1258 /* Extended response is 32 more byyes. */
1263 params
= nttrans_realloc(ppparams
, param_len
);
1264 if(params
== NULL
) {
1265 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1270 SCVAL(p
, 0, oplock_granted
);
1273 SSVAL(p
,0,fsp
->fnum
);
1275 if ((create_disposition
== FILE_SUPERSEDE
)
1276 && (info
== FILE_WAS_OVERWRITTEN
)) {
1277 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1283 fattr
= dos_mode(conn
, smb_fname
);
1285 fattr
= FILE_ATTRIBUTE_NORMAL
;
1288 /* Deal with other possible opens having a modified
1290 ZERO_STRUCT(write_time_ts
);
1291 get_file_infos(fsp
->file_id
, 0, NULL
, &write_time_ts
);
1292 if (!null_timespec(write_time_ts
)) {
1293 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
1297 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1298 a_timespec
= smb_fname
->st
.st_ex_atime
;
1299 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1300 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1302 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1303 dos_filetime_timespec(&create_timespec
);
1304 dos_filetime_timespec(&a_timespec
);
1305 dos_filetime_timespec(&m_timespec
);
1306 dos_filetime_timespec(&c_timespec
);
1309 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
1311 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
1313 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
1315 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
1317 SIVAL(p
,0,fattr
); /* File Attributes. */
1319 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1321 SOFF_T(p
,0,file_len
);
1323 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1324 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
1325 size_t num_names
= 0;
1326 unsigned int num_streams
= 0;
1327 struct stream_struct
*streams
= NULL
;
1329 /* Do we have any EA's ? */
1330 status
= get_ea_names_from_file(ctx
, conn
, fsp
,
1331 smb_fname
->base_name
, NULL
, &num_names
);
1332 if (NT_STATUS_IS_OK(status
) && num_names
) {
1333 file_status
&= ~NO_EAS
;
1335 status
= vfs_streaminfo(conn
, NULL
, smb_fname
->base_name
, ctx
,
1336 &num_streams
, &streams
);
1337 /* There is always one stream, ::$DATA. */
1338 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
1339 file_status
&= ~NO_SUBSTREAMS
;
1341 TALLOC_FREE(streams
);
1342 SSVAL(p
,2,file_status
);
1345 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1347 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1350 if (fsp
->is_directory
||
1351 can_write_to_file(conn
, smb_fname
)) {
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
)
1376 * Go through and cancel any pending change notifies.
1379 START_PROFILE(SMBntcancel
);
1380 srv_cancel_sign_response(req
->sconn
);
1381 remove_pending_change_notify_requests_by_mid(req
->sconn
, req
->mid
);
1382 remove_pending_lock_requests_by_mid_smb1(req
->sconn
, req
->mid
);
1384 DEBUG(3,("reply_ntcancel: cancel called on mid = %llu.\n",
1385 (unsigned long long)req
->mid
));
1387 END_PROFILE(SMBntcancel
);
1391 /****************************************************************************
1393 ****************************************************************************/
1395 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1396 connection_struct
*conn
,
1397 struct smb_request
*req
,
1398 struct smb_filename
*smb_fname_src
,
1399 struct smb_filename
*smb_fname_dst
,
1402 files_struct
*fsp1
,*fsp2
;
1406 NTSTATUS status
= NT_STATUS_OK
;
1409 if (!CAN_WRITE(conn
)) {
1410 status
= NT_STATUS_MEDIA_WRITE_PROTECTED
;
1414 /* Source must already exist. */
1415 if (!VALID_STAT(smb_fname_src
->st
)) {
1416 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1420 /* Ensure attributes match. */
1421 fattr
= dos_mode(conn
, smb_fname_src
);
1422 if ((fattr
& ~attrs
) & (FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
)) {
1423 status
= NT_STATUS_NO_SUCH_FILE
;
1427 /* Disallow if dst file already exists. */
1428 if (VALID_STAT(smb_fname_dst
->st
)) {
1429 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
1433 /* No links from a directory. */
1434 if (S_ISDIR(smb_fname_src
->st
.st_ex_mode
)) {
1435 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
1439 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1440 smb_fname_str_dbg(smb_fname_src
),
1441 smb_fname_str_dbg(smb_fname_dst
)));
1443 status
= SMB_VFS_CREATE_FILE(
1446 0, /* root_dir_fid */
1447 smb_fname_src
, /* fname */
1448 FILE_READ_DATA
|FILE_READ_ATTRIBUTES
|
1449 FILE_READ_EA
, /* access_mask */
1450 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1452 FILE_OPEN
, /* create_disposition*/
1453 0, /* create_options */
1454 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
1455 NO_OPLOCK
, /* oplock_request */
1456 0, /* allocation_size */
1457 0, /* private_flags */
1463 if (!NT_STATUS_IS_OK(status
)) {
1467 status
= SMB_VFS_CREATE_FILE(
1470 0, /* root_dir_fid */
1471 smb_fname_dst
, /* fname */
1472 FILE_WRITE_DATA
|FILE_WRITE_ATTRIBUTES
|
1473 FILE_WRITE_EA
, /* access_mask */
1474 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1476 FILE_CREATE
, /* create_disposition*/
1477 0, /* create_options */
1478 fattr
, /* file_attributes */
1479 NO_OPLOCK
, /* oplock_request */
1480 0, /* allocation_size */
1481 0, /* private_flags */
1487 if (!NT_STATUS_IS_OK(status
)) {
1488 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1492 if (smb_fname_src
->st
.st_ex_size
) {
1493 ret
= vfs_transfer_file(fsp1
, fsp2
, smb_fname_src
->st
.st_ex_size
);
1497 * As we are opening fsp1 read-only we only expect
1498 * an error on close on fsp2 if we are out of space.
1499 * Thus we don't look at the error return from the
1502 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1504 /* Ensure the modtime is set correctly on the destination file. */
1505 set_close_write_time(fsp2
, smb_fname_src
->st
.st_ex_mtime
);
1507 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1509 /* Grrr. We have to do this as open_file_ntcreate adds FILE_ATTRIBUTE_ARCHIVE when it
1510 creates the file. This isn't the correct thing to do in the copy
1512 if (!parent_dirname(talloc_tos(), smb_fname_dst
->base_name
, &parent
,
1514 status
= NT_STATUS_NO_MEMORY
;
1517 file_set_dosmode(conn
, smb_fname_dst
, fattr
, parent
, false);
1518 TALLOC_FREE(parent
);
1520 if (ret
< (SMB_OFF_T
)smb_fname_src
->st
.st_ex_size
) {
1521 status
= NT_STATUS_DISK_FULL
;
1525 if (!NT_STATUS_IS_OK(status
)) {
1526 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1527 nt_errstr(status
), smb_fname_str_dbg(smb_fname_src
),
1528 smb_fname_str_dbg(smb_fname_dst
)));
1534 /****************************************************************************
1535 Reply to a NT rename request.
1536 ****************************************************************************/
1538 void reply_ntrename(struct smb_request
*req
)
1540 connection_struct
*conn
= req
->conn
;
1541 struct smb_filename
*smb_fname_old
= NULL
;
1542 struct smb_filename
*smb_fname_new
= NULL
;
1543 char *oldname
= NULL
;
1544 char *newname
= NULL
;
1547 bool src_has_wcard
= False
;
1548 bool dest_has_wcard
= False
;
1550 uint32_t ucf_flags_src
= 0;
1551 uint32_t ucf_flags_dst
= 0;
1553 TALLOC_CTX
*ctx
= talloc_tos();
1554 bool stream_rename
= false;
1556 START_PROFILE(SMBntrename
);
1559 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1563 attrs
= SVAL(req
->vwv
+0, 0);
1564 rename_type
= SVAL(req
->vwv
+1, 0);
1566 p
= (const char *)req
->buf
+ 1;
1567 p
+= srvstr_get_path_req_wcard(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1568 &status
, &src_has_wcard
);
1569 if (!NT_STATUS_IS_OK(status
)) {
1570 reply_nterror(req
, status
);
1574 if (ms_has_wild(oldname
)) {
1575 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1580 p
+= srvstr_get_path_req_wcard(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1581 &status
, &dest_has_wcard
);
1582 if (!NT_STATUS_IS_OK(status
)) {
1583 reply_nterror(req
, status
);
1587 if (!lp_posix_pathnames()) {
1588 /* The newname must begin with a ':' if the
1589 oldname contains a ':'. */
1590 if (strchr_m(oldname
, ':')) {
1591 if (newname
[0] != ':') {
1592 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1595 stream_rename
= true;
1600 * If this is a rename operation, allow wildcards and save the
1601 * destination's last component.
1603 if (rename_type
== RENAME_FLAG_RENAME
) {
1604 ucf_flags_src
= UCF_COND_ALLOW_WCARD_LCOMP
;
1605 ucf_flags_dst
= UCF_COND_ALLOW_WCARD_LCOMP
| UCF_SAVE_LCOMP
;
1608 /* rename_internals() calls unix_convert(), so don't call it here. */
1609 status
= filename_convert(ctx
, conn
,
1610 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1615 if (!NT_STATUS_IS_OK(status
)) {
1616 if (NT_STATUS_EQUAL(status
,
1617 NT_STATUS_PATH_NOT_COVERED
)) {
1618 reply_botherror(req
,
1619 NT_STATUS_PATH_NOT_COVERED
,
1620 ERRSRV
, ERRbadpath
);
1623 reply_nterror(req
, status
);
1627 status
= filename_convert(ctx
, conn
,
1628 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1633 if (!NT_STATUS_IS_OK(status
)) {
1634 if (NT_STATUS_EQUAL(status
,
1635 NT_STATUS_PATH_NOT_COVERED
)) {
1636 reply_botherror(req
,
1637 NT_STATUS_PATH_NOT_COVERED
,
1638 ERRSRV
, ERRbadpath
);
1641 reply_nterror(req
, status
);
1645 if (stream_rename
) {
1646 /* smb_fname_new must be the same as smb_fname_old. */
1647 TALLOC_FREE(smb_fname_new
->base_name
);
1648 smb_fname_new
->base_name
= talloc_strdup(smb_fname_new
,
1649 smb_fname_old
->base_name
);
1650 if (!smb_fname_new
->base_name
) {
1651 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1656 DEBUG(3,("reply_ntrename: %s -> %s\n",
1657 smb_fname_str_dbg(smb_fname_old
),
1658 smb_fname_str_dbg(smb_fname_new
)));
1660 switch(rename_type
) {
1661 case RENAME_FLAG_RENAME
:
1662 status
= rename_internals(ctx
, conn
, req
,
1663 smb_fname_old
, smb_fname_new
,
1664 attrs
, False
, src_has_wcard
,
1668 case RENAME_FLAG_HARD_LINK
:
1669 if (src_has_wcard
|| dest_has_wcard
) {
1671 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1673 status
= hardlink_internals(ctx
, conn
,
1680 case RENAME_FLAG_COPY
:
1681 if (src_has_wcard
|| dest_has_wcard
) {
1683 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1685 status
= copy_internals(ctx
, conn
, req
,
1691 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1692 status
= NT_STATUS_INVALID_PARAMETER
;
1695 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1699 if (!NT_STATUS_IS_OK(status
)) {
1700 if (open_was_deferred(req
->mid
)) {
1701 /* We have re-scheduled this call. */
1705 reply_nterror(req
, status
);
1709 reply_outbuf(req
, 0, 0);
1711 END_PROFILE(SMBntrename
);
1715 /****************************************************************************
1716 Reply to a notify change - queue the request and
1717 don't allow a directory to be opened.
1718 ****************************************************************************/
1720 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1721 NTSTATUS error_code
,
1722 uint8_t *buf
, size_t len
)
1724 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1727 static void call_nt_transact_notify_change(connection_struct
*conn
,
1728 struct smb_request
*req
,
1732 uint32 parameter_count
,
1733 char **ppdata
, uint32 data_count
,
1734 uint32 max_data_count
,
1735 uint32 max_param_count
)
1737 uint16
*setup
= *ppsetup
;
1743 if(setup_count
< 6) {
1744 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1748 fsp
= file_fsp(req
, SVAL(setup
,4));
1749 filter
= IVAL(setup
, 0);
1750 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1752 DEBUG(3,("call_nt_transact_notify_change\n"));
1755 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1760 char *filter_string
;
1762 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1763 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1767 DEBUG(3,("call_nt_transact_notify_change: notify change "
1768 "called on %s, filter = %s, recursive = %d\n",
1769 fsp_str_dbg(fsp
), filter_string
, recursive
));
1771 TALLOC_FREE(filter_string
);
1774 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1775 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1779 if (fsp
->notify
== NULL
) {
1781 status
= change_notify_create(fsp
, filter
, recursive
);
1783 if (!NT_STATUS_IS_OK(status
)) {
1784 DEBUG(10, ("change_notify_create returned %s\n",
1785 nt_errstr(status
)));
1786 reply_nterror(req
, status
);
1791 if (fsp
->notify
->num_changes
!= 0) {
1794 * We've got changes pending, respond immediately
1798 * TODO: write a torture test to check the filtering behaviour
1802 change_notify_reply(req
,
1806 smbd_smb1_notify_reply
);
1809 * change_notify_reply() above has independently sent its
1816 * No changes pending, queue the request
1819 status
= change_notify_add_request(req
,
1823 smbd_smb1_notify_reply
);
1824 if (!NT_STATUS_IS_OK(status
)) {
1825 reply_nterror(req
, status
);
1830 /****************************************************************************
1831 Reply to an NT transact rename command.
1832 ****************************************************************************/
1834 static void call_nt_transact_rename(connection_struct
*conn
,
1835 struct smb_request
*req
,
1836 uint16
**ppsetup
, uint32 setup_count
,
1837 char **ppparams
, uint32 parameter_count
,
1838 char **ppdata
, uint32 data_count
,
1839 uint32 max_data_count
)
1841 char *params
= *ppparams
;
1842 char *new_name
= NULL
;
1843 files_struct
*fsp
= NULL
;
1844 bool dest_has_wcard
= False
;
1846 TALLOC_CTX
*ctx
= talloc_tos();
1848 if(parameter_count
< 5) {
1849 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1853 fsp
= file_fsp(req
, SVAL(params
, 0));
1854 if (!check_fsp(conn
, req
, fsp
)) {
1857 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1858 parameter_count
- 4,
1859 STR_TERMINATE
, &status
, &dest_has_wcard
);
1860 if (!NT_STATUS_IS_OK(status
)) {
1861 reply_nterror(req
, status
);
1866 * W2K3 ignores this request as the RAW-RENAME test
1867 * demonstrates, so we do.
1869 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1871 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1872 fsp_str_dbg(fsp
), new_name
));
1877 /******************************************************************************
1878 Fake up a completely empty SD.
1879 *******************************************************************************/
1881 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppsd
)
1885 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1887 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1888 return NT_STATUS_NO_MEMORY
;
1891 return NT_STATUS_OK
;
1894 /****************************************************************************
1895 Reply to query a security descriptor.
1896 Callable from SMB2 and SMB2.
1897 If it returns NT_STATUS_BUFFER_TOO_SMALL, pdata_size is initialized with
1899 ****************************************************************************/
1901 NTSTATUS
smbd_do_query_security_desc(connection_struct
*conn
,
1902 TALLOC_CTX
*mem_ctx
,
1904 uint32_t security_info_wanted
,
1905 uint32_t max_data_count
,
1906 uint8_t **ppmarshalled_sd
,
1910 struct security_descriptor
*psd
= NULL
;
1913 * Get the permissions to return.
1916 if ((security_info_wanted
& SECINFO_SACL
) &&
1917 !(fsp
->access_mask
& SEC_FLAG_SYSTEM_SECURITY
)) {
1918 return NT_STATUS_ACCESS_DENIED
;
1921 if ((security_info_wanted
& (SECINFO_DACL
|SECINFO_OWNER
|SECINFO_GROUP
)) &&
1922 !(fsp
->access_mask
& SEC_STD_READ_CONTROL
)) {
1923 return NT_STATUS_ACCESS_DENIED
;
1926 if (security_info_wanted
& (SECINFO_DACL
|SECINFO_OWNER
|
1927 SECINFO_GROUP
|SECINFO_SACL
)) {
1928 /* Don't return SECINFO_LABEL if anything else was
1929 requested. See bug #8458. */
1930 security_info_wanted
&= ~SECINFO_LABEL
;
1933 if (!lp_nt_acl_support(SNUM(conn
))) {
1934 status
= get_null_nt_acl(mem_ctx
, &psd
);
1935 } else if (security_info_wanted
& SECINFO_LABEL
) {
1936 /* Like W2K3 return a null object. */
1937 status
= get_null_nt_acl(mem_ctx
, &psd
);
1939 status
= SMB_VFS_FGET_NT_ACL(
1940 fsp
, security_info_wanted
, &psd
);
1942 if (!NT_STATUS_IS_OK(status
)) {
1946 if (!(security_info_wanted
& SECINFO_OWNER
)) {
1947 psd
->owner_sid
= NULL
;
1949 if (!(security_info_wanted
& SECINFO_GROUP
)) {
1950 psd
->group_sid
= NULL
;
1952 if (!(security_info_wanted
& SECINFO_DACL
)) {
1953 psd
->type
&= ~SEC_DESC_DACL_PRESENT
;
1956 if (!(security_info_wanted
& SECINFO_SACL
)) {
1957 psd
->type
&= ~SEC_DESC_SACL_PRESENT
;
1961 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1962 * present in the reply to match Windows behavior */
1963 if (psd
->sacl
== NULL
&&
1964 security_info_wanted
& SECINFO_SACL
)
1965 psd
->type
|= SEC_DESC_SACL_PRESENT
;
1966 if (psd
->dacl
== NULL
&&
1967 security_info_wanted
& SECINFO_DACL
)
1968 psd
->type
|= SEC_DESC_DACL_PRESENT
;
1970 if (security_info_wanted
& SECINFO_LABEL
) {
1971 /* Like W2K3 return a null object. */
1972 psd
->owner_sid
= NULL
;
1973 psd
->group_sid
= NULL
;
1976 psd
->type
&= ~(SEC_DESC_DACL_PRESENT
|SEC_DESC_SACL_PRESENT
);
1979 *psd_size
= ndr_size_security_descriptor(psd
, 0);
1981 DEBUG(3,("smbd_do_query_security_desc: sd_size = %lu.\n",
1982 (unsigned long)*psd_size
));
1984 if (DEBUGLEVEL
>= 10) {
1985 DEBUG(10,("smbd_do_query_security_desc for file %s\n",
1987 NDR_PRINT_DEBUG(security_descriptor
, psd
);
1990 if (max_data_count
< *psd_size
) {
1992 return NT_STATUS_BUFFER_TOO_SMALL
;
1995 status
= marshall_sec_desc(mem_ctx
, psd
,
1996 ppmarshalled_sd
, psd_size
);
1998 if (!NT_STATUS_IS_OK(status
)) {
2004 return NT_STATUS_OK
;
2007 /****************************************************************************
2008 SMB1 reply to query a security descriptor.
2009 ****************************************************************************/
2011 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
2012 struct smb_request
*req
,
2016 uint32 parameter_count
,
2019 uint32 max_data_count
)
2021 char *params
= *ppparams
;
2022 char *data
= *ppdata
;
2024 uint32 security_info_wanted
;
2025 files_struct
*fsp
= NULL
;
2027 uint8_t *marshalled_sd
= NULL
;
2029 if(parameter_count
< 8) {
2030 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2034 fsp
= file_fsp(req
, SVAL(params
,0));
2036 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2040 security_info_wanted
= IVAL(params
,4);
2042 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
2043 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
2044 (unsigned int)security_info_wanted
));
2046 params
= nttrans_realloc(ppparams
, 4);
2047 if(params
== NULL
) {
2048 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2053 * Get the permissions to return.
2056 status
= smbd_do_query_security_desc(conn
,
2059 security_info_wanted
,
2064 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
2065 SIVAL(params
,0,(uint32_t)sd_size
);
2066 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
2067 params
, 4, NULL
, 0);
2071 if (!NT_STATUS_IS_OK(status
)) {
2072 reply_nterror(req
, status
);
2076 SMB_ASSERT(sd_size
> 0);
2078 SIVAL(params
,0,(uint32_t)sd_size
);
2080 if (max_data_count
< sd_size
) {
2081 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
2082 params
, 4, NULL
, 0);
2087 * Allocate the data we will return.
2090 data
= nttrans_realloc(ppdata
, sd_size
);
2092 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2096 memcpy(data
, marshalled_sd
, sd_size
);
2098 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
2103 /****************************************************************************
2104 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2105 ****************************************************************************/
2107 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
2108 struct smb_request
*req
,
2112 uint32 parameter_count
,
2115 uint32 max_data_count
)
2117 char *params
= *ppparams
;
2118 char *data
= *ppdata
;
2119 files_struct
*fsp
= NULL
;
2120 uint32 security_info_sent
= 0;
2123 if(parameter_count
< 8) {
2124 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2128 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
2129 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2133 if (!CAN_WRITE(fsp
->conn
)) {
2134 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2138 if(!lp_nt_acl_support(SNUM(conn
))) {
2142 security_info_sent
= IVAL(params
,4);
2144 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
2145 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
2147 if (data_count
== 0) {
2148 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2152 status
= set_sd_blob(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
2154 if (!NT_STATUS_IS_OK(status
)) {
2155 reply_nterror(req
, status
);
2160 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2165 * Implement the default fsctl operation.
2168 static bool vfswrap_logged_ioctl_message
= false;
2171 * In 3.6 we do not have a SMB_VFS_FSCTL() function
2172 * it's just faked to make it more look like
2175 NTSTATUS
smb_fsctl(struct files_struct
*fsp
,
2178 uint16_t req_flags
, /* Needed for UNICODE ... */
2179 const uint8_t *_in_data
,
2181 uint8_t **_out_data
,
2182 uint32_t max_out_len
,
2185 const char *in_data
= (const char *)_in_data
;
2186 char **out_data
= (char **)_out_data
;
2189 case FSCTL_SET_SPARSE
:
2191 bool set_sparse
= true;
2194 if (in_len
>= 1 && in_data
[0] == 0) {
2198 status
= file_set_sparse(fsp
->conn
, fsp
, set_sparse
);
2200 DEBUG(NT_STATUS_IS_OK(status
) ? 10 : 9,
2201 ("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
2202 smb_fname_str_dbg(fsp
->fsp_name
), set_sparse
,
2203 nt_errstr(status
)));
2208 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
2210 unsigned char objid
[16];
2211 char *return_data
= NULL
;
2213 /* This should return the object-id on this file.
2214 * I think I'll make this be the inode+dev. JRA.
2217 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fsp
->fnum
));
2219 *out_len
= (max_out_len
>= 64) ? 64 : max_out_len
;
2220 /* Hmmm, will this cause problems if less data asked for? */
2221 return_data
= talloc_array(ctx
, char, 64);
2222 if (return_data
== NULL
) {
2223 return NT_STATUS_NO_MEMORY
;
2226 /* For backwards compatibility only store the dev/inode. */
2227 push_file_id_16(return_data
, &fsp
->file_id
);
2228 memcpy(return_data
+16,create_volume_objectid(fsp
->conn
,objid
),16);
2229 push_file_id_16(return_data
+32, &fsp
->file_id
);
2230 *out_data
= return_data
;
2231 return NT_STATUS_OK
;
2234 case FSCTL_GET_REPARSE_POINT
:
2236 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
2237 DEBUG(10, ("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp
->fnum
));
2238 return NT_STATUS_NOT_A_REPARSE_POINT
;
2241 case FSCTL_SET_REPARSE_POINT
:
2243 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
2244 DEBUG(10, ("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp
->fnum
));
2245 return NT_STATUS_NOT_A_REPARSE_POINT
;
2248 case FSCTL_GET_SHADOW_COPY_DATA
:
2251 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2252 * and return their volume names. If max_data_count is 16, then it is just
2253 * asking for the number of volumes and length of the combined names.
2255 * pdata is the data allocated by our caller, but that uses
2256 * total_data_count (which is 0 in our case) rather than max_data_count.
2257 * Allocate the correct amount and return the pointer to let
2258 * it be deallocated when we return.
2260 struct shadow_copy_data
*shadow_data
= NULL
;
2261 bool labels
= False
;
2262 uint32 labels_data_count
= 0;
2264 char *cur_pdata
= NULL
;
2266 if (max_out_len
< 16) {
2267 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2269 return NT_STATUS_INVALID_PARAMETER
;
2272 if (max_out_len
> 16) {
2276 shadow_data
= talloc_zero(ctx
, struct shadow_copy_data
);
2277 if (shadow_data
== NULL
) {
2278 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2279 return NT_STATUS_NO_MEMORY
;
2283 * Call the VFS routine to actually do the work.
2285 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2286 TALLOC_FREE(shadow_data
);
2287 if (errno
== ENOSYS
) {
2288 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2289 fsp
->conn
->connectpath
));
2290 return NT_STATUS_NOT_SUPPORTED
;
2292 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2293 fsp
->conn
->connectpath
));
2294 return NT_STATUS_UNSUCCESSFUL
;
2298 labels_data_count
= (shadow_data
->num_volumes
* 2 *
2299 sizeof(SHADOW_COPY_LABEL
)) + 2;
2304 *out_len
= 12 + labels_data_count
+ 4;
2307 if (max_out_len
< *out_len
) {
2308 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2309 max_out_len
, *out_len
));
2310 TALLOC_FREE(shadow_data
);
2311 return NT_STATUS_BUFFER_TOO_SMALL
;
2314 cur_pdata
= talloc_array(ctx
, char, *out_len
);
2315 if (cur_pdata
== NULL
) {
2316 TALLOC_FREE(shadow_data
);
2317 return NT_STATUS_NO_MEMORY
;
2320 *out_data
= cur_pdata
;
2322 /* num_volumes 4 bytes */
2323 SIVAL(cur_pdata
, 0, shadow_data
->num_volumes
);
2326 /* num_labels 4 bytes */
2327 SIVAL(cur_pdata
, 4, shadow_data
->num_volumes
);
2330 /* needed_data_count 4 bytes */
2331 SIVAL(cur_pdata
, 8, labels_data_count
+ 4);
2335 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2336 shadow_data
->num_volumes
, fsp_str_dbg(fsp
)));
2337 if (labels
&& shadow_data
->labels
) {
2338 for (i
=0; i
<shadow_data
->num_volumes
; i
++) {
2339 srvstr_push(cur_pdata
, req_flags
,
2340 cur_pdata
, shadow_data
->labels
[i
],
2341 2 * sizeof(SHADOW_COPY_LABEL
),
2342 STR_UNICODE
|STR_TERMINATE
);
2343 cur_pdata
+= 2 * sizeof(SHADOW_COPY_LABEL
);
2344 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2348 TALLOC_FREE(shadow_data
);
2350 return NT_STATUS_OK
;
2353 case FSCTL_FIND_FILES_BY_SID
:
2355 /* pretend this succeeded -
2357 * we have to send back a list with all files owned by this SID
2359 * but I have to check that --metze
2365 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n", fsp
->fnum
));
2368 /* NT_STATUS_BUFFER_TOO_SMALL maybe? */
2369 return NT_STATUS_INVALID_PARAMETER
;
2372 sid_len
= MIN(in_len
- 4,SID_MAX_SIZE
);
2374 /* unknown 4 bytes: this is not the length of the sid :-( */
2375 /*unknown = IVAL(pdata,0);*/
2377 if (!sid_parse(in_data
+ 4, sid_len
, &sid
)) {
2378 return NT_STATUS_INVALID_PARAMETER
;
2380 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
2382 if (!sid_to_uid(&sid
, &uid
)) {
2383 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2384 sid_string_dbg(&sid
),
2385 (unsigned long)sid_len
));
2389 /* we can take a look at the find source :-)
2391 * find ./ -uid $uid -name '*' is what we need here
2394 * and send 4bytes len and then NULL terminated unicode strings
2397 * but I don't know how to deal with the paged results
2398 * (maybe we can hang the result anywhere in the fsp struct)
2400 * but I don't know how to deal with the paged results
2401 * (maybe we can hang the result anywhere in the fsp struct)
2403 * we don't send all files at once
2404 * and at the next we should *not* start from the beginning,
2405 * so we have to cache the result
2410 /* this works for now... */
2411 return NT_STATUS_OK
;
2414 case FSCTL_QUERY_ALLOCATED_RANGES
:
2416 /* FIXME: This is just a dummy reply, telling that all of the
2417 * file is allocated. MKS cp needs that.
2418 * Adding the real allocated ranges via FIEMAP on Linux
2419 * and SEEK_DATA/SEEK_HOLE on Solaris is needed to make
2420 * this FSCTL correct for sparse files.
2423 uint64_t offset
, length
;
2424 char *out_data_tmp
= NULL
;
2427 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: data_count(%u) != 16 is invalid!\n",
2429 return NT_STATUS_INVALID_PARAMETER
;
2432 if (max_out_len
< 16) {
2433 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_out_len (%u) < 16 is invalid!\n",
2435 return NT_STATUS_INVALID_PARAMETER
;
2438 offset
= BVAL(in_data
,0);
2439 length
= BVAL(in_data
,8);
2441 if (offset
+ length
< offset
) {
2442 /* No 64-bit integer wrap. */
2443 return NT_STATUS_INVALID_PARAMETER
;
2446 /* Shouldn't this be SMB_VFS_STAT ... ? */
2447 status
= vfs_stat_fsp(fsp
);
2448 if (!NT_STATUS_IS_OK(status
)) {
2453 out_data_tmp
= talloc_array(ctx
, char, *out_len
);
2454 if (out_data_tmp
== NULL
) {
2455 DEBUG(10, ("unable to allocate memory for response\n"));
2456 return NT_STATUS_NO_MEMORY
;
2459 if (offset
> fsp
->fsp_name
->st
.st_ex_size
||
2460 fsp
->fsp_name
->st
.st_ex_size
== 0 ||
2462 memset(out_data_tmp
, 0, *out_len
);
2464 uint64_t end
= offset
+ length
;
2465 end
= MIN(end
, fsp
->fsp_name
->st
.st_ex_size
);
2466 SBVAL(out_data_tmp
, 0, 0);
2467 SBVAL(out_data_tmp
, 8, end
);
2470 *out_data
= out_data_tmp
;
2472 return NT_STATUS_OK
;
2475 case FSCTL_IS_VOLUME_DIRTY
:
2477 DEBUG(10,("FSCTL_IS_VOLUME_DIRTY: called on FID[0x%04X] "
2478 "(but not implemented)\n", fsp
->fnum
));
2480 * http://msdn.microsoft.com/en-us/library/cc232128%28PROT.10%29.aspx
2481 * says we have to respond with NT_STATUS_INVALID_PARAMETER
2483 return NT_STATUS_INVALID_PARAMETER
;
2488 * Only print once ... unfortunately there could be lots of
2489 * different FSCTLs that are called.
2491 if (!vfswrap_logged_ioctl_message
) {
2492 vfswrap_logged_ioctl_message
= true;
2493 DEBUG(2, ("%s (0x%x): Currently not implemented.\n",
2494 __FUNCTION__
, function
));
2498 return NT_STATUS_NOT_SUPPORTED
;
2501 /****************************************************************************
2503 ****************************************************************************/
2505 static void call_nt_transact_ioctl(connection_struct
*conn
,
2506 struct smb_request
*req
,
2507 uint16
**ppsetup
, uint32 setup_count
,
2508 char **ppparams
, uint32 parameter_count
,
2509 char **ppdata
, uint32 data_count
,
2510 uint32 max_data_count
)
2518 char *out_data
= NULL
;
2519 uint32 out_data_len
= 0;
2520 char *pdata
= *ppdata
;
2521 TALLOC_CTX
*ctx
= talloc_tos();
2523 if (setup_count
!= 8) {
2524 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
2525 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2529 function
= IVAL(*ppsetup
, 0);
2530 fidnum
= SVAL(*ppsetup
, 4);
2531 isFSctl
= CVAL(*ppsetup
, 6);
2532 compfilter
= CVAL(*ppsetup
, 7);
2534 DEBUG(10, ("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2535 function
, fidnum
, isFSctl
, compfilter
));
2537 fsp
=file_fsp(req
, fidnum
);
2540 * We don't really implement IOCTLs, especially on files.
2543 DEBUG(10, ("isFSctl: 0x%02X indicates IOCTL, not FSCTL!\n",
2545 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2549 /* Has to be for an open file! */
2550 if (!check_fsp_open(conn
, req
, fsp
)) {
2555 * out_data might be allocated by the VFS module, but talloc should be
2556 * used, and should be cleaned up when the request ends.
2558 status
= smb_fsctl(fsp
,
2564 (uint8_t **)&out_data
,
2567 if (!NT_STATUS_IS_OK(status
)) {
2568 reply_nterror(req
, status
);
2570 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, out_data
, out_data_len
);
2575 #ifdef HAVE_SYS_QUOTAS
2576 /****************************************************************************
2577 Reply to get user quota
2578 ****************************************************************************/
2580 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2581 struct smb_request
*req
,
2585 uint32 parameter_count
,
2588 uint32 max_data_count
)
2590 NTSTATUS nt_status
= NT_STATUS_OK
;
2591 char *params
= *ppparams
;
2592 char *pdata
= *ppdata
;
2594 int data_len
=0,param_len
=0;
2597 files_struct
*fsp
= NULL
;
2601 bool start_enum
= True
;
2602 SMB_NTQUOTA_STRUCT qt
;
2603 SMB_NTQUOTA_LIST
*tmp_list
;
2604 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2609 if (get_current_uid(conn
) != 0) {
2610 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2611 "[%s]\n", lp_servicename(SNUM(conn
)),
2612 conn
->session_info
->unix_name
));
2613 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2618 * Ensure minimum number of parameters sent.
2621 if (parameter_count
< 4) {
2622 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2623 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2627 /* maybe we can check the quota_fnum */
2628 fsp
= file_fsp(req
, SVAL(params
,0));
2629 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2630 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2631 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2635 /* the NULL pointer checking for fsp->fake_file_handle->pd
2636 * is done by CHECK_NTQUOTA_HANDLE_OK()
2638 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2640 level
= SVAL(params
,2);
2642 /* unknown 12 bytes leading in params */
2645 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2646 /* seems that we should continue with the enum here --metze */
2648 if (qt_handle
->quota_list
!=NULL
&&
2649 qt_handle
->tmp_list
==NULL
) {
2652 free_ntquota_list(&(qt_handle
->quota_list
));
2654 /* Realloc the size of parameters and data we will return */
2656 params
= nttrans_realloc(ppparams
, param_len
);
2657 if(params
== NULL
) {
2658 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2663 SIVAL(params
,0,data_len
);
2670 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2672 if (qt_handle
->quota_list
==NULL
&&
2673 qt_handle
->tmp_list
==NULL
) {
2677 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2678 reply_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
2682 /* Realloc the size of parameters and data we will return */
2684 params
= nttrans_realloc(ppparams
, param_len
);
2685 if(params
== NULL
) {
2686 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2690 /* we should not trust the value in max_data_count*/
2691 max_data_count
= MIN(max_data_count
,2048);
2693 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2695 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2701 /* set params Size of returned Quota Data 4 bytes*/
2702 /* but set it later when we know it */
2704 /* for each entry push the data */
2707 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2710 tmp_list
= qt_handle
->tmp_list
;
2712 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2713 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2715 sid_len
= ndr_size_dom_sid(
2716 &tmp_list
->quotas
->sid
, 0);
2717 entry_len
= 40 + sid_len
;
2719 /* nextoffset entry 4 bytes */
2720 SIVAL(entry
,0,entry_len
);
2722 /* then the len of the SID 4 bytes */
2723 SIVAL(entry
,4,sid_len
);
2725 /* unknown data 8 bytes uint64_t */
2726 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2728 /* the used disk space 8 bytes uint64_t */
2729 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2731 /* the soft quotas 8 bytes uint64_t */
2732 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2734 /* the hard quotas 8 bytes uint64_t */
2735 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2737 /* and now the SID */
2738 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2741 qt_handle
->tmp_list
= tmp_list
;
2743 /* overwrite the offset of the last entry */
2744 SIVAL(entry
-entry_len
,0,0);
2746 data_len
= 4+qt_len
;
2747 /* overwrite the params quota_data_len */
2748 SIVAL(params
,0,data_len
);
2752 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2754 /* unknown 4 bytes IVAL(pdata,0) */
2756 if (data_count
< 8) {
2757 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2758 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2762 sid_len
= IVAL(pdata
,4);
2763 /* Ensure this is less than 1mb. */
2764 if (sid_len
> (1024*1024)) {
2765 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2769 if (data_count
< 8+sid_len
) {
2770 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2771 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2775 data_len
= 4+40+sid_len
;
2777 if (max_data_count
< data_len
) {
2778 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2779 max_data_count
, data_len
));
2781 SIVAL(params
,0,data_len
);
2783 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2787 if (!sid_parse(pdata
+8,sid_len
,&sid
)) {
2788 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2792 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2795 * we have to return zero's in all fields
2796 * instead of returning an error here
2801 /* Realloc the size of parameters and data we will return */
2803 params
= nttrans_realloc(ppparams
, param_len
);
2804 if(params
== NULL
) {
2805 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2809 pdata
= nttrans_realloc(ppdata
, data_len
);
2811 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2817 /* set params Size of returned Quota Data 4 bytes*/
2818 SIVAL(params
,0,data_len
);
2820 /* nextoffset entry 4 bytes */
2823 /* then the len of the SID 4 bytes */
2824 SIVAL(entry
,4,sid_len
);
2826 /* unknown data 8 bytes uint64_t */
2827 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2829 /* the used disk space 8 bytes uint64_t */
2830 SBIG_UINT(entry
,16,qt
.usedspace
);
2832 /* the soft quotas 8 bytes uint64_t */
2833 SBIG_UINT(entry
,24,qt
.softlim
);
2835 /* the hard quotas 8 bytes uint64_t */
2836 SBIG_UINT(entry
,32,qt
.hardlim
);
2838 /* and now the SID */
2839 sid_linearize(entry
+40, sid_len
, &sid
);
2844 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2845 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2850 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2854 /****************************************************************************
2855 Reply to set user quota
2856 ****************************************************************************/
2858 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2859 struct smb_request
*req
,
2863 uint32 parameter_count
,
2866 uint32 max_data_count
)
2868 char *params
= *ppparams
;
2869 char *pdata
= *ppdata
;
2870 int data_len
=0,param_len
=0;
2871 SMB_NTQUOTA_STRUCT qt
;
2874 files_struct
*fsp
= NULL
;
2879 if (get_current_uid(conn
) != 0) {
2880 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2881 "[%s]\n", lp_servicename(SNUM(conn
)),
2882 conn
->session_info
->unix_name
));
2883 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2888 * Ensure minimum number of parameters sent.
2891 if (parameter_count
< 2) {
2892 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2893 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2897 /* maybe we can check the quota_fnum */
2898 fsp
= file_fsp(req
, SVAL(params
,0));
2899 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2900 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2901 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2905 if (data_count
< 40) {
2906 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2907 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2911 /* offset to next quota record.
2912 * 4 bytes IVAL(pdata,0)
2917 sid_len
= IVAL(pdata
,4);
2919 if (data_count
< 40+sid_len
|| (40+sid_len
< sid_len
)) {
2920 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2921 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2925 /* unknown 8 bytes in pdata
2926 * maybe its the change time in NTTIME
2929 /* the used space 8 bytes (uint64_t)*/
2930 qt
.usedspace
= BVAL(pdata
,16);
2932 /* the soft quotas 8 bytes (uint64_t)*/
2933 qt
.softlim
= BVAL(pdata
,24);
2935 /* the hard quotas 8 bytes (uint64_t)*/
2936 qt
.hardlim
= BVAL(pdata
,32);
2938 if (!sid_parse(pdata
+40,sid_len
,&sid
)) {
2939 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2943 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2945 /* 44 unknown bytes left... */
2947 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2948 reply_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
2952 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2955 #endif /* HAVE_SYS_QUOTAS */
2957 static void handle_nttrans(connection_struct
*conn
,
2958 struct trans_state
*state
,
2959 struct smb_request
*req
)
2961 if (get_Protocol() >= PROTOCOL_NT1
) {
2962 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2963 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2967 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2969 /* Now we must call the relevant NT_TRANS function */
2970 switch(state
->call
) {
2971 case NT_TRANSACT_CREATE
:
2973 START_PROFILE(NT_transact_create
);
2974 call_nt_transact_create(
2976 &state
->setup
, state
->setup_count
,
2977 &state
->param
, state
->total_param
,
2978 &state
->data
, state
->total_data
,
2979 state
->max_data_return
);
2980 END_PROFILE(NT_transact_create
);
2984 case NT_TRANSACT_IOCTL
:
2986 START_PROFILE(NT_transact_ioctl
);
2987 call_nt_transact_ioctl(
2989 &state
->setup
, state
->setup_count
,
2990 &state
->param
, state
->total_param
,
2991 &state
->data
, state
->total_data
,
2992 state
->max_data_return
);
2993 END_PROFILE(NT_transact_ioctl
);
2997 case NT_TRANSACT_SET_SECURITY_DESC
:
2999 START_PROFILE(NT_transact_set_security_desc
);
3000 call_nt_transact_set_security_desc(
3002 &state
->setup
, state
->setup_count
,
3003 &state
->param
, state
->total_param
,
3004 &state
->data
, state
->total_data
,
3005 state
->max_data_return
);
3006 END_PROFILE(NT_transact_set_security_desc
);
3010 case NT_TRANSACT_NOTIFY_CHANGE
:
3012 START_PROFILE(NT_transact_notify_change
);
3013 call_nt_transact_notify_change(
3015 &state
->setup
, state
->setup_count
,
3016 &state
->param
, state
->total_param
,
3017 &state
->data
, state
->total_data
,
3018 state
->max_data_return
,
3019 state
->max_param_return
);
3020 END_PROFILE(NT_transact_notify_change
);
3024 case NT_TRANSACT_RENAME
:
3026 START_PROFILE(NT_transact_rename
);
3027 call_nt_transact_rename(
3029 &state
->setup
, state
->setup_count
,
3030 &state
->param
, state
->total_param
,
3031 &state
->data
, state
->total_data
,
3032 state
->max_data_return
);
3033 END_PROFILE(NT_transact_rename
);
3037 case NT_TRANSACT_QUERY_SECURITY_DESC
:
3039 START_PROFILE(NT_transact_query_security_desc
);
3040 call_nt_transact_query_security_desc(
3042 &state
->setup
, state
->setup_count
,
3043 &state
->param
, state
->total_param
,
3044 &state
->data
, state
->total_data
,
3045 state
->max_data_return
);
3046 END_PROFILE(NT_transact_query_security_desc
);
3050 #ifdef HAVE_SYS_QUOTAS
3051 case NT_TRANSACT_GET_USER_QUOTA
:
3053 START_PROFILE(NT_transact_get_user_quota
);
3054 call_nt_transact_get_user_quota(
3056 &state
->setup
, state
->setup_count
,
3057 &state
->param
, state
->total_param
,
3058 &state
->data
, state
->total_data
,
3059 state
->max_data_return
);
3060 END_PROFILE(NT_transact_get_user_quota
);
3064 case NT_TRANSACT_SET_USER_QUOTA
:
3066 START_PROFILE(NT_transact_set_user_quota
);
3067 call_nt_transact_set_user_quota(
3069 &state
->setup
, state
->setup_count
,
3070 &state
->param
, state
->total_param
,
3071 &state
->data
, state
->total_data
,
3072 state
->max_data_return
);
3073 END_PROFILE(NT_transact_set_user_quota
);
3076 #endif /* HAVE_SYS_QUOTAS */
3079 /* Error in request */
3080 DEBUG(0,("handle_nttrans: Unknown request %d in "
3081 "nttrans call\n", state
->call
));
3082 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
3088 /****************************************************************************
3089 Reply to a SMBNTtrans.
3090 ****************************************************************************/
3092 void reply_nttrans(struct smb_request
*req
)
3094 connection_struct
*conn
= req
->conn
;
3099 uint16 function_code
;
3101 struct trans_state
*state
;
3103 START_PROFILE(SMBnttrans
);
3105 if (req
->wct
< 19) {
3106 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3107 END_PROFILE(SMBnttrans
);
3111 pscnt
= IVAL(req
->vwv
+9, 1);
3112 psoff
= IVAL(req
->vwv
+11, 1);
3113 dscnt
= IVAL(req
->vwv
+13, 1);
3114 dsoff
= IVAL(req
->vwv
+15, 1);
3115 function_code
= SVAL(req
->vwv
+18, 0);
3117 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
3118 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
3119 END_PROFILE(SMBnttrans
);
3123 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
3124 if (!NT_STATUS_IS_OK(result
)) {
3125 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
3126 reply_nterror(req
, result
);
3127 END_PROFILE(SMBnttrans
);
3131 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
3132 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3133 END_PROFILE(SMBnttrans
);
3137 state
->cmd
= SMBnttrans
;
3139 state
->mid
= req
->mid
;
3140 state
->vuid
= req
->vuid
;
3141 state
->total_data
= IVAL(req
->vwv
+3, 1);
3143 state
->total_param
= IVAL(req
->vwv
+1, 1);
3144 state
->param
= NULL
;
3145 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
3146 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
3148 /* setup count is in *words* */
3149 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
3150 state
->setup
= NULL
;
3151 state
->call
= function_code
;
3153 DEBUG(10, ("num_setup=%u, "
3154 "param_total=%u, this_param=%u, max_param=%u, "
3155 "data_total=%u, this_data=%u, max_data=%u, "
3156 "param_offset=%u, data_offset=%u\n",
3157 (unsigned)state
->setup_count
,
3158 (unsigned)state
->total_param
, (unsigned)pscnt
,
3159 (unsigned)state
->max_param_return
,
3160 (unsigned)state
->total_data
, (unsigned)dscnt
,
3161 (unsigned)state
->max_data_return
,
3162 (unsigned)psoff
, (unsigned)dsoff
));
3165 * All nttrans messages we handle have smb_wct == 19 +
3166 * state->setup_count. Ensure this is so as a sanity check.
3169 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
3170 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
3171 req
->wct
, 19 + (state
->setup_count
/2)));
3175 /* Don't allow more than 128mb for each value. */
3176 if ((state
->total_data
> (1024*1024*128)) ||
3177 (state
->total_param
> (1024*1024*128))) {
3178 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3179 END_PROFILE(SMBnttrans
);
3183 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
3186 if (state
->total_data
) {
3188 if (trans_oob(state
->total_data
, 0, dscnt
)
3189 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
3193 /* Can't use talloc here, the core routines do realloc on the
3194 * params and data. */
3195 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
3196 DEBUG(0,("reply_nttrans: data malloc fail for %u "
3197 "bytes !\n", (unsigned int)state
->total_data
));
3199 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3200 END_PROFILE(SMBnttrans
);
3204 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
3207 if (state
->total_param
) {
3209 if (trans_oob(state
->total_param
, 0, pscnt
)
3210 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
3214 /* Can't use talloc here, the core routines do realloc on the
3215 * params and data. */
3216 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
3217 DEBUG(0,("reply_nttrans: param malloc fail for %u "
3218 "bytes !\n", (unsigned int)state
->total_param
));
3219 SAFE_FREE(state
->data
);
3221 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3222 END_PROFILE(SMBnttrans
);
3226 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
3229 state
->received_data
= dscnt
;
3230 state
->received_param
= pscnt
;
3232 if(state
->setup_count
> 0) {
3233 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
3234 state
->setup_count
));
3237 * No overflow possible here, state->setup_count is an
3238 * unsigned int, being filled by a single byte from
3239 * CVAL(req->vwv+13, 0) above. The cast in the comparison
3240 * below is not necessary, it's here to clarify things. The
3241 * validity of req->vwv and req->wct has been checked in
3242 * init_smb_request already.
3244 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
3248 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
3249 if (state
->setup
== NULL
) {
3250 DEBUG(0,("reply_nttrans : Out of memory\n"));
3251 SAFE_FREE(state
->data
);
3252 SAFE_FREE(state
->param
);
3254 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3255 END_PROFILE(SMBnttrans
);
3259 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
3260 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
3263 if ((state
->received_data
== state
->total_data
) &&
3264 (state
->received_param
== state
->total_param
)) {
3265 handle_nttrans(conn
, state
, req
);
3266 SAFE_FREE(state
->param
);
3267 SAFE_FREE(state
->data
);
3269 END_PROFILE(SMBnttrans
);
3273 DLIST_ADD(conn
->pending_trans
, state
);
3275 /* We need to send an interim response then receive the rest
3276 of the parameter/data bytes */
3277 reply_outbuf(req
, 0, 0);
3278 show_msg((char *)req
->outbuf
);
3279 END_PROFILE(SMBnttrans
);
3284 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3285 SAFE_FREE(state
->data
);
3286 SAFE_FREE(state
->param
);
3288 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3289 END_PROFILE(SMBnttrans
);
3293 /****************************************************************************
3294 Reply to a SMBnttranss
3295 ****************************************************************************/
3297 void reply_nttranss(struct smb_request
*req
)
3299 connection_struct
*conn
= req
->conn
;
3300 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
3301 struct trans_state
*state
;
3303 START_PROFILE(SMBnttranss
);
3305 show_msg((char *)req
->inbuf
);
3307 /* Windows clients expect all replies to
3308 an NT transact secondary (SMBnttranss 0xA1)
3309 to have a command code of NT transact
3310 (SMBnttrans 0xA0). See bug #8989 for details. */
3311 req
->cmd
= SMBnttrans
;
3313 if (req
->wct
< 18) {
3314 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3315 END_PROFILE(SMBnttranss
);
3319 for (state
= conn
->pending_trans
; state
!= NULL
;
3320 state
= state
->next
) {
3321 if (state
->mid
== req
->mid
) {
3326 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
3327 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3328 END_PROFILE(SMBnttranss
);
3332 /* Revise state->total_param and state->total_data in case they have
3333 changed downwards */
3334 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
3335 state
->total_param
= IVAL(req
->vwv
+1, 1);
3337 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
3338 state
->total_data
= IVAL(req
->vwv
+3, 1);
3341 pcnt
= IVAL(req
->vwv
+5, 1);
3342 poff
= IVAL(req
->vwv
+7, 1);
3343 pdisp
= IVAL(req
->vwv
+9, 1);
3345 dcnt
= IVAL(req
->vwv
+11, 1);
3346 doff
= IVAL(req
->vwv
+13, 1);
3347 ddisp
= IVAL(req
->vwv
+15, 1);
3349 state
->received_param
+= pcnt
;
3350 state
->received_data
+= dcnt
;
3352 if ((state
->received_data
> state
->total_data
) ||
3353 (state
->received_param
> state
->total_param
))
3357 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
3358 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
3361 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
3365 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
3366 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
3369 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
3372 if ((state
->received_param
< state
->total_param
) ||
3373 (state
->received_data
< state
->total_data
)) {
3374 END_PROFILE(SMBnttranss
);
3378 handle_nttrans(conn
, state
, req
);
3380 DLIST_REMOVE(conn
->pending_trans
, state
);
3381 SAFE_FREE(state
->data
);
3382 SAFE_FREE(state
->param
);
3384 END_PROFILE(SMBnttranss
);
3389 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3390 DLIST_REMOVE(conn
->pending_trans
, state
);
3391 SAFE_FREE(state
->data
);
3392 SAFE_FREE(state
->param
);
3394 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3395 END_PROFILE(SMBnttranss
);