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
)
527 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
,&status
);
528 if (!NT_STATUS_IS_OK(status
))
529 return ERROR_NT(status
);
531 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
535 * Deal with pipe return.
538 set_message(outbuf
,34,0,True
);
540 p
= outbuf
+ smb_vwv2
;
544 SIVAL(p
,0,FILE_WAS_OPENED
);
547 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
550 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
552 SSVAL(p
,2, 0x5FF); /* ? */
554 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
556 return chain_reply(inbuf
,outbuf
,length
,bufsize
);
559 /****************************************************************************
560 Reply to an NT create and X call.
561 ****************************************************************************/
563 int reply_ntcreate_and_X(connection_struct
*conn
,
564 char *inbuf
,char *outbuf
,int length
,int bufsize
)
568 enum FAKE_FILE_TYPE fake_file_type
= FAKE_FILE_TYPE_NONE
;
569 uint32 flags
= IVAL(inbuf
,smb_ntcreate_Flags
);
570 uint32 desired_access
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
571 uint32 file_attributes
= IVAL(inbuf
,smb_ntcreate_FileAttributes
);
572 uint32 share_access
= IVAL(inbuf
,smb_ntcreate_ShareAccess
);
573 uint32 create_disposition
= IVAL(inbuf
,smb_ntcreate_CreateDisposition
);
574 uint32 create_options
= IVAL(inbuf
,smb_ntcreate_CreateOptions
);
575 uint16 root_dir_fid
= (uint16
)IVAL(inbuf
,smb_ntcreate_RootDirectoryFid
);
576 SMB_BIG_UINT allocation_size
= 0;
579 int smb_attr
= (file_attributes
& SAMBA_ATTRIBUTES_MASK
);
580 /* Breakout the oplock request bits so we can set the
581 reply bits separately. */
582 int oplock_request
= 0;
585 SMB_OFF_T file_len
= 0;
586 SMB_STRUCT_STAT sbuf
;
588 BOOL bad_path
= False
;
589 files_struct
*fsp
=NULL
;
592 BOOL extended_oplock_granted
= False
;
595 START_PROFILE(SMBntcreateX
);
597 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
598 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
599 create_options = 0x%x root_dir_fid = 0x%x\n", flags
, desired_access
, file_attributes
,
600 share_access
, create_disposition
,
601 create_options
, root_dir_fid
));
603 /* If it's an IPC, use the pipe handler. */
606 if (lp_nt_pipe_support()) {
607 END_PROFILE(SMBntcreateX
);
608 return do_ntcreate_pipe_open(conn
,inbuf
,outbuf
,length
,bufsize
);
610 END_PROFILE(SMBntcreateX
);
611 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
615 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
616 END_PROFILE(SMBntcreateX
);
617 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
621 * We need to construct the open_and_X ofun value from the
622 * NT values, as that's what our code is structured to accept.
625 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1) {
626 END_PROFILE(SMBntcreateX
);
627 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
634 if(root_dir_fid
!= 0) {
636 * This filename is relative to a directory fid.
638 files_struct
*dir_fsp
= file_fsp(inbuf
,smb_ntcreate_RootDirectoryFid
);
642 END_PROFILE(SMBntcreateX
);
643 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
646 if(!dir_fsp
->is_directory
) {
648 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
,&status
);
649 if (!NT_STATUS_IS_OK(status
)) {
650 END_PROFILE(SMBntcreateX
);
651 return ERROR_NT(status
);
655 * Check to see if this is a mac fork of some kind.
658 if( strchr_m(fname
, ':')) {
659 END_PROFILE(SMBntcreateX
);
660 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
665 we need to handle the case when we get a
666 relative open relative to a file and the
667 pathname is blank - this is a reopen!
668 (hint from demyn plantenberg)
672 END_PROFILE(SMBntcreateX
);
673 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
677 * Copy in the base directory name.
680 pstrcpy( fname
, dir_fsp
->fsp_name
);
681 dir_name_len
= strlen(fname
);
684 * Ensure it ends in a '\'.
687 if(fname
[dir_name_len
-1] != '\\' && fname
[dir_name_len
-1] != '/') {
688 pstrcat(fname
, "\\");
692 srvstr_get_path(inbuf
, &fname
[dir_name_len
], smb_buf(inbuf
), sizeof(fname
)-dir_name_len
, STR_TERMINATE
,&status
);
693 if (!NT_STATUS_IS_OK(status
)) {
694 END_PROFILE(SMBntcreateX
);
695 return ERROR_NT(status
);
698 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
,&status
);
699 if (!NT_STATUS_IS_OK(status
)) {
700 END_PROFILE(SMBntcreateX
);
701 return ERROR_NT(status
);
705 * Check to see if this is a mac fork of some kind.
708 if( strchr_m(fname
, ':')) {
710 #ifdef HAVE_SYS_QUOTAS
711 if ((fake_file_type
=is_fake_file(fname
))!=FAKE_FILE_TYPE_NONE
) {
713 * here we go! support for changing the disk quotas --metze
715 * we need to fake up to open this MAGIC QUOTA file
716 * and return a valid FID
718 * w2k close this file directly after openening
719 * xp also tries a QUERY_FILE_INFO on the file and then close it
723 END_PROFILE(SMBntcreateX
);
724 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
725 #ifdef HAVE_SYS_QUOTAS
732 * Now contruct the smb_open_mode value from the filename,
733 * desired access and the share access.
735 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
737 if((smb_open_mode
= map_share_mode(fname
, create_options
, &desired_access
,
739 file_attributes
)) == -1) {
740 END_PROFILE(SMBntcreateX
);
741 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
744 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
745 if (oplock_request
) {
746 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
750 * Ordinary file or directory.
754 * Check if POSIX semantics are wanted.
757 set_posix_case_semantics(file_attributes
);
759 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
761 unixmode
= unix_mode(conn
,smb_attr
| aARCH
, fname
);
764 * If it's a request for a directory open, deal with it separately.
767 if(create_options
& FILE_DIRECTORY_FILE
) {
770 /* Can't open a temp directory. IFS kit test. */
771 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
772 END_PROFILE(SMBntcreateX
);
773 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
776 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
778 restore_case_semantics(file_attributes
);
781 END_PROFILE(SMBntcreateX
);
782 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
786 * Ordinary file case.
789 /* NB. We have a potential bug here. If we
790 * cause an oplock break to ourselves, then we
791 * could end up processing filename related
792 * SMB requests whilst we await the oplock
793 * break response. As we may have changed the
794 * filename case semantics to be POSIX-like,
795 * this could mean a filename request could
796 * fail when it should succeed. This is a rare
797 * condition, but eventually we must arrange
798 * to restore the correct case semantics
799 * before issuing an oplock break request to
800 * our client. JRA. */
802 if (fake_file_type
==FAKE_FILE_TYPE_NONE
) {
803 fsp
= open_file_shared1(conn
,fname
,&sbuf
,
806 smb_ofun
,unixmode
, oplock_request
,
809 /* to open a fake_file --metze */
810 fsp
= open_fake_file_shared1(fake_file_type
,conn
,fname
,&sbuf
,
813 smb_ofun
,unixmode
, oplock_request
,
818 /* We cheat here. There are two cases we
819 * care about. One is a directory rename,
820 * where the NT client will attempt to
821 * open the source directory for
822 * DELETE access. Note that when the
823 * NT client does this it does *not*
824 * set the directory bit in the
825 * request packet. This is translated
826 * into a read/write open
827 * request. POSIX states that any open
828 * for write request on a directory
829 * will generate an EISDIR error, so
830 * we can catch this here and open a
831 * pseudo handle that is flagged as a
832 * directory. The second is an open
833 * for a permissions read only, which
834 * we handle in the open_file_stat case. JRA.
837 if(errno
== EISDIR
) {
840 * Fail the open if it was explicitly a non-directory file.
843 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
844 restore_case_semantics(file_attributes
);
845 SSVAL(outbuf
, smb_flg2
,
846 SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
847 END_PROFILE(SMBntcreateX
);
848 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
852 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
855 restore_case_semantics(file_attributes
);
856 END_PROFILE(SMBntcreateX
);
857 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
861 restore_case_semantics(file_attributes
);
862 END_PROFILE(SMBntcreateX
);
863 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
868 restore_case_semantics(file_attributes
);
870 file_len
= sbuf
.st_size
;
871 fmode
= dos_mode(conn
,fname
,&sbuf
);
873 fmode
= FILE_ATTRIBUTE_NORMAL
;
874 if (!fsp
->is_directory
&& (fmode
& aDIR
)) {
875 close_file(fsp
,False
);
876 END_PROFILE(SMBntcreateX
);
877 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
880 /* Save the requested allocation size. */
881 allocation_size
= (SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
);
882 #ifdef LARGE_SMB_OFF_T
883 allocation_size
|= (((SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
+ 4)) << 32);
885 if (allocation_size
&& (allocation_size
> (SMB_BIG_UINT
)file_len
)) {
886 fsp
->initial_allocation_size
= SMB_ROUNDUP(allocation_size
,SMB_ROUNDUP_ALLOCATION_SIZE
);
887 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
888 close_file(fsp
,False
);
889 END_PROFILE(SMBntcreateX
);
890 return ERROR_NT(NT_STATUS_DISK_FULL
);
893 fsp
->initial_allocation_size
= SMB_ROUNDUP(((SMB_BIG_UINT
)file_len
),SMB_ROUNDUP_ALLOCATION_SIZE
);
897 * If the caller set the extended oplock request bit
898 * and we granted one (by whatever means) - set the
899 * correct bit for extended oplock reply.
902 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
903 extended_oplock_granted
= True
;
905 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
906 extended_oplock_granted
= True
;
909 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
910 set_message(outbuf
,42,0,True
);
912 set_message(outbuf
,34,0,True
);
915 p
= outbuf
+ smb_vwv2
;
918 * Currently as we don't support level II oplocks we just report
919 * exclusive & batch here.
922 if (extended_oplock_granted
) {
923 if (flags
& REQUEST_BATCH_OPLOCK
) {
924 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
926 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
928 } else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
)) {
929 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
931 SCVAL(p
,0,NO_OPLOCK_RETURN
);
935 SSVAL(p
,0,fsp
->fnum
);
937 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
938 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
940 SIVAL(p
,0,smb_action
);
944 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
946 if (lp_dos_filetime_resolution(SNUM(conn
))) {
953 put_long_date(p
,c_time
);
955 put_long_date(p
,sbuf
.st_atime
); /* access time */
957 put_long_date(p
,sbuf
.st_mtime
); /* write time */
959 put_long_date(p
,sbuf
.st_mtime
); /* change time */
961 SIVAL(p
,0,fmode
); /* File Attributes. */
963 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
965 SOFF_T(p
,0,file_len
);
967 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
969 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
971 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
972 END_PROFILE(SMBntcreateX
);
976 /****************************************************************************
977 Reply to a NT_TRANSACT_CREATE call to open a pipe.
978 ****************************************************************************/
980 static int do_nt_transact_create_pipe( connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
981 char **ppsetup
, uint32 setup_count
,
982 char **ppparams
, uint32 parameter_count
,
983 char **ppdata
, uint32 data_count
)
986 char *params
= *ppparams
;
993 * Ensure minimum number of parameters sent.
996 if(parameter_count
< 54) {
997 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
998 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1001 srvstr_pull(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
);
1002 status
= check_path_syntax(fname
);
1003 if (!NT_STATUS_IS_OK(status
)) {
1004 return ERROR_NT(status
);
1007 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
1010 /* Realloc the size of parameters and data we will return */
1011 params
= nttrans_realloc(ppparams
, 69);
1013 return ERROR_DOS(ERRDOS
,ERRnomem
);
1016 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1021 SIVAL(p
,0,FILE_WAS_OPENED
);
1025 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
1028 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
1030 SSVAL(p
,2, 0x5FF); /* ? */
1032 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
1034 /* Send the required number of replies */
1035 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1040 /****************************************************************************
1041 Internal fn to set security descriptors.
1042 ****************************************************************************/
1044 static NTSTATUS
set_sd(files_struct
*fsp
, char *data
, uint32 sd_len
, uint32 security_info_sent
)
1047 SEC_DESC
*psd
= NULL
;
1048 TALLOC_CTX
*mem_ctx
;
1052 return NT_STATUS_OK
;
1056 * Init the parse struct we will unmarshall from.
1059 if ((mem_ctx
= talloc_init("set_sd")) == NULL
) {
1060 DEBUG(0,("set_sd: talloc_init failed.\n"));
1061 return NT_STATUS_NO_MEMORY
;
1064 prs_init(&pd
, 0, mem_ctx
, UNMARSHALL
);
1067 * Setup the prs_struct to point at the memory we just
1071 prs_give_memory( &pd
, data
, sd_len
, False
);
1074 * Finally, unmarshall from the data buffer.
1077 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1078 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1080 * Return access denied for want of a better error message..
1082 talloc_destroy(mem_ctx
);
1083 return NT_STATUS_NO_MEMORY
;
1086 if (psd
->off_owner_sid
==0)
1087 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
1088 if (psd
->off_grp_sid
==0)
1089 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
1090 if (psd
->off_sacl
==0)
1091 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
1092 if (psd
->off_dacl
==0)
1093 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
1095 ret
= SMB_VFS_FSET_NT_ACL( fsp
, fsp
->fd
, security_info_sent
, psd
);
1098 talloc_destroy(mem_ctx
);
1099 return NT_STATUS_ACCESS_DENIED
;
1102 talloc_destroy(mem_ctx
);
1104 return NT_STATUS_OK
;
1107 /****************************************************************************
1108 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1109 ****************************************************************************/
1111 static int call_nt_transact_create(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1112 char **ppsetup
, uint32 setup_count
,
1113 char **ppparams
, uint32 parameter_count
,
1114 char **ppdata
, uint32 data_count
)
1117 char *params
= *ppparams
;
1118 char *data
= *ppdata
;
1119 /* Breakout the oplock request bits so we can set the reply bits separately. */
1120 int oplock_request
= 0;
1122 int fmode
=0,rmode
=0;
1123 SMB_OFF_T file_len
= 0;
1124 SMB_STRUCT_STAT sbuf
;
1126 BOOL bad_path
= False
;
1127 files_struct
*fsp
= NULL
;
1129 BOOL extended_oplock_granted
= False
;
1131 uint32 desired_access
;
1132 uint32 file_attributes
;
1133 uint32 share_access
;
1134 uint32 create_disposition
;
1135 uint32 create_options
;
1137 uint16 root_dir_fid
;
1138 SMB_BIG_UINT allocation_size
= 0;
1145 DEBUG(5,("call_nt_transact_create\n"));
1148 * If it's an IPC, use the pipe handler.
1152 if (lp_nt_pipe_support())
1153 return do_nt_transact_create_pipe(conn
, inbuf
, outbuf
, length
,
1155 ppsetup
, setup_count
,
1156 ppparams
, parameter_count
,
1157 ppdata
, data_count
);
1159 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1163 * Ensure minimum number of parameters sent.
1166 if(parameter_count
< 54) {
1167 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1168 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1171 flags
= IVAL(params
,0);
1172 desired_access
= IVAL(params
,8);
1173 file_attributes
= IVAL(params
,20);
1174 share_access
= IVAL(params
,24);
1175 create_disposition
= IVAL(params
,28);
1176 create_options
= IVAL(params
,32);
1177 sd_len
= IVAL(params
,36);
1178 root_dir_fid
= (uint16
)IVAL(params
,4);
1179 smb_attr
= (file_attributes
& SAMBA_ATTRIBUTES_MASK
);
1181 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
1182 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1186 * We need to construct the open_and_X ofun value from the
1187 * NT values, as that's what our code is structured to accept.
1190 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1)
1191 return ERROR_DOS(ERRDOS
,ERRbadmem
);
1194 * Get the file name.
1197 if(root_dir_fid
!= 0) {
1199 * This filename is relative to a directory fid.
1202 files_struct
*dir_fsp
= file_fsp(params
,4);
1203 size_t dir_name_len
;
1206 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1208 if(!dir_fsp
->is_directory
) {
1210 srvstr_pull(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
);
1211 nt_status
= check_path_syntax(fname
);
1212 if (!NT_STATUS_IS_OK(nt_status
)) {
1213 return ERROR_NT(nt_status
);
1217 * Check to see if this is a mac fork of some kind.
1220 if( strchr_m(fname
, ':'))
1221 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1223 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1227 * Copy in the base directory name.
1230 pstrcpy( fname
, dir_fsp
->fsp_name
);
1231 dir_name_len
= strlen(fname
);
1234 * Ensure it ends in a '\'.
1237 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
1238 pstrcat(fname
, "\\");
1242 srvstr_pull(inbuf
, &fname
[dir_name_len
], params
+53, sizeof(fname
)-dir_name_len
,
1243 parameter_count
-53, STR_TERMINATE
);
1244 nt_status
= check_path_syntax(fname
);
1245 if (!NT_STATUS_IS_OK(nt_status
)) {
1246 return ERROR_NT(nt_status
);
1249 srvstr_pull(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
);
1250 nt_status
= check_path_syntax(fname
);
1251 if (!NT_STATUS_IS_OK(nt_status
)) {
1252 return ERROR_NT(nt_status
);
1256 * Check to see if this is a mac fork of some kind.
1259 if( strchr_m(fname
, ':'))
1260 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1264 * Now contruct the smb_open_mode value from the desired access
1265 * and the share access.
1268 if((smb_open_mode
= map_share_mode( fname
, create_options
, &desired_access
,
1269 share_access
, file_attributes
)) == -1)
1270 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1272 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1273 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1276 * Check if POSIX semantics are wanted.
1279 set_posix_case_semantics(file_attributes
);
1281 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
1283 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
1285 unixmode
= unix_mode(conn
,smb_attr
| aARCH
, fname
);
1288 * If it's a request for a directory open, deal with it separately.
1291 if(create_options
& FILE_DIRECTORY_FILE
) {
1293 /* Can't open a temp directory. IFS kit test. */
1294 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
1295 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1301 * We will get a create directory here if the Win32
1302 * app specified a security descriptor in the
1303 * CreateDirectory() call.
1306 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
1309 restore_case_semantics(file_attributes
);
1310 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1316 * Ordinary file case.
1319 fsp
= open_file_shared1(conn
,fname
,&sbuf
,desired_access
,
1320 smb_open_mode
,smb_ofun
,unixmode
,
1321 oplock_request
,&rmode
,&smb_action
);
1325 if(errno
== EISDIR
) {
1328 * Fail the open if it was explicitly a non-directory file.
1331 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
1332 restore_case_semantics(file_attributes
);
1333 SSVAL(outbuf
, smb_flg2
, SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
1334 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
1338 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, unixmode
, &smb_action
);
1341 restore_case_semantics(file_attributes
);
1342 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1345 restore_case_semantics(file_attributes
);
1346 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1350 file_len
= sbuf
.st_size
;
1351 fmode
= dos_mode(conn
,fname
,&sbuf
);
1353 fmode
= FILE_ATTRIBUTE_NORMAL
;
1356 close_file(fsp
,False
);
1357 restore_case_semantics(file_attributes
);
1358 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1362 * If the caller set the extended oplock request bit
1363 * and we granted one (by whatever means) - set the
1364 * correct bit for extended oplock reply.
1367 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
1368 extended_oplock_granted
= True
;
1370 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
1371 extended_oplock_granted
= True
;
1375 * Now try and apply the desired SD.
1378 if (sd_len
&& !NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, sd_len
, ALL_SECURITY_INFORMATION
))) {
1379 close_file(fsp
,False
);
1380 restore_case_semantics(file_attributes
);
1381 return ERROR_NT(nt_status
);
1384 restore_case_semantics(file_attributes
);
1386 /* Save the requested allocation size. */
1387 allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
1388 #ifdef LARGE_SMB_OFF_T
1389 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
1391 if (allocation_size
&& (allocation_size
> file_len
)) {
1392 fsp
->initial_allocation_size
= SMB_ROUNDUP(allocation_size
,SMB_ROUNDUP_ALLOCATION_SIZE
);
1393 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
1394 close_file(fsp
,False
);
1395 return ERROR_NT(NT_STATUS_DISK_FULL
);
1398 fsp
->initial_allocation_size
= SMB_ROUNDUP(((SMB_BIG_UINT
)file_len
),SMB_ROUNDUP_ALLOCATION_SIZE
);
1401 /* Realloc the size of parameters and data we will return */
1402 params
= nttrans_realloc(ppparams
, 69);
1404 return ERROR_DOS(ERRDOS
,ERRnomem
);
1407 if (extended_oplock_granted
)
1408 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
1409 else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
))
1410 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
1412 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1415 SSVAL(p
,0,fsp
->fnum
);
1417 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
1418 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1420 SIVAL(p
,0,smb_action
);
1424 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1426 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1428 sbuf
.st_atime
&= ~1;
1429 sbuf
.st_mtime
&= ~1;
1430 sbuf
.st_mtime
&= ~1;
1433 put_long_date(p
,c_time
);
1435 put_long_date(p
,sbuf
.st_atime
); /* access time */
1437 put_long_date(p
,sbuf
.st_mtime
); /* write time */
1439 put_long_date(p
,sbuf
.st_mtime
); /* change time */
1441 SIVAL(p
,0,fmode
); /* File Attributes. */
1443 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
1445 SOFF_T(p
,0,file_len
);
1447 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname
));
1449 /* Send the required number of replies */
1450 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1455 /****************************************************************************
1456 Reply to a NT CANCEL request.
1457 ****************************************************************************/
1459 int reply_ntcancel(connection_struct
*conn
,
1460 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1463 * Go through and cancel any pending change notifies.
1466 int mid
= SVAL(inbuf
,smb_mid
);
1467 START_PROFILE(SMBntcancel
);
1468 remove_pending_change_notify_requests_by_mid(mid
);
1469 remove_pending_lock_requests_by_mid(mid
);
1470 srv_cancel_sign_response(mid
);
1472 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid
));
1474 END_PROFILE(SMBntcancel
);
1478 /****************************************************************************
1479 Reply to an unsolicited SMBNTtranss - just ignore it!
1480 ****************************************************************************/
1482 int reply_nttranss(connection_struct
*conn
,
1483 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1485 START_PROFILE(SMBnttranss
);
1486 DEBUG(4,("Ignoring nttranss of length %d\n",length
));
1487 END_PROFILE(SMBnttranss
);
1491 /****************************************************************************
1492 Reply to a notify change - queue the request and
1493 don't allow a directory to be opened.
1494 ****************************************************************************/
1496 static int call_nt_transact_notify_change(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1497 char **ppsetup
, uint32 setup_count
,
1498 char **ppparams
, uint32 parameter_count
,
1499 char **ppdata
, uint32 data_count
)
1501 char *setup
= *ppsetup
;
1506 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1508 fsp
= file_fsp(setup
,4);
1509 flags
= IVAL(setup
, 0);
1511 DEBUG(3,("call_nt_transact_notify_change\n"));
1514 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1516 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
))
1517 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1519 if (!change_notify_set(inbuf
, fsp
, conn
, flags
))
1520 return(UNIXERROR(ERRDOS
,ERRbadfid
));
1522 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1523 name = %s\n", fsp
->fsp_name
));
1528 /****************************************************************************
1529 Reply to an NT transact rename command.
1530 ****************************************************************************/
1532 static int call_nt_transact_rename(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1533 char **ppsetup
, uint32 setup_count
,
1534 char **ppparams
, uint32 parameter_count
,
1535 char **ppdata
, uint32 data_count
)
1537 char *params
= *ppparams
;
1539 files_struct
*fsp
= NULL
;
1540 BOOL replace_if_exists
= False
;
1543 if(parameter_count
< 4)
1544 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1546 fsp
= file_fsp(params
, 0);
1547 replace_if_exists
= (SVAL(params
,2) & RENAME_REPLACE_IF_EXISTS
) ? True
: False
;
1548 CHECK_FSP(fsp
, conn
);
1549 srvstr_pull(inbuf
, new_name
, params
+4, sizeof(new_name
), -1, STR_TERMINATE
);
1550 status
= check_path_syntax(new_name
);
1551 if (!NT_STATUS_IS_OK(status
)) {
1552 return ERROR_NT(status
);
1555 status
= rename_internals(conn
, fsp
->fsp_name
,
1556 new_name
, replace_if_exists
);
1557 if (!NT_STATUS_IS_OK(status
))
1558 return ERROR_NT(status
);
1561 * Rename was successful.
1563 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1565 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1566 fsp
->fsp_name
, new_name
));
1569 * Win2k needs a changenotify request response before it will
1570 * update after a rename..
1573 process_pending_change_notify_queue((time_t)0);
1578 /******************************************************************************
1579 Fake up a completely empty SD.
1580 *******************************************************************************/
1582 static size_t get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1584 extern DOM_SID global_sid_World
;
1587 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1589 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1596 /****************************************************************************
1597 Reply to query a security descriptor.
1598 ****************************************************************************/
1600 static int call_nt_transact_query_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1601 char **ppsetup
, uint32 setup_count
,
1602 char **ppparams
, uint32 parameter_count
,
1603 char **ppdata
, uint32 data_count
)
1605 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
1606 char *params
= *ppparams
;
1607 char *data
= *ppdata
;
1609 SEC_DESC
*psd
= NULL
;
1611 uint32 security_info_wanted
;
1612 TALLOC_CTX
*mem_ctx
;
1613 files_struct
*fsp
= NULL
;
1615 if(parameter_count
< 8)
1616 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1618 fsp
= file_fsp(params
,0);
1620 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1622 security_info_wanted
= IVAL(params
,4);
1624 DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp
->fsp_name
));
1626 params
= nttrans_realloc(ppparams
, 4);
1628 return ERROR_DOS(ERRDOS
,ERRnomem
);
1630 if ((mem_ctx
= talloc_init("call_nt_transact_query_security_desc")) == NULL
) {
1631 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1632 return ERROR_DOS(ERRDOS
,ERRnomem
);
1636 * Get the permissions to return.
1639 if (!lp_nt_acl_support(SNUM(conn
)))
1640 sd_size
= get_null_nt_acl(mem_ctx
, &psd
);
1642 sd_size
= SMB_VFS_FGET_NT_ACL(fsp
, fsp
->fd
, security_info_wanted
, &psd
);
1645 talloc_destroy(mem_ctx
);
1646 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1649 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size
));
1651 SIVAL(params
,0,(uint32
)sd_size
);
1653 if(max_data_count
< sd_size
) {
1655 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_BUFFER_TOO_SMALL
,
1656 params
, 4, *ppdata
, 0);
1657 talloc_destroy(mem_ctx
);
1662 * Allocate the data we will point this at.
1665 data
= nttrans_realloc(ppdata
, sd_size
);
1667 talloc_destroy(mem_ctx
);
1668 return ERROR_DOS(ERRDOS
,ERRnomem
);
1672 * Init the parse struct we will marshall into.
1675 prs_init(&pd
, 0, mem_ctx
, MARSHALL
);
1678 * Setup the prs_struct to point at the memory we just
1682 prs_give_memory( &pd
, data
, (uint32
)sd_size
, False
);
1685 * Finally, linearize into the outgoing buffer.
1688 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1689 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
1690 security descriptor.\n"));
1692 * Return access denied for want of a better error message..
1694 talloc_destroy(mem_ctx
);
1695 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1699 * Now we can delete the security descriptor.
1702 talloc_destroy(mem_ctx
);
1704 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1708 /****************************************************************************
1709 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1710 ****************************************************************************/
1712 static int call_nt_transact_set_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1713 char **ppsetup
, uint32 setup_count
,
1714 char **ppparams
, uint32 parameter_count
,
1715 char **ppdata
, uint32 data_count
)
1717 char *params
= *ppparams
;
1718 char *data
= *ppdata
;
1719 files_struct
*fsp
= NULL
;
1720 uint32 security_info_sent
= 0;
1723 if(parameter_count
< 8)
1724 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1726 if((fsp
= file_fsp(params
,0)) == NULL
)
1727 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1729 if(!lp_nt_acl_support(SNUM(conn
)))
1732 security_info_sent
= IVAL(params
,4);
1734 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
1735 (unsigned int)security_info_sent
));
1737 if (data_count
== 0)
1738 return ERROR_DOS(ERRDOS
, ERRnoaccess
);
1740 if (!NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, data_count
, security_info_sent
)))
1741 return ERROR_NT(nt_status
);
1745 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1749 /****************************************************************************
1751 ****************************************************************************/
1753 static int call_nt_transact_ioctl(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1754 char **ppsetup
, uint32 setup_count
,
1755 char **ppparams
, uint32 parameter_count
,
1756 char **ppdata
, uint32 data_count
)
1763 static BOOL logged_message
;
1764 char *pdata
= *ppdata
;
1766 if (setup_count
!= 8) {
1767 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1768 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1771 function
= IVAL(*ppsetup
, 0);
1772 fidnum
= SVAL(*ppsetup
, 4);
1773 isFSctl
= CVAL(*ppsetup
, 6);
1774 compfilter
= CVAL(*ppsetup
, 7);
1776 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1777 function
, fidnum
, isFSctl
, compfilter
));
1779 fsp
=file_fsp(*ppsetup
, 4);
1780 /* this check is done in each implemented function case for now
1781 because I don't want to break anything... --metze
1782 FSP_BELONGS_CONN(fsp,conn);*/
1785 case FSCTL_SET_SPARSE
:
1786 /* pretend this succeeded - tho strictly we should
1787 mark the file sparse (if the local fs supports it)
1788 so we can know if we need to pre-allocate or not */
1790 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1791 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1794 case FSCTL_0x000900C0
:
1795 /* pretend this succeeded - don't know what this really is
1796 but works ok like this --metze
1799 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum
));
1800 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1803 case FSCTL_GET_REPARSE_POINT
:
1804 /* pretend this fail - my winXP does it like this
1808 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1809 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
1812 case FSCTL_SET_REPARSE_POINT
:
1813 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1817 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1818 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
1821 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
1824 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1825 * and return their volume names. If max_data_count is 16, then it is just
1826 * asking for the number of volumes and length of the combined names.
1828 * pdata is the data allocated by our caller, but that uses
1829 * total_data_count (which is 0 in our case) rather than max_data_count.
1830 * Allocate the correct amount and return the pointer to let
1831 * it be deallocated when we return.
1833 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
1834 SHADOW_COPY_DATA
*shadow_data
= NULL
;
1835 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
1836 BOOL labels
= False
;
1837 uint32 labels_data_count
= 0;
1841 FSP_BELONGS_CONN(fsp
,conn
);
1843 if (max_data_count
< 16) {
1844 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1846 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1849 if (max_data_count
> 16) {
1853 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
1854 if (shadow_mem_ctx
== NULL
) {
1855 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1856 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1859 shadow_data
= (SHADOW_COPY_DATA
*)talloc_zero(shadow_mem_ctx
,sizeof(SHADOW_COPY_DATA
));
1860 if (shadow_data
== NULL
) {
1861 DEBUG(0,("talloc_zero() failed!\n"));
1862 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1865 shadow_data
->mem_ctx
= shadow_mem_ctx
;
1868 * Call the VFS routine to actually do the work.
1870 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
1871 talloc_destroy(shadow_data
->mem_ctx
);
1872 if (errno
== ENOSYS
) {
1873 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1874 conn
->connectpath
));
1875 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1877 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1878 conn
->connectpath
));
1879 return ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
1883 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
1888 data_count
= 12+labels_data_count
+4;
1891 if (max_data_count
<data_count
) {
1892 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1893 max_data_count
,data_count
));
1894 talloc_destroy(shadow_data
->mem_ctx
);
1895 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL
);
1898 pdata
= nttrans_realloc(ppdata
, data_count
);
1899 if (pdata
== NULL
) {
1900 talloc_destroy(shadow_data
->mem_ctx
);
1901 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1906 /* num_volumes 4 bytes */
1907 SIVAL(pdata
,0,shadow_data
->num_volumes
);
1910 /* num_labels 4 bytes */
1911 SIVAL(pdata
,4,shadow_data
->num_volumes
);
1914 /* needed_data_count 4 bytes */
1915 SIVAL(pdata
,8,labels_data_count
);
1919 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
1920 shadow_data
->num_volumes
,fsp
->fsp_name
));
1921 if (labels
&& shadow_data
->labels
) {
1922 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
1923 srvstr_push(outbuf
, cur_pdata
, shadow_data
->labels
[i
], 2*sizeof(SHADOW_COPY_LABEL
), STR_UNICODE
|STR_TERMINATE
);
1924 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
1925 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
1929 talloc_destroy(shadow_data
->mem_ctx
);
1931 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, pdata
, data_count
);
1936 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
1938 /* pretend this succeeded -
1940 * we have to send back a list with all files owned by this SID
1942 * but I have to check that --metze
1946 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
1948 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
1950 FSP_BELONGS_CONN(fsp
,conn
);
1952 /* unknown 4 bytes: this is not the length of the sid :-( */
1953 /*unknown = IVAL(pdata,0);*/
1955 sid_parse(pdata
+4,sid_len
,&sid
);
1956 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid
)));
1958 if (!NT_STATUS_IS_OK(sid_to_uid(&sid
, &uid
))) {
1959 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
1960 sid_string_static(&sid
),(unsigned long)sid_len
));
1964 /* we can take a look at the find source :-)
1966 * find ./ -uid $uid -name '*' is what we need here
1969 * and send 4bytes len and then NULL terminated unicode strings
1972 * but I don't know how to deal with the paged results
1973 * (maybe we can hang the result anywhere in the fsp struct)
1975 * we don't send all files at once
1976 * and at the next we should *not* start from the beginning,
1977 * so we have to cache the result
1982 /* this works for now... */
1983 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1987 if (!logged_message
) {
1988 logged_message
= True
; /* Only print this once... */
1989 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
1994 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1998 #ifdef HAVE_SYS_QUOTAS
1999 /****************************************************************************
2000 Reply to get user quota
2001 ****************************************************************************/
2003 static int call_nt_transact_get_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2004 char **ppsetup
, uint32 setup_count
,
2005 char **ppparams
, uint32 parameter_count
,
2006 char **ppdata
, uint32 data_count
)
2008 NTSTATUS nt_status
= NT_STATUS_OK
;
2009 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
2010 char *params
= *ppparams
;
2011 char *pdata
= *ppdata
;
2013 int data_len
=0,param_len
=0;
2016 files_struct
*fsp
= NULL
;
2020 BOOL start_enum
= True
;
2021 SMB_NTQUOTA_STRUCT qt
;
2022 SMB_NTQUOTA_LIST
*tmp_list
;
2023 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2028 if (conn
->admin_user
!= True
) {
2029 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2030 lp_servicename(SNUM(conn
)),conn
->user
));
2031 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2035 * Ensure minimum number of parameters sent.
2038 if (parameter_count
< 4) {
2039 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2040 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2043 /* maybe we can check the quota_fnum */
2044 fsp
= file_fsp(params
,0);
2045 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2046 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2047 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2050 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2051 * is done by CHECK_NTQUOTA_HANDLE_OK()
2053 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
2055 level
= SVAL(params
,2);
2057 /* unknown 12 bytes leading in params */
2060 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2061 /* seems that we should continue with the enum here --metze */
2063 if (qt_handle
->quota_list
!=NULL
&&
2064 qt_handle
->tmp_list
==NULL
) {
2067 free_ntquota_list(&(qt_handle
->quota_list
));
2069 /* Realloc the size of parameters and data we will return */
2071 params
= nttrans_realloc(ppparams
, param_len
);
2073 return ERROR_DOS(ERRDOS
,ERRnomem
);
2076 SIVAL(params
,0,data_len
);
2083 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2085 if (qt_handle
->quota_list
==NULL
&&
2086 qt_handle
->tmp_list
==NULL
) {
2090 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0)
2091 return ERROR_DOS(ERRSRV
,ERRerror
);
2093 /* Realloc the size of parameters and data we will return */
2095 params
= nttrans_realloc(ppparams
, param_len
);
2097 return ERROR_DOS(ERRDOS
,ERRnomem
);
2099 /* we should not trust the value in max_data_count*/
2100 max_data_count
= MIN(max_data_count
,2048);
2102 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2104 return ERROR_DOS(ERRDOS
,ERRnomem
);
2109 /* set params Size of returned Quota Data 4 bytes*/
2110 /* but set it later when we know it */
2112 /* for each entry push the data */
2115 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2118 tmp_list
= qt_handle
->tmp_list
;
2120 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2121 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2123 sid_len
= sid_size(&tmp_list
->quotas
->sid
);
2124 entry_len
= 40 + sid_len
;
2126 /* nextoffset entry 4 bytes */
2127 SIVAL(entry
,0,entry_len
);
2129 /* then the len of the SID 4 bytes */
2130 SIVAL(entry
,4,sid_len
);
2132 /* unknown data 8 bytes SMB_BIG_UINT */
2133 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2135 /* the used disk space 8 bytes SMB_BIG_UINT */
2136 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2138 /* the soft quotas 8 bytes SMB_BIG_UINT */
2139 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2141 /* the hard quotas 8 bytes SMB_BIG_UINT */
2142 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2144 /* and now the SID */
2145 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2148 qt_handle
->tmp_list
= tmp_list
;
2150 /* overwrite the offset of the last entry */
2151 SIVAL(entry
-entry_len
,0,0);
2153 data_len
= 4+qt_len
;
2154 /* overwrite the params quota_data_len */
2155 SIVAL(params
,0,data_len
);
2159 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2161 /* unknown 4 bytes IVAL(pdata,0) */
2163 if (data_count
< 8) {
2164 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2165 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2168 sid_len
= IVAL(pdata
,4);
2170 if (data_count
< 8+sid_len
) {
2171 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2172 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2175 data_len
= 4+40+sid_len
;
2177 if (max_data_count
< data_len
) {
2178 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2179 max_data_count
, data_len
));
2181 SIVAL(params
,0,data_len
);
2183 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2187 sid_parse(pdata
+8,sid_len
,&sid
);
2190 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2193 * we have to return zero's in all fields
2194 * instead of returning an error here
2199 /* Realloc the size of parameters and data we will return */
2201 params
= nttrans_realloc(ppparams
, param_len
);
2203 return ERROR_DOS(ERRDOS
,ERRnomem
);
2205 pdata
= nttrans_realloc(ppdata
, data_len
);
2207 return ERROR_DOS(ERRDOS
,ERRnomem
);
2211 /* set params Size of returned Quota Data 4 bytes*/
2212 SIVAL(params
,0,data_len
);
2214 /* nextoffset entry 4 bytes */
2217 /* then the len of the SID 4 bytes */
2218 SIVAL(entry
,4,sid_len
);
2220 /* unknown data 8 bytes SMB_BIG_UINT */
2221 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2223 /* the used disk space 8 bytes SMB_BIG_UINT */
2224 SBIG_UINT(entry
,16,qt
.usedspace
);
2226 /* the soft quotas 8 bytes SMB_BIG_UINT */
2227 SBIG_UINT(entry
,24,qt
.softlim
);
2229 /* the hard quotas 8 bytes SMB_BIG_UINT */
2230 SBIG_UINT(entry
,32,qt
.hardlim
);
2232 /* and now the SID */
2233 sid_linearize(entry
+40, sid_len
, &sid
);
2238 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2239 return ERROR_DOS(ERRSRV
,ERRerror
);
2243 send_nt_replies(inbuf
, outbuf
, bufsize
, nt_status
, params
, param_len
, pdata
, data_len
);
2248 /****************************************************************************
2249 Reply to set user quota
2250 ****************************************************************************/
2252 static int call_nt_transact_set_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2253 char **ppsetup
, uint32 setup_count
,
2254 char **ppparams
, uint32 parameter_count
,
2255 char **ppdata
, uint32 data_count
)
2257 char *params
= *ppparams
;
2258 char *pdata
= *ppdata
;
2259 int data_len
=0,param_len
=0;
2260 SMB_NTQUOTA_STRUCT qt
;
2263 files_struct
*fsp
= NULL
;
2268 if (conn
->admin_user
!= True
) {
2269 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2270 lp_servicename(SNUM(conn
)),conn
->user
));
2271 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2275 * Ensure minimum number of parameters sent.
2278 if (parameter_count
< 2) {
2279 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2280 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2283 /* maybe we can check the quota_fnum */
2284 fsp
= file_fsp(params
,0);
2285 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2286 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2287 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2290 if (data_count
< 40) {
2291 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2292 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2295 /* offset to next quota record.
2296 * 4 bytes IVAL(pdata,0)
2301 sid_len
= IVAL(pdata
,4);
2303 if (data_count
< 40+sid_len
) {
2304 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2305 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2308 /* unknown 8 bytes in pdata
2309 * maybe its the change time in NTTIME
2312 /* the used space 8 bytes (SMB_BIG_UINT)*/
2313 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2314 #ifdef LARGE_SMB_OFF_T
2315 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2316 #else /* LARGE_SMB_OFF_T */
2317 if ((IVAL(pdata
,20) != 0)&&
2318 ((qt
.usedspace
!= 0xFFFFFFFF)||
2319 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2320 /* more than 32 bits? */
2321 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2323 #endif /* LARGE_SMB_OFF_T */
2325 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2326 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2327 #ifdef LARGE_SMB_OFF_T
2328 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2329 #else /* LARGE_SMB_OFF_T */
2330 if ((IVAL(pdata
,28) != 0)&&
2331 ((qt
.softlim
!= 0xFFFFFFFF)||
2332 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2333 /* more than 32 bits? */
2334 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2336 #endif /* LARGE_SMB_OFF_T */
2338 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2339 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2340 #ifdef LARGE_SMB_OFF_T
2341 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2342 #else /* LARGE_SMB_OFF_T */
2343 if ((IVAL(pdata
,36) != 0)&&
2344 ((qt
.hardlim
!= 0xFFFFFFFF)||
2345 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2346 /* more than 32 bits? */
2347 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2349 #endif /* LARGE_SMB_OFF_T */
2351 sid_parse(pdata
+40,sid_len
,&sid
);
2352 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid
)));
2354 /* 44 unknown bytes left... */
2356 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2357 return ERROR_DOS(ERRSRV
,ERRerror
);
2360 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, pdata
, data_len
);
2364 #endif /* HAVE_SYS_QUOTAS */
2366 /****************************************************************************
2367 Reply to a SMBNTtrans.
2368 ****************************************************************************/
2370 int reply_nttrans(connection_struct
*conn
,
2371 char *inbuf
,char *outbuf
,int length
,int bufsize
)
2374 #if 0 /* Not used. */
2375 uint16 max_setup_count
= CVAL(inbuf
, smb_nt_MaxSetupCount
);
2376 uint32 max_parameter_count
= IVAL(inbuf
, smb_nt_MaxParameterCount
);
2377 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
2378 #endif /* Not used. */
2379 uint32 total_parameter_count
= IVAL(inbuf
, smb_nt_TotalParameterCount
);
2380 uint32 total_data_count
= IVAL(inbuf
, smb_nt_TotalDataCount
);
2381 uint32 parameter_count
= IVAL(inbuf
,smb_nt_ParameterCount
);
2382 uint32 parameter_offset
= IVAL(inbuf
,smb_nt_ParameterOffset
);
2383 uint32 data_count
= IVAL(inbuf
,smb_nt_DataCount
);
2384 uint32 data_offset
= IVAL(inbuf
,smb_nt_DataOffset
);
2385 uint16 setup_count
= 2*CVAL(inbuf
,smb_nt_SetupCount
); /* setup count is in *words* */
2386 uint16 function_code
= SVAL( inbuf
, smb_nt_Function
);
2387 char *params
= NULL
, *data
= NULL
, *setup
= NULL
;
2388 uint32 num_params_sofar
, num_data_sofar
;
2389 START_PROFILE(SMBnttrans
);
2391 if(global_oplock_break
&&
2392 ((function_code
== NT_TRANSACT_CREATE
) ||
2393 (function_code
== NT_TRANSACT_RENAME
))) {
2395 * Queue this open message as we are the process of an oplock break.
2398 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2399 due to being in oplock break state.\n", (unsigned int)function_code
));
2401 push_oplock_pending_smb_message( inbuf
, length
);
2402 END_PROFILE(SMBnttrans
);
2406 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2407 END_PROFILE(SMBnttrans
);
2408 return ERROR_DOS(ERRSRV
,ERRaccess
);
2411 outsize
= set_message(outbuf
,0,0,True
);
2414 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2415 * Ensure this is so as a sanity check.
2418 if(CVAL(inbuf
, smb_wct
) != 19 + (setup_count
/2)) {
2419 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2420 CVAL(inbuf
, smb_wct
), 19 + (setup_count
/2)));
2424 /* Allocate the space for the setup, the maximum needed parameters and data */
2427 setup
= (char *)malloc(setup_count
);
2428 if (total_parameter_count
> 0)
2429 params
= (char *)malloc(total_parameter_count
);
2430 if (total_data_count
> 0)
2431 data
= (char *)malloc(total_data_count
);
2433 if ((total_parameter_count
&& !params
) || (total_data_count
&& !data
) ||
2434 (setup_count
&& !setup
)) {
2438 DEBUG(0,("reply_nttrans : Out of memory\n"));
2439 END_PROFILE(SMBnttrans
);
2440 return ERROR_DOS(ERRDOS
,ERRnomem
);
2443 /* Copy the param and data bytes sent with this request into the params buffer */
2444 num_params_sofar
= parameter_count
;
2445 num_data_sofar
= data_count
;
2447 if (parameter_count
> total_parameter_count
|| data_count
> total_data_count
)
2451 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count
));
2452 if ((smb_nt_SetupStart
+ setup_count
< smb_nt_SetupStart
) ||
2453 (smb_nt_SetupStart
+ setup_count
< setup_count
))
2455 if (smb_nt_SetupStart
+ setup_count
> length
)
2458 memcpy( setup
, &inbuf
[smb_nt_SetupStart
], setup_count
);
2459 dump_data(10, setup
, setup_count
);
2462 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count
));
2463 if ((parameter_offset
+ parameter_count
< parameter_offset
) ||
2464 (parameter_offset
+ parameter_count
< parameter_count
))
2466 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
> inbuf
+ length
)||
2467 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
)))
2470 memcpy( params
, smb_base(inbuf
) + parameter_offset
, parameter_count
);
2471 dump_data(10, params
, parameter_count
);
2474 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count
));
2475 if ((data_offset
+ data_count
< data_offset
) || (data_offset
+ data_count
< data_count
))
2477 if ((smb_base(inbuf
) + data_offset
+ data_count
> inbuf
+ length
) ||
2478 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
)))
2481 memcpy( data
, smb_base(inbuf
) + data_offset
, data_count
);
2482 dump_data(10, data
, data_count
);
2485 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2487 if(num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2488 /* We need to send an interim response then receive the rest
2489 of the parameter/data bytes */
2490 outsize
= set_message(outbuf
,0,0,True
);
2491 if (!send_smb(smbd_server_fd(),outbuf
))
2492 exit_server("reply_nttrans: send_smb failed.");
2494 while( num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2496 uint32 parameter_displacement
;
2497 uint32 data_displacement
;
2499 ret
= receive_next_smb(inbuf
,bufsize
,SMB_SECONDARY_WAIT
);
2501 if((ret
&& (CVAL(inbuf
, smb_com
) != SMBnttranss
)) || !ret
) {
2502 outsize
= set_message(outbuf
,0,0,True
);
2504 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2506 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2507 (smb_read_error
== READ_ERROR
) ? "error" : "timeout" ));
2512 /* Revise total_params and total_data in case they have changed downwards */
2513 if (IVAL(inbuf
, smb_nts_TotalParameterCount
) < total_parameter_count
)
2514 total_parameter_count
= IVAL(inbuf
, smb_nts_TotalParameterCount
);
2515 if (IVAL(inbuf
, smb_nts_TotalDataCount
) < total_data_count
)
2516 total_data_count
= IVAL(inbuf
, smb_nts_TotalDataCount
);
2518 parameter_count
= IVAL(inbuf
,smb_nts_ParameterCount
);
2519 parameter_offset
= IVAL(inbuf
, smb_nts_ParameterOffset
);
2520 parameter_displacement
= IVAL(inbuf
, smb_nts_ParameterDisplacement
);
2521 num_params_sofar
+= parameter_count
;
2523 data_count
= IVAL(inbuf
, smb_nts_DataCount
);
2524 data_displacement
= IVAL(inbuf
, smb_nts_DataDisplacement
);
2525 data_offset
= IVAL(inbuf
, smb_nts_DataOffset
);
2526 num_data_sofar
+= data_count
;
2528 if (num_params_sofar
> total_parameter_count
|| num_data_sofar
> total_data_count
) {
2529 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2533 if (parameter_count
) {
2534 if (parameter_displacement
+ parameter_count
>= total_parameter_count
)
2536 if ((parameter_displacement
+ parameter_count
< parameter_displacement
) ||
2537 (parameter_displacement
+ parameter_count
< parameter_count
))
2539 if (parameter_displacement
> total_parameter_count
)
2541 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
>= inbuf
+ bufsize
) ||
2542 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
)))
2544 if (parameter_displacement
+ params
< params
)
2547 memcpy( ¶ms
[parameter_displacement
], smb_base(inbuf
) + parameter_offset
, parameter_count
);
2551 if (data_displacement
+ data_count
>= total_data_count
)
2553 if ((data_displacement
+ data_count
< data_displacement
) ||
2554 (data_displacement
+ data_count
< data_count
))
2556 if (data_displacement
> total_data_count
)
2558 if ((smb_base(inbuf
) + data_offset
+ data_count
>= inbuf
+ bufsize
) ||
2559 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
)))
2561 if (data_displacement
+ data
< data
)
2564 memcpy( &data
[data_displacement
], smb_base(inbuf
)+ data_offset
, data_count
);
2569 if (Protocol
>= PROTOCOL_NT1
)
2570 SSVAL(outbuf
,smb_flg2
,SVAL(outbuf
,smb_flg2
) | FLAGS2_IS_LONG_NAME
);
2572 /* Now we must call the relevant NT_TRANS function */
2573 switch(function_code
) {
2574 case NT_TRANSACT_CREATE
:
2575 START_PROFILE_NESTED(NT_transact_create
);
2576 outsize
= call_nt_transact_create(conn
, inbuf
, outbuf
,
2578 &setup
, setup_count
,
2579 ¶ms
, total_parameter_count
,
2580 &data
, total_data_count
);
2581 END_PROFILE_NESTED(NT_transact_create
);
2583 case NT_TRANSACT_IOCTL
:
2584 START_PROFILE_NESTED(NT_transact_ioctl
);
2585 outsize
= call_nt_transact_ioctl(conn
, inbuf
, outbuf
,
2587 &setup
, setup_count
,
2588 ¶ms
, total_parameter_count
,
2589 &data
, total_data_count
);
2590 END_PROFILE_NESTED(NT_transact_ioctl
);
2592 case NT_TRANSACT_SET_SECURITY_DESC
:
2593 START_PROFILE_NESTED(NT_transact_set_security_desc
);
2594 outsize
= call_nt_transact_set_security_desc(conn
, inbuf
, outbuf
,
2596 &setup
, setup_count
,
2597 ¶ms
, total_parameter_count
,
2598 &data
, total_data_count
);
2599 END_PROFILE_NESTED(NT_transact_set_security_desc
);
2601 case NT_TRANSACT_NOTIFY_CHANGE
:
2602 START_PROFILE_NESTED(NT_transact_notify_change
);
2603 outsize
= call_nt_transact_notify_change(conn
, inbuf
, outbuf
,
2605 &setup
, setup_count
,
2606 ¶ms
, total_parameter_count
,
2607 &data
, total_data_count
);
2608 END_PROFILE_NESTED(NT_transact_notify_change
);
2610 case NT_TRANSACT_RENAME
:
2611 START_PROFILE_NESTED(NT_transact_rename
);
2612 outsize
= call_nt_transact_rename(conn
, inbuf
, outbuf
,
2614 &setup
, setup_count
,
2615 ¶ms
, total_parameter_count
,
2616 &data
, total_data_count
);
2617 END_PROFILE_NESTED(NT_transact_rename
);
2620 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2621 START_PROFILE_NESTED(NT_transact_query_security_desc
);
2622 outsize
= call_nt_transact_query_security_desc(conn
, inbuf
, outbuf
,
2624 &setup
, setup_count
,
2625 ¶ms
, total_parameter_count
,
2626 &data
, total_data_count
);
2627 END_PROFILE_NESTED(NT_transact_query_security_desc
);
2629 #ifdef HAVE_SYS_QUOTAS
2630 case NT_TRANSACT_GET_USER_QUOTA
:
2631 START_PROFILE_NESTED(NT_transact_get_user_quota
);
2632 outsize
= call_nt_transact_get_user_quota(conn
, inbuf
, outbuf
,
2634 &setup
, setup_count
,
2635 ¶ms
, total_parameter_count
,
2636 &data
, total_data_count
);
2637 END_PROFILE_NESTED(NT_transact_get_user_quota
);
2639 case NT_TRANSACT_SET_USER_QUOTA
:
2640 START_PROFILE_NESTED(NT_transact_set_user_quota
);
2641 outsize
= call_nt_transact_set_user_quota(conn
, inbuf
, outbuf
,
2643 &setup
, setup_count
,
2644 ¶ms
, total_parameter_count
,
2645 &data
, total_data_count
);
2646 END_PROFILE_NESTED(NT_transact_set_user_quota
);
2648 #endif /* HAVE_SYS_QUOTAS */
2650 /* Error in request */
2651 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code
));
2655 END_PROFILE(SMBnttrans
);
2656 srv_signing_trans_stop();
2657 return ERROR_DOS(ERRSRV
,ERRerror
);
2660 /* As we do not know how many data packets will need to be
2661 returned here the various call_nt_transact_xxxx calls
2662 must send their own. Thus a call_nt_transact_xxxx routine only
2663 returns a value other than -1 when it wants to send
2667 srv_signing_trans_stop();
2672 END_PROFILE(SMBnttrans
);
2673 return outsize
; /* If a correct response was needed the call_nt_transact_xxxx
2674 calls have already sent it. If outsize != -1 then it is
2675 returning an error packet. */
2679 srv_signing_trans_stop();
2683 END_PROFILE(SMBnttrans
);
2684 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);