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 /* Map generic permissions to file object specific permissions */
51 struct generic_mapping file_generic_mapping = {
58 static char *nttrans_realloc(char **ptr, size_t size)
62 smb_panic("nttrans_realloc() called with NULL ptr\n");
64 tptr = SMB_REALLOC(*ptr, size);
69 memset(tptr,'\0',size);
76 /****************************************************************************
77 Send the required number of replies back.
78 We assume all fields other than the data fields are
79 set correctly for the type of call.
80 HACK ! Always assumes smb_setup field is zero.
81 ****************************************************************************/
83 static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, NTSTATUS nt_error, char *params,
84 int paramsize, char *pdata, int datasize)
86 int data_to_send = datasize;
87 int params_to_send = paramsize;
91 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
92 int alignment_offset = 3;
93 int data_alignment_offset = 0;
96 * Initially set the wcnt area to be 18 - this is true for all
100 set_message(outbuf,18,0,True);
102 if (NT_STATUS_V(nt_error))
106 * If there genuinely are no parameters or data to send just send
110 if(params_to_send == 0 && data_to_send == 0) {
111 if (!send_smb(smbd_server_fd(),outbuf))
112 exit_server("send_nt_replies: send_smb failed.");
117 * When sending params and data ensure that both are nicely aligned.
118 * Only do this alignment when there is also data to send - else
119 * can cause NT redirector problems.
122 if (((params_to_send % 4) != 0) && (data_to_send != 0))
123 data_alignment_offset = 4 - (params_to_send % 4);
126 * Space is bufsize minus Netbios over TCP header minus SMB header.
127 * The alignment_offset is to align the param bytes on a four byte
128 * boundary (2 bytes for data len, one byte pad).
129 * NT needs this to work correctly.
132 useable_space = bufsize - ((smb_buf(outbuf)+
133 alignment_offset+data_alignment_offset) -
137 * useable_space can never be more than max_send minus the
141 useable_space = MIN(useable_space,
142 max_send - (alignment_offset+data_alignment_offset));
145 while (params_to_send || data_to_send) {
148 * Calculate whether we will totally or partially fill this packet.
151 total_sent_thistime = params_to_send + data_to_send +
152 alignment_offset + data_alignment_offset;
155 * We can never send more than useable_space.
158 total_sent_thistime = MIN(total_sent_thistime, useable_space);
160 set_message(outbuf, 18, total_sent_thistime, True);
163 * Set total params and data to be sent.
166 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
167 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
170 * Calculate how many parameters and data we can fit into
171 * this packet. Parameters get precedence.
174 params_sent_thistime = MIN(params_to_send,useable_space);
175 data_sent_thistime = useable_space - params_sent_thistime;
176 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
178 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
180 if(params_sent_thistime == 0) {
181 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
182 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
185 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
186 * parameter bytes, however the first 4 bytes of outbuf are
187 * the Netbios over TCP header. Thus use smb_base() to subtract
188 * them from the calculation.
191 SIVAL(outbuf,smb_ntr_ParameterOffset,
192 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
194 * Absolute displacement of param bytes sent in this packet.
197 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
201 * Deal with the data portion.
204 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
206 if(data_sent_thistime == 0) {
207 SIVAL(outbuf,smb_ntr_DataOffset,0);
208 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
211 * The offset of the data bytes is the offset of the
212 * parameter bytes plus the number of parameters being sent this time.
215 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
216 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
217 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
221 * Copy the param bytes into the packet.
224 if(params_sent_thistime)
225 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
228 * Copy in the data bytes
231 if(data_sent_thistime)
232 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
233 data_alignment_offset,pd,data_sent_thistime);
235 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
236 params_sent_thistime, data_sent_thistime, useable_space));
237 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
238 params_to_send, data_to_send, paramsize, datasize));
240 /* Send the packet */
241 if (!send_smb(smbd_server_fd(),outbuf))
242 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))
293 saved_case_sensitive = conn->case_sensitive;
294 saved_case_preserve = conn->case_preserve;
295 saved_short_case_preserve = conn->short_case_preserve;
298 conn->case_sensitive = True;
299 conn->case_preserve = True;
300 conn->short_case_preserve = True;
303 /****************************************************************************
304 Restore case semantics.
305 ****************************************************************************/
307 static void restore_case_semantics(connection_struct *conn, uint32 file_attributes)
309 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS))
312 conn->case_sensitive = saved_case_sensitive;
313 conn->case_preserve = saved_case_preserve;
314 conn->short_case_preserve = saved_short_case_preserve;
317 /****************************************************************************
318 Utility function to map create disposition.
319 ****************************************************************************/
321 static int map_create_disposition( uint32 create_disposition)
325 switch( create_disposition ) {
327 /* create if not exist, fail if exist */
328 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_FAIL);
331 case FILE_OVERWRITE_IF:
332 /* create if not exist, trunc if exist */
333 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
336 /* fail if not exist, open if exists */
337 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN);
340 /* create if not exist, open if exists */
341 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_OPEN);
344 /* fail if not exist, truncate if exists */
345 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
348 DEBUG(0,("map_create_disposition: Incorrect value for create_disposition = %d\n",
349 create_disposition ));
353 DEBUG(10,("map_create_disposition: Mapped create_disposition 0x%lx to 0x%x\n",
354 (unsigned long)create_disposition, ret ));
359 /****************************************************************************
360 Utility function to map share modes.
361 ****************************************************************************/
363 static int map_share_mode( char *fname, uint32 create_options,
364 uint32 *desired_access, uint32 share_access, uint32 file_attributes)
366 int smb_open_mode = -1;
367 uint32 original_desired_access = *desired_access;
369 /* This is a nasty hack - must fix... JRA. */
370 if (*desired_access == MAXIMUM_ALLOWED_ACCESS) {
371 *desired_access = FILE_GENERIC_ALL;
375 * Convert GENERIC bits to specific bits.
378 se_map_generic(desired_access, &file_generic_mapping);
380 switch( *desired_access & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA) ) {
382 smb_open_mode = DOS_OPEN_RDONLY;
384 case FILE_WRITE_DATA:
385 case FILE_APPEND_DATA:
386 case FILE_WRITE_DATA|FILE_APPEND_DATA:
387 smb_open_mode = DOS_OPEN_WRONLY;
389 case FILE_READ_DATA|FILE_WRITE_DATA:
390 case FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA:
391 case FILE_READ_DATA|FILE_APPEND_DATA:
392 smb_open_mode = DOS_OPEN_RDWR;
397 * NB. For DELETE_ACCESS we should really check the
398 * directory permissions, as that is what controls
399 * delete, and for WRITE_DAC_ACCESS we should really
400 * check the ownership, as that is what controls the
401 * chmod. Note that this is *NOT* a security hole (this
402 * note is for you, Andrew) as we are not *allowing*
403 * the access at this point, the actual unlink or
404 * chown or chmod call would do this. We are just helping
405 * clients out by telling them if they have a hope
406 * of any of this succeeding. POSIX acls may still
407 * deny the real call. JRA.
410 if (smb_open_mode == -1) {
412 if(*desired_access & (DELETE_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS|SYNCHRONIZE_ACCESS|
413 FILE_EXECUTE|FILE_READ_ATTRIBUTES|
414 FILE_READ_EA|FILE_WRITE_EA|SYSTEM_SECURITY_ACCESS|
415 FILE_WRITE_ATTRIBUTES|READ_CONTROL_ACCESS)) {
416 smb_open_mode = DOS_OPEN_RDONLY;
417 } else if(*desired_access == 0) {
420 * JRA - NT seems to sometimes send desired_access as zero. play it safe
421 * and map to a stat open.
424 smb_open_mode = DOS_OPEN_RDONLY;
427 DEBUG(0,("map_share_mode: Incorrect value 0x%lx for desired_access to file %s\n",
428 (unsigned long)*desired_access, fname));
434 * Set the special bit that means allow share delete.
435 * This is held outside the normal share mode bits at 1<<15.
439 if(share_access & FILE_SHARE_DELETE) {
440 smb_open_mode |= ALLOW_SHARE_DELETE;
441 DEBUG(10,("map_share_mode: FILE_SHARE_DELETE requested. open_mode = 0x%x\n", smb_open_mode));
444 if(*desired_access & DELETE_ACCESS) {
445 DEBUG(10,("map_share_mode: DELETE_ACCESS requested. open_mode = 0x%x\n", smb_open_mode));
449 * We need to store the intent to open for Delete. This
450 * is what determines if a delete on close flag can be set.
451 * This is the wrong way (and place) to store this, but for 2.2 this
452 * is the only practical way. JRA.
455 if (create_options & FILE_DELETE_ON_CLOSE) {
457 * W2K3 bug compatibility mode... To set delete on close
458 * the redirector must have *specifically* set DELETE_ACCESS
459 * in the desired_access field. Just asking for GENERIC_ALL won't do. JRA.
462 if (!(original_desired_access & DELETE_ACCESS)) {
463 DEBUG(5,("map_share_mode: FILE_DELETE_ON_CLOSE requested without \
464 DELETE_ACCESS for file %s. (desired_access = 0x%lx)\n",
465 fname, (unsigned long)*desired_access));
468 /* Implicit delete access is *NOT* requested... */
469 smb_open_mode |= DELETE_ON_CLOSE_FLAG;
470 DEBUG(10,("map_share_mode: FILE_DELETE_ON_CLOSE requested. open_mode = 0x%x\n", smb_open_mode));
473 /* Add in the requested share mode. */
474 switch( share_access & (FILE_SHARE_READ|FILE_SHARE_WRITE)) {
475 case FILE_SHARE_READ:
476 smb_open_mode |= SET_DENY_MODE(DENY_WRITE);
478 case FILE_SHARE_WRITE:
479 smb_open_mode |= SET_DENY_MODE(DENY_READ);
481 case (FILE_SHARE_READ|FILE_SHARE_WRITE):
482 smb_open_mode |= SET_DENY_MODE(DENY_NONE);
484 case FILE_SHARE_NONE:
485 smb_open_mode |= SET_DENY_MODE(DENY_ALL);
490 * Handle an O_SYNC request.
493 if(file_attributes & FILE_FLAG_WRITE_THROUGH)
494 smb_open_mode |= FILE_SYNC_OPENMODE;
496 DEBUG(10,("map_share_mode: Mapped desired access 0x%lx, share access 0x%lx, file attributes 0x%lx \
497 to open_mode 0x%x\n", (unsigned long)*desired_access, (unsigned long)share_access,
498 (unsigned long)file_attributes, smb_open_mode ));
500 return smb_open_mode;
503 /****************************************************************************
504 Reply to an NT create and X call on a pipe.
505 ****************************************************************************/
507 static int nt_open_pipe(char *fname, connection_struct *conn,
508 char *inbuf, char *outbuf, int *ppnum)
510 smb_np_struct *p = NULL;
512 uint16 vuid = SVAL(inbuf, smb_uid);
515 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
517 /* See if it is one we want to handle. */
519 if (lp_disable_spoolss() && strequal(fname, "\\spoolss"))
520 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
522 for( i = 0; known_nt_pipes[i]; i++ )
523 if( strequal(fname,known_nt_pipes[i]))
526 if ( known_nt_pipes[i] == NULL )
527 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
529 /* Strip \\ off the name. */
532 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
534 p = open_rpc_pipe_p(fname, conn, vuid);
536 return(ERROR_DOS(ERRSRV,ERRnofids));
543 /****************************************************************************
544 Reply to an NT create and X call for pipes.
545 ****************************************************************************/
547 static int do_ntcreate_pipe_open(connection_struct *conn,
548 char *inbuf,char *outbuf,int length,int bufsize)
555 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
557 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
561 * Deal with pipe return.
564 set_message(outbuf,34,0,True);
566 p = outbuf + smb_vwv2;
570 SIVAL(p,0,FILE_WAS_OPENED);
573 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
576 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
578 SSVAL(p,2, 0x5FF); /* ? */
580 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
582 return chain_reply(inbuf,outbuf,length,bufsize);
585 /****************************************************************************
586 Reply to an NT create and X call.
587 ****************************************************************************/
589 int reply_ntcreate_and_X(connection_struct *conn,
590 char *inbuf,char *outbuf,int length,int bufsize)
594 enum FAKE_FILE_TYPE fake_file_type = FAKE_FILE_TYPE_NONE;
595 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
596 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
597 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
598 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
599 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
600 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
601 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
604 /* Breakout the oplock request bits so we can set the
605 reply bits separately. */
606 int oplock_request = 0;
608 SMB_OFF_T file_len = 0;
609 SMB_STRUCT_STAT sbuf;
611 BOOL bad_path = False;
612 files_struct *fsp=NULL;
615 BOOL extended_oplock_granted = False;
618 START_PROFILE(SMBntcreateX);
620 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
621 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
622 create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attributes,
623 share_access, create_disposition,
624 create_options, root_dir_fid ));
626 /* If it's an IPC, use the pipe handler. */
629 if (lp_nt_pipe_support()) {
630 END_PROFILE(SMBntcreateX);
631 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
633 END_PROFILE(SMBntcreateX);
634 return(ERROR_DOS(ERRDOS,ERRnoaccess));
638 if (create_options & FILE_OPEN_BY_FILE_ID) {
639 END_PROFILE(SMBntcreateX);
640 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
644 * We need to construct the open_and_X ofun value from the
645 * NT values, as that's what our code is structured to accept.
648 if((smb_ofun = map_create_disposition( create_disposition )) == -1) {
649 END_PROFILE(SMBntcreateX);
650 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
657 if(root_dir_fid != 0) {
659 * This filename is relative to a directory fid.
662 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
666 END_PROFILE(SMBntcreateX);
667 return(ERROR_DOS(ERRDOS,ERRbadfid));
670 if(!dir_fsp->is_directory) {
672 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status,False);
673 if (!NT_STATUS_IS_OK(status)) {
674 END_PROFILE(SMBntcreateX);
675 return ERROR_NT(status);
679 * Check to see if this is a mac fork of some kind.
682 if( is_ntfs_stream_name(fname)) {
683 END_PROFILE(SMBntcreateX);
684 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
688 we need to handle the case when we get a
689 relative open relative to a file and the
690 pathname is blank - this is a reopen!
691 (hint from demyn plantenberg)
694 END_PROFILE(SMBntcreateX);
695 return(ERROR_DOS(ERRDOS,ERRbadfid));
699 * Copy in the base directory name.
702 pstrcpy( fname, dir_fsp->fsp_name );
703 dir_name_len = strlen(fname);
706 * Ensure it ends in a '\'.
709 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
714 srvstr_get_path(inbuf, rel_fname, smb_buf(inbuf), sizeof(rel_fname), 0, STR_TERMINATE, &status,False);
715 if (!NT_STATUS_IS_OK(status)) {
716 END_PROFILE(SMBntcreateX);
717 return ERROR_NT(status);
719 pstrcat(fname, rel_fname);
721 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status,False);
722 if (!NT_STATUS_IS_OK(status)) {
723 END_PROFILE(SMBntcreateX);
724 return ERROR_NT(status);
728 * Check to see if this is a mac fork of some kind.
731 if( is_ntfs_stream_name(fname)) {
733 #ifdef HAVE_SYS_QUOTAS
734 if ((fake_file_type=is_fake_file(fname))!=FAKE_FILE_TYPE_NONE) {
736 * here we go! support for changing the disk quotas --metze
738 * we need to fake up to open this MAGIC QUOTA file
739 * and return a valid FID
741 * w2k close this file directly after openening
742 * xp also tries a QUERY_FILE_INFO on the file and then close it
746 END_PROFILE(SMBntcreateX);
747 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
748 #ifdef HAVE_SYS_QUOTAS
755 * Now contruct the smb_open_mode value from the filename,
756 * desired access and the share access.
758 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
760 if((smb_open_mode = map_share_mode(fname, create_options, &desired_access,
762 file_attributes)) == -1) {
763 END_PROFILE(SMBntcreateX);
764 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
767 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
768 if (oplock_request) {
769 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
773 * Ordinary file or directory.
777 * Check if POSIX semantics are wanted.
780 set_posix_case_semantics(conn, file_attributes);
782 unix_convert(fname,conn,0,&bad_path,&sbuf);
784 /* FAKE_FILE is a special case */
785 if (fake_file_type == FAKE_FILE_TYPE_NONE) {
788 restore_case_semantics(conn, file_attributes);
789 END_PROFILE(SMBntcreateX);
790 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
792 /* All file access must go through check_name() */
793 if (!check_name(fname,conn)) {
794 restore_case_semantics(conn, file_attributes);
795 END_PROFILE(SMBntcreateX);
796 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
801 /* This is the correct thing to do (check every time) but can_delete is
802 expensive (it may have to read the parent directory permissions). So
803 for now we're not doing it unless we have a strong hint the client
804 is really going to delete this file. */
805 if (desired_access & DELETE_ACCESS) {
807 /* Setting FILE_SHARE_DELETE is the hint. */
808 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE) && (desired_access & DELETE_ACCESS)) {
810 status = can_delete(conn, fname, file_attributes, bad_path, True);
811 /* We're only going to fail here if it's access denied, as that's the
812 only error we care about for "can we delete this ?" questions. */
813 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
814 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
815 restore_case_semantics(conn, file_attributes);
816 END_PROFILE(SMBntcreateX);
817 return ERROR_NT(status);
822 * If it's a request for a directory open, deal with it separately.
825 if(create_options & FILE_DIRECTORY_FILE) {
828 /* Can't open a temp directory. IFS kit test. */
829 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
830 END_PROFILE(SMBntcreateX);
831 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
834 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
836 restore_case_semantics(conn, file_attributes);
839 END_PROFILE(SMBntcreateX);
840 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
844 * Ordinary file case.
847 /* NB. We have a potential bug here. If we
848 * cause an oplock break to ourselves, then we
849 * could end up processing filename related
850 * SMB requests whilst we await the oplock
851 * break response. As we may have changed the
852 * filename case semantics to be POSIX-like,
853 * this could mean a filename request could
854 * fail when it should succeed. This is a rare
855 * condition, but eventually we must arrange
856 * to restore the correct case semantics
857 * before issuing an oplock break request to
858 * our client. JRA. */
860 if (fake_file_type==FAKE_FILE_TYPE_NONE) {
861 fsp = open_file_shared1(conn,fname,&sbuf,
864 smb_ofun,file_attributes,oplock_request,
867 /* to open a fake_file --metze */
868 fsp = open_fake_file_shared1(fake_file_type,conn,fname,&sbuf,
871 smb_ofun,file_attributes, oplock_request,
876 /* We cheat here. There are two cases we
877 * care about. One is a directory rename,
878 * where the NT client will attempt to
879 * open the source directory for
880 * DELETE access. Note that when the
881 * NT client does this it does *not*
882 * set the directory bit in the
883 * request packet. This is translated
884 * into a read/write open
885 * request. POSIX states that any open
886 * for write request on a directory
887 * will generate an EISDIR error, so
888 * we can catch this here and open a
889 * pseudo handle that is flagged as a
890 * directory. The second is an open
891 * for a permissions read only, which
892 * we handle in the open_file_stat case. JRA.
895 if(errno == EISDIR) {
898 * Fail the open if it was explicitly a non-directory file.
901 if (create_options & FILE_NON_DIRECTORY_FILE) {
902 restore_case_semantics(conn, file_attributes);
903 END_PROFILE(SMBntcreateX);
904 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
908 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
911 restore_case_semantics(conn, file_attributes);
912 END_PROFILE(SMBntcreateX);
913 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
917 restore_case_semantics(conn, file_attributes);
918 END_PROFILE(SMBntcreateX);
919 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
920 /* We have re-scheduled this call. */
923 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
928 restore_case_semantics(conn, file_attributes);
930 file_len = sbuf.st_size;
931 fmode = dos_mode(conn,fname,&sbuf);
933 fmode = FILE_ATTRIBUTE_NORMAL;
935 if (!fsp->is_directory && (fmode & aDIR)) {
936 close_file(fsp,False);
937 END_PROFILE(SMBntcreateX);
938 return ERROR_DOS(ERRDOS,ERRnoaccess);
941 /* Save the requested allocation size. */
942 if ((smb_action == FILE_WAS_CREATED) || (smb_action == FILE_WAS_OVERWRITTEN)) {
943 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
944 #ifdef LARGE_SMB_OFF_T
945 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
947 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
948 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
949 if (fsp->is_directory) {
950 close_file(fsp,False);
951 END_PROFILE(SMBntcreateX);
952 /* Can't set allocation size on a directory. */
953 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
955 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
956 close_file(fsp,False);
957 END_PROFILE(SMBntcreateX);
958 return ERROR_NT(NT_STATUS_DISK_FULL);
961 fsp->initial_allocation_size = smb_roundup(fsp->conn,(SMB_BIG_UINT)file_len);
966 * If the caller set the extended oplock request bit
967 * and we granted one (by whatever means) - set the
968 * correct bit for extended oplock reply.
971 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
972 extended_oplock_granted = True;
975 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
976 extended_oplock_granted = True;
980 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
981 set_message(outbuf,42,0,True);
983 set_message(outbuf,34,0,True);
986 p = outbuf + smb_vwv2;
989 * Currently as we don't support level II oplocks we just report
990 * exclusive & batch here.
993 if (extended_oplock_granted) {
994 if (flags & REQUEST_BATCH_OPLOCK) {
995 SCVAL(p,0, BATCH_OPLOCK_RETURN);
997 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
999 } else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
1000 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1002 SCVAL(p,0,NO_OPLOCK_RETURN);
1006 SSVAL(p,0,fsp->fnum);
1008 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
1009 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1011 SIVAL(p,0,smb_action);
1015 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1017 if (lp_dos_filetime_resolution(SNUM(conn))) {
1019 sbuf.st_atime &= ~1;
1020 sbuf.st_mtime &= ~1;
1021 sbuf.st_mtime &= ~1;
1024 put_long_date(p,c_time);
1026 put_long_date(p,sbuf.st_atime); /* access time */
1028 put_long_date(p,sbuf.st_mtime); /* write time */
1030 put_long_date(p,sbuf.st_mtime); /* change time */
1032 SIVAL(p,0,fmode); /* File Attributes. */
1034 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1036 SOFF_T(p,0,file_len);
1038 if (flags & EXTENDED_RESPONSE_REQUIRED)
1041 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1043 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
1045 result = chain_reply(inbuf,outbuf,length,bufsize);
1046 END_PROFILE(SMBntcreateX);
1050 /****************************************************************************
1051 Reply to a NT_TRANSACT_CREATE call to open a pipe.
1052 ****************************************************************************/
1054 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1055 char **ppsetup, uint32 setup_count,
1056 char **ppparams, uint32 parameter_count,
1057 char **ppdata, uint32 data_count)
1060 char *params = *ppparams;
1067 * Ensure minimum number of parameters sent.
1070 if(parameter_count < 54) {
1071 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1072 return ERROR_DOS(ERRDOS,ERRnoaccess);
1075 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status, False);
1076 if (!NT_STATUS_IS_OK(status)) {
1077 return ERROR_NT(status);
1080 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
1083 /* Realloc the size of parameters and data we will return */
1084 params = nttrans_realloc(ppparams, 69);
1086 return ERROR_DOS(ERRDOS,ERRnomem);
1089 SCVAL(p,0,NO_OPLOCK_RETURN);
1094 SIVAL(p,0,FILE_WAS_OPENED);
1098 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
1101 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
1103 SSVAL(p,2, 0x5FF); /* ? */
1105 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
1107 /* Send the required number of replies */
1108 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1113 /****************************************************************************
1114 Internal fn to set security descriptors.
1115 ****************************************************************************/
1117 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
1120 SEC_DESC *psd = NULL;
1121 TALLOC_CTX *mem_ctx;
1124 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
1125 return NT_STATUS_OK;
1129 * Init the parse struct we will unmarshall from.
1132 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
1133 DEBUG(0,("set_sd: talloc_init failed.\n"));
1134 return NT_STATUS_NO_MEMORY;
1137 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1140 * Setup the prs_struct to point at the memory we just
1144 prs_give_memory( &pd, data, sd_len, False);
1147 * Finally, unmarshall from the data buffer.
1150 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1151 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1153 * Return access denied for want of a better error message..
1155 talloc_destroy(mem_ctx);
1156 return NT_STATUS_NO_MEMORY;
1159 if (psd->off_owner_sid==0)
1160 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1161 if (psd->off_grp_sid==0)
1162 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1163 if (psd->off_sacl==0)
1164 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1165 if (psd->off_dacl==0)
1166 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1168 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fd, security_info_sent, psd);
1171 talloc_destroy(mem_ctx);
1172 return NT_STATUS_ACCESS_DENIED;
1175 talloc_destroy(mem_ctx);
1177 return NT_STATUS_OK;
1180 /****************************************************************************
1181 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1182 ****************************************************************************/
1184 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
1186 struct ea_list *ea_list_head = NULL;
1189 if (data_size < 4) {
1193 while (offset + 4 <= data_size) {
1194 size_t next_offset = IVAL(pdata,offset);
1195 struct ea_list *tmp;
1196 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
1198 DLIST_ADD_END(ea_list_head, eal, tmp);
1199 if (next_offset == 0) {
1202 offset += next_offset;
1205 return ea_list_head;
1208 /****************************************************************************
1209 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1210 ****************************************************************************/
1212 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1213 char **ppsetup, uint32 setup_count,
1214 char **ppparams, uint32 parameter_count,
1215 char **ppdata, uint32 data_count, uint32 max_data_count)
1218 char *params = *ppparams;
1219 char *data = *ppdata;
1220 /* Breakout the oplock request bits so we can set the reply bits separately. */
1221 int oplock_request = 0;
1222 int fmode=0,rmode=0;
1223 SMB_OFF_T file_len = 0;
1224 SMB_STRUCT_STAT sbuf;
1226 BOOL bad_path = False;
1227 files_struct *fsp = NULL;
1229 BOOL extended_oplock_granted = False;
1231 uint32 desired_access;
1232 uint32 file_attributes;
1233 uint32 share_access;
1234 uint32 create_disposition;
1235 uint32 create_options;
1238 uint16 root_dir_fid;
1242 struct ea_list *ea_list = NULL;
1243 TALLOC_CTX *ctx = NULL;
1247 DEBUG(5,("call_nt_transact_create\n"));
1250 * If it's an IPC, use the pipe handler.
1254 if (lp_nt_pipe_support())
1255 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1257 ppsetup, setup_count,
1258 ppparams, parameter_count,
1259 ppdata, data_count);
1261 return ERROR_DOS(ERRDOS,ERRnoaccess);
1265 * Ensure minimum number of parameters sent.
1268 if(parameter_count < 54) {
1269 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1270 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1273 flags = IVAL(params,0);
1274 desired_access = IVAL(params,8);
1275 file_attributes = IVAL(params,20);
1276 share_access = IVAL(params,24);
1277 create_disposition = IVAL(params,28);
1278 create_options = IVAL(params,32);
1279 sd_len = IVAL(params,36);
1280 ea_len = IVAL(params,40);
1281 root_dir_fid = (uint16)IVAL(params,4);
1283 /* Ensure the data_len is correct for the sd and ea values given. */
1284 if ((ea_len + sd_len > data_count) ||
1285 (ea_len > data_count) || (sd_len > data_count) ||
1286 (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
1287 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1288 (unsigned int)ea_len, (unsigned int)sd_len, (unsigned int)data_count ));
1289 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1293 if (!lp_ea_support(SNUM(conn))) {
1294 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1295 (unsigned int)ea_len ));
1296 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
1300 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1301 (unsigned int)ea_len ));
1302 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1306 if (create_options & FILE_OPEN_BY_FILE_ID) {
1307 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1311 * We need to construct the open_and_X ofun value from the
1312 * NT values, as that's what our code is structured to accept.
1315 if((smb_ofun = map_create_disposition( create_disposition )) == -1) {
1316 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1320 * Get the file name.
1323 if(root_dir_fid != 0) {
1325 * This filename is relative to a directory fid.
1327 files_struct *dir_fsp = file_fsp(params,4);
1328 size_t dir_name_len;
1331 return ERROR_DOS(ERRDOS,ERRbadfid);
1333 if(!dir_fsp->is_directory) {
1334 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status, False);
1335 if (!NT_STATUS_IS_OK(status)) {
1336 return ERROR_NT(status);
1340 * Check to see if this is a mac fork of some kind.
1343 if( is_ntfs_stream_name(fname)) {
1344 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1347 return ERROR_DOS(ERRDOS,ERRbadfid);
1351 * Copy in the base directory name.
1354 pstrcpy( fname, dir_fsp->fsp_name );
1355 dir_name_len = strlen(fname);
1358 * Ensure it ends in a '\'.
1361 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1362 pstrcat(fname, "/");
1368 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status, False);
1369 if (!NT_STATUS_IS_OK(status)) {
1370 return ERROR_NT(status);
1372 pstrcat(fname, tmpname);
1375 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status, False);
1376 if (!NT_STATUS_IS_OK(status)) {
1377 return ERROR_NT(status);
1381 * Check to see if this is a mac fork of some kind.
1384 if( is_ntfs_stream_name(fname)) {
1385 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1390 * Now contruct the smb_open_mode value from the desired access
1391 * and the share access.
1394 if((smb_open_mode = map_share_mode( fname, create_options, &desired_access,
1395 share_access, file_attributes)) == -1)
1396 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1398 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1399 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1402 * Check if POSIX semantics are wanted.
1405 set_posix_case_semantics(conn, file_attributes);
1407 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1409 unix_convert(fname,conn,0,&bad_path,&sbuf);
1411 restore_case_semantics(conn, file_attributes);
1412 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1414 /* All file access must go through check_name() */
1415 if (!check_name(fname,conn)) {
1416 restore_case_semantics(conn, file_attributes);
1417 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
1421 /* This is the correct thing to do (check every time) but can_delete is
1422 expensive (it may have to read the parent directory permissions). So
1423 for now we're not doing it unless we have a strong hint the client
1424 is really going to delete this file. */
1425 if (desired_access & DELETE_ACCESS) {
1427 /* Setting FILE_SHARE_DELETE is the hint. */
1428 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE) && (desired_access & DELETE_ACCESS)) {
1430 status = can_delete(conn, fname, file_attributes, bad_path, True);
1431 /* We're only going to fail here if it's access denied, as that's the
1432 only error we care about for "can we delete this ?" questions. */
1433 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
1434 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
1435 restore_case_semantics(conn, file_attributes);
1436 END_PROFILE(SMBntcreateX);
1437 return ERROR_NT(status);
1442 ctx = talloc_init("NTTRANS_CREATE_EA");
1444 talloc_destroy(ctx);
1445 restore_case_semantics(conn, file_attributes);
1446 return ERROR_NT(NT_STATUS_NO_MEMORY);
1449 pdata = data + sd_len;
1451 /* We have already checked that ea_len <= data_count here. */
1452 ea_list = read_nttrans_ea_list(ctx, pdata, ea_len);
1454 talloc_destroy(ctx);
1455 restore_case_semantics(conn, file_attributes);
1456 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1461 * If it's a request for a directory open, deal with it separately.
1464 if(create_options & FILE_DIRECTORY_FILE) {
1466 /* Can't open a temp directory. IFS kit test. */
1467 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1468 talloc_destroy(ctx);
1469 restore_case_semantics(conn, file_attributes);
1470 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1476 * We will get a create directory here if the Win32
1477 * app specified a security descriptor in the
1478 * CreateDirectory() call.
1481 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
1484 talloc_destroy(ctx);
1485 restore_case_semantics(conn, file_attributes);
1486 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1492 * Ordinary file case.
1495 fsp = open_file_shared1(conn,fname,&sbuf,desired_access,
1496 smb_open_mode,smb_ofun,file_attributes,
1497 oplock_request,&rmode,&smb_action);
1500 if(errno == EISDIR) {
1503 * Fail the open if it was explicitly a non-directory file.
1506 if (create_options & FILE_NON_DIRECTORY_FILE) {
1507 restore_case_semantics(conn, file_attributes);
1508 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1512 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
1515 talloc_destroy(ctx);
1516 restore_case_semantics(conn, file_attributes);
1517 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1520 talloc_destroy(ctx);
1521 restore_case_semantics(conn, file_attributes);
1522 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1523 /* We have re-scheduled this call. */
1526 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1532 * According to the MS documentation, the only time the security
1533 * descriptor is applied to the opened file is iff we *created* the
1534 * file; an existing file stays the same.
1536 * Also, it seems (from observation) that you can open the file with
1537 * any access mask but you can still write the sd. We need to override
1538 * the granted access before we call set_sd
1539 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1542 if (lp_nt_acl_support(SNUM(conn)) && sd_len && smb_action == FILE_WAS_CREATED) {
1543 uint32 saved_access = fsp->desired_access;
1545 /* We have already checked that sd_len <= data_count here. */
1547 fsp->desired_access = FILE_GENERIC_ALL;
1549 status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION);
1550 if (!NT_STATUS_IS_OK(status)) {
1551 talloc_destroy(ctx);
1552 close_file(fsp,False);
1553 restore_case_semantics(conn, file_attributes);
1554 return ERROR_NT(status);
1556 fsp->desired_access = saved_access;
1559 if (ea_len && (smb_action == FILE_WAS_CREATED)) {
1560 status = set_ea(conn, fsp, fname, ea_list);
1561 talloc_destroy(ctx);
1562 if (!NT_STATUS_IS_OK(status)) {
1563 close_file(fsp,False);
1564 restore_case_semantics(conn, file_attributes);
1565 return ERROR_NT(status);
1569 restore_case_semantics(conn, file_attributes);
1571 file_len = sbuf.st_size;
1572 fmode = dos_mode(conn,fname,&sbuf);
1574 fmode = FILE_ATTRIBUTE_NORMAL;
1576 if (!fsp->is_directory && (fmode & aDIR)) {
1577 close_file(fsp,False);
1578 return ERROR_DOS(ERRDOS,ERRnoaccess);
1581 /* Save the requested allocation size. */
1582 if ((smb_action == FILE_WAS_CREATED) || (smb_action == FILE_WAS_OVERWRITTEN)) {
1583 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1584 #ifdef LARGE_SMB_OFF_T
1585 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1587 if (allocation_size && (allocation_size > file_len)) {
1588 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
1589 if (fsp->is_directory) {
1590 close_file(fsp,False);
1591 /* Can't set allocation size on a directory. */
1592 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1594 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1595 close_file(fsp,False);
1596 return ERROR_NT(NT_STATUS_DISK_FULL);
1599 fsp->initial_allocation_size = smb_roundup(fsp->conn, (SMB_BIG_UINT)file_len);
1604 * If the caller set the extended oplock request bit
1605 * and we granted one (by whatever means) - set the
1606 * correct bit for extended oplock reply.
1609 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
1610 extended_oplock_granted = True;
1613 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
1614 extended_oplock_granted = True;
1617 /* Realloc the size of parameters and data we will return */
1618 params = nttrans_realloc(ppparams, 69);
1620 return ERROR_DOS(ERRDOS,ERRnomem);
1623 if (extended_oplock_granted)
1624 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1625 else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
1626 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1628 SCVAL(p,0,NO_OPLOCK_RETURN);
1631 SSVAL(p,0,fsp->fnum);
1633 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
1634 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1636 SIVAL(p,0,smb_action);
1640 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1642 if (lp_dos_filetime_resolution(SNUM(conn))) {
1644 sbuf.st_atime &= ~1;
1645 sbuf.st_mtime &= ~1;
1646 sbuf.st_mtime &= ~1;
1649 put_long_date(p,c_time);
1651 put_long_date(p,sbuf.st_atime); /* access time */
1653 put_long_date(p,sbuf.st_mtime); /* write time */
1655 put_long_date(p,sbuf.st_mtime); /* change time */
1657 SIVAL(p,0,fmode); /* File Attributes. */
1659 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1661 SOFF_T(p,0,file_len);
1663 if (flags & EXTENDED_RESPONSE_REQUIRED)
1666 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1668 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1670 /* Send the required number of replies */
1671 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1676 /****************************************************************************
1677 Reply to a NT CANCEL request.
1678 ****************************************************************************/
1680 int reply_ntcancel(connection_struct *conn,
1681 char *inbuf,char *outbuf,int length,int bufsize)
1684 * Go through and cancel any pending change notifies.
1687 int mid = SVAL(inbuf,smb_mid);
1688 START_PROFILE(SMBntcancel);
1689 remove_pending_change_notify_requests_by_mid(mid);
1690 remove_pending_lock_requests_by_mid(mid);
1691 srv_cancel_sign_response(mid);
1693 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1695 END_PROFILE(SMBntcancel);
1699 /****************************************************************************
1701 ****************************************************************************/
1703 static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *newname, uint16 attrs)
1705 BOOL bad_path_oldname = False;
1706 BOOL bad_path_newname = False;
1707 SMB_STRUCT_STAT sbuf1, sbuf2;
1708 pstring last_component_oldname;
1709 pstring last_component_newname;
1710 files_struct *fsp1,*fsp2;
1716 NTSTATUS status = NT_STATUS_OK;
1722 if (ms_has_wild(newname) || ms_has_wild(oldname)) {
1723 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1726 if (!CAN_WRITE(conn))
1727 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1729 unix_convert(oldname,conn,last_component_oldname,&bad_path_oldname,&sbuf1);
1730 if (bad_path_oldname) {
1731 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1734 /* Quick check for "." and ".." */
1735 if (last_component_oldname[0] == '.') {
1736 if (!last_component_oldname[1] || (last_component_oldname[1] == '.' && !last_component_oldname[2])) {
1737 return NT_STATUS_OBJECT_NAME_INVALID;
1741 /* Source must already exist. */
1742 if (!VALID_STAT(sbuf1)) {
1743 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1745 if (!check_name(oldname,conn)) {
1746 return NT_STATUS_ACCESS_DENIED;
1749 /* Ensure attributes match. */
1750 fmode = dos_mode(conn,oldname,&sbuf1);
1751 if ((fmode & ~attrs) & (aHIDDEN | aSYSTEM))
1752 return NT_STATUS_NO_SUCH_FILE;
1754 unix_convert(newname,conn,last_component_newname,&bad_path_newname,&sbuf2);
1755 if (bad_path_newname) {
1756 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1759 /* Quick check for "." and ".." */
1760 if (last_component_newname[0] == '.') {
1761 if (!last_component_newname[1] || (last_component_newname[1] == '.' && !last_component_newname[2])) {
1762 return NT_STATUS_OBJECT_NAME_INVALID;
1766 /* Disallow if newname already exists. */
1767 if (VALID_STAT(sbuf2)) {
1768 return NT_STATUS_OBJECT_NAME_COLLISION;
1771 if (!check_name(newname,conn)) {
1772 return NT_STATUS_ACCESS_DENIED;
1775 /* No links from a directory. */
1776 if (S_ISDIR(sbuf1.st_mode)) {
1777 return NT_STATUS_FILE_IS_A_DIRECTORY;
1780 /* Ensure this is within the share. */
1781 if (!reduce_name(conn, oldname) != 0) {
1782 return NT_STATUS_ACCESS_DENIED;
1785 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname, newname));
1787 fsp1 = open_file_shared1(conn,oldname,&sbuf1,FILE_READ_DATA,SET_DENY_MODE(DENY_ALL)|SET_OPEN_MODE(DOS_OPEN_RDONLY),
1788 (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN),FILE_ATTRIBUTE_NORMAL,0,
1789 &access_mode,&smb_action);
1792 get_saved_error_triple(NULL, NULL, &status);
1793 if (NT_STATUS_IS_OK(status)) {
1794 status = NT_STATUS_ACCESS_DENIED;
1796 set_saved_error_triple(0, 0, NT_STATUS_OK);
1800 fsp2 = open_file_shared1(conn,newname,&sbuf2,FILE_WRITE_DATA,SET_DENY_MODE(DENY_ALL)|SET_OPEN_MODE(DOS_OPEN_WRONLY),
1801 (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_FAIL),fmode,INTERNAL_OPEN_ONLY,
1802 &access_mode,&smb_action);
1805 get_saved_error_triple(NULL, NULL, &status);
1806 if (NT_STATUS_IS_OK(status)) {
1807 status = NT_STATUS_ACCESS_DENIED;
1809 set_saved_error_triple(0, 0, NT_STATUS_OK);
1810 close_file(fsp1,False);
1815 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1818 * As we are opening fsp1 read-only we only expect
1819 * an error on close on fsp2 if we are out of space.
1820 * Thus we don't look at the error return from the
1823 close_file(fsp1,False);
1825 /* Ensure the modtime is set correctly on the destination file. */
1826 fsp_set_pending_modtime(fsp2, sbuf1.st_mtime);
1828 close_ret = close_file(fsp2,False);
1830 /* Grrr. We have to do this as open_file_shared1 adds aARCH when it
1831 creates the file. This isn't the correct thing to do in the copy case. JRA */
1832 file_set_dosmode(conn, newname, fmode, &sbuf2, True);
1834 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1835 return NT_STATUS_DISK_FULL;
1838 if (close_ret != 0) {
1839 status = map_nt_error_from_unix(close_ret);
1840 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1841 nt_errstr(status), oldname, newname));
1846 /****************************************************************************
1847 Reply to a NT rename request.
1848 ****************************************************************************/
1850 int reply_ntrename(connection_struct *conn,
1851 char *inbuf,char *outbuf,int length,int bufsize)
1858 uint16 attrs = SVAL(inbuf,smb_vwv0);
1859 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1861 START_PROFILE(SMBntrename);
1863 p = smb_buf(inbuf) + 1;
1864 p += srvstr_get_path(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, True);
1865 if (!NT_STATUS_IS_OK(status)) {
1866 END_PROFILE(SMBntrename);
1867 return ERROR_NT(status);
1870 if( is_ntfs_stream_name(oldname)) {
1871 /* Can't rename a stream. */
1872 END_PROFILE(SMBntrename);
1873 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1876 if (ms_has_wild(oldname)) {
1877 END_PROFILE(SMBntrename);
1878 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1882 p += srvstr_get_path(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status, False);
1883 if (!NT_STATUS_IS_OK(status)) {
1884 END_PROFILE(SMBntrename);
1885 return ERROR_NT(status);
1888 RESOLVE_DFSPATH(oldname, conn, inbuf, outbuf);
1889 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1891 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1893 switch(rename_type) {
1894 case RENAME_FLAG_RENAME:
1895 status = rename_internals(conn, oldname, newname, attrs, False);
1897 case RENAME_FLAG_HARD_LINK:
1898 status = hardlink_internals(conn, oldname, newname);
1900 case RENAME_FLAG_COPY:
1901 status = copy_internals(conn, oldname, newname, attrs);
1903 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1904 status = NT_STATUS_INVALID_PARAMETER;
1907 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1911 if (!NT_STATUS_IS_OK(status)) {
1912 END_PROFILE(SMBntrename);
1913 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1914 /* We have re-scheduled this call. */
1917 return ERROR_NT(status);
1921 * Win2k needs a changenotify request response before it will
1922 * update after a rename..
1924 process_pending_change_notify_queue((time_t)0);
1925 outsize = set_message(outbuf,0,0,True);
1927 END_PROFILE(SMBntrename);
1931 /****************************************************************************
1932 Reply to an unsolicited SMBNTtranss - just ignore it!
1933 ****************************************************************************/
1935 int reply_nttranss(connection_struct *conn,
1936 char *inbuf,char *outbuf,int length,int bufsize)
1938 START_PROFILE(SMBnttranss);
1939 DEBUG(4,("Ignoring nttranss of length %d\n",length));
1940 END_PROFILE(SMBnttranss);
1944 /****************************************************************************
1945 Reply to a notify change - queue the request and
1946 don't allow a directory to be opened.
1947 ****************************************************************************/
1949 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1950 char **ppsetup, uint32 setup_count,
1951 char **ppparams, uint32 parameter_count,
1952 char **ppdata, uint32 data_count, uint32 max_data_count)
1954 char *setup = *ppsetup;
1959 return ERROR_DOS(ERRDOS,ERRbadfunc);
1961 fsp = file_fsp(setup,4);
1962 flags = IVAL(setup, 0);
1964 DEBUG(3,("call_nt_transact_notify_change\n"));
1967 return ERROR_DOS(ERRDOS,ERRbadfid);
1969 if((!fsp->is_directory) || (conn != fsp->conn))
1970 return ERROR_DOS(ERRDOS,ERRbadfid);
1972 if (!change_notify_set(inbuf, fsp, conn, flags))
1973 return(UNIXERROR(ERRDOS,ERRbadfid));
1975 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1976 name = %s\n", fsp->fsp_name ));
1981 /****************************************************************************
1982 Reply to an NT transact rename command.
1983 ****************************************************************************/
1985 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1986 char **ppsetup, uint32 setup_count,
1987 char **ppparams, uint32 parameter_count,
1988 char **ppdata, uint32 data_count, uint32 max_data_count)
1990 char *params = *ppparams;
1992 files_struct *fsp = NULL;
1993 BOOL replace_if_exists = False;
1996 if(parameter_count < 4)
1997 return ERROR_DOS(ERRDOS,ERRbadfunc);
1999 fsp = file_fsp(params, 0);
2000 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
2001 CHECK_FSP(fsp, conn);
2002 srvstr_get_path(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE, &status, True);
2003 if (!NT_STATUS_IS_OK(status)) {
2004 return ERROR_NT(status);
2007 status = rename_internals(conn, fsp->fsp_name,
2008 new_name, 0, replace_if_exists);
2009 if (!NT_STATUS_IS_OK(status))
2010 return ERROR_NT(status);
2013 * Rename was successful.
2015 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2017 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
2018 fsp->fsp_name, new_name));
2021 * Win2k needs a changenotify request response before it will
2022 * update after a rename..
2025 process_pending_change_notify_queue((time_t)0);
2030 /******************************************************************************
2031 Fake up a completely empty SD.
2032 *******************************************************************************/
2034 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
2038 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
2040 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
2047 /****************************************************************************
2048 Reply to query a security descriptor.
2049 ****************************************************************************/
2051 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2052 char **ppsetup, uint32 setup_count,
2053 char **ppparams, uint32 parameter_count,
2054 char **ppdata, uint32 data_count, uint32 max_data_count)
2056 char *params = *ppparams;
2057 char *data = *ppdata;
2059 SEC_DESC *psd = NULL;
2061 uint32 security_info_wanted;
2062 TALLOC_CTX *mem_ctx;
2063 files_struct *fsp = NULL;
2065 if(parameter_count < 8)
2066 return ERROR_DOS(ERRDOS,ERRbadfunc);
2068 fsp = file_fsp(params,0);
2070 return ERROR_DOS(ERRDOS,ERRbadfid);
2072 security_info_wanted = IVAL(params,4);
2074 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
2075 (unsigned int)security_info_wanted ));
2077 params = nttrans_realloc(ppparams, 4);
2079 return ERROR_DOS(ERRDOS,ERRnomem);
2081 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
2082 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
2083 return ERROR_DOS(ERRDOS,ERRnomem);
2087 * Get the permissions to return.
2090 if (!lp_nt_acl_support(SNUM(conn)))
2091 sd_size = get_null_nt_acl(mem_ctx, &psd);
2093 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fd, security_info_wanted, &psd);
2096 talloc_destroy(mem_ctx);
2097 return(UNIXERROR(ERRDOS,ERRnoaccess));
2100 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size));
2102 SIVAL(params,0,(uint32)sd_size);
2104 if(max_data_count < sd_size) {
2106 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
2107 params, 4, *ppdata, 0);
2108 talloc_destroy(mem_ctx);
2113 * Allocate the data we will point this at.
2116 data = nttrans_realloc(ppdata, sd_size);
2118 talloc_destroy(mem_ctx);
2119 return ERROR_DOS(ERRDOS,ERRnomem);
2123 * Init the parse struct we will marshall into.
2126 prs_init(&pd, 0, mem_ctx, MARSHALL);
2129 * Setup the prs_struct to point at the memory we just
2133 prs_give_memory( &pd, data, (uint32)sd_size, False);
2136 * Finally, linearize into the outgoing buffer.
2139 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2140 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2141 security descriptor.\n"));
2143 * Return access denied for want of a better error message..
2145 talloc_destroy(mem_ctx);
2146 return(UNIXERROR(ERRDOS,ERRnoaccess));
2150 * Now we can delete the security descriptor.
2153 talloc_destroy(mem_ctx);
2155 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 4, data, (int)sd_size);
2159 /****************************************************************************
2160 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2161 ****************************************************************************/
2163 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2164 char **ppsetup, uint32 setup_count,
2165 char **ppparams, uint32 parameter_count,
2166 char **ppdata, uint32 data_count, uint32 max_data_count)
2168 char *params= *ppparams;
2169 char *data = *ppdata;
2170 files_struct *fsp = NULL;
2171 uint32 security_info_sent = 0;
2174 if(parameter_count < 8)
2175 return ERROR_DOS(ERRDOS,ERRbadfunc);
2177 if((fsp = file_fsp(params,0)) == NULL)
2178 return ERROR_DOS(ERRDOS,ERRbadfid);
2180 if(!lp_nt_acl_support(SNUM(conn)))
2183 security_info_sent = IVAL(params,4);
2185 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
2186 (unsigned int)security_info_sent ));
2188 if (data_count == 0)
2189 return ERROR_DOS(ERRDOS, ERRnoaccess);
2191 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent)))
2192 return ERROR_NT(nt_status);
2196 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2200 /****************************************************************************
2202 ****************************************************************************/
2204 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2205 char **ppsetup, uint32 setup_count,
2206 char **ppparams, uint32 parameter_count,
2207 char **ppdata, uint32 data_count, uint32 max_data_count)
2214 static BOOL logged_message;
2215 char *pdata = *ppdata;
2217 if (setup_count != 8) {
2218 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2219 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2222 function = IVAL(*ppsetup, 0);
2223 fidnum = SVAL(*ppsetup, 4);
2224 isFSctl = CVAL(*ppsetup, 6);
2225 compfilter = CVAL(*ppsetup, 7);
2227 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2228 function, fidnum, isFSctl, compfilter));
2230 fsp=file_fsp(*ppsetup, 4);
2231 /* this check is done in each implemented function case for now
2232 because I don't want to break anything... --metze
2233 FSP_BELONGS_CONN(fsp,conn);*/
2236 case FSCTL_SET_SPARSE:
2237 /* pretend this succeeded - tho strictly we should
2238 mark the file sparse (if the local fs supports it)
2239 so we can know if we need to pre-allocate or not */
2241 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2242 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2245 case FSCTL_0x000900C0:
2246 /* pretend this succeeded - don't know what this really is
2247 but works ok like this --metze
2250 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2251 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2254 case FSCTL_GET_REPARSE_POINT:
2255 /* pretend this fail - my winXP does it like this
2259 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2260 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2263 case FSCTL_SET_REPARSE_POINT:
2264 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2268 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2269 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2272 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
2275 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2276 * and return their volume names. If max_data_count is 16, then it is just
2277 * asking for the number of volumes and length of the combined names.
2279 * pdata is the data allocated by our caller, but that uses
2280 * total_data_count (which is 0 in our case) rather than max_data_count.
2281 * Allocate the correct amount and return the pointer to let
2282 * it be deallocated when we return.
2284 SHADOW_COPY_DATA *shadow_data = NULL;
2285 TALLOC_CTX *shadow_mem_ctx = NULL;
2286 BOOL labels = False;
2287 uint32 labels_data_count = 0;
2291 FSP_BELONGS_CONN(fsp,conn);
2293 if (max_data_count < 16) {
2294 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2296 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2299 if (max_data_count > 16) {
2303 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2304 if (shadow_mem_ctx == NULL) {
2305 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2306 return ERROR_NT(NT_STATUS_NO_MEMORY);
2309 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2310 if (shadow_data == NULL) {
2311 DEBUG(0,("talloc_zero() failed!\n"));
2312 talloc_destroy(shadow_mem_ctx);
2313 return ERROR_NT(NT_STATUS_NO_MEMORY);
2316 shadow_data->mem_ctx = shadow_mem_ctx;
2319 * Call the VFS routine to actually do the work.
2321 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2322 talloc_destroy(shadow_data->mem_ctx);
2323 if (errno == ENOSYS) {
2324 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2325 conn->connectpath));
2326 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2328 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2329 conn->connectpath));
2330 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
2334 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2339 data_count = 12+labels_data_count+4;
2342 if (max_data_count<data_count) {
2343 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2344 max_data_count,data_count));
2345 talloc_destroy(shadow_data->mem_ctx);
2346 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
2349 pdata = nttrans_realloc(ppdata, data_count);
2350 if (pdata == NULL) {
2351 talloc_destroy(shadow_data->mem_ctx);
2352 return ERROR_NT(NT_STATUS_NO_MEMORY);
2357 /* num_volumes 4 bytes */
2358 SIVAL(pdata,0,shadow_data->num_volumes);
2361 /* num_labels 4 bytes */
2362 SIVAL(pdata,4,shadow_data->num_volumes);
2365 /* needed_data_count 4 bytes */
2366 SIVAL(pdata,8,labels_data_count);
2370 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2371 shadow_data->num_volumes,fsp->fsp_name));
2372 if (labels && shadow_data->labels) {
2373 for (i=0;i<shadow_data->num_volumes;i++) {
2374 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2375 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2376 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2380 talloc_destroy(shadow_data->mem_ctx);
2382 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
2387 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2389 /* pretend this succeeded -
2391 * we have to send back a list with all files owned by this SID
2393 * but I have to check that --metze
2397 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2399 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2401 FSP_BELONGS_CONN(fsp,conn);
2403 /* unknown 4 bytes: this is not the length of the sid :-( */
2404 /*unknown = IVAL(pdata,0);*/
2406 sid_parse(pdata+4,sid_len,&sid);
2407 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2409 if (!NT_STATUS_IS_OK(sid_to_uid(&sid, &uid))) {
2410 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2411 sid_string_static(&sid),(unsigned long)sid_len));
2415 /* we can take a look at the find source :-)
2417 * find ./ -uid $uid -name '*' is what we need here
2420 * and send 4bytes len and then NULL terminated unicode strings
2423 * but I don't know how to deal with the paged results
2424 * (maybe we can hang the result anywhere in the fsp struct)
2426 * we don't send all files at once
2427 * and at the next we should *not* start from the beginning,
2428 * so we have to cache the result
2433 /* this works for now... */
2434 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2438 if (!logged_message) {
2439 logged_message = True; /* Only print this once... */
2440 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2445 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2449 #ifdef HAVE_SYS_QUOTAS
2450 /****************************************************************************
2451 Reply to get user quota
2452 ****************************************************************************/
2454 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2455 char **ppsetup, uint32 setup_count,
2456 char **ppparams, uint32 parameter_count,
2457 char **ppdata, uint32 data_count, uint32 max_data_count)
2459 NTSTATUS nt_status = NT_STATUS_OK;
2460 char *params = *ppparams;
2461 char *pdata = *ppdata;
2463 int data_len=0,param_len=0;
2466 files_struct *fsp = NULL;
2470 BOOL start_enum = True;
2471 SMB_NTQUOTA_STRUCT qt;
2472 SMB_NTQUOTA_LIST *tmp_list;
2473 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2474 extern struct current_user current_user;
2479 if (current_user.uid != 0) {
2480 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2481 lp_servicename(SNUM(conn)),conn->user));
2482 return ERROR_DOS(ERRDOS,ERRnoaccess);
2486 * Ensure minimum number of parameters sent.
2489 if (parameter_count < 4) {
2490 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2491 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2494 /* maybe we can check the quota_fnum */
2495 fsp = file_fsp(params,0);
2496 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2497 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2498 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2501 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2502 * is done by CHECK_NTQUOTA_HANDLE_OK()
2504 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2506 level = SVAL(params,2);
2508 /* unknown 12 bytes leading in params */
2511 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2512 /* seems that we should continue with the enum here --metze */
2514 if (qt_handle->quota_list!=NULL &&
2515 qt_handle->tmp_list==NULL) {
2518 free_ntquota_list(&(qt_handle->quota_list));
2520 /* Realloc the size of parameters and data we will return */
2522 params = nttrans_realloc(ppparams, param_len);
2524 return ERROR_DOS(ERRDOS,ERRnomem);
2527 SIVAL(params,0,data_len);
2534 case TRANSACT_GET_USER_QUOTA_LIST_START:
2536 if (qt_handle->quota_list==NULL &&
2537 qt_handle->tmp_list==NULL) {
2541 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2542 return ERROR_DOS(ERRSRV,ERRerror);
2544 /* Realloc the size of parameters and data we will return */
2546 params = nttrans_realloc(ppparams, param_len);
2548 return ERROR_DOS(ERRDOS,ERRnomem);
2550 /* we should not trust the value in max_data_count*/
2551 max_data_count = MIN(max_data_count,2048);
2553 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2555 return ERROR_DOS(ERRDOS,ERRnomem);
2560 /* set params Size of returned Quota Data 4 bytes*/
2561 /* but set it later when we know it */
2563 /* for each entry push the data */
2566 qt_handle->tmp_list = qt_handle->quota_list;
2569 tmp_list = qt_handle->tmp_list;
2571 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2572 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2574 sid_len = sid_size(&tmp_list->quotas->sid);
2575 entry_len = 40 + sid_len;
2577 /* nextoffset entry 4 bytes */
2578 SIVAL(entry,0,entry_len);
2580 /* then the len of the SID 4 bytes */
2581 SIVAL(entry,4,sid_len);
2583 /* unknown data 8 bytes SMB_BIG_UINT */
2584 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2586 /* the used disk space 8 bytes SMB_BIG_UINT */
2587 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2589 /* the soft quotas 8 bytes SMB_BIG_UINT */
2590 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2592 /* the hard quotas 8 bytes SMB_BIG_UINT */
2593 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2595 /* and now the SID */
2596 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2599 qt_handle->tmp_list = tmp_list;
2601 /* overwrite the offset of the last entry */
2602 SIVAL(entry-entry_len,0,0);
2604 data_len = 4+qt_len;
2605 /* overwrite the params quota_data_len */
2606 SIVAL(params,0,data_len);
2610 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2612 /* unknown 4 bytes IVAL(pdata,0) */
2614 if (data_count < 8) {
2615 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2616 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2619 sid_len = IVAL(pdata,4);
2620 /* Ensure this is less than 1mb. */
2621 if (sid_len > (1024*1024)) {
2622 return ERROR_DOS(ERRDOS,ERRnomem);
2625 if (data_count < 8+sid_len) {
2626 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2627 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2630 data_len = 4+40+sid_len;
2632 if (max_data_count < data_len) {
2633 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2634 max_data_count, data_len));
2636 SIVAL(params,0,data_len);
2638 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2642 sid_parse(pdata+8,sid_len,&sid);
2645 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2648 * we have to return zero's in all fields
2649 * instead of returning an error here
2654 /* Realloc the size of parameters and data we will return */
2656 params = nttrans_realloc(ppparams, param_len);
2658 return ERROR_DOS(ERRDOS,ERRnomem);
2660 pdata = nttrans_realloc(ppdata, data_len);
2662 return ERROR_DOS(ERRDOS,ERRnomem);
2666 /* set params Size of returned Quota Data 4 bytes*/
2667 SIVAL(params,0,data_len);
2669 /* nextoffset entry 4 bytes */
2672 /* then the len of the SID 4 bytes */
2673 SIVAL(entry,4,sid_len);
2675 /* unknown data 8 bytes SMB_BIG_UINT */
2676 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2678 /* the used disk space 8 bytes SMB_BIG_UINT */
2679 SBIG_UINT(entry,16,qt.usedspace);
2681 /* the soft quotas 8 bytes SMB_BIG_UINT */
2682 SBIG_UINT(entry,24,qt.softlim);
2684 /* the hard quotas 8 bytes SMB_BIG_UINT */
2685 SBIG_UINT(entry,32,qt.hardlim);
2687 /* and now the SID */
2688 sid_linearize(entry+40, sid_len, &sid);
2693 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2694 return ERROR_DOS(ERRSRV,ERRerror);
2698 send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
2703 /****************************************************************************
2704 Reply to set user quota
2705 ****************************************************************************/
2707 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2708 char **ppsetup, uint32 setup_count,
2709 char **ppparams, uint32 parameter_count,
2710 char **ppdata, uint32 data_count, uint32 max_data_count)
2712 char *params = *ppparams;
2713 char *pdata = *ppdata;
2714 int data_len=0,param_len=0;
2715 SMB_NTQUOTA_STRUCT qt;
2718 files_struct *fsp = NULL;
2723 if (current_user.uid != 0) {
2724 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2725 lp_servicename(SNUM(conn)),conn->user));
2726 return ERROR_DOS(ERRDOS,ERRnoaccess);
2730 * Ensure minimum number of parameters sent.
2733 if (parameter_count < 2) {
2734 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2735 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2738 /* maybe we can check the quota_fnum */
2739 fsp = file_fsp(params,0);
2740 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2741 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2742 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2745 if (data_count < 40) {
2746 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2747 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2750 /* offset to next quota record.
2751 * 4 bytes IVAL(pdata,0)
2756 sid_len = IVAL(pdata,4);
2758 if (data_count < 40+sid_len) {
2759 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2760 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2763 /* unknown 8 bytes in pdata
2764 * maybe its the change time in NTTIME
2767 /* the used space 8 bytes (SMB_BIG_UINT)*/
2768 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2769 #ifdef LARGE_SMB_OFF_T
2770 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2771 #else /* LARGE_SMB_OFF_T */
2772 if ((IVAL(pdata,20) != 0)&&
2773 ((qt.usedspace != 0xFFFFFFFF)||
2774 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2775 /* more than 32 bits? */
2776 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2778 #endif /* LARGE_SMB_OFF_T */
2780 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2781 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2782 #ifdef LARGE_SMB_OFF_T
2783 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2784 #else /* LARGE_SMB_OFF_T */
2785 if ((IVAL(pdata,28) != 0)&&
2786 ((qt.softlim != 0xFFFFFFFF)||
2787 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2788 /* more than 32 bits? */
2789 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2791 #endif /* LARGE_SMB_OFF_T */
2793 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2794 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2795 #ifdef LARGE_SMB_OFF_T
2796 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2797 #else /* LARGE_SMB_OFF_T */
2798 if ((IVAL(pdata,36) != 0)&&
2799 ((qt.hardlim != 0xFFFFFFFF)||
2800 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2801 /* more than 32 bits? */
2802 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2804 #endif /* LARGE_SMB_OFF_T */
2806 sid_parse(pdata+40,sid_len,&sid);
2807 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2809 /* 44 unknown bytes left... */
2811 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2812 return ERROR_DOS(ERRSRV,ERRerror);
2815 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
2819 #endif /* HAVE_SYS_QUOTAS */
2821 /****************************************************************************
2822 Reply to a SMBNTtrans.
2823 ****************************************************************************/
2825 int reply_nttrans(connection_struct *conn,
2826 char *inbuf,char *outbuf,int length,int bufsize)
2829 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2830 #if 0 /* Not used. */
2831 uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount);
2832 uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
2833 #endif /* Not used. */
2834 uint32 total_parameter_count = IVAL(inbuf, smb_nt_TotalParameterCount);
2835 uint32 total_data_count = IVAL(inbuf, smb_nt_TotalDataCount);
2836 uint32 parameter_count = IVAL(inbuf,smb_nt_ParameterCount);
2837 uint32 parameter_offset = IVAL(inbuf,smb_nt_ParameterOffset);
2838 uint32 data_count = IVAL(inbuf,smb_nt_DataCount);
2839 uint32 data_offset = IVAL(inbuf,smb_nt_DataOffset);
2840 uint16 setup_count = 2*CVAL(inbuf,smb_nt_SetupCount); /* setup count is in *words* */
2841 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2842 char *params = NULL, *data = NULL, *setup = NULL;
2843 uint32 num_params_sofar, num_data_sofar;
2844 START_PROFILE(SMBnttrans);
2846 if(global_oplock_break &&
2847 ((function_code == NT_TRANSACT_CREATE) ||
2848 (function_code == NT_TRANSACT_RENAME))) {
2850 * Queue this open message as we are the process of an oplock break.
2853 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2854 due to being in oplock break state.\n", (unsigned int)function_code ));
2856 push_oplock_pending_smb_message( inbuf, length);
2857 END_PROFILE(SMBnttrans);
2861 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2862 END_PROFILE(SMBnttrans);
2863 return ERROR_DOS(ERRSRV,ERRaccess);
2866 outsize = set_message(outbuf,0,0,True);
2869 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2870 * Ensure this is so as a sanity check.
2873 if(CVAL(inbuf, smb_wct) != 19 + (setup_count/2)) {
2874 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2875 CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
2879 /* Don't allow more than 128mb for each value. */
2880 if ((total_parameter_count > (1024*1024*128)) || (total_data_count > (1024*1024*128))) {
2881 END_PROFILE(SMBnttrans);
2882 return ERROR_DOS(ERRDOS,ERRnomem);
2885 /* Allocate the space for the setup, the maximum needed parameters and data */
2888 setup = (char *)SMB_MALLOC(setup_count);
2889 if (total_parameter_count > 0)
2890 params = (char *)SMB_MALLOC(total_parameter_count);
2891 if (total_data_count > 0)
2892 data = (char *)SMB_MALLOC(total_data_count);
2894 if ((total_parameter_count && !params) || (total_data_count && !data) ||
2895 (setup_count && !setup)) {
2899 DEBUG(0,("reply_nttrans : Out of memory\n"));
2900 END_PROFILE(SMBnttrans);
2901 return ERROR_DOS(ERRDOS,ERRnomem);
2904 /* Copy the param and data bytes sent with this request into the params buffer */
2905 num_params_sofar = parameter_count;
2906 num_data_sofar = data_count;
2908 if (parameter_count > total_parameter_count || data_count > total_data_count)
2912 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
2913 if ((smb_nt_SetupStart + setup_count < smb_nt_SetupStart) ||
2914 (smb_nt_SetupStart + setup_count < setup_count))
2916 if (smb_nt_SetupStart + setup_count > length)
2919 memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
2920 dump_data(10, setup, setup_count);
2923 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count));
2924 if ((parameter_offset + parameter_count < parameter_offset) ||
2925 (parameter_offset + parameter_count < parameter_count))
2927 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length)||
2928 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
2931 memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
2932 dump_data(10, params, parameter_count);
2935 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
2936 if ((data_offset + data_count < data_offset) || (data_offset + data_count < data_count))
2938 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2939 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
2942 memcpy( data, smb_base(inbuf) + data_offset, data_count);
2943 dump_data(10, data, data_count);
2946 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2948 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2949 /* We need to send an interim response then receive the rest
2950 of the parameter/data bytes */
2951 outsize = set_message(outbuf,0,0,True);
2952 srv_signing_trans_stop();
2953 if (!send_smb(smbd_server_fd(),outbuf))
2954 exit_server("reply_nttrans: send_smb failed.");
2956 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2958 uint32 parameter_displacement;
2959 uint32 data_displacement;
2961 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
2963 /* We need to re-calcuate the new length after we've read the secondary packet. */
2964 length = smb_len(inbuf) + 4;
2967 * The sequence number for the trans reply is always
2968 * based on the last secondary received.
2971 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2973 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
2974 outsize = set_message(outbuf,0,0,True);
2976 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2978 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2979 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
2984 /* Revise total_params and total_data in case they have changed downwards */
2985 if (IVAL(inbuf, smb_nts_TotalParameterCount) < total_parameter_count)
2986 total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
2987 if (IVAL(inbuf, smb_nts_TotalDataCount) < total_data_count)
2988 total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
2990 parameter_count = IVAL(inbuf,smb_nts_ParameterCount);
2991 parameter_offset = IVAL(inbuf, smb_nts_ParameterOffset);
2992 parameter_displacement = IVAL(inbuf, smb_nts_ParameterDisplacement);
2993 num_params_sofar += parameter_count;
2995 data_count = IVAL(inbuf, smb_nts_DataCount);
2996 data_displacement = IVAL(inbuf, smb_nts_DataDisplacement);
2997 data_offset = IVAL(inbuf, smb_nts_DataOffset);
2998 num_data_sofar += data_count;
3000 if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count) {
3001 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
3005 if (parameter_count) {
3006 if (parameter_displacement + parameter_count > total_parameter_count)
3008 if ((parameter_displacement + parameter_count < parameter_displacement) ||
3009 (parameter_displacement + parameter_count < parameter_count))
3011 if (parameter_displacement > total_parameter_count)
3013 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length) ||
3014 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
3016 if (parameter_displacement + params < params)
3019 memcpy( ¶ms[parameter_displacement], smb_base(inbuf) + parameter_offset, parameter_count);
3023 if (data_displacement + data_count > total_data_count)
3025 if ((data_displacement + data_count < data_displacement) ||
3026 (data_displacement + data_count < data_count))
3028 if (data_displacement > total_data_count)
3030 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
3031 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
3033 if (data_displacement + data < data)
3036 memcpy( &data[data_displacement], smb_base(inbuf)+ data_offset, data_count);
3041 if (Protocol >= PROTOCOL_NT1)
3042 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_IS_LONG_NAME);
3044 /* Now we must call the relevant NT_TRANS function */
3045 switch(function_code) {
3046 case NT_TRANSACT_CREATE:
3047 START_PROFILE_NESTED(NT_transact_create);
3048 outsize = call_nt_transact_create(conn, inbuf, outbuf,
3050 &setup, setup_count,
3051 ¶ms, total_parameter_count,
3052 &data, total_data_count, max_data_count);
3053 END_PROFILE_NESTED(NT_transact_create);
3055 case NT_TRANSACT_IOCTL:
3056 START_PROFILE_NESTED(NT_transact_ioctl);
3057 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
3059 &setup, setup_count,
3060 ¶ms, total_parameter_count,
3061 &data, total_data_count, max_data_count);
3062 END_PROFILE_NESTED(NT_transact_ioctl);
3064 case NT_TRANSACT_SET_SECURITY_DESC:
3065 START_PROFILE_NESTED(NT_transact_set_security_desc);
3066 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
3068 &setup, setup_count,
3069 ¶ms, total_parameter_count,
3070 &data, total_data_count, max_data_count);
3071 END_PROFILE_NESTED(NT_transact_set_security_desc);
3073 case NT_TRANSACT_NOTIFY_CHANGE:
3074 START_PROFILE_NESTED(NT_transact_notify_change);
3075 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
3077 &setup, setup_count,
3078 ¶ms, total_parameter_count,
3079 &data, total_data_count, max_data_count);
3080 END_PROFILE_NESTED(NT_transact_notify_change);
3082 case NT_TRANSACT_RENAME:
3083 START_PROFILE_NESTED(NT_transact_rename);
3084 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
3086 &setup, setup_count,
3087 ¶ms, total_parameter_count,
3088 &data, total_data_count, max_data_count);
3089 END_PROFILE_NESTED(NT_transact_rename);
3092 case NT_TRANSACT_QUERY_SECURITY_DESC:
3093 START_PROFILE_NESTED(NT_transact_query_security_desc);
3094 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
3096 &setup, setup_count,
3097 ¶ms, total_parameter_count,
3098 &data, total_data_count, max_data_count);
3099 END_PROFILE_NESTED(NT_transact_query_security_desc);
3101 #ifdef HAVE_SYS_QUOTAS
3102 case NT_TRANSACT_GET_USER_QUOTA:
3103 START_PROFILE_NESTED(NT_transact_get_user_quota);
3104 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
3106 &setup, setup_count,
3107 ¶ms, total_parameter_count,
3108 &data, total_data_count, max_data_count);
3109 END_PROFILE_NESTED(NT_transact_get_user_quota);
3111 case NT_TRANSACT_SET_USER_QUOTA:
3112 START_PROFILE_NESTED(NT_transact_set_user_quota);
3113 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
3115 &setup, setup_count,
3116 ¶ms, total_parameter_count,
3117 &data, total_data_count, max_data_count);
3118 END_PROFILE_NESTED(NT_transact_set_user_quota);
3120 #endif /* HAVE_SYS_QUOTAS */
3122 /* Error in request */
3123 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
3127 END_PROFILE(SMBnttrans);
3128 srv_signing_trans_stop();
3129 return ERROR_DOS(ERRSRV,ERRerror);
3132 /* As we do not know how many data packets will need to be
3133 returned here the various call_nt_transact_xxxx calls
3134 must send their own. Thus a call_nt_transact_xxxx routine only
3135 returns a value other than -1 when it wants to send
3139 srv_signing_trans_stop();
3144 END_PROFILE(SMBnttrans);
3145 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
3146 calls have already sent it. If outsize != -1 then it is
3147 returning an error packet. */
3151 srv_signing_trans_stop();
3155 END_PROFILE(SMBnttrans);
3156 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);