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 struct current_user current_user;
29 static const char *known_nt_pipes[] = {
50 static char *nttrans_realloc(char **ptr, size_t size)
53 smb_panic("nttrans_realloc() called with NULL ptr\n");
56 *ptr = (char *)SMB_REALLOC(*ptr, size);
60 memset(*ptr,'\0',size);
64 /****************************************************************************
65 Send the required number of replies back.
66 We assume all fields other than the data fields are
67 set correctly for the type of call.
68 HACK ! Always assumes smb_setup field is zero.
69 ****************************************************************************/
71 int send_nt_replies(char *outbuf, int bufsize, NTSTATUS nt_error,
72 char *params, int paramsize, char *pdata, int datasize)
74 int data_to_send = datasize;
75 int params_to_send = paramsize;
79 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
80 int alignment_offset = 3;
81 int data_alignment_offset = 0;
84 * Initially set the wcnt area to be 18 - this is true for all
88 set_message(outbuf,18,0,True);
90 if (NT_STATUS_V(nt_error)) {
95 * If there genuinely are no parameters or data to send just send
99 if(params_to_send == 0 && data_to_send == 0) {
101 if (!send_smb(smbd_server_fd(),outbuf)) {
102 exit_server_cleanly("send_nt_replies: send_smb failed.");
108 * When sending params and data ensure that both are nicely aligned.
109 * Only do this alignment when there is also data to send - else
110 * can cause NT redirector problems.
113 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
114 data_alignment_offset = 4 - (params_to_send % 4);
118 * Space is bufsize minus Netbios over TCP header minus SMB header.
119 * The alignment_offset is to align the param bytes on a four byte
120 * boundary (2 bytes for data len, one byte pad).
121 * NT needs this to work correctly.
124 useable_space = bufsize - ((smb_buf(outbuf)+
125 alignment_offset+data_alignment_offset) -
129 * useable_space can never be more than max_send minus the
133 useable_space = MIN(useable_space,
134 max_send - (alignment_offset+data_alignment_offset));
137 while (params_to_send || data_to_send) {
140 * Calculate whether we will totally or partially fill this packet.
143 total_sent_thistime = params_to_send + data_to_send +
144 alignment_offset + data_alignment_offset;
147 * We can never send more than useable_space.
150 total_sent_thistime = MIN(total_sent_thistime, useable_space);
152 set_message(outbuf, 18, total_sent_thistime, True);
155 * Set total params and data to be sent.
158 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
159 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
162 * Calculate how many parameters and data we can fit into
163 * this packet. Parameters get precedence.
166 params_sent_thistime = MIN(params_to_send,useable_space);
167 data_sent_thistime = useable_space - params_sent_thistime;
168 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
170 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
172 if(params_sent_thistime == 0) {
173 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
174 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
177 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
178 * parameter bytes, however the first 4 bytes of outbuf are
179 * the Netbios over TCP header. Thus use smb_base() to subtract
180 * them from the calculation.
183 SIVAL(outbuf,smb_ntr_ParameterOffset,
184 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
186 * Absolute displacement of param bytes sent in this packet.
189 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
193 * Deal with the data portion.
196 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
198 if(data_sent_thistime == 0) {
199 SIVAL(outbuf,smb_ntr_DataOffset,0);
200 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
203 * The offset of the data bytes is the offset of the
204 * parameter bytes plus the number of parameters being sent this time.
207 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
208 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
209 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
213 * Copy the param bytes into the packet.
216 if(params_sent_thistime) {
217 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
221 * Copy in the data bytes
224 if(data_sent_thistime) {
225 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
226 data_alignment_offset,pd,data_sent_thistime);
229 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
230 params_sent_thistime, data_sent_thistime, useable_space));
231 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
232 params_to_send, data_to_send, paramsize, datasize));
234 /* Send the packet */
236 if (!send_smb(smbd_server_fd(),outbuf)) {
237 exit_server_cleanly("send_nt_replies: send_smb failed.");
240 pp += params_sent_thistime;
241 pd += data_sent_thistime;
243 params_to_send -= params_sent_thistime;
244 data_to_send -= data_sent_thistime;
250 if(params_to_send < 0 || data_to_send < 0) {
251 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
252 params_to_send, data_to_send));
260 /****************************************************************************
261 Is it an NTFS stream name ?
262 ****************************************************************************/
264 BOOL is_ntfs_stream_name(const char *fname)
266 if (lp_posix_pathnames()) {
269 return (strchr_m(fname, ':') != NULL) ? True : False;
272 /****************************************************************************
274 ****************************************************************************/
276 static BOOL saved_case_sensitive;
277 static BOOL saved_case_preserve;
278 static BOOL saved_short_case_preserve;
280 /****************************************************************************
282 ****************************************************************************/
284 static void set_posix_case_semantics(connection_struct *conn, uint32 file_attributes)
286 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
290 saved_case_sensitive = conn->case_sensitive;
291 saved_case_preserve = conn->case_preserve;
292 saved_short_case_preserve = conn->short_case_preserve;
295 conn->case_sensitive = True;
296 conn->case_preserve = True;
297 conn->short_case_preserve = True;
300 /****************************************************************************
301 Restore case semantics.
302 ****************************************************************************/
304 static void restore_case_semantics(connection_struct *conn, uint32 file_attributes)
306 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
310 conn->case_sensitive = saved_case_sensitive;
311 conn->case_preserve = saved_case_preserve;
312 conn->short_case_preserve = saved_short_case_preserve;
315 /****************************************************************************
316 Reply to an NT create and X call on a pipe.
317 ****************************************************************************/
319 static int nt_open_pipe(char *fname, connection_struct *conn,
320 char *inbuf, char *outbuf, int *ppnum)
322 smb_np_struct *p = NULL;
323 uint16 vuid = SVAL(inbuf, smb_uid);
326 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
328 /* See if it is one we want to handle. */
330 if (lp_disable_spoolss() && strequal(fname, "\\spoolss")) {
331 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
334 for( i = 0; known_nt_pipes[i]; i++ ) {
335 if( strequal(fname,known_nt_pipes[i])) {
340 if ( known_nt_pipes[i] == NULL ) {
341 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
344 /* Strip \\ off the name. */
347 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
349 p = open_rpc_pipe_p(fname, conn, vuid);
351 return(ERROR_DOS(ERRSRV,ERRnofids));
354 /* TODO: Add pipe to db */
356 if ( !store_pipe_opendb( p ) ) {
357 DEBUG(3,("nt_open_pipe: failed to store %s pipe open.\n", fname));
364 /****************************************************************************
365 Reply to an NT create and X call for pipes.
366 ****************************************************************************/
368 static int do_ntcreate_pipe_open(connection_struct *conn,
369 char *inbuf,char *outbuf,int length,int bufsize)
376 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
378 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
383 * Deal with pipe return.
386 set_message(outbuf,34,0,True);
388 p = outbuf + smb_vwv2;
392 SIVAL(p,0,FILE_WAS_OPENED);
395 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
398 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
400 SSVAL(p,2, 0x5FF); /* ? */
402 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
404 return chain_reply(inbuf,outbuf,length,bufsize);
407 /****************************************************************************
408 Reply to an NT create and X call for a quota file.
409 ****************************************************************************/
411 int reply_ntcreate_and_X_quota(connection_struct *conn,
416 enum FAKE_FILE_TYPE fake_file_type,
421 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
425 status = open_fake_file(conn, fake_file_type, fname, desired_access,
428 if (!NT_STATUS_IS_OK(status)) {
429 return ERROR_NT(status);
432 set_message(outbuf,34,0,True);
434 p = outbuf + smb_vwv2;
436 /* SCVAL(p,0,NO_OPLOCK_RETURN); */
438 SSVAL(p,0,fsp->fnum);
440 DEBUG(5,("reply_ntcreate_and_X_quota: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
442 result = chain_reply(inbuf,outbuf,length,bufsize);
446 /****************************************************************************
447 Reply to an NT create and X call.
448 ****************************************************************************/
450 int reply_ntcreate_and_X(connection_struct *conn,
451 char *inbuf,char *outbuf,int length,int bufsize)
455 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
456 uint32 access_mask = IVAL(inbuf,smb_ntcreate_DesiredAccess);
457 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
458 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
459 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
460 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
461 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
462 /* Breakout the oplock request bits so we can set the
463 reply bits separately. */
464 int oplock_request = 0;
466 SMB_OFF_T file_len = 0;
467 SMB_STRUCT_STAT sbuf;
469 BOOL bad_path = False;
470 files_struct *fsp=NULL;
472 struct timespec c_timespec;
473 struct timespec a_timespec;
474 struct timespec m_timespec;
475 BOOL extended_oplock_granted = False;
478 START_PROFILE(SMBntcreateX);
480 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
481 "file_attributes = 0x%x, share_access = 0x%x, "
482 "create_disposition = 0x%x create_options = 0x%x "
483 "root_dir_fid = 0x%x\n",
485 (unsigned int)access_mask,
486 (unsigned int)file_attributes,
487 (unsigned int)share_access,
488 (unsigned int)create_disposition,
489 (unsigned int)create_options,
490 (unsigned int)root_dir_fid ));
492 /* If it's an IPC, use the pipe handler. */
495 if (lp_nt_pipe_support()) {
496 END_PROFILE(SMBntcreateX);
497 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
499 END_PROFILE(SMBntcreateX);
500 return(ERROR_DOS(ERRDOS,ERRnoaccess));
504 if (create_options & FILE_OPEN_BY_FILE_ID) {
505 END_PROFILE(SMBntcreateX);
506 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
513 if(root_dir_fid != 0) {
515 * This filename is relative to a directory fid.
518 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
522 END_PROFILE(SMBntcreateX);
523 return(ERROR_DOS(ERRDOS,ERRbadfid));
526 if(!dir_fsp->is_directory) {
528 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
529 if (!NT_STATUS_IS_OK(status)) {
530 END_PROFILE(SMBntcreateX);
531 return ERROR_NT(status);
535 * Check to see if this is a mac fork of some kind.
538 if( is_ntfs_stream_name(fname)) {
539 END_PROFILE(SMBntcreateX);
540 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
544 we need to handle the case when we get a
545 relative open relative to a file and the
546 pathname is blank - this is a reopen!
547 (hint from demyn plantenberg)
550 END_PROFILE(SMBntcreateX);
551 return(ERROR_DOS(ERRDOS,ERRbadfid));
555 * Copy in the base directory name.
558 pstrcpy( fname, dir_fsp->fsp_name );
559 dir_name_len = strlen(fname);
562 * Ensure it ends in a '\'.
565 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
570 srvstr_get_path(inbuf, rel_fname, smb_buf(inbuf), sizeof(rel_fname), 0, STR_TERMINATE, &status);
571 if (!NT_STATUS_IS_OK(status)) {
572 END_PROFILE(SMBntcreateX);
573 return ERROR_NT(status);
575 pstrcat(fname, rel_fname);
577 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
578 if (!NT_STATUS_IS_OK(status)) {
579 END_PROFILE(SMBntcreateX);
580 return ERROR_NT(status);
584 * Check to see if this is a mac fork of some kind.
587 if( is_ntfs_stream_name(fname)) {
588 enum FAKE_FILE_TYPE fake_file_type = is_fake_file(fname);
589 if (fake_file_type!=FAKE_FILE_TYPE_NONE) {
591 * Here we go! support for changing the disk quotas --metze
593 * We need to fake up to open this MAGIC QUOTA file
594 * and return a valid FID.
596 * w2k close this file directly after openening
597 * xp also tries a QUERY_FILE_INFO on the file and then close it
599 result = reply_ntcreate_and_X_quota(conn, inbuf, outbuf, length, bufsize,
600 fake_file_type, fname);
601 END_PROFILE(SMBntcreateX);
604 END_PROFILE(SMBntcreateX);
605 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
611 * Now contruct the smb_open_mode value from the filename,
612 * desired access and the share access.
614 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
616 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
617 if (oplock_request) {
618 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
622 * Ordinary file or directory.
626 * Check if POSIX semantics are wanted.
629 set_posix_case_semantics(conn, file_attributes);
631 unix_convert(fname,conn,0,&bad_path,&sbuf);
634 restore_case_semantics(conn, file_attributes);
635 END_PROFILE(SMBntcreateX);
636 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
638 /* All file access must go through check_name() */
639 if (!check_name(fname,conn)) {
640 restore_case_semantics(conn, file_attributes);
641 END_PROFILE(SMBntcreateX);
642 return UNIXERROR(ERRDOS, ERRbadpath);
646 /* This is the correct thing to do (check every time) but can_delete is
647 expensive (it may have to read the parent directory permissions). So
648 for now we're not doing it unless we have a strong hint the client
649 is really going to delete this file. */
650 if ((desired_access & DELETE_ACCESS)
651 && !can_delete_file_in_directory(conn, fname)) {
653 /* Setting FILE_SHARE_DELETE is the hint. */
654 if (lp_acl_check_permissions(SNUM(conn))
655 && (share_access & FILE_SHARE_DELETE)
656 && (access_mask & DELETE_ACCESS)
657 && !can_delete_file_in_directory(conn, fname)) {
659 restore_case_semantics(conn, file_attributes);
660 END_PROFILE(SMBntcreateX);
661 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
665 * If it's a request for a directory open, deal with it separately.
668 if(create_options & FILE_DIRECTORY_FILE) {
671 /* Can't open a temp directory. IFS kit test. */
672 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
673 END_PROFILE(SMBntcreateX);
674 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
677 status = open_directory(conn, fname, &sbuf,
684 restore_case_semantics(conn, file_attributes);
686 if(!NT_STATUS_IS_OK(status)) {
687 if (!use_nt_status() && NT_STATUS_EQUAL(
688 status, NT_STATUS_OBJECT_NAME_COLLISION)) {
689 status = NT_STATUS_DOS(ERRDOS, ERRfilexists);
691 END_PROFILE(SMBntcreateX);
692 return ERROR_NT(status);
696 * Ordinary file case.
699 /* NB. We have a potential bug here. If we
700 * cause an oplock break to ourselves, then we
701 * could end up processing filename related
702 * SMB requests whilst we await the oplock
703 * break response. As we may have changed the
704 * filename case semantics to be POSIX-like,
705 * this could mean a filename request could
706 * fail when it should succeed. This is a rare
707 * condition, but eventually we must arrange
708 * to restore the correct case semantics
709 * before issuing an oplock break request to
710 * our client. JRA. */
712 status = open_file_ntcreate(conn,fname,&sbuf,
720 if (!NT_STATUS_IS_OK(status)) {
721 /* We cheat here. There are two cases we
722 * care about. One is a directory rename,
723 * where the NT client will attempt to
724 * open the source directory for
725 * DELETE access. Note that when the
726 * NT client does this it does *not*
727 * set the directory bit in the
728 * request packet. This is translated
729 * into a read/write open
730 * request. POSIX states that any open
731 * for write request on a directory
732 * will generate an EISDIR error, so
733 * we can catch this here and open a
734 * pseudo handle that is flagged as a
735 * directory. The second is an open
736 * for a permissions read only, which
737 * we handle in the open_file_stat case. JRA.
740 if (NT_STATUS_EQUAL(status,
741 NT_STATUS_FILE_IS_A_DIRECTORY)) {
744 * Fail the open if it was explicitly a non-directory file.
747 if (create_options & FILE_NON_DIRECTORY_FILE) {
748 restore_case_semantics(conn, file_attributes);
749 END_PROFILE(SMBntcreateX);
750 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
754 status = open_directory(conn, fname, &sbuf,
761 if(!NT_STATUS_IS_OK(status)) {
762 restore_case_semantics(conn, file_attributes);
763 if (!use_nt_status() && NT_STATUS_EQUAL(
764 status, NT_STATUS_OBJECT_NAME_COLLISION)) {
765 status = NT_STATUS_DOS(ERRDOS, ERRfilexists);
767 END_PROFILE(SMBntcreateX);
768 return ERROR_NT(status);
772 restore_case_semantics(conn, file_attributes);
773 END_PROFILE(SMBntcreateX);
774 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
775 /* We have re-scheduled this call. */
778 return ERROR_NT(status);
783 restore_case_semantics(conn, file_attributes);
785 file_len = sbuf.st_size;
786 fattr = dos_mode(conn,fname,&sbuf);
788 fattr = FILE_ATTRIBUTE_NORMAL;
790 if (!fsp->is_directory && (fattr & aDIR)) {
791 close_file(fsp,ERROR_CLOSE);
792 END_PROFILE(SMBntcreateX);
793 return ERROR_DOS(ERRDOS,ERRnoaccess);
796 /* Save the requested allocation size. */
797 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
798 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
799 #ifdef LARGE_SMB_OFF_T
800 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
802 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
803 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
804 if (fsp->is_directory) {
805 close_file(fsp,ERROR_CLOSE);
806 END_PROFILE(SMBntcreateX);
807 /* Can't set allocation size on a directory. */
808 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
810 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
811 close_file(fsp,ERROR_CLOSE);
812 END_PROFILE(SMBntcreateX);
813 return ERROR_NT(NT_STATUS_DISK_FULL);
816 fsp->initial_allocation_size = smb_roundup(fsp->conn,(SMB_BIG_UINT)file_len);
821 * If the caller set the extended oplock request bit
822 * and we granted one (by whatever means) - set the
823 * correct bit for extended oplock reply.
826 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
827 extended_oplock_granted = True;
830 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
831 extended_oplock_granted = True;
835 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
836 set_message(outbuf,42,0,True);
838 set_message(outbuf,34,0,True);
841 p = outbuf + smb_vwv2;
844 * Currently as we don't support level II oplocks we just report
845 * exclusive & batch here.
848 if (extended_oplock_granted) {
849 if (flags & REQUEST_BATCH_OPLOCK) {
850 SCVAL(p,0, BATCH_OPLOCK_RETURN);
852 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
854 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
855 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
857 SCVAL(p,0,NO_OPLOCK_RETURN);
861 SSVAL(p,0,fsp->fnum);
863 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
864 SIVAL(p,0,FILE_WAS_SUPERSEDED);
871 c_timespec = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
872 a_timespec = get_atimespec(&sbuf);
873 m_timespec = get_mtimespec(&sbuf);
875 if (lp_dos_filetime_resolution(SNUM(conn))) {
876 dos_filetime_timespec(&c_timespec);
877 dos_filetime_timespec(&a_timespec);
878 dos_filetime_timespec(&m_timespec);
881 put_long_date_timespec(p, c_timespec);
883 put_long_date_timespec(p, a_timespec); /* access time */
885 put_long_date_timespec(p, m_timespec); /* write time */
887 put_long_date_timespec(p, m_timespec); /* change time */
889 SIVAL(p,0,fattr); /* File Attributes. */
891 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
893 SOFF_T(p,0,file_len);
895 if (flags & EXTENDED_RESPONSE_REQUIRED) {
899 SCVAL(p,0,fsp->is_directory ? 1 : 0);
901 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
903 result = chain_reply(inbuf,outbuf,length,bufsize);
904 END_PROFILE(SMBntcreateX);
908 /****************************************************************************
909 Reply to a NT_TRANSACT_CREATE call to open a pipe.
910 ****************************************************************************/
912 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
913 uint16 **ppsetup, uint32 setup_count,
914 char **ppparams, uint32 parameter_count,
915 char **ppdata, uint32 data_count)
918 char *params = *ppparams;
925 * Ensure minimum number of parameters sent.
928 if(parameter_count < 54) {
929 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
930 return ERROR_DOS(ERRDOS,ERRnoaccess);
933 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
934 if (!NT_STATUS_IS_OK(status)) {
935 return ERROR_NT(status);
938 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
942 /* Realloc the size of parameters and data we will return */
943 params = nttrans_realloc(ppparams, 69);
945 return ERROR_DOS(ERRDOS,ERRnomem);
949 SCVAL(p,0,NO_OPLOCK_RETURN);
954 SIVAL(p,0,FILE_WAS_OPENED);
958 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
961 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
963 SSVAL(p,2, 0x5FF); /* ? */
965 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
967 /* Send the required number of replies */
968 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
973 /****************************************************************************
974 Internal fn to set security descriptors.
975 ****************************************************************************/
977 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
980 SEC_DESC *psd = NULL;
984 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
989 * Init the parse struct we will unmarshall from.
992 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
993 DEBUG(0,("set_sd: talloc_init failed.\n"));
994 return NT_STATUS_NO_MEMORY;
997 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1000 * Setup the prs_struct to point at the memory we just
1004 prs_give_memory( &pd, data, sd_len, False);
1007 * Finally, unmarshall from the data buffer.
1010 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1011 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1013 * Return access denied for want of a better error message..
1015 talloc_destroy(mem_ctx);
1016 return NT_STATUS_NO_MEMORY;
1019 if (psd->owner_sid==0) {
1020 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1022 if (psd->group_sid==0) {
1023 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1026 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1029 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1032 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fh->fd, security_info_sent, psd);
1035 talloc_destroy(mem_ctx);
1036 return NT_STATUS_ACCESS_DENIED;
1039 talloc_destroy(mem_ctx);
1041 return NT_STATUS_OK;
1044 /****************************************************************************
1045 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1046 ****************************************************************************/
1048 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
1050 struct ea_list *ea_list_head = NULL;
1053 if (data_size < 4) {
1057 while (offset + 4 <= data_size) {
1058 size_t next_offset = IVAL(pdata,offset);
1059 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
1065 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
1066 if (next_offset == 0) {
1069 offset += next_offset;
1072 return ea_list_head;
1075 /****************************************************************************
1076 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1077 ****************************************************************************/
1079 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1080 uint16 **ppsetup, uint32 setup_count,
1081 char **ppparams, uint32 parameter_count,
1082 char **ppdata, uint32 data_count, uint32 max_data_count)
1085 char *params = *ppparams;
1086 char *data = *ppdata;
1087 /* Breakout the oplock request bits so we can set the reply bits separately. */
1088 int oplock_request = 0;
1090 SMB_OFF_T file_len = 0;
1091 SMB_STRUCT_STAT sbuf;
1093 BOOL bad_path = False;
1094 files_struct *fsp = NULL;
1096 BOOL extended_oplock_granted = False;
1099 uint32 file_attributes;
1100 uint32 share_access;
1101 uint32 create_disposition;
1102 uint32 create_options;
1105 uint16 root_dir_fid;
1106 struct timespec c_timespec;
1107 struct timespec a_timespec;
1108 struct timespec m_timespec;
1109 struct ea_list *ea_list = NULL;
1110 TALLOC_CTX *ctx = NULL;
1114 DEBUG(5,("call_nt_transact_create\n"));
1117 * If it's an IPC, use the pipe handler.
1121 if (lp_nt_pipe_support()) {
1122 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1124 ppsetup, setup_count,
1125 ppparams, parameter_count,
1126 ppdata, data_count);
1128 return ERROR_DOS(ERRDOS,ERRnoaccess);
1133 * Ensure minimum number of parameters sent.
1136 if(parameter_count < 54) {
1137 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1138 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1141 flags = IVAL(params,0);
1142 access_mask = IVAL(params,8);
1143 file_attributes = IVAL(params,20);
1144 share_access = IVAL(params,24);
1145 create_disposition = IVAL(params,28);
1146 create_options = IVAL(params,32);
1147 sd_len = IVAL(params,36);
1148 ea_len = IVAL(params,40);
1149 root_dir_fid = (uint16)IVAL(params,4);
1151 /* Ensure the data_len is correct for the sd and ea values given. */
1152 if ((ea_len + sd_len > data_count) ||
1153 (ea_len > data_count) || (sd_len > data_count) ||
1154 (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
1155 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1156 (unsigned int)ea_len, (unsigned int)sd_len, (unsigned int)data_count ));
1157 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1161 if (!lp_ea_support(SNUM(conn))) {
1162 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1163 (unsigned int)ea_len ));
1164 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
1168 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1169 (unsigned int)ea_len ));
1170 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1174 if (create_options & FILE_OPEN_BY_FILE_ID) {
1175 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1179 * Get the file name.
1182 if(root_dir_fid != 0) {
1184 * This filename is relative to a directory fid.
1186 files_struct *dir_fsp = file_fsp(params,4);
1187 size_t dir_name_len;
1190 return ERROR_DOS(ERRDOS,ERRbadfid);
1193 if(!dir_fsp->is_directory) {
1194 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1195 if (!NT_STATUS_IS_OK(status)) {
1196 return ERROR_NT(status);
1200 * Check to see if this is a mac fork of some kind.
1203 if( is_ntfs_stream_name(fname)) {
1204 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1207 return ERROR_DOS(ERRDOS,ERRbadfid);
1211 * Copy in the base directory name.
1214 pstrcpy( fname, dir_fsp->fsp_name );
1215 dir_name_len = strlen(fname);
1218 * Ensure it ends in a '\'.
1221 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1222 pstrcat(fname, "/");
1228 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status);
1229 if (!NT_STATUS_IS_OK(status)) {
1230 return ERROR_NT(status);
1232 pstrcat(fname, tmpname);
1235 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1236 if (!NT_STATUS_IS_OK(status)) {
1237 return ERROR_NT(status);
1241 * Check to see if this is a mac fork of some kind.
1244 if( is_ntfs_stream_name(fname)) {
1245 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1249 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1250 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1253 * Check if POSIX semantics are wanted.
1256 set_posix_case_semantics(conn, file_attributes);
1258 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1260 unix_convert(fname,conn,0,&bad_path,&sbuf);
1262 restore_case_semantics(conn, file_attributes);
1263 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1265 /* All file access must go through check_name() */
1266 if (!check_name(fname,conn)) {
1267 restore_case_semantics(conn, file_attributes);
1268 return UNIXERROR(ERRDOS, ERRbadpath);
1272 /* This is the correct thing to do (check every time) but can_delete is
1273 expensive (it may have to read the parent directory permissions). So
1274 for now we're not doing it unless we have a strong hint the client
1275 is really going to delete this file. */
1276 if ((desired_access & DELETE_ACCESS)
1277 && !can_delete_file_in_directory(conn, fname)) {
1279 /* Setting FILE_SHARE_DELETE is the hint. */
1280 if (lp_acl_check_permissions(SNUM(conn))
1281 && (share_access & FILE_SHARE_DELETE)
1282 && (access_mask & DELETE_ACCESS)
1283 && !can_delete_file_in_directory(conn, fname)) {
1285 restore_case_semantics(conn, file_attributes);
1286 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1290 pdata = data + sd_len;
1292 /* We have already checked that ea_len <= data_count here. */
1293 ea_list = read_nttrans_ea_list(tmp_talloc_ctx(), pdata,
1296 restore_case_semantics(conn, file_attributes);
1297 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1302 * If it's a request for a directory open, deal with it separately.
1305 if(create_options & FILE_DIRECTORY_FILE) {
1307 /* Can't open a temp directory. IFS kit test. */
1308 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1309 restore_case_semantics(conn, file_attributes);
1310 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1316 * We will get a create directory here if the Win32
1317 * app specified a security descriptor in the
1318 * CreateDirectory() call.
1321 status = open_directory(conn, fname, &sbuf,
1327 if(!NT_STATUS_IS_OK(status)) {
1328 restore_case_semantics(conn, file_attributes);
1329 return ERROR_NT(status);
1335 * Ordinary file case.
1338 status = open_file_ntcreate(conn,fname,&sbuf,
1347 if (!NT_STATUS_IS_OK(status)) {
1348 if (NT_STATUS_EQUAL(status,
1349 NT_STATUS_FILE_IS_A_DIRECTORY)) {
1352 * Fail the open if it was explicitly a non-directory file.
1355 if (create_options & FILE_NON_DIRECTORY_FILE) {
1356 restore_case_semantics(conn, file_attributes);
1357 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1361 status = open_directory(conn, fname, &sbuf,
1367 if(!NT_STATUS_IS_OK(status)) {
1368 restore_case_semantics(conn, file_attributes);
1369 return ERROR_NT(status);
1372 restore_case_semantics(conn, file_attributes);
1373 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1374 /* We have re-scheduled this call. */
1377 return ERROR_NT(status);
1383 * According to the MS documentation, the only time the security
1384 * descriptor is applied to the opened file is iff we *created* the
1385 * file; an existing file stays the same.
1387 * Also, it seems (from observation) that you can open the file with
1388 * any access mask but you can still write the sd. We need to override
1389 * the granted access before we call set_sd
1390 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1393 if (lp_nt_acl_support(SNUM(conn)) && sd_len && info == FILE_WAS_CREATED) {
1394 uint32 saved_access_mask = fsp->access_mask;
1396 /* We have already checked that sd_len <= data_count here. */
1398 fsp->access_mask = FILE_GENERIC_ALL;
1400 status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION);
1401 if (!NT_STATUS_IS_OK(status)) {
1402 talloc_destroy(ctx);
1403 close_file(fsp,ERROR_CLOSE);
1404 restore_case_semantics(conn, file_attributes);
1405 return ERROR_NT(status);
1407 fsp->access_mask = saved_access_mask;
1410 if (ea_len && (info == FILE_WAS_CREATED)) {
1411 status = set_ea(conn, fsp, fname, ea_list);
1412 if (!NT_STATUS_IS_OK(status)) {
1413 close_file(fsp,ERROR_CLOSE);
1414 restore_case_semantics(conn, file_attributes);
1415 return ERROR_NT(status);
1419 restore_case_semantics(conn, file_attributes);
1421 file_len = sbuf.st_size;
1422 fattr = dos_mode(conn,fname,&sbuf);
1424 fattr = FILE_ATTRIBUTE_NORMAL;
1426 if (!fsp->is_directory && (fattr & aDIR)) {
1427 close_file(fsp,ERROR_CLOSE);
1428 return ERROR_DOS(ERRDOS,ERRnoaccess);
1431 /* Save the requested allocation size. */
1432 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
1433 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1434 #ifdef LARGE_SMB_OFF_T
1435 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1437 if (allocation_size && (allocation_size > file_len)) {
1438 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
1439 if (fsp->is_directory) {
1440 close_file(fsp,ERROR_CLOSE);
1441 /* Can't set allocation size on a directory. */
1442 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1444 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1445 close_file(fsp,ERROR_CLOSE);
1446 return ERROR_NT(NT_STATUS_DISK_FULL);
1449 fsp->initial_allocation_size = smb_roundup(fsp->conn, (SMB_BIG_UINT)file_len);
1454 * If the caller set the extended oplock request bit
1455 * and we granted one (by whatever means) - set the
1456 * correct bit for extended oplock reply.
1459 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
1460 extended_oplock_granted = True;
1463 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
1464 extended_oplock_granted = True;
1467 /* Realloc the size of parameters and data we will return */
1468 params = nttrans_realloc(ppparams, 69);
1469 if(params == NULL) {
1470 return ERROR_DOS(ERRDOS,ERRnomem);
1474 if (extended_oplock_granted) {
1475 if (flags & REQUEST_BATCH_OPLOCK) {
1476 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1478 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
1480 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1481 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1483 SCVAL(p,0,NO_OPLOCK_RETURN);
1487 SSVAL(p,0,fsp->fnum);
1489 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
1490 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1497 c_timespec = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1498 a_timespec = get_atimespec(&sbuf);
1499 m_timespec = get_mtimespec(&sbuf);
1501 if (lp_dos_filetime_resolution(SNUM(conn))) {
1502 dos_filetime_timespec(&c_timespec);
1503 dos_filetime_timespec(&a_timespec);
1504 dos_filetime_timespec(&m_timespec);
1507 put_long_date_timespec(p, c_timespec); /* create time. */
1509 put_long_date_timespec(p, a_timespec); /* access time */
1511 put_long_date_timespec(p, m_timespec); /* write time */
1513 put_long_date_timespec(p, m_timespec); /* change time */
1515 SIVAL(p,0,fattr); /* File Attributes. */
1517 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1519 SOFF_T(p,0,file_len);
1521 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1525 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1527 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1529 /* Send the required number of replies */
1530 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1535 /****************************************************************************
1536 Reply to a NT CANCEL request.
1537 conn POINTER CAN BE NULL HERE !
1538 ****************************************************************************/
1540 int reply_ntcancel(connection_struct *conn,
1541 char *inbuf,char *outbuf,int length,int bufsize)
1544 * Go through and cancel any pending change notifies.
1547 int mid = SVAL(inbuf,smb_mid);
1548 START_PROFILE(SMBntcancel);
1549 remove_pending_change_notify_requests_by_mid(mid);
1550 remove_pending_lock_requests_by_mid(mid);
1551 srv_cancel_sign_response(mid);
1553 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1555 END_PROFILE(SMBntcancel);
1559 /****************************************************************************
1561 ****************************************************************************/
1563 static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *newname, uint32 attrs)
1565 BOOL bad_path_oldname = False;
1566 BOOL bad_path_newname = False;
1567 SMB_STRUCT_STAT sbuf1, sbuf2;
1568 pstring last_component_oldname;
1569 pstring last_component_newname;
1570 files_struct *fsp1,*fsp2;
1575 NTSTATUS status = NT_STATUS_OK;
1581 if (ms_has_wild(newname) || ms_has_wild(oldname)) {
1582 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1585 if (!CAN_WRITE(conn))
1586 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1588 unix_convert(oldname,conn,last_component_oldname,&bad_path_oldname,&sbuf1);
1589 if (bad_path_oldname) {
1590 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1593 /* Quick check for "." and ".." */
1594 if (last_component_oldname[0] == '.') {
1595 if (!last_component_oldname[1] || (last_component_oldname[1] == '.' && !last_component_oldname[2])) {
1596 return NT_STATUS_OBJECT_NAME_INVALID;
1600 /* Source must already exist. */
1601 if (!VALID_STAT(sbuf1)) {
1602 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1604 if (!check_name(oldname,conn)) {
1605 return NT_STATUS_ACCESS_DENIED;
1608 /* Ensure attributes match. */
1609 fattr = dos_mode(conn,oldname,&sbuf1);
1610 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1611 return NT_STATUS_NO_SUCH_FILE;
1614 unix_convert(newname,conn,last_component_newname,&bad_path_newname,&sbuf2);
1615 if (bad_path_newname) {
1616 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1619 /* Quick check for "." and ".." */
1620 if (last_component_newname[0] == '.') {
1621 if (!last_component_newname[1] || (last_component_newname[1] == '.' && !last_component_newname[2])) {
1622 return NT_STATUS_OBJECT_NAME_INVALID;
1626 /* Disallow if newname already exists. */
1627 if (VALID_STAT(sbuf2)) {
1628 return NT_STATUS_OBJECT_NAME_COLLISION;
1631 if (!check_name(newname,conn)) {
1632 return NT_STATUS_ACCESS_DENIED;
1635 /* No links from a directory. */
1636 if (S_ISDIR(sbuf1.st_mode)) {
1637 return NT_STATUS_FILE_IS_A_DIRECTORY;
1640 /* Ensure this is within the share. */
1641 if (!reduce_name(conn, oldname) != 0) {
1642 return NT_STATUS_ACCESS_DENIED;
1645 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname, newname));
1647 status = open_file_ntcreate(conn,oldname,&sbuf1,
1648 FILE_READ_DATA, /* Read-only. */
1649 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1651 0, /* No create options. */
1652 FILE_ATTRIBUTE_NORMAL,
1656 if (!NT_STATUS_IS_OK(status)) {
1660 status = open_file_ntcreate(conn,newname,&sbuf2,
1661 FILE_WRITE_DATA, /* Read-only. */
1662 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1664 0, /* No create options. */
1669 if (!NT_STATUS_IS_OK(status)) {
1670 close_file(fsp1,ERROR_CLOSE);
1674 if (sbuf1.st_size) {
1675 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1679 * As we are opening fsp1 read-only we only expect
1680 * an error on close on fsp2 if we are out of space.
1681 * Thus we don't look at the error return from the
1684 close_file(fsp1,NORMAL_CLOSE);
1686 /* Ensure the modtime is set correctly on the destination file. */
1687 fsp_set_pending_modtime(fsp2, sbuf1.st_mtime);
1689 close_ret = close_file(fsp2,NORMAL_CLOSE);
1691 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1692 creates the file. This isn't the correct thing to do in the copy
1694 file_set_dosmode(conn, newname, fattr, &sbuf2,
1695 parent_dirname(newname));
1697 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1698 return NT_STATUS_DISK_FULL;
1701 if (close_ret != 0) {
1702 status = map_nt_error_from_unix(close_ret);
1703 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1704 nt_errstr(status), oldname, newname));
1709 /****************************************************************************
1710 Reply to a NT rename request.
1711 ****************************************************************************/
1713 int reply_ntrename(connection_struct *conn,
1714 char *inbuf,char *outbuf,int length,int bufsize)
1721 BOOL path1_contains_wcard = False;
1722 BOOL path2_contains_wcard = False;
1723 uint32 attrs = SVAL(inbuf,smb_vwv0);
1724 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1726 START_PROFILE(SMBntrename);
1728 p = smb_buf(inbuf) + 1;
1729 p += srvstr_get_path_wcard(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, &path1_contains_wcard);
1730 if (!NT_STATUS_IS_OK(status)) {
1731 END_PROFILE(SMBntrename);
1732 return ERROR_NT(status);
1735 if( is_ntfs_stream_name(oldname)) {
1736 /* Can't rename a stream. */
1737 END_PROFILE(SMBntrename);
1738 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1741 if (ms_has_wild(oldname)) {
1742 END_PROFILE(SMBntrename);
1743 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1747 p += srvstr_get_path_wcard(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status, &path2_contains_wcard);
1748 if (!NT_STATUS_IS_OK(status)) {
1749 END_PROFILE(SMBntrename);
1750 return ERROR_NT(status);
1753 RESOLVE_DFSPATH(oldname, conn, inbuf, outbuf);
1754 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1756 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1758 switch(rename_type) {
1759 case RENAME_FLAG_RENAME:
1760 status = rename_internals(conn, oldname, newname, attrs, False, path1_contains_wcard);
1762 case RENAME_FLAG_HARD_LINK:
1763 if (path1_contains_wcard || path2_contains_wcard) {
1765 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1767 status = hardlink_internals(conn, oldname, newname);
1770 case RENAME_FLAG_COPY:
1771 if (path1_contains_wcard || path2_contains_wcard) {
1773 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1775 status = copy_internals(conn, oldname, newname, attrs);
1778 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1779 status = NT_STATUS_INVALID_PARAMETER;
1782 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1786 if (!NT_STATUS_IS_OK(status)) {
1787 END_PROFILE(SMBntrename);
1788 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1789 /* We have re-scheduled this call. */
1792 return ERROR_NT(status);
1796 * Win2k needs a changenotify request response before it will
1797 * update after a rename..
1799 process_pending_change_notify_queue((time_t)0);
1800 outsize = set_message(outbuf,0,0,False);
1802 END_PROFILE(SMBntrename);
1806 /****************************************************************************
1807 Reply to a notify change - queue the request and
1808 don't allow a directory to be opened.
1809 ****************************************************************************/
1811 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf,
1812 char *outbuf, int length,
1814 uint16 **ppsetup, uint32 setup_count,
1816 uint32 parameter_count,
1817 char **ppdata, uint32 data_count,
1818 uint32 max_data_count,
1819 uint32 max_param_count)
1821 uint16 *setup = *ppsetup;
1826 if(setup_count < 6) {
1827 return ERROR_DOS(ERRDOS,ERRbadfunc);
1830 fsp = file_fsp((char *)setup,4);
1831 filter = IVAL(setup, 0);
1833 DEBUG(3,("call_nt_transact_notify_change\n"));
1836 return ERROR_DOS(ERRDOS,ERRbadfid);
1839 DEBUG(3,("call_nt_transact_notify_change: notify change called on "
1840 "directory name = %s\n", fsp->fsp_name ));
1842 if((!fsp->is_directory) || (conn != fsp->conn)) {
1843 return ERROR_DOS(ERRDOS,ERRbadfid);
1846 if (fsp->notify == NULL) {
1847 if (!(fsp->notify = TALLOC_ZERO_P(
1848 NULL, struct notify_change_buf))) {
1849 return ERROR_NT(NT_STATUS_NO_MEMORY);
1853 if (fsp->notify->num_changes > 0) {
1856 * We've got changes pending, respond immediately
1860 * TODO: write a torture test to check the filtering behaviour
1864 SMB_ASSERT(fsp->notify->requests == NULL);
1866 change_notify_reply(inbuf, max_param_count,
1867 fsp->notify->num_changes,
1868 fsp->notify->changes);
1870 TALLOC_FREE(fsp->notify->changes);
1871 fsp->notify->num_changes = 0;
1874 * change_notify_reply() above has independently sent its
1881 * No changes pending, queue the request
1884 status = change_notify_add_request(inbuf, max_param_count, filter,
1886 if (!NT_STATUS_IS_OK(status)) {
1887 return ERROR_NT(status);
1893 /****************************************************************************
1894 Reply to an NT transact rename command.
1895 ****************************************************************************/
1897 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1898 uint16 **ppsetup, uint32 setup_count,
1899 char **ppparams, uint32 parameter_count,
1900 char **ppdata, uint32 data_count, uint32 max_data_count)
1902 char *params = *ppparams;
1904 files_struct *fsp = NULL;
1905 BOOL replace_if_exists = False;
1906 BOOL path_contains_wcard = False;
1909 if(parameter_count < 5) {
1910 return ERROR_DOS(ERRDOS,ERRbadfunc);
1913 fsp = file_fsp(params, 0);
1914 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1915 CHECK_FSP(fsp, conn);
1916 srvstr_get_path_wcard(inbuf, new_name, params+4, sizeof(new_name), parameter_count - 4, STR_TERMINATE, &status, &path_contains_wcard);
1917 if (!NT_STATUS_IS_OK(status)) {
1918 return ERROR_NT(status);
1921 status = rename_internals(conn, fsp->fsp_name,
1922 new_name, 0, replace_if_exists, path_contains_wcard);
1923 if (!NT_STATUS_IS_OK(status))
1924 return ERROR_NT(status);
1927 * Rename was successful.
1929 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1931 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1932 fsp->fsp_name, new_name));
1935 * Win2k needs a changenotify request response before it will
1936 * update after a rename..
1939 process_pending_change_notify_queue((time_t)0);
1944 /******************************************************************************
1945 Fake up a completely empty SD.
1946 *******************************************************************************/
1948 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1952 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1954 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1961 /****************************************************************************
1962 Reply to query a security descriptor.
1963 ****************************************************************************/
1965 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1966 uint16 **ppsetup, uint32 setup_count,
1967 char **ppparams, uint32 parameter_count,
1968 char **ppdata, uint32 data_count, uint32 max_data_count)
1970 char *params = *ppparams;
1971 char *data = *ppdata;
1973 SEC_DESC *psd = NULL;
1975 uint32 security_info_wanted;
1976 TALLOC_CTX *mem_ctx;
1977 files_struct *fsp = NULL;
1979 if(parameter_count < 8) {
1980 return ERROR_DOS(ERRDOS,ERRbadfunc);
1983 fsp = file_fsp(params,0);
1985 return ERROR_DOS(ERRDOS,ERRbadfid);
1988 security_info_wanted = IVAL(params,4);
1990 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1991 (unsigned int)security_info_wanted ));
1993 params = nttrans_realloc(ppparams, 4);
1994 if(params == NULL) {
1995 return ERROR_DOS(ERRDOS,ERRnomem);
1998 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1999 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
2000 return ERROR_DOS(ERRDOS,ERRnomem);
2004 * Get the permissions to return.
2007 if (!lp_nt_acl_support(SNUM(conn))) {
2008 sd_size = get_null_nt_acl(mem_ctx, &psd);
2010 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fh->fd, security_info_wanted, &psd);
2014 talloc_destroy(mem_ctx);
2015 return(UNIXERROR(ERRDOS,ERRnoaccess));
2018 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
2020 SIVAL(params,0,(uint32)sd_size);
2022 if(max_data_count < sd_size) {
2024 send_nt_replies(outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
2025 params, 4, *ppdata, 0);
2026 talloc_destroy(mem_ctx);
2031 * Allocate the data we will point this at.
2034 data = nttrans_realloc(ppdata, sd_size);
2036 talloc_destroy(mem_ctx);
2037 return ERROR_DOS(ERRDOS,ERRnomem);
2041 * Init the parse struct we will marshall into.
2044 prs_init(&pd, 0, mem_ctx, MARSHALL);
2047 * Setup the prs_struct to point at the memory we just
2051 prs_give_memory( &pd, data, (uint32)sd_size, False);
2054 * Finally, linearize into the outgoing buffer.
2057 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2058 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2059 security descriptor.\n"));
2061 * Return access denied for want of a better error message..
2063 talloc_destroy(mem_ctx);
2064 return(UNIXERROR(ERRDOS,ERRnoaccess));
2068 * Now we can delete the security descriptor.
2071 talloc_destroy(mem_ctx);
2073 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 4, data,
2078 /****************************************************************************
2079 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2080 ****************************************************************************/
2082 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2083 uint16 **ppsetup, uint32 setup_count,
2084 char **ppparams, uint32 parameter_count,
2085 char **ppdata, uint32 data_count, uint32 max_data_count)
2087 char *params= *ppparams;
2088 char *data = *ppdata;
2089 files_struct *fsp = NULL;
2090 uint32 security_info_sent = 0;
2093 if(parameter_count < 8) {
2094 return ERROR_DOS(ERRDOS,ERRbadfunc);
2097 if((fsp = file_fsp(params,0)) == NULL) {
2098 return ERROR_DOS(ERRDOS,ERRbadfid);
2101 if(!lp_nt_acl_support(SNUM(conn))) {
2105 security_info_sent = IVAL(params,4);
2107 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
2108 (unsigned int)security_info_sent ));
2110 if (data_count == 0) {
2111 return ERROR_DOS(ERRDOS, ERRnoaccess);
2114 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent))) {
2115 return ERROR_NT(nt_status);
2120 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2124 /****************************************************************************
2126 ****************************************************************************/
2128 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2129 uint16 **ppsetup, uint32 setup_count,
2130 char **ppparams, uint32 parameter_count,
2131 char **ppdata, uint32 data_count, uint32 max_data_count)
2138 static BOOL logged_message;
2139 char *pdata = *ppdata;
2141 if (setup_count != 8) {
2142 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2143 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2146 function = IVAL(*ppsetup, 0);
2147 fidnum = SVAL(*ppsetup, 4);
2148 isFSctl = CVAL(*ppsetup, 6);
2149 compfilter = CVAL(*ppsetup, 7);
2151 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2152 function, fidnum, isFSctl, compfilter));
2154 fsp=file_fsp((char *)*ppsetup, 4);
2155 /* this check is done in each implemented function case for now
2156 because I don't want to break anything... --metze
2157 FSP_BELONGS_CONN(fsp,conn);*/
2160 case FSCTL_SET_SPARSE:
2161 /* pretend this succeeded - tho strictly we should
2162 mark the file sparse (if the local fs supports it)
2163 so we can know if we need to pre-allocate or not */
2165 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2166 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL,
2170 case FSCTL_0x000900C0:
2171 /* pretend this succeeded - don't know what this really is
2172 but works ok like this --metze
2175 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2176 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL,
2180 case FSCTL_GET_REPARSE_POINT:
2181 /* pretend this fail - my winXP does it like this
2185 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2186 send_nt_replies(outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT,
2190 case FSCTL_SET_REPARSE_POINT:
2191 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2195 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2196 send_nt_replies(outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT,
2200 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
2203 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2204 * and return their volume names. If max_data_count is 16, then it is just
2205 * asking for the number of volumes and length of the combined names.
2207 * pdata is the data allocated by our caller, but that uses
2208 * total_data_count (which is 0 in our case) rather than max_data_count.
2209 * Allocate the correct amount and return the pointer to let
2210 * it be deallocated when we return.
2212 SHADOW_COPY_DATA *shadow_data = NULL;
2213 TALLOC_CTX *shadow_mem_ctx = NULL;
2214 BOOL labels = False;
2215 uint32 labels_data_count = 0;
2219 FSP_BELONGS_CONN(fsp,conn);
2221 if (max_data_count < 16) {
2222 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2224 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2227 if (max_data_count > 16) {
2231 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2232 if (shadow_mem_ctx == NULL) {
2233 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2234 return ERROR_NT(NT_STATUS_NO_MEMORY);
2237 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2238 if (shadow_data == NULL) {
2239 DEBUG(0,("talloc_zero() failed!\n"));
2240 talloc_destroy(shadow_mem_ctx);
2241 return ERROR_NT(NT_STATUS_NO_MEMORY);
2244 shadow_data->mem_ctx = shadow_mem_ctx;
2247 * Call the VFS routine to actually do the work.
2249 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2250 talloc_destroy(shadow_data->mem_ctx);
2251 if (errno == ENOSYS) {
2252 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2253 conn->connectpath));
2254 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2256 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2257 conn->connectpath));
2258 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
2262 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2267 data_count = 12+labels_data_count+4;
2270 if (max_data_count<data_count) {
2271 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2272 max_data_count,data_count));
2273 talloc_destroy(shadow_data->mem_ctx);
2274 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
2277 pdata = nttrans_realloc(ppdata, data_count);
2278 if (pdata == NULL) {
2279 talloc_destroy(shadow_data->mem_ctx);
2280 return ERROR_NT(NT_STATUS_NO_MEMORY);
2285 /* num_volumes 4 bytes */
2286 SIVAL(pdata,0,shadow_data->num_volumes);
2289 /* num_labels 4 bytes */
2290 SIVAL(pdata,4,shadow_data->num_volumes);
2293 /* needed_data_count 4 bytes */
2294 SIVAL(pdata,8,labels_data_count);
2298 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2299 shadow_data->num_volumes,fsp->fsp_name));
2300 if (labels && shadow_data->labels) {
2301 for (i=0;i<shadow_data->num_volumes;i++) {
2302 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2303 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2304 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2308 talloc_destroy(shadow_data->mem_ctx);
2310 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0,
2316 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2318 /* pretend this succeeded -
2320 * we have to send back a list with all files owned by this SID
2322 * but I have to check that --metze
2326 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2328 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2330 FSP_BELONGS_CONN(fsp,conn);
2332 /* unknown 4 bytes: this is not the length of the sid :-( */
2333 /*unknown = IVAL(pdata,0);*/
2335 sid_parse(pdata+4,sid_len,&sid);
2336 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2338 if (!sid_to_uid(&sid, &uid)) {
2339 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2340 sid_string_static(&sid),(unsigned long)sid_len));
2344 /* we can take a look at the find source :-)
2346 * find ./ -uid $uid -name '*' is what we need here
2349 * and send 4bytes len and then NULL terminated unicode strings
2352 * but I don't know how to deal with the paged results
2353 * (maybe we can hang the result anywhere in the fsp struct)
2355 * we don't send all files at once
2356 * and at the next we should *not* start from the beginning,
2357 * so we have to cache the result
2362 /* this works for now... */
2363 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0,
2368 if (!logged_message) {
2369 logged_message = True; /* Only print this once... */
2370 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2375 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2379 #ifdef HAVE_SYS_QUOTAS
2380 /****************************************************************************
2381 Reply to get user quota
2382 ****************************************************************************/
2384 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2385 uint16 **ppsetup, uint32 setup_count,
2386 char **ppparams, uint32 parameter_count,
2387 char **ppdata, uint32 data_count, uint32 max_data_count)
2389 NTSTATUS nt_status = NT_STATUS_OK;
2390 char *params = *ppparams;
2391 char *pdata = *ppdata;
2393 int data_len=0,param_len=0;
2396 files_struct *fsp = NULL;
2400 BOOL start_enum = True;
2401 SMB_NTQUOTA_STRUCT qt;
2402 SMB_NTQUOTA_LIST *tmp_list;
2403 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2408 if (current_user.ut.uid != 0) {
2409 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2410 lp_servicename(SNUM(conn)),conn->user));
2411 return ERROR_DOS(ERRDOS,ERRnoaccess);
2415 * Ensure minimum number of parameters sent.
2418 if (parameter_count < 4) {
2419 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2420 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2423 /* maybe we can check the quota_fnum */
2424 fsp = file_fsp(params,0);
2425 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2426 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2427 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2430 /* the NULL pointer checking for fsp->fake_file_handle->pd
2431 * is done by CHECK_NTQUOTA_HANDLE_OK()
2433 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2435 level = SVAL(params,2);
2437 /* unknown 12 bytes leading in params */
2440 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2441 /* seems that we should continue with the enum here --metze */
2443 if (qt_handle->quota_list!=NULL &&
2444 qt_handle->tmp_list==NULL) {
2447 free_ntquota_list(&(qt_handle->quota_list));
2449 /* Realloc the size of parameters and data we will return */
2451 params = nttrans_realloc(ppparams, param_len);
2452 if(params == NULL) {
2453 return ERROR_DOS(ERRDOS,ERRnomem);
2457 SIVAL(params,0,data_len);
2464 case TRANSACT_GET_USER_QUOTA_LIST_START:
2466 if (qt_handle->quota_list==NULL &&
2467 qt_handle->tmp_list==NULL) {
2471 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2472 return ERROR_DOS(ERRSRV,ERRerror);
2474 /* Realloc the size of parameters and data we will return */
2476 params = nttrans_realloc(ppparams, param_len);
2477 if(params == NULL) {
2478 return ERROR_DOS(ERRDOS,ERRnomem);
2481 /* we should not trust the value in max_data_count*/
2482 max_data_count = MIN(max_data_count,2048);
2484 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2486 return ERROR_DOS(ERRDOS,ERRnomem);
2491 /* set params Size of returned Quota Data 4 bytes*/
2492 /* but set it later when we know it */
2494 /* for each entry push the data */
2497 qt_handle->tmp_list = qt_handle->quota_list;
2500 tmp_list = qt_handle->tmp_list;
2502 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2503 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2505 sid_len = sid_size(&tmp_list->quotas->sid);
2506 entry_len = 40 + sid_len;
2508 /* nextoffset entry 4 bytes */
2509 SIVAL(entry,0,entry_len);
2511 /* then the len of the SID 4 bytes */
2512 SIVAL(entry,4,sid_len);
2514 /* unknown data 8 bytes SMB_BIG_UINT */
2515 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2517 /* the used disk space 8 bytes SMB_BIG_UINT */
2518 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2520 /* the soft quotas 8 bytes SMB_BIG_UINT */
2521 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2523 /* the hard quotas 8 bytes SMB_BIG_UINT */
2524 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2526 /* and now the SID */
2527 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2530 qt_handle->tmp_list = tmp_list;
2532 /* overwrite the offset of the last entry */
2533 SIVAL(entry-entry_len,0,0);
2535 data_len = 4+qt_len;
2536 /* overwrite the params quota_data_len */
2537 SIVAL(params,0,data_len);
2541 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2543 /* unknown 4 bytes IVAL(pdata,0) */
2545 if (data_count < 8) {
2546 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2547 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2550 sid_len = IVAL(pdata,4);
2551 /* Ensure this is less than 1mb. */
2552 if (sid_len > (1024*1024)) {
2553 return ERROR_DOS(ERRDOS,ERRnomem);
2556 if (data_count < 8+sid_len) {
2557 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2558 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2561 data_len = 4+40+sid_len;
2563 if (max_data_count < data_len) {
2564 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2565 max_data_count, data_len));
2567 SIVAL(params,0,data_len);
2569 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2573 sid_parse(pdata+8,sid_len,&sid);
2575 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2578 * we have to return zero's in all fields
2579 * instead of returning an error here
2584 /* Realloc the size of parameters and data we will return */
2586 params = nttrans_realloc(ppparams, param_len);
2587 if(params == NULL) {
2588 return ERROR_DOS(ERRDOS,ERRnomem);
2591 pdata = nttrans_realloc(ppdata, data_len);
2593 return ERROR_DOS(ERRDOS,ERRnomem);
2598 /* set params Size of returned Quota Data 4 bytes*/
2599 SIVAL(params,0,data_len);
2601 /* nextoffset entry 4 bytes */
2604 /* then the len of the SID 4 bytes */
2605 SIVAL(entry,4,sid_len);
2607 /* unknown data 8 bytes SMB_BIG_UINT */
2608 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2610 /* the used disk space 8 bytes SMB_BIG_UINT */
2611 SBIG_UINT(entry,16,qt.usedspace);
2613 /* the soft quotas 8 bytes SMB_BIG_UINT */
2614 SBIG_UINT(entry,24,qt.softlim);
2616 /* the hard quotas 8 bytes SMB_BIG_UINT */
2617 SBIG_UINT(entry,32,qt.hardlim);
2619 /* and now the SID */
2620 sid_linearize(entry+40, sid_len, &sid);
2625 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2626 return ERROR_DOS(ERRSRV,ERRerror);
2630 send_nt_replies(outbuf, bufsize, nt_status, params, param_len,
2636 /****************************************************************************
2637 Reply to set user quota
2638 ****************************************************************************/
2640 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2641 uint16 **ppsetup, uint32 setup_count,
2642 char **ppparams, uint32 parameter_count,
2643 char **ppdata, uint32 data_count, uint32 max_data_count)
2645 char *params = *ppparams;
2646 char *pdata = *ppdata;
2647 int data_len=0,param_len=0;
2648 SMB_NTQUOTA_STRUCT qt;
2651 files_struct *fsp = NULL;
2656 if (current_user.ut.uid != 0) {
2657 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2658 lp_servicename(SNUM(conn)),conn->user));
2659 return ERROR_DOS(ERRDOS,ERRnoaccess);
2663 * Ensure minimum number of parameters sent.
2666 if (parameter_count < 2) {
2667 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2668 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2671 /* maybe we can check the quota_fnum */
2672 fsp = file_fsp(params,0);
2673 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2674 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2675 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2678 if (data_count < 40) {
2679 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2680 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2683 /* offset to next quota record.
2684 * 4 bytes IVAL(pdata,0)
2689 sid_len = IVAL(pdata,4);
2691 if (data_count < 40+sid_len) {
2692 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2693 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2696 /* unknown 8 bytes in pdata
2697 * maybe its the change time in NTTIME
2700 /* the used space 8 bytes (SMB_BIG_UINT)*/
2701 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2702 #ifdef LARGE_SMB_OFF_T
2703 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2704 #else /* LARGE_SMB_OFF_T */
2705 if ((IVAL(pdata,20) != 0)&&
2706 ((qt.usedspace != 0xFFFFFFFF)||
2707 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2708 /* more than 32 bits? */
2709 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2711 #endif /* LARGE_SMB_OFF_T */
2713 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2714 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2715 #ifdef LARGE_SMB_OFF_T
2716 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2717 #else /* LARGE_SMB_OFF_T */
2718 if ((IVAL(pdata,28) != 0)&&
2719 ((qt.softlim != 0xFFFFFFFF)||
2720 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2721 /* more than 32 bits? */
2722 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2724 #endif /* LARGE_SMB_OFF_T */
2726 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2727 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2728 #ifdef LARGE_SMB_OFF_T
2729 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2730 #else /* LARGE_SMB_OFF_T */
2731 if ((IVAL(pdata,36) != 0)&&
2732 ((qt.hardlim != 0xFFFFFFFF)||
2733 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2734 /* more than 32 bits? */
2735 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2737 #endif /* LARGE_SMB_OFF_T */
2739 sid_parse(pdata+40,sid_len,&sid);
2740 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2742 /* 44 unknown bytes left... */
2744 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2745 return ERROR_DOS(ERRSRV,ERRerror);
2748 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, param_len,
2753 #endif /* HAVE_SYS_QUOTAS */
2755 static int handle_nttrans(connection_struct *conn,
2756 struct trans_state *state,
2757 char *inbuf, char *outbuf, int size, int bufsize)
2761 if (Protocol >= PROTOCOL_NT1) {
2762 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | 0x40); /* IS_LONG_NAME */
2765 /* Now we must call the relevant NT_TRANS function */
2766 switch(state->call) {
2767 case NT_TRANSACT_CREATE:
2769 START_PROFILE_NESTED(NT_transact_create);
2770 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2772 &state->setup, state->setup_count,
2773 &state->param, state->total_param,
2774 &state->data, state->total_data,
2775 state->max_data_return);
2776 END_PROFILE_NESTED(NT_transact_create);
2780 case NT_TRANSACT_IOCTL:
2782 START_PROFILE_NESTED(NT_transact_ioctl);
2783 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2785 &state->setup, state->setup_count,
2786 &state->param, state->total_param,
2787 &state->data, state->total_data, state->max_data_return);
2788 END_PROFILE_NESTED(NT_transact_ioctl);
2792 case NT_TRANSACT_SET_SECURITY_DESC:
2794 START_PROFILE_NESTED(NT_transact_set_security_desc);
2795 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2797 &state->setup, state->setup_count,
2798 &state->param, state->total_param,
2799 &state->data, state->total_data, state->max_data_return);
2800 END_PROFILE_NESTED(NT_transact_set_security_desc);
2804 case NT_TRANSACT_NOTIFY_CHANGE:
2806 START_PROFILE_NESTED(NT_transact_notify_change);
2807 outsize = call_nt_transact_notify_change(
2808 conn, inbuf, outbuf, size, bufsize,
2809 &state->setup, state->setup_count,
2810 &state->param, state->total_param,
2811 &state->data, state->total_data,
2812 state->max_data_return,
2813 state->max_param_return);
2814 END_PROFILE_NESTED(NT_transact_notify_change);
2818 case NT_TRANSACT_RENAME:
2820 START_PROFILE_NESTED(NT_transact_rename);
2821 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2823 &state->setup, state->setup_count,
2824 &state->param, state->total_param,
2825 &state->data, state->total_data, state->max_data_return);
2826 END_PROFILE_NESTED(NT_transact_rename);
2830 case NT_TRANSACT_QUERY_SECURITY_DESC:
2832 START_PROFILE_NESTED(NT_transact_query_security_desc);
2833 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
2835 &state->setup, state->setup_count,
2836 &state->param, state->total_param,
2837 &state->data, state->total_data, state->max_data_return);
2838 END_PROFILE_NESTED(NT_transact_query_security_desc);
2842 #ifdef HAVE_SYS_QUOTAS
2843 case NT_TRANSACT_GET_USER_QUOTA:
2845 START_PROFILE_NESTED(NT_transact_get_user_quota);
2846 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
2848 &state->setup, state->setup_count,
2849 &state->param, state->total_param,
2850 &state->data, state->total_data, state->max_data_return);
2851 END_PROFILE_NESTED(NT_transact_get_user_quota);
2855 case NT_TRANSACT_SET_USER_QUOTA:
2857 START_PROFILE_NESTED(NT_transact_set_user_quota);
2858 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
2860 &state->setup, state->setup_count,
2861 &state->param, state->total_param,
2862 &state->data, state->total_data, state->max_data_return);
2863 END_PROFILE_NESTED(NT_transact_set_user_quota);
2866 #endif /* HAVE_SYS_QUOTAS */
2869 /* Error in request */
2870 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n",
2872 return ERROR_DOS(ERRSRV,ERRerror);
2877 /****************************************************************************
2878 Reply to a SMBNTtrans.
2879 ****************************************************************************/
2881 int reply_nttrans(connection_struct *conn,
2882 char *inbuf,char *outbuf,int size,int bufsize)
2885 uint32 pscnt = IVAL(inbuf,smb_nt_ParameterCount);
2886 uint32 psoff = IVAL(inbuf,smb_nt_ParameterOffset);
2887 uint32 dscnt = IVAL(inbuf,smb_nt_DataCount);
2888 uint32 dsoff = IVAL(inbuf,smb_nt_DataOffset);
2890 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2892 struct trans_state *state;
2894 START_PROFILE(SMBnttrans);
2896 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2897 END_PROFILE(SMBnttrans);
2898 return ERROR_DOS(ERRSRV,ERRaccess);
2901 result = allow_new_trans(conn->pending_trans, SVAL(inbuf, smb_mid));
2902 if (!NT_STATUS_IS_OK(result)) {
2903 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2904 END_PROFILE(SMBnttrans);
2905 return ERROR_NT(result);
2908 if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
2909 END_PROFILE(SMBnttrans);
2910 return ERROR_DOS(ERRSRV,ERRaccess);
2913 state->cmd = SMBnttrans;
2915 state->mid = SVAL(inbuf,smb_mid);
2916 state->vuid = SVAL(inbuf,smb_uid);
2917 state->total_data = IVAL(inbuf, smb_nt_TotalDataCount);
2919 state->total_param = IVAL(inbuf, smb_nt_TotalParameterCount);
2920 state->param = NULL;
2921 state->max_data_return = IVAL(inbuf,smb_nt_MaxDataCount);
2922 state->max_param_return = IVAL(inbuf,smb_nt_MaxParameterCount);
2924 /* setup count is in *words* */
2925 state->setup_count = 2*CVAL(inbuf,smb_nt_SetupCount);
2926 state->setup = NULL;
2927 state->call = function_code;
2930 * All nttrans messages we handle have smb_wct == 19 +
2931 * state->setup_count. Ensure this is so as a sanity check.
2934 if(CVAL(inbuf, smb_wct) != 19 + (state->setup_count/2)) {
2935 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2936 CVAL(inbuf, smb_wct), 19 + (state->setup_count/2)));
2940 /* Don't allow more than 128mb for each value. */
2941 if ((state->total_data > (1024*1024*128)) ||
2942 (state->total_param > (1024*1024*128))) {
2943 END_PROFILE(SMBnttrans);
2944 return ERROR_DOS(ERRDOS,ERRnomem);
2947 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2950 if (state->total_data) {
2951 /* Can't use talloc here, the core routines do realloc on the
2952 * params and data. */
2953 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2954 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2955 "bytes !\n", (unsigned int)state->total_data));
2957 END_PROFILE(SMBnttrans);
2958 return(ERROR_DOS(ERRDOS,ERRnomem));
2960 if ((dsoff+dscnt < dsoff) || (dsoff+dscnt < dscnt))
2962 if ((smb_base(inbuf)+dsoff+dscnt > inbuf + size) ||
2963 (smb_base(inbuf)+dsoff+dscnt < smb_base(inbuf)))
2966 memcpy(state->data,smb_base(inbuf)+dsoff,dscnt);
2969 if (state->total_param) {
2970 /* Can't use talloc here, the core routines do realloc on the
2971 * params and data. */
2972 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2973 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2974 "bytes !\n", (unsigned int)state->total_param));
2975 SAFE_FREE(state->data);
2977 END_PROFILE(SMBnttrans);
2978 return(ERROR_DOS(ERRDOS,ERRnomem));
2980 if ((psoff+pscnt < psoff) || (psoff+pscnt < pscnt))
2982 if ((smb_base(inbuf)+psoff+pscnt > inbuf + size) ||
2983 (smb_base(inbuf)+psoff+pscnt < smb_base(inbuf)))
2986 memcpy(state->param,smb_base(inbuf)+psoff,pscnt);
2989 state->received_data = dscnt;
2990 state->received_param = pscnt;
2992 if(state->setup_count > 0) {
2993 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2994 state->setup_count));
2995 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2996 if (state->setup == NULL) {
2997 DEBUG(0,("reply_nttrans : Out of memory\n"));
2998 SAFE_FREE(state->data);
2999 SAFE_FREE(state->param);
3001 END_PROFILE(SMBnttrans);
3002 return ERROR_DOS(ERRDOS,ERRnomem);
3005 if ((smb_nt_SetupStart + state->setup_count < smb_nt_SetupStart) ||
3006 (smb_nt_SetupStart + state->setup_count < state->setup_count)) {
3009 if (smb_nt_SetupStart + state->setup_count > size) {
3013 memcpy( state->setup, &inbuf[smb_nt_SetupStart], state->setup_count);
3014 dump_data(10, (char *)state->setup, state->setup_count);
3017 if ((state->received_data == state->total_data) &&
3018 (state->received_param == state->total_param)) {
3019 outsize = handle_nttrans(conn, state, inbuf, outbuf,
3021 SAFE_FREE(state->param);
3022 SAFE_FREE(state->data);
3024 END_PROFILE(SMBnttrans);
3028 DLIST_ADD(conn->pending_trans, state);
3030 /* We need to send an interim response then receive the rest
3031 of the parameter/data bytes */
3032 outsize = set_message(outbuf,0,0,False);
3034 END_PROFILE(SMBnttrans);
3039 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3040 SAFE_FREE(state->data);
3041 SAFE_FREE(state->param);
3043 END_PROFILE(SMBnttrans);
3044 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
3047 /****************************************************************************
3048 Reply to a SMBnttranss
3049 ****************************************************************************/
3051 int reply_nttranss(connection_struct *conn, char *inbuf,char *outbuf,
3052 int size,int bufsize)
3055 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
3056 struct trans_state *state;
3058 START_PROFILE(SMBnttranss);
3062 for (state = conn->pending_trans; state != NULL;
3063 state = state->next) {
3064 if (state->mid == SVAL(inbuf,smb_mid)) {
3069 if ((state == NULL) || (state->cmd != SMBnttrans)) {
3070 END_PROFILE(SMBnttranss);
3071 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
3074 /* Revise state->total_param and state->total_data in case they have
3075 changed downwards */
3076 if (IVAL(inbuf, smb_nts_TotalParameterCount) < state->total_param) {
3077 state->total_param = IVAL(inbuf, smb_nts_TotalParameterCount);
3079 if (IVAL(inbuf, smb_nts_TotalDataCount) < state->total_data) {
3080 state->total_data = IVAL(inbuf, smb_nts_TotalDataCount);
3083 pcnt = IVAL(inbuf,smb_nts_ParameterCount);
3084 poff = IVAL(inbuf, smb_nts_ParameterOffset);
3085 pdisp = IVAL(inbuf, smb_nts_ParameterDisplacement);
3087 dcnt = IVAL(inbuf, smb_nts_DataCount);
3088 ddisp = IVAL(inbuf, smb_nts_DataDisplacement);
3089 doff = IVAL(inbuf, smb_nts_DataOffset);
3091 state->received_param += pcnt;
3092 state->received_data += dcnt;
3094 if ((state->received_data > state->total_data) ||
3095 (state->received_param > state->total_param))
3099 if (pdisp+pcnt > state->total_param)
3101 if ((pdisp+pcnt < pdisp) || (pdisp+pcnt < pcnt))
3103 if (pdisp > state->total_param)
3105 if ((smb_base(inbuf) + poff + pcnt > inbuf + size) ||
3106 (smb_base(inbuf) + poff + pcnt < smb_base(inbuf)))
3108 if (state->param + pdisp < state->param)
3111 memcpy(state->param+pdisp,smb_base(inbuf)+poff,
3116 if (ddisp+dcnt > state->total_data)
3118 if ((ddisp+dcnt < ddisp) || (ddisp+dcnt < dcnt))
3120 if (ddisp > state->total_data)
3122 if ((smb_base(inbuf) + doff + dcnt > inbuf + size) ||
3123 (smb_base(inbuf) + doff + dcnt < smb_base(inbuf)))
3125 if (state->data + ddisp < state->data)
3128 memcpy(state->data+ddisp, smb_base(inbuf)+doff,
3132 if ((state->received_param < state->total_param) ||
3133 (state->received_data < state->total_data)) {
3134 END_PROFILE(SMBnttranss);
3138 /* construct_reply_common has done us the favor to pre-fill the
3139 * command field with SMBnttranss which is wrong :-)
3141 SCVAL(outbuf,smb_com,SMBnttrans);
3143 outsize = handle_nttrans(conn, state, inbuf, outbuf,
3146 DLIST_REMOVE(conn->pending_trans, state);
3147 SAFE_FREE(state->data);
3148 SAFE_FREE(state->param);
3152 END_PROFILE(SMBnttranss);
3153 return(ERROR_DOS(ERRSRV,ERRnosupport));
3156 END_PROFILE(SMBnttranss);
3161 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3162 DLIST_REMOVE(conn->pending_trans, state);
3163 SAFE_FREE(state->data);
3164 SAFE_FREE(state->param);
3166 END_PROFILE(SMBnttranss);
3167 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);