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.
24 extern enum protocol_types Protocol
;
25 extern int smb_read_error
;
26 extern int global_oplock_break
;
27 extern struct current_user current_user
;
29 static const char *known_nt_pipes
[] = {
46 /* Map generic permissions to file object specific permissions */
48 struct generic_mapping file_generic_mapping
= {
55 static char *nttrans_realloc(char **ptr
, size_t size
)
59 smb_panic("nttrans_realloc() called with NULL ptr\n");
61 tptr
= SMB_REALLOC(*ptr
, size
);
66 memset(tptr
,'\0',size
);
74 /****************************************************************************
75 Send the required number of replies back.
76 We assume all fields other than the data fields are
77 set correctly for the type of call.
78 HACK ! Always assumes smb_setup field is zero.
79 ****************************************************************************/
81 static int send_nt_replies(char *inbuf
, char *outbuf
, int bufsize
, NTSTATUS nt_error
, char *params
,
82 int paramsize
, char *pdata
, int datasize
)
85 int data_to_send
= datasize
;
86 int params_to_send
= paramsize
;
90 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
91 int alignment_offset
= 3;
92 int data_alignment_offset
= 0;
95 * Initially set the wcnt area to be 18 - this is true for all
99 set_message(outbuf
,18,0,True
);
101 if (NT_STATUS_V(nt_error
))
105 * If there genuinely are no parameters or data to send just send
109 if(params_to_send
== 0 && data_to_send
== 0) {
110 if (!send_smb(smbd_server_fd(),outbuf
))
111 exit_server("send_nt_replies: send_smb failed.");
116 * When sending params and data ensure that both are nicely aligned.
117 * Only do this alignment when there is also data to send - else
118 * can cause NT redirector problems.
121 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0))
122 data_alignment_offset
= 4 - (params_to_send
% 4);
125 * Space is bufsize minus Netbios over TCP header minus SMB header.
126 * The alignment_offset is to align the param bytes on a four byte
127 * boundary (2 bytes for data len, one byte pad).
128 * NT needs this to work correctly.
131 useable_space
= bufsize
- ((smb_buf(outbuf
)+
132 alignment_offset
+data_alignment_offset
) -
136 * useable_space can never be more than max_send minus the
140 useable_space
= MIN(useable_space
,
141 max_send
- (alignment_offset
+data_alignment_offset
));
144 while (params_to_send
|| data_to_send
) {
147 * Calculate whether we will totally or partially fill this packet.
150 total_sent_thistime
= params_to_send
+ data_to_send
+
151 alignment_offset
+ data_alignment_offset
;
154 * We can never send more than useable_space.
157 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
159 set_message(outbuf
, 18, total_sent_thistime
, True
);
162 * Set total params and data to be sent.
165 SIVAL(outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
166 SIVAL(outbuf
,smb_ntr_TotalDataCount
,datasize
);
169 * Calculate how many parameters and data we can fit into
170 * this packet. Parameters get precedence.
173 params_sent_thistime
= MIN(params_to_send
,useable_space
);
174 data_sent_thistime
= useable_space
- params_sent_thistime
;
175 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
177 SIVAL(outbuf
,smb_ntr_ParameterCount
,params_sent_thistime
);
179 if(params_sent_thistime
== 0) {
180 SIVAL(outbuf
,smb_ntr_ParameterOffset
,0);
181 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,0);
184 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
185 * parameter bytes, however the first 4 bytes of outbuf are
186 * the Netbios over TCP header. Thus use smb_base() to subtract
187 * them from the calculation.
190 SIVAL(outbuf
,smb_ntr_ParameterOffset
,
191 ((smb_buf(outbuf
)+alignment_offset
) - smb_base(outbuf
)));
193 * Absolute displacement of param bytes sent in this packet.
196 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,pp
- params
);
200 * Deal with the data portion.
203 SIVAL(outbuf
,smb_ntr_DataCount
, data_sent_thistime
);
205 if(data_sent_thistime
== 0) {
206 SIVAL(outbuf
,smb_ntr_DataOffset
,0);
207 SIVAL(outbuf
,smb_ntr_DataDisplacement
, 0);
210 * The offset of the data bytes is the offset of the
211 * parameter bytes plus the number of parameters being sent this time.
214 SIVAL(outbuf
,smb_ntr_DataOffset
,((smb_buf(outbuf
)+alignment_offset
) -
215 smb_base(outbuf
)) + params_sent_thistime
+ data_alignment_offset
);
216 SIVAL(outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
220 * Copy the param bytes into the packet.
223 if(params_sent_thistime
)
224 memcpy((smb_buf(outbuf
)+alignment_offset
),pp
,params_sent_thistime
);
227 * Copy in the data bytes
230 if(data_sent_thistime
)
231 memcpy(smb_buf(outbuf
)+alignment_offset
+params_sent_thistime
+
232 data_alignment_offset
,pd
,data_sent_thistime
);
234 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
235 params_sent_thistime
, data_sent_thistime
, useable_space
));
236 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
237 params_to_send
, data_to_send
, paramsize
, datasize
));
239 /* Send the packet */
240 if (!send_smb(smbd_server_fd(),outbuf
))
241 exit_server("send_nt_replies: send_smb failed.");
243 pp
+= params_sent_thistime
;
244 pd
+= data_sent_thistime
;
246 params_to_send
-= params_sent_thistime
;
247 data_to_send
-= data_sent_thistime
;
253 if(params_to_send
< 0 || data_to_send
< 0) {
254 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
255 params_to_send
, data_to_send
));
263 /****************************************************************************
265 ****************************************************************************/
267 static BOOL saved_case_sensitive
;
268 static BOOL saved_case_preserve
;
269 static BOOL saved_short_case_preserve
;
271 /****************************************************************************
273 ****************************************************************************/
275 static void set_posix_case_semantics(connection_struct
*conn
, uint32 file_attributes
)
277 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
))
280 saved_case_sensitive
= conn
->case_sensitive
;
281 saved_case_preserve
= conn
->case_preserve
;
282 saved_short_case_preserve
= conn
->short_case_preserve
;
285 conn
->case_sensitive
= True
;
286 conn
->case_preserve
= True
;
287 conn
->short_case_preserve
= True
;
290 /****************************************************************************
291 Restore case semantics.
292 ****************************************************************************/
294 static void restore_case_semantics(connection_struct
*conn
, uint32 file_attributes
)
296 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
))
299 conn
->case_sensitive
= saved_case_sensitive
;
300 conn
->case_preserve
= saved_case_preserve
;
301 conn
->short_case_preserve
= saved_short_case_preserve
;
304 /****************************************************************************
305 Utility function to map create disposition.
306 ****************************************************************************/
308 static int map_create_disposition( uint32 create_disposition
)
312 switch( create_disposition
) {
314 /* create if not exist, fail if exist */
315 ret
= (FILE_CREATE_IF_NOT_EXIST
|FILE_EXISTS_FAIL
);
318 case FILE_OVERWRITE_IF
:
319 /* create if not exist, trunc if exist */
320 ret
= (FILE_CREATE_IF_NOT_EXIST
|FILE_EXISTS_TRUNCATE
);
323 /* fail if not exist, open if exists */
324 ret
= (FILE_FAIL_IF_NOT_EXIST
|FILE_EXISTS_OPEN
);
327 /* create if not exist, open if exists */
328 ret
= (FILE_CREATE_IF_NOT_EXIST
|FILE_EXISTS_OPEN
);
331 /* fail if not exist, truncate if exists */
332 ret
= (FILE_FAIL_IF_NOT_EXIST
|FILE_EXISTS_TRUNCATE
);
335 DEBUG(0,("map_create_disposition: Incorrect value for create_disposition = %d\n",
336 create_disposition
));
340 DEBUG(10,("map_create_disposition: Mapped create_disposition 0x%lx to 0x%x\n",
341 (unsigned long)create_disposition
, ret
));
346 /****************************************************************************
347 Utility function to map share modes.
348 ****************************************************************************/
350 static int map_share_mode( char *fname
, uint32 create_options
,
351 uint32
*desired_access
, uint32 share_access
, uint32 file_attributes
)
353 int smb_open_mode
= -1;
354 uint32 original_desired_access
= *desired_access
;
357 * Convert GENERIC bits to specific bits.
360 se_map_generic(desired_access
, &file_generic_mapping
);
362 switch( *desired_access
& (FILE_READ_DATA
|FILE_WRITE_DATA
|FILE_APPEND_DATA
) ) {
364 smb_open_mode
= DOS_OPEN_RDONLY
;
366 case FILE_WRITE_DATA
:
367 case FILE_APPEND_DATA
:
368 case FILE_WRITE_DATA
|FILE_APPEND_DATA
:
369 smb_open_mode
= DOS_OPEN_WRONLY
;
371 case FILE_READ_DATA
|FILE_WRITE_DATA
:
372 case FILE_READ_DATA
|FILE_WRITE_DATA
|FILE_APPEND_DATA
:
373 case FILE_READ_DATA
|FILE_APPEND_DATA
:
374 smb_open_mode
= DOS_OPEN_RDWR
;
379 * NB. For DELETE_ACCESS we should really check the
380 * directory permissions, as that is what controls
381 * delete, and for WRITE_DAC_ACCESS we should really
382 * check the ownership, as that is what controls the
383 * chmod. Note that this is *NOT* a security hole (this
384 * note is for you, Andrew) as we are not *allowing*
385 * the access at this point, the actual unlink or
386 * chown or chmod call would do this. We are just helping
387 * clients out by telling them if they have a hope
388 * of any of this succeeding. POSIX acls may still
389 * deny the real call. JRA.
392 if (smb_open_mode
== -1) {
394 if(*desired_access
& (DELETE_ACCESS
|WRITE_DAC_ACCESS
|WRITE_OWNER_ACCESS
|SYNCHRONIZE_ACCESS
|
395 FILE_EXECUTE
|FILE_READ_ATTRIBUTES
|
396 FILE_READ_EA
|FILE_WRITE_EA
|SYSTEM_SECURITY_ACCESS
|
397 FILE_WRITE_ATTRIBUTES
|READ_CONTROL_ACCESS
)) {
398 smb_open_mode
= DOS_OPEN_RDONLY
;
399 } else if(*desired_access
== 0) {
402 * JRA - NT seems to sometimes send desired_access as zero. play it safe
403 * and map to a stat open.
406 smb_open_mode
= DOS_OPEN_RDONLY
;
409 DEBUG(0,("map_share_mode: Incorrect value 0x%lx for desired_access to file %s\n",
410 (unsigned long)*desired_access
, fname
));
416 * Set the special bit that means allow share delete.
417 * This is held outside the normal share mode bits at 1<<15.
421 if(share_access
& FILE_SHARE_DELETE
) {
422 smb_open_mode
|= ALLOW_SHARE_DELETE
;
423 DEBUG(10,("map_share_mode: FILE_SHARE_DELETE requested. open_mode = 0x%x\n", smb_open_mode
));
426 if(*desired_access
& DELETE_ACCESS
) {
427 DEBUG(10,("map_share_mode: DELETE_ACCESS requested. open_mode = 0x%x\n", smb_open_mode
));
431 * We need to store the intent to open for Delete. This
432 * is what determines if a delete on close flag can be set.
433 * This is the wrong way (and place) to store this, but for 2.2 this
434 * is the only practical way. JRA.
437 if (create_options
& FILE_DELETE_ON_CLOSE
) {
439 * W2K3 bug compatibility mode... To set delete on close
440 * the redirector must have *specifically* set DELETE_ACCESS
441 * in the desired_access field. Just asking for GENERIC_ALL won't do. JRA.
444 if (!(original_desired_access
& DELETE_ACCESS
)) {
445 DEBUG(5,("map_share_mode: FILE_DELETE_ON_CLOSE requested without \
446 DELETE_ACCESS for file %s. (desired_access = 0x%lx)\n",
447 fname
, (unsigned long)*desired_access
));
450 /* Implicit delete access is *NOT* requested... */
451 smb_open_mode
|= DELETE_ON_CLOSE_FLAG
;
452 DEBUG(10,("map_share_mode: FILE_DELETE_ON_CLOSE requested. open_mode = 0x%x\n", smb_open_mode
));
455 /* Add in the requested share mode. */
456 switch( share_access
& (FILE_SHARE_READ
|FILE_SHARE_WRITE
)) {
457 case FILE_SHARE_READ
:
458 smb_open_mode
|= SET_DENY_MODE(DENY_WRITE
);
460 case FILE_SHARE_WRITE
:
461 smb_open_mode
|= SET_DENY_MODE(DENY_READ
);
463 case (FILE_SHARE_READ
|FILE_SHARE_WRITE
):
464 smb_open_mode
|= SET_DENY_MODE(DENY_NONE
);
466 case FILE_SHARE_NONE
:
467 smb_open_mode
|= SET_DENY_MODE(DENY_ALL
);
472 * Handle an O_SYNC request.
475 if(file_attributes
& FILE_FLAG_WRITE_THROUGH
)
476 smb_open_mode
|= FILE_SYNC_OPENMODE
;
478 DEBUG(10,("map_share_mode: Mapped desired access 0x%lx, share access 0x%lx, file attributes 0x%lx \
479 to open_mode 0x%x\n", (unsigned long)*desired_access
, (unsigned long)share_access
,
480 (unsigned long)file_attributes
, smb_open_mode
));
482 return smb_open_mode
;
485 /****************************************************************************
486 Reply to an NT create and X call on a pipe.
487 ****************************************************************************/
489 static int nt_open_pipe(char *fname
, connection_struct
*conn
,
490 char *inbuf
, char *outbuf
, int *ppnum
)
492 smb_np_struct
*p
= NULL
;
494 uint16 vuid
= SVAL(inbuf
, smb_uid
);
497 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
499 /* See if it is one we want to handle. */
501 if (lp_disable_spoolss() && strequal(fname
, "\\spoolss"))
502 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
504 for( i
= 0; known_nt_pipes
[i
]; i
++ )
505 if( strequal(fname
,known_nt_pipes
[i
]))
508 if ( known_nt_pipes
[i
] == NULL
)
509 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
511 /* Strip \\ off the name. */
514 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname
));
516 p
= open_rpc_pipe_p(fname
, conn
, vuid
);
518 return(ERROR_DOS(ERRSRV
,ERRnofids
));
525 /****************************************************************************
526 Reply to an NT create and X call for pipes.
527 ****************************************************************************/
529 static int do_ntcreate_pipe_open(connection_struct
*conn
,
530 char *inbuf
,char *outbuf
,int length
,int bufsize
)
537 srvstr_pull_buf(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
);
539 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
543 * Deal with pipe return.
546 set_message(outbuf
,34,0,True
);
548 p
= outbuf
+ smb_vwv2
;
552 SIVAL(p
,0,FILE_WAS_OPENED
);
555 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
558 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
560 SSVAL(p
,2, 0x5FF); /* ? */
562 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
564 return chain_reply(inbuf
,outbuf
,length
,bufsize
);
567 /****************************************************************************
568 Reply to an NT create and X call.
569 ****************************************************************************/
571 int reply_ntcreate_and_X(connection_struct
*conn
,
572 char *inbuf
,char *outbuf
,int length
,int bufsize
)
576 enum FAKE_FILE_TYPE fake_file_type
= FAKE_FILE_TYPE_NONE
;
577 uint32 flags
= IVAL(inbuf
,smb_ntcreate_Flags
);
578 uint32 desired_access
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
579 uint32 file_attributes
= IVAL(inbuf
,smb_ntcreate_FileAttributes
);
580 uint32 share_access
= IVAL(inbuf
,smb_ntcreate_ShareAccess
);
581 uint32 create_disposition
= IVAL(inbuf
,smb_ntcreate_CreateDisposition
);
582 uint32 create_options
= IVAL(inbuf
,smb_ntcreate_CreateOptions
);
583 uint16 root_dir_fid
= (uint16
)IVAL(inbuf
,smb_ntcreate_RootDirectoryFid
);
584 SMB_BIG_UINT allocation_size
= 0;
587 /* Breakout the oplock request bits so we can set the
588 reply bits separately. */
589 int oplock_request
= 0;
591 SMB_OFF_T file_len
= 0;
592 SMB_STRUCT_STAT sbuf
;
594 BOOL bad_path
= False
;
595 files_struct
*fsp
=NULL
;
598 BOOL extended_oplock_granted
= False
;
601 START_PROFILE(SMBntcreateX
);
603 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
604 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
605 create_options = 0x%x root_dir_fid = 0x%x\n", flags
, desired_access
, file_attributes
,
606 share_access
, create_disposition
,
607 create_options
, root_dir_fid
));
609 /* If it's an IPC, use the pipe handler. */
612 if (lp_nt_pipe_support()) {
613 END_PROFILE(SMBntcreateX
);
614 return do_ntcreate_pipe_open(conn
,inbuf
,outbuf
,length
,bufsize
);
616 END_PROFILE(SMBntcreateX
);
617 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
621 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
622 END_PROFILE(SMBntcreateX
);
623 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
627 * We need to construct the open_and_X ofun value from the
628 * NT values, as that's what our code is structured to accept.
631 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1) {
632 END_PROFILE(SMBntcreateX
);
633 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
640 if(root_dir_fid
!= 0) {
642 * This filename is relative to a directory fid.
645 files_struct
*dir_fsp
= file_fsp(inbuf
,smb_ntcreate_RootDirectoryFid
);
649 END_PROFILE(SMBntcreateX
);
650 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
653 if(!dir_fsp
->is_directory
) {
655 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), 0, STR_TERMINATE
, &status
,False
);
656 if (!NT_STATUS_IS_OK(status
)) {
657 END_PROFILE(SMBntcreateX
);
658 return ERROR_NT(status
);
662 * Check to see if this is a mac fork of some kind.
665 if( strchr_m(fname
, ':')) {
666 END_PROFILE(SMBntcreateX
);
667 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
671 we need to handle the case when we get a
672 relative open relative to a file and the
673 pathname is blank - this is a reopen!
674 (hint from demyn plantenberg)
677 END_PROFILE(SMBntcreateX
);
678 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
682 * Copy in the base directory name.
685 pstrcpy( fname
, dir_fsp
->fsp_name
);
686 dir_name_len
= strlen(fname
);
689 * Ensure it ends in a '\'.
692 if(fname
[dir_name_len
-1] != '\\' && fname
[dir_name_len
-1] != '/') {
697 srvstr_get_path(inbuf
, rel_fname
, smb_buf(inbuf
), sizeof(rel_fname
), 0, STR_TERMINATE
, &status
,False
);
698 if (!NT_STATUS_IS_OK(status
)) {
699 END_PROFILE(SMBntcreateX
);
700 return ERROR_NT(status
);
702 pstrcat(fname
, rel_fname
);
704 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), 0, STR_TERMINATE
, &status
,False
);
705 if (!NT_STATUS_IS_OK(status
)) {
706 END_PROFILE(SMBntcreateX
);
707 return ERROR_NT(status
);
711 * Check to see if this is a mac fork of some kind.
714 if( strchr_m(fname
, ':')) {
716 #ifdef HAVE_SYS_QUOTAS
717 if ((fake_file_type
=is_fake_file(fname
))!=FAKE_FILE_TYPE_NONE
) {
719 * here we go! support for changing the disk quotas --metze
721 * we need to fake up to open this MAGIC QUOTA file
722 * and return a valid FID
724 * w2k close this file directly after openening
725 * xp also tries a QUERY_FILE_INFO on the file and then close it
729 END_PROFILE(SMBntcreateX
);
730 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
731 #ifdef HAVE_SYS_QUOTAS
738 * Now contruct the smb_open_mode value from the filename,
739 * desired access and the share access.
741 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
743 if((smb_open_mode
= map_share_mode(fname
, create_options
, &desired_access
,
745 file_attributes
)) == -1) {
746 END_PROFILE(SMBntcreateX
);
747 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
750 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
751 if (oplock_request
) {
752 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
756 * Ordinary file or directory.
760 * Check if POSIX semantics are wanted.
763 set_posix_case_semantics(conn
, file_attributes
);
765 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
767 /* FAKE_FILE is a special case */
768 if (fake_file_type
== FAKE_FILE_TYPE_NONE
) {
771 restore_case_semantics(conn
, file_attributes
);
772 END_PROFILE(SMBntcreateX
);
773 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
775 /* All file access must go through check_name() */
776 if (!check_name(fname
,conn
)) {
777 restore_case_semantics(conn
, file_attributes
);
778 END_PROFILE(SMBntcreateX
);
779 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRbadpath
);
784 * If it's a request for a directory open, deal with it separately.
787 if(create_options
& FILE_DIRECTORY_FILE
) {
790 /* Can't open a temp directory. IFS kit test. */
791 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
792 END_PROFILE(SMBntcreateX
);
793 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
796 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
798 restore_case_semantics(conn
, file_attributes
);
801 END_PROFILE(SMBntcreateX
);
802 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
806 * Ordinary file case.
809 /* NB. We have a potential bug here. If we
810 * cause an oplock break to ourselves, then we
811 * could end up processing filename related
812 * SMB requests whilst we await the oplock
813 * break response. As we may have changed the
814 * filename case semantics to be POSIX-like,
815 * this could mean a filename request could
816 * fail when it should succeed. This is a rare
817 * condition, but eventually we must arrange
818 * to restore the correct case semantics
819 * before issuing an oplock break request to
820 * our client. JRA. */
822 if (fake_file_type
==FAKE_FILE_TYPE_NONE
) {
823 fsp
= open_file_shared1(conn
,fname
,&sbuf
,
826 smb_ofun
,file_attributes
,oplock_request
,
829 /* to open a fake_file --metze */
830 fsp
= open_fake_file_shared1(fake_file_type
,conn
,fname
,&sbuf
,
833 smb_ofun
,file_attributes
, oplock_request
,
838 /* We cheat here. There are two cases we
839 * care about. One is a directory rename,
840 * where the NT client will attempt to
841 * open the source directory for
842 * DELETE access. Note that when the
843 * NT client does this it does *not*
844 * set the directory bit in the
845 * request packet. This is translated
846 * into a read/write open
847 * request. POSIX states that any open
848 * for write request on a directory
849 * will generate an EISDIR error, so
850 * we can catch this here and open a
851 * pseudo handle that is flagged as a
852 * directory. The second is an open
853 * for a permissions read only, which
854 * we handle in the open_file_stat case. JRA.
857 if(errno
== EISDIR
) {
860 * Fail the open if it was explicitly a non-directory file.
863 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
864 restore_case_semantics(conn
, file_attributes
);
865 SSVAL(outbuf
, smb_flg2
,
866 SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
867 END_PROFILE(SMBntcreateX
);
868 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
872 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
875 restore_case_semantics(conn
, file_attributes
);
876 END_PROFILE(SMBntcreateX
);
877 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
881 restore_case_semantics(conn
, file_attributes
);
882 END_PROFILE(SMBntcreateX
);
883 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
884 /* We have re-scheduled this call. */
885 clear_cached_errors();
888 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
893 restore_case_semantics(conn
, file_attributes
);
895 file_len
= sbuf
.st_size
;
896 fmode
= dos_mode(conn
,fname
,&sbuf
);
898 fmode
= FILE_ATTRIBUTE_NORMAL
;
899 if (!fsp
->is_directory
&& (fmode
& aDIR
)) {
900 close_file(fsp
,False
);
901 END_PROFILE(SMBntcreateX
);
902 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
905 /* Save the requested allocation size. */
906 allocation_size
= (SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
);
907 #ifdef LARGE_SMB_OFF_T
908 allocation_size
|= (((SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
+ 4)) << 32);
910 if (allocation_size
&& (allocation_size
> (SMB_BIG_UINT
)file_len
)) {
911 fsp
->initial_allocation_size
= smb_roundup(allocation_size
);
912 if (fsp
->is_directory
) {
913 close_file(fsp
,False
);
914 END_PROFILE(SMBntcreateX
);
915 /* Can't set allocation size on a directory. */
916 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
918 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
919 close_file(fsp
,False
);
920 END_PROFILE(SMBntcreateX
);
921 return ERROR_NT(NT_STATUS_DISK_FULL
);
924 fsp
->initial_allocation_size
= smb_roundup((SMB_BIG_UINT
)file_len
);
928 * If the caller set the extended oplock request bit
929 * and we granted one (by whatever means) - set the
930 * correct bit for extended oplock reply.
933 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
934 extended_oplock_granted
= True
;
936 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
937 extended_oplock_granted
= True
;
940 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
941 set_message(outbuf
,42,0,True
);
943 set_message(outbuf
,34,0,True
);
946 p
= outbuf
+ smb_vwv2
;
949 * Currently as we don't support level II oplocks we just report
950 * exclusive & batch here.
953 if (extended_oplock_granted
) {
954 if (flags
& REQUEST_BATCH_OPLOCK
) {
955 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
957 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
959 } else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
)) {
960 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
962 SCVAL(p
,0,NO_OPLOCK_RETURN
);
966 SSVAL(p
,0,fsp
->fnum
);
968 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
969 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
971 SIVAL(p
,0,smb_action
);
975 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
977 if (lp_dos_filetime_resolution(SNUM(conn
))) {
984 put_long_date(p
,c_time
);
986 put_long_date(p
,sbuf
.st_atime
); /* access time */
988 put_long_date(p
,sbuf
.st_mtime
); /* write time */
990 put_long_date(p
,sbuf
.st_mtime
); /* change time */
992 SIVAL(p
,0,fmode
); /* File Attributes. */
994 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
996 SOFF_T(p
,0,file_len
);
998 if (flags
& EXTENDED_RESPONSE_REQUIRED
)
1001 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1003 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
1005 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
1006 END_PROFILE(SMBntcreateX
);
1010 /****************************************************************************
1011 Reply to a NT_TRANSACT_CREATE call to open a pipe.
1012 ****************************************************************************/
1014 static int do_nt_transact_create_pipe( connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1015 char **ppsetup
, uint32 setup_count
,
1016 char **ppparams
, uint32 parameter_count
,
1017 char **ppdata
, uint32 data_count
)
1020 char *params
= *ppparams
;
1027 * Ensure minimum number of parameters sent.
1030 if(parameter_count
< 54) {
1031 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1032 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1035 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
1036 if (!NT_STATUS_IS_OK(status
)) {
1037 return ERROR_NT(status
);
1040 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0)
1043 /* Realloc the size of parameters and data we will return */
1044 params
= nttrans_realloc(ppparams
, 69);
1046 return ERROR_DOS(ERRDOS
,ERRnomem
);
1049 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1054 SIVAL(p
,0,FILE_WAS_OPENED
);
1058 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
1061 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
1063 SSVAL(p
,2, 0x5FF); /* ? */
1065 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
1067 /* Send the required number of replies */
1068 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1073 /****************************************************************************
1074 Internal fn to set security descriptors.
1075 ****************************************************************************/
1077 static NTSTATUS
set_sd(files_struct
*fsp
, char *data
, uint32 sd_len
, uint32 security_info_sent
)
1080 SEC_DESC
*psd
= NULL
;
1081 TALLOC_CTX
*mem_ctx
;
1084 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
1085 return NT_STATUS_OK
;
1089 * Init the parse struct we will unmarshall from.
1092 if ((mem_ctx
= talloc_init("set_sd")) == NULL
) {
1093 DEBUG(0,("set_sd: talloc_init failed.\n"));
1094 return NT_STATUS_NO_MEMORY
;
1097 prs_init(&pd
, 0, mem_ctx
, UNMARSHALL
);
1100 * Setup the prs_struct to point at the memory we just
1104 prs_give_memory( &pd
, data
, sd_len
, False
);
1107 * Finally, unmarshall from the data buffer.
1110 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1111 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1113 * Return access denied for want of a better error message..
1115 talloc_destroy(mem_ctx
);
1116 return NT_STATUS_NO_MEMORY
;
1119 if (psd
->off_owner_sid
==0)
1120 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
1121 if (psd
->off_grp_sid
==0)
1122 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
1123 if (psd
->off_sacl
==0)
1124 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
1125 if (psd
->off_dacl
==0)
1126 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
1128 ret
= SMB_VFS_FSET_NT_ACL( fsp
, fsp
->fd
, security_info_sent
, psd
);
1131 talloc_destroy(mem_ctx
);
1132 return NT_STATUS_ACCESS_DENIED
;
1135 talloc_destroy(mem_ctx
);
1137 return NT_STATUS_OK
;
1140 /****************************************************************************
1141 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1142 ****************************************************************************/
1144 static int call_nt_transact_create(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1145 char **ppsetup
, uint32 setup_count
,
1146 char **ppparams
, uint32 parameter_count
,
1147 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1150 char *params
= *ppparams
;
1151 char *data
= *ppdata
;
1152 /* Breakout the oplock request bits so we can set the reply bits separately. */
1153 int oplock_request
= 0;
1154 int fmode
=0,rmode
=0;
1155 SMB_OFF_T file_len
= 0;
1156 SMB_STRUCT_STAT sbuf
;
1158 BOOL bad_path
= False
;
1159 files_struct
*fsp
= NULL
;
1161 BOOL extended_oplock_granted
= False
;
1163 uint32 desired_access
;
1164 uint32 file_attributes
;
1165 uint32 share_access
;
1166 uint32 create_disposition
;
1167 uint32 create_options
;
1169 uint16 root_dir_fid
;
1170 SMB_BIG_UINT allocation_size
= 0;
1176 DEBUG(5,("call_nt_transact_create\n"));
1179 * If it's an IPC, use the pipe handler.
1183 if (lp_nt_pipe_support())
1184 return do_nt_transact_create_pipe(conn
, inbuf
, outbuf
, length
,
1186 ppsetup
, setup_count
,
1187 ppparams
, parameter_count
,
1188 ppdata
, data_count
);
1190 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1194 * Ensure minimum number of parameters sent.
1197 if(parameter_count
< 54) {
1198 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1199 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1202 flags
= IVAL(params
,0);
1203 desired_access
= IVAL(params
,8);
1204 file_attributes
= IVAL(params
,20);
1205 share_access
= IVAL(params
,24);
1206 create_disposition
= IVAL(params
,28);
1207 create_options
= IVAL(params
,32);
1208 sd_len
= IVAL(params
,36);
1209 root_dir_fid
= (uint16
)IVAL(params
,4);
1211 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
1212 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1216 * We need to construct the open_and_X ofun value from the
1217 * NT values, as that's what our code is structured to accept.
1220 if((smb_ofun
= map_create_disposition( create_disposition
)) == -1)
1221 return ERROR_DOS(ERRDOS
,ERRbadmem
);
1224 * Get the file name.
1227 if(root_dir_fid
!= 0) {
1229 * This filename is relative to a directory fid.
1231 files_struct
*dir_fsp
= file_fsp(params
,4);
1232 size_t dir_name_len
;
1235 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1237 if(!dir_fsp
->is_directory
) {
1238 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
1239 if (!NT_STATUS_IS_OK(status
)) {
1240 return ERROR_NT(status
);
1244 * Check to see if this is a mac fork of some kind.
1247 if( strchr_m(fname
, ':'))
1248 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1250 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1254 * Copy in the base directory name.
1257 pstrcpy( fname
, dir_fsp
->fsp_name
);
1258 dir_name_len
= strlen(fname
);
1261 * Ensure it ends in a '\'.
1264 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
1265 pstrcat(fname
, "/");
1271 srvstr_get_path(inbuf
, tmpname
, params
+53, sizeof(tmpname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
1272 if (!NT_STATUS_IS_OK(status
)) {
1273 return ERROR_NT(status
);
1275 pstrcat(fname
, tmpname
);
1278 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
1279 if (!NT_STATUS_IS_OK(status
)) {
1280 return ERROR_NT(status
);
1284 * Check to see if this is a mac fork of some kind.
1287 if( strchr_m(fname
, ':'))
1288 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1292 * Now contruct the smb_open_mode value from the desired access
1293 * and the share access.
1296 if((smb_open_mode
= map_share_mode( fname
, create_options
, &desired_access
,
1297 share_access
, file_attributes
)) == -1)
1298 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1300 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1301 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1304 * Check if POSIX semantics are wanted.
1307 set_posix_case_semantics(conn
, file_attributes
);
1309 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
1311 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
1313 restore_case_semantics(conn
, file_attributes
);
1314 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1316 /* All file access must go through check_name() */
1317 if (!check_name(fname
,conn
)) {
1318 restore_case_semantics(conn
, file_attributes
);
1319 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRbadpath
);
1323 * If it's a request for a directory open, deal with it separately.
1326 if(create_options
& FILE_DIRECTORY_FILE
) {
1328 /* Can't open a temp directory. IFS kit test. */
1329 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
1330 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1336 * We will get a create directory here if the Win32
1337 * app specified a security descriptor in the
1338 * CreateDirectory() call.
1341 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
1344 restore_case_semantics(conn
, file_attributes
);
1345 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1351 * Ordinary file case.
1354 fsp
= open_file_shared1(conn
,fname
,&sbuf
,desired_access
,
1355 smb_open_mode
,smb_ofun
,file_attributes
,
1356 oplock_request
,&rmode
,&smb_action
);
1360 if(errno
== EISDIR
) {
1363 * Fail the open if it was explicitly a non-directory file.
1366 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
1367 restore_case_semantics(conn
, file_attributes
);
1368 SSVAL(outbuf
, smb_flg2
, SVAL(outbuf
,smb_flg2
) | FLAGS2_32_BIT_ERROR_CODES
);
1369 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
1373 fsp
= open_directory(conn
, fname
, &sbuf
, desired_access
, smb_open_mode
, smb_ofun
, &smb_action
);
1376 restore_case_semantics(conn
, file_attributes
);
1377 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1380 restore_case_semantics(conn
, file_attributes
);
1381 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1382 /* We have re-scheduled this call. */
1383 clear_cached_errors();
1386 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1390 file_len
= sbuf
.st_size
;
1391 fmode
= dos_mode(conn
,fname
,&sbuf
);
1393 fmode
= FILE_ATTRIBUTE_NORMAL
;
1396 close_file(fsp
,False
);
1397 restore_case_semantics(conn
, file_attributes
);
1398 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1402 * If the caller set the extended oplock request bit
1403 * and we granted one (by whatever means) - set the
1404 * correct bit for extended oplock reply.
1407 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
)))
1408 extended_oplock_granted
= True
;
1410 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))
1411 extended_oplock_granted
= True
;
1415 * Now try and apply the desired SD.
1418 if (lp_nt_acl_support(SNUM(conn
)) && sd_len
&&
1419 !NT_STATUS_IS_OK(status
= set_sd( fsp
, data
, sd_len
, ALL_SECURITY_INFORMATION
))) {
1420 close_file(fsp
,False
);
1421 restore_case_semantics(conn
, file_attributes
);
1422 return ERROR_NT(status
);
1425 restore_case_semantics(conn
, file_attributes
);
1427 /* Save the requested allocation size. */
1428 allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
1429 #ifdef LARGE_SMB_OFF_T
1430 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
1432 if (allocation_size
&& (allocation_size
> file_len
)) {
1433 fsp
->initial_allocation_size
= smb_roundup(allocation_size
);
1434 if (fsp
->is_directory
) {
1435 close_file(fsp
,False
);
1436 END_PROFILE(SMBntcreateX
);
1437 /* Can't set allocation size on a directory. */
1438 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1440 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
1441 close_file(fsp
,False
);
1442 return ERROR_NT(NT_STATUS_DISK_FULL
);
1445 fsp
->initial_allocation_size
= smb_roundup((SMB_BIG_UINT
)file_len
);
1448 /* Realloc the size of parameters and data we will return */
1449 params
= nttrans_realloc(ppparams
, 69);
1451 return ERROR_DOS(ERRDOS
,ERRnomem
);
1454 if (extended_oplock_granted
)
1455 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
1456 else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
))
1457 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
1459 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1462 SSVAL(p
,0,fsp
->fnum
);
1464 if ((create_disposition
== FILE_SUPERSEDE
) && (smb_action
== FILE_WAS_OVERWRITTEN
))
1465 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1467 SIVAL(p
,0,smb_action
);
1471 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1473 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1475 sbuf
.st_atime
&= ~1;
1476 sbuf
.st_mtime
&= ~1;
1477 sbuf
.st_mtime
&= ~1;
1480 put_long_date(p
,c_time
);
1482 put_long_date(p
,sbuf
.st_atime
); /* access time */
1484 put_long_date(p
,sbuf
.st_mtime
); /* write time */
1486 put_long_date(p
,sbuf
.st_mtime
); /* change time */
1488 SIVAL(p
,0,fmode
); /* File Attributes. */
1490 SOFF_T(p
, 0, get_allocation_size(fsp
,&sbuf
));
1492 SOFF_T(p
,0,file_len
);
1494 if (flags
& EXTENDED_RESPONSE_REQUIRED
)
1497 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1499 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname
));
1501 /* Send the required number of replies */
1502 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1507 /****************************************************************************
1508 Reply to a NT CANCEL request.
1509 ****************************************************************************/
1511 int reply_ntcancel(connection_struct
*conn
,
1512 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1515 * Go through and cancel any pending change notifies.
1518 int mid
= SVAL(inbuf
,smb_mid
);
1519 START_PROFILE(SMBntcancel
);
1520 remove_pending_change_notify_requests_by_mid(mid
);
1521 remove_pending_lock_requests_by_mid(mid
);
1522 srv_cancel_sign_response(mid
);
1524 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid
));
1526 END_PROFILE(SMBntcancel
);
1530 /****************************************************************************
1532 ****************************************************************************/
1534 static NTSTATUS
copy_internals(connection_struct
*conn
, char *oldname
, char *newname
, uint16 attrs
)
1536 BOOL bad_path_oldname
= False
;
1537 BOOL bad_path_newname
= False
;
1538 SMB_STRUCT_STAT sbuf1
, sbuf2
;
1539 pstring last_component_oldname
;
1540 pstring last_component_newname
;
1541 files_struct
*fsp1
,*fsp2
;
1547 NTSTATUS status
= NT_STATUS_OK
;
1553 if (ms_has_wild(newname
) || ms_has_wild(oldname
)) {
1554 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1557 if (!CAN_WRITE(conn
))
1558 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1560 unix_convert(oldname
,conn
,last_component_oldname
,&bad_path_oldname
,&sbuf1
);
1561 if (bad_path_oldname
) {
1562 return NT_STATUS_OBJECT_PATH_NOT_FOUND
;
1565 /* Quick check for "." and ".." */
1566 if (last_component_oldname
[0] == '.') {
1567 if (!last_component_oldname
[1] || (last_component_oldname
[1] == '.' && !last_component_oldname
[2])) {
1568 return NT_STATUS_OBJECT_NAME_INVALID
;
1572 /* Source must already exist. */
1573 if (!VALID_STAT(sbuf1
)) {
1574 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1576 if (!check_name(oldname
,conn
)) {
1577 return NT_STATUS_ACCESS_DENIED
;
1580 /* Ensure attributes match. */
1581 fmode
= dos_mode(conn
,oldname
,&sbuf1
);
1582 if ((fmode
& ~attrs
) & (aHIDDEN
| aSYSTEM
))
1583 return NT_STATUS_NO_SUCH_FILE
;
1585 unix_convert(newname
,conn
,last_component_newname
,&bad_path_newname
,&sbuf2
);
1586 if (bad_path_newname
) {
1587 return NT_STATUS_OBJECT_PATH_NOT_FOUND
;
1590 /* Quick check for "." and ".." */
1591 if (last_component_newname
[0] == '.') {
1592 if (!last_component_newname
[1] || (last_component_newname
[1] == '.' && !last_component_newname
[2])) {
1593 return NT_STATUS_OBJECT_NAME_INVALID
;
1597 /* Disallow if newname already exists. */
1598 if (VALID_STAT(sbuf2
)) {
1599 return NT_STATUS_OBJECT_NAME_COLLISION
;
1602 if (!check_name(newname
,conn
)) {
1603 return NT_STATUS_ACCESS_DENIED
;
1606 /* No links from a directory. */
1607 if (S_ISDIR(sbuf1
.st_mode
)) {
1608 return NT_STATUS_FILE_IS_A_DIRECTORY
;
1611 /* Ensure this is within the share. */
1612 if (!reduce_name(conn
, oldname
) != 0) {
1613 return NT_STATUS_ACCESS_DENIED
;
1616 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname
, newname
));
1618 fsp1
= open_file_shared1(conn
,oldname
,&sbuf1
,FILE_READ_DATA
,SET_DENY_MODE(DENY_ALL
)|SET_OPEN_MODE(DOS_OPEN_RDONLY
),
1619 (FILE_FAIL_IF_NOT_EXIST
|FILE_EXISTS_OPEN
),FILE_ATTRIBUTE_NORMAL
,0,
1620 &access_mode
,&smb_action
);
1623 status
= NT_STATUS_ACCESS_DENIED
;
1624 if (unix_ERR_class
== ERRDOS
&& unix_ERR_code
== ERRbadshare
)
1625 status
= NT_STATUS_SHARING_VIOLATION
;
1628 unix_ERR_ntstatus
= NT_STATUS_OK
;
1632 fsp2
= open_file_shared1(conn
,newname
,&sbuf2
,FILE_WRITE_DATA
,SET_DENY_MODE(DENY_ALL
)|SET_OPEN_MODE(DOS_OPEN_WRONLY
),
1633 (FILE_CREATE_IF_NOT_EXIST
|FILE_EXISTS_FAIL
),fmode
,INTERNAL_OPEN_ONLY
,
1634 &access_mode
,&smb_action
);
1637 status
= NT_STATUS_ACCESS_DENIED
;
1638 if (unix_ERR_class
== ERRDOS
&& unix_ERR_code
== ERRbadshare
)
1639 status
= NT_STATUS_SHARING_VIOLATION
;
1642 unix_ERR_ntstatus
= NT_STATUS_OK
;
1643 close_file(fsp1
,False
);
1648 ret
= vfs_transfer_file(fsp1
, fsp2
, sbuf1
.st_size
);
1651 * As we are opening fsp1 read-only we only expect
1652 * an error on close on fsp2 if we are out of space.
1653 * Thus we don't look at the error return from the
1656 close_file(fsp1
,False
);
1658 /* Ensure the modtime is set correctly on the destination file. */
1659 fsp2
->pending_modtime
= sbuf1
.st_mtime
;
1661 close_ret
= close_file(fsp2
,False
);
1663 /* Grrr. We have to do this as open_file_shared1 adds aARCH when it
1664 creates the file. This isn't the correct thing to do in the copy case. JRA */
1665 file_set_dosmode(conn
, newname
, fmode
, &sbuf2
, True
);
1667 if (ret
< (SMB_OFF_T
)sbuf1
.st_size
) {
1668 return NT_STATUS_DISK_FULL
;
1671 if (close_ret
!= 0) {
1672 status
= map_nt_error_from_unix(close_ret
);
1673 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1674 nt_errstr(status
), oldname
, newname
));
1679 /****************************************************************************
1680 Reply to a NT rename request.
1681 ****************************************************************************/
1683 int reply_ntrename(connection_struct
*conn
,
1684 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1691 uint16 attrs
= SVAL(inbuf
,smb_vwv0
);
1692 uint16 rename_type
= SVAL(inbuf
,smb_vwv1
);
1694 START_PROFILE(SMBntrename
);
1696 p
= smb_buf(inbuf
) + 1;
1697 p
+= srvstr_get_path(inbuf
, oldname
, p
, sizeof(oldname
), 0, STR_TERMINATE
, &status
, True
);
1698 if (!NT_STATUS_IS_OK(status
)) {
1699 END_PROFILE(SMBntrename
);
1700 return ERROR_NT(status
);
1703 if( strchr_m(oldname
, ':')) {
1704 /* Can't rename a stream. */
1705 END_PROFILE(SMBntrename
);
1706 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1709 if (ms_has_wild(oldname
)) {
1710 END_PROFILE(SMBntrename
);
1711 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1715 p
+= srvstr_get_path(inbuf
, newname
, p
, sizeof(newname
), 0, STR_TERMINATE
, &status
, False
);
1716 if (!NT_STATUS_IS_OK(status
)) {
1717 END_PROFILE(SMBntrename
);
1718 return ERROR_NT(status
);
1721 RESOLVE_DFSPATH(oldname
, conn
, inbuf
, outbuf
);
1722 RESOLVE_DFSPATH(newname
, conn
, inbuf
, outbuf
);
1724 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1726 switch(rename_type
) {
1727 case RENAME_FLAG_RENAME
:
1728 status
= rename_internals(conn
, oldname
, newname
, attrs
, False
);
1730 case RENAME_FLAG_HARD_LINK
:
1731 status
= hardlink_internals(conn
, oldname
, newname
);
1733 case RENAME_FLAG_COPY
:
1734 status
= copy_internals(conn
, oldname
, newname
, attrs
);
1736 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1737 status
= NT_STATUS_INVALID_PARAMETER
;
1740 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1744 if (!NT_STATUS_IS_OK(status
)) {
1745 END_PROFILE(SMBntrename
);
1746 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1747 /* We have re-scheduled this call. */
1748 clear_cached_errors();
1751 return ERROR_NT(status
);
1755 * Win2k needs a changenotify request response before it will
1756 * update after a rename..
1758 process_pending_change_notify_queue((time_t)0);
1759 outsize
= set_message(outbuf
,0,0,True
);
1761 END_PROFILE(SMBntrename
);
1765 /****************************************************************************
1766 Reply to an unsolicited SMBNTtranss - just ignore it!
1767 ****************************************************************************/
1769 int reply_nttranss(connection_struct
*conn
,
1770 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1772 START_PROFILE(SMBnttranss
);
1773 DEBUG(4,("Ignoring nttranss of length %d\n",length
));
1774 END_PROFILE(SMBnttranss
);
1778 /****************************************************************************
1779 Reply to a notify change - queue the request and
1780 don't allow a directory to be opened.
1781 ****************************************************************************/
1783 static int call_nt_transact_notify_change(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1784 char **ppsetup
, uint32 setup_count
,
1785 char **ppparams
, uint32 parameter_count
,
1786 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1788 char *setup
= *ppsetup
;
1793 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1795 fsp
= file_fsp(setup
,4);
1796 flags
= IVAL(setup
, 0);
1798 DEBUG(3,("call_nt_transact_notify_change\n"));
1801 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1803 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
))
1804 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1806 if (!change_notify_set(inbuf
, fsp
, conn
, flags
))
1807 return(UNIXERROR(ERRDOS
,ERRbadfid
));
1809 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1810 name = %s\n", fsp
->fsp_name
));
1815 /****************************************************************************
1816 Reply to an NT transact rename command.
1817 ****************************************************************************/
1819 static int call_nt_transact_rename(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1820 char **ppsetup
, uint32 setup_count
,
1821 char **ppparams
, uint32 parameter_count
,
1822 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1824 char *params
= *ppparams
;
1826 files_struct
*fsp
= NULL
;
1827 BOOL replace_if_exists
= False
;
1830 if(parameter_count
< 4)
1831 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1833 fsp
= file_fsp(params
, 0);
1834 replace_if_exists
= (SVAL(params
,2) & RENAME_REPLACE_IF_EXISTS
) ? True
: False
;
1835 CHECK_FSP(fsp
, conn
);
1836 srvstr_get_path(inbuf
, new_name
, params
+4, sizeof(new_name
), -1, STR_TERMINATE
, &status
, True
);
1837 if (!NT_STATUS_IS_OK(status
)) {
1838 return ERROR_NT(status
);
1841 status
= rename_internals(conn
, fsp
->fsp_name
,
1842 new_name
, 0, replace_if_exists
);
1843 if (!NT_STATUS_IS_OK(status
))
1844 return ERROR_NT(status
);
1847 * Rename was successful.
1849 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1851 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1852 fsp
->fsp_name
, new_name
));
1855 * Win2k needs a changenotify request response before it will
1856 * update after a rename..
1859 process_pending_change_notify_queue((time_t)0);
1864 /******************************************************************************
1865 Fake up a completely empty SD.
1866 *******************************************************************************/
1868 static size_t get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1870 extern DOM_SID global_sid_World
;
1873 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1875 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1882 /****************************************************************************
1883 Reply to query a security descriptor.
1884 ****************************************************************************/
1886 static int call_nt_transact_query_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1887 char **ppsetup
, uint32 setup_count
,
1888 char **ppparams
, uint32 parameter_count
,
1889 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1891 char *params
= *ppparams
;
1892 char *data
= *ppdata
;
1894 SEC_DESC
*psd
= NULL
;
1896 uint32 security_info_wanted
;
1897 TALLOC_CTX
*mem_ctx
;
1898 files_struct
*fsp
= NULL
;
1900 if(parameter_count
< 8)
1901 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1903 fsp
= file_fsp(params
,0);
1905 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1907 security_info_wanted
= IVAL(params
,4);
1909 DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp
->fsp_name
));
1911 params
= nttrans_realloc(ppparams
, 4);
1913 return ERROR_DOS(ERRDOS
,ERRnomem
);
1915 if ((mem_ctx
= talloc_init("call_nt_transact_query_security_desc")) == NULL
) {
1916 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1917 return ERROR_DOS(ERRDOS
,ERRnomem
);
1921 * Get the permissions to return.
1924 if (!lp_nt_acl_support(SNUM(conn
)))
1925 sd_size
= get_null_nt_acl(mem_ctx
, &psd
);
1927 sd_size
= SMB_VFS_FGET_NT_ACL(fsp
, fsp
->fd
, security_info_wanted
, &psd
);
1930 talloc_destroy(mem_ctx
);
1931 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1934 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size
));
1936 SIVAL(params
,0,(uint32
)sd_size
);
1938 if(max_data_count
< sd_size
) {
1940 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_BUFFER_TOO_SMALL
,
1941 params
, 4, *ppdata
, 0);
1942 talloc_destroy(mem_ctx
);
1947 * Allocate the data we will point this at.
1950 data
= nttrans_realloc(ppdata
, sd_size
);
1952 talloc_destroy(mem_ctx
);
1953 return ERROR_DOS(ERRDOS
,ERRnomem
);
1957 * Init the parse struct we will marshall into.
1960 prs_init(&pd
, 0, mem_ctx
, MARSHALL
);
1963 * Setup the prs_struct to point at the memory we just
1967 prs_give_memory( &pd
, data
, (uint32
)sd_size
, False
);
1970 * Finally, linearize into the outgoing buffer.
1973 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1974 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
1975 security descriptor.\n"));
1977 * Return access denied for want of a better error message..
1979 talloc_destroy(mem_ctx
);
1980 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1984 * Now we can delete the security descriptor.
1987 talloc_destroy(mem_ctx
);
1989 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1993 /****************************************************************************
1994 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1995 ****************************************************************************/
1997 static int call_nt_transact_set_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1998 char **ppsetup
, uint32 setup_count
,
1999 char **ppparams
, uint32 parameter_count
,
2000 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2002 char *params
= *ppparams
;
2003 char *data
= *ppdata
;
2004 files_struct
*fsp
= NULL
;
2005 uint32 security_info_sent
= 0;
2008 if(parameter_count
< 8)
2009 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2011 if((fsp
= file_fsp(params
,0)) == NULL
)
2012 return ERROR_DOS(ERRDOS
,ERRbadfid
);
2014 if(!lp_nt_acl_support(SNUM(conn
)))
2017 security_info_sent
= IVAL(params
,4);
2019 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
2020 (unsigned int)security_info_sent
));
2022 if (data_count
== 0)
2023 return ERROR_DOS(ERRDOS
, ERRnoaccess
);
2025 if (!NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, data_count
, security_info_sent
)))
2026 return ERROR_NT(nt_status
);
2030 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2034 /****************************************************************************
2036 ****************************************************************************/
2038 static int call_nt_transact_ioctl(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2039 char **ppsetup
, uint32 setup_count
,
2040 char **ppparams
, uint32 parameter_count
,
2041 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2048 static BOOL logged_message
;
2049 char *pdata
= *ppdata
;
2051 if (setup_count
!= 8) {
2052 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
2053 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2056 function
= IVAL(*ppsetup
, 0);
2057 fidnum
= SVAL(*ppsetup
, 4);
2058 isFSctl
= CVAL(*ppsetup
, 6);
2059 compfilter
= CVAL(*ppsetup
, 7);
2061 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2062 function
, fidnum
, isFSctl
, compfilter
));
2064 fsp
=file_fsp(*ppsetup
, 4);
2065 /* this check is done in each implemented function case for now
2066 because I don't want to break anything... --metze
2067 FSP_BELONGS_CONN(fsp,conn);*/
2070 case FSCTL_SET_SPARSE
:
2071 /* pretend this succeeded - tho strictly we should
2072 mark the file sparse (if the local fs supports it)
2073 so we can know if we need to pre-allocate or not */
2075 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
2076 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2079 case FSCTL_0x000900C0
:
2080 /* pretend this succeeded - don't know what this really is
2081 but works ok like this --metze
2084 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum
));
2085 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2088 case FSCTL_GET_REPARSE_POINT
:
2089 /* pretend this fail - my winXP does it like this
2093 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2094 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
2097 case FSCTL_SET_REPARSE_POINT
:
2098 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2102 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2103 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
2106 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
2109 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2110 * and return their volume names. If max_data_count is 16, then it is just
2111 * asking for the number of volumes and length of the combined names.
2113 * pdata is the data allocated by our caller, but that uses
2114 * total_data_count (which is 0 in our case) rather than max_data_count.
2115 * Allocate the correct amount and return the pointer to let
2116 * it be deallocated when we return.
2118 SHADOW_COPY_DATA
*shadow_data
= NULL
;
2119 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
2120 BOOL labels
= False
;
2121 uint32 labels_data_count
= 0;
2125 FSP_BELONGS_CONN(fsp
,conn
);
2127 if (max_data_count
< 16) {
2128 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2130 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
2133 if (max_data_count
> 16) {
2137 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
2138 if (shadow_mem_ctx
== NULL
) {
2139 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2140 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2143 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
2144 if (shadow_data
== NULL
) {
2145 DEBUG(0,("talloc_zero() failed!\n"));
2146 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2149 shadow_data
->mem_ctx
= shadow_mem_ctx
;
2152 * Call the VFS routine to actually do the work.
2154 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2155 talloc_destroy(shadow_data
->mem_ctx
);
2156 if (errno
== ENOSYS
) {
2157 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2158 conn
->connectpath
));
2159 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2161 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2162 conn
->connectpath
));
2163 return ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
2167 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2172 data_count
= 12+labels_data_count
+4;
2175 if (max_data_count
<data_count
) {
2176 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2177 max_data_count
,data_count
));
2178 talloc_destroy(shadow_data
->mem_ctx
);
2179 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL
);
2182 pdata
= nttrans_realloc(ppdata
, data_count
);
2183 if (pdata
== NULL
) {
2184 talloc_destroy(shadow_data
->mem_ctx
);
2185 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2190 /* num_volumes 4 bytes */
2191 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2194 /* num_labels 4 bytes */
2195 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2198 /* needed_data_count 4 bytes */
2199 SIVAL(pdata
,8,labels_data_count
);
2203 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2204 shadow_data
->num_volumes
,fsp
->fsp_name
));
2205 if (labels
&& shadow_data
->labels
) {
2206 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2207 srvstr_push(outbuf
, cur_pdata
, shadow_data
->labels
[i
], 2*sizeof(SHADOW_COPY_LABEL
), STR_UNICODE
|STR_TERMINATE
);
2208 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2209 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2213 talloc_destroy(shadow_data
->mem_ctx
);
2215 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, pdata
, data_count
);
2220 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2222 /* pretend this succeeded -
2224 * we have to send back a list with all files owned by this SID
2226 * but I have to check that --metze
2230 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2232 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2234 FSP_BELONGS_CONN(fsp
,conn
);
2236 /* unknown 4 bytes: this is not the length of the sid :-( */
2237 /*unknown = IVAL(pdata,0);*/
2239 sid_parse(pdata
+4,sid_len
,&sid
);
2240 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid
)));
2242 if (!NT_STATUS_IS_OK(sid_to_uid(&sid
, &uid
))) {
2243 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2244 sid_string_static(&sid
),(unsigned long)sid_len
));
2248 /* we can take a look at the find source :-)
2250 * find ./ -uid $uid -name '*' is what we need here
2253 * and send 4bytes len and then NULL terminated unicode strings
2256 * but I don't know how to deal with the paged results
2257 * (maybe we can hang the result anywhere in the fsp struct)
2259 * we don't send all files at once
2260 * and at the next we should *not* start from the beginning,
2261 * so we have to cache the result
2266 /* this works for now... */
2267 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2271 if (!logged_message
) {
2272 logged_message
= True
; /* Only print this once... */
2273 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2278 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2282 #ifdef HAVE_SYS_QUOTAS
2283 /****************************************************************************
2284 Reply to get user quota
2285 ****************************************************************************/
2287 static int call_nt_transact_get_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2288 char **ppsetup
, uint32 setup_count
,
2289 char **ppparams
, uint32 parameter_count
,
2290 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2292 NTSTATUS nt_status
= NT_STATUS_OK
;
2293 char *params
= *ppparams
;
2294 char *pdata
= *ppdata
;
2296 int data_len
=0,param_len
=0;
2299 files_struct
*fsp
= NULL
;
2303 BOOL start_enum
= True
;
2304 SMB_NTQUOTA_STRUCT qt
;
2305 SMB_NTQUOTA_LIST
*tmp_list
;
2306 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2307 extern struct current_user current_user
;
2312 if (current_user
.uid
!= 0) {
2313 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2314 lp_servicename(SNUM(conn
)),conn
->user
));
2315 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2319 * Ensure minimum number of parameters sent.
2322 if (parameter_count
< 4) {
2323 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2324 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2327 /* maybe we can check the quota_fnum */
2328 fsp
= file_fsp(params
,0);
2329 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2330 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2331 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2334 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2335 * is done by CHECK_NTQUOTA_HANDLE_OK()
2337 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
2339 level
= SVAL(params
,2);
2341 /* unknown 12 bytes leading in params */
2344 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2345 /* seems that we should continue with the enum here --metze */
2347 if (qt_handle
->quota_list
!=NULL
&&
2348 qt_handle
->tmp_list
==NULL
) {
2351 free_ntquota_list(&(qt_handle
->quota_list
));
2353 /* Realloc the size of parameters and data we will return */
2355 params
= nttrans_realloc(ppparams
, param_len
);
2357 return ERROR_DOS(ERRDOS
,ERRnomem
);
2360 SIVAL(params
,0,data_len
);
2367 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2369 if (qt_handle
->quota_list
==NULL
&&
2370 qt_handle
->tmp_list
==NULL
) {
2374 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0)
2375 return ERROR_DOS(ERRSRV
,ERRerror
);
2377 /* Realloc the size of parameters and data we will return */
2379 params
= nttrans_realloc(ppparams
, param_len
);
2381 return ERROR_DOS(ERRDOS
,ERRnomem
);
2383 /* we should not trust the value in max_data_count*/
2384 max_data_count
= MIN(max_data_count
,2048);
2386 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2388 return ERROR_DOS(ERRDOS
,ERRnomem
);
2393 /* set params Size of returned Quota Data 4 bytes*/
2394 /* but set it later when we know it */
2396 /* for each entry push the data */
2399 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2402 tmp_list
= qt_handle
->tmp_list
;
2404 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2405 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2407 sid_len
= sid_size(&tmp_list
->quotas
->sid
);
2408 entry_len
= 40 + sid_len
;
2410 /* nextoffset entry 4 bytes */
2411 SIVAL(entry
,0,entry_len
);
2413 /* then the len of the SID 4 bytes */
2414 SIVAL(entry
,4,sid_len
);
2416 /* unknown data 8 bytes SMB_BIG_UINT */
2417 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2419 /* the used disk space 8 bytes SMB_BIG_UINT */
2420 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2422 /* the soft quotas 8 bytes SMB_BIG_UINT */
2423 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2425 /* the hard quotas 8 bytes SMB_BIG_UINT */
2426 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2428 /* and now the SID */
2429 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2432 qt_handle
->tmp_list
= tmp_list
;
2434 /* overwrite the offset of the last entry */
2435 SIVAL(entry
-entry_len
,0,0);
2437 data_len
= 4+qt_len
;
2438 /* overwrite the params quota_data_len */
2439 SIVAL(params
,0,data_len
);
2443 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2445 /* unknown 4 bytes IVAL(pdata,0) */
2447 if (data_count
< 8) {
2448 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2449 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2452 sid_len
= IVAL(pdata
,4);
2453 /* Ensure this is less than 1mb. */
2454 if (sid_len
> (1024*1024)) {
2455 return ERROR_DOS(ERRDOS
,ERRnomem
);
2458 if (data_count
< 8+sid_len
) {
2459 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2460 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2463 data_len
= 4+40+sid_len
;
2465 if (max_data_count
< data_len
) {
2466 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2467 max_data_count
, data_len
));
2469 SIVAL(params
,0,data_len
);
2471 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2475 sid_parse(pdata
+8,sid_len
,&sid
);
2478 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2481 * we have to return zero's in all fields
2482 * instead of returning an error here
2487 /* Realloc the size of parameters and data we will return */
2489 params
= nttrans_realloc(ppparams
, param_len
);
2491 return ERROR_DOS(ERRDOS
,ERRnomem
);
2493 pdata
= nttrans_realloc(ppdata
, data_len
);
2495 return ERROR_DOS(ERRDOS
,ERRnomem
);
2499 /* set params Size of returned Quota Data 4 bytes*/
2500 SIVAL(params
,0,data_len
);
2502 /* nextoffset entry 4 bytes */
2505 /* then the len of the SID 4 bytes */
2506 SIVAL(entry
,4,sid_len
);
2508 /* unknown data 8 bytes SMB_BIG_UINT */
2509 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2511 /* the used disk space 8 bytes SMB_BIG_UINT */
2512 SBIG_UINT(entry
,16,qt
.usedspace
);
2514 /* the soft quotas 8 bytes SMB_BIG_UINT */
2515 SBIG_UINT(entry
,24,qt
.softlim
);
2517 /* the hard quotas 8 bytes SMB_BIG_UINT */
2518 SBIG_UINT(entry
,32,qt
.hardlim
);
2520 /* and now the SID */
2521 sid_linearize(entry
+40, sid_len
, &sid
);
2526 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2527 return ERROR_DOS(ERRSRV
,ERRerror
);
2531 send_nt_replies(inbuf
, outbuf
, bufsize
, nt_status
, params
, param_len
, pdata
, data_len
);
2536 /****************************************************************************
2537 Reply to set user quota
2538 ****************************************************************************/
2540 static int call_nt_transact_set_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2541 char **ppsetup
, uint32 setup_count
,
2542 char **ppparams
, uint32 parameter_count
,
2543 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2545 char *params
= *ppparams
;
2546 char *pdata
= *ppdata
;
2547 int data_len
=0,param_len
=0;
2548 SMB_NTQUOTA_STRUCT qt
;
2551 files_struct
*fsp
= NULL
;
2556 if (current_user
.uid
!= 0) {
2557 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2558 lp_servicename(SNUM(conn
)),conn
->user
));
2559 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2563 * Ensure minimum number of parameters sent.
2566 if (parameter_count
< 2) {
2567 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2568 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2571 /* maybe we can check the quota_fnum */
2572 fsp
= file_fsp(params
,0);
2573 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2574 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2575 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2578 if (data_count
< 40) {
2579 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2580 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2583 /* offset to next quota record.
2584 * 4 bytes IVAL(pdata,0)
2589 sid_len
= IVAL(pdata
,4);
2591 if (data_count
< 40+sid_len
) {
2592 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2593 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2596 /* unknown 8 bytes in pdata
2597 * maybe its the change time in NTTIME
2600 /* the used space 8 bytes (SMB_BIG_UINT)*/
2601 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2602 #ifdef LARGE_SMB_OFF_T
2603 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2604 #else /* LARGE_SMB_OFF_T */
2605 if ((IVAL(pdata
,20) != 0)&&
2606 ((qt
.usedspace
!= 0xFFFFFFFF)||
2607 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2608 /* more than 32 bits? */
2609 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2611 #endif /* LARGE_SMB_OFF_T */
2613 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2614 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2615 #ifdef LARGE_SMB_OFF_T
2616 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2617 #else /* LARGE_SMB_OFF_T */
2618 if ((IVAL(pdata
,28) != 0)&&
2619 ((qt
.softlim
!= 0xFFFFFFFF)||
2620 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2621 /* more than 32 bits? */
2622 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2624 #endif /* LARGE_SMB_OFF_T */
2626 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2627 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2628 #ifdef LARGE_SMB_OFF_T
2629 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2630 #else /* LARGE_SMB_OFF_T */
2631 if ((IVAL(pdata
,36) != 0)&&
2632 ((qt
.hardlim
!= 0xFFFFFFFF)||
2633 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2634 /* more than 32 bits? */
2635 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2637 #endif /* LARGE_SMB_OFF_T */
2639 sid_parse(pdata
+40,sid_len
,&sid
);
2640 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid
)));
2642 /* 44 unknown bytes left... */
2644 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2645 return ERROR_DOS(ERRSRV
,ERRerror
);
2648 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, pdata
, data_len
);
2652 #endif /* HAVE_SYS_QUOTAS */
2654 /****************************************************************************
2655 Reply to a SMBNTtrans.
2656 ****************************************************************************/
2658 int reply_nttrans(connection_struct
*conn
,
2659 char *inbuf
,char *outbuf
,int length
,int bufsize
)
2662 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
2663 #if 0 /* Not used. */
2664 uint16 max_setup_count
= CVAL(inbuf
, smb_nt_MaxSetupCount
);
2665 uint32 max_parameter_count
= IVAL(inbuf
, smb_nt_MaxParameterCount
);
2666 #endif /* Not used. */
2667 uint32 total_parameter_count
= IVAL(inbuf
, smb_nt_TotalParameterCount
);
2668 uint32 total_data_count
= IVAL(inbuf
, smb_nt_TotalDataCount
);
2669 uint32 parameter_count
= IVAL(inbuf
,smb_nt_ParameterCount
);
2670 uint32 parameter_offset
= IVAL(inbuf
,smb_nt_ParameterOffset
);
2671 uint32 data_count
= IVAL(inbuf
,smb_nt_DataCount
);
2672 uint32 data_offset
= IVAL(inbuf
,smb_nt_DataOffset
);
2673 uint16 setup_count
= 2*CVAL(inbuf
,smb_nt_SetupCount
); /* setup count is in *words* */
2674 uint16 function_code
= SVAL( inbuf
, smb_nt_Function
);
2675 char *params
= NULL
, *data
= NULL
, *setup
= NULL
;
2676 uint32 num_params_sofar
, num_data_sofar
;
2677 START_PROFILE(SMBnttrans
);
2679 if(global_oplock_break
&&
2680 ((function_code
== NT_TRANSACT_CREATE
) ||
2681 (function_code
== NT_TRANSACT_RENAME
))) {
2683 * Queue this open message as we are the process of an oplock break.
2686 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2687 due to being in oplock break state.\n", (unsigned int)function_code
));
2689 push_oplock_pending_smb_message( inbuf
, length
);
2690 END_PROFILE(SMBnttrans
);
2694 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2695 END_PROFILE(SMBnttrans
);
2696 return ERROR_DOS(ERRSRV
,ERRaccess
);
2699 outsize
= set_message(outbuf
,0,0,True
);
2702 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2703 * Ensure this is so as a sanity check.
2706 if(CVAL(inbuf
, smb_wct
) != 19 + (setup_count
/2)) {
2707 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2708 CVAL(inbuf
, smb_wct
), 19 + (setup_count
/2)));
2712 /* Don't allow more than 128mb for each value. */
2713 if ((total_parameter_count
> (1024*1024*128)) || (total_data_count
> (1024*1024*128))) {
2714 END_PROFILE(SMBnttrans
);
2715 return ERROR_DOS(ERRDOS
,ERRnomem
);
2718 /* Allocate the space for the setup, the maximum needed parameters and data */
2721 setup
= (char *)SMB_MALLOC(setup_count
);
2722 if (total_parameter_count
> 0)
2723 params
= (char *)SMB_MALLOC(total_parameter_count
);
2724 if (total_data_count
> 0)
2725 data
= (char *)SMB_MALLOC(total_data_count
);
2727 if ((total_parameter_count
&& !params
) || (total_data_count
&& !data
) ||
2728 (setup_count
&& !setup
)) {
2732 DEBUG(0,("reply_nttrans : Out of memory\n"));
2733 END_PROFILE(SMBnttrans
);
2734 return ERROR_DOS(ERRDOS
,ERRnomem
);
2737 /* Copy the param and data bytes sent with this request into the params buffer */
2738 num_params_sofar
= parameter_count
;
2739 num_data_sofar
= data_count
;
2741 if (parameter_count
> total_parameter_count
|| data_count
> total_data_count
)
2745 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count
));
2746 if ((smb_nt_SetupStart
+ setup_count
< smb_nt_SetupStart
) ||
2747 (smb_nt_SetupStart
+ setup_count
< setup_count
))
2749 if (smb_nt_SetupStart
+ setup_count
> length
)
2752 memcpy( setup
, &inbuf
[smb_nt_SetupStart
], setup_count
);
2753 dump_data(10, setup
, setup_count
);
2756 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count
));
2757 if ((parameter_offset
+ parameter_count
< parameter_offset
) ||
2758 (parameter_offset
+ parameter_count
< parameter_count
))
2760 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
> inbuf
+ length
)||
2761 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
)))
2764 memcpy( params
, smb_base(inbuf
) + parameter_offset
, parameter_count
);
2765 dump_data(10, params
, parameter_count
);
2768 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count
));
2769 if ((data_offset
+ data_count
< data_offset
) || (data_offset
+ data_count
< data_count
))
2771 if ((smb_base(inbuf
) + data_offset
+ data_count
> inbuf
+ length
) ||
2772 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
)))
2775 memcpy( data
, smb_base(inbuf
) + data_offset
, data_count
);
2776 dump_data(10, data
, data_count
);
2779 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2781 if(num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2782 /* We need to send an interim response then receive the rest
2783 of the parameter/data bytes */
2784 outsize
= set_message(outbuf
,0,0,True
);
2785 srv_signing_trans_stop();
2786 if (!send_smb(smbd_server_fd(),outbuf
))
2787 exit_server("reply_nttrans: send_smb failed.");
2789 while( num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2791 uint32 parameter_displacement
;
2792 uint32 data_displacement
;
2794 ret
= receive_next_smb(inbuf
,bufsize
,SMB_SECONDARY_WAIT
);
2797 * The sequence number for the trans reply is always
2798 * based on the last secondary received.
2801 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2803 if((ret
&& (CVAL(inbuf
, smb_com
) != SMBnttranss
)) || !ret
) {
2804 outsize
= set_message(outbuf
,0,0,True
);
2806 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2808 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2809 (smb_read_error
== READ_ERROR
) ? "error" : "timeout" ));
2814 /* Revise total_params and total_data in case they have changed downwards */
2815 if (IVAL(inbuf
, smb_nts_TotalParameterCount
) < total_parameter_count
)
2816 total_parameter_count
= IVAL(inbuf
, smb_nts_TotalParameterCount
);
2817 if (IVAL(inbuf
, smb_nts_TotalDataCount
) < total_data_count
)
2818 total_data_count
= IVAL(inbuf
, smb_nts_TotalDataCount
);
2820 parameter_count
= IVAL(inbuf
,smb_nts_ParameterCount
);
2821 parameter_offset
= IVAL(inbuf
, smb_nts_ParameterOffset
);
2822 parameter_displacement
= IVAL(inbuf
, smb_nts_ParameterDisplacement
);
2823 num_params_sofar
+= parameter_count
;
2825 data_count
= IVAL(inbuf
, smb_nts_DataCount
);
2826 data_displacement
= IVAL(inbuf
, smb_nts_DataDisplacement
);
2827 data_offset
= IVAL(inbuf
, smb_nts_DataOffset
);
2828 num_data_sofar
+= data_count
;
2830 if (num_params_sofar
> total_parameter_count
|| num_data_sofar
> total_data_count
) {
2831 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2835 if (parameter_count
) {
2836 if (parameter_displacement
+ parameter_count
> total_parameter_count
)
2838 if ((parameter_displacement
+ parameter_count
< parameter_displacement
) ||
2839 (parameter_displacement
+ parameter_count
< parameter_count
))
2841 if (parameter_displacement
> total_parameter_count
)
2843 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
>= inbuf
+ bufsize
) ||
2844 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
)))
2846 if (parameter_displacement
+ params
< params
)
2849 memcpy( ¶ms
[parameter_displacement
], smb_base(inbuf
) + parameter_offset
, parameter_count
);
2853 if (data_displacement
+ data_count
> total_data_count
)
2855 if ((data_displacement
+ data_count
< data_displacement
) ||
2856 (data_displacement
+ data_count
< data_count
))
2858 if (data_displacement
> total_data_count
)
2860 if ((smb_base(inbuf
) + data_offset
+ data_count
>= inbuf
+ bufsize
) ||
2861 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
)))
2863 if (data_displacement
+ data
< data
)
2866 memcpy( &data
[data_displacement
], smb_base(inbuf
)+ data_offset
, data_count
);
2871 if (Protocol
>= PROTOCOL_NT1
)
2872 SSVAL(outbuf
,smb_flg2
,SVAL(outbuf
,smb_flg2
) | FLAGS2_IS_LONG_NAME
);
2874 /* Now we must call the relevant NT_TRANS function */
2875 switch(function_code
) {
2876 case NT_TRANSACT_CREATE
:
2877 START_PROFILE_NESTED(NT_transact_create
);
2878 outsize
= call_nt_transact_create(conn
, inbuf
, outbuf
,
2880 &setup
, setup_count
,
2881 ¶ms
, total_parameter_count
,
2882 &data
, total_data_count
, max_data_count
);
2883 END_PROFILE_NESTED(NT_transact_create
);
2885 case NT_TRANSACT_IOCTL
:
2886 START_PROFILE_NESTED(NT_transact_ioctl
);
2887 outsize
= call_nt_transact_ioctl(conn
, inbuf
, outbuf
,
2889 &setup
, setup_count
,
2890 ¶ms
, total_parameter_count
,
2891 &data
, total_data_count
, max_data_count
);
2892 END_PROFILE_NESTED(NT_transact_ioctl
);
2894 case NT_TRANSACT_SET_SECURITY_DESC
:
2895 START_PROFILE_NESTED(NT_transact_set_security_desc
);
2896 outsize
= call_nt_transact_set_security_desc(conn
, inbuf
, outbuf
,
2898 &setup
, setup_count
,
2899 ¶ms
, total_parameter_count
,
2900 &data
, total_data_count
, max_data_count
);
2901 END_PROFILE_NESTED(NT_transact_set_security_desc
);
2903 case NT_TRANSACT_NOTIFY_CHANGE
:
2904 START_PROFILE_NESTED(NT_transact_notify_change
);
2905 outsize
= call_nt_transact_notify_change(conn
, inbuf
, outbuf
,
2907 &setup
, setup_count
,
2908 ¶ms
, total_parameter_count
,
2909 &data
, total_data_count
, max_data_count
);
2910 END_PROFILE_NESTED(NT_transact_notify_change
);
2912 case NT_TRANSACT_RENAME
:
2913 START_PROFILE_NESTED(NT_transact_rename
);
2914 outsize
= call_nt_transact_rename(conn
, inbuf
, outbuf
,
2916 &setup
, setup_count
,
2917 ¶ms
, total_parameter_count
,
2918 &data
, total_data_count
, max_data_count
);
2919 END_PROFILE_NESTED(NT_transact_rename
);
2922 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2923 START_PROFILE_NESTED(NT_transact_query_security_desc
);
2924 outsize
= call_nt_transact_query_security_desc(conn
, inbuf
, outbuf
,
2926 &setup
, setup_count
,
2927 ¶ms
, total_parameter_count
,
2928 &data
, total_data_count
, max_data_count
);
2929 END_PROFILE_NESTED(NT_transact_query_security_desc
);
2931 #ifdef HAVE_SYS_QUOTAS
2932 case NT_TRANSACT_GET_USER_QUOTA
:
2933 START_PROFILE_NESTED(NT_transact_get_user_quota
);
2934 outsize
= call_nt_transact_get_user_quota(conn
, inbuf
, outbuf
,
2936 &setup
, setup_count
,
2937 ¶ms
, total_parameter_count
,
2938 &data
, total_data_count
, max_data_count
);
2939 END_PROFILE_NESTED(NT_transact_get_user_quota
);
2941 case NT_TRANSACT_SET_USER_QUOTA
:
2942 START_PROFILE_NESTED(NT_transact_set_user_quota
);
2943 outsize
= call_nt_transact_set_user_quota(conn
, inbuf
, outbuf
,
2945 &setup
, setup_count
,
2946 ¶ms
, total_parameter_count
,
2947 &data
, total_data_count
, max_data_count
);
2948 END_PROFILE_NESTED(NT_transact_set_user_quota
);
2950 #endif /* HAVE_SYS_QUOTAS */
2952 /* Error in request */
2953 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code
));
2957 END_PROFILE(SMBnttrans
);
2958 srv_signing_trans_stop();
2959 return ERROR_DOS(ERRSRV
,ERRerror
);
2962 /* As we do not know how many data packets will need to be
2963 returned here the various call_nt_transact_xxxx calls
2964 must send their own. Thus a call_nt_transact_xxxx routine only
2965 returns a value other than -1 when it wants to send
2969 srv_signing_trans_stop();
2974 END_PROFILE(SMBnttrans
);
2975 return outsize
; /* If a correct response was needed the call_nt_transact_xxxx
2976 calls have already sent it. If outsize != -1 then it is
2977 returning an error packet. */
2981 srv_signing_trans_stop();
2985 END_PROFILE(SMBnttrans
);
2986 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);