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 enum protocol_types Protocol
;
26 extern int smb_read_error
;
27 extern int global_oplock_break
;
28 extern struct current_user current_user
;
30 static const char *known_nt_pipes
[] = {
49 static char *nttrans_realloc(char **ptr
, size_t size
)
53 smb_panic("nttrans_realloc() called with NULL ptr\n");
56 tptr
= SMB_REALLOC(*ptr
, size
);
61 memset(tptr
,'\0',size
);
68 /****************************************************************************
69 Send the required number of replies back.
70 We assume all fields other than the data fields are
71 set correctly for the type of call.
72 HACK ! Always assumes smb_setup field is zero.
73 ****************************************************************************/
75 static int send_nt_replies(char *inbuf
, char *outbuf
, int bufsize
, NTSTATUS nt_error
, char *params
,
76 int paramsize
, char *pdata
, int datasize
)
78 int data_to_send
= datasize
;
79 int params_to_send
= paramsize
;
83 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
84 int alignment_offset
= 3;
85 int data_alignment_offset
= 0;
88 * Initially set the wcnt area to be 18 - this is true for all
92 set_message(outbuf
,18,0,True
);
94 if (NT_STATUS_V(nt_error
)) {
99 * If there genuinely are no parameters or data to send just send
103 if(params_to_send
== 0 && data_to_send
== 0) {
105 if (!send_smb(smbd_server_fd(),outbuf
)) {
106 exit_server("send_nt_replies: send_smb failed.");
112 * When sending params and data ensure that both are nicely aligned.
113 * Only do this alignment when there is also data to send - else
114 * can cause NT redirector problems.
117 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
118 data_alignment_offset
= 4 - (params_to_send
% 4);
122 * Space is bufsize minus Netbios over TCP header minus SMB header.
123 * The alignment_offset is to align the param bytes on a four byte
124 * boundary (2 bytes for data len, one byte pad).
125 * NT needs this to work correctly.
128 useable_space
= bufsize
- ((smb_buf(outbuf
)+
129 alignment_offset
+data_alignment_offset
) -
133 * useable_space can never be more than max_send minus the
137 useable_space
= MIN(useable_space
,
138 max_send
- (alignment_offset
+data_alignment_offset
));
141 while (params_to_send
|| data_to_send
) {
144 * Calculate whether we will totally or partially fill this packet.
147 total_sent_thistime
= params_to_send
+ data_to_send
+
148 alignment_offset
+ data_alignment_offset
;
151 * We can never send more than useable_space.
154 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
156 set_message(outbuf
, 18, total_sent_thistime
, True
);
159 * Set total params and data to be sent.
162 SIVAL(outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
163 SIVAL(outbuf
,smb_ntr_TotalDataCount
,datasize
);
166 * Calculate how many parameters and data we can fit into
167 * this packet. Parameters get precedence.
170 params_sent_thistime
= MIN(params_to_send
,useable_space
);
171 data_sent_thistime
= useable_space
- params_sent_thistime
;
172 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
174 SIVAL(outbuf
,smb_ntr_ParameterCount
,params_sent_thistime
);
176 if(params_sent_thistime
== 0) {
177 SIVAL(outbuf
,smb_ntr_ParameterOffset
,0);
178 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,0);
181 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
182 * parameter bytes, however the first 4 bytes of outbuf are
183 * the Netbios over TCP header. Thus use smb_base() to subtract
184 * them from the calculation.
187 SIVAL(outbuf
,smb_ntr_ParameterOffset
,
188 ((smb_buf(outbuf
)+alignment_offset
) - smb_base(outbuf
)));
190 * Absolute displacement of param bytes sent in this packet.
193 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,pp
- params
);
197 * Deal with the data portion.
200 SIVAL(outbuf
,smb_ntr_DataCount
, data_sent_thistime
);
202 if(data_sent_thistime
== 0) {
203 SIVAL(outbuf
,smb_ntr_DataOffset
,0);
204 SIVAL(outbuf
,smb_ntr_DataDisplacement
, 0);
207 * The offset of the data bytes is the offset of the
208 * parameter bytes plus the number of parameters being sent this time.
211 SIVAL(outbuf
,smb_ntr_DataOffset
,((smb_buf(outbuf
)+alignment_offset
) -
212 smb_base(outbuf
)) + params_sent_thistime
+ data_alignment_offset
);
213 SIVAL(outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
217 * Copy the param bytes into the packet.
220 if(params_sent_thistime
) {
221 memcpy((smb_buf(outbuf
)+alignment_offset
),pp
,params_sent_thistime
);
225 * Copy in the data bytes
228 if(data_sent_thistime
) {
229 memcpy(smb_buf(outbuf
)+alignment_offset
+params_sent_thistime
+
230 data_alignment_offset
,pd
,data_sent_thistime
);
233 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
234 params_sent_thistime
, data_sent_thistime
, useable_space
));
235 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
236 params_to_send
, data_to_send
, paramsize
, datasize
));
238 /* Send the packet */
240 if (!send_smb(smbd_server_fd(),outbuf
)) {
241 exit_server("send_nt_replies: send_smb failed.");
244 pp
+= params_sent_thistime
;
245 pd
+= data_sent_thistime
;
247 params_to_send
-= params_sent_thistime
;
248 data_to_send
-= data_sent_thistime
;
254 if(params_to_send
< 0 || data_to_send
< 0) {
255 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
256 params_to_send
, data_to_send
));
264 /****************************************************************************
265 Is it an NTFS stream name ?
266 ****************************************************************************/
268 BOOL
is_ntfs_stream_name(const char *fname
)
270 if (lp_posix_pathnames()) {
273 return (strchr_m(fname
, ':') != NULL
) ? True
: False
;
276 /****************************************************************************
278 ****************************************************************************/
280 static BOOL saved_case_sensitive
;
281 static BOOL saved_case_preserve
;
282 static BOOL saved_short_case_preserve
;
284 /****************************************************************************
286 ****************************************************************************/
288 static void set_posix_case_semantics(connection_struct
*conn
, uint32 file_attributes
)
290 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
)) {
294 saved_case_sensitive
= conn
->case_sensitive
;
295 saved_case_preserve
= conn
->case_preserve
;
296 saved_short_case_preserve
= conn
->short_case_preserve
;
299 conn
->case_sensitive
= True
;
300 conn
->case_preserve
= True
;
301 conn
->short_case_preserve
= True
;
304 /****************************************************************************
305 Restore case semantics.
306 ****************************************************************************/
308 static void restore_case_semantics(connection_struct
*conn
, uint32 file_attributes
)
310 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
)) {
314 conn
->case_sensitive
= saved_case_sensitive
;
315 conn
->case_preserve
= saved_case_preserve
;
316 conn
->short_case_preserve
= saved_short_case_preserve
;
319 /****************************************************************************
320 Reply to an NT create and X call on a pipe.
321 ****************************************************************************/
323 static int nt_open_pipe(char *fname
, connection_struct
*conn
,
324 char *inbuf
, char *outbuf
, int *ppnum
)
326 smb_np_struct
*p
= NULL
;
327 uint16 vuid
= SVAL(inbuf
, smb_uid
);
330 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
332 /* See if it is one we want to handle. */
334 if (lp_disable_spoolss() && strequal(fname
, "\\spoolss")) {
335 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
338 for( i
= 0; known_nt_pipes
[i
]; i
++ ) {
339 if( strequal(fname
,known_nt_pipes
[i
])) {
344 if ( known_nt_pipes
[i
] == NULL
) {
345 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
348 /* Strip \\ off the name. */
351 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname
));
353 p
= open_rpc_pipe_p(fname
, conn
, vuid
);
355 return(ERROR_DOS(ERRSRV
,ERRnofids
));
362 /****************************************************************************
363 Reply to an NT create and X call for pipes.
364 ****************************************************************************/
366 static int do_ntcreate_pipe_open(connection_struct
*conn
,
367 char *inbuf
,char *outbuf
,int length
,int bufsize
)
374 srvstr_pull_buf(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), STR_TERMINATE
);
376 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0) {
381 * Deal with pipe return.
384 set_message(outbuf
,34,0,True
);
386 p
= outbuf
+ smb_vwv2
;
390 SIVAL(p
,0,FILE_WAS_OPENED
);
393 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
396 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
398 SSVAL(p
,2, 0x5FF); /* ? */
400 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
402 return chain_reply(inbuf
,outbuf
,length
,bufsize
);
405 /****************************************************************************
406 Reply to an NT create and X call for a quota file.
407 ****************************************************************************/
409 int reply_ntcreate_and_X_quota(connection_struct
*conn
,
414 enum FAKE_FILE_TYPE fake_file_type
,
419 uint32 desired_access
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
420 files_struct
*fsp
= open_fake_file(conn
, fake_file_type
, fname
, desired_access
);
423 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
426 set_message(outbuf
,34,0,True
);
428 p
= outbuf
+ smb_vwv2
;
430 /* SCVAL(p,0,NO_OPLOCK_RETURN); */
432 SSVAL(p
,0,fsp
->fnum
);
435 SIVAL(p
,0,smb_action
);
439 put_long_date(p
,c_time
);
441 put_long_date(p
,sbuf
.st_atime
); /* access time */
443 put_long_date(p
,sbuf
.st_mtime
); /* write time */
445 put_long_date(p
,sbuf
.st_mtime
); /* change time */
447 SIVAL(p
,0,fattr
); /* File Attributes. */
449 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
451 SOFF_T(p
,0,file_len
);
453 if (flags
& EXTENDED_RESPONSE_REQUIRED
)
456 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
459 DEBUG(5,("reply_ntcreate_and_X_quota: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
461 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
465 /****************************************************************************
466 Reply to an NT create and X call.
467 ****************************************************************************/
469 int reply_ntcreate_and_X(connection_struct
*conn
,
470 char *inbuf
,char *outbuf
,int length
,int bufsize
)
474 uint32 flags
= IVAL(inbuf
,smb_ntcreate_Flags
);
475 uint32 access_mask
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
476 uint32 file_attributes
= IVAL(inbuf
,smb_ntcreate_FileAttributes
);
477 uint32 share_access
= IVAL(inbuf
,smb_ntcreate_ShareAccess
);
478 uint32 create_disposition
= IVAL(inbuf
,smb_ntcreate_CreateDisposition
);
479 uint32 create_options
= IVAL(inbuf
,smb_ntcreate_CreateOptions
);
480 uint16 root_dir_fid
= (uint16
)IVAL(inbuf
,smb_ntcreate_RootDirectoryFid
);
481 /* Breakout the oplock request bits so we can set the
482 reply bits separately. */
483 int oplock_request
= 0;
485 SMB_OFF_T file_len
= 0;
486 SMB_STRUCT_STAT sbuf
;
488 BOOL bad_path
= False
;
489 files_struct
*fsp
=NULL
;
492 BOOL extended_oplock_granted
= False
;
495 START_PROFILE(SMBntcreateX
);
497 DEBUG(10,("reply_ntcreateX: flags = 0x%x, access_mask = 0x%x \
498 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
499 create_options = 0x%x root_dir_fid = 0x%x\n",
501 (unsigned int)access_mask
,
502 (unsigned int)file_attributes
,
503 (unsigned int)share_access
,
504 (unsigned int)create_disposition
,
505 (unsigned int)create_options
,
506 (unsigned int)root_dir_fid
));
508 /* If it's an IPC, use the pipe handler. */
511 if (lp_nt_pipe_support()) {
512 END_PROFILE(SMBntcreateX
);
513 return do_ntcreate_pipe_open(conn
,inbuf
,outbuf
,length
,bufsize
);
515 END_PROFILE(SMBntcreateX
);
516 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
520 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
521 END_PROFILE(SMBntcreateX
);
522 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
529 if(root_dir_fid
!= 0) {
531 * This filename is relative to a directory fid.
534 files_struct
*dir_fsp
= file_fsp(inbuf
,smb_ntcreate_RootDirectoryFid
);
538 END_PROFILE(SMBntcreateX
);
539 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
542 if(!dir_fsp
->is_directory
) {
544 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), 0, STR_TERMINATE
, &status
,False
);
545 if (!NT_STATUS_IS_OK(status
)) {
546 END_PROFILE(SMBntcreateX
);
547 return ERROR_NT(status
);
551 * Check to see if this is a mac fork of some kind.
554 if( is_ntfs_stream_name(fname
)) {
555 END_PROFILE(SMBntcreateX
);
556 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
560 we need to handle the case when we get a
561 relative open relative to a file and the
562 pathname is blank - this is a reopen!
563 (hint from demyn plantenberg)
566 END_PROFILE(SMBntcreateX
);
567 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
571 * Copy in the base directory name.
574 pstrcpy( fname
, dir_fsp
->fsp_name
);
575 dir_name_len
= strlen(fname
);
578 * Ensure it ends in a '\'.
581 if(fname
[dir_name_len
-1] != '\\' && fname
[dir_name_len
-1] != '/') {
586 srvstr_get_path(inbuf
, rel_fname
, smb_buf(inbuf
), sizeof(rel_fname
), 0, STR_TERMINATE
, &status
,False
);
587 if (!NT_STATUS_IS_OK(status
)) {
588 END_PROFILE(SMBntcreateX
);
589 return ERROR_NT(status
);
591 pstrcat(fname
, rel_fname
);
593 srvstr_get_path(inbuf
, fname
, smb_buf(inbuf
), sizeof(fname
), 0, STR_TERMINATE
, &status
,False
);
594 if (!NT_STATUS_IS_OK(status
)) {
595 END_PROFILE(SMBntcreateX
);
596 return ERROR_NT(status
);
600 * Check to see if this is a mac fork of some kind.
603 if( is_ntfs_stream_name(fname
)) {
604 enum FAKE_FILE_TYPE fake_file_type
= is_fake_file(fname
);
605 if (fake_file_type
!=FAKE_FILE_TYPE_NONE
) {
607 * Here we go! support for changing the disk quotas --metze
609 * We need to fake up to open this MAGIC QUOTA file
610 * and return a valid FID.
612 * w2k close this file directly after openening
613 * xp also tries a QUERY_FILE_INFO on the file and then close it
615 result
= reply_ntcreate_and_X_quota(conn
, inbuf
, outbuf
, length
, bufsize
,
616 fake_file_type
, fname
);
617 END_PROFILE(SMBntcreateX
);
620 END_PROFILE(SMBntcreateX
);
621 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
627 * Now contruct the smb_open_mode value from the filename,
628 * desired access and the share access.
630 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
632 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
633 if (oplock_request
) {
634 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
638 * Ordinary file or directory.
642 * Check if POSIX semantics are wanted.
645 set_posix_case_semantics(conn
, file_attributes
);
647 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
650 restore_case_semantics(conn
, file_attributes
);
651 END_PROFILE(SMBntcreateX
);
652 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
654 /* All file access must go through check_name() */
655 if (!check_name(fname
,conn
)) {
656 restore_case_semantics(conn
, file_attributes
);
657 END_PROFILE(SMBntcreateX
);
658 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRbadpath
);
662 /* This is the correct thing to do (check every time) but can_delete is
663 expensive (it may have to read the parent directory permissions). So
664 for now we're not doing it unless we have a strong hint the client
665 is really going to delete this file. */
666 if (desired_access
& DELETE_ACCESS
) {
668 /* Setting FILE_SHARE_DELETE is the hint. */
669 if (lp_acl_check_permissions(SNUM(conn
)) && (share_access
& FILE_SHARE_DELETE
)
670 && (access_mask
& DELETE_ACCESS
)) {
672 status
= can_delete(conn
, fname
, file_attributes
, bad_path
, True
);
673 /* We're only going to fail here if it's access denied, as that's the
674 only error we care about for "can we delete this ?" questions. */
675 if (!NT_STATUS_IS_OK(status
) && (NT_STATUS_EQUAL(status
,NT_STATUS_ACCESS_DENIED
) ||
676 NT_STATUS_EQUAL(status
,NT_STATUS_CANNOT_DELETE
))) {
677 restore_case_semantics(conn
, file_attributes
);
678 END_PROFILE(SMBntcreateX
);
679 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
684 * If it's a request for a directory open, deal with it separately.
687 if(create_options
& FILE_DIRECTORY_FILE
) {
690 /* Can't open a temp directory. IFS kit test. */
691 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
692 END_PROFILE(SMBntcreateX
);
693 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
696 fsp
= open_directory(conn
, fname
, &sbuf
,
703 restore_case_semantics(conn
, file_attributes
);
706 END_PROFILE(SMBntcreateX
);
707 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
711 * Ordinary file case.
714 /* NB. We have a potential bug here. If we
715 * cause an oplock break to ourselves, then we
716 * could end up processing filename related
717 * SMB requests whilst we await the oplock
718 * break response. As we may have changed the
719 * filename case semantics to be POSIX-like,
720 * this could mean a filename request could
721 * fail when it should succeed. This is a rare
722 * condition, but eventually we must arrange
723 * to restore the correct case semantics
724 * before issuing an oplock break request to
725 * our client. JRA. */
727 fsp
= open_file_ntcreate(conn
,fname
,&sbuf
,
736 /* We cheat here. There are two cases we
737 * care about. One is a directory rename,
738 * where the NT client will attempt to
739 * open the source directory for
740 * DELETE access. Note that when the
741 * NT client does this it does *not*
742 * set the directory bit in the
743 * request packet. This is translated
744 * into a read/write open
745 * request. POSIX states that any open
746 * for write request on a directory
747 * will generate an EISDIR error, so
748 * we can catch this here and open a
749 * pseudo handle that is flagged as a
750 * directory. The second is an open
751 * for a permissions read only, which
752 * we handle in the open_file_stat case. JRA.
755 if(errno
== EISDIR
) {
758 * Fail the open if it was explicitly a non-directory file.
761 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
762 restore_case_semantics(conn
, file_attributes
);
763 END_PROFILE(SMBntcreateX
);
764 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
768 fsp
= open_directory(conn
, fname
, &sbuf
,
776 restore_case_semantics(conn
, file_attributes
);
777 END_PROFILE(SMBntcreateX
);
778 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
782 restore_case_semantics(conn
, file_attributes
);
783 END_PROFILE(SMBntcreateX
);
784 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
785 /* We have re-scheduled this call. */
788 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
793 restore_case_semantics(conn
, file_attributes
);
795 file_len
= sbuf
.st_size
;
796 fattr
= dos_mode(conn
,fname
,&sbuf
);
798 fattr
= FILE_ATTRIBUTE_NORMAL
;
800 if (!fsp
->is_directory
&& (fattr
& aDIR
)) {
801 close_file(fsp
,False
);
802 END_PROFILE(SMBntcreateX
);
803 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
806 /* Save the requested allocation size. */
807 if ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
)) {
808 SMB_BIG_UINT allocation_size
= (SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
);
809 #ifdef LARGE_SMB_OFF_T
810 allocation_size
|= (((SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
+ 4)) << 32);
812 if (allocation_size
&& (allocation_size
> (SMB_BIG_UINT
)file_len
)) {
813 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, allocation_size
);
814 if (fsp
->is_directory
) {
815 close_file(fsp
,False
);
816 END_PROFILE(SMBntcreateX
);
817 /* Can't set allocation size on a directory. */
818 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
820 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
821 close_file(fsp
,False
);
822 END_PROFILE(SMBntcreateX
);
823 return ERROR_NT(NT_STATUS_DISK_FULL
);
826 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
,(SMB_BIG_UINT
)file_len
);
831 * If the caller set the extended oplock request bit
832 * and we granted one (by whatever means) - set the
833 * correct bit for extended oplock reply.
836 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
837 extended_oplock_granted
= True
;
840 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
)) {
841 extended_oplock_granted
= True
;
845 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
846 set_message(outbuf
,42,0,True
);
848 set_message(outbuf
,34,0,True
);
851 p
= outbuf
+ smb_vwv2
;
854 * Currently as we don't support level II oplocks we just report
855 * exclusive & batch here.
858 if (extended_oplock_granted
) {
859 if (flags
& REQUEST_BATCH_OPLOCK
) {
860 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
862 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
864 } else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
)) {
865 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
867 SCVAL(p
,0,NO_OPLOCK_RETURN
);
871 SSVAL(p
,0,fsp
->fnum
);
873 if ((create_disposition
== FILE_SUPERSEDE
) && (info
== FILE_WAS_OVERWRITTEN
)) {
874 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
881 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
883 if (lp_dos_filetime_resolution(SNUM(conn
))) {
890 put_long_date(p
,c_time
);
892 put_long_date(p
,sbuf
.st_atime
); /* access time */
894 put_long_date(p
,sbuf
.st_mtime
); /* write time */
896 put_long_date(p
,sbuf
.st_mtime
); /* change time */
898 SIVAL(p
,0,fattr
); /* File Attributes. */
900 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
902 SOFF_T(p
,0,file_len
);
904 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
908 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
910 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
912 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
913 END_PROFILE(SMBntcreateX
);
917 /****************************************************************************
918 Reply to a NT_TRANSACT_CREATE call to open a pipe.
919 ****************************************************************************/
921 static int do_nt_transact_create_pipe( connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
922 char **ppsetup
, uint32 setup_count
,
923 char **ppparams
, uint32 parameter_count
,
924 char **ppdata
, uint32 data_count
)
927 char *params
= *ppparams
;
934 * Ensure minimum number of parameters sent.
937 if(parameter_count
< 54) {
938 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
939 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
942 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
943 if (!NT_STATUS_IS_OK(status
)) {
944 return ERROR_NT(status
);
947 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0) {
951 /* Realloc the size of parameters and data we will return */
952 params
= nttrans_realloc(ppparams
, 69);
954 return ERROR_DOS(ERRDOS
,ERRnomem
);
958 SCVAL(p
,0,NO_OPLOCK_RETURN
);
963 SIVAL(p
,0,FILE_WAS_OPENED
);
967 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
970 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
972 SSVAL(p
,2, 0x5FF); /* ? */
974 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
976 /* Send the required number of replies */
977 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
982 /****************************************************************************
983 Internal fn to set security descriptors.
984 ****************************************************************************/
986 static NTSTATUS
set_sd(files_struct
*fsp
, char *data
, uint32 sd_len
, uint32 security_info_sent
)
989 SEC_DESC
*psd
= NULL
;
993 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
998 * Init the parse struct we will unmarshall from.
1001 if ((mem_ctx
= talloc_init("set_sd")) == NULL
) {
1002 DEBUG(0,("set_sd: talloc_init failed.\n"));
1003 return NT_STATUS_NO_MEMORY
;
1006 prs_init(&pd
, 0, mem_ctx
, UNMARSHALL
);
1009 * Setup the prs_struct to point at the memory we just
1013 prs_give_memory( &pd
, data
, sd_len
, False
);
1016 * Finally, unmarshall from the data buffer.
1019 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1020 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1022 * Return access denied for want of a better error message..
1024 talloc_destroy(mem_ctx
);
1025 return NT_STATUS_NO_MEMORY
;
1028 if (psd
->off_owner_sid
==0) {
1029 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
1031 if (psd
->off_grp_sid
==0) {
1032 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
1034 if (psd
->off_sacl
==0) {
1035 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
1037 if (psd
->off_dacl
==0) {
1038 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
1041 ret
= SMB_VFS_FSET_NT_ACL( fsp
, fsp
->fh
->fd
, security_info_sent
, psd
);
1044 talloc_destroy(mem_ctx
);
1045 return NT_STATUS_ACCESS_DENIED
;
1048 talloc_destroy(mem_ctx
);
1050 return NT_STATUS_OK
;
1053 /****************************************************************************
1054 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1055 ****************************************************************************/
1057 static struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
1059 struct ea_list
*ea_list_head
= NULL
;
1062 if (data_size
< 4) {
1066 while (offset
+ 4 <= data_size
) {
1067 size_t next_offset
= IVAL(pdata
,offset
);
1068 struct ea_list
*tmp
;
1069 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
1071 DLIST_ADD_END(ea_list_head
, eal
, tmp
);
1072 if (next_offset
== 0) {
1075 offset
+= next_offset
;
1078 return ea_list_head
;
1081 /****************************************************************************
1082 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1083 ****************************************************************************/
1085 static int call_nt_transact_create(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1086 char **ppsetup
, uint32 setup_count
,
1087 char **ppparams
, uint32 parameter_count
,
1088 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1091 char *params
= *ppparams
;
1092 char *data
= *ppdata
;
1093 /* Breakout the oplock request bits so we can set the reply bits separately. */
1094 int oplock_request
= 0;
1096 SMB_OFF_T file_len
= 0;
1097 SMB_STRUCT_STAT sbuf
;
1099 BOOL bad_path
= False
;
1100 files_struct
*fsp
= NULL
;
1102 BOOL extended_oplock_granted
= False
;
1105 uint32 file_attributes
;
1106 uint32 share_access
;
1107 uint32 create_disposition
;
1108 uint32 create_options
;
1111 uint16 root_dir_fid
;
1113 struct ea_list
*ea_list
= NULL
;
1114 TALLOC_CTX
*ctx
= NULL
;
1118 DEBUG(5,("call_nt_transact_create\n"));
1121 * If it's an IPC, use the pipe handler.
1125 if (lp_nt_pipe_support()) {
1126 return do_nt_transact_create_pipe(conn
, inbuf
, outbuf
, length
,
1128 ppsetup
, setup_count
,
1129 ppparams
, parameter_count
,
1130 ppdata
, data_count
);
1132 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1137 * Ensure minimum number of parameters sent.
1140 if(parameter_count
< 54) {
1141 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1142 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1145 flags
= IVAL(params
,0);
1146 access_mask
= IVAL(params
,8);
1147 file_attributes
= IVAL(params
,20);
1148 share_access
= IVAL(params
,24);
1149 create_disposition
= IVAL(params
,28);
1150 create_options
= IVAL(params
,32);
1151 sd_len
= IVAL(params
,36);
1152 ea_len
= IVAL(params
,40);
1153 root_dir_fid
= (uint16
)IVAL(params
,4);
1155 /* Ensure the data_len is correct for the sd and ea values given. */
1156 if ((ea_len
+ sd_len
> data_count
) ||
1157 (ea_len
> data_count
) || (sd_len
> data_count
) ||
1158 (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1159 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1160 (unsigned int)ea_len
, (unsigned int)sd_len
, (unsigned int)data_count
));
1161 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1165 if (!lp_ea_support(SNUM(conn
))) {
1166 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1167 (unsigned int)ea_len
));
1168 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED
);
1172 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1173 (unsigned int)ea_len
));
1174 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1178 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
1179 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1183 * Get the file name.
1186 if(root_dir_fid
!= 0) {
1188 * This filename is relative to a directory fid.
1190 files_struct
*dir_fsp
= file_fsp(params
,4);
1191 size_t dir_name_len
;
1194 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1197 if(!dir_fsp
->is_directory
) {
1198 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
1199 if (!NT_STATUS_IS_OK(status
)) {
1200 return ERROR_NT(status
);
1204 * Check to see if this is a mac fork of some kind.
1207 if( is_ntfs_stream_name(fname
)) {
1208 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1211 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1215 * Copy in the base directory name.
1218 pstrcpy( fname
, dir_fsp
->fsp_name
);
1219 dir_name_len
= strlen(fname
);
1222 * Ensure it ends in a '\'.
1225 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
1226 pstrcat(fname
, "/");
1232 srvstr_get_path(inbuf
, tmpname
, params
+53, sizeof(tmpname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
1233 if (!NT_STATUS_IS_OK(status
)) {
1234 return ERROR_NT(status
);
1236 pstrcat(fname
, tmpname
);
1239 srvstr_get_path(inbuf
, fname
, params
+53, sizeof(fname
), parameter_count
-53, STR_TERMINATE
, &status
, False
);
1240 if (!NT_STATUS_IS_OK(status
)) {
1241 return ERROR_NT(status
);
1245 * Check to see if this is a mac fork of some kind.
1248 if( is_ntfs_stream_name(fname
)) {
1249 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1253 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1254 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1257 * Check if POSIX semantics are wanted.
1260 set_posix_case_semantics(conn
, file_attributes
);
1262 RESOLVE_DFSPATH(fname
, conn
, inbuf
, outbuf
);
1264 unix_convert(fname
,conn
,0,&bad_path
,&sbuf
);
1266 restore_case_semantics(conn
, file_attributes
);
1267 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1269 /* All file access must go through check_name() */
1270 if (!check_name(fname
,conn
)) {
1271 restore_case_semantics(conn
, file_attributes
);
1272 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRbadpath
);
1276 /* This is the correct thing to do (check every time) but can_delete is
1277 expensive (it may have to read the parent directory permissions). So
1278 for now we're not doing it unless we have a strong hint the client
1279 is really going to delete this file. */
1280 if (desired_access
& DELETE_ACCESS
) {
1282 /* Setting FILE_SHARE_DELETE is the hint. */
1283 if (lp_acl_check_permissions(SNUM(conn
)) && (share_access
& FILE_SHARE_DELETE
) && (access_mask
& DELETE_ACCESS
)) {
1285 status
= can_delete(conn
, fname
, file_attributes
, bad_path
, True
);
1286 /* We're only going to fail here if it's access denied, as that's the
1287 only error we care about for "can we delete this ?" questions. */
1288 if (!NT_STATUS_IS_OK(status
) && (NT_STATUS_EQUAL(status
,NT_STATUS_ACCESS_DENIED
) ||
1289 NT_STATUS_EQUAL(status
,NT_STATUS_CANNOT_DELETE
))) {
1290 restore_case_semantics(conn
, file_attributes
);
1291 END_PROFILE(SMBntcreateX
);
1292 return ERROR_NT(status
);
1297 ctx
= talloc_init("NTTRANS_CREATE_EA");
1299 talloc_destroy(ctx
);
1300 restore_case_semantics(conn
, file_attributes
);
1301 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1304 pdata
= data
+ sd_len
;
1306 /* We have already checked that ea_len <= data_count here. */
1307 ea_list
= read_nttrans_ea_list(ctx
, pdata
, ea_len
);
1309 talloc_destroy(ctx
);
1310 restore_case_semantics(conn
, file_attributes
);
1311 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1316 * If it's a request for a directory open, deal with it separately.
1319 if(create_options
& FILE_DIRECTORY_FILE
) {
1321 /* Can't open a temp directory. IFS kit test. */
1322 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
1323 talloc_destroy(ctx
);
1324 restore_case_semantics(conn
, file_attributes
);
1325 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1331 * We will get a create directory here if the Win32
1332 * app specified a security descriptor in the
1333 * CreateDirectory() call.
1336 fsp
= open_directory(conn
, fname
, &sbuf
,
1343 talloc_destroy(ctx
);
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_ntcreate(conn
,fname
,&sbuf
,
1364 if(errno
== EISDIR
) {
1367 * Fail the open if it was explicitly a non-directory file.
1370 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
1371 restore_case_semantics(conn
, file_attributes
);
1372 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
1376 fsp
= open_directory(conn
, fname
, &sbuf
,
1383 talloc_destroy(ctx
);
1384 restore_case_semantics(conn
, file_attributes
);
1385 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1388 talloc_destroy(ctx
);
1389 restore_case_semantics(conn
, file_attributes
);
1390 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1391 /* We have re-scheduled this call. */
1394 return set_bad_path_error(errno
, bad_path
, outbuf
, ERRDOS
,ERRnoaccess
);
1400 * According to the MS documentation, the only time the security
1401 * descriptor is applied to the opened file is iff we *created* the
1402 * file; an existing file stays the same.
1404 * Also, it seems (from observation) that you can open the file with
1405 * any access mask but you can still write the sd. We need to override
1406 * the granted access before we call set_sd
1407 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1410 if (lp_nt_acl_support(SNUM(conn
)) && sd_len
&& info
== FILE_WAS_CREATED
) {
1411 uint32 saved_access_mask
= fsp
->access_mask
;
1413 /* We have already checked that sd_len <= data_count here. */
1415 fsp
->access_mask
= FILE_GENERIC_ALL
;
1417 status
= set_sd( fsp
, data
, sd_len
, ALL_SECURITY_INFORMATION
);
1418 if (!NT_STATUS_IS_OK(status
)) {
1419 talloc_destroy(ctx
);
1420 close_file(fsp
,False
);
1421 restore_case_semantics(conn
, file_attributes
);
1422 return ERROR_NT(status
);
1424 fsp
->access_mask
= saved_access_mask
;
1427 if (ea_len
&& (info
== FILE_WAS_CREATED
)) {
1428 status
= set_ea(conn
, fsp
, fname
, ea_list
);
1429 talloc_destroy(ctx
);
1430 if (!NT_STATUS_IS_OK(status
)) {
1431 close_file(fsp
,False
);
1432 restore_case_semantics(conn
, file_attributes
);
1433 return ERROR_NT(status
);
1437 restore_case_semantics(conn
, file_attributes
);
1439 file_len
= sbuf
.st_size
;
1440 fattr
= dos_mode(conn
,fname
,&sbuf
);
1442 fattr
= FILE_ATTRIBUTE_NORMAL
;
1444 if (!fsp
->is_directory
&& (fattr
& aDIR
)) {
1445 close_file(fsp
,False
);
1446 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1449 /* Save the requested allocation size. */
1450 if ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
)) {
1451 SMB_BIG_UINT allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
1452 #ifdef LARGE_SMB_OFF_T
1453 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
1455 if (allocation_size
&& (allocation_size
> file_len
)) {
1456 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, allocation_size
);
1457 if (fsp
->is_directory
) {
1458 close_file(fsp
,False
);
1459 /* Can't set allocation size on a directory. */
1460 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1462 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
1463 close_file(fsp
,False
);
1464 return ERROR_NT(NT_STATUS_DISK_FULL
);
1467 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, (SMB_BIG_UINT
)file_len
);
1472 * If the caller set the extended oplock request bit
1473 * and we granted one (by whatever means) - set the
1474 * correct bit for extended oplock reply.
1477 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
1478 extended_oplock_granted
= True
;
1481 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
)) {
1482 extended_oplock_granted
= True
;
1485 /* Realloc the size of parameters and data we will return */
1486 params
= nttrans_realloc(ppparams
, 69);
1487 if(params
== NULL
) {
1488 return ERROR_DOS(ERRDOS
,ERRnomem
);
1492 if (extended_oplock_granted
) {
1493 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
1494 } else if (LEVEL_II_OPLOCK_TYPE(fsp
->oplock_type
)) {
1495 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
1497 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1501 SSVAL(p
,0,fsp
->fnum
);
1503 if ((create_disposition
== FILE_SUPERSEDE
) && (info
== FILE_WAS_OVERWRITTEN
)) {
1504 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1511 c_time
= get_create_time(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1513 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1515 sbuf
.st_atime
&= ~1;
1516 sbuf
.st_mtime
&= ~1;
1517 sbuf
.st_mtime
&= ~1;
1520 put_long_date(p
,c_time
);
1522 put_long_date(p
,sbuf
.st_atime
); /* access time */
1524 put_long_date(p
,sbuf
.st_mtime
); /* write time */
1526 put_long_date(p
,sbuf
.st_mtime
); /* change time */
1528 SIVAL(p
,0,fattr
); /* File Attributes. */
1530 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
1532 SOFF_T(p
,0,file_len
);
1534 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1538 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1540 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname
));
1542 /* Send the required number of replies */
1543 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 69, *ppdata
, 0);
1548 /****************************************************************************
1549 Reply to a NT CANCEL request.
1550 ****************************************************************************/
1552 int reply_ntcancel(connection_struct
*conn
,
1553 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1556 * Go through and cancel any pending change notifies.
1559 int mid
= SVAL(inbuf
,smb_mid
);
1560 START_PROFILE(SMBntcancel
);
1561 remove_pending_change_notify_requests_by_mid(mid
);
1562 remove_pending_lock_requests_by_mid(mid
);
1563 srv_cancel_sign_response(mid
);
1565 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid
));
1567 END_PROFILE(SMBntcancel
);
1571 /****************************************************************************
1573 ****************************************************************************/
1575 static NTSTATUS
copy_internals(connection_struct
*conn
, char *oldname
, char *newname
, uint32 attrs
)
1577 BOOL bad_path_oldname
= False
;
1578 BOOL bad_path_newname
= False
;
1579 SMB_STRUCT_STAT sbuf1
, sbuf2
;
1580 pstring last_component_oldname
;
1581 pstring last_component_newname
;
1582 files_struct
*fsp1
,*fsp2
;
1587 NTSTATUS status
= NT_STATUS_OK
;
1593 if (ms_has_wild(newname
) || ms_has_wild(oldname
)) {
1594 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1597 if (!CAN_WRITE(conn
))
1598 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1600 unix_convert(oldname
,conn
,last_component_oldname
,&bad_path_oldname
,&sbuf1
);
1601 if (bad_path_oldname
) {
1602 return NT_STATUS_OBJECT_PATH_NOT_FOUND
;
1605 /* Quick check for "." and ".." */
1606 if (last_component_oldname
[0] == '.') {
1607 if (!last_component_oldname
[1] || (last_component_oldname
[1] == '.' && !last_component_oldname
[2])) {
1608 return NT_STATUS_OBJECT_NAME_INVALID
;
1612 /* Source must already exist. */
1613 if (!VALID_STAT(sbuf1
)) {
1614 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1616 if (!check_name(oldname
,conn
)) {
1617 return NT_STATUS_ACCESS_DENIED
;
1620 /* Ensure attributes match. */
1621 fattr
= dos_mode(conn
,oldname
,&sbuf1
);
1622 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1623 return NT_STATUS_NO_SUCH_FILE
;
1626 unix_convert(newname
,conn
,last_component_newname
,&bad_path_newname
,&sbuf2
);
1627 if (bad_path_newname
) {
1628 return NT_STATUS_OBJECT_PATH_NOT_FOUND
;
1631 /* Quick check for "." and ".." */
1632 if (last_component_newname
[0] == '.') {
1633 if (!last_component_newname
[1] || (last_component_newname
[1] == '.' && !last_component_newname
[2])) {
1634 return NT_STATUS_OBJECT_NAME_INVALID
;
1638 /* Disallow if newname already exists. */
1639 if (VALID_STAT(sbuf2
)) {
1640 return NT_STATUS_OBJECT_NAME_COLLISION
;
1643 if (!check_name(newname
,conn
)) {
1644 return NT_STATUS_ACCESS_DENIED
;
1647 /* No links from a directory. */
1648 if (S_ISDIR(sbuf1
.st_mode
)) {
1649 return NT_STATUS_FILE_IS_A_DIRECTORY
;
1652 /* Ensure this is within the share. */
1653 if (!reduce_name(conn
, oldname
) != 0) {
1654 return NT_STATUS_ACCESS_DENIED
;
1657 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname
, newname
));
1659 fsp1
= open_file_ntcreate(conn
,oldname
,&sbuf1
,
1660 FILE_READ_DATA
, /* Read-only. */
1661 0, /* No sharing. */
1663 0, /* No create options. */
1664 FILE_ATTRIBUTE_NORMAL
,
1669 get_saved_error_triple(NULL
, NULL
, &status
);
1670 if (NT_STATUS_IS_OK(status
)) {
1671 status
= NT_STATUS_ACCESS_DENIED
;
1673 set_saved_error_triple(0, 0, NT_STATUS_OK
);
1677 fsp2
= open_file_ntcreate(conn
,newname
,&sbuf2
,
1678 FILE_WRITE_DATA
, /* Read-only. */
1679 0, /* No sharing. */
1681 0, /* No create options. */
1687 get_saved_error_triple(NULL
, NULL
, &status
);
1688 if (NT_STATUS_IS_OK(status
)) {
1689 status
= NT_STATUS_ACCESS_DENIED
;
1691 set_saved_error_triple(0, 0, NT_STATUS_OK
);
1692 close_file(fsp1
,False
);
1696 if (sbuf1
.st_size
) {
1697 ret
= vfs_transfer_file(fsp1
, fsp2
, sbuf1
.st_size
);
1701 * As we are opening fsp1 read-only we only expect
1702 * an error on close on fsp2 if we are out of space.
1703 * Thus we don't look at the error return from the
1706 close_file(fsp1
,False
);
1708 /* Ensure the modtime is set correctly on the destination file. */
1709 fsp_set_pending_modtime(fsp2
, sbuf1
.st_mtime
);
1711 close_ret
= close_file(fsp2
,False
);
1713 /* Grrr. We have to do this as open_file_shared1 adds aARCH when it
1714 creates the file. This isn't the correct thing to do in the copy case. JRA */
1715 file_set_dosmode(conn
, newname
, fattr
, &sbuf2
, True
);
1717 if (ret
< (SMB_OFF_T
)sbuf1
.st_size
) {
1718 return NT_STATUS_DISK_FULL
;
1721 if (close_ret
!= 0) {
1722 status
= map_nt_error_from_unix(close_ret
);
1723 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1724 nt_errstr(status
), oldname
, newname
));
1729 /****************************************************************************
1730 Reply to a NT rename request.
1731 ****************************************************************************/
1733 int reply_ntrename(connection_struct
*conn
,
1734 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1741 uint32 attrs
= SVAL(inbuf
,smb_vwv0
);
1742 uint16 rename_type
= SVAL(inbuf
,smb_vwv1
);
1744 START_PROFILE(SMBntrename
);
1746 p
= smb_buf(inbuf
) + 1;
1747 p
+= srvstr_get_path(inbuf
, oldname
, p
, sizeof(oldname
), 0, STR_TERMINATE
, &status
, True
);
1748 if (!NT_STATUS_IS_OK(status
)) {
1749 END_PROFILE(SMBntrename
);
1750 return ERROR_NT(status
);
1753 if( is_ntfs_stream_name(oldname
)) {
1754 /* Can't rename a stream. */
1755 END_PROFILE(SMBntrename
);
1756 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1759 if (ms_has_wild(oldname
)) {
1760 END_PROFILE(SMBntrename
);
1761 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1765 p
+= srvstr_get_path(inbuf
, newname
, p
, sizeof(newname
), 0, STR_TERMINATE
, &status
, False
);
1766 if (!NT_STATUS_IS_OK(status
)) {
1767 END_PROFILE(SMBntrename
);
1768 return ERROR_NT(status
);
1771 RESOLVE_DFSPATH(oldname
, conn
, inbuf
, outbuf
);
1772 RESOLVE_DFSPATH(newname
, conn
, inbuf
, outbuf
);
1774 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1776 switch(rename_type
) {
1777 case RENAME_FLAG_RENAME
:
1778 status
= rename_internals(conn
, oldname
, newname
, attrs
, False
);
1780 case RENAME_FLAG_HARD_LINK
:
1781 status
= hardlink_internals(conn
, oldname
, newname
);
1783 case RENAME_FLAG_COPY
:
1784 status
= copy_internals(conn
, oldname
, newname
, attrs
);
1786 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1787 status
= NT_STATUS_INVALID_PARAMETER
;
1790 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1794 if (!NT_STATUS_IS_OK(status
)) {
1795 END_PROFILE(SMBntrename
);
1796 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1797 /* We have re-scheduled this call. */
1800 return ERROR_NT(status
);
1804 * Win2k needs a changenotify request response before it will
1805 * update after a rename..
1807 process_pending_change_notify_queue((time_t)0);
1808 outsize
= set_message(outbuf
,0,0,True
);
1810 END_PROFILE(SMBntrename
);
1814 /****************************************************************************
1815 Reply to an unsolicited SMBNTtranss - just ignore it!
1816 ****************************************************************************/
1818 int reply_nttranss(connection_struct
*conn
,
1819 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1821 START_PROFILE(SMBnttranss
);
1822 DEBUG(4,("Ignoring nttranss of length %d\n",length
));
1823 END_PROFILE(SMBnttranss
);
1827 /****************************************************************************
1828 Reply to a notify change - queue the request and
1829 don't allow a directory to be opened.
1830 ****************************************************************************/
1832 static int call_nt_transact_notify_change(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1833 char **ppsetup
, uint32 setup_count
,
1834 char **ppparams
, uint32 parameter_count
,
1835 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1837 char *setup
= *ppsetup
;
1841 if(setup_count
< 6) {
1842 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1845 fsp
= file_fsp(setup
,4);
1846 flags
= IVAL(setup
, 0);
1848 DEBUG(3,("call_nt_transact_notify_change\n"));
1851 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1854 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1855 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1858 if (!change_notify_set(inbuf
, fsp
, conn
, flags
)) {
1859 return(UNIXERROR(ERRDOS
,ERRbadfid
));
1862 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1863 name = %s\n", fsp
->fsp_name
));
1868 /****************************************************************************
1869 Reply to an NT transact rename command.
1870 ****************************************************************************/
1872 static int call_nt_transact_rename(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1873 char **ppsetup
, uint32 setup_count
,
1874 char **ppparams
, uint32 parameter_count
,
1875 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1877 char *params
= *ppparams
;
1879 files_struct
*fsp
= NULL
;
1880 BOOL replace_if_exists
= False
;
1883 if(parameter_count
< 4) {
1884 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1887 fsp
= file_fsp(params
, 0);
1888 replace_if_exists
= (SVAL(params
,2) & RENAME_REPLACE_IF_EXISTS
) ? True
: False
;
1889 CHECK_FSP(fsp
, conn
);
1890 srvstr_get_path(inbuf
, new_name
, params
+4, sizeof(new_name
), -1, STR_TERMINATE
, &status
, True
);
1891 if (!NT_STATUS_IS_OK(status
)) {
1892 return ERROR_NT(status
);
1895 status
= rename_internals(conn
, fsp
->fsp_name
,
1896 new_name
, 0, replace_if_exists
);
1897 if (!NT_STATUS_IS_OK(status
))
1898 return ERROR_NT(status
);
1901 * Rename was successful.
1903 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1905 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1906 fsp
->fsp_name
, new_name
));
1909 * Win2k needs a changenotify request response before it will
1910 * update after a rename..
1913 process_pending_change_notify_queue((time_t)0);
1918 /******************************************************************************
1919 Fake up a completely empty SD.
1920 *******************************************************************************/
1922 static size_t get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1926 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1928 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1935 /****************************************************************************
1936 Reply to query a security descriptor.
1937 ****************************************************************************/
1939 static int call_nt_transact_query_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1940 char **ppsetup
, uint32 setup_count
,
1941 char **ppparams
, uint32 parameter_count
,
1942 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1944 char *params
= *ppparams
;
1945 char *data
= *ppdata
;
1947 SEC_DESC
*psd
= NULL
;
1949 uint32 security_info_wanted
;
1950 TALLOC_CTX
*mem_ctx
;
1951 files_struct
*fsp
= NULL
;
1953 if(parameter_count
< 8) {
1954 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1957 fsp
= file_fsp(params
,0);
1959 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1962 security_info_wanted
= IVAL(params
,4);
1964 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp
->fsp_name
,
1965 (unsigned int)security_info_wanted
));
1967 params
= nttrans_realloc(ppparams
, 4);
1968 if(params
== NULL
) {
1969 return ERROR_DOS(ERRDOS
,ERRnomem
);
1972 if ((mem_ctx
= talloc_init("call_nt_transact_query_security_desc")) == NULL
) {
1973 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1974 return ERROR_DOS(ERRDOS
,ERRnomem
);
1978 * Get the permissions to return.
1981 if (!lp_nt_acl_support(SNUM(conn
))) {
1982 sd_size
= get_null_nt_acl(mem_ctx
, &psd
);
1984 sd_size
= SMB_VFS_FGET_NT_ACL(fsp
, fsp
->fh
->fd
, security_info_wanted
, &psd
);
1988 talloc_destroy(mem_ctx
);
1989 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
1992 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size
));
1994 SIVAL(params
,0,(uint32
)sd_size
);
1996 if(max_data_count
< sd_size
) {
1998 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_BUFFER_TOO_SMALL
,
1999 params
, 4, *ppdata
, 0);
2000 talloc_destroy(mem_ctx
);
2005 * Allocate the data we will point this at.
2008 data
= nttrans_realloc(ppdata
, sd_size
);
2010 talloc_destroy(mem_ctx
);
2011 return ERROR_DOS(ERRDOS
,ERRnomem
);
2015 * Init the parse struct we will marshall into.
2018 prs_init(&pd
, 0, mem_ctx
, MARSHALL
);
2021 * Setup the prs_struct to point at the memory we just
2025 prs_give_memory( &pd
, data
, (uint32
)sd_size
, False
);
2028 * Finally, linearize into the outgoing buffer.
2031 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
2032 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2033 security descriptor.\n"));
2035 * Return access denied for want of a better error message..
2037 talloc_destroy(mem_ctx
);
2038 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
2042 * Now we can delete the security descriptor.
2045 talloc_destroy(mem_ctx
);
2047 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
2051 /****************************************************************************
2052 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2053 ****************************************************************************/
2055 static int call_nt_transact_set_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2056 char **ppsetup
, uint32 setup_count
,
2057 char **ppparams
, uint32 parameter_count
,
2058 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2060 char *params
= *ppparams
;
2061 char *data
= *ppdata
;
2062 files_struct
*fsp
= NULL
;
2063 uint32 security_info_sent
= 0;
2066 if(parameter_count
< 8) {
2067 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2070 if((fsp
= file_fsp(params
,0)) == NULL
) {
2071 return ERROR_DOS(ERRDOS
,ERRbadfid
);
2074 if(!lp_nt_acl_support(SNUM(conn
))) {
2078 security_info_sent
= IVAL(params
,4);
2080 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
2081 (unsigned int)security_info_sent
));
2083 if (data_count
== 0) {
2084 return ERROR_DOS(ERRDOS
, ERRnoaccess
);
2087 if (!NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, data_count
, security_info_sent
))) {
2088 return ERROR_NT(nt_status
);
2093 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2097 /****************************************************************************
2099 ****************************************************************************/
2101 static int call_nt_transact_ioctl(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2102 char **ppsetup
, uint32 setup_count
,
2103 char **ppparams
, uint32 parameter_count
,
2104 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2111 static BOOL logged_message
;
2112 char *pdata
= *ppdata
;
2114 if (setup_count
!= 8) {
2115 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
2116 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2119 function
= IVAL(*ppsetup
, 0);
2120 fidnum
= SVAL(*ppsetup
, 4);
2121 isFSctl
= CVAL(*ppsetup
, 6);
2122 compfilter
= CVAL(*ppsetup
, 7);
2124 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2125 function
, fidnum
, isFSctl
, compfilter
));
2127 fsp
=file_fsp(*ppsetup
, 4);
2128 /* this check is done in each implemented function case for now
2129 because I don't want to break anything... --metze
2130 FSP_BELONGS_CONN(fsp,conn);*/
2133 case FSCTL_SET_SPARSE
:
2134 /* pretend this succeeded - tho strictly we should
2135 mark the file sparse (if the local fs supports it)
2136 so we can know if we need to pre-allocate or not */
2138 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
2139 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2142 case FSCTL_0x000900C0
:
2143 /* pretend this succeeded - don't know what this really is
2144 but works ok like this --metze
2147 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum
));
2148 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2151 case FSCTL_GET_REPARSE_POINT
:
2152 /* pretend this fail - my winXP does it like this
2156 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2157 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
2160 case FSCTL_SET_REPARSE_POINT
:
2161 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2165 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2166 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_NOT_A_REPARSE_POINT
, NULL
, 0, NULL
, 0);
2169 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
2172 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2173 * and return their volume names. If max_data_count is 16, then it is just
2174 * asking for the number of volumes and length of the combined names.
2176 * pdata is the data allocated by our caller, but that uses
2177 * total_data_count (which is 0 in our case) rather than max_data_count.
2178 * Allocate the correct amount and return the pointer to let
2179 * it be deallocated when we return.
2181 SHADOW_COPY_DATA
*shadow_data
= NULL
;
2182 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
2183 BOOL labels
= False
;
2184 uint32 labels_data_count
= 0;
2188 FSP_BELONGS_CONN(fsp
,conn
);
2190 if (max_data_count
< 16) {
2191 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2193 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
2196 if (max_data_count
> 16) {
2200 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
2201 if (shadow_mem_ctx
== NULL
) {
2202 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2203 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2206 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
2207 if (shadow_data
== NULL
) {
2208 DEBUG(0,("talloc_zero() failed!\n"));
2209 talloc_destroy(shadow_mem_ctx
);
2210 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2213 shadow_data
->mem_ctx
= shadow_mem_ctx
;
2216 * Call the VFS routine to actually do the work.
2218 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2219 talloc_destroy(shadow_data
->mem_ctx
);
2220 if (errno
== ENOSYS
) {
2221 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2222 conn
->connectpath
));
2223 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2225 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2226 conn
->connectpath
));
2227 return ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
2231 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2236 data_count
= 12+labels_data_count
+4;
2239 if (max_data_count
<data_count
) {
2240 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2241 max_data_count
,data_count
));
2242 talloc_destroy(shadow_data
->mem_ctx
);
2243 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL
);
2246 pdata
= nttrans_realloc(ppdata
, data_count
);
2247 if (pdata
== NULL
) {
2248 talloc_destroy(shadow_data
->mem_ctx
);
2249 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2254 /* num_volumes 4 bytes */
2255 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2258 /* num_labels 4 bytes */
2259 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2262 /* needed_data_count 4 bytes */
2263 SIVAL(pdata
,8,labels_data_count
);
2267 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2268 shadow_data
->num_volumes
,fsp
->fsp_name
));
2269 if (labels
&& shadow_data
->labels
) {
2270 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2271 srvstr_push(outbuf
, cur_pdata
, shadow_data
->labels
[i
], 2*sizeof(SHADOW_COPY_LABEL
), STR_UNICODE
|STR_TERMINATE
);
2272 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2273 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2277 talloc_destroy(shadow_data
->mem_ctx
);
2279 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, pdata
, data_count
);
2284 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2286 /* pretend this succeeded -
2288 * we have to send back a list with all files owned by this SID
2290 * but I have to check that --metze
2294 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2296 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2298 FSP_BELONGS_CONN(fsp
,conn
);
2300 /* unknown 4 bytes: this is not the length of the sid :-( */
2301 /*unknown = IVAL(pdata,0);*/
2303 sid_parse(pdata
+4,sid_len
,&sid
);
2304 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid
)));
2306 if (!NT_STATUS_IS_OK(sid_to_uid(&sid
, &uid
))) {
2307 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2308 sid_string_static(&sid
),(unsigned long)sid_len
));
2312 /* we can take a look at the find source :-)
2314 * find ./ -uid $uid -name '*' is what we need here
2317 * and send 4bytes len and then NULL terminated unicode strings
2320 * but I don't know how to deal with the paged results
2321 * (maybe we can hang the result anywhere in the fsp struct)
2323 * we don't send all files at once
2324 * and at the next we should *not* start from the beginning,
2325 * so we have to cache the result
2330 /* this works for now... */
2331 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2335 if (!logged_message
) {
2336 logged_message
= True
; /* Only print this once... */
2337 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2342 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2346 #ifdef HAVE_SYS_QUOTAS
2347 /****************************************************************************
2348 Reply to get user quota
2349 ****************************************************************************/
2351 static int call_nt_transact_get_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2352 char **ppsetup
, uint32 setup_count
,
2353 char **ppparams
, uint32 parameter_count
,
2354 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2356 NTSTATUS nt_status
= NT_STATUS_OK
;
2357 char *params
= *ppparams
;
2358 char *pdata
= *ppdata
;
2360 int data_len
=0,param_len
=0;
2363 files_struct
*fsp
= NULL
;
2367 BOOL start_enum
= True
;
2368 SMB_NTQUOTA_STRUCT qt
;
2369 SMB_NTQUOTA_LIST
*tmp_list
;
2370 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2371 extern struct current_user current_user
;
2376 if (current_user
.uid
!= 0) {
2377 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2378 lp_servicename(SNUM(conn
)),conn
->user
));
2379 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2383 * Ensure minimum number of parameters sent.
2386 if (parameter_count
< 4) {
2387 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2388 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2391 /* maybe we can check the quota_fnum */
2392 fsp
= file_fsp(params
,0);
2393 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2394 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2395 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2398 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2399 * is done by CHECK_NTQUOTA_HANDLE_OK()
2401 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
2403 level
= SVAL(params
,2);
2405 /* unknown 12 bytes leading in params */
2408 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2409 /* seems that we should continue with the enum here --metze */
2411 if (qt_handle
->quota_list
!=NULL
&&
2412 qt_handle
->tmp_list
==NULL
) {
2415 free_ntquota_list(&(qt_handle
->quota_list
));
2417 /* Realloc the size of parameters and data we will return */
2419 params
= nttrans_realloc(ppparams
, param_len
);
2420 if(params
== NULL
) {
2421 return ERROR_DOS(ERRDOS
,ERRnomem
);
2425 SIVAL(params
,0,data_len
);
2432 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2434 if (qt_handle
->quota_list
==NULL
&&
2435 qt_handle
->tmp_list
==NULL
) {
2439 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0)
2440 return ERROR_DOS(ERRSRV
,ERRerror
);
2442 /* Realloc the size of parameters and data we will return */
2444 params
= nttrans_realloc(ppparams
, param_len
);
2445 if(params
== NULL
) {
2446 return ERROR_DOS(ERRDOS
,ERRnomem
);
2449 /* we should not trust the value in max_data_count*/
2450 max_data_count
= MIN(max_data_count
,2048);
2452 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2454 return ERROR_DOS(ERRDOS
,ERRnomem
);
2459 /* set params Size of returned Quota Data 4 bytes*/
2460 /* but set it later when we know it */
2462 /* for each entry push the data */
2465 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2468 tmp_list
= qt_handle
->tmp_list
;
2470 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2471 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2473 sid_len
= sid_size(&tmp_list
->quotas
->sid
);
2474 entry_len
= 40 + sid_len
;
2476 /* nextoffset entry 4 bytes */
2477 SIVAL(entry
,0,entry_len
);
2479 /* then the len of the SID 4 bytes */
2480 SIVAL(entry
,4,sid_len
);
2482 /* unknown data 8 bytes SMB_BIG_UINT */
2483 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2485 /* the used disk space 8 bytes SMB_BIG_UINT */
2486 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2488 /* the soft quotas 8 bytes SMB_BIG_UINT */
2489 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2491 /* the hard quotas 8 bytes SMB_BIG_UINT */
2492 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2494 /* and now the SID */
2495 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2498 qt_handle
->tmp_list
= tmp_list
;
2500 /* overwrite the offset of the last entry */
2501 SIVAL(entry
-entry_len
,0,0);
2503 data_len
= 4+qt_len
;
2504 /* overwrite the params quota_data_len */
2505 SIVAL(params
,0,data_len
);
2509 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2511 /* unknown 4 bytes IVAL(pdata,0) */
2513 if (data_count
< 8) {
2514 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2515 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2518 sid_len
= IVAL(pdata
,4);
2519 /* Ensure this is less than 1mb. */
2520 if (sid_len
> (1024*1024)) {
2521 return ERROR_DOS(ERRDOS
,ERRnomem
);
2524 if (data_count
< 8+sid_len
) {
2525 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2526 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2529 data_len
= 4+40+sid_len
;
2531 if (max_data_count
< data_len
) {
2532 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2533 max_data_count
, data_len
));
2535 SIVAL(params
,0,data_len
);
2537 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2541 sid_parse(pdata
+8,sid_len
,&sid
);
2543 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2546 * we have to return zero's in all fields
2547 * instead of returning an error here
2552 /* Realloc the size of parameters and data we will return */
2554 params
= nttrans_realloc(ppparams
, param_len
);
2555 if(params
== NULL
) {
2556 return ERROR_DOS(ERRDOS
,ERRnomem
);
2559 pdata
= nttrans_realloc(ppdata
, data_len
);
2561 return ERROR_DOS(ERRDOS
,ERRnomem
);
2566 /* set params Size of returned Quota Data 4 bytes*/
2567 SIVAL(params
,0,data_len
);
2569 /* nextoffset entry 4 bytes */
2572 /* then the len of the SID 4 bytes */
2573 SIVAL(entry
,4,sid_len
);
2575 /* unknown data 8 bytes SMB_BIG_UINT */
2576 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2578 /* the used disk space 8 bytes SMB_BIG_UINT */
2579 SBIG_UINT(entry
,16,qt
.usedspace
);
2581 /* the soft quotas 8 bytes SMB_BIG_UINT */
2582 SBIG_UINT(entry
,24,qt
.softlim
);
2584 /* the hard quotas 8 bytes SMB_BIG_UINT */
2585 SBIG_UINT(entry
,32,qt
.hardlim
);
2587 /* and now the SID */
2588 sid_linearize(entry
+40, sid_len
, &sid
);
2593 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2594 return ERROR_DOS(ERRSRV
,ERRerror
);
2598 send_nt_replies(inbuf
, outbuf
, bufsize
, nt_status
, params
, param_len
, pdata
, data_len
);
2603 /****************************************************************************
2604 Reply to set user quota
2605 ****************************************************************************/
2607 static int call_nt_transact_set_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2608 char **ppsetup
, uint32 setup_count
,
2609 char **ppparams
, uint32 parameter_count
,
2610 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2612 char *params
= *ppparams
;
2613 char *pdata
= *ppdata
;
2614 int data_len
=0,param_len
=0;
2615 SMB_NTQUOTA_STRUCT qt
;
2618 files_struct
*fsp
= NULL
;
2623 if (current_user
.uid
!= 0) {
2624 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2625 lp_servicename(SNUM(conn
)),conn
->user
));
2626 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2630 * Ensure minimum number of parameters sent.
2633 if (parameter_count
< 2) {
2634 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2635 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2638 /* maybe we can check the quota_fnum */
2639 fsp
= file_fsp(params
,0);
2640 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2641 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2642 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2645 if (data_count
< 40) {
2646 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2647 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2650 /* offset to next quota record.
2651 * 4 bytes IVAL(pdata,0)
2656 sid_len
= IVAL(pdata
,4);
2658 if (data_count
< 40+sid_len
) {
2659 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2660 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2663 /* unknown 8 bytes in pdata
2664 * maybe its the change time in NTTIME
2667 /* the used space 8 bytes (SMB_BIG_UINT)*/
2668 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2669 #ifdef LARGE_SMB_OFF_T
2670 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2671 #else /* LARGE_SMB_OFF_T */
2672 if ((IVAL(pdata
,20) != 0)&&
2673 ((qt
.usedspace
!= 0xFFFFFFFF)||
2674 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2675 /* more than 32 bits? */
2676 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2678 #endif /* LARGE_SMB_OFF_T */
2680 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2681 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2682 #ifdef LARGE_SMB_OFF_T
2683 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2684 #else /* LARGE_SMB_OFF_T */
2685 if ((IVAL(pdata
,28) != 0)&&
2686 ((qt
.softlim
!= 0xFFFFFFFF)||
2687 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2688 /* more than 32 bits? */
2689 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2691 #endif /* LARGE_SMB_OFF_T */
2693 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2694 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2695 #ifdef LARGE_SMB_OFF_T
2696 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2697 #else /* LARGE_SMB_OFF_T */
2698 if ((IVAL(pdata
,36) != 0)&&
2699 ((qt
.hardlim
!= 0xFFFFFFFF)||
2700 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2701 /* more than 32 bits? */
2702 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2704 #endif /* LARGE_SMB_OFF_T */
2706 sid_parse(pdata
+40,sid_len
,&sid
);
2707 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid
)));
2709 /* 44 unknown bytes left... */
2711 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2712 return ERROR_DOS(ERRSRV
,ERRerror
);
2715 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, pdata
, data_len
);
2719 #endif /* HAVE_SYS_QUOTAS */
2721 /****************************************************************************
2722 Reply to a SMBNTtrans.
2723 ****************************************************************************/
2725 int reply_nttrans(connection_struct
*conn
,
2726 char *inbuf
,char *outbuf
,int length
,int bufsize
)
2729 uint32 max_data_count
= IVAL(inbuf
,smb_nt_MaxDataCount
);
2730 #if 0 /* Not used. */
2731 uint16 max_setup_count
= CVAL(inbuf
, smb_nt_MaxSetupCount
);
2732 uint32 max_parameter_count
= IVAL(inbuf
, smb_nt_MaxParameterCount
);
2733 #endif /* Not used. */
2734 uint32 total_parameter_count
= IVAL(inbuf
, smb_nt_TotalParameterCount
);
2735 uint32 total_data_count
= IVAL(inbuf
, smb_nt_TotalDataCount
);
2736 uint32 parameter_count
= IVAL(inbuf
,smb_nt_ParameterCount
);
2737 uint32 parameter_offset
= IVAL(inbuf
,smb_nt_ParameterOffset
);
2738 uint32 data_count
= IVAL(inbuf
,smb_nt_DataCount
);
2739 uint32 data_offset
= IVAL(inbuf
,smb_nt_DataOffset
);
2740 uint16 setup_count
= 2*CVAL(inbuf
,smb_nt_SetupCount
); /* setup count is in *words* */
2741 uint16 function_code
= SVAL( inbuf
, smb_nt_Function
);
2742 char *params
= NULL
, *data
= NULL
, *setup
= NULL
;
2743 uint32 num_params_sofar
, num_data_sofar
;
2744 START_PROFILE(SMBnttrans
);
2746 if(global_oplock_break
&&
2747 ((function_code
== NT_TRANSACT_CREATE
) ||
2748 (function_code
== NT_TRANSACT_RENAME
))) {
2750 * Queue this open message as we are the process of an oplock break.
2753 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2754 due to being in oplock break state.\n", (unsigned int)function_code
));
2756 push_oplock_pending_smb_message( inbuf
, length
);
2757 END_PROFILE(SMBnttrans
);
2761 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2762 END_PROFILE(SMBnttrans
);
2763 return ERROR_DOS(ERRSRV
,ERRaccess
);
2766 outsize
= set_message(outbuf
,0,0,True
);
2769 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2770 * Ensure this is so as a sanity check.
2773 if(CVAL(inbuf
, smb_wct
) != 19 + (setup_count
/2)) {
2774 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2775 CVAL(inbuf
, smb_wct
), 19 + (setup_count
/2)));
2779 /* Don't allow more than 128mb for each value. */
2780 if ((total_parameter_count
> (1024*1024*128)) || (total_data_count
> (1024*1024*128))) {
2781 END_PROFILE(SMBnttrans
);
2782 return ERROR_DOS(ERRDOS
,ERRnomem
);
2785 /* Allocate the space for the setup, the maximum needed parameters and data */
2787 if(setup_count
> 0) {
2788 setup
= (char *)SMB_MALLOC(setup_count
);
2790 if (total_parameter_count
> 0) {
2791 params
= (char *)SMB_MALLOC(total_parameter_count
);
2793 if (total_data_count
> 0) {
2794 data
= (char *)SMB_MALLOC(total_data_count
);
2797 if ((total_parameter_count
&& !params
) || (total_data_count
&& !data
) ||
2798 (setup_count
&& !setup
)) {
2802 DEBUG(0,("reply_nttrans : Out of memory\n"));
2803 END_PROFILE(SMBnttrans
);
2804 return ERROR_DOS(ERRDOS
,ERRnomem
);
2807 /* Copy the param and data bytes sent with this request into the params buffer */
2808 num_params_sofar
= parameter_count
;
2809 num_data_sofar
= data_count
;
2811 if (parameter_count
> total_parameter_count
|| data_count
> total_data_count
)
2815 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count
));
2816 if ((smb_nt_SetupStart
+ setup_count
< smb_nt_SetupStart
) ||
2817 (smb_nt_SetupStart
+ setup_count
< setup_count
)) {
2820 if (smb_nt_SetupStart
+ setup_count
> length
) {
2824 memcpy( setup
, &inbuf
[smb_nt_SetupStart
], setup_count
);
2825 dump_data(10, setup
, setup_count
);
2828 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count
));
2829 if ((parameter_offset
+ parameter_count
< parameter_offset
) ||
2830 (parameter_offset
+ parameter_count
< parameter_count
)) {
2833 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
> inbuf
+ length
)||
2834 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
))) {
2838 memcpy( params
, smb_base(inbuf
) + parameter_offset
, parameter_count
);
2839 dump_data(10, params
, parameter_count
);
2842 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count
));
2843 if ((data_offset
+ data_count
< data_offset
) || (data_offset
+ data_count
< data_count
)) {
2846 if ((smb_base(inbuf
) + data_offset
+ data_count
> inbuf
+ length
) ||
2847 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
))) {
2851 memcpy( data
, smb_base(inbuf
) + data_offset
, data_count
);
2852 dump_data(10, data
, data_count
);
2855 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2857 if(num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2858 /* We need to send an interim response then receive the rest
2859 of the parameter/data bytes */
2860 outsize
= set_message(outbuf
,0,0,True
);
2861 srv_signing_trans_stop();
2863 if (!send_smb(smbd_server_fd(),outbuf
)) {
2864 exit_server("reply_nttrans: send_smb failed.");
2867 while( num_data_sofar
< total_data_count
|| num_params_sofar
< total_parameter_count
) {
2869 uint32 parameter_displacement
;
2870 uint32 data_displacement
;
2872 ret
= receive_next_smb(inbuf
,bufsize
,SMB_SECONDARY_WAIT
);
2874 /* We need to re-calcuate the new length after we've read the secondary packet. */
2875 length
= smb_len(inbuf
) + 4;
2878 * The sequence number for the trans reply is always
2879 * based on the last secondary received.
2882 srv_signing_trans_start(SVAL(inbuf
,smb_mid
));
2884 if((ret
&& (CVAL(inbuf
, smb_com
) != SMBnttranss
)) || !ret
) {
2885 outsize
= set_message(outbuf
,0,0,True
);
2887 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2889 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2890 (smb_read_error
== READ_ERROR
) ? "error" : "timeout" ));
2895 /* Revise total_params and total_data in case they have changed downwards */
2896 if (IVAL(inbuf
, smb_nts_TotalParameterCount
) < total_parameter_count
) {
2897 total_parameter_count
= IVAL(inbuf
, smb_nts_TotalParameterCount
);
2899 if (IVAL(inbuf
, smb_nts_TotalDataCount
) < total_data_count
) {
2900 total_data_count
= IVAL(inbuf
, smb_nts_TotalDataCount
);
2903 parameter_count
= IVAL(inbuf
,smb_nts_ParameterCount
);
2904 parameter_offset
= IVAL(inbuf
, smb_nts_ParameterOffset
);
2905 parameter_displacement
= IVAL(inbuf
, smb_nts_ParameterDisplacement
);
2906 num_params_sofar
+= parameter_count
;
2908 data_count
= IVAL(inbuf
, smb_nts_DataCount
);
2909 data_displacement
= IVAL(inbuf
, smb_nts_DataDisplacement
);
2910 data_offset
= IVAL(inbuf
, smb_nts_DataOffset
);
2911 num_data_sofar
+= data_count
;
2913 if (num_params_sofar
> total_parameter_count
|| num_data_sofar
> total_data_count
) {
2914 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2918 if (parameter_count
) {
2919 if (parameter_displacement
+ parameter_count
> total_parameter_count
) {
2922 if ((parameter_displacement
+ parameter_count
< parameter_displacement
) ||
2923 (parameter_displacement
+ parameter_count
< parameter_count
)) {
2926 if (parameter_displacement
> total_parameter_count
) {
2929 if ((smb_base(inbuf
) + parameter_offset
+ parameter_count
> inbuf
+ length
) ||
2930 (smb_base(inbuf
) + parameter_offset
+ parameter_count
< smb_base(inbuf
))) {
2933 if (parameter_displacement
+ params
< params
) {
2937 memcpy( ¶ms
[parameter_displacement
], smb_base(inbuf
) + parameter_offset
, parameter_count
);
2941 if (data_displacement
+ data_count
> total_data_count
) {
2944 if ((data_displacement
+ data_count
< data_displacement
) ||
2945 (data_displacement
+ data_count
< data_count
)) {
2948 if (data_displacement
> total_data_count
) {
2951 if ((smb_base(inbuf
) + data_offset
+ data_count
> inbuf
+ length
) ||
2952 (smb_base(inbuf
) + data_offset
+ data_count
< smb_base(inbuf
))) {
2955 if (data_displacement
+ data
< data
) {
2959 memcpy( &data
[data_displacement
], smb_base(inbuf
)+ data_offset
, data_count
);
2964 if (Protocol
>= PROTOCOL_NT1
) {
2965 SSVAL(outbuf
,smb_flg2
,SVAL(outbuf
,smb_flg2
) | FLAGS2_IS_LONG_NAME
);
2968 /* Now we must call the relevant NT_TRANS function */
2969 switch(function_code
) {
2970 case NT_TRANSACT_CREATE
:
2971 START_PROFILE_NESTED(NT_transact_create
);
2972 outsize
= call_nt_transact_create(conn
, inbuf
, outbuf
,
2974 &setup
, setup_count
,
2975 ¶ms
, total_parameter_count
,
2976 &data
, total_data_count
, max_data_count
);
2977 END_PROFILE_NESTED(NT_transact_create
);
2979 case NT_TRANSACT_IOCTL
:
2980 START_PROFILE_NESTED(NT_transact_ioctl
);
2981 outsize
= call_nt_transact_ioctl(conn
, inbuf
, outbuf
,
2983 &setup
, setup_count
,
2984 ¶ms
, total_parameter_count
,
2985 &data
, total_data_count
, max_data_count
);
2986 END_PROFILE_NESTED(NT_transact_ioctl
);
2988 case NT_TRANSACT_SET_SECURITY_DESC
:
2989 START_PROFILE_NESTED(NT_transact_set_security_desc
);
2990 outsize
= call_nt_transact_set_security_desc(conn
, inbuf
, outbuf
,
2992 &setup
, setup_count
,
2993 ¶ms
, total_parameter_count
,
2994 &data
, total_data_count
, max_data_count
);
2995 END_PROFILE_NESTED(NT_transact_set_security_desc
);
2997 case NT_TRANSACT_NOTIFY_CHANGE
:
2998 START_PROFILE_NESTED(NT_transact_notify_change
);
2999 outsize
= call_nt_transact_notify_change(conn
, inbuf
, outbuf
,
3001 &setup
, setup_count
,
3002 ¶ms
, total_parameter_count
,
3003 &data
, total_data_count
, max_data_count
);
3004 END_PROFILE_NESTED(NT_transact_notify_change
);
3006 case NT_TRANSACT_RENAME
:
3007 START_PROFILE_NESTED(NT_transact_rename
);
3008 outsize
= call_nt_transact_rename(conn
, inbuf
, outbuf
,
3010 &setup
, setup_count
,
3011 ¶ms
, total_parameter_count
,
3012 &data
, total_data_count
, max_data_count
);
3013 END_PROFILE_NESTED(NT_transact_rename
);
3016 case NT_TRANSACT_QUERY_SECURITY_DESC
:
3017 START_PROFILE_NESTED(NT_transact_query_security_desc
);
3018 outsize
= call_nt_transact_query_security_desc(conn
, inbuf
, outbuf
,
3020 &setup
, setup_count
,
3021 ¶ms
, total_parameter_count
,
3022 &data
, total_data_count
, max_data_count
);
3023 END_PROFILE_NESTED(NT_transact_query_security_desc
);
3025 #ifdef HAVE_SYS_QUOTAS
3026 case NT_TRANSACT_GET_USER_QUOTA
:
3027 START_PROFILE_NESTED(NT_transact_get_user_quota
);
3028 outsize
= call_nt_transact_get_user_quota(conn
, inbuf
, outbuf
,
3030 &setup
, setup_count
,
3031 ¶ms
, total_parameter_count
,
3032 &data
, total_data_count
, max_data_count
);
3033 END_PROFILE_NESTED(NT_transact_get_user_quota
);
3035 case NT_TRANSACT_SET_USER_QUOTA
:
3036 START_PROFILE_NESTED(NT_transact_set_user_quota
);
3037 outsize
= call_nt_transact_set_user_quota(conn
, inbuf
, outbuf
,
3039 &setup
, setup_count
,
3040 ¶ms
, total_parameter_count
,
3041 &data
, total_data_count
, max_data_count
);
3042 END_PROFILE_NESTED(NT_transact_set_user_quota
);
3044 #endif /* HAVE_SYS_QUOTAS */
3046 /* Error in request */
3047 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code
));
3051 END_PROFILE(SMBnttrans
);
3052 srv_signing_trans_stop();
3053 return ERROR_DOS(ERRSRV
,ERRerror
);
3056 /* As we do not know how many data packets will need to be
3057 returned here the various call_nt_transact_xxxx calls
3058 must send their own. Thus a call_nt_transact_xxxx routine only
3059 returns a value other than -1 when it wants to send
3063 srv_signing_trans_stop();
3068 END_PROFILE(SMBnttrans
);
3069 return outsize
; /* If a correct response was needed the call_nt_transact_xxxx
3070 calls have already sent it. If outsize != -1 then it is
3071 returning an error packet. */
3075 srv_signing_trans_stop();
3079 END_PROFILE(SMBnttrans
);
3080 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);