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 "smbd/globals.h"
23 #include "fake_file.h"
24 #include "../libcli/security/security.h"
25 #include "../librpc/gen_ndr/ndr_security.h"
27 extern const struct generic_mapping file_generic_mapping
;
29 static char *nttrans_realloc(char **ptr
, size_t size
)
32 smb_panic("nttrans_realloc() called with NULL ptr");
35 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
39 memset(*ptr
,'\0',size
);
43 /****************************************************************************
44 Send the required number of replies back.
45 We assume all fields other than the data fields are
46 set correctly for the type of call.
47 HACK ! Always assumes smb_setup field is zero.
48 ****************************************************************************/
50 void send_nt_replies(connection_struct
*conn
,
51 struct smb_request
*req
, NTSTATUS nt_error
,
52 char *params
, int paramsize
,
53 char *pdata
, int datasize
)
55 int data_to_send
= datasize
;
56 int params_to_send
= paramsize
;
60 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
61 int alignment_offset
= 1;
62 int data_alignment_offset
= 0;
63 struct smbd_server_connection
*sconn
= req
->sconn
;
64 int max_send
= sconn
->smb1
.sessions
.max_send
;
67 * If there genuinely are no parameters or data to send just send
71 if(params_to_send
== 0 && data_to_send
== 0) {
72 reply_outbuf(req
, 18, 0);
73 if (NT_STATUS_V(nt_error
)) {
74 error_packet_set((char *)req
->outbuf
,
78 show_msg((char *)req
->outbuf
);
79 if (!srv_send_smb(sconn
,
82 IS_CONN_ENCRYPTED(conn
),
84 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
86 TALLOC_FREE(req
->outbuf
);
91 * When sending params and data ensure that both are nicely aligned.
92 * Only do this alignment when there is also data to send - else
93 * can cause NT redirector problems.
96 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
97 data_alignment_offset
= 4 - (params_to_send
% 4);
101 * Space is bufsize minus Netbios over TCP header minus SMB header.
102 * The alignment_offset is to align the param bytes on a four byte
103 * boundary (2 bytes for data len, one byte pad).
104 * NT needs this to work correctly.
107 useable_space
= max_send
- (smb_size
110 + data_alignment_offset
);
112 if (useable_space
< 0) {
113 char *msg
= talloc_asprintf(
115 "send_nt_replies failed sanity useable_space = %d!!!",
117 DEBUG(0, ("%s\n", msg
));
118 exit_server_cleanly(msg
);
121 while (params_to_send
|| data_to_send
) {
124 * Calculate whether we will totally or partially fill this packet.
127 total_sent_thistime
= params_to_send
+ data_to_send
;
130 * We can never send more than useable_space.
133 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
135 reply_outbuf(req
, 18,
136 total_sent_thistime
+ alignment_offset
137 + data_alignment_offset
);
140 * We might have had SMBnttranss in req->inbuf, fix that.
142 SCVAL(req
->outbuf
, smb_com
, SMBnttrans
);
145 * Set total params and data to be sent.
148 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
149 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
152 * Calculate how many parameters and data we can fit into
153 * this packet. Parameters get precedence.
156 params_sent_thistime
= MIN(params_to_send
,useable_space
);
157 data_sent_thistime
= useable_space
- params_sent_thistime
;
158 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
160 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
161 params_sent_thistime
);
163 if(params_sent_thistime
== 0) {
164 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
165 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
168 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
169 * parameter bytes, however the first 4 bytes of outbuf are
170 * the Netbios over TCP header. Thus use smb_base() to subtract
171 * them from the calculation.
174 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
175 ((smb_buf(req
->outbuf
)+alignment_offset
)
176 - smb_base(req
->outbuf
)));
178 * Absolute displacement of param bytes sent in this packet.
181 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
186 * Deal with the data portion.
189 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
191 if(data_sent_thistime
== 0) {
192 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
193 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
196 * The offset of the data bytes is the offset of the
197 * parameter bytes plus the number of parameters being sent this time.
200 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
201 ((smb_buf(req
->outbuf
)+alignment_offset
) -
202 smb_base(req
->outbuf
))
203 + params_sent_thistime
+ data_alignment_offset
);
204 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
208 * Copy the param bytes into the packet.
211 if(params_sent_thistime
) {
212 if (alignment_offset
!= 0) {
213 memset(smb_buf(req
->outbuf
), 0,
216 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
217 params_sent_thistime
);
221 * Copy in the data bytes
224 if(data_sent_thistime
) {
225 if (data_alignment_offset
!= 0) {
226 memset((smb_buf(req
->outbuf
)+alignment_offset
+
227 params_sent_thistime
), 0,
228 data_alignment_offset
);
230 memcpy(smb_buf(req
->outbuf
)+alignment_offset
231 +params_sent_thistime
+data_alignment_offset
,
232 pd
,data_sent_thistime
);
235 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
236 params_sent_thistime
, data_sent_thistime
, useable_space
));
237 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
238 params_to_send
, data_to_send
, paramsize
, datasize
));
240 if (NT_STATUS_V(nt_error
)) {
241 error_packet_set((char *)req
->outbuf
,
246 /* Send the packet */
247 show_msg((char *)req
->outbuf
);
248 if (!srv_send_smb(sconn
,
251 IS_CONN_ENCRYPTED(conn
),
253 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
256 TALLOC_FREE(req
->outbuf
);
258 pp
+= params_sent_thistime
;
259 pd
+= data_sent_thistime
;
261 params_to_send
-= params_sent_thistime
;
262 data_to_send
-= data_sent_thistime
;
268 if(params_to_send
< 0 || data_to_send
< 0) {
269 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
270 params_to_send
, data_to_send
));
271 exit_server_cleanly("send_nt_replies: internal error");
276 /****************************************************************************
277 Reply to an NT create and X call on a pipe
278 ****************************************************************************/
280 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
281 struct smb_request
*req
, int *ppnum
)
286 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
288 /* Strip \\ off the name. */
291 status
= open_np_file(req
, fname
, &fsp
);
292 if (!NT_STATUS_IS_OK(status
)) {
293 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
294 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
298 reply_nterror(req
, status
);
306 /****************************************************************************
307 Reply to an NT create and X call for pipes.
308 ****************************************************************************/
310 static void do_ntcreate_pipe_open(connection_struct
*conn
,
311 struct smb_request
*req
)
316 uint32 flags
= IVAL(req
->vwv
+3, 1);
317 TALLOC_CTX
*ctx
= talloc_tos();
319 srvstr_pull_req_talloc(ctx
, req
, &fname
, req
->buf
, STR_TERMINATE
);
322 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
326 nt_open_pipe(fname
, conn
, req
, &pnum
);
334 * Deal with pipe return.
337 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
338 /* This is very strange. We
339 * return 50 words, but only set
340 * the wcnt to 42 ? It's definately
341 * what happens on the wire....
343 reply_outbuf(req
, 50, 0);
344 SCVAL(req
->outbuf
,smb_wct
,42);
346 reply_outbuf(req
, 34, 0);
349 p
= (char *)req
->outbuf
+ smb_vwv2
;
353 SIVAL(p
,0,FILE_WAS_OPENED
);
356 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
359 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
361 SSVAL(p
,2, 0x5FF); /* ? */
364 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
366 SIVAL(p
,0,FILE_GENERIC_ALL
);
368 * For pipes W2K3 seems to return
370 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
372 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
375 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
380 struct case_semantics_state
{
381 connection_struct
*conn
;
384 bool short_case_preserve
;
387 /****************************************************************************
388 Restore case semantics.
389 ****************************************************************************/
391 static int restore_case_semantics(struct case_semantics_state
*state
)
393 state
->conn
->case_sensitive
= state
->case_sensitive
;
394 state
->conn
->case_preserve
= state
->case_preserve
;
395 state
->conn
->short_case_preserve
= state
->short_case_preserve
;
399 /****************************************************************************
401 ****************************************************************************/
403 static struct case_semantics_state
*set_posix_case_semantics(TALLOC_CTX
*mem_ctx
,
404 connection_struct
*conn
)
406 struct case_semantics_state
*result
;
408 if (!(result
= talloc(mem_ctx
, struct case_semantics_state
))) {
413 result
->case_sensitive
= conn
->case_sensitive
;
414 result
->case_preserve
= conn
->case_preserve
;
415 result
->short_case_preserve
= conn
->short_case_preserve
;
418 conn
->case_sensitive
= True
;
419 conn
->case_preserve
= True
;
420 conn
->short_case_preserve
= True
;
422 talloc_set_destructor(result
, restore_case_semantics
);
427 /****************************************************************************
428 Reply to an NT create and X call.
429 ****************************************************************************/
431 void reply_ntcreate_and_X(struct smb_request
*req
)
433 connection_struct
*conn
= req
->conn
;
434 struct smb_filename
*smb_fname
= NULL
;
438 uint32 file_attributes
;
440 uint32 create_disposition
;
441 uint32 create_options
;
443 uint64_t allocation_size
;
444 /* Breakout the oplock request bits so we can set the
445 reply bits separately. */
447 SMB_OFF_T file_len
= 0;
449 files_struct
*fsp
= NULL
;
451 struct timespec create_timespec
;
452 struct timespec c_timespec
;
453 struct timespec a_timespec
;
454 struct timespec m_timespec
;
455 struct timespec write_time_ts
;
458 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
459 struct case_semantics_state
*case_state
= NULL
;
460 TALLOC_CTX
*ctx
= talloc_tos();
462 START_PROFILE(SMBntcreateX
);
465 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
469 flags
= IVAL(req
->vwv
+3, 1);
470 access_mask
= IVAL(req
->vwv
+7, 1);
471 file_attributes
= IVAL(req
->vwv
+13, 1);
472 share_access
= IVAL(req
->vwv
+15, 1);
473 create_disposition
= IVAL(req
->vwv
+17, 1);
474 create_options
= IVAL(req
->vwv
+19, 1);
475 root_dir_fid
= (uint16
)IVAL(req
->vwv
+5, 1);
477 allocation_size
= (uint64_t)IVAL(req
->vwv
+9, 1);
478 #ifdef LARGE_SMB_OFF_T
479 allocation_size
|= (((uint64_t)IVAL(req
->vwv
+11, 1)) << 32);
482 srvstr_get_path_req(ctx
, req
, &fname
, (const char *)req
->buf
,
483 STR_TERMINATE
, &status
);
485 if (!NT_STATUS_IS_OK(status
)) {
486 reply_nterror(req
, status
);
490 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
491 "file_attributes = 0x%x, share_access = 0x%x, "
492 "create_disposition = 0x%x create_options = 0x%x "
493 "root_dir_fid = 0x%x, fname = %s\n",
495 (unsigned int)access_mask
,
496 (unsigned int)file_attributes
,
497 (unsigned int)share_access
,
498 (unsigned int)create_disposition
,
499 (unsigned int)create_options
,
500 (unsigned int)root_dir_fid
,
504 * we need to remove ignored bits when they come directly from the client
505 * because we reuse some of them for internal stuff
507 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
510 * If it's an IPC, use the pipe handler.
514 if (lp_nt_pipe_support()) {
515 do_ntcreate_pipe_open(conn
, req
);
518 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
522 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
523 if (oplock_request
) {
524 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
528 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
529 case_state
= set_posix_case_semantics(ctx
, conn
);
531 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
536 status
= filename_convert(ctx
,
538 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
544 TALLOC_FREE(case_state
);
546 if (!NT_STATUS_IS_OK(status
)) {
547 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
549 NT_STATUS_PATH_NOT_COVERED
,
553 reply_nterror(req
, status
);
558 * Bug #6898 - clients using Windows opens should
559 * never be able to set this attribute into the
562 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
564 status
= SMB_VFS_CREATE_FILE(
567 root_dir_fid
, /* root_dir_fid */
568 smb_fname
, /* fname */
569 access_mask
, /* access_mask */
570 share_access
, /* share_access */
571 create_disposition
, /* create_disposition*/
572 create_options
, /* create_options */
573 file_attributes
, /* file_attributes */
574 oplock_request
, /* oplock_request */
575 allocation_size
, /* allocation_size */
576 0, /* private_flags */
582 if (!NT_STATUS_IS_OK(status
)) {
583 if (open_was_deferred(req
->mid
)) {
584 /* We have re-scheduled this call, no error. */
587 reply_openerror(req
, status
);
591 /* Ensure we're pointing at the correct stat struct. */
592 TALLOC_FREE(smb_fname
);
593 smb_fname
= fsp
->fsp_name
;
596 * If the caller set the extended oplock request bit
597 * and we granted one (by whatever means) - set the
598 * correct bit for extended oplock reply.
601 if (oplock_request
&&
602 (lp_fake_oplocks(SNUM(conn
))
603 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
606 * Exclusive oplock granted
609 if (flags
& REQUEST_BATCH_OPLOCK
) {
610 oplock_granted
= BATCH_OPLOCK_RETURN
;
612 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
614 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
615 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
617 oplock_granted
= NO_OPLOCK_RETURN
;
620 file_len
= smb_fname
->st
.st_ex_size
;
622 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
623 /* This is very strange. We
624 * return 50 words, but only set
625 * the wcnt to 42 ? It's definately
626 * what happens on the wire....
628 reply_outbuf(req
, 50, 0);
629 SCVAL(req
->outbuf
,smb_wct
,42);
631 reply_outbuf(req
, 34, 0);
634 p
= (char *)req
->outbuf
+ smb_vwv2
;
636 SCVAL(p
, 0, oplock_granted
);
639 SSVAL(p
,0,fsp
->fnum
);
641 if ((create_disposition
== FILE_SUPERSEDE
)
642 && (info
== FILE_WAS_OVERWRITTEN
)) {
643 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
649 fattr
= dos_mode(conn
, smb_fname
);
651 fattr
= FILE_ATTRIBUTE_NORMAL
;
654 /* Deal with other possible opens having a modified
656 ZERO_STRUCT(write_time_ts
);
657 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
658 if (!null_timespec(write_time_ts
)) {
659 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
663 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
664 a_timespec
= smb_fname
->st
.st_ex_atime
;
665 m_timespec
= smb_fname
->st
.st_ex_mtime
;
666 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
668 if (lp_dos_filetime_resolution(SNUM(conn
))) {
669 dos_filetime_timespec(&create_timespec
);
670 dos_filetime_timespec(&a_timespec
);
671 dos_filetime_timespec(&m_timespec
);
672 dos_filetime_timespec(&c_timespec
);
675 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
677 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
679 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
681 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
683 SIVAL(p
,0,fattr
); /* File Attributes. */
685 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
687 SOFF_T(p
,0,file_len
);
689 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
690 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
691 size_t num_names
= 0;
692 unsigned int num_streams
;
693 struct stream_struct
*streams
= NULL
;
695 /* Do we have any EA's ? */
696 status
= get_ea_names_from_file(ctx
, conn
, fsp
,
697 smb_fname
->base_name
, NULL
, &num_names
);
698 if (NT_STATUS_IS_OK(status
) && num_names
) {
699 file_status
&= ~NO_EAS
;
701 status
= SMB_VFS_STREAMINFO(conn
, NULL
, smb_fname
->base_name
, ctx
,
702 &num_streams
, &streams
);
703 /* There is always one stream, ::$DATA. */
704 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
705 file_status
&= ~NO_SUBSTREAMS
;
707 TALLOC_FREE(streams
);
708 SSVAL(p
,2,file_status
);
711 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
713 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
716 if (fsp
->is_directory
||
717 can_write_to_file(conn
, smb_fname
)) {
718 perms
= FILE_GENERIC_ALL
;
720 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
725 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
726 fsp
->fnum
, smb_fname_str_dbg(smb_fname
)));
730 END_PROFILE(SMBntcreateX
);
734 /****************************************************************************
735 Reply to a NT_TRANSACT_CREATE call to open a pipe.
736 ****************************************************************************/
738 static void do_nt_transact_create_pipe(connection_struct
*conn
,
739 struct smb_request
*req
,
740 uint16
**ppsetup
, uint32 setup_count
,
741 char **ppparams
, uint32 parameter_count
,
742 char **ppdata
, uint32 data_count
)
745 char *params
= *ppparams
;
751 TALLOC_CTX
*ctx
= talloc_tos();
754 * Ensure minimum number of parameters sent.
757 if(parameter_count
< 54) {
758 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
759 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
763 flags
= IVAL(params
,0);
765 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
766 parameter_count
-53, STR_TERMINATE
,
768 if (!NT_STATUS_IS_OK(status
)) {
769 reply_nterror(req
, status
);
773 nt_open_pipe(fname
, conn
, req
, &pnum
);
780 /* Realloc the size of parameters and data we will return */
781 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
782 /* Extended response is 32 more byyes. */
787 params
= nttrans_realloc(ppparams
, param_len
);
789 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
794 SCVAL(p
,0,NO_OPLOCK_RETURN
);
799 SIVAL(p
,0,FILE_WAS_OPENED
);
803 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
806 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
808 SSVAL(p
,2, 0x5FF); /* ? */
811 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
813 SIVAL(p
,0,FILE_GENERIC_ALL
);
815 * For pipes W2K3 seems to return
817 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
819 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
822 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
824 /* Send the required number of replies */
825 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
830 /****************************************************************************
831 Internal fn to set security descriptors.
832 ****************************************************************************/
834 NTSTATUS
set_sd(files_struct
*fsp
, uint8_t *data
, uint32_t sd_len
,
835 uint32_t security_info_sent
)
837 struct security_descriptor
*psd
= NULL
;
841 return NT_STATUS_INVALID_PARAMETER
;
844 if (!CAN_WRITE(fsp
->conn
)) {
845 return NT_STATUS_ACCESS_DENIED
;
848 if (!lp_nt_acl_support(SNUM(fsp
->conn
))) {
852 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
854 if (!NT_STATUS_IS_OK(status
)) {
858 if (psd
->owner_sid
== NULL
) {
859 security_info_sent
&= ~SECINFO_OWNER
;
861 if (psd
->group_sid
== NULL
) {
862 security_info_sent
&= ~SECINFO_GROUP
;
865 /* Ensure we have at least one thing set. */
866 if ((security_info_sent
& (SECINFO_OWNER
|SECINFO_GROUP
|SECINFO_DACL
|SECINFO_SACL
)) == 0) {
867 return NT_STATUS_INVALID_PARAMETER
;
870 /* Ensure we have the rights to do this. */
871 if (security_info_sent
& SECINFO_OWNER
) {
872 if (!(fsp
->access_mask
& SEC_STD_WRITE_OWNER
)) {
873 return NT_STATUS_ACCESS_DENIED
;
877 if (security_info_sent
& SECINFO_GROUP
) {
878 if (!(fsp
->access_mask
& SEC_STD_WRITE_OWNER
)) {
879 return NT_STATUS_ACCESS_DENIED
;
883 if (security_info_sent
& SECINFO_DACL
) {
884 if (!(fsp
->access_mask
& SEC_STD_WRITE_DAC
)) {
885 return NT_STATUS_ACCESS_DENIED
;
887 /* Convert all the generic bits. */
889 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
893 if (security_info_sent
& SECINFO_SACL
) {
894 if (!(fsp
->access_mask
& SEC_FLAG_SYSTEM_SECURITY
)) {
895 return NT_STATUS_ACCESS_DENIED
;
897 /* Convert all the generic bits. */
899 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
903 if (DEBUGLEVEL
>= 10) {
904 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp
)));
905 NDR_PRINT_DEBUG(security_descriptor
, psd
);
908 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
915 /****************************************************************************
916 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
917 ****************************************************************************/
919 struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
921 struct ea_list
*ea_list_head
= NULL
;
928 while (offset
+ 4 <= data_size
) {
929 size_t next_offset
= IVAL(pdata
,offset
);
930 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
936 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
937 if (next_offset
== 0) {
940 offset
+= next_offset
;
946 /****************************************************************************
947 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
948 ****************************************************************************/
950 static void call_nt_transact_create(connection_struct
*conn
,
951 struct smb_request
*req
,
952 uint16
**ppsetup
, uint32 setup_count
,
953 char **ppparams
, uint32 parameter_count
,
954 char **ppdata
, uint32 data_count
,
955 uint32 max_data_count
)
957 struct smb_filename
*smb_fname
= NULL
;
959 char *params
= *ppparams
;
960 char *data
= *ppdata
;
961 /* Breakout the oplock request bits so we can set the reply bits separately. */
963 SMB_OFF_T file_len
= 0;
965 files_struct
*fsp
= NULL
;
969 uint32 file_attributes
;
971 uint32 create_disposition
;
972 uint32 create_options
;
974 struct security_descriptor
*sd
= NULL
;
977 struct timespec create_timespec
;
978 struct timespec c_timespec
;
979 struct timespec a_timespec
;
980 struct timespec m_timespec
;
981 struct timespec write_time_ts
;
982 struct ea_list
*ea_list
= NULL
;
985 uint64_t allocation_size
;
987 uint8_t oplock_granted
;
988 struct case_semantics_state
*case_state
= NULL
;
989 TALLOC_CTX
*ctx
= talloc_tos();
991 DEBUG(5,("call_nt_transact_create\n"));
994 * If it's an IPC, use the pipe handler.
998 if (lp_nt_pipe_support()) {
999 do_nt_transact_create_pipe(
1001 ppsetup
, setup_count
,
1002 ppparams
, parameter_count
,
1003 ppdata
, data_count
);
1006 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1011 * Ensure minimum number of parameters sent.
1014 if(parameter_count
< 54) {
1015 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1016 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1020 flags
= IVAL(params
,0);
1021 access_mask
= IVAL(params
,8);
1022 file_attributes
= IVAL(params
,20);
1023 share_access
= IVAL(params
,24);
1024 create_disposition
= IVAL(params
,28);
1025 create_options
= IVAL(params
,32);
1026 sd_len
= IVAL(params
,36);
1027 ea_len
= IVAL(params
,40);
1028 root_dir_fid
= (uint16
)IVAL(params
,4);
1029 allocation_size
= (uint64_t)IVAL(params
,12);
1030 #ifdef LARGE_SMB_OFF_T
1031 allocation_size
|= (((uint64_t)IVAL(params
,16)) << 32);
1035 * we need to remove ignored bits when they come directly from the client
1036 * because we reuse some of them for internal stuff
1038 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
1040 /* Ensure the data_len is correct for the sd and ea values given. */
1041 if ((ea_len
+ sd_len
> data_count
)
1042 || (ea_len
> data_count
) || (sd_len
> data_count
)
1043 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1044 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
1045 "%u, data_count = %u\n", (unsigned int)ea_len
,
1046 (unsigned int)sd_len
, (unsigned int)data_count
));
1047 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1052 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1055 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
1057 if (!NT_STATUS_IS_OK(status
)) {
1058 DEBUG(10, ("call_nt_transact_create: "
1059 "unmarshall_sec_desc failed: %s\n",
1060 nt_errstr(status
)));
1061 reply_nterror(req
, status
);
1067 if (!lp_ea_support(SNUM(conn
))) {
1068 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1069 "EA's not supported.\n",
1070 (unsigned int)ea_len
));
1071 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1076 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1077 "too small (should be more than 10)\n",
1078 (unsigned int)ea_len
));
1079 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1083 /* We have already checked that ea_len <= data_count here. */
1084 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
1086 if (ea_list
== NULL
) {
1087 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1092 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
1093 params
+53, parameter_count
-53,
1094 STR_TERMINATE
, &status
);
1095 if (!NT_STATUS_IS_OK(status
)) {
1096 reply_nterror(req
, status
);
1100 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1101 case_state
= set_posix_case_semantics(ctx
, conn
);
1103 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1108 status
= filename_convert(ctx
,
1110 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1116 TALLOC_FREE(case_state
);
1118 if (!NT_STATUS_IS_OK(status
)) {
1119 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1120 reply_botherror(req
,
1121 NT_STATUS_PATH_NOT_COVERED
,
1122 ERRSRV
, ERRbadpath
);
1125 reply_nterror(req
, status
);
1129 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1130 if (oplock_request
) {
1131 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1136 * Bug #6898 - clients using Windows opens should
1137 * never be able to set this attribute into the
1140 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1142 status
= SMB_VFS_CREATE_FILE(
1145 root_dir_fid
, /* root_dir_fid */
1146 smb_fname
, /* fname */
1147 access_mask
, /* access_mask */
1148 share_access
, /* share_access */
1149 create_disposition
, /* create_disposition*/
1150 create_options
, /* create_options */
1151 file_attributes
, /* file_attributes */
1152 oplock_request
, /* oplock_request */
1153 allocation_size
, /* allocation_size */
1154 0, /* private_flags */
1156 ea_list
, /* ea_list */
1160 if(!NT_STATUS_IS_OK(status
)) {
1161 if (open_was_deferred(req
->mid
)) {
1162 /* We have re-scheduled this call, no error. */
1165 reply_openerror(req
, status
);
1169 /* Ensure we're pointing at the correct stat struct. */
1170 TALLOC_FREE(smb_fname
);
1171 smb_fname
= fsp
->fsp_name
;
1174 * If the caller set the extended oplock request bit
1175 * and we granted one (by whatever means) - set the
1176 * correct bit for extended oplock reply.
1179 if (oplock_request
&&
1180 (lp_fake_oplocks(SNUM(conn
))
1181 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1184 * Exclusive oplock granted
1187 if (flags
& REQUEST_BATCH_OPLOCK
) {
1188 oplock_granted
= BATCH_OPLOCK_RETURN
;
1190 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1192 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1193 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1195 oplock_granted
= NO_OPLOCK_RETURN
;
1198 file_len
= smb_fname
->st
.st_ex_size
;
1200 /* Realloc the size of parameters and data we will return */
1201 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1202 /* Extended response is 32 more byyes. */
1207 params
= nttrans_realloc(ppparams
, param_len
);
1208 if(params
== NULL
) {
1209 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1214 SCVAL(p
, 0, oplock_granted
);
1217 SSVAL(p
,0,fsp
->fnum
);
1219 if ((create_disposition
== FILE_SUPERSEDE
)
1220 && (info
== FILE_WAS_OVERWRITTEN
)) {
1221 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1227 fattr
= dos_mode(conn
, smb_fname
);
1229 fattr
= FILE_ATTRIBUTE_NORMAL
;
1232 /* Deal with other possible opens having a modified
1234 ZERO_STRUCT(write_time_ts
);
1235 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
1236 if (!null_timespec(write_time_ts
)) {
1237 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
1241 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1242 a_timespec
= smb_fname
->st
.st_ex_atime
;
1243 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1244 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1246 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1247 dos_filetime_timespec(&create_timespec
);
1248 dos_filetime_timespec(&a_timespec
);
1249 dos_filetime_timespec(&m_timespec
);
1250 dos_filetime_timespec(&c_timespec
);
1253 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
1255 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
1257 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
1259 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
1261 SIVAL(p
,0,fattr
); /* File Attributes. */
1263 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1265 SOFF_T(p
,0,file_len
);
1267 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1268 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
1269 size_t num_names
= 0;
1270 unsigned int num_streams
;
1271 struct stream_struct
*streams
= NULL
;
1273 /* Do we have any EA's ? */
1274 status
= get_ea_names_from_file(ctx
, conn
, fsp
,
1275 smb_fname
->base_name
, NULL
, &num_names
);
1276 if (NT_STATUS_IS_OK(status
) && num_names
) {
1277 file_status
&= ~NO_EAS
;
1279 status
= SMB_VFS_STREAMINFO(conn
, NULL
, smb_fname
->base_name
, ctx
,
1280 &num_streams
, &streams
);
1281 /* There is always one stream, ::$DATA. */
1282 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
1283 file_status
&= ~NO_SUBSTREAMS
;
1285 TALLOC_FREE(streams
);
1286 SSVAL(p
,2,file_status
);
1289 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1291 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1294 if (fsp
->is_directory
||
1295 can_write_to_file(conn
, smb_fname
)) {
1296 perms
= FILE_GENERIC_ALL
;
1298 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1303 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1304 smb_fname_str_dbg(smb_fname
)));
1306 /* Send the required number of replies */
1307 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1312 /****************************************************************************
1313 Reply to a NT CANCEL request.
1314 conn POINTER CAN BE NULL HERE !
1315 ****************************************************************************/
1317 void reply_ntcancel(struct smb_request
*req
)
1320 * Go through and cancel any pending change notifies.
1323 START_PROFILE(SMBntcancel
);
1324 srv_cancel_sign_response(req
->sconn
);
1325 remove_pending_change_notify_requests_by_mid(req
->sconn
, req
->mid
);
1326 remove_pending_lock_requests_by_mid_smb1(req
->sconn
, req
->mid
);
1328 DEBUG(3,("reply_ntcancel: cancel called on mid = %llu.\n",
1329 (unsigned long long)req
->mid
));
1331 END_PROFILE(SMBntcancel
);
1335 /****************************************************************************
1337 ****************************************************************************/
1339 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1340 connection_struct
*conn
,
1341 struct smb_request
*req
,
1342 struct smb_filename
*smb_fname_src
,
1343 struct smb_filename
*smb_fname_dst
,
1346 files_struct
*fsp1
,*fsp2
;
1350 NTSTATUS status
= NT_STATUS_OK
;
1353 if (!CAN_WRITE(conn
)) {
1354 status
= NT_STATUS_MEDIA_WRITE_PROTECTED
;
1358 /* Source must already exist. */
1359 if (!VALID_STAT(smb_fname_src
->st
)) {
1360 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1364 /* Ensure attributes match. */
1365 fattr
= dos_mode(conn
, smb_fname_src
);
1366 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1367 status
= NT_STATUS_NO_SUCH_FILE
;
1371 /* Disallow if dst file already exists. */
1372 if (VALID_STAT(smb_fname_dst
->st
)) {
1373 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
1377 /* No links from a directory. */
1378 if (S_ISDIR(smb_fname_src
->st
.st_ex_mode
)) {
1379 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
1383 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1384 smb_fname_str_dbg(smb_fname_src
),
1385 smb_fname_str_dbg(smb_fname_dst
)));
1387 status
= SMB_VFS_CREATE_FILE(
1390 0, /* root_dir_fid */
1391 smb_fname_src
, /* fname */
1392 FILE_READ_DATA
, /* access_mask */
1393 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1395 FILE_OPEN
, /* create_disposition*/
1396 0, /* create_options */
1397 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
1398 NO_OPLOCK
, /* oplock_request */
1399 0, /* allocation_size */
1400 0, /* private_flags */
1406 if (!NT_STATUS_IS_OK(status
)) {
1410 status
= SMB_VFS_CREATE_FILE(
1413 0, /* root_dir_fid */
1414 smb_fname_dst
, /* fname */
1415 FILE_WRITE_DATA
, /* access_mask */
1416 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1418 FILE_CREATE
, /* create_disposition*/
1419 0, /* create_options */
1420 fattr
, /* file_attributes */
1421 NO_OPLOCK
, /* oplock_request */
1422 0, /* allocation_size */
1423 0, /* private_flags */
1429 if (!NT_STATUS_IS_OK(status
)) {
1430 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1434 if (smb_fname_src
->st
.st_ex_size
) {
1435 ret
= vfs_transfer_file(fsp1
, fsp2
, smb_fname_src
->st
.st_ex_size
);
1439 * As we are opening fsp1 read-only we only expect
1440 * an error on close on fsp2 if we are out of space.
1441 * Thus we don't look at the error return from the
1444 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1446 /* Ensure the modtime is set correctly on the destination file. */
1447 set_close_write_time(fsp2
, smb_fname_src
->st
.st_ex_mtime
);
1449 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1451 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1452 creates the file. This isn't the correct thing to do in the copy
1454 if (!parent_dirname(talloc_tos(), smb_fname_dst
->base_name
, &parent
,
1456 status
= NT_STATUS_NO_MEMORY
;
1459 file_set_dosmode(conn
, smb_fname_dst
, fattr
, parent
, false);
1460 TALLOC_FREE(parent
);
1462 if (ret
< (SMB_OFF_T
)smb_fname_src
->st
.st_ex_size
) {
1463 status
= NT_STATUS_DISK_FULL
;
1467 if (!NT_STATUS_IS_OK(status
)) {
1468 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1469 nt_errstr(status
), smb_fname_str_dbg(smb_fname_src
),
1470 smb_fname_str_dbg(smb_fname_dst
)));
1476 /****************************************************************************
1477 Reply to a NT rename request.
1478 ****************************************************************************/
1480 void reply_ntrename(struct smb_request
*req
)
1482 connection_struct
*conn
= req
->conn
;
1483 struct smb_filename
*smb_fname_old
= NULL
;
1484 struct smb_filename
*smb_fname_new
= NULL
;
1485 char *oldname
= NULL
;
1486 char *newname
= NULL
;
1489 bool src_has_wcard
= False
;
1490 bool dest_has_wcard
= False
;
1492 uint32_t ucf_flags_src
= 0;
1493 uint32_t ucf_flags_dst
= 0;
1495 TALLOC_CTX
*ctx
= talloc_tos();
1497 START_PROFILE(SMBntrename
);
1500 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1504 attrs
= SVAL(req
->vwv
+0, 0);
1505 rename_type
= SVAL(req
->vwv
+1, 0);
1507 p
= (const char *)req
->buf
+ 1;
1508 p
+= srvstr_get_path_req_wcard(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1509 &status
, &src_has_wcard
);
1510 if (!NT_STATUS_IS_OK(status
)) {
1511 reply_nterror(req
, status
);
1515 if (ms_has_wild(oldname
)) {
1516 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1521 p
+= srvstr_get_path_req_wcard(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1522 &status
, &dest_has_wcard
);
1523 if (!NT_STATUS_IS_OK(status
)) {
1524 reply_nterror(req
, status
);
1528 /* The newname must begin with a ':' if the oldname contains a ':'. */
1529 if (strchr_m(oldname
, ':') && (newname
[0] != ':')) {
1530 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1535 * If this is a rename operation, allow wildcards and save the
1536 * destination's last component.
1538 if (rename_type
== RENAME_FLAG_RENAME
) {
1539 ucf_flags_src
= UCF_COND_ALLOW_WCARD_LCOMP
;
1540 ucf_flags_dst
= UCF_COND_ALLOW_WCARD_LCOMP
| UCF_SAVE_LCOMP
;
1543 /* rename_internals() calls unix_convert(), so don't call it here. */
1544 status
= filename_convert(ctx
, conn
,
1545 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1550 if (!NT_STATUS_IS_OK(status
)) {
1551 if (NT_STATUS_EQUAL(status
,
1552 NT_STATUS_PATH_NOT_COVERED
)) {
1553 reply_botherror(req
,
1554 NT_STATUS_PATH_NOT_COVERED
,
1555 ERRSRV
, ERRbadpath
);
1558 reply_nterror(req
, status
);
1562 status
= filename_convert(ctx
, conn
,
1563 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1568 if (!NT_STATUS_IS_OK(status
)) {
1569 if (NT_STATUS_EQUAL(status
,
1570 NT_STATUS_PATH_NOT_COVERED
)) {
1571 reply_botherror(req
,
1572 NT_STATUS_PATH_NOT_COVERED
,
1573 ERRSRV
, ERRbadpath
);
1576 reply_nterror(req
, status
);
1580 DEBUG(3,("reply_ntrename: %s -> %s\n",
1581 smb_fname_str_dbg(smb_fname_old
),
1582 smb_fname_str_dbg(smb_fname_new
)));
1584 switch(rename_type
) {
1585 case RENAME_FLAG_RENAME
:
1586 status
= rename_internals(ctx
, conn
, req
,
1587 smb_fname_old
, smb_fname_new
,
1588 attrs
, False
, src_has_wcard
,
1592 case RENAME_FLAG_HARD_LINK
:
1593 if (src_has_wcard
|| dest_has_wcard
) {
1595 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1597 status
= hardlink_internals(ctx
, conn
,
1604 case RENAME_FLAG_COPY
:
1605 if (src_has_wcard
|| dest_has_wcard
) {
1607 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1609 status
= copy_internals(ctx
, conn
, req
,
1615 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1616 status
= NT_STATUS_INVALID_PARAMETER
;
1619 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1623 if (!NT_STATUS_IS_OK(status
)) {
1624 if (open_was_deferred(req
->mid
)) {
1625 /* We have re-scheduled this call. */
1629 reply_nterror(req
, status
);
1633 reply_outbuf(req
, 0, 0);
1635 END_PROFILE(SMBntrename
);
1639 /****************************************************************************
1640 Reply to a notify change - queue the request and
1641 don't allow a directory to be opened.
1642 ****************************************************************************/
1644 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1645 NTSTATUS error_code
,
1646 uint8_t *buf
, size_t len
)
1648 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1651 static void call_nt_transact_notify_change(connection_struct
*conn
,
1652 struct smb_request
*req
,
1656 uint32 parameter_count
,
1657 char **ppdata
, uint32 data_count
,
1658 uint32 max_data_count
,
1659 uint32 max_param_count
)
1661 uint16
*setup
= *ppsetup
;
1667 if(setup_count
< 6) {
1668 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1672 fsp
= file_fsp(req
, SVAL(setup
,4));
1673 filter
= IVAL(setup
, 0);
1674 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1676 DEBUG(3,("call_nt_transact_notify_change\n"));
1679 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1684 char *filter_string
;
1686 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1687 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1691 DEBUG(3,("call_nt_transact_notify_change: notify change "
1692 "called on %s, filter = %s, recursive = %d\n",
1693 fsp_str_dbg(fsp
), filter_string
, recursive
));
1695 TALLOC_FREE(filter_string
);
1698 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1699 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1703 if (fsp
->notify
== NULL
) {
1705 status
= change_notify_create(fsp
, filter
, recursive
);
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 (fsp
->notify
->num_changes
!= 0) {
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
**ppsetup
, uint32 setup_count
,
1761 char **ppparams
, uint32 parameter_count
,
1762 char **ppdata
, uint32 data_count
,
1763 uint32 max_data_count
)
1765 char *params
= *ppparams
;
1766 char *new_name
= NULL
;
1767 files_struct
*fsp
= NULL
;
1768 bool dest_has_wcard
= False
;
1770 TALLOC_CTX
*ctx
= talloc_tos();
1772 if(parameter_count
< 5) {
1773 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1777 fsp
= file_fsp(req
, SVAL(params
, 0));
1778 if (!check_fsp(conn
, req
, fsp
)) {
1781 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1782 parameter_count
- 4,
1783 STR_TERMINATE
, &status
, &dest_has_wcard
);
1784 if (!NT_STATUS_IS_OK(status
)) {
1785 reply_nterror(req
, status
);
1790 * W2K3 ignores this request as the RAW-RENAME test
1791 * demonstrates, so we do.
1793 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1795 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1796 fsp_str_dbg(fsp
), new_name
));
1801 /******************************************************************************
1802 Fake up a completely empty SD.
1803 *******************************************************************************/
1805 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, struct security_descriptor
**ppsd
)
1809 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1811 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1812 return NT_STATUS_NO_MEMORY
;
1815 return NT_STATUS_OK
;
1818 /****************************************************************************
1819 Reply to query a security descriptor.
1820 Callable from SMB2 and SMB2.
1821 If it returns NT_STATUS_BUFFER_TOO_SMALL, pdata_size is initialized with
1823 ****************************************************************************/
1825 NTSTATUS
smbd_do_query_security_desc(connection_struct
*conn
,
1826 TALLOC_CTX
*mem_ctx
,
1828 uint32_t security_info_wanted
,
1829 uint32_t max_data_count
,
1830 uint8_t **ppmarshalled_sd
,
1834 struct security_descriptor
*psd
= NULL
;
1837 * Get the permissions to return.
1840 if ((security_info_wanted
& SECINFO_SACL
) &&
1841 !(fsp
->access_mask
& SEC_FLAG_SYSTEM_SECURITY
)) {
1842 return NT_STATUS_ACCESS_DENIED
;
1845 if ((security_info_wanted
& (SECINFO_DACL
|SECINFO_OWNER
|SECINFO_GROUP
)) &&
1846 !(fsp
->access_mask
& SEC_STD_READ_CONTROL
)) {
1847 return NT_STATUS_ACCESS_DENIED
;
1850 if (!lp_nt_acl_support(SNUM(conn
))) {
1851 status
= get_null_nt_acl(mem_ctx
, &psd
);
1853 status
= SMB_VFS_FGET_NT_ACL(
1854 fsp
, security_info_wanted
, &psd
);
1856 if (!NT_STATUS_IS_OK(status
)) {
1860 if (!(security_info_wanted
& SECINFO_OWNER
)) {
1861 psd
->owner_sid
= NULL
;
1863 if (!(security_info_wanted
& SECINFO_GROUP
)) {
1864 psd
->group_sid
= NULL
;
1866 if (!(security_info_wanted
& SECINFO_DACL
)) {
1869 if (!(security_info_wanted
& SECINFO_SACL
)) {
1873 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1874 * present in the reply to match Windows behavior */
1875 if (psd
->sacl
== NULL
&&
1876 security_info_wanted
& SECINFO_SACL
)
1877 psd
->type
|= SEC_DESC_SACL_PRESENT
;
1878 if (psd
->dacl
== NULL
&&
1879 security_info_wanted
& SECINFO_DACL
)
1880 psd
->type
|= SEC_DESC_DACL_PRESENT
;
1882 *psd_size
= ndr_size_security_descriptor(psd
, 0);
1884 DEBUG(3,("smbd_do_query_security_desc: sd_size = %lu.\n",
1885 (unsigned long)*psd_size
));
1887 if (DEBUGLEVEL
>= 10) {
1888 DEBUG(10,("smbd_do_query_security_desc for file %s\n",
1890 NDR_PRINT_DEBUG(security_descriptor
, psd
);
1893 if (max_data_count
< *psd_size
) {
1895 return NT_STATUS_BUFFER_TOO_SMALL
;
1898 status
= marshall_sec_desc(mem_ctx
, psd
,
1899 ppmarshalled_sd
, psd_size
);
1901 if (!NT_STATUS_IS_OK(status
)) {
1907 return NT_STATUS_OK
;
1910 /****************************************************************************
1911 SMB1 reply to query a security descriptor.
1912 ****************************************************************************/
1914 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1915 struct smb_request
*req
,
1919 uint32 parameter_count
,
1922 uint32 max_data_count
)
1924 char *params
= *ppparams
;
1925 char *data
= *ppdata
;
1927 uint32 security_info_wanted
;
1928 files_struct
*fsp
= NULL
;
1930 uint8_t *marshalled_sd
= NULL
;
1932 if(parameter_count
< 8) {
1933 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1937 fsp
= file_fsp(req
, SVAL(params
,0));
1939 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1943 security_info_wanted
= IVAL(params
,4);
1945 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1946 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
1947 (unsigned int)security_info_wanted
));
1949 params
= nttrans_realloc(ppparams
, 4);
1950 if(params
== NULL
) {
1951 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1956 * Get the permissions to return.
1959 status
= smbd_do_query_security_desc(conn
,
1962 security_info_wanted
,
1967 if (NT_STATUS_EQUAL(status
, NT_STATUS_BUFFER_TOO_SMALL
)) {
1968 SIVAL(params
,0,(uint32_t)sd_size
);
1969 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1970 params
, 4, NULL
, 0);
1974 if (!NT_STATUS_IS_OK(status
)) {
1975 reply_nterror(req
, status
);
1979 SMB_ASSERT(sd_size
> 0);
1981 SIVAL(params
,0,(uint32_t)sd_size
);
1983 if (max_data_count
< sd_size
) {
1984 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1985 params
, 4, NULL
, 0);
1990 * Allocate the data we will return.
1993 data
= nttrans_realloc(ppdata
, sd_size
);
1995 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1999 memcpy(data
, marshalled_sd
, sd_size
);
2001 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
2006 /****************************************************************************
2007 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2008 ****************************************************************************/
2010 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
2011 struct smb_request
*req
,
2015 uint32 parameter_count
,
2018 uint32 max_data_count
)
2020 char *params
= *ppparams
;
2021 char *data
= *ppdata
;
2022 files_struct
*fsp
= NULL
;
2023 uint32 security_info_sent
= 0;
2026 if(parameter_count
< 8) {
2027 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2031 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
2032 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2036 if (!CAN_WRITE(fsp
->conn
)) {
2037 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2041 if(!lp_nt_acl_support(SNUM(conn
))) {
2045 security_info_sent
= IVAL(params
,4);
2047 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
2048 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
2050 if (data_count
== 0) {
2051 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2055 status
= set_sd(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
2057 if (!NT_STATUS_IS_OK(status
)) {
2058 reply_nterror(req
, status
);
2063 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2067 /****************************************************************************
2069 ****************************************************************************/
2071 static void call_nt_transact_ioctl(connection_struct
*conn
,
2072 struct smb_request
*req
,
2073 uint16
**ppsetup
, uint32 setup_count
,
2074 char **ppparams
, uint32 parameter_count
,
2075 char **ppdata
, uint32 data_count
,
2076 uint32 max_data_count
)
2083 char *pdata
= *ppdata
;
2085 if (setup_count
!= 8) {
2086 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
2087 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2091 function
= IVAL(*ppsetup
, 0);
2092 fidnum
= SVAL(*ppsetup
, 4);
2093 isFSctl
= CVAL(*ppsetup
, 6);
2094 compfilter
= CVAL(*ppsetup
, 7);
2096 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2097 function
, fidnum
, isFSctl
, compfilter
));
2099 fsp
=file_fsp(req
, fidnum
);
2100 /* this check is done in each implemented function case for now
2101 because I don't want to break anything... --metze
2102 FSP_BELONGS_CONN(fsp,conn);*/
2104 SMB_PERFCOUNT_SET_IOCTL(&req
->pcd
, function
);
2107 case FSCTL_SET_SPARSE
:
2108 /* pretend this succeeded - tho strictly we should
2109 mark the file sparse (if the local fs supports it)
2110 so we can know if we need to pre-allocate or not */
2112 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
2113 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2116 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
2118 unsigned char objid
[16];
2120 /* This should return the object-id on this file.
2121 * I think I'll make this be the inode+dev. JRA.
2124 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
2126 if (!check_fsp_open(conn
, req
, fsp
)) {
2131 pdata
= nttrans_realloc(ppdata
, data_count
);
2132 if (pdata
== NULL
) {
2133 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2137 /* For backwards compatibility only store the dev/inode. */
2138 push_file_id_16(pdata
, &fsp
->file_id
);
2139 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
2140 push_file_id_16(pdata
+32, &fsp
->file_id
);
2141 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
2146 case FSCTL_GET_REPARSE_POINT
:
2147 /* pretend this fail - my winXP does it like this
2151 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2152 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
2155 case FSCTL_SET_REPARSE_POINT
:
2156 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2160 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2161 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
2164 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
2167 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2168 * and return their volume names. If max_data_count is 16, then it is just
2169 * asking for the number of volumes and length of the combined names.
2171 * pdata is the data allocated by our caller, but that uses
2172 * total_data_count (which is 0 in our case) rather than max_data_count.
2173 * Allocate the correct amount and return the pointer to let
2174 * it be deallocated when we return.
2176 SHADOW_COPY_DATA
*shadow_data
= NULL
;
2177 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
2178 bool labels
= False
;
2179 uint32 labels_data_count
= 0;
2183 if (!check_fsp_open(conn
, req
, fsp
)) {
2187 if (max_data_count
< 16) {
2188 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2190 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2194 if (max_data_count
> 16) {
2198 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
2199 if (shadow_mem_ctx
== NULL
) {
2200 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2201 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2205 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
2206 if (shadow_data
== NULL
) {
2207 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2208 talloc_destroy(shadow_mem_ctx
);
2209 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2213 shadow_data
->mem_ctx
= shadow_mem_ctx
;
2216 * Call the VFS routine to actually do the work.
2218 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2219 talloc_destroy(shadow_data
->mem_ctx
);
2220 if (errno
== ENOSYS
) {
2221 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2222 conn
->connectpath
));
2223 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2226 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2227 conn
->connectpath
));
2228 reply_nterror(req
, NT_STATUS_UNSUCCESSFUL
);
2233 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2238 data_count
= 12+labels_data_count
+4;
2241 if (max_data_count
<data_count
) {
2242 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2243 max_data_count
,data_count
));
2244 talloc_destroy(shadow_data
->mem_ctx
);
2245 reply_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
2249 pdata
= nttrans_realloc(ppdata
, data_count
);
2250 if (pdata
== NULL
) {
2251 talloc_destroy(shadow_data
->mem_ctx
);
2252 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2258 /* num_volumes 4 bytes */
2259 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2262 /* num_labels 4 bytes */
2263 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2266 /* needed_data_count 4 bytes */
2267 SIVAL(pdata
, 8, labels_data_count
+4);
2271 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2272 shadow_data
->num_volumes
, fsp_str_dbg(fsp
)));
2273 if (labels
&& shadow_data
->labels
) {
2274 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2275 srvstr_push(pdata
, req
->flags2
,
2276 cur_pdata
, shadow_data
->labels
[i
],
2277 2*sizeof(SHADOW_COPY_LABEL
),
2278 STR_UNICODE
|STR_TERMINATE
);
2279 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2280 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2284 talloc_destroy(shadow_data
->mem_ctx
);
2286 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
2292 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2294 /* pretend this succeeded -
2296 * we have to send back a list with all files owned by this SID
2298 * but I have to check that --metze
2304 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2306 if (!check_fsp_open(conn
, req
, fsp
)) {
2310 if (data_count
< 8) {
2311 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2315 sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2317 /* unknown 4 bytes: this is not the length of the sid :-( */
2318 /*unknown = IVAL(pdata,0);*/
2320 if (!sid_parse(pdata
+4,sid_len
,&sid
)) {
2321 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2324 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
2326 if (!sid_to_uid(&sid
, &uid
)) {
2327 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2328 sid_string_dbg(&sid
),
2329 (unsigned long)sid_len
));
2333 /* we can take a look at the find source :-)
2335 * find ./ -uid $uid -name '*' is what we need here
2338 * and send 4bytes len and then NULL terminated unicode strings
2341 * but I don't know how to deal with the paged results
2342 * (maybe we can hang the result anywhere in the fsp struct)
2344 * we don't send all files at once
2345 * and at the next we should *not* start from the beginning,
2346 * so we have to cache the result
2351 /* this works for now... */
2352 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2355 case FSCTL_QUERY_ALLOCATED_RANGES
:
2357 /* FIXME: This is just a dummy reply, telling that all of the
2358 * file is allocated. MKS cp needs that.
2359 * Adding the real allocated ranges via FIEMAP on Linux
2360 * and SEEK_DATA/SEEK_HOLE on Solaris is needed to make
2361 * this FSCTL correct for sparse files.
2364 uint64_t offset
, length
;
2366 if (!check_fsp_open(conn
, req
, fsp
)) {
2370 if (data_count
!= 16) {
2371 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: data_count(%u) != 16 is invalid!\n",
2373 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2377 if (max_data_count
< 16) {
2378 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_data_count(%u) < 16 is invalid!\n",
2380 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2384 offset
= BVAL(pdata
,0);
2385 length
= BVAL(pdata
,8);
2387 if (offset
+ length
< offset
) {
2388 /* No 64-bit integer wrap. */
2389 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2393 status
= vfs_stat_fsp(fsp
);
2394 if (!NT_STATUS_IS_OK(status
)) {
2395 reply_nterror(req
, status
);
2399 if (offset
> fsp
->fsp_name
->st
.st_ex_size
||
2400 fsp
->fsp_name
->st
.st_ex_size
== 0 ||
2402 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2404 uint64_t end
= offset
+ length
;
2405 end
= MIN(end
, fsp
->fsp_name
->st
.st_ex_size
);
2408 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
2414 /* Only print this once... */
2415 if (!logged_ioctl_message
) {
2416 logged_ioctl_message
= true;
2417 DEBUG(2,("call_nt_transact_ioctl(0x%x): "
2418 "Currently not implemented.\n",
2423 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2427 #ifdef HAVE_SYS_QUOTAS
2428 /****************************************************************************
2429 Reply to get user quota
2430 ****************************************************************************/
2432 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2433 struct smb_request
*req
,
2437 uint32 parameter_count
,
2440 uint32 max_data_count
)
2442 NTSTATUS nt_status
= NT_STATUS_OK
;
2443 char *params
= *ppparams
;
2444 char *pdata
= *ppdata
;
2446 int data_len
=0,param_len
=0;
2449 files_struct
*fsp
= NULL
;
2453 bool start_enum
= True
;
2454 SMB_NTQUOTA_STRUCT qt
;
2455 SMB_NTQUOTA_LIST
*tmp_list
;
2456 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2461 if (conn
->server_info
->utok
.uid
!= 0) {
2462 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2463 "[%s]\n", lp_servicename(SNUM(conn
)),
2464 conn
->server_info
->unix_name
));
2465 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2470 * Ensure minimum number of parameters sent.
2473 if (parameter_count
< 4) {
2474 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2475 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2479 /* maybe we can check the quota_fnum */
2480 fsp
= file_fsp(req
, SVAL(params
,0));
2481 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2482 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2483 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2487 /* the NULL pointer checking for fsp->fake_file_handle->pd
2488 * is done by CHECK_NTQUOTA_HANDLE_OK()
2490 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2492 level
= SVAL(params
,2);
2494 /* unknown 12 bytes leading in params */
2497 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2498 /* seems that we should continue with the enum here --metze */
2500 if (qt_handle
->quota_list
!=NULL
&&
2501 qt_handle
->tmp_list
==NULL
) {
2504 free_ntquota_list(&(qt_handle
->quota_list
));
2506 /* Realloc the size of parameters and data we will return */
2508 params
= nttrans_realloc(ppparams
, param_len
);
2509 if(params
== NULL
) {
2510 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2515 SIVAL(params
,0,data_len
);
2522 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2524 if (qt_handle
->quota_list
==NULL
&&
2525 qt_handle
->tmp_list
==NULL
) {
2529 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2530 reply_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
2534 /* Realloc the size of parameters and data we will return */
2536 params
= nttrans_realloc(ppparams
, param_len
);
2537 if(params
== NULL
) {
2538 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2542 /* we should not trust the value in max_data_count*/
2543 max_data_count
= MIN(max_data_count
,2048);
2545 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2547 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2553 /* set params Size of returned Quota Data 4 bytes*/
2554 /* but set it later when we know it */
2556 /* for each entry push the data */
2559 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2562 tmp_list
= qt_handle
->tmp_list
;
2564 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2565 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2567 sid_len
= ndr_size_dom_sid(
2568 &tmp_list
->quotas
->sid
, 0);
2569 entry_len
= 40 + sid_len
;
2571 /* nextoffset entry 4 bytes */
2572 SIVAL(entry
,0,entry_len
);
2574 /* then the len of the SID 4 bytes */
2575 SIVAL(entry
,4,sid_len
);
2577 /* unknown data 8 bytes uint64_t */
2578 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2580 /* the used disk space 8 bytes uint64_t */
2581 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2583 /* the soft quotas 8 bytes uint64_t */
2584 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2586 /* the hard quotas 8 bytes uint64_t */
2587 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2589 /* and now the SID */
2590 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2593 qt_handle
->tmp_list
= tmp_list
;
2595 /* overwrite the offset of the last entry */
2596 SIVAL(entry
-entry_len
,0,0);
2598 data_len
= 4+qt_len
;
2599 /* overwrite the params quota_data_len */
2600 SIVAL(params
,0,data_len
);
2604 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2606 /* unknown 4 bytes IVAL(pdata,0) */
2608 if (data_count
< 8) {
2609 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2610 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2614 sid_len
= IVAL(pdata
,4);
2615 /* Ensure this is less than 1mb. */
2616 if (sid_len
> (1024*1024)) {
2617 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2621 if (data_count
< 8+sid_len
) {
2622 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2623 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2627 data_len
= 4+40+sid_len
;
2629 if (max_data_count
< data_len
) {
2630 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2631 max_data_count
, data_len
));
2633 SIVAL(params
,0,data_len
);
2635 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2639 if (!sid_parse(pdata
+8,sid_len
,&sid
)) {
2640 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2644 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2647 * we have to return zero's in all fields
2648 * instead of returning an error here
2653 /* Realloc the size of parameters and data we will return */
2655 params
= nttrans_realloc(ppparams
, param_len
);
2656 if(params
== NULL
) {
2657 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2661 pdata
= nttrans_realloc(ppdata
, data_len
);
2663 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2669 /* set params Size of returned Quota Data 4 bytes*/
2670 SIVAL(params
,0,data_len
);
2672 /* nextoffset entry 4 bytes */
2675 /* then the len of the SID 4 bytes */
2676 SIVAL(entry
,4,sid_len
);
2678 /* unknown data 8 bytes uint64_t */
2679 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2681 /* the used disk space 8 bytes uint64_t */
2682 SBIG_UINT(entry
,16,qt
.usedspace
);
2684 /* the soft quotas 8 bytes uint64_t */
2685 SBIG_UINT(entry
,24,qt
.softlim
);
2687 /* the hard quotas 8 bytes uint64_t */
2688 SBIG_UINT(entry
,32,qt
.hardlim
);
2690 /* and now the SID */
2691 sid_linearize(entry
+40, sid_len
, &sid
);
2696 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2697 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2702 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2706 /****************************************************************************
2707 Reply to set user quota
2708 ****************************************************************************/
2710 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2711 struct smb_request
*req
,
2715 uint32 parameter_count
,
2718 uint32 max_data_count
)
2720 char *params
= *ppparams
;
2721 char *pdata
= *ppdata
;
2722 int data_len
=0,param_len
=0;
2723 SMB_NTQUOTA_STRUCT qt
;
2726 files_struct
*fsp
= NULL
;
2731 if (conn
->server_info
->utok
.uid
!= 0) {
2732 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2733 "[%s]\n", lp_servicename(SNUM(conn
)),
2734 conn
->server_info
->unix_name
));
2735 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2740 * Ensure minimum number of parameters sent.
2743 if (parameter_count
< 2) {
2744 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2745 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2749 /* maybe we can check the quota_fnum */
2750 fsp
= file_fsp(req
, SVAL(params
,0));
2751 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2752 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2753 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2757 if (data_count
< 40) {
2758 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2759 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2763 /* offset to next quota record.
2764 * 4 bytes IVAL(pdata,0)
2769 sid_len
= IVAL(pdata
,4);
2771 if (data_count
< 40+sid_len
|| (40+sid_len
< sid_len
)) {
2772 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2773 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2777 /* unknown 8 bytes in pdata
2778 * maybe its the change time in NTTIME
2781 /* the used space 8 bytes (uint64_t)*/
2782 qt
.usedspace
= (uint64_t)IVAL(pdata
,16);
2783 #ifdef LARGE_SMB_OFF_T
2784 qt
.usedspace
|= (((uint64_t)IVAL(pdata
,20)) << 32);
2785 #else /* LARGE_SMB_OFF_T */
2786 if ((IVAL(pdata
,20) != 0)&&
2787 ((qt
.usedspace
!= 0xFFFFFFFF)||
2788 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2789 /* more than 32 bits? */
2790 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2793 #endif /* LARGE_SMB_OFF_T */
2795 /* the soft quotas 8 bytes (uint64_t)*/
2796 qt
.softlim
= (uint64_t)IVAL(pdata
,24);
2797 #ifdef LARGE_SMB_OFF_T
2798 qt
.softlim
|= (((uint64_t)IVAL(pdata
,28)) << 32);
2799 #else /* LARGE_SMB_OFF_T */
2800 if ((IVAL(pdata
,28) != 0)&&
2801 ((qt
.softlim
!= 0xFFFFFFFF)||
2802 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2803 /* more than 32 bits? */
2804 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2807 #endif /* LARGE_SMB_OFF_T */
2809 /* the hard quotas 8 bytes (uint64_t)*/
2810 qt
.hardlim
= (uint64_t)IVAL(pdata
,32);
2811 #ifdef LARGE_SMB_OFF_T
2812 qt
.hardlim
|= (((uint64_t)IVAL(pdata
,36)) << 32);
2813 #else /* LARGE_SMB_OFF_T */
2814 if ((IVAL(pdata
,36) != 0)&&
2815 ((qt
.hardlim
!= 0xFFFFFFFF)||
2816 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2817 /* more than 32 bits? */
2818 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2821 #endif /* LARGE_SMB_OFF_T */
2823 if (!sid_parse(pdata
+40,sid_len
,&sid
)) {
2824 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2828 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2830 /* 44 unknown bytes left... */
2832 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2833 reply_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
2837 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2840 #endif /* HAVE_SYS_QUOTAS */
2842 static void handle_nttrans(connection_struct
*conn
,
2843 struct trans_state
*state
,
2844 struct smb_request
*req
)
2846 if (get_Protocol() >= PROTOCOL_NT1
) {
2847 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2848 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2852 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2854 /* Now we must call the relevant NT_TRANS function */
2855 switch(state
->call
) {
2856 case NT_TRANSACT_CREATE
:
2858 START_PROFILE(NT_transact_create
);
2859 call_nt_transact_create(
2861 &state
->setup
, state
->setup_count
,
2862 &state
->param
, state
->total_param
,
2863 &state
->data
, state
->total_data
,
2864 state
->max_data_return
);
2865 END_PROFILE(NT_transact_create
);
2869 case NT_TRANSACT_IOCTL
:
2871 START_PROFILE(NT_transact_ioctl
);
2872 call_nt_transact_ioctl(
2874 &state
->setup
, state
->setup_count
,
2875 &state
->param
, state
->total_param
,
2876 &state
->data
, state
->total_data
,
2877 state
->max_data_return
);
2878 END_PROFILE(NT_transact_ioctl
);
2882 case NT_TRANSACT_SET_SECURITY_DESC
:
2884 START_PROFILE(NT_transact_set_security_desc
);
2885 call_nt_transact_set_security_desc(
2887 &state
->setup
, state
->setup_count
,
2888 &state
->param
, state
->total_param
,
2889 &state
->data
, state
->total_data
,
2890 state
->max_data_return
);
2891 END_PROFILE(NT_transact_set_security_desc
);
2895 case NT_TRANSACT_NOTIFY_CHANGE
:
2897 START_PROFILE(NT_transact_notify_change
);
2898 call_nt_transact_notify_change(
2900 &state
->setup
, state
->setup_count
,
2901 &state
->param
, state
->total_param
,
2902 &state
->data
, state
->total_data
,
2903 state
->max_data_return
,
2904 state
->max_param_return
);
2905 END_PROFILE(NT_transact_notify_change
);
2909 case NT_TRANSACT_RENAME
:
2911 START_PROFILE(NT_transact_rename
);
2912 call_nt_transact_rename(
2914 &state
->setup
, state
->setup_count
,
2915 &state
->param
, state
->total_param
,
2916 &state
->data
, state
->total_data
,
2917 state
->max_data_return
);
2918 END_PROFILE(NT_transact_rename
);
2922 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2924 START_PROFILE(NT_transact_query_security_desc
);
2925 call_nt_transact_query_security_desc(
2927 &state
->setup
, state
->setup_count
,
2928 &state
->param
, state
->total_param
,
2929 &state
->data
, state
->total_data
,
2930 state
->max_data_return
);
2931 END_PROFILE(NT_transact_query_security_desc
);
2935 #ifdef HAVE_SYS_QUOTAS
2936 case NT_TRANSACT_GET_USER_QUOTA
:
2938 START_PROFILE(NT_transact_get_user_quota
);
2939 call_nt_transact_get_user_quota(
2941 &state
->setup
, state
->setup_count
,
2942 &state
->param
, state
->total_param
,
2943 &state
->data
, state
->total_data
,
2944 state
->max_data_return
);
2945 END_PROFILE(NT_transact_get_user_quota
);
2949 case NT_TRANSACT_SET_USER_QUOTA
:
2951 START_PROFILE(NT_transact_set_user_quota
);
2952 call_nt_transact_set_user_quota(
2954 &state
->setup
, state
->setup_count
,
2955 &state
->param
, state
->total_param
,
2956 &state
->data
, state
->total_data
,
2957 state
->max_data_return
);
2958 END_PROFILE(NT_transact_set_user_quota
);
2961 #endif /* HAVE_SYS_QUOTAS */
2964 /* Error in request */
2965 DEBUG(0,("handle_nttrans: Unknown request %d in "
2966 "nttrans call\n", state
->call
));
2967 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2973 /****************************************************************************
2974 Reply to a SMBNTtrans.
2975 ****************************************************************************/
2977 void reply_nttrans(struct smb_request
*req
)
2979 connection_struct
*conn
= req
->conn
;
2984 uint16 function_code
;
2986 struct trans_state
*state
;
2988 START_PROFILE(SMBnttrans
);
2990 if (req
->wct
< 19) {
2991 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2992 END_PROFILE(SMBnttrans
);
2996 pscnt
= IVAL(req
->vwv
+9, 1);
2997 psoff
= IVAL(req
->vwv
+11, 1);
2998 dscnt
= IVAL(req
->vwv
+13, 1);
2999 dsoff
= IVAL(req
->vwv
+15, 1);
3000 function_code
= SVAL(req
->vwv
+18, 0);
3002 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
3003 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
3004 END_PROFILE(SMBnttrans
);
3008 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
3009 if (!NT_STATUS_IS_OK(result
)) {
3010 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
3011 reply_nterror(req
, result
);
3012 END_PROFILE(SMBnttrans
);
3016 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
3017 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3018 END_PROFILE(SMBnttrans
);
3022 state
->cmd
= SMBnttrans
;
3024 state
->mid
= req
->mid
;
3025 state
->vuid
= req
->vuid
;
3026 state
->total_data
= IVAL(req
->vwv
+3, 1);
3028 state
->total_param
= IVAL(req
->vwv
+1, 1);
3029 state
->param
= NULL
;
3030 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
3031 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
3033 /* setup count is in *words* */
3034 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
3035 state
->setup
= NULL
;
3036 state
->call
= function_code
;
3038 DEBUG(10, ("num_setup=%u, "
3039 "param_total=%u, this_param=%u, max_param=%u, "
3040 "data_total=%u, this_data=%u, max_data=%u, "
3041 "param_offset=%u, data_offset=%u\n",
3042 (unsigned)state
->setup_count
,
3043 (unsigned)state
->total_param
, (unsigned)pscnt
,
3044 (unsigned)state
->max_param_return
,
3045 (unsigned)state
->total_data
, (unsigned)dscnt
,
3046 (unsigned)state
->max_data_return
,
3047 (unsigned)psoff
, (unsigned)dsoff
));
3050 * All nttrans messages we handle have smb_wct == 19 +
3051 * state->setup_count. Ensure this is so as a sanity check.
3054 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
3055 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
3056 req
->wct
, 19 + (state
->setup_count
/2)));
3060 /* Don't allow more than 128mb for each value. */
3061 if ((state
->total_data
> (1024*1024*128)) ||
3062 (state
->total_param
> (1024*1024*128))) {
3063 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3064 END_PROFILE(SMBnttrans
);
3068 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
3071 if (state
->total_data
) {
3073 if (trans_oob(state
->total_data
, 0, dscnt
)
3074 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
3078 /* Can't use talloc here, the core routines do realloc on the
3079 * params and data. */
3080 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
3081 DEBUG(0,("reply_nttrans: data malloc fail for %u "
3082 "bytes !\n", (unsigned int)state
->total_data
));
3084 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3085 END_PROFILE(SMBnttrans
);
3089 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
3092 if (state
->total_param
) {
3094 if (trans_oob(state
->total_param
, 0, pscnt
)
3095 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
3099 /* Can't use talloc here, the core routines do realloc on the
3100 * params and data. */
3101 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
3102 DEBUG(0,("reply_nttrans: param malloc fail for %u "
3103 "bytes !\n", (unsigned int)state
->total_param
));
3104 SAFE_FREE(state
->data
);
3106 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3107 END_PROFILE(SMBnttrans
);
3111 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
3114 state
->received_data
= dscnt
;
3115 state
->received_param
= pscnt
;
3117 if(state
->setup_count
> 0) {
3118 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
3119 state
->setup_count
));
3122 * No overflow possible here, state->setup_count is an
3123 * unsigned int, being filled by a single byte from
3124 * CVAL(req->vwv+13, 0) above. The cast in the comparison
3125 * below is not necessary, it's here to clarify things. The
3126 * validity of req->vwv and req->wct has been checked in
3127 * init_smb_request already.
3129 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
3133 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
3134 if (state
->setup
== NULL
) {
3135 DEBUG(0,("reply_nttrans : Out of memory\n"));
3136 SAFE_FREE(state
->data
);
3137 SAFE_FREE(state
->param
);
3139 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
3140 END_PROFILE(SMBnttrans
);
3144 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
3145 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
3148 if ((state
->received_data
== state
->total_data
) &&
3149 (state
->received_param
== state
->total_param
)) {
3150 handle_nttrans(conn
, state
, req
);
3151 SAFE_FREE(state
->param
);
3152 SAFE_FREE(state
->data
);
3154 END_PROFILE(SMBnttrans
);
3158 DLIST_ADD(conn
->pending_trans
, state
);
3160 /* We need to send an interim response then receive the rest
3161 of the parameter/data bytes */
3162 reply_outbuf(req
, 0, 0);
3163 show_msg((char *)req
->outbuf
);
3164 END_PROFILE(SMBnttrans
);
3169 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3170 SAFE_FREE(state
->data
);
3171 SAFE_FREE(state
->param
);
3173 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3174 END_PROFILE(SMBnttrans
);
3178 /****************************************************************************
3179 Reply to a SMBnttranss
3180 ****************************************************************************/
3182 void reply_nttranss(struct smb_request
*req
)
3184 connection_struct
*conn
= req
->conn
;
3185 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
3186 struct trans_state
*state
;
3188 START_PROFILE(SMBnttranss
);
3190 show_msg((char *)req
->inbuf
);
3192 if (req
->wct
< 18) {
3193 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3194 END_PROFILE(SMBnttranss
);
3198 for (state
= conn
->pending_trans
; state
!= NULL
;
3199 state
= state
->next
) {
3200 if (state
->mid
== req
->mid
) {
3205 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
3206 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3207 END_PROFILE(SMBnttranss
);
3211 /* Revise state->total_param and state->total_data in case they have
3212 changed downwards */
3213 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
3214 state
->total_param
= IVAL(req
->vwv
+1, 1);
3216 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
3217 state
->total_data
= IVAL(req
->vwv
+3, 1);
3220 pcnt
= IVAL(req
->vwv
+5, 1);
3221 poff
= IVAL(req
->vwv
+7, 1);
3222 pdisp
= IVAL(req
->vwv
+9, 1);
3224 dcnt
= IVAL(req
->vwv
+11, 1);
3225 doff
= IVAL(req
->vwv
+13, 1);
3226 ddisp
= IVAL(req
->vwv
+15, 1);
3228 state
->received_param
+= pcnt
;
3229 state
->received_data
+= dcnt
;
3231 if ((state
->received_data
> state
->total_data
) ||
3232 (state
->received_param
> state
->total_param
))
3236 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
3237 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
3240 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
3244 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
3245 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
3248 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
3251 if ((state
->received_param
< state
->total_param
) ||
3252 (state
->received_data
< state
->total_data
)) {
3253 END_PROFILE(SMBnttranss
);
3257 handle_nttrans(conn
, state
, req
);
3259 DLIST_REMOVE(conn
->pending_trans
, state
);
3260 SAFE_FREE(state
->data
);
3261 SAFE_FREE(state
->param
);
3263 END_PROFILE(SMBnttranss
);
3268 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3269 DLIST_REMOVE(conn
->pending_trans
, state
);
3270 SAFE_FREE(state
->data
);
3271 SAFE_FREE(state
->param
);
3273 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3274 END_PROFILE(SMBnttranss
);