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/>.
24 extern enum protocol_types Protocol
;
25 extern const struct generic_mapping file_generic_mapping
;
27 static char *nttrans_realloc(char **ptr
, size_t size
)
30 smb_panic("nttrans_realloc() called with NULL ptr");
33 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
37 memset(*ptr
,'\0',size
);
41 /****************************************************************************
42 Send the required number of replies back.
43 We assume all fields other than the data fields are
44 set correctly for the type of call.
45 HACK ! Always assumes smb_setup field is zero.
46 ****************************************************************************/
48 void send_nt_replies(connection_struct
*conn
,
49 struct smb_request
*req
, NTSTATUS nt_error
,
50 char *params
, int paramsize
,
51 char *pdata
, int datasize
)
53 int data_to_send
= datasize
;
54 int params_to_send
= paramsize
;
58 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
59 int alignment_offset
= 3;
60 int data_alignment_offset
= 0;
63 * If there genuinely are no parameters or data to send just send
67 if(params_to_send
== 0 && data_to_send
== 0) {
68 reply_outbuf(req
, 18, 0);
69 show_msg((char *)req
->outbuf
);
74 * When sending params and data ensure that both are nicely aligned.
75 * Only do this alignment when there is also data to send - else
76 * can cause NT redirector problems.
79 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
80 data_alignment_offset
= 4 - (params_to_send
% 4);
84 * Space is bufsize minus Netbios over TCP header minus SMB header.
85 * The alignment_offset is to align the param bytes on a four byte
86 * boundary (2 bytes for data len, one byte pad).
87 * NT needs this to work correctly.
90 useable_space
= max_send
- (smb_size
93 + data_alignment_offset
);
95 if (useable_space
< 0) {
96 DEBUG(0, ("send_nt_replies failed sanity useable_space "
97 "= %d!!!", useable_space
));
98 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
101 while (params_to_send
|| data_to_send
) {
104 * Calculate whether we will totally or partially fill this packet.
107 total_sent_thistime
= params_to_send
+ data_to_send
;
110 * We can never send more than useable_space.
113 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
115 reply_outbuf(req
, 18,
116 total_sent_thistime
+ alignment_offset
117 + data_alignment_offset
);
120 * Set total params and data to be sent.
123 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
124 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
127 * Calculate how many parameters and data we can fit into
128 * this packet. Parameters get precedence.
131 params_sent_thistime
= MIN(params_to_send
,useable_space
);
132 data_sent_thistime
= useable_space
- params_sent_thistime
;
133 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
135 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
136 params_sent_thistime
);
138 if(params_sent_thistime
== 0) {
139 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
140 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
143 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
144 * parameter bytes, however the first 4 bytes of outbuf are
145 * the Netbios over TCP header. Thus use smb_base() to subtract
146 * them from the calculation.
149 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
150 ((smb_buf(req
->outbuf
)+alignment_offset
)
151 - smb_base(req
->outbuf
)));
153 * Absolute displacement of param bytes sent in this packet.
156 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
161 * Deal with the data portion.
164 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
166 if(data_sent_thistime
== 0) {
167 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
168 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
171 * The offset of the data bytes is the offset of the
172 * parameter bytes plus the number of parameters being sent this time.
175 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
176 ((smb_buf(req
->outbuf
)+alignment_offset
) -
177 smb_base(req
->outbuf
))
178 + params_sent_thistime
+ data_alignment_offset
);
179 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
183 * Copy the param bytes into the packet.
186 if(params_sent_thistime
) {
187 if (alignment_offset
!= 0) {
188 memset(smb_buf(req
->outbuf
), 0,
191 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
192 params_sent_thistime
);
196 * Copy in the data bytes
199 if(data_sent_thistime
) {
200 if (data_alignment_offset
!= 0) {
201 memset((smb_buf(req
->outbuf
)+alignment_offset
+
202 params_sent_thistime
), 0,
203 data_alignment_offset
);
205 memcpy(smb_buf(req
->outbuf
)+alignment_offset
206 +params_sent_thistime
+data_alignment_offset
,
207 pd
,data_sent_thistime
);
210 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
211 params_sent_thistime
, data_sent_thistime
, useable_space
));
212 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
213 params_to_send
, data_to_send
, paramsize
, datasize
));
215 if (NT_STATUS_V(nt_error
)) {
216 error_packet_set((char *)req
->outbuf
,
221 /* Send the packet */
222 show_msg((char *)req
->outbuf
);
223 if (!srv_send_smb(smbd_server_fd(),
225 IS_CONN_ENCRYPTED(conn
))) {
226 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
229 TALLOC_FREE(req
->outbuf
);
231 pp
+= params_sent_thistime
;
232 pd
+= data_sent_thistime
;
234 params_to_send
-= params_sent_thistime
;
235 data_to_send
-= data_sent_thistime
;
241 if(params_to_send
< 0 || data_to_send
< 0) {
242 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
243 params_to_send
, data_to_send
));
244 exit_server_cleanly("send_nt_replies: internal error");
249 /****************************************************************************
250 Is it an NTFS stream name ?
251 An NTFS file name is <path>.<extention>:<stream name>:<stream type>
252 $DATA can be used as both a stream name and a stream type. A missing stream
253 name or type implies $DATA.
254 ****************************************************************************/
256 bool is_ntfs_stream_name(const char *fname
)
258 if (lp_posix_pathnames()) {
261 return (strchr_m(fname
, ':') != NULL
) ? True
: False
;
264 /****************************************************************************
265 Reply to an NT create and X call on a pipe
266 ****************************************************************************/
268 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
269 struct smb_request
*req
, int *ppnum
)
274 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
276 /* See if it is one we want to handle. */
278 if (!is_known_pipename(fname
)) {
279 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
284 /* Strip \\ off the name. */
287 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname
));
289 status
= np_open(req
, conn
, fname
, &fsp
);
290 if (!NT_STATUS_IS_OK(status
)) {
291 reply_nterror(req
, status
);
299 /****************************************************************************
300 Reply to an NT create and X call for pipes.
301 ****************************************************************************/
303 static void do_ntcreate_pipe_open(connection_struct
*conn
,
304 struct smb_request
*req
)
309 uint32 flags
= IVAL(req
->inbuf
,smb_ntcreate_Flags
);
310 TALLOC_CTX
*ctx
= talloc_tos();
312 srvstr_pull_buf_talloc(ctx
, (char *)req
->inbuf
, req
->flags2
, &fname
,
313 smb_buf(req
->inbuf
), STR_TERMINATE
);
316 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
320 nt_open_pipe(fname
, conn
, req
, &pnum
);
328 * Deal with pipe return.
331 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
332 /* This is very strange. We
333 * return 50 words, but only set
334 * the wcnt to 42 ? It's definately
335 * what happens on the wire....
337 reply_outbuf(req
, 50, 0);
338 SCVAL(req
->outbuf
,smb_wct
,42);
340 reply_outbuf(req
, 34, 0);
343 p
= (char *)req
->outbuf
+ smb_vwv2
;
347 SIVAL(p
,0,FILE_WAS_OPENED
);
350 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
353 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
355 SSVAL(p
,2, 0x5FF); /* ? */
358 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
360 SIVAL(p
,0,FILE_GENERIC_ALL
);
362 * For pipes W2K3 seems to return
364 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
366 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
369 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
374 /****************************************************************************
375 Reply to an NT create and X call.
376 ****************************************************************************/
378 void reply_ntcreate_and_X(struct smb_request
*req
)
380 connection_struct
*conn
= req
->conn
;
384 uint32 file_attributes
;
386 uint32 create_disposition
;
387 uint32 create_options
;
389 SMB_BIG_UINT allocation_size
;
390 /* Breakout the oplock request bits so we can set the
391 reply bits separately. */
393 SMB_OFF_T file_len
= 0;
394 SMB_STRUCT_STAT sbuf
;
396 files_struct
*fsp
= NULL
;
398 struct timespec c_timespec
;
399 struct timespec a_timespec
;
400 struct timespec m_timespec
;
403 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
404 TALLOC_CTX
*ctx
= talloc_tos();
406 START_PROFILE(SMBntcreateX
);
409 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
413 flags
= IVAL(req
->inbuf
,smb_ntcreate_Flags
);
414 access_mask
= IVAL(req
->inbuf
,smb_ntcreate_DesiredAccess
);
415 file_attributes
= IVAL(req
->inbuf
,smb_ntcreate_FileAttributes
);
416 share_access
= IVAL(req
->inbuf
,smb_ntcreate_ShareAccess
);
417 create_disposition
= IVAL(req
->inbuf
,smb_ntcreate_CreateDisposition
);
418 create_options
= IVAL(req
->inbuf
,smb_ntcreate_CreateOptions
);
419 root_dir_fid
= (uint16
)IVAL(req
->inbuf
,smb_ntcreate_RootDirectoryFid
);
421 allocation_size
= (SMB_BIG_UINT
)IVAL(req
->inbuf
,
422 smb_ntcreate_AllocationSize
);
423 #ifdef LARGE_SMB_OFF_T
424 allocation_size
|= (((SMB_BIG_UINT
)IVAL(
426 smb_ntcreate_AllocationSize
+ 4)) << 32);
429 srvstr_get_path(ctx
, (char *)req
->inbuf
, req
->flags2
, &fname
,
430 smb_buf(req
->inbuf
), 0, STR_TERMINATE
, &status
);
432 if (!NT_STATUS_IS_OK(status
)) {
433 reply_nterror(req
, status
);
434 END_PROFILE(SMBntcreateX
);
438 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
439 "file_attributes = 0x%x, share_access = 0x%x, "
440 "create_disposition = 0x%x create_options = 0x%x "
441 "root_dir_fid = 0x%x, fname = %s\n",
443 (unsigned int)access_mask
,
444 (unsigned int)file_attributes
,
445 (unsigned int)share_access
,
446 (unsigned int)create_disposition
,
447 (unsigned int)create_options
,
448 (unsigned int)root_dir_fid
,
452 * we need to remove ignored bits when they come directly from the client
453 * because we reuse some of them for internal stuff
455 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
458 * If it's an IPC, use the pipe handler.
462 if (lp_nt_pipe_support()) {
463 do_ntcreate_pipe_open(conn
, req
);
464 END_PROFILE(SMBntcreateX
);
467 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
468 END_PROFILE(SMBntcreateX
);
472 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
473 if (oplock_request
) {
474 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
478 status
= create_file(conn
, req
, root_dir_fid
, fname
,
479 access_mask
, share_access
, create_disposition
,
480 create_options
, file_attributes
, oplock_request
,
481 allocation_size
, NULL
, NULL
, &fsp
, &info
, &sbuf
);
483 if (!NT_STATUS_IS_OK(status
)) {
484 if (open_was_deferred(req
->mid
)) {
485 /* We have re-scheduled this call, no error. */
486 END_PROFILE(SMBntcreateX
);
489 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
490 reply_botherror(req
, status
, ERRDOS
, ERRfilexists
);
493 reply_nterror(req
, status
);
495 END_PROFILE(SMBntcreateX
);
500 * If the caller set the extended oplock request bit
501 * and we granted one (by whatever means) - set the
502 * correct bit for extended oplock reply.
505 if (oplock_request
&&
506 (lp_fake_oplocks(SNUM(conn
))
507 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
510 * Exclusive oplock granted
513 if (flags
& REQUEST_BATCH_OPLOCK
) {
514 oplock_granted
= BATCH_OPLOCK_RETURN
;
516 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
518 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
519 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
521 oplock_granted
= NO_OPLOCK_RETURN
;
524 file_len
= sbuf
.st_size
;
525 fattr
= dos_mode(conn
,fsp
->fsp_name
,&sbuf
);
527 fattr
= FILE_ATTRIBUTE_NORMAL
;
530 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
531 /* This is very strange. We
532 * return 50 words, but only set
533 * the wcnt to 42 ? It's definately
534 * what happens on the wire....
536 reply_outbuf(req
, 50, 0);
537 SCVAL(req
->outbuf
,smb_wct
,42);
539 reply_outbuf(req
, 34, 0);
542 p
= (char *)req
->outbuf
+ smb_vwv2
;
544 SCVAL(p
, 0, oplock_granted
);
547 SSVAL(p
,0,fsp
->fnum
);
549 if ((create_disposition
== FILE_SUPERSEDE
)
550 && (info
== FILE_WAS_OVERWRITTEN
)) {
551 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
558 c_timespec
= get_create_timespec(
559 &sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
560 a_timespec
= get_atimespec(&sbuf
);
561 m_timespec
= get_mtimespec(&sbuf
);
563 if (lp_dos_filetime_resolution(SNUM(conn
))) {
564 dos_filetime_timespec(&c_timespec
);
565 dos_filetime_timespec(&a_timespec
);
566 dos_filetime_timespec(&m_timespec
);
569 put_long_date_timespec(p
, c_timespec
); /* create time. */
571 put_long_date_timespec(p
, a_timespec
); /* access time */
573 put_long_date_timespec(p
, m_timespec
); /* write time */
575 put_long_date_timespec(p
, m_timespec
); /* change time */
577 SIVAL(p
,0,fattr
); /* File Attributes. */
579 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
581 SOFF_T(p
,0,file_len
);
583 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
587 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
589 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
592 if (fsp
->is_directory
593 || can_write_to_file(conn
, fsp
->fsp_name
, &sbuf
)) {
594 perms
= FILE_GENERIC_ALL
;
596 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
601 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
602 fsp
->fnum
, fsp
->fsp_name
));
605 END_PROFILE(SMBntcreateX
);
609 /****************************************************************************
610 Reply to a NT_TRANSACT_CREATE call to open a pipe.
611 ****************************************************************************/
613 static void do_nt_transact_create_pipe(connection_struct
*conn
,
614 struct smb_request
*req
,
615 uint16
**ppsetup
, uint32 setup_count
,
616 char **ppparams
, uint32 parameter_count
,
617 char **ppdata
, uint32 data_count
)
620 char *params
= *ppparams
;
626 TALLOC_CTX
*ctx
= talloc_tos();
629 * Ensure minimum number of parameters sent.
632 if(parameter_count
< 54) {
633 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
634 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
638 flags
= IVAL(params
,0);
640 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
641 parameter_count
-53, STR_TERMINATE
,
643 if (!NT_STATUS_IS_OK(status
)) {
644 reply_nterror(req
, status
);
648 nt_open_pipe(fname
, conn
, req
, &pnum
);
655 /* Realloc the size of parameters and data we will return */
656 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
657 /* Extended response is 32 more byyes. */
662 params
= nttrans_realloc(ppparams
, param_len
);
664 reply_doserror(req
, ERRDOS
, ERRnomem
);
669 SCVAL(p
,0,NO_OPLOCK_RETURN
);
674 SIVAL(p
,0,FILE_WAS_OPENED
);
678 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
681 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
683 SSVAL(p
,2, 0x5FF); /* ? */
686 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
688 SIVAL(p
,0,FILE_GENERIC_ALL
);
690 * For pipes W2K3 seems to return
692 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
694 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
697 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
699 /* Send the required number of replies */
700 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
705 /****************************************************************************
706 Internal fn to set security descriptors.
707 ****************************************************************************/
709 static NTSTATUS
set_sd(files_struct
*fsp
, uint8
*data
, uint32 sd_len
,
710 uint32 security_info_sent
)
712 SEC_DESC
*psd
= NULL
;
715 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
719 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
721 if (!NT_STATUS_IS_OK(status
)) {
725 if (psd
->owner_sid
==0) {
726 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
728 if (psd
->group_sid
==0) {
729 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
732 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
735 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
738 /* Convert all the generic bits. */
739 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
740 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
742 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
749 /****************************************************************************
750 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
751 ****************************************************************************/
753 static struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
755 struct ea_list
*ea_list_head
= NULL
;
762 while (offset
+ 4 <= data_size
) {
763 size_t next_offset
= IVAL(pdata
,offset
);
764 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
770 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
771 if (next_offset
== 0) {
774 offset
+= next_offset
;
780 /****************************************************************************
781 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
782 ****************************************************************************/
784 static void call_nt_transact_create(connection_struct
*conn
,
785 struct smb_request
*req
,
786 uint16
**ppsetup
, uint32 setup_count
,
787 char **ppparams
, uint32 parameter_count
,
788 char **ppdata
, uint32 data_count
,
789 uint32 max_data_count
)
792 char *params
= *ppparams
;
793 char *data
= *ppdata
;
794 /* Breakout the oplock request bits so we can set the reply bits separately. */
796 SMB_OFF_T file_len
= 0;
797 SMB_STRUCT_STAT sbuf
;
799 files_struct
*fsp
= NULL
;
803 uint32 file_attributes
;
805 uint32 create_disposition
;
806 uint32 create_options
;
808 struct security_descriptor
*sd
= NULL
;
811 struct timespec c_timespec
;
812 struct timespec a_timespec
;
813 struct timespec m_timespec
;
814 struct ea_list
*ea_list
= NULL
;
817 SMB_BIG_UINT allocation_size
;
819 uint8_t oplock_granted
;
820 TALLOC_CTX
*ctx
= talloc_tos();
822 DEBUG(5,("call_nt_transact_create\n"));
825 * If it's an IPC, use the pipe handler.
829 if (lp_nt_pipe_support()) {
830 do_nt_transact_create_pipe(
832 ppsetup
, setup_count
,
833 ppparams
, parameter_count
,
837 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
842 * Ensure minimum number of parameters sent.
845 if(parameter_count
< 54) {
846 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
847 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
851 flags
= IVAL(params
,0);
852 access_mask
= IVAL(params
,8);
853 file_attributes
= IVAL(params
,20);
854 share_access
= IVAL(params
,24);
855 create_disposition
= IVAL(params
,28);
856 create_options
= IVAL(params
,32);
857 sd_len
= IVAL(params
,36);
858 ea_len
= IVAL(params
,40);
859 root_dir_fid
= (uint16
)IVAL(params
,4);
860 allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
861 #ifdef LARGE_SMB_OFF_T
862 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
866 * we need to remove ignored bits when they come directly from the client
867 * because we reuse some of them for internal stuff
869 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
871 /* Ensure the data_len is correct for the sd and ea values given. */
872 if ((ea_len
+ sd_len
> data_count
)
873 || (ea_len
> data_count
) || (sd_len
> data_count
)
874 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
875 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
876 "%u, data_count = %u\n", (unsigned int)ea_len
,
877 (unsigned int)sd_len
, (unsigned int)data_count
));
878 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
883 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
886 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
888 if (!NT_STATUS_IS_OK(status
)) {
889 DEBUG(10, ("call_nt_transact_create: "
890 "unmarshall_sec_desc failed: %s\n",
892 reply_nterror(req
, status
);
898 if (!lp_ea_support(SNUM(conn
))) {
899 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
900 "EA's not supported.\n",
901 (unsigned int)ea_len
));
902 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
907 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
908 "too small (should be more than 10)\n",
909 (unsigned int)ea_len
));
910 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
914 /* We have already checked that ea_len <= data_count here. */
915 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
917 if (ea_list
== NULL
) {
918 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
923 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
924 params
+53, parameter_count
-53,
925 STR_TERMINATE
, &status
);
926 if (!NT_STATUS_IS_OK(status
)) {
927 reply_nterror(req
, status
);
931 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
932 if (oplock_request
) {
933 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
937 status
= create_file(conn
, req
, root_dir_fid
, fname
,
938 access_mask
, share_access
, create_disposition
,
939 create_options
, file_attributes
, oplock_request
,
940 allocation_size
, sd
, ea_list
, &fsp
, &info
, &sbuf
);
942 if(!NT_STATUS_IS_OK(status
)) {
943 if (open_was_deferred(req
->mid
)) {
944 /* We have re-scheduled this call, no error. */
947 reply_openerror(req
, status
);
952 * If the caller set the extended oplock request bit
953 * and we granted one (by whatever means) - set the
954 * correct bit for extended oplock reply.
957 if (oplock_request
&&
958 (lp_fake_oplocks(SNUM(conn
))
959 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
962 * Exclusive oplock granted
965 if (flags
& REQUEST_BATCH_OPLOCK
) {
966 oplock_granted
= BATCH_OPLOCK_RETURN
;
968 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
970 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
971 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
973 oplock_granted
= NO_OPLOCK_RETURN
;
976 file_len
= sbuf
.st_size
;
977 fattr
= dos_mode(conn
,fsp
->fsp_name
,&sbuf
);
979 fattr
= FILE_ATTRIBUTE_NORMAL
;
982 /* Realloc the size of parameters and data we will return */
983 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
984 /* Extended response is 32 more byyes. */
989 params
= nttrans_realloc(ppparams
, param_len
);
991 reply_doserror(req
, ERRDOS
, ERRnomem
);
996 SCVAL(p
, 0, oplock_granted
);
999 SSVAL(p
,0,fsp
->fnum
);
1001 if ((create_disposition
== FILE_SUPERSEDE
)
1002 && (info
== FILE_WAS_OVERWRITTEN
)) {
1003 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1010 c_timespec
= get_create_timespec(
1011 &sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1012 a_timespec
= get_atimespec(&sbuf
);
1013 m_timespec
= get_mtimespec(&sbuf
);
1015 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1016 dos_filetime_timespec(&c_timespec
);
1017 dos_filetime_timespec(&a_timespec
);
1018 dos_filetime_timespec(&m_timespec
);
1021 put_long_date_timespec(p
, c_timespec
); /* create time. */
1023 put_long_date_timespec(p
, a_timespec
); /* access time */
1025 put_long_date_timespec(p
, m_timespec
); /* write time */
1027 put_long_date_timespec(p
, m_timespec
); /* change time */
1029 SIVAL(p
,0,fattr
); /* File Attributes. */
1031 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
1033 SOFF_T(p
,0,file_len
);
1035 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1039 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1041 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1044 if (fsp
->is_directory
1045 || can_write_to_file(conn
, fsp
->fsp_name
, &sbuf
)) {
1046 perms
= FILE_GENERIC_ALL
;
1048 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1053 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp
->fsp_name
));
1055 /* Send the required number of replies */
1056 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1061 /****************************************************************************
1062 Reply to a NT CANCEL request.
1063 conn POINTER CAN BE NULL HERE !
1064 ****************************************************************************/
1066 void reply_ntcancel(struct smb_request
*req
)
1069 * Go through and cancel any pending change notifies.
1072 START_PROFILE(SMBntcancel
);
1073 remove_pending_change_notify_requests_by_mid(req
->mid
);
1074 remove_pending_lock_requests_by_mid(req
->mid
);
1075 srv_cancel_sign_response(req
->mid
);
1077 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req
->mid
));
1079 END_PROFILE(SMBntcancel
);
1083 /****************************************************************************
1085 ****************************************************************************/
1087 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1088 connection_struct
*conn
,
1089 struct smb_request
*req
,
1090 const char *oldname_in
,
1091 const char *newname_in
,
1094 SMB_STRUCT_STAT sbuf1
, sbuf2
;
1095 char *oldname
= NULL
;
1096 char *newname
= NULL
;
1097 char *last_component_oldname
= NULL
;
1098 char *last_component_newname
= NULL
;
1099 files_struct
*fsp1
,*fsp2
;
1103 NTSTATUS status
= NT_STATUS_OK
;
1108 if (!CAN_WRITE(conn
)) {
1109 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1112 status
= unix_convert(ctx
, conn
, oldname_in
, False
, &oldname
,
1113 &last_component_oldname
, &sbuf1
);
1114 if (!NT_STATUS_IS_OK(status
)) {
1118 status
= check_name(conn
, oldname
);
1119 if (!NT_STATUS_IS_OK(status
)) {
1123 /* Source must already exist. */
1124 if (!VALID_STAT(sbuf1
)) {
1125 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1127 /* Ensure attributes match. */
1128 fattr
= dos_mode(conn
,oldname
,&sbuf1
);
1129 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1130 return NT_STATUS_NO_SUCH_FILE
;
1133 status
= unix_convert(ctx
, conn
, newname_in
, False
, &newname
,
1134 &last_component_newname
, &sbuf2
);
1135 if (!NT_STATUS_IS_OK(status
)) {
1139 status
= check_name(conn
, newname
);
1140 if (!NT_STATUS_IS_OK(status
)) {
1144 /* Disallow if newname already exists. */
1145 if (VALID_STAT(sbuf2
)) {
1146 return NT_STATUS_OBJECT_NAME_COLLISION
;
1149 /* No links from a directory. */
1150 if (S_ISDIR(sbuf1
.st_mode
)) {
1151 return NT_STATUS_FILE_IS_A_DIRECTORY
;
1154 /* Ensure this is within the share. */
1155 status
= check_reduced_name(conn
, oldname
);
1156 if (!NT_STATUS_IS_OK(status
)) {
1160 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1163 status
= open_file_ntcreate(conn
, req
, oldname
, &sbuf1
,
1164 FILE_READ_DATA
, /* Read-only. */
1165 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1167 0, /* No create options. */
1168 FILE_ATTRIBUTE_NORMAL
,
1172 if (!NT_STATUS_IS_OK(status
)) {
1176 status
= open_file_ntcreate(conn
, req
, newname
, &sbuf2
,
1177 FILE_WRITE_DATA
, /* Read-only. */
1178 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1180 0, /* No create options. */
1185 if (!NT_STATUS_IS_OK(status
)) {
1186 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1190 if (sbuf1
.st_size
) {
1191 ret
= vfs_transfer_file(fsp1
, fsp2
, sbuf1
.st_size
);
1195 * As we are opening fsp1 read-only we only expect
1196 * an error on close on fsp2 if we are out of space.
1197 * Thus we don't look at the error return from the
1200 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1202 /* Ensure the modtime is set correctly on the destination file. */
1203 set_close_write_time(fsp2
, get_mtimespec(&sbuf1
));
1205 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1207 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1208 creates the file. This isn't the correct thing to do in the copy
1210 file_set_dosmode(conn
, newname
, fattr
, &sbuf2
,
1211 parent_dirname(newname
),false);
1213 if (ret
< (SMB_OFF_T
)sbuf1
.st_size
) {
1214 return NT_STATUS_DISK_FULL
;
1217 if (!NT_STATUS_IS_OK(status
)) {
1218 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1219 nt_errstr(status
), oldname
, newname
));
1224 /****************************************************************************
1225 Reply to a NT rename request.
1226 ****************************************************************************/
1228 void reply_ntrename(struct smb_request
*req
)
1230 connection_struct
*conn
= req
->conn
;
1231 char *oldname
= NULL
;
1232 char *newname
= NULL
;
1235 bool src_has_wcard
= False
;
1236 bool dest_has_wcard
= False
;
1239 TALLOC_CTX
*ctx
= talloc_tos();
1241 START_PROFILE(SMBntrename
);
1244 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1245 END_PROFILE(SMBntrename
);
1249 attrs
= SVAL(req
->inbuf
,smb_vwv0
);
1250 rename_type
= SVAL(req
->inbuf
,smb_vwv1
);
1252 p
= smb_buf(req
->inbuf
) + 1;
1253 p
+= srvstr_get_path_wcard(ctx
, (char *)req
->inbuf
, req
->flags2
, &oldname
, p
,
1254 0, STR_TERMINATE
, &status
,
1256 if (!NT_STATUS_IS_OK(status
)) {
1257 reply_nterror(req
, status
);
1258 END_PROFILE(SMBntrename
);
1262 if( is_ntfs_stream_name(oldname
)) {
1263 /* Can't rename a stream. */
1264 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1265 END_PROFILE(SMBntrename
);
1269 if (ms_has_wild(oldname
)) {
1270 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1271 END_PROFILE(SMBntrename
);
1276 p
+= srvstr_get_path_wcard(ctx
, (char *)req
->inbuf
, req
->flags2
, &newname
, p
,
1277 0, STR_TERMINATE
, &status
,
1279 if (!NT_STATUS_IS_OK(status
)) {
1280 reply_nterror(req
, status
);
1281 END_PROFILE(SMBntrename
);
1285 status
= resolve_dfspath(ctx
, conn
,
1286 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1289 if (!NT_STATUS_IS_OK(status
)) {
1290 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1291 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
1292 ERRSRV
, ERRbadpath
);
1293 END_PROFILE(SMBntrename
);
1296 reply_nterror(req
, status
);
1297 END_PROFILE(SMBntrename
);
1301 status
= resolve_dfspath(ctx
, conn
,
1302 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1305 if (!NT_STATUS_IS_OK(status
)) {
1306 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1307 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
1308 ERRSRV
, ERRbadpath
);
1309 END_PROFILE(SMBntrename
);
1312 reply_nterror(req
, status
);
1313 END_PROFILE(SMBntrename
);
1317 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1319 switch(rename_type
) {
1320 case RENAME_FLAG_RENAME
:
1321 status
= rename_internals(ctx
, conn
, req
, oldname
,
1322 newname
, attrs
, False
, src_has_wcard
,
1323 dest_has_wcard
, DELETE_ACCESS
);
1325 case RENAME_FLAG_HARD_LINK
:
1326 if (src_has_wcard
|| dest_has_wcard
) {
1328 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1330 status
= hardlink_internals(ctx
,
1336 case RENAME_FLAG_COPY
:
1337 if (src_has_wcard
|| dest_has_wcard
) {
1339 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1341 status
= copy_internals(ctx
, conn
, req
, oldname
,
1345 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1346 status
= NT_STATUS_INVALID_PARAMETER
;
1349 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1353 if (!NT_STATUS_IS_OK(status
)) {
1354 if (open_was_deferred(req
->mid
)) {
1355 /* We have re-scheduled this call. */
1356 END_PROFILE(SMBntrename
);
1360 reply_nterror(req
, status
);
1361 END_PROFILE(SMBntrename
);
1365 reply_outbuf(req
, 0, 0);
1367 END_PROFILE(SMBntrename
);
1371 /****************************************************************************
1372 Reply to a notify change - queue the request and
1373 don't allow a directory to be opened.
1374 ****************************************************************************/
1376 static void call_nt_transact_notify_change(connection_struct
*conn
,
1377 struct smb_request
*req
,
1381 uint32 parameter_count
,
1382 char **ppdata
, uint32 data_count
,
1383 uint32 max_data_count
,
1384 uint32 max_param_count
)
1386 uint16
*setup
= *ppsetup
;
1392 if(setup_count
< 6) {
1393 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1397 fsp
= file_fsp(req
, SVAL(setup
,4));
1398 filter
= IVAL(setup
, 0);
1399 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1401 DEBUG(3,("call_nt_transact_notify_change\n"));
1404 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1409 char *filter_string
;
1411 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1412 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1416 DEBUG(3,("call_nt_transact_notify_change: notify change "
1417 "called on %s, filter = %s, recursive = %d\n",
1418 fsp
->fsp_name
, filter_string
, recursive
));
1420 TALLOC_FREE(filter_string
);
1423 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1424 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1428 if (fsp
->notify
== NULL
) {
1430 status
= change_notify_create(fsp
, filter
, recursive
);
1432 if (!NT_STATUS_IS_OK(status
)) {
1433 DEBUG(10, ("change_notify_create returned %s\n",
1434 nt_errstr(status
)));
1435 reply_nterror(req
, status
);
1440 if (fsp
->notify
->num_changes
!= 0) {
1443 * We've got changes pending, respond immediately
1447 * TODO: write a torture test to check the filtering behaviour
1451 change_notify_reply(fsp
->conn
, req
->inbuf
, max_param_count
, fsp
->notify
);
1454 * change_notify_reply() above has independently sent its
1461 * No changes pending, queue the request
1464 status
= change_notify_add_request(req
,
1468 if (!NT_STATUS_IS_OK(status
)) {
1469 reply_nterror(req
, status
);
1474 /****************************************************************************
1475 Reply to an NT transact rename command.
1476 ****************************************************************************/
1478 static void call_nt_transact_rename(connection_struct
*conn
,
1479 struct smb_request
*req
,
1480 uint16
**ppsetup
, uint32 setup_count
,
1481 char **ppparams
, uint32 parameter_count
,
1482 char **ppdata
, uint32 data_count
,
1483 uint32 max_data_count
)
1485 char *params
= *ppparams
;
1486 char *new_name
= NULL
;
1487 files_struct
*fsp
= NULL
;
1488 bool dest_has_wcard
= False
;
1490 TALLOC_CTX
*ctx
= talloc_tos();
1492 if(parameter_count
< 5) {
1493 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1497 fsp
= file_fsp(req
, SVAL(params
, 0));
1498 if (!check_fsp(conn
, req
, fsp
)) {
1501 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1502 parameter_count
- 4,
1503 STR_TERMINATE
, &status
, &dest_has_wcard
);
1504 if (!NT_STATUS_IS_OK(status
)) {
1505 reply_nterror(req
, status
);
1510 * W2K3 ignores this request as the RAW-RENAME test
1511 * demonstrates, so we do.
1513 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1515 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1516 fsp
->fsp_name
, new_name
));
1521 /******************************************************************************
1522 Fake up a completely empty SD.
1523 *******************************************************************************/
1525 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1529 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1531 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1532 return NT_STATUS_NO_MEMORY
;
1535 return NT_STATUS_OK
;
1538 /****************************************************************************
1539 Reply to query a security descriptor.
1540 ****************************************************************************/
1542 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1543 struct smb_request
*req
,
1547 uint32 parameter_count
,
1550 uint32 max_data_count
)
1552 char *params
= *ppparams
;
1553 char *data
= *ppdata
;
1554 SEC_DESC
*psd
= NULL
;
1556 uint32 security_info_wanted
;
1557 files_struct
*fsp
= NULL
;
1561 if(parameter_count
< 8) {
1562 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1566 fsp
= file_fsp(req
, SVAL(params
,0));
1568 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1572 security_info_wanted
= IVAL(params
,4);
1574 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp
->fsp_name
,
1575 (unsigned int)security_info_wanted
));
1577 params
= nttrans_realloc(ppparams
, 4);
1578 if(params
== NULL
) {
1579 reply_doserror(req
, ERRDOS
, ERRnomem
);
1584 * Get the permissions to return.
1587 if (!lp_nt_acl_support(SNUM(conn
))) {
1588 status
= get_null_nt_acl(talloc_tos(), &psd
);
1590 status
= SMB_VFS_FGET_NT_ACL(
1591 fsp
, security_info_wanted
, &psd
);
1594 if (!NT_STATUS_IS_OK(status
)) {
1595 reply_nterror(req
, status
);
1599 sd_size
= ndr_size_security_descriptor(psd
, 0);
1601 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
1603 SIVAL(params
,0,(uint32
)sd_size
);
1605 if (max_data_count
< sd_size
) {
1606 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1607 params
, 4, *ppdata
, 0);
1612 * Allocate the data we will point this at.
1615 data
= nttrans_realloc(ppdata
, sd_size
);
1617 reply_doserror(req
, ERRDOS
, ERRnomem
);
1621 status
= marshall_sec_desc(talloc_tos(), psd
,
1622 &blob
.data
, &blob
.length
);
1624 if (!NT_STATUS_IS_OK(status
)) {
1625 reply_nterror(req
, status
);
1629 SMB_ASSERT(sd_size
== blob
.length
);
1630 memcpy(data
, blob
.data
, sd_size
);
1632 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1637 /****************************************************************************
1638 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1639 ****************************************************************************/
1641 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1642 struct smb_request
*req
,
1646 uint32 parameter_count
,
1649 uint32 max_data_count
)
1651 char *params
= *ppparams
;
1652 char *data
= *ppdata
;
1653 files_struct
*fsp
= NULL
;
1654 uint32 security_info_sent
= 0;
1657 if(parameter_count
< 8) {
1658 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1662 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1663 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1667 if(!lp_nt_acl_support(SNUM(conn
))) {
1671 security_info_sent
= IVAL(params
,4);
1673 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
1674 (unsigned int)security_info_sent
));
1676 if (data_count
== 0) {
1677 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
1681 status
= set_sd(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
1683 if (!NT_STATUS_IS_OK(status
)) {
1684 reply_nterror(req
, status
);
1689 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1693 /****************************************************************************
1695 ****************************************************************************/
1697 static void call_nt_transact_ioctl(connection_struct
*conn
,
1698 struct smb_request
*req
,
1699 uint16
**ppsetup
, uint32 setup_count
,
1700 char **ppparams
, uint32 parameter_count
,
1701 char **ppdata
, uint32 data_count
,
1702 uint32 max_data_count
)
1709 static bool logged_message
;
1710 char *pdata
= *ppdata
;
1712 if (setup_count
!= 8) {
1713 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1714 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1718 function
= IVAL(*ppsetup
, 0);
1719 fidnum
= SVAL(*ppsetup
, 4);
1720 isFSctl
= CVAL(*ppsetup
, 6);
1721 compfilter
= CVAL(*ppsetup
, 7);
1723 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1724 function
, fidnum
, isFSctl
, compfilter
));
1726 fsp
=file_fsp(req
, fidnum
);
1727 /* this check is done in each implemented function case for now
1728 because I don't want to break anything... --metze
1729 FSP_BELONGS_CONN(fsp,conn);*/
1732 case FSCTL_SET_SPARSE
:
1733 /* pretend this succeeded - tho strictly we should
1734 mark the file sparse (if the local fs supports it)
1735 so we can know if we need to pre-allocate or not */
1737 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1738 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1741 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
1743 unsigned char objid
[16];
1745 /* This should return the object-id on this file.
1746 * I think I'll make this be the inode+dev. JRA.
1749 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
1751 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1756 pdata
= nttrans_realloc(ppdata
, data_count
);
1757 if (pdata
== NULL
) {
1758 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1761 push_file_id_16(pdata
, &fsp
->file_id
);
1762 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
1763 push_file_id_16(pdata
+32, &fsp
->file_id
);
1764 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1769 case FSCTL_GET_REPARSE_POINT
:
1770 /* pretend this fail - my winXP does it like this
1774 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1775 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1778 case FSCTL_SET_REPARSE_POINT
:
1779 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1783 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1784 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1787 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
1790 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1791 * and return their volume names. If max_data_count is 16, then it is just
1792 * asking for the number of volumes and length of the combined names.
1794 * pdata is the data allocated by our caller, but that uses
1795 * total_data_count (which is 0 in our case) rather than max_data_count.
1796 * Allocate the correct amount and return the pointer to let
1797 * it be deallocated when we return.
1799 SHADOW_COPY_DATA
*shadow_data
= NULL
;
1800 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
1801 bool labels
= False
;
1802 uint32 labels_data_count
= 0;
1806 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1810 if (max_data_count
< 16) {
1811 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1813 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1817 if (max_data_count
> 16) {
1821 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
1822 if (shadow_mem_ctx
== NULL
) {
1823 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1824 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1828 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
1829 if (shadow_data
== NULL
) {
1830 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1831 talloc_destroy(shadow_mem_ctx
);
1832 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1836 shadow_data
->mem_ctx
= shadow_mem_ctx
;
1839 * Call the VFS routine to actually do the work.
1841 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
1842 talloc_destroy(shadow_data
->mem_ctx
);
1843 if (errno
== ENOSYS
) {
1844 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1845 conn
->connectpath
));
1846 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1849 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1850 conn
->connectpath
));
1851 reply_nterror(req
, NT_STATUS_UNSUCCESSFUL
);
1856 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
1861 data_count
= 12+labels_data_count
+4;
1864 if (max_data_count
<data_count
) {
1865 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1866 max_data_count
,data_count
));
1867 talloc_destroy(shadow_data
->mem_ctx
);
1868 reply_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
1872 pdata
= nttrans_realloc(ppdata
, data_count
);
1873 if (pdata
== NULL
) {
1874 talloc_destroy(shadow_data
->mem_ctx
);
1875 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1881 /* num_volumes 4 bytes */
1882 SIVAL(pdata
,0,shadow_data
->num_volumes
);
1885 /* num_labels 4 bytes */
1886 SIVAL(pdata
,4,shadow_data
->num_volumes
);
1889 /* needed_data_count 4 bytes */
1890 SIVAL(pdata
,8,labels_data_count
);
1894 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
1895 shadow_data
->num_volumes
,fsp
->fsp_name
));
1896 if (labels
&& shadow_data
->labels
) {
1897 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
1898 srvstr_push(pdata
, req
->flags2
,
1899 cur_pdata
, shadow_data
->labels
[i
],
1900 2*sizeof(SHADOW_COPY_LABEL
),
1901 STR_UNICODE
|STR_TERMINATE
);
1902 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
1903 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
1907 talloc_destroy(shadow_data
->mem_ctx
);
1909 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1915 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
1917 /* pretend this succeeded -
1919 * we have to send back a list with all files owned by this SID
1921 * but I have to check that --metze
1925 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
1927 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
1929 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1933 /* unknown 4 bytes: this is not the length of the sid :-( */
1934 /*unknown = IVAL(pdata,0);*/
1936 sid_parse(pdata
+4,sid_len
,&sid
);
1937 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
1939 if (!sid_to_uid(&sid
, &uid
)) {
1940 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
1941 sid_string_dbg(&sid
),
1942 (unsigned long)sid_len
));
1946 /* we can take a look at the find source :-)
1948 * find ./ -uid $uid -name '*' is what we need here
1951 * and send 4bytes len and then NULL terminated unicode strings
1954 * but I don't know how to deal with the paged results
1955 * (maybe we can hang the result anywhere in the fsp struct)
1957 * we don't send all files at once
1958 * and at the next we should *not* start from the beginning,
1959 * so we have to cache the result
1964 /* this works for now... */
1965 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1969 if (!logged_message
) {
1970 logged_message
= True
; /* Only print this once... */
1971 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
1976 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1980 #ifdef HAVE_SYS_QUOTAS
1981 /****************************************************************************
1982 Reply to get user quota
1983 ****************************************************************************/
1985 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
1986 struct smb_request
*req
,
1990 uint32 parameter_count
,
1993 uint32 max_data_count
)
1995 NTSTATUS nt_status
= NT_STATUS_OK
;
1996 char *params
= *ppparams
;
1997 char *pdata
= *ppdata
;
1999 int data_len
=0,param_len
=0;
2002 files_struct
*fsp
= NULL
;
2006 bool start_enum
= True
;
2007 SMB_NTQUOTA_STRUCT qt
;
2008 SMB_NTQUOTA_LIST
*tmp_list
;
2009 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2014 if (conn
->server_info
->utok
.uid
!= 0) {
2015 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2016 "[%s]\n", lp_servicename(SNUM(conn
)),
2017 conn
->server_info
->unix_name
));
2018 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2023 * Ensure minimum number of parameters sent.
2026 if (parameter_count
< 4) {
2027 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2028 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2032 /* maybe we can check the quota_fnum */
2033 fsp
= file_fsp(req
, SVAL(params
,0));
2034 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2035 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2036 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2040 /* the NULL pointer checking for fsp->fake_file_handle->pd
2041 * is done by CHECK_NTQUOTA_HANDLE_OK()
2043 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2045 level
= SVAL(params
,2);
2047 /* unknown 12 bytes leading in params */
2050 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2051 /* seems that we should continue with the enum here --metze */
2053 if (qt_handle
->quota_list
!=NULL
&&
2054 qt_handle
->tmp_list
==NULL
) {
2057 free_ntquota_list(&(qt_handle
->quota_list
));
2059 /* Realloc the size of parameters and data we will return */
2061 params
= nttrans_realloc(ppparams
, param_len
);
2062 if(params
== NULL
) {
2063 reply_doserror(req
, ERRDOS
, ERRnomem
);
2068 SIVAL(params
,0,data_len
);
2075 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2077 if (qt_handle
->quota_list
==NULL
&&
2078 qt_handle
->tmp_list
==NULL
) {
2082 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2083 reply_doserror(req
, ERRSRV
, ERRerror
);
2087 /* Realloc the size of parameters and data we will return */
2089 params
= nttrans_realloc(ppparams
, param_len
);
2090 if(params
== NULL
) {
2091 reply_doserror(req
, ERRDOS
, ERRnomem
);
2095 /* we should not trust the value in max_data_count*/
2096 max_data_count
= MIN(max_data_count
,2048);
2098 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2100 reply_doserror(req
, ERRDOS
, ERRnomem
);
2106 /* set params Size of returned Quota Data 4 bytes*/
2107 /* but set it later when we know it */
2109 /* for each entry push the data */
2112 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2115 tmp_list
= qt_handle
->tmp_list
;
2117 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2118 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2120 sid_len
= ndr_size_dom_sid(
2121 &tmp_list
->quotas
->sid
, 0);
2122 entry_len
= 40 + sid_len
;
2124 /* nextoffset entry 4 bytes */
2125 SIVAL(entry
,0,entry_len
);
2127 /* then the len of the SID 4 bytes */
2128 SIVAL(entry
,4,sid_len
);
2130 /* unknown data 8 bytes SMB_BIG_UINT */
2131 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2133 /* the used disk space 8 bytes SMB_BIG_UINT */
2134 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2136 /* the soft quotas 8 bytes SMB_BIG_UINT */
2137 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2139 /* the hard quotas 8 bytes SMB_BIG_UINT */
2140 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2142 /* and now the SID */
2143 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2146 qt_handle
->tmp_list
= tmp_list
;
2148 /* overwrite the offset of the last entry */
2149 SIVAL(entry
-entry_len
,0,0);
2151 data_len
= 4+qt_len
;
2152 /* overwrite the params quota_data_len */
2153 SIVAL(params
,0,data_len
);
2157 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2159 /* unknown 4 bytes IVAL(pdata,0) */
2161 if (data_count
< 8) {
2162 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2163 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2167 sid_len
= IVAL(pdata
,4);
2168 /* Ensure this is less than 1mb. */
2169 if (sid_len
> (1024*1024)) {
2170 reply_doserror(req
, ERRDOS
, ERRnomem
);
2174 if (data_count
< 8+sid_len
) {
2175 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2176 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2180 data_len
= 4+40+sid_len
;
2182 if (max_data_count
< data_len
) {
2183 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2184 max_data_count
, data_len
));
2186 SIVAL(params
,0,data_len
);
2188 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2192 sid_parse(pdata
+8,sid_len
,&sid
);
2194 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2197 * we have to return zero's in all fields
2198 * instead of returning an error here
2203 /* Realloc the size of parameters and data we will return */
2205 params
= nttrans_realloc(ppparams
, param_len
);
2206 if(params
== NULL
) {
2207 reply_doserror(req
, ERRDOS
, ERRnomem
);
2211 pdata
= nttrans_realloc(ppdata
, data_len
);
2213 reply_doserror(req
, ERRDOS
, ERRnomem
);
2219 /* set params Size of returned Quota Data 4 bytes*/
2220 SIVAL(params
,0,data_len
);
2222 /* nextoffset entry 4 bytes */
2225 /* then the len of the SID 4 bytes */
2226 SIVAL(entry
,4,sid_len
);
2228 /* unknown data 8 bytes SMB_BIG_UINT */
2229 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2231 /* the used disk space 8 bytes SMB_BIG_UINT */
2232 SBIG_UINT(entry
,16,qt
.usedspace
);
2234 /* the soft quotas 8 bytes SMB_BIG_UINT */
2235 SBIG_UINT(entry
,24,qt
.softlim
);
2237 /* the hard quotas 8 bytes SMB_BIG_UINT */
2238 SBIG_UINT(entry
,32,qt
.hardlim
);
2240 /* and now the SID */
2241 sid_linearize(entry
+40, sid_len
, &sid
);
2246 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2247 reply_doserror(req
, ERRSRV
, ERRerror
);
2252 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2256 /****************************************************************************
2257 Reply to set user quota
2258 ****************************************************************************/
2260 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2261 struct smb_request
*req
,
2265 uint32 parameter_count
,
2268 uint32 max_data_count
)
2270 char *params
= *ppparams
;
2271 char *pdata
= *ppdata
;
2272 int data_len
=0,param_len
=0;
2273 SMB_NTQUOTA_STRUCT qt
;
2276 files_struct
*fsp
= NULL
;
2281 if (conn
->server_info
->utok
.uid
!= 0) {
2282 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2283 "[%s]\n", lp_servicename(SNUM(conn
)),
2284 conn
->server_info
->unix_name
));
2285 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2290 * Ensure minimum number of parameters sent.
2293 if (parameter_count
< 2) {
2294 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2295 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2299 /* maybe we can check the quota_fnum */
2300 fsp
= file_fsp(req
, SVAL(params
,0));
2301 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2302 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2303 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2307 if (data_count
< 40) {
2308 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2309 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2313 /* offset to next quota record.
2314 * 4 bytes IVAL(pdata,0)
2319 sid_len
= IVAL(pdata
,4);
2321 if (data_count
< 40+sid_len
) {
2322 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2323 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2327 /* unknown 8 bytes in pdata
2328 * maybe its the change time in NTTIME
2331 /* the used space 8 bytes (SMB_BIG_UINT)*/
2332 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2333 #ifdef LARGE_SMB_OFF_T
2334 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2335 #else /* LARGE_SMB_OFF_T */
2336 if ((IVAL(pdata
,20) != 0)&&
2337 ((qt
.usedspace
!= 0xFFFFFFFF)||
2338 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2339 /* more than 32 bits? */
2340 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2343 #endif /* LARGE_SMB_OFF_T */
2345 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2346 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2347 #ifdef LARGE_SMB_OFF_T
2348 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2349 #else /* LARGE_SMB_OFF_T */
2350 if ((IVAL(pdata
,28) != 0)&&
2351 ((qt
.softlim
!= 0xFFFFFFFF)||
2352 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2353 /* more than 32 bits? */
2354 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2357 #endif /* LARGE_SMB_OFF_T */
2359 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2360 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2361 #ifdef LARGE_SMB_OFF_T
2362 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2363 #else /* LARGE_SMB_OFF_T */
2364 if ((IVAL(pdata
,36) != 0)&&
2365 ((qt
.hardlim
!= 0xFFFFFFFF)||
2366 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2367 /* more than 32 bits? */
2368 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2371 #endif /* LARGE_SMB_OFF_T */
2373 sid_parse(pdata
+40,sid_len
,&sid
);
2374 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2376 /* 44 unknown bytes left... */
2378 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2379 reply_doserror(req
, ERRSRV
, ERRerror
);
2383 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2386 #endif /* HAVE_SYS_QUOTAS */
2388 static void handle_nttrans(connection_struct
*conn
,
2389 struct trans_state
*state
,
2390 struct smb_request
*req
)
2392 if (Protocol
>= PROTOCOL_NT1
) {
2393 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2394 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2397 /* Now we must call the relevant NT_TRANS function */
2398 switch(state
->call
) {
2399 case NT_TRANSACT_CREATE
:
2401 START_PROFILE(NT_transact_create
);
2402 call_nt_transact_create(
2404 &state
->setup
, state
->setup_count
,
2405 &state
->param
, state
->total_param
,
2406 &state
->data
, state
->total_data
,
2407 state
->max_data_return
);
2408 END_PROFILE(NT_transact_create
);
2412 case NT_TRANSACT_IOCTL
:
2414 START_PROFILE(NT_transact_ioctl
);
2415 call_nt_transact_ioctl(
2417 &state
->setup
, state
->setup_count
,
2418 &state
->param
, state
->total_param
,
2419 &state
->data
, state
->total_data
,
2420 state
->max_data_return
);
2421 END_PROFILE(NT_transact_ioctl
);
2425 case NT_TRANSACT_SET_SECURITY_DESC
:
2427 START_PROFILE(NT_transact_set_security_desc
);
2428 call_nt_transact_set_security_desc(
2430 &state
->setup
, state
->setup_count
,
2431 &state
->param
, state
->total_param
,
2432 &state
->data
, state
->total_data
,
2433 state
->max_data_return
);
2434 END_PROFILE(NT_transact_set_security_desc
);
2438 case NT_TRANSACT_NOTIFY_CHANGE
:
2440 START_PROFILE(NT_transact_notify_change
);
2441 call_nt_transact_notify_change(
2443 &state
->setup
, state
->setup_count
,
2444 &state
->param
, state
->total_param
,
2445 &state
->data
, state
->total_data
,
2446 state
->max_data_return
,
2447 state
->max_param_return
);
2448 END_PROFILE(NT_transact_notify_change
);
2452 case NT_TRANSACT_RENAME
:
2454 START_PROFILE(NT_transact_rename
);
2455 call_nt_transact_rename(
2457 &state
->setup
, state
->setup_count
,
2458 &state
->param
, state
->total_param
,
2459 &state
->data
, state
->total_data
,
2460 state
->max_data_return
);
2461 END_PROFILE(NT_transact_rename
);
2465 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2467 START_PROFILE(NT_transact_query_security_desc
);
2468 call_nt_transact_query_security_desc(
2470 &state
->setup
, state
->setup_count
,
2471 &state
->param
, state
->total_param
,
2472 &state
->data
, state
->total_data
,
2473 state
->max_data_return
);
2474 END_PROFILE(NT_transact_query_security_desc
);
2478 #ifdef HAVE_SYS_QUOTAS
2479 case NT_TRANSACT_GET_USER_QUOTA
:
2481 START_PROFILE(NT_transact_get_user_quota
);
2482 call_nt_transact_get_user_quota(
2484 &state
->setup
, state
->setup_count
,
2485 &state
->param
, state
->total_param
,
2486 &state
->data
, state
->total_data
,
2487 state
->max_data_return
);
2488 END_PROFILE(NT_transact_get_user_quota
);
2492 case NT_TRANSACT_SET_USER_QUOTA
:
2494 START_PROFILE(NT_transact_set_user_quota
);
2495 call_nt_transact_set_user_quota(
2497 &state
->setup
, state
->setup_count
,
2498 &state
->param
, state
->total_param
,
2499 &state
->data
, state
->total_data
,
2500 state
->max_data_return
);
2501 END_PROFILE(NT_transact_set_user_quota
);
2504 #endif /* HAVE_SYS_QUOTAS */
2507 /* Error in request */
2508 DEBUG(0,("handle_nttrans: Unknown request %d in "
2509 "nttrans call\n", state
->call
));
2510 reply_doserror(req
, ERRSRV
, ERRerror
);
2516 /****************************************************************************
2517 Reply to a SMBNTtrans.
2518 ****************************************************************************/
2520 void reply_nttrans(struct smb_request
*req
)
2522 connection_struct
*conn
= req
->conn
;
2527 uint16 function_code
;
2529 struct trans_state
*state
;
2533 START_PROFILE(SMBnttrans
);
2535 if (req
->wct
< 19) {
2536 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2537 END_PROFILE(SMBnttrans
);
2541 size
= smb_len(req
->inbuf
) + 4;
2542 av_size
= smb_len(req
->inbuf
);
2543 pscnt
= IVAL(req
->inbuf
,smb_nt_ParameterCount
);
2544 psoff
= IVAL(req
->inbuf
,smb_nt_ParameterOffset
);
2545 dscnt
= IVAL(req
->inbuf
,smb_nt_DataCount
);
2546 dsoff
= IVAL(req
->inbuf
,smb_nt_DataOffset
);
2547 function_code
= SVAL(req
->inbuf
, smb_nt_Function
);
2549 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2550 reply_doserror(req
, ERRSRV
, ERRaccess
);
2551 END_PROFILE(SMBnttrans
);
2555 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2556 if (!NT_STATUS_IS_OK(result
)) {
2557 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2558 reply_nterror(req
, result
);
2559 END_PROFILE(SMBnttrans
);
2563 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
2564 reply_doserror(req
, ERRSRV
, ERRaccess
);
2565 END_PROFILE(SMBnttrans
);
2569 state
->cmd
= SMBnttrans
;
2571 state
->mid
= req
->mid
;
2572 state
->vuid
= req
->vuid
;
2573 state
->total_data
= IVAL(req
->inbuf
, smb_nt_TotalDataCount
);
2575 state
->total_param
= IVAL(req
->inbuf
, smb_nt_TotalParameterCount
);
2576 state
->param
= NULL
;
2577 state
->max_data_return
= IVAL(req
->inbuf
,smb_nt_MaxDataCount
);
2578 state
->max_param_return
= IVAL(req
->inbuf
,smb_nt_MaxParameterCount
);
2580 /* setup count is in *words* */
2581 state
->setup_count
= 2*CVAL(req
->inbuf
,smb_nt_SetupCount
);
2582 state
->setup
= NULL
;
2583 state
->call
= function_code
;
2585 DEBUG(10, ("num_setup=%u, "
2586 "param_total=%u, this_param=%u, max_param=%u, "
2587 "data_total=%u, this_data=%u, max_data=%u, "
2588 "param_offset=%u, data_offset=%u\n",
2589 (unsigned)state
->setup_count
,
2590 (unsigned)state
->total_param
, (unsigned)pscnt
,
2591 (unsigned)state
->max_param_return
,
2592 (unsigned)state
->total_data
, (unsigned)dscnt
,
2593 (unsigned)state
->max_data_return
,
2594 (unsigned)psoff
, (unsigned)dsoff
));
2597 * All nttrans messages we handle have smb_wct == 19 +
2598 * state->setup_count. Ensure this is so as a sanity check.
2601 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2602 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2603 req
->wct
, 19 + (state
->setup_count
/2)));
2607 /* Don't allow more than 128mb for each value. */
2608 if ((state
->total_data
> (1024*1024*128)) ||
2609 (state
->total_param
> (1024*1024*128))) {
2610 reply_doserror(req
, ERRDOS
, ERRnomem
);
2611 END_PROFILE(SMBnttrans
);
2615 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2618 if (state
->total_data
) {
2619 /* Can't use talloc here, the core routines do realloc on the
2620 * params and data. */
2621 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2622 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2623 "bytes !\n", (unsigned int)state
->total_data
));
2625 reply_doserror(req
, ERRDOS
, ERRnomem
);
2626 END_PROFILE(SMBnttrans
);
2630 if (dscnt
> state
->total_data
||
2631 dsoff
+dscnt
< dsoff
) {
2635 if (dsoff
> av_size
||
2637 dsoff
+dscnt
> av_size
) {
2641 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2644 if (state
->total_param
) {
2645 /* Can't use talloc here, the core routines do realloc on the
2646 * params and data. */
2647 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2648 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2649 "bytes !\n", (unsigned int)state
->total_param
));
2650 SAFE_FREE(state
->data
);
2652 reply_doserror(req
, ERRDOS
, ERRnomem
);
2653 END_PROFILE(SMBnttrans
);
2657 if (pscnt
> state
->total_param
||
2658 psoff
+pscnt
< psoff
) {
2662 if (psoff
> av_size
||
2664 psoff
+pscnt
> av_size
) {
2668 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2671 state
->received_data
= dscnt
;
2672 state
->received_param
= pscnt
;
2674 if(state
->setup_count
> 0) {
2675 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2676 state
->setup_count
));
2677 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
2678 if (state
->setup
== NULL
) {
2679 DEBUG(0,("reply_nttrans : Out of memory\n"));
2680 SAFE_FREE(state
->data
);
2681 SAFE_FREE(state
->param
);
2683 reply_doserror(req
, ERRDOS
, ERRnomem
);
2684 END_PROFILE(SMBnttrans
);
2688 if ((smb_nt_SetupStart
+ state
->setup_count
< smb_nt_SetupStart
) ||
2689 (smb_nt_SetupStart
+ state
->setup_count
< state
->setup_count
)) {
2692 if (smb_nt_SetupStart
+ state
->setup_count
> size
) {
2696 memcpy( state
->setup
, &req
->inbuf
[smb_nt_SetupStart
],
2697 state
->setup_count
);
2698 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
2701 if ((state
->received_data
== state
->total_data
) &&
2702 (state
->received_param
== state
->total_param
)) {
2703 handle_nttrans(conn
, state
, req
);
2704 SAFE_FREE(state
->param
);
2705 SAFE_FREE(state
->data
);
2707 END_PROFILE(SMBnttrans
);
2711 DLIST_ADD(conn
->pending_trans
, state
);
2713 /* We need to send an interim response then receive the rest
2714 of the parameter/data bytes */
2715 reply_outbuf(req
, 0, 0);
2716 show_msg((char *)req
->outbuf
);
2717 END_PROFILE(SMBnttrans
);
2722 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2723 SAFE_FREE(state
->data
);
2724 SAFE_FREE(state
->param
);
2726 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2727 END_PROFILE(SMBnttrans
);
2731 /****************************************************************************
2732 Reply to a SMBnttranss
2733 ****************************************************************************/
2735 void reply_nttranss(struct smb_request
*req
)
2737 connection_struct
*conn
= req
->conn
;
2738 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2739 struct trans_state
*state
;
2743 START_PROFILE(SMBnttranss
);
2745 show_msg((char *)req
->inbuf
);
2747 if (req
->wct
< 18) {
2748 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2749 END_PROFILE(SMBnttranss
);
2753 for (state
= conn
->pending_trans
; state
!= NULL
;
2754 state
= state
->next
) {
2755 if (state
->mid
== req
->mid
) {
2760 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2761 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2762 END_PROFILE(SMBnttranss
);
2766 /* Revise state->total_param and state->total_data in case they have
2767 changed downwards */
2768 if (IVAL(req
->inbuf
, smb_nts_TotalParameterCount
)
2769 < state
->total_param
) {
2770 state
->total_param
= IVAL(req
->inbuf
,
2771 smb_nts_TotalParameterCount
);
2773 if (IVAL(req
->inbuf
, smb_nts_TotalDataCount
) < state
->total_data
) {
2774 state
->total_data
= IVAL(req
->inbuf
, smb_nts_TotalDataCount
);
2777 size
= smb_len(req
->inbuf
) + 4;
2778 av_size
= smb_len(req
->inbuf
);
2780 pcnt
= IVAL(req
->inbuf
,smb_nts_ParameterCount
);
2781 poff
= IVAL(req
->inbuf
, smb_nts_ParameterOffset
);
2782 pdisp
= IVAL(req
->inbuf
, smb_nts_ParameterDisplacement
);
2784 dcnt
= IVAL(req
->inbuf
, smb_nts_DataCount
);
2785 ddisp
= IVAL(req
->inbuf
, smb_nts_DataDisplacement
);
2786 doff
= IVAL(req
->inbuf
, smb_nts_DataOffset
);
2788 state
->received_param
+= pcnt
;
2789 state
->received_data
+= dcnt
;
2791 if ((state
->received_data
> state
->total_data
) ||
2792 (state
->received_param
> state
->total_param
))
2796 if (pdisp
> state
->total_param
||
2797 pcnt
> state
->total_param
||
2798 pdisp
+pcnt
> state
->total_param
||
2799 pdisp
+pcnt
< pdisp
) {
2803 if (poff
> av_size
||
2805 poff
+pcnt
> av_size
||
2810 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,
2815 if (ddisp
> state
->total_data
||
2816 dcnt
> state
->total_data
||
2817 ddisp
+dcnt
> state
->total_data
||
2818 ddisp
+dcnt
< ddisp
) {
2822 if (ddisp
> av_size
||
2824 ddisp
+dcnt
> av_size
||
2825 ddisp
+dcnt
< ddisp
) {
2829 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,
2833 if ((state
->received_param
< state
->total_param
) ||
2834 (state
->received_data
< state
->total_data
)) {
2835 END_PROFILE(SMBnttranss
);
2840 * construct_reply_common will copy smb_com from inbuf to
2841 * outbuf. SMBnttranss is wrong here.
2843 SCVAL(req
->inbuf
,smb_com
,SMBnttrans
);
2845 handle_nttrans(conn
, state
, req
);
2847 DLIST_REMOVE(conn
->pending_trans
, state
);
2848 SAFE_FREE(state
->data
);
2849 SAFE_FREE(state
->param
);
2851 END_PROFILE(SMBnttranss
);
2856 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2857 DLIST_REMOVE(conn
->pending_trans
, state
);
2858 SAFE_FREE(state
->data
);
2859 SAFE_FREE(state
->param
);
2861 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2862 END_PROFILE(SMBnttranss
);