2 Unix SMB/CIFS implementation.
3 SMB NT transaction handling
4 Copyright (C) Jeremy Allison 1994-1998
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 extern int smb_read_error
;
26 extern int global_oplock_break
;
27 extern BOOL case_sensitive
;
28 extern BOOL case_preserve
;
29 extern BOOL short_case_preserve
;
30 extern struct current_user current_user
;
32 static const char *known_nt_pipes
[] = {
49 /* Map generic permissions to file object specific permissions */
51 struct generic_mapping file_generic_mapping
= {
58 char *nttrans_realloc(char **ptr
, size_t size
)
62 smb_panic("nttrans_realloc() called with NULL ptr\n");
64 tptr
= Realloc_zero(*ptr
, size
);
76 /****************************************************************************
77 Send the required number of replies back.
78 We assume all fields other than the data fields are
79 set correctly for the type of call.
80 HACK ! Always assumes smb_setup field is zero.
81 ****************************************************************************/
83 static int send_nt_replies(char *inbuf
, char *outbuf
, int bufsize
, NTSTATUS nt_error
, char *params
,
84 int paramsize
, char *pdata
, int datasize
)
87 int data_to_send
= datasize
;
88 int params_to_send
= paramsize
;
92 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
93 int alignment_offset
= 3;
94 int data_alignment_offset
= 0;
97 * Initially set the wcnt area to be 18 - this is true for all
101 set_message(outbuf
,18,0,True
);
103 if (NT_STATUS_V(nt_error
))
107 * If there genuinely are no parameters or data to send just send
111 if(params_to_send
== 0 && data_to_send
== 0) {
112 if (!send_smb(smbd_server_fd(),outbuf
))
113 exit_server("send_nt_replies: send_smb failed.");
118 * When sending params and data ensure that both are nicely aligned.
119 * Only do this alignment when there is also data to send - else
120 * can cause NT redirector problems.
123 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0))
124 data_alignment_offset
= 4 - (params_to_send
% 4);
127 * Space is bufsize minus Netbios over TCP header minus SMB header.
128 * The alignment_offset is to align the param bytes on a four byte
129 * boundary (2 bytes for data len, one byte pad).
130 * NT needs this to work correctly.
133 useable_space
= bufsize
- ((smb_buf(outbuf
)+
134 alignment_offset
+data_alignment_offset
) -
138 * useable_space can never be more than max_send minus the
142 useable_space
= MIN(useable_space
,
143 max_send
- (alignment_offset
+data_alignment_offset
));
146 while (params_to_send
|| data_to_send
) {
149 * Calculate whether we will totally or partially fill this packet.
152 total_sent_thistime
= params_to_send
+ data_to_send
+
153 alignment_offset
+ data_alignment_offset
;
156 * We can never send more than useable_space.
159 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
161 set_message(outbuf
, 18, total_sent_thistime
, True
);
164 * Set total params and data to be sent.
167 SIVAL(outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
168 SIVAL(outbuf
,smb_ntr_TotalDataCount
,datasize
);
171 * Calculate how many parameters and data we can fit into
172 * this packet. Parameters get precedence.
175 params_sent_thistime
= MIN(params_to_send
,useable_space
);
176 data_sent_thistime
= useable_space
- params_sent_thistime
;
177 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
179 SIVAL(outbuf
,smb_ntr_ParameterCount
,params_sent_thistime
);
181 if(params_sent_thistime
== 0) {
182 SIVAL(outbuf
,smb_ntr_ParameterOffset
,0);
183 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,0);
186 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
187 * parameter bytes, however the first 4 bytes of outbuf are
188 * the Netbios over TCP header. Thus use smb_base() to subtract
189 * them from the calculation.
192 SIVAL(outbuf
,smb_ntr_ParameterOffset
,
193 ((smb_buf(outbuf
)+alignment_offset
) - smb_base(outbuf
)));
195 * Absolute displacement of param bytes sent in this packet.
198 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,pp
- params
);
202 * Deal with the data portion.
205 SIVAL(outbuf
,smb_ntr_DataCount
, data_sent_thistime
);
207 if(data_sent_thistime
== 0) {
208 SIVAL(outbuf
,smb_ntr_DataOffset
,0);
209 SIVAL(outbuf
,smb_ntr_DataDisplacement
, 0);
212 * The offset of the data bytes is the offset of the
213 * parameter bytes plus the number of parameters being sent this time.
216 SIVAL(outbuf
,smb_ntr_DataOffset
,((smb_buf(outbuf
)+alignment_offset
) -
217 smb_base(outbuf
)) + params_sent_thistime
+ data_alignment_offset
);
218 SIVAL(outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
222 * Copy the param bytes into the packet.
225 if(params_sent_thistime
)
226 memcpy((smb_buf(outbuf
)+alignment_offset
),pp
,params_sent_thistime
);
229 * Copy in the data bytes
232 if(data_sent_thistime
)
233 memcpy(smb_buf(outbuf
)+alignment_offset
+params_sent_thistime
+
234 data_alignment_offset
,pd
,data_sent_thistime
);
236 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
237 params_sent_thistime
, data_sent_thistime
, useable_space
));
238 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
239 params_to_send
, data_to_send
, paramsize
, datasize
));
241 /* Send the packet */
242 if (!send_smb(smbd_server_fd(),outbuf
))
243 exit_server("send_nt_replies: send_smb failed.");
245 pp
+= params_sent_thistime
;
246 pd
+= data_sent_thistime
;
248 params_to_send
-= params_sent_thistime
;
249 data_to_send
-= data_sent_thistime
;
255 if(params_to_send
< 0 || data_to_send
< 0) {
256 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
257 params_to_send
, data_to_send
));
265 /****************************************************************************
267 ****************************************************************************/
269 static BOOL saved_case_sensitive
;
270 static BOOL saved_case_preserve
;
271 static BOOL saved_short_case_preserve
;
273 /****************************************************************************
275 ****************************************************************************/
277 static void set_posix_case_semantics(uint32 file_attributes
)
279 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
))
282 saved_case_sensitive
= case_sensitive
;
283 saved_case_preserve
= case_preserve
;
284 saved_short_case_preserve
= short_case_preserve
;
287 case_sensitive
= True
;
288 case_preserve
= True
;
289 short_case_preserve
= True
;
292 /****************************************************************************
293 Restore case semantics.
294 ****************************************************************************/
296 static void restore_case_semantics(uint32 file_attributes
)
298 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
))
301 case_sensitive
= saved_case_sensitive
;
302 case_preserve
= saved_case_preserve
;
303 short_case_preserve
= saved_short_case_preserve
;
306 /****************************************************************************
307 Utility function to map create disposition.
308 ****************************************************************************/
310 static int map_create_disposition( uint32 create_disposition
)
314 switch( create_disposition
) {
316 /* create if not exist, fail if exist */
317 ret
= (FILE_CREATE_IF_NOT_EXIST
|FILE_EXISTS_FAIL
);
320 case FILE_OVERWRITE_IF
:
321 /* create if not exist, trunc if exist */
322 ret
= (FILE_CREATE_IF_NOT_EXIST
|FILE_EXISTS_TRUNCATE
);
325 /* fail if not exist, open if exists */
326 ret
= (FILE_FAIL_IF_NOT_EXIST
|FILE_EXISTS_OPEN
);
329 /* create if not exist, open if exists */
330 ret
= (FILE_CREATE_IF_NOT_EXIST
|FILE_EXISTS_OPEN
);
333 /* fail if not exist, truncate if exists */
334 ret
= (FILE_FAIL_IF_NOT_EXIST
|FILE_EXISTS_TRUNCATE
);
337 DEBUG(0,("map_create_disposition: Incorrect value for create_disposition = %d\n",
338 create_disposition
));
342 DEBUG(10,("map_create_disposition: Mapped create_disposition 0x%lx to 0x%x\n",
343 (unsigned long)create_disposition
, ret
));
348 /****************************************************************************
349 Utility function to map share modes.
350 ****************************************************************************/
352 static int map_share_mode( char *fname
, uint32 create_options
,
353 uint32
*desired_access
, uint32 share_access
, uint32 file_attributes
)
355 int smb_open_mode
= -1;
358 * Convert GENERIC bits to specific bits.
361 se_map_generic(desired_access
, &file_generic_mapping
);
363 switch( *desired_access
& (FILE_READ_DATA
|FILE_WRITE_DATA
|FILE_APPEND_DATA
) ) {
365 smb_open_mode
= DOS_OPEN_RDONLY
;
367 case FILE_WRITE_DATA
:
368 case FILE_APPEND_DATA
:
369 case FILE_WRITE_DATA
|FILE_APPEND_DATA
:
370 smb_open_mode
= DOS_OPEN_WRONLY
;
372 case FILE_READ_DATA
|FILE_WRITE_DATA
:
373 case FILE_READ_DATA
|FILE_WRITE_DATA
|FILE_APPEND_DATA
:
374 case FILE_READ_DATA
|FILE_APPEND_DATA
:
375 smb_open_mode
= DOS_OPEN_RDWR
;
380 * NB. For DELETE_ACCESS we should really check the
381 * directory permissions, as that is what controls
382 * delete, and for WRITE_DAC_ACCESS we should really
383 * check the ownership, as that is what controls the
384 * chmod. Note that this is *NOT* a security hole (this
385 * note is for you, Andrew) as we are not *allowing*
386 * the access at this point, the actual unlink or
387 * chown or chmod call would do this. We are just helping
388 * clients out by telling them if they have a hope
389 * of any of this succeeding. POSIX acls may still
390 * deny the real call. JRA.
393 if (smb_open_mode
== -1) {
395 if(*desired_access
& (DELETE_ACCESS
|WRITE_DAC_ACCESS
|WRITE_OWNER_ACCESS
|SYNCHRONIZE_ACCESS
|
396 FILE_EXECUTE
|FILE_READ_ATTRIBUTES
|
397 FILE_READ_EA
|FILE_WRITE_EA
|SYSTEM_SECURITY_ACCESS
|
398 FILE_WRITE_ATTRIBUTES
|READ_CONTROL_ACCESS
)) {
399 smb_open_mode
= DOS_OPEN_RDONLY
;
400 } else if(*desired_access
== 0) {
403 * JRA - NT seems to sometimes send desired_access as zero. play it safe
404 * and map to a stat open.
407 smb_open_mode
= DOS_OPEN_RDONLY
;
410 DEBUG(0,("map_share_mode: Incorrect value 0x%lx for desired_access to file %s\n",
411 (unsigned long)*desired_access
, fname
));
417 * Set the special bit that means allow share delete.
418 * This is held outside the normal share mode bits at 1<<15.
422 if(share_access
& FILE_SHARE_DELETE
) {
423 smb_open_mode
|= ALLOW_SHARE_DELETE
;
424 DEBUG(10,("map_share_mode: FILE_SHARE_DELETE requested. open_mode = 0x%x\n", smb_open_mode
));
428 * We need to store the intent to open for Delete. This
429 * is what determines if a delete on close flag can be set.
430 * This is the wrong way (and place) to store this, but for 2.2 this
431 * is the only practical way. JRA.
434 if(*desired_access
& DELETE_ACCESS
) {
435 DEBUG(10,("map_share_mode: DELETE_ACCESS requested. open_mode = 0x%x\n", smb_open_mode
));
438 if (create_options
& FILE_DELETE_ON_CLOSE
) {
439 /* Implicit delete access is *NOT* requested... */
440 smb_open_mode
|= DELETE_ON_CLOSE_FLAG
;
441 DEBUG(10,("map_share_mode: FILE_DELETE_ON_CLOSE requested. open_mode = 0x%x\n", smb_open_mode
));
444 /* Add in the requested share mode. */
445 switch( share_access
& (FILE_SHARE_READ
|FILE_SHARE_WRITE
)) {
446 case FILE_SHARE_READ
:
447 smb_open_mode
|= SET_DENY_MODE(DENY_WRITE
);
449 case FILE_SHARE_WRITE
:
450 smb_open_mode
|= SET_DENY_MODE(DENY_READ
);
452 case (FILE_SHARE_READ
|FILE_SHARE_WRITE
):
453 smb_open_mode
|= SET_DENY_MODE(DENY_NONE
);
455 case FILE_SHARE_NONE
:
456 smb_open_mode
|= SET_DENY_MODE(DENY_ALL
);
461 * Handle an O_SYNC request.
464 if(file_attributes
& FILE_FLAG_WRITE_THROUGH
)
465 smb_open_mode
|= FILE_SYNC_OPENMODE
;
467 DEBUG(10,("map_share_mode: Mapped desired access 0x%lx, share access 0x%lx, file attributes 0x%lx \
468 to open_mode 0x%x\n", (unsigned long)*desired_access
, (unsigned long)share_access
,
469 (unsigned long)file_attributes
, smb_open_mode
));
471 return smb_open_mode
;
474 /****************************************************************************
475 Reply to an NT create and X call on a pipe.
476 ****************************************************************************/
478 static int nt_open_pipe(char *fname
, connection_struct
*conn
,
479 char *inbuf
, char *outbuf
, int *ppnum
)
481 smb_np_struct
*p
= NULL
;
483 uint16 vuid
= SVAL(inbuf
, smb_uid
);
486 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
488 /* See if it is one we want to handle. */
490 if (lp_disable_spoolss() && strequal(fname
, "\\spoolss"))
491 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
493 for( i
= 0; known_nt_pipes
[i
]; i
++ )
494 if( strequal(fname
,known_nt_pipes
[i
]))
497 if ( known_nt_pipes
[i
] == NULL
)
498 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
500 /* Strip \\ off the name. */
503 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname
));
505 p
= open_rpc_pipe_p(fname
, conn
, vuid
);
507 return(ERROR_DOS(ERRSRV
,ERRnofids
));
514 /****************************************************************************
515 Reply to an NT create and X call for pipes.
516 ****************************************************************************/
518 static int do_ntcreate_pipe_open(connection_struct
*conn
,
519 char *inbuf
,char *outbuf
,int length
,int bufsize
)
526 srvstr_pull_buf(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
);
528 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
532 * Deal with pipe return.
535 set_message(outbuf
,34,0,True
);
537 p
= outbuf
+ smb_vwv2
;
541 SIVAL(p
,0,FILE_WAS_OPENED
);
544 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
547 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
549 SSVAL(p
,2, 0x5FF); /* ? */
551 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
553 return chain_reply(inbuf
,outbuf
,length
,bufsize
);
556 /****************************************************************************
557 Reply to an NT create and X call.
558 ****************************************************************************/
560 int reply_ntcreate_and_X(connection_struct
*conn
,
561 char *inbuf
,char *outbuf
,int length
,int bufsize
)
565 enum FAKE_FILE_TYPE fake_file_type
= FAKE_FILE_TYPE_NONE
;
566 uint32 flags
= IVAL(inbuf
,smb_ntcreate_Flags
);
567 uint32 desired_access
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
568 uint32 file_attributes
= IVAL(inbuf
,smb_ntcreate_FileAttributes
);
569 uint32 share_access
= IVAL(inbuf
,smb_ntcreate_ShareAccess
);
570 uint32 create_disposition
= IVAL(inbuf
,smb_ntcreate_CreateDisposition
);
571 uint32 create_options
= IVAL(inbuf
,smb_ntcreate_CreateOptions
);
572 uint16 root_dir_fid
= (uint16
)IVAL(inbuf
,smb_ntcreate_RootDirectoryFid
);
573 SMB_BIG_UINT allocation_size
= 0;
576 int smb_attr
= (file_attributes
& SAMBA_ATTRIBUTES_MASK
);
577 /* Breakout the oplock request bits so we can set the
578 reply bits separately. */
579 int oplock_request
= 0;
582 SMB_OFF_T file_len
= 0;
583 SMB_STRUCT_STAT sbuf
;
585 BOOL bad_path
= False
;
586 files_struct
*fsp
=NULL
;
589 BOOL extended_oplock_granted
= False
;
591 START_PROFILE(SMBntcreateX
);
593 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
594 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
595 create_options = 0x%x root_dir_fid = 0x%x\n", flags
, desired_access
, file_attributes
,
596 share_access
, create_disposition
,
597 create_options
, root_dir_fid
));
599 /* If it's an IPC, use the pipe handler. */
602 if (lp_nt_pipe_support()) {
603 END_PROFILE(SMBntcreateX
);
604 return do_ntcreate_pipe_open(conn
,inbuf
,outbuf
,length
,bufsize
);
606 END_PROFILE(SMBntcreateX
);
607 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
611 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
612 END_PROFILE(SMBntcreateX
);
613 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
617 * We need to construct the open_and_X ofun value from the
618 * NT values, as that's what our code is structured to accept.
621 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1) {
622 END_PROFILE(SMBntcreateX
);
623 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
630 if(root_dir_fid
!= 0) {
632 * This filename is relative to a directory fid.
634 files_struct
*dir_fsp
= file_fsp(inbuf
,smb_ntcreate_RootDirectoryFid
);
638 END_PROFILE(SMBntcreateX
);
639 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
642 if(!dir_fsp
->is_directory
) {
644 srvstr_pull_buf(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
);
647 * Check to see if this is a mac fork of some kind.
650 if( strchr_m(fname
, ':')) {
651 END_PROFILE(SMBntcreateX
);
652 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
657 we need to handle the case when we get a
658 relative open relative to a file and the
659 pathname is blank - this is a reopen!
660 (hint from demyn plantenberg)
664 END_PROFILE(SMBntcreateX
);
665 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
669 * Copy in the base directory name.
672 pstrcpy( fname
, dir_fsp
->fsp_name
);
673 dir_name_len
= strlen(fname
);
676 * Ensure it ends in a '\'.
679 if(fname
[dir_name_len
-1] != '\\' && fname
[dir_name_len
-1] != '/') {
680 pstrcat(fname
, "\\");
684 srvstr_pull_buf(inbuf
, &fname
[dir_name_len
], smb_buf(inbuf
), sizeof(fname
)-dir_name_len
, STR_TERMINATE
);
686 srvstr_pull_buf(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
);
689 * Check to see if this is a mac fork of some kind.
692 if( strchr_m(fname
, ':')) {
694 #ifdef HAVE_SYS_QUOTAS
695 if ((fake_file_type
=is_fake_file(fname
))!=FAKE_FILE_TYPE_NONE
) {
697 * here we go! support for changing the disk quotas --metze
699 * we need to fake up to open this MAGIC QUOTA file
700 * and return a valid FID
702 * w2k close this file directly after openening
703 * xp also tries a QUERY_FILE_INFO on the file and then close it
707 END_PROFILE(SMBntcreateX
);
708 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
709 #ifdef HAVE_SYS_QUOTAS
716 * Now contruct the smb_open_mode value from the filename,
717 * desired access and the share access.
719 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
721 if((smb_open_mode
= map_share_mode(fname
, create_options
, &desired_access
,
723 file_attributes
)) == -1) {
724 END_PROFILE(SMBntcreateX
);
725 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
728 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
729 if (oplock_request
) {
730 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
734 * Ordinary file or directory.
738 * Check if POSIX semantics are wanted.
741 set_posix_case_semantics(file_attributes
);
743 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
745 unixmode
= unix_mode(conn
,smb_attr
| aARCH
, fname
);
748 * If it's a request for a directory open, deal with it separately.
751 if(create_options
& FILE_DIRECTORY_FILE
) {
754 /* Can't open a temp directory. IFS kit test. */
755 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
756 END_PROFILE(SMBntcreateX
);
757 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
760 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
762 restore_case_semantics(file_attributes
);
765 set_bad_path_error(errno
, bad_path
);
766 END_PROFILE(SMBntcreateX
);
767 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
771 * Ordinary file case.
774 /* NB. We have a potential bug here. If we
775 * cause an oplock break to ourselves, then we
776 * could end up processing filename related
777 * SMB requests whilst we await the oplock
778 * break response. As we may have changed the
779 * filename case semantics to be POSIX-like,
780 * this could mean a filename request could
781 * fail when it should succeed. This is a rare
782 * condition, but eventually we must arrange
783 * to restore the correct case semantics
784 * before issuing an oplock break request to
785 * our client. JRA. */
787 if (fake_file_type
==FAKE_FILE_TYPE_NONE
) {
788 fsp
= open_file_shared1(conn
,fname
,&sbuf
,
791 smb_ofun
,unixmode
, oplock_request
,
794 /* to open a fake_file --metze */
795 fsp
= open_fake_file_shared1(fake_file_type
,conn
,fname
,&sbuf
,
798 smb_ofun
,unixmode
, oplock_request
,
803 /* We cheat here. There are two cases we
804 * care about. One is a directory rename,
805 * where the NT client will attempt to
806 * open the source directory for
807 * DELETE access. Note that when the
808 * NT client does this it does *not*
809 * set the directory bit in the
810 * request packet. This is translated
811 * into a read/write open
812 * request. POSIX states that any open
813 * for write request on a directory
814 * will generate an EISDIR error, so
815 * we can catch this here and open a
816 * pseudo handle that is flagged as a
817 * directory. The second is an open
818 * for a permissions read only, which
819 * we handle in the open_file_stat case. JRA.
822 if(errno
== EISDIR
) {
825 * Fail the open if it was explicitly a non-directory file.
828 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
829 restore_case_semantics(file_attributes
);
830 SSVAL(outbuf
, smb_flg2
,
831 SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
832 END_PROFILE(SMBntcreateX
);
833 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
837 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
840 restore_case_semantics(file_attributes
);
841 set_bad_path_error(errno
, bad_path
);
842 END_PROFILE(SMBntcreateX
);
843 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
847 restore_case_semantics(file_attributes
);
848 set_bad_path_error(errno
, bad_path
);
849 END_PROFILE(SMBntcreateX
);
850 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
855 restore_case_semantics(file_attributes
);
857 file_len
= sbuf
.st_size
;
858 fmode
= dos_mode(conn
,fname
,&sbuf
);
860 fmode
= FILE_ATTRIBUTE_NORMAL
;
861 if (!fsp
->is_directory
&& (fmode
& aDIR
)) {
862 close_file(fsp
,False
);
863 END_PROFILE(SMBntcreateX
);
864 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
867 /* Save the requested allocation size. */
868 allocation_size
= (SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
);
869 #ifdef LARGE_SMB_OFF_T
870 allocation_size
|= (((SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
+ 4)) << 32);
872 if (allocation_size
&& (allocation_size
> (SMB_BIG_UINT
)file_len
)) {
873 fsp
->initial_allocation_size
= SMB_ROUNDUP(allocation_size
,SMB_ROUNDUP_ALLOCATION_SIZE
);
874 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
875 close_file(fsp
,False
);
876 END_PROFILE(SMBntcreateX
);
877 return ERROR_NT(NT_STATUS_DISK_FULL
);
880 fsp
->initial_allocation_size
= SMB_ROUNDUP(((SMB_BIG_UINT
)file_len
),SMB_ROUNDUP_ALLOCATION_SIZE
);
884 * If the caller set the extended oplock request bit
885 * and we granted one (by whatever means) - set the
886 * correct bit for extended oplock reply.
889 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
890 extended_oplock_granted
= True
;
892 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
893 extended_oplock_granted
= True
;
896 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
897 set_message(outbuf
,42,0,True
);
899 set_message(outbuf
,34,0,True
);
902 p
= outbuf
+ smb_vwv2
;
905 * Currently as we don't support level II oplocks we just report
906 * exclusive & batch here.
909 if (extended_oplock_granted
) {
910 if (flags
& REQUEST_BATCH_OPLOCK
) {
911 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
913 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
915 } else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
)) {
916 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
918 SCVAL(p
,0,NO_OPLOCK_RETURN
);
922 SSVAL(p
,0,fsp
->fnum
);
924 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
925 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
927 SIVAL(p
,0,smb_action
);
931 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
933 if (lp_dos_filetime_resolution(SNUM(conn
))) {
940 put_long_date(p
,c_time
);
942 put_long_date(p
,sbuf
.st_atime
); /* access time */
944 put_long_date(p
,sbuf
.st_mtime
); /* write time */
946 put_long_date(p
,sbuf
.st_mtime
); /* change time */
948 SIVAL(p
,0,fmode
); /* File Attributes. */
950 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
952 SOFF_T(p
,0,file_len
);
954 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
956 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
958 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
959 END_PROFILE(SMBntcreateX
);
963 /****************************************************************************
964 Reply to a NT_TRANSACT_CREATE call to open a pipe.
965 ****************************************************************************/
967 static int do_nt_transact_create_pipe( connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
968 char **ppsetup
, uint32 setup_count
,
969 char **ppparams
, uint32 parameter_count
,
970 char **ppdata
, uint32 data_count
)
973 char *params
= *ppparams
;
979 * Ensure minimum number of parameters sent.
982 if(parameter_count
< 54) {
983 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
984 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
987 srvstr_pull(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
);
989 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
992 /* Realloc the size of parameters and data we will return */
993 params
= nttrans_realloc(ppparams
, 69);
995 return ERROR_DOS(ERRDOS
,ERRnomem
);
998 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1003 SIVAL(p
,0,FILE_WAS_OPENED
);
1007 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
1010 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
1012 SSVAL(p
,2, 0x5FF); /* ? */
1014 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
1016 /* Send the required number of replies */
1017 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1022 /****************************************************************************
1023 Internal fn to set security descriptors.
1024 ****************************************************************************/
1026 static NTSTATUS
set_sd(files_struct
*fsp
, char *data
, uint32 sd_len
, uint32 security_info_sent
)
1029 SEC_DESC
*psd
= NULL
;
1030 TALLOC_CTX
*mem_ctx
;
1034 return NT_STATUS_OK
;
1038 * Init the parse struct we will unmarshall from.
1041 if ((mem_ctx
= talloc_init("set_sd")) == NULL
) {
1042 DEBUG(0,("set_sd: talloc_init failed.\n"));
1043 return NT_STATUS_NO_MEMORY
;
1046 prs_init(&pd
, 0, mem_ctx
, UNMARSHALL
);
1049 * Setup the prs_struct to point at the memory we just
1053 prs_give_memory( &pd
, data
, sd_len
, False
);
1056 * Finally, unmarshall from the data buffer.
1059 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1060 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1062 * Return access denied for want of a better error message..
1064 talloc_destroy(mem_ctx
);
1065 return NT_STATUS_NO_MEMORY
;
1068 if (psd
->off_owner_sid
==0)
1069 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
1070 if (psd
->off_grp_sid
==0)
1071 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
1072 if (psd
->off_sacl
==0)
1073 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
1074 if (psd
->off_dacl
==0)
1075 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
1077 ret
= SMB_VFS_FSET_NT_ACL( fsp
, fsp
->fd
, security_info_sent
, psd
);
1080 talloc_destroy(mem_ctx
);
1081 return NT_STATUS_ACCESS_DENIED
;
1084 talloc_destroy(mem_ctx
);
1086 return NT_STATUS_OK
;
1089 /****************************************************************************
1090 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1091 ****************************************************************************/
1093 static int call_nt_transact_create(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1094 char **ppsetup
, uint32 setup_count
,
1095 char **ppparams
, uint32 parameter_count
,
1096 char **ppdata
, uint32 data_count
)
1099 char *params
= *ppparams
;
1100 char *data
= *ppdata
;
1101 /* Breakout the oplock request bits so we can set the reply bits separately. */
1102 int oplock_request
= 0;
1104 int fmode
=0,rmode
=0;
1105 SMB_OFF_T file_len
= 0;
1106 SMB_STRUCT_STAT sbuf
;
1108 BOOL bad_path
= False
;
1109 files_struct
*fsp
= NULL
;
1111 BOOL extended_oplock_granted
= False
;
1113 uint32 desired_access
;
1114 uint32 file_attributes
;
1115 uint32 share_access
;
1116 uint32 create_disposition
;
1117 uint32 create_options
;
1119 uint16 root_dir_fid
;
1120 SMB_BIG_UINT allocation_size
= 0;
1127 DEBUG(5,("call_nt_transact_create\n"));
1130 * If it's an IPC, use the pipe handler.
1134 if (lp_nt_pipe_support())
1135 return do_nt_transact_create_pipe(conn
, inbuf
, outbuf
, length
,
1137 ppsetup
, setup_count
,
1138 ppparams
, parameter_count
,
1139 ppdata
, data_count
);
1141 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1145 * Ensure minimum number of parameters sent.
1148 if(parameter_count
< 54) {
1149 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1150 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1153 flags
= IVAL(params
,0);
1154 desired_access
= IVAL(params
,8);
1155 file_attributes
= IVAL(params
,20);
1156 share_access
= IVAL(params
,24);
1157 create_disposition
= IVAL(params
,28);
1158 create_options
= IVAL(params
,32);
1159 sd_len
= IVAL(params
,36);
1160 root_dir_fid
= (uint16
)IVAL(params
,4);
1161 smb_attr
= (file_attributes
& SAMBA_ATTRIBUTES_MASK
);
1163 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
1164 END_PROFILE(SMBntcreateX
);
1165 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1169 * We need to construct the open_and_X ofun value from the
1170 * NT values, as that's what our code is structured to accept.
1173 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1)
1174 return ERROR_DOS(ERRDOS
,ERRbadmem
);
1177 * Get the file name.
1180 if(root_dir_fid
!= 0) {
1182 * This filename is relative to a directory fid.
1185 files_struct
*dir_fsp
= file_fsp(params
,4);
1186 size_t dir_name_len
;
1189 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1191 if(!dir_fsp
->is_directory
) {
1193 srvstr_pull(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
);
1196 * Check to see if this is a mac fork of some kind.
1199 if( strchr_m(fname
, ':'))
1200 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1202 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1206 * Copy in the base directory name.
1209 pstrcpy( fname
, dir_fsp
->fsp_name
);
1210 dir_name_len
= strlen(fname
);
1213 * Ensure it ends in a '\'.
1216 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
1217 pstrcat(fname
, "\\");
1221 srvstr_pull(inbuf
, &fname
[dir_name_len
], params
+53, sizeof(fname
)-dir_name_len
,
1222 parameter_count
-53, STR_TERMINATE
);
1224 srvstr_pull(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
);
1227 * Check to see if this is a mac fork of some kind.
1230 if( strchr_m(fname
, ':'))
1231 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1235 * Now contruct the smb_open_mode value from the desired access
1236 * and the share access.
1239 if((smb_open_mode
= map_share_mode( fname
, create_options
, &desired_access
,
1240 share_access
, file_attributes
)) == -1)
1241 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1243 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1244 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1247 * Check if POSIX semantics are wanted.
1250 set_posix_case_semantics(file_attributes
);
1252 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
1254 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
1256 unixmode
= unix_mode(conn
,smb_attr
| aARCH
, fname
);
1259 * If it's a request for a directory open, deal with it separately.
1262 if(create_options
& FILE_DIRECTORY_FILE
) {
1264 /* Can't open a temp directory. IFS kit test. */
1265 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
1266 END_PROFILE(SMBntcreateX
);
1267 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1273 * We will get a create directory here if the Win32
1274 * app specified a security descriptor in the
1275 * CreateDirectory() call.
1278 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
1281 restore_case_semantics(file_attributes
);
1282 set_bad_path_error(errno
, bad_path
);
1283 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1289 * Ordinary file case.
1292 fsp
= open_file_shared1(conn
,fname
,&sbuf
,desired_access
,
1293 smb_open_mode
,smb_ofun
,unixmode
,
1294 oplock_request
,&rmode
,&smb_action
);
1298 if(errno
== EISDIR
) {
1301 * Fail the open if it was explicitly a non-directory file.
1304 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
1305 restore_case_semantics(file_attributes
);
1306 SSVAL(outbuf
, smb_flg2
, SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
1307 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
1311 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
1314 restore_case_semantics(file_attributes
);
1315 set_bad_path_error(errno
, bad_path
);
1316 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1319 restore_case_semantics(file_attributes
);
1320 set_bad_path_error(errno
, bad_path
);
1321 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1325 file_len
= sbuf
.st_size
;
1326 fmode
= dos_mode(conn
,fname
,&sbuf
);
1328 fmode
= FILE_ATTRIBUTE_NORMAL
;
1331 close_file(fsp
,False
);
1332 restore_case_semantics(file_attributes
);
1333 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1337 * If the caller set the extended oplock request bit
1338 * and we granted one (by whatever means) - set the
1339 * correct bit for extended oplock reply.
1342 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
1343 extended_oplock_granted
= True
;
1345 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
1346 extended_oplock_granted
= True
;
1350 * Now try and apply the desired SD.
1353 if (sd_len
&& !NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, sd_len
, ALL_SECURITY_INFORMATION
))) {
1354 close_file(fsp
,False
);
1355 restore_case_semantics(file_attributes
);
1356 return ERROR_NT(nt_status
);
1359 restore_case_semantics(file_attributes
);
1361 /* Save the requested allocation size. */
1362 allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
1363 #ifdef LARGE_SMB_OFF_T
1364 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
1366 if (allocation_size
&& (allocation_size
> file_len
)) {
1367 fsp
->initial_allocation_size
= SMB_ROUNDUP(allocation_size
,SMB_ROUNDUP_ALLOCATION_SIZE
);
1368 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
1369 close_file(fsp
,False
);
1370 END_PROFILE(SMBntcreateX
);
1371 return ERROR_NT(NT_STATUS_DISK_FULL
);
1374 fsp
->initial_allocation_size
= SMB_ROUNDUP(((SMB_BIG_UINT
)file_len
),SMB_ROUNDUP_ALLOCATION_SIZE
);
1377 /* Realloc the size of parameters and data we will return */
1378 params
= nttrans_realloc(ppparams
, 69);
1380 return ERROR_DOS(ERRDOS
,ERRnomem
);
1383 if (extended_oplock_granted
)
1384 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
1385 else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
))
1386 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
1388 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1391 SSVAL(p
,0,fsp
->fnum
);
1393 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
1394 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1396 SIVAL(p
,0,smb_action
);
1400 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1402 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1404 sbuf
.st_atime
&= ~1;
1405 sbuf
.st_mtime
&= ~1;
1406 sbuf
.st_mtime
&= ~1;
1409 put_long_date(p
,c_time
);
1411 put_long_date(p
,sbuf
.st_atime
); /* access time */
1413 put_long_date(p
,sbuf
.st_mtime
); /* write time */
1415 put_long_date(p
,sbuf
.st_mtime
); /* change time */
1417 SIVAL(p
,0,fmode
); /* File Attributes. */
1419 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
1421 SOFF_T(p
,0,file_len
);
1423 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname
));
1425 /* Send the required number of replies */
1426 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1431 /****************************************************************************
1432 Reply to a NT CANCEL request.
1433 ****************************************************************************/
1435 int reply_ntcancel(connection_struct
*conn
,
1436 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1439 * Go through and cancel any pending change notifies.
1442 int mid
= SVAL(inbuf
,smb_mid
);
1443 START_PROFILE(SMBntcancel
);
1444 remove_pending_change_notify_requests_by_mid(mid
);
1445 remove_pending_lock_requests_by_mid(mid
);
1446 srv_cancel_sign_response(mid
);
1448 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid
));
1450 END_PROFILE(SMBntcancel
);
1454 /****************************************************************************
1455 Reply to an unsolicited SMBNTtranss - just ignore it!
1456 ****************************************************************************/
1458 int reply_nttranss(connection_struct
*conn
,
1459 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1461 START_PROFILE(SMBnttranss
);
1462 DEBUG(4,("Ignoring nttranss of length %d\n",length
));
1463 END_PROFILE(SMBnttranss
);
1467 /****************************************************************************
1468 Reply to a notify change - queue the request and
1469 don't allow a directory to be opened.
1470 ****************************************************************************/
1472 static int call_nt_transact_notify_change(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1473 char **ppsetup
, uint32 setup_count
,
1474 char **ppparams
, uint32 parameter_count
,
1475 char **ppdata
, uint32 data_count
)
1477 char *setup
= *ppsetup
;
1481 fsp
= file_fsp(setup
,4);
1482 flags
= IVAL(setup
, 0);
1484 DEBUG(3,("call_nt_transact_notify_change\n"));
1487 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1489 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
))
1490 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1492 if (!change_notify_set(inbuf
, fsp
, conn
, flags
))
1493 return(UNIXERROR(ERRDOS
,ERRbadfid
));
1495 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1496 name = %s\n", fsp
->fsp_name
));
1501 /****************************************************************************
1502 Reply to an NT transact rename command.
1503 ****************************************************************************/
1505 static int call_nt_transact_rename(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1506 char **ppsetup
, uint32 setup_count
,
1507 char **ppparams
, uint32 parameter_count
,
1508 char **ppdata
, uint32 data_count
)
1510 char *params
= *ppparams
;
1512 files_struct
*fsp
= NULL
;
1513 BOOL replace_if_exists
= False
;
1516 if(parameter_count
< 4)
1517 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1519 fsp
= file_fsp(params
, 0);
1520 replace_if_exists
= (SVAL(params
,2) & RENAME_REPLACE_IF_EXISTS
) ? True
: False
;
1521 CHECK_FSP(fsp
, conn
);
1522 srvstr_pull(inbuf
, new_name
, params
+4, sizeof(new_name
), -1, STR_TERMINATE
);
1524 status
= rename_internals(conn
, fsp
->fsp_name
,
1525 new_name
, replace_if_exists
);
1526 if (!NT_STATUS_IS_OK(status
))
1527 return ERROR_NT(status
);
1530 * Rename was successful.
1532 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1534 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1535 fsp
->fsp_name
, new_name
));
1538 * Win2k needs a changenotify request response before it will
1539 * update after a rename..
1542 process_pending_change_notify_queue((time_t)0);
1547 /******************************************************************************
1548 Fake up a completely empty SD.
1549 *******************************************************************************/
1551 static size_t get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1553 extern DOM_SID global_sid_World
;
1556 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1558 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1565 /****************************************************************************
1566 Reply to query a security descriptor.
1567 ****************************************************************************/
1569 static int call_nt_transact_query_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1570 char **ppsetup
, uint32 setup_count
,
1571 char **ppparams
, uint32 parameter_count
,
1572 char **ppdata
, uint32 data_count
)
1574 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
1575 char *params
= *ppparams
;
1576 char *data
= *ppdata
;
1578 SEC_DESC
*psd
= NULL
;
1580 uint32 security_info_wanted
;
1581 TALLOC_CTX
*mem_ctx
;
1582 files_struct
*fsp
= NULL
;
1584 if(parameter_count
< 8)
1585 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1587 fsp
= file_fsp(params
,0);
1589 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1591 security_info_wanted
= IVAL(params
,4);
1593 DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp
->fsp_name
));
1595 params
= nttrans_realloc(ppparams
, 4);
1597 return ERROR_DOS(ERRDOS
,ERRnomem
);
1599 if ((mem_ctx
= talloc_init("call_nt_transact_query_security_desc")) == NULL
) {
1600 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1601 return ERROR_DOS(ERRDOS
,ERRnomem
);
1605 * Get the permissions to return.
1608 if (!lp_nt_acl_support(SNUM(conn
)))
1609 sd_size
= get_null_nt_acl(mem_ctx
, &psd
);
1611 sd_size
= SMB_VFS_FGET_NT_ACL(fsp
, fsp
->fd
, security_info_wanted
, &psd
);
1614 talloc_destroy(mem_ctx
);
1615 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1618 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size
));
1620 SIVAL(params
,0,(uint32
)sd_size
);
1622 if(max_data_count
< sd_size
) {
1624 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_BUFFER_TOO_SMALL
,
1625 params
, 4, *ppdata
, 0);
1626 talloc_destroy(mem_ctx
);
1631 * Allocate the data we will point this at.
1634 data
= nttrans_realloc(ppdata
, sd_size
);
1636 talloc_destroy(mem_ctx
);
1637 return ERROR_DOS(ERRDOS
,ERRnomem
);
1641 * Init the parse struct we will marshall into.
1644 prs_init(&pd
, 0, mem_ctx
, MARSHALL
);
1647 * Setup the prs_struct to point at the memory we just
1651 prs_give_memory( &pd
, data
, (uint32
)sd_size
, False
);
1654 * Finally, linearize into the outgoing buffer.
1657 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1658 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
1659 security descriptor.\n"));
1661 * Return access denied for want of a better error message..
1663 talloc_destroy(mem_ctx
);
1664 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1668 * Now we can delete the security descriptor.
1671 talloc_destroy(mem_ctx
);
1673 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1677 /****************************************************************************
1678 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1679 ****************************************************************************/
1681 static int call_nt_transact_set_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1682 char **ppsetup
, uint32 setup_count
,
1683 char **ppparams
, uint32 parameter_count
,
1684 char **ppdata
, uint32 data_count
)
1686 char *params
= *ppparams
;
1687 char *data
= *ppdata
;
1688 files_struct
*fsp
= NULL
;
1689 uint32 security_info_sent
= 0;
1692 if(parameter_count
< 8)
1693 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1695 if((fsp
= file_fsp(params
,0)) == NULL
)
1696 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1698 if(!lp_nt_acl_support(SNUM(conn
)))
1701 security_info_sent
= IVAL(params
,4);
1703 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
1704 (unsigned int)security_info_sent
));
1706 if (data_count
== 0)
1707 return ERROR_DOS(ERRDOS
, ERRnoaccess
);
1709 if (!NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, data_count
, security_info_sent
)))
1710 return ERROR_NT(nt_status
);
1714 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1718 /****************************************************************************
1720 ****************************************************************************/
1722 static int call_nt_transact_ioctl(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1723 char **ppsetup
, uint32 setup_count
,
1724 char **ppparams
, uint32 parameter_count
,
1725 char **ppdata
, uint32 data_count
)
1727 unsigned fnum
, control
;
1728 static BOOL logged_message
;
1729 char *pdata
= *ppdata
;
1731 if (setup_count
!= 8) {
1732 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1733 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1736 fnum
= SVAL(*ppsetup
, 4);
1737 control
= IVAL(*ppsetup
, 0);
1739 DEBUG(10,("call_nt_transact_ioctl: fnum=%d control=0x%08x\n",
1743 case FSCTL_SET_SPARSE
:
1744 /* pretend this succeeded - tho strictly we should
1745 mark the file sparse (if the local fs supports it)
1746 so we can know if we need to pre-allocate or not */
1748 DEBUG(10,("FSCTL_SET_SPARSE: fnum=%d control=0x%08x\n",fnum
,control
));
1749 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1752 case FSCTL_0x000900C0
:
1753 /* pretend this succeeded - don't know what this really is
1754 but works ok like this --metze
1757 DEBUG(10,("FSCTL_GET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum
,control
));
1758 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1761 case FSCTL_GET_REPARSE_POINT
:
1762 /* pretend this fail - my winXP does it like this
1766 DEBUG(10,("FSCTL_GET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum
,control
));
1767 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
1770 case FSCTL_SET_REPARSE_POINT
:
1771 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1775 DEBUG(10,("FSCTL_SET_REPARSE_POINT: fnum=%d control=0x%08x\n",fnum
,control
));
1776 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
1779 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
1781 /* pretend this succeeded -
1783 * we have to send back a list with all files owned by this SID
1785 * but I have to check that --metze
1790 size_t sid_len
=SID_MAX_SIZE
;
1792 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: fnum=%d control=0x%08x\n",fnum
,control
));
1794 /* this is not the length of the sid :-( so unknown 4 bytes */
1795 /*sid_len = IVAL(pdata,0);
1796 DEBUGADD(0,("sid_len: (%u)\n",sid_len));*/
1798 sid_parse(pdata
+4,sid_len
,&sid
);
1799 DEBUGADD(10,("SID: %s\n",sid_string_static(&sid
)));
1801 if (!NT_STATUS_IS_OK(sid_to_uid(&sid
, &uid
))) {
1802 DEBUG(0,("sid_to_uid: failed, sid[%s]\n",
1803 sid_string_static(&sid
)));
1807 /* we can take a look at the find source :-)
1809 * find ./ -uid $uid -name '*' is what we need here
1812 * and send 4bytes len and then NULL terminated unicode strings
1815 * but I don't know how to deal with the paged results
1817 * we don't send all files at once
1818 * and at the next we should *not* start from the beginning,
1819 * so we have to cache the result
1824 /* this works for now... */
1825 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1829 if (!logged_message
) {
1830 logged_message
= True
; /* Only print this once... */
1831 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
1836 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1840 #ifdef HAVE_SYS_QUOTAS
1841 /****************************************************************************
1842 Reply to get user quota
1843 ****************************************************************************/
1845 static int call_nt_transact_get_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1846 char **ppsetup
, uint32 setup_count
,
1847 char **ppparams
, uint32 parameter_count
,
1848 char **ppdata
, uint32 data_count
)
1850 NTSTATUS nt_status
= NT_STATUS_OK
;
1851 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
1852 char *params
= *ppparams
;
1853 char *pdata
= *ppdata
;
1855 int data_len
=0,param_len
=0;
1858 files_struct
*fsp
= NULL
;
1862 BOOL start_enum
= True
;
1863 SMB_NTQUOTA_STRUCT qt
;
1864 SMB_NTQUOTA_LIST
*tmp_list
;
1865 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
1870 if (conn
->admin_user
!= True
) {
1871 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
1872 lp_servicename(SNUM(conn
)),conn
->user
));
1873 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1877 * Ensure minimum number of parameters sent.
1880 if (parameter_count
< 4) {
1881 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
1882 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
1885 /* maybe we can check the quota_fnum */
1886 fsp
= file_fsp(params
,0);
1887 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
1888 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
1889 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
1892 /* the NULL pointer cheking for fsp->fake_file_handle->pd
1893 * is done by CHECK_NTQUOTA_HANDLE_OK()
1895 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
1897 level
= SVAL(params
,2);
1899 /* unknown 12 bytes leading in params */
1902 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
1903 /* seems that we should continue with the enum here --metze */
1905 if (qt_handle
->quota_list
!=NULL
&&
1906 qt_handle
->tmp_list
==NULL
) {
1909 free_ntquota_list(&(qt_handle
->quota_list
));
1911 /* Realloc the size of parameters and data we will return */
1913 params
= nttrans_realloc(ppparams
, param_len
);
1915 return ERROR_DOS(ERRDOS
,ERRnomem
);
1918 SIVAL(params
,0,data_len
);
1925 case TRANSACT_GET_USER_QUOTA_LIST_START
:
1927 if (qt_handle
->quota_list
==NULL
&&
1928 qt_handle
->tmp_list
==NULL
) {
1932 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0)
1933 return ERROR_DOS(ERRSRV
,ERRerror
);
1935 /* Realloc the size of parameters and data we will return */
1937 params
= nttrans_realloc(ppparams
, param_len
);
1939 return ERROR_DOS(ERRDOS
,ERRnomem
);
1941 /* we should not trust the value in max_data_count*/
1942 max_data_count
= MIN(max_data_count
,2048);
1944 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
1946 return ERROR_DOS(ERRDOS
,ERRnomem
);
1951 /* set params Size of returned Quota Data 4 bytes*/
1952 /* but set it later when we know it */
1954 /* for each entry push the data */
1957 qt_handle
->tmp_list
= qt_handle
->quota_list
;
1960 tmp_list
= qt_handle
->tmp_list
;
1962 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
1963 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
1965 sid_len
= sid_size(&tmp_list
->quotas
->sid
);
1966 entry_len
= 40 + sid_len
;
1968 /* nextoffset entry 4 bytes */
1969 SIVAL(entry
,0,entry_len
);
1971 /* then the len of the SID 4 bytes */
1972 SIVAL(entry
,4,sid_len
);
1974 /* unknown data 8 bytes SMB_BIG_UINT */
1975 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
1977 /* the used disk space 8 bytes SMB_BIG_UINT */
1978 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
1980 /* the soft quotas 8 bytes SMB_BIG_UINT */
1981 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
1983 /* the hard quotas 8 bytes SMB_BIG_UINT */
1984 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
1986 /* and now the SID */
1987 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
1990 qt_handle
->tmp_list
= tmp_list
;
1992 /* overwrite the offset of the last entry */
1993 SIVAL(entry
-entry_len
,0,0);
1995 data_len
= 4+qt_len
;
1996 /* overwrite the params quota_data_len */
1997 SIVAL(params
,0,data_len
);
2001 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2003 /* unknown 4 bytes IVAL(pdata,0) */
2005 if (data_count
< 8) {
2006 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2007 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2010 sid_len
= IVAL(pdata
,4);
2012 if (data_count
< 8+sid_len
) {
2013 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8+sid_len
));
2014 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2017 data_len
= 4+40+sid_len
;
2019 if (max_data_count
< data_len
) {
2020 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2021 max_data_count
, data_len
));
2023 SIVAL(params
,0,data_len
);
2025 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2029 sid_parse(pdata
+8,sid_len
,&sid
);
2032 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2035 * we have to return zero's in all fields
2036 * instead of returning an error here
2041 /* Realloc the size of parameters and data we will return */
2043 params
= nttrans_realloc(ppparams
, param_len
);
2045 return ERROR_DOS(ERRDOS
,ERRnomem
);
2047 pdata
= nttrans_realloc(ppdata
, data_len
);
2049 return ERROR_DOS(ERRDOS
,ERRnomem
);
2053 /* set params Size of returned Quota Data 4 bytes*/
2054 SIVAL(params
,0,data_len
);
2056 /* nextoffset entry 4 bytes */
2059 /* then the len of the SID 4 bytes */
2060 SIVAL(entry
,4,sid_len
);
2062 /* unknown data 8 bytes SMB_BIG_UINT */
2063 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2065 /* the used disk space 8 bytes SMB_BIG_UINT */
2066 SBIG_UINT(entry
,16,qt
.usedspace
);
2068 /* the soft quotas 8 bytes SMB_BIG_UINT */
2069 SBIG_UINT(entry
,24,qt
.softlim
);
2071 /* the hard quotas 8 bytes SMB_BIG_UINT */
2072 SBIG_UINT(entry
,32,qt
.hardlim
);
2074 /* and now the SID */
2075 sid_linearize(entry
+40, sid_len
, &sid
);
2080 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2081 return ERROR_DOS(ERRSRV
,ERRerror
);
2085 send_nt_replies(inbuf
, outbuf
, bufsize
, nt_status
, params
, param_len
, pdata
, data_len
);
2090 /****************************************************************************
2091 Reply to set user quota
2092 ****************************************************************************/
2094 static int call_nt_transact_set_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2095 char **ppsetup
, uint32 setup_count
,
2096 char **ppparams
, uint32 parameter_count
,
2097 char **ppdata
, uint32 data_count
)
2099 char *params
= *ppparams
;
2100 char *pdata
= *ppdata
;
2101 int data_len
=0,param_len
=0;
2102 SMB_NTQUOTA_STRUCT qt
;
2105 files_struct
*fsp
= NULL
;
2110 if (conn
->admin_user
!= True
) {
2111 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2112 lp_servicename(SNUM(conn
)),conn
->user
));
2113 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2117 * Ensure minimum number of parameters sent.
2120 if (parameter_count
< 2) {
2121 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2122 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2125 /* maybe we can check the quota_fnum */
2126 fsp
= file_fsp(params
,0);
2127 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2128 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2129 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2132 if (data_count
< 40) {
2133 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2134 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2137 /* offset to next quota record.
2138 * 4 bytes IVAL(pdata,0)
2143 sid_len
= IVAL(pdata
,4);
2145 if (data_count
< 40+sid_len
) {
2146 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40+sid_len
));
2147 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2150 /* unknown 8 bytes in pdata
2151 * maybe its the change time in NTTIME
2154 /* the used space 8 bytes (SMB_BIG_UINT)*/
2155 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2156 #ifdef LARGE_SMB_OFF_T
2157 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2158 #else /* LARGE_SMB_OFF_T */
2159 if ((IVAL(pdata
,20) != 0)&&
2160 ((qt
.usedspace
!= 0xFFFFFFFF)||
2161 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2162 /* more than 32 bits? */
2163 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2165 #endif /* LARGE_SMB_OFF_T */
2167 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2168 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2169 #ifdef LARGE_SMB_OFF_T
2170 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2171 #else /* LARGE_SMB_OFF_T */
2172 if ((IVAL(pdata
,28) != 0)&&
2173 ((qt
.softlim
!= 0xFFFFFFFF)||
2174 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2175 /* more than 32 bits? */
2176 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2178 #endif /* LARGE_SMB_OFF_T */
2180 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2181 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2182 #ifdef LARGE_SMB_OFF_T
2183 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2184 #else /* LARGE_SMB_OFF_T */
2185 if ((IVAL(pdata
,36) != 0)&&
2186 ((qt
.hardlim
!= 0xFFFFFFFF)||
2187 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2188 /* more than 32 bits? */
2189 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2191 #endif /* LARGE_SMB_OFF_T */
2193 sid_parse(pdata
+40,sid_len
,&sid
);
2194 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid
)));
2196 /* 44 unknown bytes left... */
2198 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2199 return ERROR_DOS(ERRSRV
,ERRerror
);
2202 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, pdata
, data_len
);
2206 #endif /* HAVE_SYS_QUOTAS */
2208 /****************************************************************************
2209 Reply to a SMBNTtrans.
2210 ****************************************************************************/
2212 int reply_nttrans(connection_struct
*conn
,
2213 char *inbuf
,char *outbuf
,int length
,int bufsize
)
2216 #if 0 /* Not used. */
2217 uint16 max_setup_count
= CVAL(inbuf
, smb_nt_MaxSetupCount
);
2218 uint32 max_parameter_count
= IVAL(inbuf
, smb_nt_MaxParameterCount
);
2219 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
2220 #endif /* Not used. */
2221 uint32 total_parameter_count
= IVAL(inbuf
, smb_nt_TotalParameterCount
);
2222 uint32 total_data_count
= IVAL(inbuf
, smb_nt_TotalDataCount
);
2223 uint32 parameter_count
= IVAL(inbuf
,smb_nt_ParameterCount
);
2224 uint32 parameter_offset
= IVAL(inbuf
,smb_nt_ParameterOffset
);
2225 uint32 data_count
= IVAL(inbuf
,smb_nt_DataCount
);
2226 uint32 data_offset
= IVAL(inbuf
,smb_nt_DataOffset
);
2227 uint16 setup_count
= 2*CVAL(inbuf
,smb_nt_SetupCount
); /* setup count is in *words* */
2228 uint16 function_code
= SVAL( inbuf
, smb_nt_Function
);
2229 char *params
= NULL
, *data
= NULL
, *setup
= NULL
;
2230 uint32 num_params_sofar
, num_data_sofar
;
2231 START_PROFILE(SMBnttrans
);
2233 if(global_oplock_break
&&
2234 ((function_code
== NT_TRANSACT_CREATE
) ||
2235 (function_code
== NT_TRANSACT_RENAME
))) {
2237 * Queue this open message as we are the process of an oplock break.
2240 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2241 due to being in oplock break state.\n", (unsigned int)function_code
));
2243 push_oplock_pending_smb_message( inbuf
, length
);
2244 END_PROFILE(SMBnttrans
);
2248 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2249 END_PROFILE(SMBnttrans
);
2250 return ERROR_DOS(ERRSRV
,ERRaccess
);
2253 outsize
= set_message(outbuf
,0,0,True
);
2256 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2257 * Ensure this is so as a sanity check.
2260 if(CVAL(inbuf
, smb_wct
) != 19 + (setup_count
/2)) {
2261 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2262 CVAL(inbuf
, smb_wct
), 19 + (setup_count
/2)));
2266 /* Allocate the space for the setup, the maximum needed parameters and data */
2269 setup
= (char *)malloc(setup_count
);
2270 if (total_parameter_count
> 0)
2271 params
= (char *)malloc(total_parameter_count
);
2272 if (total_data_count
> 0)
2273 data
= (char *)malloc(total_data_count
);
2275 if ((total_parameter_count
&& !params
) || (total_data_count
&& !data
) ||
2276 (setup_count
&& !setup
)) {
2280 DEBUG(0,("reply_nttrans : Out of memory\n"));
2281 END_PROFILE(SMBnttrans
);
2282 return ERROR_DOS(ERRDOS
,ERRnomem
);
2285 /* Copy the param and data bytes sent with this request into the params buffer */
2286 num_params_sofar
= parameter_count
;
2287 num_data_sofar
= data_count
;
2289 if (parameter_count
> total_parameter_count
|| data_count
> total_data_count
)
2293 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count
));
2294 if ((smb_nt_SetupStart
+ setup_count
< smb_nt_SetupStart
) ||
2295 (smb_nt_SetupStart
+ setup_count
< setup_count
))
2297 if (smb_nt_SetupStart
+ setup_count
> length
)
2300 memcpy( setup
, &inbuf
[smb_nt_SetupStart
], setup_count
);
2301 dump_data(10, setup
, setup_count
);
2304 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count
));
2305 if ((parameter_offset
+ parameter_count
< parameter_offset
) ||
2306 (parameter_offset
+ parameter_count
< parameter_count
))
2308 if (smb_base(inbuf
) + parameter_offset
+ parameter_count
> inbuf
+ length
)
2311 memcpy( params
, smb_base(inbuf
) + parameter_offset
, parameter_count
);
2312 dump_data(10, params
, parameter_count
);
2315 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count
));
2316 if ((data_offset
+ data_count
< data_offset
) || (data_offset
+ data_count
< data_count
))
2318 if (smb_base(inbuf
) + data_offset
+ data_count
> inbuf
+ length
)
2321 memcpy( data
, smb_base(inbuf
) + data_offset
, data_count
);
2322 dump_data(10, data
, data_count
);
2325 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2327 if(num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2328 /* We need to send an interim response then receive the rest
2329 of the parameter/data bytes */
2330 outsize
= set_message(outbuf
,0,0,True
);
2331 if (!send_smb(smbd_server_fd(),outbuf
))
2332 exit_server("reply_nttrans: send_smb failed.");
2334 while( num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2336 uint32 parameter_displacement
;
2337 uint32 data_displacement
;
2339 ret
= receive_next_smb(inbuf
,bufsize
,SMB_SECONDARY_WAIT
);
2341 if((ret
&& (CVAL(inbuf
, smb_com
) != SMBnttranss
)) || !ret
) {
2342 outsize
= set_message(outbuf
,0,0,True
);
2344 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2346 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2347 (smb_read_error
== READ_ERROR
) ? "error" : "timeout" ));
2352 /* Revise total_params and total_data in case they have changed downwards */
2353 if (IVAL(inbuf
, smb_nts_TotalParameterCount
) < total_parameter_count
)
2354 total_parameter_count
= IVAL(inbuf
, smb_nts_TotalParameterCount
);
2355 if (IVAL(inbuf
, smb_nts_TotalDataCount
) < total_data_count
)
2356 total_data_count
= IVAL(inbuf
, smb_nts_TotalDataCount
);
2358 parameter_count
= IVAL(inbuf
,smb_nts_ParameterCount
);
2359 parameter_offset
= IVAL(inbuf
, smb_nts_ParameterOffset
);
2360 parameter_displacement
= IVAL(inbuf
, smb_nts_ParameterDisplacement
);
2361 num_params_sofar
+= parameter_count
;
2363 data_count
= IVAL(inbuf
, smb_nts_DataCount
);
2364 data_displacement
= IVAL(inbuf
, smb_nts_DataDisplacement
);
2365 data_offset
= IVAL(inbuf
, smb_nts_DataOffset
);
2366 num_data_sofar
+= data_count
;
2368 if (num_params_sofar
> total_parameter_count
|| num_data_sofar
> total_data_count
) {
2369 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2373 if (parameter_count
) {
2374 if (parameter_displacement
+ parameter_count
>= total_parameter_count
)
2376 if ((parameter_displacement
+ parameter_count
< parameter_displacement
) ||
2377 (parameter_displacement
+ parameter_count
< parameter_count
))
2379 if (smb_base(inbuf
) + parameter_offset
+ parameter_count
>= inbuf
+ bufsize
)
2381 if (parameter_displacement
+ params
< params
)
2384 memcpy( ¶ms
[parameter_displacement
], smb_base(inbuf
) + parameter_offset
, parameter_count
);
2388 if (data_displacement
+ data_count
>= total_data_count
)
2390 if ((data_displacement
+ data_count
< data_displacement
) ||
2391 (data_displacement
+ data_count
< data_count
))
2393 if (smb_base(inbuf
) + data_offset
+ data_count
>= inbuf
+ bufsize
)
2395 if (data_displacement
+ data
< data
)
2398 memcpy( &data
[data_displacement
], smb_base(inbuf
)+ data_offset
, data_count
);
2403 if (Protocol
>= PROTOCOL_NT1
)
2404 SSVAL(outbuf
,smb_flg2
,SVAL(outbuf
,smb_flg2
) | FLAGS2_IS_LONG_NAME
);
2406 /* Now we must call the relevant NT_TRANS function */
2407 switch(function_code
) {
2408 case NT_TRANSACT_CREATE
:
2409 START_PROFILE_NESTED(NT_transact_create
);
2410 outsize
= call_nt_transact_create(conn
, inbuf
, outbuf
,
2412 &setup
, setup_count
,
2413 ¶ms
, total_parameter_count
,
2414 &data
, total_data_count
);
2415 END_PROFILE_NESTED(NT_transact_create
);
2417 case NT_TRANSACT_IOCTL
:
2418 START_PROFILE_NESTED(NT_transact_ioctl
);
2419 outsize
= call_nt_transact_ioctl(conn
, inbuf
, outbuf
,
2421 &setup
, setup_count
,
2422 ¶ms
, total_parameter_count
,
2423 &data
, total_data_count
);
2424 END_PROFILE_NESTED(NT_transact_ioctl
);
2426 case NT_TRANSACT_SET_SECURITY_DESC
:
2427 START_PROFILE_NESTED(NT_transact_set_security_desc
);
2428 outsize
= call_nt_transact_set_security_desc(conn
, inbuf
, outbuf
,
2430 &setup
, setup_count
,
2431 ¶ms
, total_parameter_count
,
2432 &data
, total_data_count
);
2433 END_PROFILE_NESTED(NT_transact_set_security_desc
);
2435 case NT_TRANSACT_NOTIFY_CHANGE
:
2436 START_PROFILE_NESTED(NT_transact_notify_change
);
2437 outsize
= call_nt_transact_notify_change(conn
, inbuf
, outbuf
,
2439 &setup
, setup_count
,
2440 ¶ms
, total_parameter_count
,
2441 &data
, total_data_count
);
2442 END_PROFILE_NESTED(NT_transact_notify_change
);
2444 case NT_TRANSACT_RENAME
:
2445 START_PROFILE_NESTED(NT_transact_rename
);
2446 outsize
= call_nt_transact_rename(conn
, inbuf
, outbuf
,
2448 &setup
, setup_count
,
2449 ¶ms
, total_parameter_count
,
2450 &data
, total_data_count
);
2451 END_PROFILE_NESTED(NT_transact_rename
);
2454 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2455 START_PROFILE_NESTED(NT_transact_query_security_desc
);
2456 outsize
= call_nt_transact_query_security_desc(conn
, inbuf
, outbuf
,
2458 &setup
, setup_count
,
2459 ¶ms
, total_parameter_count
,
2460 &data
, total_data_count
);
2461 END_PROFILE_NESTED(NT_transact_query_security_desc
);
2463 #ifdef HAVE_SYS_QUOTAS
2464 case NT_TRANSACT_GET_USER_QUOTA
:
2465 START_PROFILE_NESTED(NT_transact_get_user_quota
);
2466 outsize
= call_nt_transact_get_user_quota(conn
, inbuf
, outbuf
,
2468 &setup
, setup_count
,
2469 ¶ms
, total_parameter_count
,
2470 &data
, total_data_count
);
2471 END_PROFILE_NESTED(NT_transact_get_user_quota
);
2473 case NT_TRANSACT_SET_USER_QUOTA
:
2474 START_PROFILE_NESTED(NT_transact_set_user_quota
);
2475 outsize
= call_nt_transact_set_user_quota(conn
, inbuf
, outbuf
,
2477 &setup
, setup_count
,
2478 ¶ms
, total_parameter_count
,
2479 &data
, total_data_count
);
2480 END_PROFILE_NESTED(NT_transact_set_user_quota
);
2482 #endif /* HAVE_SYS_QUOTAS */
2484 /* Error in request */
2485 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code
));
2489 END_PROFILE(SMBnttrans
);
2490 srv_signing_trans_stop();
2491 return ERROR_DOS(ERRSRV
,ERRerror
);
2494 /* As we do not know how many data packets will need to be
2495 returned here the various call_nt_transact_xxxx calls
2496 must send their own. Thus a call_nt_transact_xxxx routine only
2497 returns a value other than -1 when it wants to send
2501 srv_signing_trans_stop();
2506 END_PROFILE(SMBnttrans
);
2507 return outsize
; /* If a correct response was needed the call_nt_transact_xxxx
2508 calls have already sent it. If outsize != -1 then it is
2509 returning an error packet. */
2513 srv_signing_trans_stop();
2517 END_PROFILE(SMBnttrans
);
2518 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);