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"
24 extern const struct generic_mapping file_generic_mapping
;
26 static char *nttrans_realloc(char **ptr
, size_t size
)
29 smb_panic("nttrans_realloc() called with NULL ptr");
32 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
36 memset(*ptr
,'\0',size
);
40 /****************************************************************************
41 Send the required number of replies back.
42 We assume all fields other than the data fields are
43 set correctly for the type of call.
44 HACK ! Always assumes smb_setup field is zero.
45 ****************************************************************************/
47 void send_nt_replies(connection_struct
*conn
,
48 struct smb_request
*req
, NTSTATUS nt_error
,
49 char *params
, int paramsize
,
50 char *pdata
, int datasize
)
52 int data_to_send
= datasize
;
53 int params_to_send
= paramsize
;
57 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
58 int alignment_offset
= 3;
59 int data_alignment_offset
= 0;
60 struct smbd_server_connection
*sconn
= smbd_server_conn
;
61 int max_send
= sconn
->smb1
.sessions
.max_send
;
64 * If there genuinely are no parameters or data to send just send
68 if(params_to_send
== 0 && data_to_send
== 0) {
69 reply_outbuf(req
, 18, 0);
70 if (NT_STATUS_V(nt_error
)) {
71 error_packet_set((char *)req
->outbuf
,
75 show_msg((char *)req
->outbuf
);
76 if (!srv_send_smb(smbd_server_fd(),
79 IS_CONN_ENCRYPTED(conn
),
81 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
83 TALLOC_FREE(req
->outbuf
);
88 * When sending params and data ensure that both are nicely aligned.
89 * Only do this alignment when there is also data to send - else
90 * can cause NT redirector problems.
93 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
94 data_alignment_offset
= 4 - (params_to_send
% 4);
98 * Space is bufsize minus Netbios over TCP header minus SMB header.
99 * The alignment_offset is to align the param bytes on a four byte
100 * boundary (2 bytes for data len, one byte pad).
101 * NT needs this to work correctly.
104 useable_space
= max_send
- (smb_size
107 + data_alignment_offset
);
109 if (useable_space
< 0) {
110 char *msg
= talloc_asprintf(
112 "send_nt_replies failed sanity useable_space = %d!!!",
114 DEBUG(0, ("%s\n", msg
));
115 exit_server_cleanly(msg
);
118 while (params_to_send
|| data_to_send
) {
121 * Calculate whether we will totally or partially fill this packet.
124 total_sent_thistime
= params_to_send
+ data_to_send
;
127 * We can never send more than useable_space.
130 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
132 reply_outbuf(req
, 18,
133 total_sent_thistime
+ alignment_offset
134 + data_alignment_offset
);
137 * We might have had SMBnttranss in req->inbuf, fix that.
139 SCVAL(req
->outbuf
, smb_com
, SMBnttrans
);
142 * Set total params and data to be sent.
145 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
146 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
149 * Calculate how many parameters and data we can fit into
150 * this packet. Parameters get precedence.
153 params_sent_thistime
= MIN(params_to_send
,useable_space
);
154 data_sent_thistime
= useable_space
- params_sent_thistime
;
155 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
157 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
158 params_sent_thistime
);
160 if(params_sent_thistime
== 0) {
161 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
162 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
165 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
166 * parameter bytes, however the first 4 bytes of outbuf are
167 * the Netbios over TCP header. Thus use smb_base() to subtract
168 * them from the calculation.
171 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
172 ((smb_buf(req
->outbuf
)+alignment_offset
)
173 - smb_base(req
->outbuf
)));
175 * Absolute displacement of param bytes sent in this packet.
178 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
183 * Deal with the data portion.
186 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
188 if(data_sent_thistime
== 0) {
189 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
190 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
193 * The offset of the data bytes is the offset of the
194 * parameter bytes plus the number of parameters being sent this time.
197 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
198 ((smb_buf(req
->outbuf
)+alignment_offset
) -
199 smb_base(req
->outbuf
))
200 + params_sent_thistime
+ data_alignment_offset
);
201 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
205 * Copy the param bytes into the packet.
208 if(params_sent_thistime
) {
209 if (alignment_offset
!= 0) {
210 memset(smb_buf(req
->outbuf
), 0,
213 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
214 params_sent_thistime
);
218 * Copy in the data bytes
221 if(data_sent_thistime
) {
222 if (data_alignment_offset
!= 0) {
223 memset((smb_buf(req
->outbuf
)+alignment_offset
+
224 params_sent_thistime
), 0,
225 data_alignment_offset
);
227 memcpy(smb_buf(req
->outbuf
)+alignment_offset
228 +params_sent_thistime
+data_alignment_offset
,
229 pd
,data_sent_thistime
);
232 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
233 params_sent_thistime
, data_sent_thistime
, useable_space
));
234 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
235 params_to_send
, data_to_send
, paramsize
, datasize
));
237 if (NT_STATUS_V(nt_error
)) {
238 error_packet_set((char *)req
->outbuf
,
243 /* Send the packet */
244 show_msg((char *)req
->outbuf
);
245 if (!srv_send_smb(smbd_server_fd(),
248 IS_CONN_ENCRYPTED(conn
),
250 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
253 TALLOC_FREE(req
->outbuf
);
255 pp
+= params_sent_thistime
;
256 pd
+= data_sent_thistime
;
258 params_to_send
-= params_sent_thistime
;
259 data_to_send
-= data_sent_thistime
;
265 if(params_to_send
< 0 || data_to_send
< 0) {
266 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
267 params_to_send
, data_to_send
));
268 exit_server_cleanly("send_nt_replies: internal error");
273 /****************************************************************************
274 Reply to an NT create and X call on a pipe
275 ****************************************************************************/
277 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
278 struct smb_request
*req
, int *ppnum
)
283 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
285 /* Strip \\ off the name. */
288 status
= open_np_file(req
, fname
, &fsp
);
289 if (!NT_STATUS_IS_OK(status
)) {
290 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
291 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
295 reply_nterror(req
, status
);
303 /****************************************************************************
304 Reply to an NT create and X call for pipes.
305 ****************************************************************************/
307 static void do_ntcreate_pipe_open(connection_struct
*conn
,
308 struct smb_request
*req
)
313 uint32 flags
= IVAL(req
->vwv
+3, 1);
314 TALLOC_CTX
*ctx
= talloc_tos();
316 srvstr_pull_req_talloc(ctx
, req
, &fname
, req
->buf
, STR_TERMINATE
);
319 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
323 nt_open_pipe(fname
, conn
, req
, &pnum
);
331 * Deal with pipe return.
334 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
335 /* This is very strange. We
336 * return 50 words, but only set
337 * the wcnt to 42 ? It's definately
338 * what happens on the wire....
340 reply_outbuf(req
, 50, 0);
341 SCVAL(req
->outbuf
,smb_wct
,42);
343 reply_outbuf(req
, 34, 0);
346 p
= (char *)req
->outbuf
+ smb_vwv2
;
350 SIVAL(p
,0,FILE_WAS_OPENED
);
353 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
356 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
358 SSVAL(p
,2, 0x5FF); /* ? */
361 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
363 SIVAL(p
,0,FILE_GENERIC_ALL
);
365 * For pipes W2K3 seems to return
367 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
369 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
372 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
377 struct case_semantics_state
{
378 connection_struct
*conn
;
381 bool short_case_preserve
;
384 /****************************************************************************
385 Restore case semantics.
386 ****************************************************************************/
388 static int restore_case_semantics(struct case_semantics_state
*state
)
390 state
->conn
->case_sensitive
= state
->case_sensitive
;
391 state
->conn
->case_preserve
= state
->case_preserve
;
392 state
->conn
->short_case_preserve
= state
->short_case_preserve
;
396 /****************************************************************************
398 ****************************************************************************/
400 static struct case_semantics_state
*set_posix_case_semantics(TALLOC_CTX
*mem_ctx
,
401 connection_struct
*conn
)
403 struct case_semantics_state
*result
;
405 if (!(result
= talloc(mem_ctx
, struct case_semantics_state
))) {
410 result
->case_sensitive
= conn
->case_sensitive
;
411 result
->case_preserve
= conn
->case_preserve
;
412 result
->short_case_preserve
= conn
->short_case_preserve
;
415 conn
->case_sensitive
= True
;
416 conn
->case_preserve
= True
;
417 conn
->short_case_preserve
= True
;
419 talloc_set_destructor(result
, restore_case_semantics
);
424 /****************************************************************************
425 Reply to an NT create and X call.
426 ****************************************************************************/
428 void reply_ntcreate_and_X(struct smb_request
*req
)
430 connection_struct
*conn
= req
->conn
;
431 struct smb_filename
*smb_fname
= NULL
;
435 uint32 file_attributes
;
437 uint32 create_disposition
;
438 uint32 create_options
;
440 uint64_t allocation_size
;
441 /* Breakout the oplock request bits so we can set the
442 reply bits separately. */
444 SMB_OFF_T file_len
= 0;
446 files_struct
*fsp
= NULL
;
448 struct timespec create_timespec
;
449 struct timespec c_timespec
;
450 struct timespec a_timespec
;
451 struct timespec m_timespec
;
452 struct timespec write_time_ts
;
455 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
456 struct case_semantics_state
*case_state
= NULL
;
457 TALLOC_CTX
*ctx
= talloc_tos();
459 START_PROFILE(SMBntcreateX
);
462 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
466 flags
= IVAL(req
->vwv
+3, 1);
467 access_mask
= IVAL(req
->vwv
+7, 1);
468 file_attributes
= IVAL(req
->vwv
+13, 1);
469 share_access
= IVAL(req
->vwv
+15, 1);
470 create_disposition
= IVAL(req
->vwv
+17, 1);
471 create_options
= IVAL(req
->vwv
+19, 1);
472 root_dir_fid
= (uint16
)IVAL(req
->vwv
+5, 1);
474 allocation_size
= (uint64_t)IVAL(req
->vwv
+9, 1);
475 #ifdef LARGE_SMB_OFF_T
476 allocation_size
|= (((uint64_t)IVAL(req
->vwv
+11, 1)) << 32);
479 srvstr_get_path_req(ctx
, req
, &fname
, (const char *)req
->buf
,
480 STR_TERMINATE
, &status
);
482 if (!NT_STATUS_IS_OK(status
)) {
483 reply_nterror(req
, status
);
487 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
488 "file_attributes = 0x%x, share_access = 0x%x, "
489 "create_disposition = 0x%x create_options = 0x%x "
490 "root_dir_fid = 0x%x, fname = %s\n",
492 (unsigned int)access_mask
,
493 (unsigned int)file_attributes
,
494 (unsigned int)share_access
,
495 (unsigned int)create_disposition
,
496 (unsigned int)create_options
,
497 (unsigned int)root_dir_fid
,
501 * we need to remove ignored bits when they come directly from the client
502 * because we reuse some of them for internal stuff
504 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
507 * If it's an IPC, use the pipe handler.
511 if (lp_nt_pipe_support()) {
512 do_ntcreate_pipe_open(conn
, req
);
515 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
519 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
520 if (oplock_request
) {
521 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
525 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
526 case_state
= set_posix_case_semantics(ctx
, conn
);
528 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
533 status
= filename_convert(ctx
,
535 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
541 TALLOC_FREE(case_state
);
543 if (!NT_STATUS_IS_OK(status
)) {
544 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
546 NT_STATUS_PATH_NOT_COVERED
,
550 reply_nterror(req
, status
);
555 * Bug #6898 - clients using Windows opens should
556 * never be able to set this attribute into the
559 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
561 status
= SMB_VFS_CREATE_FILE(
564 root_dir_fid
, /* root_dir_fid */
565 smb_fname
, /* fname */
566 access_mask
, /* access_mask */
567 share_access
, /* share_access */
568 create_disposition
, /* create_disposition*/
569 create_options
, /* create_options */
570 file_attributes
, /* file_attributes */
571 oplock_request
, /* oplock_request */
572 allocation_size
, /* allocation_size */
578 if (!NT_STATUS_IS_OK(status
)) {
579 if (open_was_deferred(req
->mid
)) {
580 /* We have re-scheduled this call, no error. */
583 reply_openerror(req
, status
);
587 /* Ensure we're pointing at the correct stat struct. */
588 TALLOC_FREE(smb_fname
);
589 smb_fname
= fsp
->fsp_name
;
592 * If the caller set the extended oplock request bit
593 * and we granted one (by whatever means) - set the
594 * correct bit for extended oplock reply.
597 if (oplock_request
&&
598 (lp_fake_oplocks(SNUM(conn
))
599 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
602 * Exclusive oplock granted
605 if (flags
& REQUEST_BATCH_OPLOCK
) {
606 oplock_granted
= BATCH_OPLOCK_RETURN
;
608 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
610 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
611 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
613 oplock_granted
= NO_OPLOCK_RETURN
;
616 file_len
= smb_fname
->st
.st_ex_size
;
618 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
619 /* This is very strange. We
620 * return 50 words, but only set
621 * the wcnt to 42 ? It's definately
622 * what happens on the wire....
624 reply_outbuf(req
, 50, 0);
625 SCVAL(req
->outbuf
,smb_wct
,42);
627 reply_outbuf(req
, 34, 0);
630 p
= (char *)req
->outbuf
+ smb_vwv2
;
632 SCVAL(p
, 0, oplock_granted
);
635 SSVAL(p
,0,fsp
->fnum
);
637 if ((create_disposition
== FILE_SUPERSEDE
)
638 && (info
== FILE_WAS_OVERWRITTEN
)) {
639 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
645 fattr
= dos_mode(conn
, smb_fname
);
647 fattr
= FILE_ATTRIBUTE_NORMAL
;
650 /* Deal with other possible opens having a modified
652 ZERO_STRUCT(write_time_ts
);
653 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
654 if (!null_timespec(write_time_ts
)) {
655 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
659 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
660 a_timespec
= smb_fname
->st
.st_ex_atime
;
661 m_timespec
= smb_fname
->st
.st_ex_mtime
;
662 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
664 if (lp_dos_filetime_resolution(SNUM(conn
))) {
665 dos_filetime_timespec(&create_timespec
);
666 dos_filetime_timespec(&a_timespec
);
667 dos_filetime_timespec(&m_timespec
);
668 dos_filetime_timespec(&c_timespec
);
671 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
673 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
675 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
677 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
679 SIVAL(p
,0,fattr
); /* File Attributes. */
681 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
683 SOFF_T(p
,0,file_len
);
685 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
686 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
687 size_t num_names
= 0;
688 unsigned int num_streams
;
689 struct stream_struct
*streams
= NULL
;
691 /* Do we have any EA's ? */
692 status
= get_ea_names_from_file(ctx
, conn
, fsp
,
693 smb_fname
->base_name
, NULL
, &num_names
);
694 if (NT_STATUS_IS_OK(status
) && num_names
) {
695 file_status
&= ~NO_EAS
;
697 status
= SMB_VFS_STREAMINFO(conn
, NULL
, smb_fname
->base_name
, ctx
,
698 &num_streams
, &streams
);
699 /* There is always one stream, ::$DATA. */
700 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
701 file_status
&= ~NO_SUBSTREAMS
;
703 TALLOC_FREE(streams
);
704 SSVAL(p
,2,file_status
);
707 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
709 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
712 if (fsp
->is_directory
||
713 can_write_to_file(conn
, smb_fname
)) {
714 perms
= FILE_GENERIC_ALL
;
716 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
721 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
722 fsp
->fnum
, smb_fname_str_dbg(smb_fname
)));
726 END_PROFILE(SMBntcreateX
);
730 /****************************************************************************
731 Reply to a NT_TRANSACT_CREATE call to open a pipe.
732 ****************************************************************************/
734 static void do_nt_transact_create_pipe(connection_struct
*conn
,
735 struct smb_request
*req
,
736 uint16
**ppsetup
, uint32 setup_count
,
737 char **ppparams
, uint32 parameter_count
,
738 char **ppdata
, uint32 data_count
)
741 char *params
= *ppparams
;
747 TALLOC_CTX
*ctx
= talloc_tos();
750 * Ensure minimum number of parameters sent.
753 if(parameter_count
< 54) {
754 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
755 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
759 flags
= IVAL(params
,0);
761 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
762 parameter_count
-53, STR_TERMINATE
,
764 if (!NT_STATUS_IS_OK(status
)) {
765 reply_nterror(req
, status
);
769 nt_open_pipe(fname
, conn
, req
, &pnum
);
776 /* Realloc the size of parameters and data we will return */
777 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
778 /* Extended response is 32 more byyes. */
783 params
= nttrans_realloc(ppparams
, param_len
);
785 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
790 SCVAL(p
,0,NO_OPLOCK_RETURN
);
795 SIVAL(p
,0,FILE_WAS_OPENED
);
799 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
802 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
804 SSVAL(p
,2, 0x5FF); /* ? */
807 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
809 SIVAL(p
,0,FILE_GENERIC_ALL
);
811 * For pipes W2K3 seems to return
813 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
815 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
818 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
820 /* Send the required number of replies */
821 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
826 /****************************************************************************
827 Internal fn to set security descriptors.
828 ****************************************************************************/
830 static NTSTATUS
set_sd(files_struct
*fsp
, uint8
*data
, uint32 sd_len
,
831 uint32 security_info_sent
)
833 SEC_DESC
*psd
= NULL
;
836 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
840 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
842 if (!NT_STATUS_IS_OK(status
)) {
846 if (psd
->owner_sid
== NULL
) {
847 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
849 if (psd
->group_sid
== NULL
) {
850 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
853 /* Convert all the generic bits. */
854 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
855 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
857 if (DEBUGLEVEL
>= 10) {
858 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp
)));
859 NDR_PRINT_DEBUG(security_descriptor
, psd
);
862 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
869 /****************************************************************************
870 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
871 ****************************************************************************/
873 struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
875 struct ea_list
*ea_list_head
= NULL
;
882 while (offset
+ 4 <= data_size
) {
883 size_t next_offset
= IVAL(pdata
,offset
);
884 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
890 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
891 if (next_offset
== 0) {
894 offset
+= next_offset
;
900 /****************************************************************************
901 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
902 ****************************************************************************/
904 static void call_nt_transact_create(connection_struct
*conn
,
905 struct smb_request
*req
,
906 uint16
**ppsetup
, uint32 setup_count
,
907 char **ppparams
, uint32 parameter_count
,
908 char **ppdata
, uint32 data_count
,
909 uint32 max_data_count
)
911 struct smb_filename
*smb_fname
= NULL
;
913 char *params
= *ppparams
;
914 char *data
= *ppdata
;
915 /* Breakout the oplock request bits so we can set the reply bits separately. */
917 SMB_OFF_T file_len
= 0;
919 files_struct
*fsp
= NULL
;
923 uint32 file_attributes
;
925 uint32 create_disposition
;
926 uint32 create_options
;
928 struct security_descriptor
*sd
= NULL
;
931 struct timespec create_timespec
;
932 struct timespec c_timespec
;
933 struct timespec a_timespec
;
934 struct timespec m_timespec
;
935 struct timespec write_time_ts
;
936 struct ea_list
*ea_list
= NULL
;
939 uint64_t allocation_size
;
941 uint8_t oplock_granted
;
942 struct case_semantics_state
*case_state
= NULL
;
943 TALLOC_CTX
*ctx
= talloc_tos();
945 DEBUG(5,("call_nt_transact_create\n"));
948 * If it's an IPC, use the pipe handler.
952 if (lp_nt_pipe_support()) {
953 do_nt_transact_create_pipe(
955 ppsetup
, setup_count
,
956 ppparams
, parameter_count
,
960 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
965 * Ensure minimum number of parameters sent.
968 if(parameter_count
< 54) {
969 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
970 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
974 flags
= IVAL(params
,0);
975 access_mask
= IVAL(params
,8);
976 file_attributes
= IVAL(params
,20);
977 share_access
= IVAL(params
,24);
978 create_disposition
= IVAL(params
,28);
979 create_options
= IVAL(params
,32);
980 sd_len
= IVAL(params
,36);
981 ea_len
= IVAL(params
,40);
982 root_dir_fid
= (uint16
)IVAL(params
,4);
983 allocation_size
= (uint64_t)IVAL(params
,12);
984 #ifdef LARGE_SMB_OFF_T
985 allocation_size
|= (((uint64_t)IVAL(params
,16)) << 32);
989 * we need to remove ignored bits when they come directly from the client
990 * because we reuse some of them for internal stuff
992 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
994 /* Ensure the data_len is correct for the sd and ea values given. */
995 if ((ea_len
+ sd_len
> data_count
)
996 || (ea_len
> data_count
) || (sd_len
> data_count
)
997 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
998 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
999 "%u, data_count = %u\n", (unsigned int)ea_len
,
1000 (unsigned int)sd_len
, (unsigned int)data_count
));
1001 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1006 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1009 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
1011 if (!NT_STATUS_IS_OK(status
)) {
1012 DEBUG(10, ("call_nt_transact_create: "
1013 "unmarshall_sec_desc failed: %s\n",
1014 nt_errstr(status
)));
1015 reply_nterror(req
, status
);
1021 if (!lp_ea_support(SNUM(conn
))) {
1022 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1023 "EA's not supported.\n",
1024 (unsigned int)ea_len
));
1025 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
1030 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1031 "too small (should be more than 10)\n",
1032 (unsigned int)ea_len
));
1033 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1037 /* We have already checked that ea_len <= data_count here. */
1038 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
1040 if (ea_list
== NULL
) {
1041 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1046 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
1047 params
+53, parameter_count
-53,
1048 STR_TERMINATE
, &status
);
1049 if (!NT_STATUS_IS_OK(status
)) {
1050 reply_nterror(req
, status
);
1054 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1055 case_state
= set_posix_case_semantics(ctx
, conn
);
1057 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1062 status
= filename_convert(ctx
,
1064 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1070 TALLOC_FREE(case_state
);
1072 if (!NT_STATUS_IS_OK(status
)) {
1073 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1074 reply_botherror(req
,
1075 NT_STATUS_PATH_NOT_COVERED
,
1076 ERRSRV
, ERRbadpath
);
1079 reply_nterror(req
, status
);
1083 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1084 if (oplock_request
) {
1085 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1090 * Bug #6898 - clients using Windows opens should
1091 * never be able to set this attribute into the
1094 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1096 status
= SMB_VFS_CREATE_FILE(
1099 root_dir_fid
, /* root_dir_fid */
1100 smb_fname
, /* fname */
1101 access_mask
, /* access_mask */
1102 share_access
, /* share_access */
1103 create_disposition
, /* create_disposition*/
1104 create_options
, /* create_options */
1105 file_attributes
, /* file_attributes */
1106 oplock_request
, /* oplock_request */
1107 allocation_size
, /* allocation_size */
1109 ea_list
, /* ea_list */
1113 if(!NT_STATUS_IS_OK(status
)) {
1114 if (open_was_deferred(req
->mid
)) {
1115 /* We have re-scheduled this call, no error. */
1118 reply_openerror(req
, status
);
1122 /* Ensure we're pointing at the correct stat struct. */
1123 TALLOC_FREE(smb_fname
);
1124 smb_fname
= fsp
->fsp_name
;
1127 * If the caller set the extended oplock request bit
1128 * and we granted one (by whatever means) - set the
1129 * correct bit for extended oplock reply.
1132 if (oplock_request
&&
1133 (lp_fake_oplocks(SNUM(conn
))
1134 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1137 * Exclusive oplock granted
1140 if (flags
& REQUEST_BATCH_OPLOCK
) {
1141 oplock_granted
= BATCH_OPLOCK_RETURN
;
1143 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1145 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1146 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1148 oplock_granted
= NO_OPLOCK_RETURN
;
1151 file_len
= smb_fname
->st
.st_ex_size
;
1153 /* Realloc the size of parameters and data we will return */
1154 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1155 /* Extended response is 32 more byyes. */
1160 params
= nttrans_realloc(ppparams
, param_len
);
1161 if(params
== NULL
) {
1162 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1167 SCVAL(p
, 0, oplock_granted
);
1170 SSVAL(p
,0,fsp
->fnum
);
1172 if ((create_disposition
== FILE_SUPERSEDE
)
1173 && (info
== FILE_WAS_OVERWRITTEN
)) {
1174 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1180 fattr
= dos_mode(conn
, smb_fname
);
1182 fattr
= FILE_ATTRIBUTE_NORMAL
;
1185 /* Deal with other possible opens having a modified
1187 ZERO_STRUCT(write_time_ts
);
1188 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
1189 if (!null_timespec(write_time_ts
)) {
1190 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
1194 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1195 a_timespec
= smb_fname
->st
.st_ex_atime
;
1196 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1197 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1199 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1200 dos_filetime_timespec(&create_timespec
);
1201 dos_filetime_timespec(&a_timespec
);
1202 dos_filetime_timespec(&m_timespec
);
1203 dos_filetime_timespec(&c_timespec
);
1206 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
1208 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
1210 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
1212 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
1214 SIVAL(p
,0,fattr
); /* File Attributes. */
1216 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1218 SOFF_T(p
,0,file_len
);
1220 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1224 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1226 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1229 if (fsp
->is_directory
||
1230 can_write_to_file(conn
, smb_fname
)) {
1231 perms
= FILE_GENERIC_ALL
;
1233 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1238 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1239 smb_fname_str_dbg(smb_fname
)));
1241 /* Send the required number of replies */
1242 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1247 /****************************************************************************
1248 Reply to a NT CANCEL request.
1249 conn POINTER CAN BE NULL HERE !
1250 ****************************************************************************/
1252 void reply_ntcancel(struct smb_request
*req
)
1255 * Go through and cancel any pending change notifies.
1258 START_PROFILE(SMBntcancel
);
1259 srv_cancel_sign_response(smbd_server_conn
);
1260 remove_pending_change_notify_requests_by_mid(req
->mid
);
1261 remove_pending_lock_requests_by_mid(req
->mid
);
1263 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req
->mid
));
1265 END_PROFILE(SMBntcancel
);
1269 /****************************************************************************
1271 ****************************************************************************/
1273 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1274 connection_struct
*conn
,
1275 struct smb_request
*req
,
1276 struct smb_filename
*smb_fname_src
,
1277 struct smb_filename
*smb_fname_dst
,
1280 files_struct
*fsp1
,*fsp2
;
1284 NTSTATUS status
= NT_STATUS_OK
;
1287 if (!CAN_WRITE(conn
)) {
1288 status
= NT_STATUS_MEDIA_WRITE_PROTECTED
;
1292 /* Source must already exist. */
1293 if (!VALID_STAT(smb_fname_src
->st
)) {
1294 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1298 /* Ensure attributes match. */
1299 fattr
= dos_mode(conn
, smb_fname_src
);
1300 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1301 status
= NT_STATUS_NO_SUCH_FILE
;
1305 /* Disallow if dst file already exists. */
1306 if (VALID_STAT(smb_fname_dst
->st
)) {
1307 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
1311 /* No links from a directory. */
1312 if (S_ISDIR(smb_fname_src
->st
.st_ex_mode
)) {
1313 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
1317 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1318 smb_fname_str_dbg(smb_fname_src
),
1319 smb_fname_str_dbg(smb_fname_dst
)));
1321 status
= SMB_VFS_CREATE_FILE(
1324 0, /* root_dir_fid */
1325 smb_fname_src
, /* fname */
1326 FILE_READ_DATA
, /* access_mask */
1327 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1329 FILE_OPEN
, /* create_disposition*/
1330 0, /* create_options */
1331 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
1332 NO_OPLOCK
, /* oplock_request */
1333 0, /* allocation_size */
1339 if (!NT_STATUS_IS_OK(status
)) {
1343 status
= SMB_VFS_CREATE_FILE(
1346 0, /* root_dir_fid */
1347 smb_fname_dst
, /* fname */
1348 FILE_WRITE_DATA
, /* access_mask */
1349 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1351 FILE_CREATE
, /* create_disposition*/
1352 0, /* create_options */
1353 fattr
, /* file_attributes */
1354 NO_OPLOCK
, /* oplock_request */
1355 0, /* allocation_size */
1361 if (!NT_STATUS_IS_OK(status
)) {
1362 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1366 if (smb_fname_src
->st
.st_ex_size
) {
1367 ret
= vfs_transfer_file(fsp1
, fsp2
, smb_fname_src
->st
.st_ex_size
);
1371 * As we are opening fsp1 read-only we only expect
1372 * an error on close on fsp2 if we are out of space.
1373 * Thus we don't look at the error return from the
1376 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1378 /* Ensure the modtime is set correctly on the destination file. */
1379 set_close_write_time(fsp2
, smb_fname_src
->st
.st_ex_mtime
);
1381 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1383 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1384 creates the file. This isn't the correct thing to do in the copy
1386 if (!parent_dirname(talloc_tos(), smb_fname_dst
->base_name
, &parent
,
1388 status
= NT_STATUS_NO_MEMORY
;
1391 file_set_dosmode(conn
, smb_fname_dst
, fattr
, parent
, false);
1392 TALLOC_FREE(parent
);
1394 if (ret
< (SMB_OFF_T
)smb_fname_src
->st
.st_ex_size
) {
1395 status
= NT_STATUS_DISK_FULL
;
1399 if (!NT_STATUS_IS_OK(status
)) {
1400 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1401 nt_errstr(status
), smb_fname_str_dbg(smb_fname_src
),
1402 smb_fname_str_dbg(smb_fname_dst
)));
1408 /****************************************************************************
1409 Reply to a NT rename request.
1410 ****************************************************************************/
1412 void reply_ntrename(struct smb_request
*req
)
1414 connection_struct
*conn
= req
->conn
;
1415 struct smb_filename
*smb_fname_old
= NULL
;
1416 struct smb_filename
*smb_fname_new
= NULL
;
1417 char *oldname
= NULL
;
1418 char *newname
= NULL
;
1421 bool src_has_wcard
= False
;
1422 bool dest_has_wcard
= False
;
1424 uint32_t ucf_flags_src
= 0;
1425 uint32_t ucf_flags_dst
= 0;
1427 TALLOC_CTX
*ctx
= talloc_tos();
1429 START_PROFILE(SMBntrename
);
1432 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1436 attrs
= SVAL(req
->vwv
+0, 0);
1437 rename_type
= SVAL(req
->vwv
+1, 0);
1439 p
= (const char *)req
->buf
+ 1;
1440 p
+= srvstr_get_path_req_wcard(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1441 &status
, &src_has_wcard
);
1442 if (!NT_STATUS_IS_OK(status
)) {
1443 reply_nterror(req
, status
);
1447 if (ms_has_wild(oldname
)) {
1448 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1453 p
+= srvstr_get_path_req_wcard(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1454 &status
, &dest_has_wcard
);
1455 if (!NT_STATUS_IS_OK(status
)) {
1456 reply_nterror(req
, status
);
1460 /* The newname must begin with a ':' if the oldname contains a ':'. */
1461 if (strchr_m(oldname
, ':') && (newname
[0] != ':')) {
1462 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1467 * If this is a rename operation, allow wildcards and save the
1468 * destination's last component.
1470 if (rename_type
== RENAME_FLAG_RENAME
) {
1471 ucf_flags_src
= UCF_COND_ALLOW_WCARD_LCOMP
;
1472 ucf_flags_dst
= UCF_COND_ALLOW_WCARD_LCOMP
| UCF_SAVE_LCOMP
;
1475 /* rename_internals() calls unix_convert(), so don't call it here. */
1476 status
= filename_convert(ctx
, conn
,
1477 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1482 if (!NT_STATUS_IS_OK(status
)) {
1483 if (NT_STATUS_EQUAL(status
,
1484 NT_STATUS_PATH_NOT_COVERED
)) {
1485 reply_botherror(req
,
1486 NT_STATUS_PATH_NOT_COVERED
,
1487 ERRSRV
, ERRbadpath
);
1490 reply_nterror(req
, status
);
1494 status
= filename_convert(ctx
, conn
,
1495 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1500 if (!NT_STATUS_IS_OK(status
)) {
1501 if (NT_STATUS_EQUAL(status
,
1502 NT_STATUS_PATH_NOT_COVERED
)) {
1503 reply_botherror(req
,
1504 NT_STATUS_PATH_NOT_COVERED
,
1505 ERRSRV
, ERRbadpath
);
1508 reply_nterror(req
, status
);
1512 DEBUG(3,("reply_ntrename: %s -> %s\n",
1513 smb_fname_str_dbg(smb_fname_old
),
1514 smb_fname_str_dbg(smb_fname_new
)));
1516 switch(rename_type
) {
1517 case RENAME_FLAG_RENAME
:
1518 status
= rename_internals(ctx
, conn
, req
,
1519 smb_fname_old
, smb_fname_new
,
1520 attrs
, False
, src_has_wcard
,
1524 case RENAME_FLAG_HARD_LINK
:
1525 if (src_has_wcard
|| dest_has_wcard
) {
1527 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1529 status
= hardlink_internals(ctx
, conn
,
1534 case RENAME_FLAG_COPY
:
1535 if (src_has_wcard
|| dest_has_wcard
) {
1537 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1539 status
= copy_internals(ctx
, conn
, req
,
1545 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1546 status
= NT_STATUS_INVALID_PARAMETER
;
1549 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1553 if (!NT_STATUS_IS_OK(status
)) {
1554 if (open_was_deferred(req
->mid
)) {
1555 /* We have re-scheduled this call. */
1559 reply_nterror(req
, status
);
1563 reply_outbuf(req
, 0, 0);
1565 END_PROFILE(SMBntrename
);
1569 /****************************************************************************
1570 Reply to a notify change - queue the request and
1571 don't allow a directory to be opened.
1572 ****************************************************************************/
1574 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1575 NTSTATUS error_code
,
1576 uint8_t *buf
, size_t len
)
1578 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1581 static void call_nt_transact_notify_change(connection_struct
*conn
,
1582 struct smb_request
*req
,
1586 uint32 parameter_count
,
1587 char **ppdata
, uint32 data_count
,
1588 uint32 max_data_count
,
1589 uint32 max_param_count
)
1591 uint16
*setup
= *ppsetup
;
1597 if(setup_count
< 6) {
1598 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1602 fsp
= file_fsp(req
, SVAL(setup
,4));
1603 filter
= IVAL(setup
, 0);
1604 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1606 DEBUG(3,("call_nt_transact_notify_change\n"));
1609 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1614 char *filter_string
;
1616 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1617 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1621 DEBUG(3,("call_nt_transact_notify_change: notify change "
1622 "called on %s, filter = %s, recursive = %d\n",
1623 fsp_str_dbg(fsp
), filter_string
, recursive
));
1625 TALLOC_FREE(filter_string
);
1628 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1629 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1633 if (fsp
->notify
== NULL
) {
1635 status
= change_notify_create(fsp
, filter
, recursive
);
1637 if (!NT_STATUS_IS_OK(status
)) {
1638 DEBUG(10, ("change_notify_create returned %s\n",
1639 nt_errstr(status
)));
1640 reply_nterror(req
, status
);
1645 if (fsp
->notify
->num_changes
!= 0) {
1648 * We've got changes pending, respond immediately
1652 * TODO: write a torture test to check the filtering behaviour
1656 change_notify_reply(fsp
->conn
, req
,
1660 smbd_smb1_notify_reply
);
1663 * change_notify_reply() above has independently sent its
1670 * No changes pending, queue the request
1673 status
= change_notify_add_request(req
,
1677 smbd_smb1_notify_reply
);
1678 if (!NT_STATUS_IS_OK(status
)) {
1679 reply_nterror(req
, status
);
1684 /****************************************************************************
1685 Reply to an NT transact rename command.
1686 ****************************************************************************/
1688 static void call_nt_transact_rename(connection_struct
*conn
,
1689 struct smb_request
*req
,
1690 uint16
**ppsetup
, uint32 setup_count
,
1691 char **ppparams
, uint32 parameter_count
,
1692 char **ppdata
, uint32 data_count
,
1693 uint32 max_data_count
)
1695 char *params
= *ppparams
;
1696 char *new_name
= NULL
;
1697 files_struct
*fsp
= NULL
;
1698 bool dest_has_wcard
= False
;
1700 TALLOC_CTX
*ctx
= talloc_tos();
1702 if(parameter_count
< 5) {
1703 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1707 fsp
= file_fsp(req
, SVAL(params
, 0));
1708 if (!check_fsp(conn
, req
, fsp
)) {
1711 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1712 parameter_count
- 4,
1713 STR_TERMINATE
, &status
, &dest_has_wcard
);
1714 if (!NT_STATUS_IS_OK(status
)) {
1715 reply_nterror(req
, status
);
1720 * W2K3 ignores this request as the RAW-RENAME test
1721 * demonstrates, so we do.
1723 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1725 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1726 fsp_str_dbg(fsp
), new_name
));
1731 /******************************************************************************
1732 Fake up a completely empty SD.
1733 *******************************************************************************/
1735 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1739 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1741 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1742 return NT_STATUS_NO_MEMORY
;
1745 return NT_STATUS_OK
;
1748 /****************************************************************************
1749 Reply to query a security descriptor.
1750 ****************************************************************************/
1752 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1753 struct smb_request
*req
,
1757 uint32 parameter_count
,
1760 uint32 max_data_count
)
1762 char *params
= *ppparams
;
1763 char *data
= *ppdata
;
1764 SEC_DESC
*psd
= NULL
;
1766 uint32 security_info_wanted
;
1767 files_struct
*fsp
= NULL
;
1771 if(parameter_count
< 8) {
1772 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1776 fsp
= file_fsp(req
, SVAL(params
,0));
1778 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1782 security_info_wanted
= IVAL(params
,4);
1784 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1785 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
1786 (unsigned int)security_info_wanted
));
1788 params
= nttrans_realloc(ppparams
, 4);
1789 if(params
== NULL
) {
1790 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1795 * Get the permissions to return.
1798 if (!lp_nt_acl_support(SNUM(conn
))) {
1799 status
= get_null_nt_acl(talloc_tos(), &psd
);
1801 status
= SMB_VFS_FGET_NT_ACL(
1802 fsp
, security_info_wanted
, &psd
);
1804 if (!NT_STATUS_IS_OK(status
)) {
1805 reply_nterror(req
, status
);
1809 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1810 * present in the reply to match Windows behavior */
1811 if (psd
->sacl
== NULL
&&
1812 security_info_wanted
& SACL_SECURITY_INFORMATION
)
1813 psd
->type
|= SEC_DESC_SACL_PRESENT
;
1814 if (psd
->dacl
== NULL
&&
1815 security_info_wanted
& DACL_SECURITY_INFORMATION
)
1816 psd
->type
|= SEC_DESC_DACL_PRESENT
;
1818 sd_size
= ndr_size_security_descriptor(psd
, NULL
, 0);
1820 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
1822 if (DEBUGLEVEL
>= 10) {
1823 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
1825 NDR_PRINT_DEBUG(security_descriptor
, psd
);
1828 SIVAL(params
,0,(uint32
)sd_size
);
1830 if (max_data_count
< sd_size
) {
1831 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1832 params
, 4, *ppdata
, 0);
1837 * Allocate the data we will point this at.
1840 data
= nttrans_realloc(ppdata
, sd_size
);
1842 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1846 status
= marshall_sec_desc(talloc_tos(), psd
,
1847 &blob
.data
, &blob
.length
);
1849 if (!NT_STATUS_IS_OK(status
)) {
1850 reply_nterror(req
, status
);
1854 SMB_ASSERT(sd_size
== blob
.length
);
1855 memcpy(data
, blob
.data
, sd_size
);
1857 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1862 /****************************************************************************
1863 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1864 ****************************************************************************/
1866 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1867 struct smb_request
*req
,
1871 uint32 parameter_count
,
1874 uint32 max_data_count
)
1876 char *params
= *ppparams
;
1877 char *data
= *ppdata
;
1878 files_struct
*fsp
= NULL
;
1879 uint32 security_info_sent
= 0;
1882 if(parameter_count
< 8) {
1883 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1887 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1888 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
1892 if(!lp_nt_acl_support(SNUM(conn
))) {
1896 security_info_sent
= IVAL(params
,4);
1898 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1899 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
1901 if (data_count
== 0) {
1902 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1906 status
= set_sd(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
1908 if (!NT_STATUS_IS_OK(status
)) {
1909 reply_nterror(req
, status
);
1914 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1918 /****************************************************************************
1920 ****************************************************************************/
1922 static void call_nt_transact_ioctl(connection_struct
*conn
,
1923 struct smb_request
*req
,
1924 uint16
**ppsetup
, uint32 setup_count
,
1925 char **ppparams
, uint32 parameter_count
,
1926 char **ppdata
, uint32 data_count
,
1927 uint32 max_data_count
)
1934 char *pdata
= *ppdata
;
1936 if (setup_count
!= 8) {
1937 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1938 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1942 function
= IVAL(*ppsetup
, 0);
1943 fidnum
= SVAL(*ppsetup
, 4);
1944 isFSctl
= CVAL(*ppsetup
, 6);
1945 compfilter
= CVAL(*ppsetup
, 7);
1947 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1948 function
, fidnum
, isFSctl
, compfilter
));
1950 fsp
=file_fsp(req
, fidnum
);
1951 /* this check is done in each implemented function case for now
1952 because I don't want to break anything... --metze
1953 FSP_BELONGS_CONN(fsp,conn);*/
1955 SMB_PERFCOUNT_SET_IOCTL(&req
->pcd
, function
);
1958 case FSCTL_SET_SPARSE
:
1959 /* pretend this succeeded - tho strictly we should
1960 mark the file sparse (if the local fs supports it)
1961 so we can know if we need to pre-allocate or not */
1963 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1964 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1967 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
1969 unsigned char objid
[16];
1971 /* This should return the object-id on this file.
1972 * I think I'll make this be the inode+dev. JRA.
1975 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
1977 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1982 pdata
= nttrans_realloc(ppdata
, data_count
);
1983 if (pdata
== NULL
) {
1984 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1988 /* For backwards compatibility only store the dev/inode. */
1989 push_file_id_16(pdata
, &fsp
->file_id
);
1990 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
1991 push_file_id_16(pdata
+32, &fsp
->file_id
);
1992 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1997 case FSCTL_GET_REPARSE_POINT
:
1998 /* pretend this fail - my winXP does it like this
2002 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2003 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
2006 case FSCTL_SET_REPARSE_POINT
:
2007 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2011 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2012 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
2015 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
2018 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2019 * and return their volume names. If max_data_count is 16, then it is just
2020 * asking for the number of volumes and length of the combined names.
2022 * pdata is the data allocated by our caller, but that uses
2023 * total_data_count (which is 0 in our case) rather than max_data_count.
2024 * Allocate the correct amount and return the pointer to let
2025 * it be deallocated when we return.
2027 SHADOW_COPY_DATA
*shadow_data
= NULL
;
2028 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
2029 bool labels
= False
;
2030 uint32 labels_data_count
= 0;
2034 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
2038 if (max_data_count
< 16) {
2039 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2041 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2045 if (max_data_count
> 16) {
2049 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
2050 if (shadow_mem_ctx
== NULL
) {
2051 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2052 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2056 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
2057 if (shadow_data
== NULL
) {
2058 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2059 talloc_destroy(shadow_mem_ctx
);
2060 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2064 shadow_data
->mem_ctx
= shadow_mem_ctx
;
2067 * Call the VFS routine to actually do the work.
2069 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2070 talloc_destroy(shadow_data
->mem_ctx
);
2071 if (errno
== ENOSYS
) {
2072 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2073 conn
->connectpath
));
2074 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2077 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2078 conn
->connectpath
));
2079 reply_nterror(req
, NT_STATUS_UNSUCCESSFUL
);
2084 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2089 data_count
= 12+labels_data_count
+4;
2092 if (max_data_count
<data_count
) {
2093 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2094 max_data_count
,data_count
));
2095 talloc_destroy(shadow_data
->mem_ctx
);
2096 reply_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
2100 pdata
= nttrans_realloc(ppdata
, data_count
);
2101 if (pdata
== NULL
) {
2102 talloc_destroy(shadow_data
->mem_ctx
);
2103 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2109 /* num_volumes 4 bytes */
2110 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2113 /* num_labels 4 bytes */
2114 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2117 /* needed_data_count 4 bytes */
2118 SIVAL(pdata
, 8, labels_data_count
+4);
2122 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2123 shadow_data
->num_volumes
, fsp_str_dbg(fsp
)));
2124 if (labels
&& shadow_data
->labels
) {
2125 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2126 srvstr_push(pdata
, req
->flags2
,
2127 cur_pdata
, shadow_data
->labels
[i
],
2128 2*sizeof(SHADOW_COPY_LABEL
),
2129 STR_UNICODE
|STR_TERMINATE
);
2130 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2131 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2135 talloc_destroy(shadow_data
->mem_ctx
);
2137 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
2143 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2145 /* pretend this succeeded -
2147 * we have to send back a list with all files owned by this SID
2149 * but I have to check that --metze
2153 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2155 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2157 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
2161 /* unknown 4 bytes: this is not the length of the sid :-( */
2162 /*unknown = IVAL(pdata,0);*/
2164 sid_parse(pdata
+4,sid_len
,&sid
);
2165 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
2167 if (!sid_to_uid(&sid
, &uid
)) {
2168 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2169 sid_string_dbg(&sid
),
2170 (unsigned long)sid_len
));
2174 /* we can take a look at the find source :-)
2176 * find ./ -uid $uid -name '*' is what we need here
2179 * and send 4bytes len and then NULL terminated unicode strings
2182 * but I don't know how to deal with the paged results
2183 * (maybe we can hang the result anywhere in the fsp struct)
2185 * we don't send all files at once
2186 * and at the next we should *not* start from the beginning,
2187 * so we have to cache the result
2192 /* this works for now... */
2193 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2197 if (!logged_ioctl_message
) {
2198 logged_ioctl_message
= true; /* Only print this once... */
2199 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2204 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2208 #ifdef HAVE_SYS_QUOTAS
2209 /****************************************************************************
2210 Reply to get user quota
2211 ****************************************************************************/
2213 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2214 struct smb_request
*req
,
2218 uint32 parameter_count
,
2221 uint32 max_data_count
)
2223 NTSTATUS nt_status
= NT_STATUS_OK
;
2224 char *params
= *ppparams
;
2225 char *pdata
= *ppdata
;
2227 int data_len
=0,param_len
=0;
2230 files_struct
*fsp
= NULL
;
2234 bool start_enum
= True
;
2235 SMB_NTQUOTA_STRUCT qt
;
2236 SMB_NTQUOTA_LIST
*tmp_list
;
2237 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2242 if (conn
->server_info
->utok
.uid
!= 0) {
2243 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2244 "[%s]\n", lp_servicename(SNUM(conn
)),
2245 conn
->server_info
->unix_name
));
2246 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2251 * Ensure minimum number of parameters sent.
2254 if (parameter_count
< 4) {
2255 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2256 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2260 /* maybe we can check the quota_fnum */
2261 fsp
= file_fsp(req
, SVAL(params
,0));
2262 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2263 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2264 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2268 /* the NULL pointer checking for fsp->fake_file_handle->pd
2269 * is done by CHECK_NTQUOTA_HANDLE_OK()
2271 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2273 level
= SVAL(params
,2);
2275 /* unknown 12 bytes leading in params */
2278 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2279 /* seems that we should continue with the enum here --metze */
2281 if (qt_handle
->quota_list
!=NULL
&&
2282 qt_handle
->tmp_list
==NULL
) {
2285 free_ntquota_list(&(qt_handle
->quota_list
));
2287 /* Realloc the size of parameters and data we will return */
2289 params
= nttrans_realloc(ppparams
, param_len
);
2290 if(params
== NULL
) {
2291 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2296 SIVAL(params
,0,data_len
);
2303 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2305 if (qt_handle
->quota_list
==NULL
&&
2306 qt_handle
->tmp_list
==NULL
) {
2310 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2311 reply_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
2315 /* Realloc the size of parameters and data we will return */
2317 params
= nttrans_realloc(ppparams
, param_len
);
2318 if(params
== NULL
) {
2319 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2323 /* we should not trust the value in max_data_count*/
2324 max_data_count
= MIN(max_data_count
,2048);
2326 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2328 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2334 /* set params Size of returned Quota Data 4 bytes*/
2335 /* but set it later when we know it */
2337 /* for each entry push the data */
2340 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2343 tmp_list
= qt_handle
->tmp_list
;
2345 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2346 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2348 sid_len
= ndr_size_dom_sid(
2349 &tmp_list
->quotas
->sid
, NULL
, 0);
2350 entry_len
= 40 + sid_len
;
2352 /* nextoffset entry 4 bytes */
2353 SIVAL(entry
,0,entry_len
);
2355 /* then the len of the SID 4 bytes */
2356 SIVAL(entry
,4,sid_len
);
2358 /* unknown data 8 bytes uint64_t */
2359 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2361 /* the used disk space 8 bytes uint64_t */
2362 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2364 /* the soft quotas 8 bytes uint64_t */
2365 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2367 /* the hard quotas 8 bytes uint64_t */
2368 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2370 /* and now the SID */
2371 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2374 qt_handle
->tmp_list
= tmp_list
;
2376 /* overwrite the offset of the last entry */
2377 SIVAL(entry
-entry_len
,0,0);
2379 data_len
= 4+qt_len
;
2380 /* overwrite the params quota_data_len */
2381 SIVAL(params
,0,data_len
);
2385 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2387 /* unknown 4 bytes IVAL(pdata,0) */
2389 if (data_count
< 8) {
2390 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2391 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2395 sid_len
= IVAL(pdata
,4);
2396 /* Ensure this is less than 1mb. */
2397 if (sid_len
> (1024*1024)) {
2398 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2402 if (data_count
< 8+sid_len
) {
2403 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2404 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2408 data_len
= 4+40+sid_len
;
2410 if (max_data_count
< data_len
) {
2411 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2412 max_data_count
, data_len
));
2414 SIVAL(params
,0,data_len
);
2416 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2420 sid_parse(pdata
+8,sid_len
,&sid
);
2422 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2425 * we have to return zero's in all fields
2426 * instead of returning an error here
2431 /* Realloc the size of parameters and data we will return */
2433 params
= nttrans_realloc(ppparams
, param_len
);
2434 if(params
== NULL
) {
2435 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2439 pdata
= nttrans_realloc(ppdata
, data_len
);
2441 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2447 /* set params Size of returned Quota Data 4 bytes*/
2448 SIVAL(params
,0,data_len
);
2450 /* nextoffset entry 4 bytes */
2453 /* then the len of the SID 4 bytes */
2454 SIVAL(entry
,4,sid_len
);
2456 /* unknown data 8 bytes uint64_t */
2457 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2459 /* the used disk space 8 bytes uint64_t */
2460 SBIG_UINT(entry
,16,qt
.usedspace
);
2462 /* the soft quotas 8 bytes uint64_t */
2463 SBIG_UINT(entry
,24,qt
.softlim
);
2465 /* the hard quotas 8 bytes uint64_t */
2466 SBIG_UINT(entry
,32,qt
.hardlim
);
2468 /* and now the SID */
2469 sid_linearize(entry
+40, sid_len
, &sid
);
2474 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2475 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2480 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2484 /****************************************************************************
2485 Reply to set user quota
2486 ****************************************************************************/
2488 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2489 struct smb_request
*req
,
2493 uint32 parameter_count
,
2496 uint32 max_data_count
)
2498 char *params
= *ppparams
;
2499 char *pdata
= *ppdata
;
2500 int data_len
=0,param_len
=0;
2501 SMB_NTQUOTA_STRUCT qt
;
2504 files_struct
*fsp
= NULL
;
2509 if (conn
->server_info
->utok
.uid
!= 0) {
2510 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2511 "[%s]\n", lp_servicename(SNUM(conn
)),
2512 conn
->server_info
->unix_name
));
2513 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2518 * Ensure minimum number of parameters sent.
2521 if (parameter_count
< 2) {
2522 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2523 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2527 /* maybe we can check the quota_fnum */
2528 fsp
= file_fsp(req
, SVAL(params
,0));
2529 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2530 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2531 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2535 if (data_count
< 40) {
2536 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2537 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2541 /* offset to next quota record.
2542 * 4 bytes IVAL(pdata,0)
2547 sid_len
= IVAL(pdata
,4);
2549 if (data_count
< 40+sid_len
) {
2550 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2551 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2555 /* unknown 8 bytes in pdata
2556 * maybe its the change time in NTTIME
2559 /* the used space 8 bytes (uint64_t)*/
2560 qt
.usedspace
= (uint64_t)IVAL(pdata
,16);
2561 #ifdef LARGE_SMB_OFF_T
2562 qt
.usedspace
|= (((uint64_t)IVAL(pdata
,20)) << 32);
2563 #else /* LARGE_SMB_OFF_T */
2564 if ((IVAL(pdata
,20) != 0)&&
2565 ((qt
.usedspace
!= 0xFFFFFFFF)||
2566 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2567 /* more than 32 bits? */
2568 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2571 #endif /* LARGE_SMB_OFF_T */
2573 /* the soft quotas 8 bytes (uint64_t)*/
2574 qt
.softlim
= (uint64_t)IVAL(pdata
,24);
2575 #ifdef LARGE_SMB_OFF_T
2576 qt
.softlim
|= (((uint64_t)IVAL(pdata
,28)) << 32);
2577 #else /* LARGE_SMB_OFF_T */
2578 if ((IVAL(pdata
,28) != 0)&&
2579 ((qt
.softlim
!= 0xFFFFFFFF)||
2580 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2581 /* more than 32 bits? */
2582 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2585 #endif /* LARGE_SMB_OFF_T */
2587 /* the hard quotas 8 bytes (uint64_t)*/
2588 qt
.hardlim
= (uint64_t)IVAL(pdata
,32);
2589 #ifdef LARGE_SMB_OFF_T
2590 qt
.hardlim
|= (((uint64_t)IVAL(pdata
,36)) << 32);
2591 #else /* LARGE_SMB_OFF_T */
2592 if ((IVAL(pdata
,36) != 0)&&
2593 ((qt
.hardlim
!= 0xFFFFFFFF)||
2594 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2595 /* more than 32 bits? */
2596 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2599 #endif /* LARGE_SMB_OFF_T */
2601 sid_parse(pdata
+40,sid_len
,&sid
);
2602 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2604 /* 44 unknown bytes left... */
2606 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2607 reply_nterror(req
, NT_STATUS_INTERNAL_ERROR
);
2611 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2614 #endif /* HAVE_SYS_QUOTAS */
2616 static void handle_nttrans(connection_struct
*conn
,
2617 struct trans_state
*state
,
2618 struct smb_request
*req
)
2620 if (get_Protocol() >= PROTOCOL_NT1
) {
2621 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2622 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2626 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2628 /* Now we must call the relevant NT_TRANS function */
2629 switch(state
->call
) {
2630 case NT_TRANSACT_CREATE
:
2632 START_PROFILE(NT_transact_create
);
2633 call_nt_transact_create(
2635 &state
->setup
, state
->setup_count
,
2636 &state
->param
, state
->total_param
,
2637 &state
->data
, state
->total_data
,
2638 state
->max_data_return
);
2639 END_PROFILE(NT_transact_create
);
2643 case NT_TRANSACT_IOCTL
:
2645 START_PROFILE(NT_transact_ioctl
);
2646 call_nt_transact_ioctl(
2648 &state
->setup
, state
->setup_count
,
2649 &state
->param
, state
->total_param
,
2650 &state
->data
, state
->total_data
,
2651 state
->max_data_return
);
2652 END_PROFILE(NT_transact_ioctl
);
2656 case NT_TRANSACT_SET_SECURITY_DESC
:
2658 START_PROFILE(NT_transact_set_security_desc
);
2659 call_nt_transact_set_security_desc(
2661 &state
->setup
, state
->setup_count
,
2662 &state
->param
, state
->total_param
,
2663 &state
->data
, state
->total_data
,
2664 state
->max_data_return
);
2665 END_PROFILE(NT_transact_set_security_desc
);
2669 case NT_TRANSACT_NOTIFY_CHANGE
:
2671 START_PROFILE(NT_transact_notify_change
);
2672 call_nt_transact_notify_change(
2674 &state
->setup
, state
->setup_count
,
2675 &state
->param
, state
->total_param
,
2676 &state
->data
, state
->total_data
,
2677 state
->max_data_return
,
2678 state
->max_param_return
);
2679 END_PROFILE(NT_transact_notify_change
);
2683 case NT_TRANSACT_RENAME
:
2685 START_PROFILE(NT_transact_rename
);
2686 call_nt_transact_rename(
2688 &state
->setup
, state
->setup_count
,
2689 &state
->param
, state
->total_param
,
2690 &state
->data
, state
->total_data
,
2691 state
->max_data_return
);
2692 END_PROFILE(NT_transact_rename
);
2696 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2698 START_PROFILE(NT_transact_query_security_desc
);
2699 call_nt_transact_query_security_desc(
2701 &state
->setup
, state
->setup_count
,
2702 &state
->param
, state
->total_param
,
2703 &state
->data
, state
->total_data
,
2704 state
->max_data_return
);
2705 END_PROFILE(NT_transact_query_security_desc
);
2709 #ifdef HAVE_SYS_QUOTAS
2710 case NT_TRANSACT_GET_USER_QUOTA
:
2712 START_PROFILE(NT_transact_get_user_quota
);
2713 call_nt_transact_get_user_quota(
2715 &state
->setup
, state
->setup_count
,
2716 &state
->param
, state
->total_param
,
2717 &state
->data
, state
->total_data
,
2718 state
->max_data_return
);
2719 END_PROFILE(NT_transact_get_user_quota
);
2723 case NT_TRANSACT_SET_USER_QUOTA
:
2725 START_PROFILE(NT_transact_set_user_quota
);
2726 call_nt_transact_set_user_quota(
2728 &state
->setup
, state
->setup_count
,
2729 &state
->param
, state
->total_param
,
2730 &state
->data
, state
->total_data
,
2731 state
->max_data_return
);
2732 END_PROFILE(NT_transact_set_user_quota
);
2735 #endif /* HAVE_SYS_QUOTAS */
2738 /* Error in request */
2739 DEBUG(0,("handle_nttrans: Unknown request %d in "
2740 "nttrans call\n", state
->call
));
2741 reply_nterror(req
, NT_STATUS_INVALID_LEVEL
);
2747 /****************************************************************************
2748 Reply to a SMBNTtrans.
2749 ****************************************************************************/
2751 void reply_nttrans(struct smb_request
*req
)
2753 connection_struct
*conn
= req
->conn
;
2758 uint16 function_code
;
2760 struct trans_state
*state
;
2762 START_PROFILE(SMBnttrans
);
2764 if (req
->wct
< 19) {
2765 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2766 END_PROFILE(SMBnttrans
);
2770 pscnt
= IVAL(req
->vwv
+9, 1);
2771 psoff
= IVAL(req
->vwv
+11, 1);
2772 dscnt
= IVAL(req
->vwv
+13, 1);
2773 dsoff
= IVAL(req
->vwv
+15, 1);
2774 function_code
= SVAL(req
->vwv
+18, 0);
2776 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2777 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
2778 END_PROFILE(SMBnttrans
);
2782 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2783 if (!NT_STATUS_IS_OK(result
)) {
2784 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2785 reply_nterror(req
, result
);
2786 END_PROFILE(SMBnttrans
);
2790 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
2791 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2792 END_PROFILE(SMBnttrans
);
2796 state
->cmd
= SMBnttrans
;
2798 state
->mid
= req
->mid
;
2799 state
->vuid
= req
->vuid
;
2800 state
->total_data
= IVAL(req
->vwv
+3, 1);
2802 state
->total_param
= IVAL(req
->vwv
+1, 1);
2803 state
->param
= NULL
;
2804 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2805 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2807 /* setup count is in *words* */
2808 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2809 state
->setup
= NULL
;
2810 state
->call
= function_code
;
2812 DEBUG(10, ("num_setup=%u, "
2813 "param_total=%u, this_param=%u, max_param=%u, "
2814 "data_total=%u, this_data=%u, max_data=%u, "
2815 "param_offset=%u, data_offset=%u\n",
2816 (unsigned)state
->setup_count
,
2817 (unsigned)state
->total_param
, (unsigned)pscnt
,
2818 (unsigned)state
->max_param_return
,
2819 (unsigned)state
->total_data
, (unsigned)dscnt
,
2820 (unsigned)state
->max_data_return
,
2821 (unsigned)psoff
, (unsigned)dsoff
));
2824 * All nttrans messages we handle have smb_wct == 19 +
2825 * state->setup_count. Ensure this is so as a sanity check.
2828 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2829 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2830 req
->wct
, 19 + (state
->setup_count
/2)));
2834 /* Don't allow more than 128mb for each value. */
2835 if ((state
->total_data
> (1024*1024*128)) ||
2836 (state
->total_param
> (1024*1024*128))) {
2837 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2838 END_PROFILE(SMBnttrans
);
2842 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2845 if (state
->total_data
) {
2847 if (trans_oob(state
->total_data
, 0, dscnt
)
2848 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
2852 /* Can't use talloc here, the core routines do realloc on the
2853 * params and data. */
2854 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2855 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2856 "bytes !\n", (unsigned int)state
->total_data
));
2858 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2859 END_PROFILE(SMBnttrans
);
2863 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2866 if (state
->total_param
) {
2868 if (trans_oob(state
->total_param
, 0, pscnt
)
2869 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
2873 /* Can't use talloc here, the core routines do realloc on the
2874 * params and data. */
2875 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2876 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2877 "bytes !\n", (unsigned int)state
->total_param
));
2878 SAFE_FREE(state
->data
);
2880 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2881 END_PROFILE(SMBnttrans
);
2885 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2888 state
->received_data
= dscnt
;
2889 state
->received_param
= pscnt
;
2891 if(state
->setup_count
> 0) {
2892 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2893 state
->setup_count
));
2896 * No overflow possible here, state->setup_count is an
2897 * unsigned int, being filled by a single byte from
2898 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2899 * below is not necessary, it's here to clarify things. The
2900 * validity of req->vwv and req->wct has been checked in
2901 * init_smb_request already.
2903 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
2907 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
2908 if (state
->setup
== NULL
) {
2909 DEBUG(0,("reply_nttrans : Out of memory\n"));
2910 SAFE_FREE(state
->data
);
2911 SAFE_FREE(state
->param
);
2913 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2914 END_PROFILE(SMBnttrans
);
2918 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
2919 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
2922 if ((state
->received_data
== state
->total_data
) &&
2923 (state
->received_param
== state
->total_param
)) {
2924 handle_nttrans(conn
, state
, req
);
2925 SAFE_FREE(state
->param
);
2926 SAFE_FREE(state
->data
);
2928 END_PROFILE(SMBnttrans
);
2932 DLIST_ADD(conn
->pending_trans
, state
);
2934 /* We need to send an interim response then receive the rest
2935 of the parameter/data bytes */
2936 reply_outbuf(req
, 0, 0);
2937 show_msg((char *)req
->outbuf
);
2938 END_PROFILE(SMBnttrans
);
2943 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2944 SAFE_FREE(state
->data
);
2945 SAFE_FREE(state
->param
);
2947 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2948 END_PROFILE(SMBnttrans
);
2952 /****************************************************************************
2953 Reply to a SMBnttranss
2954 ****************************************************************************/
2956 void reply_nttranss(struct smb_request
*req
)
2958 connection_struct
*conn
= req
->conn
;
2959 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2960 struct trans_state
*state
;
2962 START_PROFILE(SMBnttranss
);
2964 show_msg((char *)req
->inbuf
);
2966 if (req
->wct
< 18) {
2967 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2968 END_PROFILE(SMBnttranss
);
2972 for (state
= conn
->pending_trans
; state
!= NULL
;
2973 state
= state
->next
) {
2974 if (state
->mid
== req
->mid
) {
2979 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2980 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2981 END_PROFILE(SMBnttranss
);
2985 /* Revise state->total_param and state->total_data in case they have
2986 changed downwards */
2987 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
2988 state
->total_param
= IVAL(req
->vwv
+1, 1);
2990 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
2991 state
->total_data
= IVAL(req
->vwv
+3, 1);
2994 pcnt
= IVAL(req
->vwv
+5, 1);
2995 poff
= IVAL(req
->vwv
+7, 1);
2996 pdisp
= IVAL(req
->vwv
+9, 1);
2998 dcnt
= IVAL(req
->vwv
+11, 1);
2999 doff
= IVAL(req
->vwv
+13, 1);
3000 ddisp
= IVAL(req
->vwv
+15, 1);
3002 state
->received_param
+= pcnt
;
3003 state
->received_data
+= dcnt
;
3005 if ((state
->received_data
> state
->total_data
) ||
3006 (state
->received_param
> state
->total_param
))
3010 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
3011 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
3014 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
3018 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
3019 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
3022 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
3025 if ((state
->received_param
< state
->total_param
) ||
3026 (state
->received_data
< state
->total_data
)) {
3027 END_PROFILE(SMBnttranss
);
3031 handle_nttrans(conn
, state
, req
);
3033 DLIST_REMOVE(conn
->pending_trans
, state
);
3034 SAFE_FREE(state
->data
);
3035 SAFE_FREE(state
->param
);
3037 END_PROFILE(SMBnttranss
);
3042 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3043 DLIST_REMOVE(conn
->pending_trans
, state
);
3044 SAFE_FREE(state
->data
);
3045 SAFE_FREE(state
->param
);
3047 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
3048 END_PROFILE(SMBnttranss
);