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 static 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;
356 uint32 original_desired_access
= *desired_access
;
359 * Convert GENERIC bits to specific bits.
362 se_map_generic(desired_access
, &file_generic_mapping
);
364 switch( *desired_access
& (FILE_READ_DATA
|FILE_WRITE_DATA
|FILE_APPEND_DATA
) ) {
366 smb_open_mode
= DOS_OPEN_RDONLY
;
368 case FILE_WRITE_DATA
:
369 case FILE_APPEND_DATA
:
370 case FILE_WRITE_DATA
|FILE_APPEND_DATA
:
371 smb_open_mode
= DOS_OPEN_WRONLY
;
373 case FILE_READ_DATA
|FILE_WRITE_DATA
:
374 case FILE_READ_DATA
|FILE_WRITE_DATA
|FILE_APPEND_DATA
:
375 case FILE_READ_DATA
|FILE_APPEND_DATA
:
376 smb_open_mode
= DOS_OPEN_RDWR
;
381 * NB. For DELETE_ACCESS we should really check the
382 * directory permissions, as that is what controls
383 * delete, and for WRITE_DAC_ACCESS we should really
384 * check the ownership, as that is what controls the
385 * chmod. Note that this is *NOT* a security hole (this
386 * note is for you, Andrew) as we are not *allowing*
387 * the access at this point, the actual unlink or
388 * chown or chmod call would do this. We are just helping
389 * clients out by telling them if they have a hope
390 * of any of this succeeding. POSIX acls may still
391 * deny the real call. JRA.
394 if (smb_open_mode
== -1) {
396 if(*desired_access
& (DELETE_ACCESS
|WRITE_DAC_ACCESS
|WRITE_OWNER_ACCESS
|SYNCHRONIZE_ACCESS
|
397 FILE_EXECUTE
|FILE_READ_ATTRIBUTES
|
398 FILE_READ_EA
|FILE_WRITE_EA
|SYSTEM_SECURITY_ACCESS
|
399 FILE_WRITE_ATTRIBUTES
|READ_CONTROL_ACCESS
)) {
400 smb_open_mode
= DOS_OPEN_RDONLY
;
401 } else if(*desired_access
== 0) {
404 * JRA - NT seems to sometimes send desired_access as zero. play it safe
405 * and map to a stat open.
408 smb_open_mode
= DOS_OPEN_RDONLY
;
411 DEBUG(0,("map_share_mode: Incorrect value 0x%lx for desired_access to file %s\n",
412 (unsigned long)*desired_access
, fname
));
418 * Set the special bit that means allow share delete.
419 * This is held outside the normal share mode bits at 1<<15.
423 if(share_access
& FILE_SHARE_DELETE
) {
424 smb_open_mode
|= ALLOW_SHARE_DELETE
;
425 DEBUG(10,("map_share_mode: FILE_SHARE_DELETE requested. open_mode = 0x%x\n", smb_open_mode
));
428 if(*desired_access
& DELETE_ACCESS
) {
429 DEBUG(10,("map_share_mode: DELETE_ACCESS requested. open_mode = 0x%x\n", smb_open_mode
));
433 * We need to store the intent to open for Delete. This
434 * is what determines if a delete on close flag can be set.
435 * This is the wrong way (and place) to store this, but for 2.2 this
436 * is the only practical way. JRA.
439 if (create_options
& FILE_DELETE_ON_CLOSE
) {
441 * W2K3 bug compatibility mode... To set delete on close
442 * the redirector must have *specifically* set DELETE_ACCESS
443 * in the desired_access field. Just asking for GENERIC_ALL won't do. JRA.
446 if (!(original_desired_access
& DELETE_ACCESS
)) {
447 DEBUG(5,("map_share_mode: FILE_DELETE_ON_CLOSE requested without \
448 DELETE_ACCESS for file %s. (desired_access = 0x%lx)\n",
449 fname
, (unsigned long)*desired_access
));
452 /* Implicit delete access is *NOT* requested... */
453 smb_open_mode
|= DELETE_ON_CLOSE_FLAG
;
454 DEBUG(10,("map_share_mode: FILE_DELETE_ON_CLOSE requested. open_mode = 0x%x\n", smb_open_mode
));
457 /* Add in the requested share mode. */
458 switch( share_access
& (FILE_SHARE_READ
|FILE_SHARE_WRITE
)) {
459 case FILE_SHARE_READ
:
460 smb_open_mode
|= SET_DENY_MODE(DENY_WRITE
);
462 case FILE_SHARE_WRITE
:
463 smb_open_mode
|= SET_DENY_MODE(DENY_READ
);
465 case (FILE_SHARE_READ
|FILE_SHARE_WRITE
):
466 smb_open_mode
|= SET_DENY_MODE(DENY_NONE
);
468 case FILE_SHARE_NONE
:
469 smb_open_mode
|= SET_DENY_MODE(DENY_ALL
);
474 * Handle an O_SYNC request.
477 if(file_attributes
& FILE_FLAG_WRITE_THROUGH
)
478 smb_open_mode
|= FILE_SYNC_OPENMODE
;
480 DEBUG(10,("map_share_mode: Mapped desired access 0x%lx, share access 0x%lx, file attributes 0x%lx \
481 to open_mode 0x%x\n", (unsigned long)*desired_access
, (unsigned long)share_access
,
482 (unsigned long)file_attributes
, smb_open_mode
));
484 return smb_open_mode
;
487 /****************************************************************************
488 Reply to an NT create and X call on a pipe.
489 ****************************************************************************/
491 static int nt_open_pipe(char *fname
, connection_struct
*conn
,
492 char *inbuf
, char *outbuf
, int *ppnum
)
494 smb_np_struct
*p
= NULL
;
496 uint16 vuid
= SVAL(inbuf
, smb_uid
);
499 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
501 /* See if it is one we want to handle. */
503 if (lp_disable_spoolss() && strequal(fname
, "\\spoolss"))
504 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
506 for( i
= 0; known_nt_pipes
[i
]; i
++ )
507 if( strequal(fname
,known_nt_pipes
[i
]))
510 if ( known_nt_pipes
[i
] == NULL
)
511 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
513 /* Strip \\ off the name. */
516 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname
));
518 p
= open_rpc_pipe_p(fname
, conn
, vuid
);
520 return(ERROR_DOS(ERRSRV
,ERRnofids
));
527 /****************************************************************************
528 Reply to an NT create and X call for pipes.
529 ****************************************************************************/
531 static int do_ntcreate_pipe_open(connection_struct
*conn
,
532 char *inbuf
,char *outbuf
,int length
,int bufsize
)
539 srvstr_pull_buf(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
);
541 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
545 * Deal with pipe return.
548 set_message(outbuf
,34,0,True
);
550 p
= outbuf
+ smb_vwv2
;
554 SIVAL(p
,0,FILE_WAS_OPENED
);
557 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
560 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
562 SSVAL(p
,2, 0x5FF); /* ? */
564 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
566 return chain_reply(inbuf
,outbuf
,length
,bufsize
);
569 /****************************************************************************
570 Reply to an NT create and X call.
571 ****************************************************************************/
573 int reply_ntcreate_and_X(connection_struct
*conn
,
574 char *inbuf
,char *outbuf
,int length
,int bufsize
)
578 enum FAKE_FILE_TYPE fake_file_type
= FAKE_FILE_TYPE_NONE
;
579 uint32 flags
= IVAL(inbuf
,smb_ntcreate_Flags
);
580 uint32 desired_access
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
581 uint32 file_attributes
= IVAL(inbuf
,smb_ntcreate_FileAttributes
);
582 uint32 share_access
= IVAL(inbuf
,smb_ntcreate_ShareAccess
);
583 uint32 create_disposition
= IVAL(inbuf
,smb_ntcreate_CreateDisposition
);
584 uint32 create_options
= IVAL(inbuf
,smb_ntcreate_CreateOptions
);
585 uint16 root_dir_fid
= (uint16
)IVAL(inbuf
,smb_ntcreate_RootDirectoryFid
);
586 SMB_BIG_UINT allocation_size
= 0;
589 /* Breakout the oplock request bits so we can set the
590 reply bits separately. */
591 int oplock_request
= 0;
593 SMB_OFF_T file_len
= 0;
594 SMB_STRUCT_STAT sbuf
;
596 BOOL bad_path
= False
;
597 files_struct
*fsp
=NULL
;
600 BOOL extended_oplock_granted
= False
;
603 START_PROFILE(SMBntcreateX
);
605 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
606 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
607 create_options = 0x%x root_dir_fid = 0x%x\n", flags
, desired_access
, file_attributes
,
608 share_access
, create_disposition
,
609 create_options
, root_dir_fid
));
611 /* If it's an IPC, use the pipe handler. */
614 if (lp_nt_pipe_support()) {
615 END_PROFILE(SMBntcreateX
);
616 return do_ntcreate_pipe_open(conn
,inbuf
,outbuf
,length
,bufsize
);
618 END_PROFILE(SMBntcreateX
);
619 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
623 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
624 END_PROFILE(SMBntcreateX
);
625 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
629 * We need to construct the open_and_X ofun value from the
630 * NT values, as that's what our code is structured to accept.
633 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1) {
634 END_PROFILE(SMBntcreateX
);
635 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
642 if(root_dir_fid
!= 0) {
644 * This filename is relative to a directory fid.
647 files_struct
*dir_fsp
= file_fsp(inbuf
,smb_ntcreate_RootDirectoryFid
);
651 END_PROFILE(SMBntcreateX
);
652 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
655 if(!dir_fsp
->is_directory
) {
657 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), 0, STR_TERMINATE
, &status
);
658 if (!NT_STATUS_IS_OK(status
)) {
659 END_PROFILE(SMBntcreateX
);
660 return ERROR_NT(status
);
664 * Check to see if this is a mac fork of some kind.
667 if( strchr_m(fname
, ':')) {
668 END_PROFILE(SMBntcreateX
);
669 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
673 we need to handle the case when we get a
674 relative open relative to a file and the
675 pathname is blank - this is a reopen!
676 (hint from demyn plantenberg)
679 END_PROFILE(SMBntcreateX
);
680 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
684 * Copy in the base directory name.
687 pstrcpy( fname
, dir_fsp
->fsp_name
);
688 dir_name_len
= strlen(fname
);
691 * Ensure it ends in a '\'.
694 if(fname
[dir_name_len
-1] != '\\' && fname
[dir_name_len
-1] != '/') {
695 pstrcat(fname
, "\\");
699 srvstr_get_path(inbuf
, rel_fname
, smb_buf(inbuf
), sizeof(rel_fname
), 0, STR_TERMINATE
, &status
);
700 if (!NT_STATUS_IS_OK(status
)) {
701 END_PROFILE(SMBntcreateX
);
702 return ERROR_NT(status
);
704 pstrcat(fname
, rel_fname
);
706 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), 0, STR_TERMINATE
, &status
);
707 if (!NT_STATUS_IS_OK(status
)) {
708 END_PROFILE(SMBntcreateX
);
709 return ERROR_NT(status
);
713 * Check to see if this is a mac fork of some kind.
716 if( strchr_m(fname
, ':')) {
718 #ifdef HAVE_SYS_QUOTAS
719 if ((fake_file_type
=is_fake_file(fname
))!=FAKE_FILE_TYPE_NONE
) {
721 * here we go! support for changing the disk quotas --metze
723 * we need to fake up to open this MAGIC QUOTA file
724 * and return a valid FID
726 * w2k close this file directly after openening
727 * xp also tries a QUERY_FILE_INFO on the file and then close it
731 END_PROFILE(SMBntcreateX
);
732 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
733 #ifdef HAVE_SYS_QUOTAS
740 * Now contruct the smb_open_mode value from the filename,
741 * desired access and the share access.
743 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
745 if((smb_open_mode
= map_share_mode(fname
, create_options
, &desired_access
,
747 file_attributes
)) == -1) {
748 END_PROFILE(SMBntcreateX
);
749 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
752 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
753 if (oplock_request
) {
754 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
758 * Ordinary file or directory.
762 * Check if POSIX semantics are wanted.
765 set_posix_case_semantics(file_attributes
);
767 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
770 * If it's a request for a directory open, deal with it separately.
773 if(create_options
& FILE_DIRECTORY_FILE
) {
776 /* Can't open a temp directory. IFS kit test. */
777 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
778 END_PROFILE(SMBntcreateX
);
779 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
782 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
784 restore_case_semantics(file_attributes
);
787 END_PROFILE(SMBntcreateX
);
788 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
792 * Ordinary file case.
795 /* NB. We have a potential bug here. If we
796 * cause an oplock break to ourselves, then we
797 * could end up processing filename related
798 * SMB requests whilst we await the oplock
799 * break response. As we may have changed the
800 * filename case semantics to be POSIX-like,
801 * this could mean a filename request could
802 * fail when it should succeed. This is a rare
803 * condition, but eventually we must arrange
804 * to restore the correct case semantics
805 * before issuing an oplock break request to
806 * our client. JRA. */
808 if (fake_file_type
==FAKE_FILE_TYPE_NONE
) {
809 fsp
= open_file_shared1(conn
,fname
,&sbuf
,
812 smb_ofun
,file_attributes
,oplock_request
,
815 /* to open a fake_file --metze */
816 fsp
= open_fake_file_shared1(fake_file_type
,conn
,fname
,&sbuf
,
819 smb_ofun
,file_attributes
, oplock_request
,
824 /* We cheat here. There are two cases we
825 * care about. One is a directory rename,
826 * where the NT client will attempt to
827 * open the source directory for
828 * DELETE access. Note that when the
829 * NT client does this it does *not*
830 * set the directory bit in the
831 * request packet. This is translated
832 * into a read/write open
833 * request. POSIX states that any open
834 * for write request on a directory
835 * will generate an EISDIR error, so
836 * we can catch this here and open a
837 * pseudo handle that is flagged as a
838 * directory. The second is an open
839 * for a permissions read only, which
840 * we handle in the open_file_stat case. JRA.
843 if(errno
== EISDIR
) {
846 * Fail the open if it was explicitly a non-directory file.
849 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
850 restore_case_semantics(file_attributes
);
851 SSVAL(outbuf
, smb_flg2
,
852 SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
853 END_PROFILE(SMBntcreateX
);
854 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
858 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
861 restore_case_semantics(file_attributes
);
862 END_PROFILE(SMBntcreateX
);
863 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
867 restore_case_semantics(file_attributes
);
868 END_PROFILE(SMBntcreateX
);
869 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
874 restore_case_semantics(file_attributes
);
876 file_len
= sbuf
.st_size
;
877 fmode
= dos_mode(conn
,fname
,&sbuf
);
879 fmode
= FILE_ATTRIBUTE_NORMAL
;
880 if (!fsp
->is_directory
&& (fmode
& aDIR
)) {
881 close_file(fsp
,False
);
882 END_PROFILE(SMBntcreateX
);
883 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
886 /* Save the requested allocation size. */
887 allocation_size
= (SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
);
888 #ifdef LARGE_SMB_OFF_T
889 allocation_size
|= (((SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
+ 4)) << 32);
891 if (allocation_size
&& (allocation_size
> (SMB_BIG_UINT
)file_len
)) {
892 fsp
->initial_allocation_size
= SMB_ROUNDUP(allocation_size
,SMB_ROUNDUP_ALLOCATION_SIZE
);
893 if (fsp
->is_directory
) {
894 close_file(fsp
,False
);
895 END_PROFILE(SMBntcreateX
);
896 /* Can't set allocation size on a directory. */
897 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
899 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
900 close_file(fsp
,False
);
901 END_PROFILE(SMBntcreateX
);
902 return ERROR_NT(NT_STATUS_DISK_FULL
);
905 fsp
->initial_allocation_size
= SMB_ROUNDUP(((SMB_BIG_UINT
)file_len
),SMB_ROUNDUP_ALLOCATION_SIZE
);
909 * If the caller set the extended oplock request bit
910 * and we granted one (by whatever means) - set the
911 * correct bit for extended oplock reply.
914 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
915 extended_oplock_granted
= True
;
917 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
918 extended_oplock_granted
= True
;
921 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
922 set_message(outbuf
,42,0,True
);
924 set_message(outbuf
,34,0,True
);
927 p
= outbuf
+ smb_vwv2
;
930 * Currently as we don't support level II oplocks we just report
931 * exclusive & batch here.
934 if (extended_oplock_granted
) {
935 if (flags
& REQUEST_BATCH_OPLOCK
) {
936 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
938 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
940 } else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
)) {
941 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
943 SCVAL(p
,0,NO_OPLOCK_RETURN
);
947 SSVAL(p
,0,fsp
->fnum
);
949 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
950 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
952 SIVAL(p
,0,smb_action
);
956 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
958 if (lp_dos_filetime_resolution(SNUM(conn
))) {
965 put_long_date(p
,c_time
);
967 put_long_date(p
,sbuf
.st_atime
); /* access time */
969 put_long_date(p
,sbuf
.st_mtime
); /* write time */
971 put_long_date(p
,sbuf
.st_mtime
); /* change time */
973 SIVAL(p
,0,fmode
); /* File Attributes. */
975 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
977 SOFF_T(p
,0,file_len
);
979 if (flags
& EXTENDED_RESPONSE_REQUIRED
)
982 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
984 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
986 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
987 END_PROFILE(SMBntcreateX
);
991 /****************************************************************************
992 Reply to a NT_TRANSACT_CREATE call to open a pipe.
993 ****************************************************************************/
995 static int do_nt_transact_create_pipe( connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
996 char **ppsetup
, uint32 setup_count
,
997 char **ppparams
, uint32 parameter_count
,
998 char **ppdata
, uint32 data_count
)
1001 char *params
= *ppparams
;
1008 * Ensure minimum number of parameters sent.
1011 if(parameter_count
< 54) {
1012 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1013 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1016 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
);
1017 if (!NT_STATUS_IS_OK(status
)) {
1018 return ERROR_NT(status
);
1021 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
1024 /* Realloc the size of parameters and data we will return */
1025 params
= nttrans_realloc(ppparams
, 69);
1027 return ERROR_DOS(ERRDOS
,ERRnomem
);
1030 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1035 SIVAL(p
,0,FILE_WAS_OPENED
);
1039 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
1042 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
1044 SSVAL(p
,2, 0x5FF); /* ? */
1046 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
1048 /* Send the required number of replies */
1049 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1054 /****************************************************************************
1055 Internal fn to set security descriptors.
1056 ****************************************************************************/
1058 static NTSTATUS
set_sd(files_struct
*fsp
, char *data
, uint32 sd_len
, uint32 security_info_sent
)
1061 SEC_DESC
*psd
= NULL
;
1062 TALLOC_CTX
*mem_ctx
;
1066 return NT_STATUS_OK
;
1070 * Init the parse struct we will unmarshall from.
1073 if ((mem_ctx
= talloc_init("set_sd")) == NULL
) {
1074 DEBUG(0,("set_sd: talloc_init failed.\n"));
1075 return NT_STATUS_NO_MEMORY
;
1078 prs_init(&pd
, 0, mem_ctx
, UNMARSHALL
);
1081 * Setup the prs_struct to point at the memory we just
1085 prs_give_memory( &pd
, data
, sd_len
, False
);
1088 * Finally, unmarshall from the data buffer.
1091 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1092 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1094 * Return access denied for want of a better error message..
1096 talloc_destroy(mem_ctx
);
1097 return NT_STATUS_NO_MEMORY
;
1100 if (psd
->off_owner_sid
==0)
1101 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
1102 if (psd
->off_grp_sid
==0)
1103 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
1104 if (psd
->off_sacl
==0)
1105 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
1106 if (psd
->off_dacl
==0)
1107 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
1109 ret
= SMB_VFS_FSET_NT_ACL( fsp
, fsp
->fd
, security_info_sent
, psd
);
1112 talloc_destroy(mem_ctx
);
1113 return NT_STATUS_ACCESS_DENIED
;
1116 talloc_destroy(mem_ctx
);
1118 return NT_STATUS_OK
;
1121 /****************************************************************************
1122 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1123 ****************************************************************************/
1125 static int call_nt_transact_create(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1126 char **ppsetup
, uint32 setup_count
,
1127 char **ppparams
, uint32 parameter_count
,
1128 char **ppdata
, uint32 data_count
)
1131 char *params
= *ppparams
;
1132 char *data
= *ppdata
;
1133 /* Breakout the oplock request bits so we can set the reply bits separately. */
1134 int oplock_request
= 0;
1135 int fmode
=0,rmode
=0;
1136 SMB_OFF_T file_len
= 0;
1137 SMB_STRUCT_STAT sbuf
;
1139 BOOL bad_path
= False
;
1140 files_struct
*fsp
= NULL
;
1142 BOOL extended_oplock_granted
= False
;
1144 uint32 desired_access
;
1145 uint32 file_attributes
;
1146 uint32 share_access
;
1147 uint32 create_disposition
;
1148 uint32 create_options
;
1150 uint16 root_dir_fid
;
1151 SMB_BIG_UINT allocation_size
= 0;
1157 DEBUG(5,("call_nt_transact_create\n"));
1160 * If it's an IPC, use the pipe handler.
1164 if (lp_nt_pipe_support())
1165 return do_nt_transact_create_pipe(conn
, inbuf
, outbuf
, length
,
1167 ppsetup
, setup_count
,
1168 ppparams
, parameter_count
,
1169 ppdata
, data_count
);
1171 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1175 * Ensure minimum number of parameters sent.
1178 if(parameter_count
< 54) {
1179 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1180 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1183 flags
= IVAL(params
,0);
1184 desired_access
= IVAL(params
,8);
1185 file_attributes
= IVAL(params
,20);
1186 share_access
= IVAL(params
,24);
1187 create_disposition
= IVAL(params
,28);
1188 create_options
= IVAL(params
,32);
1189 sd_len
= IVAL(params
,36);
1190 root_dir_fid
= (uint16
)IVAL(params
,4);
1192 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
1193 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1197 * We need to construct the open_and_X ofun value from the
1198 * NT values, as that's what our code is structured to accept.
1201 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1)
1202 return ERROR_DOS(ERRDOS
,ERRbadmem
);
1205 * Get the file name.
1208 if(root_dir_fid
!= 0) {
1210 * This filename is relative to a directory fid.
1212 files_struct
*dir_fsp
= file_fsp(params
,4);
1213 size_t dir_name_len
;
1216 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1218 if(!dir_fsp
->is_directory
) {
1219 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
);
1220 if (!NT_STATUS_IS_OK(status
)) {
1221 return ERROR_NT(status
);
1225 * Check to see if this is a mac fork of some kind.
1228 if( strchr_m(fname
, ':'))
1229 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1231 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1235 * Copy in the base directory name.
1238 pstrcpy( fname
, dir_fsp
->fsp_name
);
1239 dir_name_len
= strlen(fname
);
1242 * Ensure it ends in a '\'.
1245 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
1246 pstrcat(fname
, "\\");
1252 srvstr_get_path(inbuf
, tmpname
, params
+53, sizeof(tmpname
), parameter_count
-53, STR_TERMINATE
, &status
);
1253 if (!NT_STATUS_IS_OK(status
)) {
1254 return ERROR_NT(status
);
1256 pstrcat(fname
, tmpname
);
1259 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
);
1260 if (!NT_STATUS_IS_OK(status
)) {
1261 return ERROR_NT(status
);
1265 * Check to see if this is a mac fork of some kind.
1268 if( strchr_m(fname
, ':'))
1269 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1273 * Now contruct the smb_open_mode value from the desired access
1274 * and the share access.
1277 if((smb_open_mode
= map_share_mode( fname
, create_options
, &desired_access
,
1278 share_access
, file_attributes
)) == -1)
1279 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1281 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1282 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1285 * Check if POSIX semantics are wanted.
1288 set_posix_case_semantics(file_attributes
);
1290 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
1292 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
1295 * If it's a request for a directory open, deal with it separately.
1298 if(create_options
& FILE_DIRECTORY_FILE
) {
1300 /* Can't open a temp directory. IFS kit test. */
1301 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
1302 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1308 * We will get a create directory here if the Win32
1309 * app specified a security descriptor in the
1310 * CreateDirectory() call.
1313 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
1316 restore_case_semantics(file_attributes
);
1317 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1323 * Ordinary file case.
1326 fsp
= open_file_shared1(conn
,fname
,&sbuf
,desired_access
,
1327 smb_open_mode
,smb_ofun
,file_attributes
,
1328 oplock_request
,&rmode
,&smb_action
);
1332 if(errno
== EISDIR
) {
1335 * Fail the open if it was explicitly a non-directory file.
1338 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
1339 restore_case_semantics(file_attributes
);
1340 SSVAL(outbuf
, smb_flg2
, SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
1341 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
1345 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
1348 restore_case_semantics(file_attributes
);
1349 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1352 restore_case_semantics(file_attributes
);
1353 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1357 file_len
= sbuf
.st_size
;
1358 fmode
= dos_mode(conn
,fname
,&sbuf
);
1360 fmode
= FILE_ATTRIBUTE_NORMAL
;
1363 close_file(fsp
,False
);
1364 restore_case_semantics(file_attributes
);
1365 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1369 * If the caller set the extended oplock request bit
1370 * and we granted one (by whatever means) - set the
1371 * correct bit for extended oplock reply.
1374 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
1375 extended_oplock_granted
= True
;
1377 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
1378 extended_oplock_granted
= True
;
1382 * Now try and apply the desired SD.
1385 if (sd_len
&& !NT_STATUS_IS_OK(status
= set_sd( fsp
, data
, sd_len
, ALL_SECURITY_INFORMATION
))) {
1386 close_file(fsp
,False
);
1387 restore_case_semantics(file_attributes
);
1388 return ERROR_NT(status
);
1391 restore_case_semantics(file_attributes
);
1393 /* Save the requested allocation size. */
1394 allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
1395 #ifdef LARGE_SMB_OFF_T
1396 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
1398 if (allocation_size
&& (allocation_size
> file_len
)) {
1399 fsp
->initial_allocation_size
= SMB_ROUNDUP(allocation_size
,SMB_ROUNDUP_ALLOCATION_SIZE
);
1400 if (fsp
->is_directory
) {
1401 close_file(fsp
,False
);
1402 END_PROFILE(SMBntcreateX
);
1403 /* Can't set allocation size on a directory. */
1404 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1406 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
1407 close_file(fsp
,False
);
1408 return ERROR_NT(NT_STATUS_DISK_FULL
);
1411 fsp
->initial_allocation_size
= SMB_ROUNDUP(((SMB_BIG_UINT
)file_len
),SMB_ROUNDUP_ALLOCATION_SIZE
);
1414 /* Realloc the size of parameters and data we will return */
1415 params
= nttrans_realloc(ppparams
, 69);
1417 return ERROR_DOS(ERRDOS
,ERRnomem
);
1420 if (extended_oplock_granted
)
1421 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
1422 else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
))
1423 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
1425 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1428 SSVAL(p
,0,fsp
->fnum
);
1430 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
1431 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1433 SIVAL(p
,0,smb_action
);
1437 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1439 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1441 sbuf
.st_atime
&= ~1;
1442 sbuf
.st_mtime
&= ~1;
1443 sbuf
.st_mtime
&= ~1;
1446 put_long_date(p
,c_time
);
1448 put_long_date(p
,sbuf
.st_atime
); /* access time */
1450 put_long_date(p
,sbuf
.st_mtime
); /* write time */
1452 put_long_date(p
,sbuf
.st_mtime
); /* change time */
1454 SIVAL(p
,0,fmode
); /* File Attributes. */
1456 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
1458 SOFF_T(p
,0,file_len
);
1460 if (flags
& EXTENDED_RESPONSE_REQUIRED
)
1463 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1465 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname
));
1467 /* Send the required number of replies */
1468 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1473 /****************************************************************************
1474 Reply to a NT CANCEL request.
1475 ****************************************************************************/
1477 int reply_ntcancel(connection_struct
*conn
,
1478 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1481 * Go through and cancel any pending change notifies.
1484 int mid
= SVAL(inbuf
,smb_mid
);
1485 START_PROFILE(SMBntcancel
);
1486 remove_pending_change_notify_requests_by_mid(mid
);
1487 remove_pending_lock_requests_by_mid(mid
);
1488 srv_cancel_sign_response(mid
);
1490 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid
));
1492 END_PROFILE(SMBntcancel
);
1496 /****************************************************************************
1497 Reply to a NT rename request.
1498 ****************************************************************************/
1500 int reply_ntrename(connection_struct
*conn
,
1501 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1508 uint16 attrs
= SVAL(inbuf
,smb_vwv0
);
1509 uint16 rename_type
= SVAL(inbuf
,smb_vwv1
);
1511 START_PROFILE(SMBntrename
);
1513 if ((rename_type
!= RENAME_FLAG_RENAME
) && (rename_type
!= RENAME_FLAG_HARD_LINK
)) {
1514 END_PROFILE(SMBntrename
);
1515 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1518 p
= smb_buf(inbuf
) + 1;
1519 p
+= srvstr_get_path(inbuf
, oldname
, p
, sizeof(oldname
), 0, STR_TERMINATE
, &status
);
1520 if (!NT_STATUS_IS_OK(status
)) {
1521 END_PROFILE(SMBntrename
);
1522 return ERROR_NT(status
);
1525 if( strchr_m(oldname
, ':')) {
1526 /* Can't rename a stream. */
1527 END_PROFILE(SMBntrename
);
1528 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1532 p
+= srvstr_get_path(inbuf
, newname
, p
, sizeof(newname
), 0, STR_TERMINATE
, &status
);
1533 if (!NT_STATUS_IS_OK(status
)) {
1534 END_PROFILE(SMBntrename
);
1535 return ERROR_NT(status
);
1538 RESOLVE_DFSPATH(oldname
, conn
, inbuf
, outbuf
);
1539 RESOLVE_DFSPATH(newname
, conn
, inbuf
, outbuf
);
1541 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1543 if (rename_type
== RENAME_FLAG_RENAME
) {
1544 status
= rename_internals(conn
, oldname
, newname
, attrs
, False
);
1546 status
= hardlink_internals(conn
, oldname
, newname
);
1549 if (!NT_STATUS_IS_OK(status
)) {
1550 END_PROFILE(SMBntrename
);
1551 return ERROR_NT(status
);
1555 * Win2k needs a changenotify request response before it will
1556 * update after a rename..
1558 process_pending_change_notify_queue((time_t)0);
1559 outsize
= set_message(outbuf
,0,0,True
);
1561 END_PROFILE(SMBntrename
);
1565 /****************************************************************************
1566 Reply to an unsolicited SMBNTtranss - just ignore it!
1567 ****************************************************************************/
1569 int reply_nttranss(connection_struct
*conn
,
1570 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1572 START_PROFILE(SMBnttranss
);
1573 DEBUG(4,("Ignoring nttranss of length %d\n",length
));
1574 END_PROFILE(SMBnttranss
);
1578 /****************************************************************************
1579 Reply to a notify change - queue the request and
1580 don't allow a directory to be opened.
1581 ****************************************************************************/
1583 static int call_nt_transact_notify_change(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1584 char **ppsetup
, uint32 setup_count
,
1585 char **ppparams
, uint32 parameter_count
,
1586 char **ppdata
, uint32 data_count
)
1588 char *setup
= *ppsetup
;
1593 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1595 fsp
= file_fsp(setup
,4);
1596 flags
= IVAL(setup
, 0);
1598 DEBUG(3,("call_nt_transact_notify_change\n"));
1601 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1603 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
))
1604 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1606 if (!change_notify_set(inbuf
, fsp
, conn
, flags
))
1607 return(UNIXERROR(ERRDOS
,ERRbadfid
));
1609 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1610 name = %s\n", fsp
->fsp_name
));
1615 /****************************************************************************
1616 Reply to an NT transact rename command.
1617 ****************************************************************************/
1619 static int call_nt_transact_rename(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1620 char **ppsetup
, uint32 setup_count
,
1621 char **ppparams
, uint32 parameter_count
,
1622 char **ppdata
, uint32 data_count
)
1624 char *params
= *ppparams
;
1626 files_struct
*fsp
= NULL
;
1627 BOOL replace_if_exists
= False
;
1630 if(parameter_count
< 4)
1631 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1633 fsp
= file_fsp(params
, 0);
1634 replace_if_exists
= (SVAL(params
,2) & RENAME_REPLACE_IF_EXISTS
) ? True
: False
;
1635 CHECK_FSP(fsp
, conn
);
1636 srvstr_get_path(inbuf
, new_name
, params
+4, sizeof(new_name
), -1, STR_TERMINATE
, &status
);
1637 if (!NT_STATUS_IS_OK(status
)) {
1638 return ERROR_NT(status
);
1641 status
= rename_internals(conn
, fsp
->fsp_name
,
1642 new_name
, 0, replace_if_exists
);
1643 if (!NT_STATUS_IS_OK(status
))
1644 return ERROR_NT(status
);
1647 * Rename was successful.
1649 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1651 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1652 fsp
->fsp_name
, new_name
));
1655 * Win2k needs a changenotify request response before it will
1656 * update after a rename..
1659 process_pending_change_notify_queue((time_t)0);
1664 /******************************************************************************
1665 Fake up a completely empty SD.
1666 *******************************************************************************/
1668 static size_t get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1670 extern DOM_SID global_sid_World
;
1673 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1675 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1682 /****************************************************************************
1683 Reply to query a security descriptor.
1684 ****************************************************************************/
1686 static int call_nt_transact_query_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1687 char **ppsetup
, uint32 setup_count
,
1688 char **ppparams
, uint32 parameter_count
,
1689 char **ppdata
, uint32 data_count
)
1691 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
1692 char *params
= *ppparams
;
1693 char *data
= *ppdata
;
1695 SEC_DESC
*psd
= NULL
;
1697 uint32 security_info_wanted
;
1698 TALLOC_CTX
*mem_ctx
;
1699 files_struct
*fsp
= NULL
;
1701 if(parameter_count
< 8)
1702 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1704 fsp
= file_fsp(params
,0);
1706 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1708 security_info_wanted
= IVAL(params
,4);
1710 DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp
->fsp_name
));
1712 params
= nttrans_realloc(ppparams
, 4);
1714 return ERROR_DOS(ERRDOS
,ERRnomem
);
1716 if ((mem_ctx
= talloc_init("call_nt_transact_query_security_desc")) == NULL
) {
1717 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1718 return ERROR_DOS(ERRDOS
,ERRnomem
);
1722 * Get the permissions to return.
1725 if (!lp_nt_acl_support(SNUM(conn
)))
1726 sd_size
= get_null_nt_acl(mem_ctx
, &psd
);
1728 sd_size
= SMB_VFS_FGET_NT_ACL(fsp
, fsp
->fd
, security_info_wanted
, &psd
);
1731 talloc_destroy(mem_ctx
);
1732 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1735 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size
));
1737 SIVAL(params
,0,(uint32
)sd_size
);
1739 if(max_data_count
< sd_size
) {
1741 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_BUFFER_TOO_SMALL
,
1742 params
, 4, *ppdata
, 0);
1743 talloc_destroy(mem_ctx
);
1748 * Allocate the data we will point this at.
1751 data
= nttrans_realloc(ppdata
, sd_size
);
1753 talloc_destroy(mem_ctx
);
1754 return ERROR_DOS(ERRDOS
,ERRnomem
);
1758 * Init the parse struct we will marshall into.
1761 prs_init(&pd
, 0, mem_ctx
, MARSHALL
);
1764 * Setup the prs_struct to point at the memory we just
1768 prs_give_memory( &pd
, data
, (uint32
)sd_size
, False
);
1771 * Finally, linearize into the outgoing buffer.
1774 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1775 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
1776 security descriptor.\n"));
1778 * Return access denied for want of a better error message..
1780 talloc_destroy(mem_ctx
);
1781 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1785 * Now we can delete the security descriptor.
1788 talloc_destroy(mem_ctx
);
1790 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1794 /****************************************************************************
1795 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1796 ****************************************************************************/
1798 static int call_nt_transact_set_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1799 char **ppsetup
, uint32 setup_count
,
1800 char **ppparams
, uint32 parameter_count
,
1801 char **ppdata
, uint32 data_count
)
1803 char *params
= *ppparams
;
1804 char *data
= *ppdata
;
1805 files_struct
*fsp
= NULL
;
1806 uint32 security_info_sent
= 0;
1809 if(parameter_count
< 8)
1810 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1812 if((fsp
= file_fsp(params
,0)) == NULL
)
1813 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1815 if(!lp_nt_acl_support(SNUM(conn
)))
1818 security_info_sent
= IVAL(params
,4);
1820 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
1821 (unsigned int)security_info_sent
));
1823 if (data_count
== 0)
1824 return ERROR_DOS(ERRDOS
, ERRnoaccess
);
1826 if (!NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, data_count
, security_info_sent
)))
1827 return ERROR_NT(nt_status
);
1831 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1835 /****************************************************************************
1837 ****************************************************************************/
1839 static int call_nt_transact_ioctl(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1840 char **ppsetup
, uint32 setup_count
,
1841 char **ppparams
, uint32 parameter_count
,
1842 char **ppdata
, uint32 data_count
)
1849 static BOOL logged_message
;
1850 char *pdata
= *ppdata
;
1852 if (setup_count
!= 8) {
1853 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1854 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1857 function
= IVAL(*ppsetup
, 0);
1858 fidnum
= SVAL(*ppsetup
, 4);
1859 isFSctl
= CVAL(*ppsetup
, 6);
1860 compfilter
= CVAL(*ppsetup
, 7);
1862 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1863 function
, fidnum
, isFSctl
, compfilter
));
1865 fsp
=file_fsp(*ppsetup
, 4);
1866 /* this check is done in each implemented function case for now
1867 because I don't want to break anything... --metze
1868 FSP_BELONGS_CONN(fsp,conn);*/
1871 case FSCTL_SET_SPARSE
:
1872 /* pretend this succeeded - tho strictly we should
1873 mark the file sparse (if the local fs supports it)
1874 so we can know if we need to pre-allocate or not */
1876 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1877 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1880 case FSCTL_0x000900C0
:
1881 /* pretend this succeeded - don't know what this really is
1882 but works ok like this --metze
1885 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum
));
1886 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1889 case FSCTL_GET_REPARSE_POINT
:
1890 /* pretend this fail - my winXP does it like this
1894 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1895 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
1898 case FSCTL_SET_REPARSE_POINT
:
1899 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1903 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1904 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
1907 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
1910 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1911 * and return their volume names. If max_data_count is 16, then it is just
1912 * asking for the number of volumes and length of the combined names.
1914 * pdata is the data allocated by our caller, but that uses
1915 * total_data_count (which is 0 in our case) rather than max_data_count.
1916 * Allocate the correct amount and return the pointer to let
1917 * it be deallocated when we return.
1919 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
1920 SHADOW_COPY_DATA
*shadow_data
= NULL
;
1921 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
1922 BOOL labels
= False
;
1923 uint32 labels_data_count
= 0;
1927 FSP_BELONGS_CONN(fsp
,conn
);
1929 if (max_data_count
< 16) {
1930 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1932 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1935 if (max_data_count
> 16) {
1939 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
1940 if (shadow_mem_ctx
== NULL
) {
1941 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1942 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1945 shadow_data
= (SHADOW_COPY_DATA
*)talloc_zero(shadow_mem_ctx
,sizeof(SHADOW_COPY_DATA
));
1946 if (shadow_data
== NULL
) {
1947 DEBUG(0,("talloc_zero() failed!\n"));
1948 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1951 shadow_data
->mem_ctx
= shadow_mem_ctx
;
1954 * Call the VFS routine to actually do the work.
1956 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
1957 talloc_destroy(shadow_data
->mem_ctx
);
1958 if (errno
== ENOSYS
) {
1959 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1960 conn
->connectpath
));
1961 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1963 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1964 conn
->connectpath
));
1965 return ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
1969 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
1974 data_count
= 12+labels_data_count
+4;
1977 if (max_data_count
<data_count
) {
1978 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1979 max_data_count
,data_count
));
1980 talloc_destroy(shadow_data
->mem_ctx
);
1981 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL
);
1984 pdata
= nttrans_realloc(ppdata
, data_count
);
1985 if (pdata
== NULL
) {
1986 talloc_destroy(shadow_data
->mem_ctx
);
1987 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1992 /* num_volumes 4 bytes */
1993 SIVAL(pdata
,0,shadow_data
->num_volumes
);
1996 /* num_labels 4 bytes */
1997 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2000 /* needed_data_count 4 bytes */
2001 SIVAL(pdata
,8,labels_data_count
);
2005 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2006 shadow_data
->num_volumes
,fsp
->fsp_name
));
2007 if (labels
&& shadow_data
->labels
) {
2008 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2009 srvstr_push(outbuf
, cur_pdata
, shadow_data
->labels
[i
], 2*sizeof(SHADOW_COPY_LABEL
), STR_UNICODE
|STR_TERMINATE
);
2010 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2011 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2015 talloc_destroy(shadow_data
->mem_ctx
);
2017 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, pdata
, data_count
);
2022 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2024 /* pretend this succeeded -
2026 * we have to send back a list with all files owned by this SID
2028 * but I have to check that --metze
2032 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2034 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2036 FSP_BELONGS_CONN(fsp
,conn
);
2038 /* unknown 4 bytes: this is not the length of the sid :-( */
2039 /*unknown = IVAL(pdata,0);*/
2041 sid_parse(pdata
+4,sid_len
,&sid
);
2042 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid
)));
2044 if (!NT_STATUS_IS_OK(sid_to_uid(&sid
, &uid
))) {
2045 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2046 sid_string_static(&sid
),(unsigned long)sid_len
));
2050 /* we can take a look at the find source :-)
2052 * find ./ -uid $uid -name '*' is what we need here
2055 * and send 4bytes len and then NULL terminated unicode strings
2058 * but I don't know how to deal with the paged results
2059 * (maybe we can hang the result anywhere in the fsp struct)
2061 * we don't send all files at once
2062 * and at the next we should *not* start from the beginning,
2063 * so we have to cache the result
2068 /* this works for now... */
2069 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2073 if (!logged_message
) {
2074 logged_message
= True
; /* Only print this once... */
2075 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2080 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2084 #ifdef HAVE_SYS_QUOTAS
2085 /****************************************************************************
2086 Reply to get user quota
2087 ****************************************************************************/
2089 static int call_nt_transact_get_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2090 char **ppsetup
, uint32 setup_count
,
2091 char **ppparams
, uint32 parameter_count
,
2092 char **ppdata
, uint32 data_count
)
2094 NTSTATUS nt_status
= NT_STATUS_OK
;
2095 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
2096 char *params
= *ppparams
;
2097 char *pdata
= *ppdata
;
2099 int data_len
=0,param_len
=0;
2102 files_struct
*fsp
= NULL
;
2106 BOOL start_enum
= True
;
2107 SMB_NTQUOTA_STRUCT qt
;
2108 SMB_NTQUOTA_LIST
*tmp_list
;
2109 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2110 extern struct current_user current_user
;
2115 if (current_user
.uid
!= 0) {
2116 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2117 lp_servicename(SNUM(conn
)),conn
->user
));
2118 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2122 * Ensure minimum number of parameters sent.
2125 if (parameter_count
< 4) {
2126 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2127 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2130 /* maybe we can check the quota_fnum */
2131 fsp
= file_fsp(params
,0);
2132 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2133 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2134 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2137 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2138 * is done by CHECK_NTQUOTA_HANDLE_OK()
2140 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
2142 level
= SVAL(params
,2);
2144 /* unknown 12 bytes leading in params */
2147 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2148 /* seems that we should continue with the enum here --metze */
2150 if (qt_handle
->quota_list
!=NULL
&&
2151 qt_handle
->tmp_list
==NULL
) {
2154 free_ntquota_list(&(qt_handle
->quota_list
));
2156 /* Realloc the size of parameters and data we will return */
2158 params
= nttrans_realloc(ppparams
, param_len
);
2160 return ERROR_DOS(ERRDOS
,ERRnomem
);
2163 SIVAL(params
,0,data_len
);
2170 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2172 if (qt_handle
->quota_list
==NULL
&&
2173 qt_handle
->tmp_list
==NULL
) {
2177 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0)
2178 return ERROR_DOS(ERRSRV
,ERRerror
);
2180 /* Realloc the size of parameters and data we will return */
2182 params
= nttrans_realloc(ppparams
, param_len
);
2184 return ERROR_DOS(ERRDOS
,ERRnomem
);
2186 /* we should not trust the value in max_data_count*/
2187 max_data_count
= MIN(max_data_count
,2048);
2189 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2191 return ERROR_DOS(ERRDOS
,ERRnomem
);
2196 /* set params Size of returned Quota Data 4 bytes*/
2197 /* but set it later when we know it */
2199 /* for each entry push the data */
2202 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2205 tmp_list
= qt_handle
->tmp_list
;
2207 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2208 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2210 sid_len
= sid_size(&tmp_list
->quotas
->sid
);
2211 entry_len
= 40 + sid_len
;
2213 /* nextoffset entry 4 bytes */
2214 SIVAL(entry
,0,entry_len
);
2216 /* then the len of the SID 4 bytes */
2217 SIVAL(entry
,4,sid_len
);
2219 /* unknown data 8 bytes SMB_BIG_UINT */
2220 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2222 /* the used disk space 8 bytes SMB_BIG_UINT */
2223 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2225 /* the soft quotas 8 bytes SMB_BIG_UINT */
2226 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2228 /* the hard quotas 8 bytes SMB_BIG_UINT */
2229 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2231 /* and now the SID */
2232 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2235 qt_handle
->tmp_list
= tmp_list
;
2237 /* overwrite the offset of the last entry */
2238 SIVAL(entry
-entry_len
,0,0);
2240 data_len
= 4+qt_len
;
2241 /* overwrite the params quota_data_len */
2242 SIVAL(params
,0,data_len
);
2246 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2248 /* unknown 4 bytes IVAL(pdata,0) */
2250 if (data_count
< 8) {
2251 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2252 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2255 sid_len
= IVAL(pdata
,4);
2257 if (data_count
< 8+sid_len
) {
2258 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2259 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2262 data_len
= 4+40+sid_len
;
2264 if (max_data_count
< data_len
) {
2265 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2266 max_data_count
, data_len
));
2268 SIVAL(params
,0,data_len
);
2270 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2274 sid_parse(pdata
+8,sid_len
,&sid
);
2277 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2280 * we have to return zero's in all fields
2281 * instead of returning an error here
2286 /* Realloc the size of parameters and data we will return */
2288 params
= nttrans_realloc(ppparams
, param_len
);
2290 return ERROR_DOS(ERRDOS
,ERRnomem
);
2292 pdata
= nttrans_realloc(ppdata
, data_len
);
2294 return ERROR_DOS(ERRDOS
,ERRnomem
);
2298 /* set params Size of returned Quota Data 4 bytes*/
2299 SIVAL(params
,0,data_len
);
2301 /* nextoffset entry 4 bytes */
2304 /* then the len of the SID 4 bytes */
2305 SIVAL(entry
,4,sid_len
);
2307 /* unknown data 8 bytes SMB_BIG_UINT */
2308 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2310 /* the used disk space 8 bytes SMB_BIG_UINT */
2311 SBIG_UINT(entry
,16,qt
.usedspace
);
2313 /* the soft quotas 8 bytes SMB_BIG_UINT */
2314 SBIG_UINT(entry
,24,qt
.softlim
);
2316 /* the hard quotas 8 bytes SMB_BIG_UINT */
2317 SBIG_UINT(entry
,32,qt
.hardlim
);
2319 /* and now the SID */
2320 sid_linearize(entry
+40, sid_len
, &sid
);
2325 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2326 return ERROR_DOS(ERRSRV
,ERRerror
);
2330 send_nt_replies(inbuf
, outbuf
, bufsize
, nt_status
, params
, param_len
, pdata
, data_len
);
2335 /****************************************************************************
2336 Reply to set user quota
2337 ****************************************************************************/
2339 static int call_nt_transact_set_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2340 char **ppsetup
, uint32 setup_count
,
2341 char **ppparams
, uint32 parameter_count
,
2342 char **ppdata
, uint32 data_count
)
2344 char *params
= *ppparams
;
2345 char *pdata
= *ppdata
;
2346 int data_len
=0,param_len
=0;
2347 SMB_NTQUOTA_STRUCT qt
;
2350 files_struct
*fsp
= NULL
;
2355 if (current_user
.uid
!= 0) {
2356 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2357 lp_servicename(SNUM(conn
)),conn
->user
));
2358 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2362 * Ensure minimum number of parameters sent.
2365 if (parameter_count
< 2) {
2366 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2367 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2370 /* maybe we can check the quota_fnum */
2371 fsp
= file_fsp(params
,0);
2372 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2373 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2374 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2377 if (data_count
< 40) {
2378 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2379 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2382 /* offset to next quota record.
2383 * 4 bytes IVAL(pdata,0)
2388 sid_len
= IVAL(pdata
,4);
2390 if (data_count
< 40+sid_len
) {
2391 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2392 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2395 /* unknown 8 bytes in pdata
2396 * maybe its the change time in NTTIME
2399 /* the used space 8 bytes (SMB_BIG_UINT)*/
2400 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2401 #ifdef LARGE_SMB_OFF_T
2402 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2403 #else /* LARGE_SMB_OFF_T */
2404 if ((IVAL(pdata
,20) != 0)&&
2405 ((qt
.usedspace
!= 0xFFFFFFFF)||
2406 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2407 /* more than 32 bits? */
2408 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2410 #endif /* LARGE_SMB_OFF_T */
2412 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2413 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2414 #ifdef LARGE_SMB_OFF_T
2415 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2416 #else /* LARGE_SMB_OFF_T */
2417 if ((IVAL(pdata
,28) != 0)&&
2418 ((qt
.softlim
!= 0xFFFFFFFF)||
2419 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2420 /* more than 32 bits? */
2421 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2423 #endif /* LARGE_SMB_OFF_T */
2425 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2426 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2427 #ifdef LARGE_SMB_OFF_T
2428 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2429 #else /* LARGE_SMB_OFF_T */
2430 if ((IVAL(pdata
,36) != 0)&&
2431 ((qt
.hardlim
!= 0xFFFFFFFF)||
2432 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2433 /* more than 32 bits? */
2434 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2436 #endif /* LARGE_SMB_OFF_T */
2438 sid_parse(pdata
+40,sid_len
,&sid
);
2439 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid
)));
2441 /* 44 unknown bytes left... */
2443 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2444 return ERROR_DOS(ERRSRV
,ERRerror
);
2447 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, pdata
, data_len
);
2451 #endif /* HAVE_SYS_QUOTAS */
2453 /****************************************************************************
2454 Reply to a SMBNTtrans.
2455 ****************************************************************************/
2457 int reply_nttrans(connection_struct
*conn
,
2458 char *inbuf
,char *outbuf
,int length
,int bufsize
)
2461 #if 0 /* Not used. */
2462 uint16 max_setup_count
= CVAL(inbuf
, smb_nt_MaxSetupCount
);
2463 uint32 max_parameter_count
= IVAL(inbuf
, smb_nt_MaxParameterCount
);
2464 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
2465 #endif /* Not used. */
2466 uint32 total_parameter_count
= IVAL(inbuf
, smb_nt_TotalParameterCount
);
2467 uint32 total_data_count
= IVAL(inbuf
, smb_nt_TotalDataCount
);
2468 uint32 parameter_count
= IVAL(inbuf
,smb_nt_ParameterCount
);
2469 uint32 parameter_offset
= IVAL(inbuf
,smb_nt_ParameterOffset
);
2470 uint32 data_count
= IVAL(inbuf
,smb_nt_DataCount
);
2471 uint32 data_offset
= IVAL(inbuf
,smb_nt_DataOffset
);
2472 uint16 setup_count
= 2*CVAL(inbuf
,smb_nt_SetupCount
); /* setup count is in *words* */
2473 uint16 function_code
= SVAL( inbuf
, smb_nt_Function
);
2474 char *params
= NULL
, *data
= NULL
, *setup
= NULL
;
2475 uint32 num_params_sofar
, num_data_sofar
;
2476 START_PROFILE(SMBnttrans
);
2478 if(global_oplock_break
&&
2479 ((function_code
== NT_TRANSACT_CREATE
) ||
2480 (function_code
== NT_TRANSACT_RENAME
))) {
2482 * Queue this open message as we are the process of an oplock break.
2485 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2486 due to being in oplock break state.\n", (unsigned int)function_code
));
2488 push_oplock_pending_smb_message( inbuf
, length
);
2489 END_PROFILE(SMBnttrans
);
2493 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2494 END_PROFILE(SMBnttrans
);
2495 return ERROR_DOS(ERRSRV
,ERRaccess
);
2498 outsize
= set_message(outbuf
,0,0,True
);
2501 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2502 * Ensure this is so as a sanity check.
2505 if(CVAL(inbuf
, smb_wct
) != 19 + (setup_count
/2)) {
2506 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2507 CVAL(inbuf
, smb_wct
), 19 + (setup_count
/2)));
2511 /* Allocate the space for the setup, the maximum needed parameters and data */
2514 setup
= (char *)malloc(setup_count
);
2515 if (total_parameter_count
> 0)
2516 params
= (char *)malloc(total_parameter_count
);
2517 if (total_data_count
> 0)
2518 data
= (char *)malloc(total_data_count
);
2520 if ((total_parameter_count
&& !params
) || (total_data_count
&& !data
) ||
2521 (setup_count
&& !setup
)) {
2525 DEBUG(0,("reply_nttrans : Out of memory\n"));
2526 END_PROFILE(SMBnttrans
);
2527 return ERROR_DOS(ERRDOS
,ERRnomem
);
2530 /* Copy the param and data bytes sent with this request into the params buffer */
2531 num_params_sofar
= parameter_count
;
2532 num_data_sofar
= data_count
;
2534 if (parameter_count
> total_parameter_count
|| data_count
> total_data_count
)
2538 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count
));
2539 if ((smb_nt_SetupStart
+ setup_count
< smb_nt_SetupStart
) ||
2540 (smb_nt_SetupStart
+ setup_count
< setup_count
))
2542 if (smb_nt_SetupStart
+ setup_count
> length
)
2545 memcpy( setup
, &inbuf
[smb_nt_SetupStart
], setup_count
);
2546 dump_data(10, setup
, setup_count
);
2549 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count
));
2550 if ((parameter_offset
+ parameter_count
< parameter_offset
) ||
2551 (parameter_offset
+ parameter_count
< parameter_count
))
2553 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
> inbuf
+ length
)||
2554 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
)))
2557 memcpy( params
, smb_base(inbuf
) + parameter_offset
, parameter_count
);
2558 dump_data(10, params
, parameter_count
);
2561 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count
));
2562 if ((data_offset
+ data_count
< data_offset
) || (data_offset
+ data_count
< data_count
))
2564 if ((smb_base(inbuf
) + data_offset
+ data_count
> inbuf
+ length
) ||
2565 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
)))
2568 memcpy( data
, smb_base(inbuf
) + data_offset
, data_count
);
2569 dump_data(10, data
, data_count
);
2572 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2574 if(num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2575 /* We need to send an interim response then receive the rest
2576 of the parameter/data bytes */
2577 outsize
= set_message(outbuf
,0,0,True
);
2578 srv_signing_trans_stop();
2579 if (!send_smb(smbd_server_fd(),outbuf
))
2580 exit_server("reply_nttrans: send_smb failed.");
2582 while( num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2584 uint32 parameter_displacement
;
2585 uint32 data_displacement
;
2587 ret
= receive_next_smb(inbuf
,bufsize
,SMB_SECONDARY_WAIT
);
2590 * The sequence number for the trans reply is always
2591 * based on the last secondary received.
2594 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2596 if((ret
&& (CVAL(inbuf
, smb_com
) != SMBnttranss
)) || !ret
) {
2597 outsize
= set_message(outbuf
,0,0,True
);
2599 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2601 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2602 (smb_read_error
== READ_ERROR
) ? "error" : "timeout" ));
2607 /* Revise total_params and total_data in case they have changed downwards */
2608 if (IVAL(inbuf
, smb_nts_TotalParameterCount
) < total_parameter_count
)
2609 total_parameter_count
= IVAL(inbuf
, smb_nts_TotalParameterCount
);
2610 if (IVAL(inbuf
, smb_nts_TotalDataCount
) < total_data_count
)
2611 total_data_count
= IVAL(inbuf
, smb_nts_TotalDataCount
);
2613 parameter_count
= IVAL(inbuf
,smb_nts_ParameterCount
);
2614 parameter_offset
= IVAL(inbuf
, smb_nts_ParameterOffset
);
2615 parameter_displacement
= IVAL(inbuf
, smb_nts_ParameterDisplacement
);
2616 num_params_sofar
+= parameter_count
;
2618 data_count
= IVAL(inbuf
, smb_nts_DataCount
);
2619 data_displacement
= IVAL(inbuf
, smb_nts_DataDisplacement
);
2620 data_offset
= IVAL(inbuf
, smb_nts_DataOffset
);
2621 num_data_sofar
+= data_count
;
2623 if (num_params_sofar
> total_parameter_count
|| num_data_sofar
> total_data_count
) {
2624 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2628 if (parameter_count
) {
2629 if (parameter_displacement
+ parameter_count
>= total_parameter_count
)
2631 if ((parameter_displacement
+ parameter_count
< parameter_displacement
) ||
2632 (parameter_displacement
+ parameter_count
< parameter_count
))
2634 if (parameter_displacement
> total_parameter_count
)
2636 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
>= inbuf
+ bufsize
) ||
2637 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
)))
2639 if (parameter_displacement
+ params
< params
)
2642 memcpy( ¶ms
[parameter_displacement
], smb_base(inbuf
) + parameter_offset
, parameter_count
);
2646 if (data_displacement
+ data_count
>= total_data_count
)
2648 if ((data_displacement
+ data_count
< data_displacement
) ||
2649 (data_displacement
+ data_count
< data_count
))
2651 if (data_displacement
> total_data_count
)
2653 if ((smb_base(inbuf
) + data_offset
+ data_count
>= inbuf
+ bufsize
) ||
2654 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
)))
2656 if (data_displacement
+ data
< data
)
2659 memcpy( &data
[data_displacement
], smb_base(inbuf
)+ data_offset
, data_count
);
2664 if (Protocol
>= PROTOCOL_NT1
)
2665 SSVAL(outbuf
,smb_flg2
,SVAL(outbuf
,smb_flg2
) | FLAGS2_IS_LONG_NAME
);
2667 /* Now we must call the relevant NT_TRANS function */
2668 switch(function_code
) {
2669 case NT_TRANSACT_CREATE
:
2670 START_PROFILE_NESTED(NT_transact_create
);
2671 outsize
= call_nt_transact_create(conn
, inbuf
, outbuf
,
2673 &setup
, setup_count
,
2674 ¶ms
, total_parameter_count
,
2675 &data
, total_data_count
);
2676 END_PROFILE_NESTED(NT_transact_create
);
2678 case NT_TRANSACT_IOCTL
:
2679 START_PROFILE_NESTED(NT_transact_ioctl
);
2680 outsize
= call_nt_transact_ioctl(conn
, inbuf
, outbuf
,
2682 &setup
, setup_count
,
2683 ¶ms
, total_parameter_count
,
2684 &data
, total_data_count
);
2685 END_PROFILE_NESTED(NT_transact_ioctl
);
2687 case NT_TRANSACT_SET_SECURITY_DESC
:
2688 START_PROFILE_NESTED(NT_transact_set_security_desc
);
2689 outsize
= call_nt_transact_set_security_desc(conn
, inbuf
, outbuf
,
2691 &setup
, setup_count
,
2692 ¶ms
, total_parameter_count
,
2693 &data
, total_data_count
);
2694 END_PROFILE_NESTED(NT_transact_set_security_desc
);
2696 case NT_TRANSACT_NOTIFY_CHANGE
:
2697 START_PROFILE_NESTED(NT_transact_notify_change
);
2698 outsize
= call_nt_transact_notify_change(conn
, inbuf
, outbuf
,
2700 &setup
, setup_count
,
2701 ¶ms
, total_parameter_count
,
2702 &data
, total_data_count
);
2703 END_PROFILE_NESTED(NT_transact_notify_change
);
2705 case NT_TRANSACT_RENAME
:
2706 START_PROFILE_NESTED(NT_transact_rename
);
2707 outsize
= call_nt_transact_rename(conn
, inbuf
, outbuf
,
2709 &setup
, setup_count
,
2710 ¶ms
, total_parameter_count
,
2711 &data
, total_data_count
);
2712 END_PROFILE_NESTED(NT_transact_rename
);
2715 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2716 START_PROFILE_NESTED(NT_transact_query_security_desc
);
2717 outsize
= call_nt_transact_query_security_desc(conn
, inbuf
, outbuf
,
2719 &setup
, setup_count
,
2720 ¶ms
, total_parameter_count
,
2721 &data
, total_data_count
);
2722 END_PROFILE_NESTED(NT_transact_query_security_desc
);
2724 #ifdef HAVE_SYS_QUOTAS
2725 case NT_TRANSACT_GET_USER_QUOTA
:
2726 START_PROFILE_NESTED(NT_transact_get_user_quota
);
2727 outsize
= call_nt_transact_get_user_quota(conn
, inbuf
, outbuf
,
2729 &setup
, setup_count
,
2730 ¶ms
, total_parameter_count
,
2731 &data
, total_data_count
);
2732 END_PROFILE_NESTED(NT_transact_get_user_quota
);
2734 case NT_TRANSACT_SET_USER_QUOTA
:
2735 START_PROFILE_NESTED(NT_transact_set_user_quota
);
2736 outsize
= call_nt_transact_set_user_quota(conn
, inbuf
, outbuf
,
2738 &setup
, setup_count
,
2739 ¶ms
, total_parameter_count
,
2740 &data
, total_data_count
);
2741 END_PROFILE_NESTED(NT_transact_set_user_quota
);
2743 #endif /* HAVE_SYS_QUOTAS */
2745 /* Error in request */
2746 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code
));
2750 END_PROFILE(SMBnttrans
);
2751 srv_signing_trans_stop();
2752 return ERROR_DOS(ERRSRV
,ERRerror
);
2755 /* As we do not know how many data packets will need to be
2756 returned here the various call_nt_transact_xxxx calls
2757 must send their own. Thus a call_nt_transact_xxxx routine only
2758 returns a value other than -1 when it wants to send
2762 srv_signing_trans_stop();
2767 END_PROFILE(SMBnttrans
);
2768 return outsize
; /* If a correct response was needed the call_nt_transact_xxxx
2769 calls have already sent it. If outsize != -1 then it is
2770 returning an error packet. */
2774 srv_signing_trans_stop();
2778 END_PROFILE(SMBnttrans
);
2779 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);