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 static int send_nt_replies(char *outbuf, int bufsize, NTSTATUS nt_error,
72 char *params, int paramsize, char *pdata,
75 int data_to_send = datasize;
76 int params_to_send = paramsize;
80 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
81 int alignment_offset = 3;
82 int data_alignment_offset = 0;
85 * Initially set the wcnt area to be 18 - this is true for all
89 set_message(outbuf,18,0,True);
91 if (NT_STATUS_V(nt_error)) {
96 * If there genuinely are no parameters or data to send just send
100 if(params_to_send == 0 && data_to_send == 0) {
102 if (!send_smb(smbd_server_fd(),outbuf)) {
103 exit_server("send_nt_replies: send_smb failed.");
109 * When sending params and data ensure that both are nicely aligned.
110 * Only do this alignment when there is also data to send - else
111 * can cause NT redirector problems.
114 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
115 data_alignment_offset = 4 - (params_to_send % 4);
119 * Space is bufsize minus Netbios over TCP header minus SMB header.
120 * The alignment_offset is to align the param bytes on a four byte
121 * boundary (2 bytes for data len, one byte pad).
122 * NT needs this to work correctly.
125 useable_space = bufsize - ((smb_buf(outbuf)+
126 alignment_offset+data_alignment_offset) -
130 * useable_space can never be more than max_send minus the
134 useable_space = MIN(useable_space,
135 max_send - (alignment_offset+data_alignment_offset));
138 while (params_to_send || data_to_send) {
141 * Calculate whether we will totally or partially fill this packet.
144 total_sent_thistime = params_to_send + data_to_send +
145 alignment_offset + data_alignment_offset;
148 * We can never send more than useable_space.
151 total_sent_thistime = MIN(total_sent_thistime, useable_space);
153 set_message(outbuf, 18, total_sent_thistime, True);
156 * Set total params and data to be sent.
159 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
160 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
163 * Calculate how many parameters and data we can fit into
164 * this packet. Parameters get precedence.
167 params_sent_thistime = MIN(params_to_send,useable_space);
168 data_sent_thistime = useable_space - params_sent_thistime;
169 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
171 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
173 if(params_sent_thistime == 0) {
174 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
175 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
178 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
179 * parameter bytes, however the first 4 bytes of outbuf are
180 * the Netbios over TCP header. Thus use smb_base() to subtract
181 * them from the calculation.
184 SIVAL(outbuf,smb_ntr_ParameterOffset,
185 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
187 * Absolute displacement of param bytes sent in this packet.
190 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
194 * Deal with the data portion.
197 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
199 if(data_sent_thistime == 0) {
200 SIVAL(outbuf,smb_ntr_DataOffset,0);
201 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
204 * The offset of the data bytes is the offset of the
205 * parameter bytes plus the number of parameters being sent this time.
208 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
209 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
210 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
214 * Copy the param bytes into the packet.
217 if(params_sent_thistime) {
218 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
222 * Copy in the data bytes
225 if(data_sent_thistime) {
226 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
227 data_alignment_offset,pd,data_sent_thistime);
230 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
231 params_sent_thistime, data_sent_thistime, useable_space));
232 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
233 params_to_send, data_to_send, paramsize, datasize));
235 /* Send the packet */
237 if (!send_smb(smbd_server_fd(),outbuf)) {
238 exit_server("send_nt_replies: send_smb failed.");
241 pp += params_sent_thistime;
242 pd += data_sent_thistime;
244 params_to_send -= params_sent_thistime;
245 data_to_send -= data_sent_thistime;
251 if(params_to_send < 0 || data_to_send < 0) {
252 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
253 params_to_send, data_to_send));
261 /****************************************************************************
262 Is it an NTFS stream name ?
263 ****************************************************************************/
265 BOOL is_ntfs_stream_name(const char *fname)
267 if (lp_posix_pathnames()) {
270 return (strchr_m(fname, ':') != NULL) ? True : False;
273 /****************************************************************************
275 ****************************************************************************/
277 static BOOL saved_case_sensitive;
278 static BOOL saved_case_preserve;
279 static BOOL saved_short_case_preserve;
281 /****************************************************************************
283 ****************************************************************************/
285 static void set_posix_case_semantics(connection_struct *conn, uint32 file_attributes)
287 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
291 saved_case_sensitive = conn->case_sensitive;
292 saved_case_preserve = conn->case_preserve;
293 saved_short_case_preserve = conn->short_case_preserve;
296 conn->case_sensitive = True;
297 conn->case_preserve = True;
298 conn->short_case_preserve = True;
301 /****************************************************************************
302 Restore case semantics.
303 ****************************************************************************/
305 static void restore_case_semantics(connection_struct *conn, uint32 file_attributes)
307 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
311 conn->case_sensitive = saved_case_sensitive;
312 conn->case_preserve = saved_case_preserve;
313 conn->short_case_preserve = saved_short_case_preserve;
316 /****************************************************************************
317 Reply to an NT create and X call on a pipe.
318 ****************************************************************************/
320 static int nt_open_pipe(char *fname, connection_struct *conn,
321 char *inbuf, char *outbuf, int *ppnum)
323 smb_np_struct *p = NULL;
324 uint16 vuid = SVAL(inbuf, smb_uid);
327 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
329 /* See if it is one we want to handle. */
331 if (lp_disable_spoolss() && strequal(fname, "\\spoolss")) {
332 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
335 for( i = 0; known_nt_pipes[i]; i++ ) {
336 if( strequal(fname,known_nt_pipes[i])) {
341 if ( known_nt_pipes[i] == NULL ) {
342 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
345 /* Strip \\ off the name. */
348 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
350 p = open_rpc_pipe_p(fname, conn, vuid);
352 return(ERROR_DOS(ERRSRV,ERRnofids));
355 /* TODO: Add pipe to db */
357 if ( !store_pipe_opendb( p ) ) {
358 DEBUG(3,("nt_open_pipe: failed to store %s pipe open.\n", fname));
365 /****************************************************************************
366 Reply to an NT create and X call for pipes.
367 ****************************************************************************/
369 static int do_ntcreate_pipe_open(connection_struct *conn,
370 char *inbuf,char *outbuf,int length,int bufsize)
377 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
379 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
384 * Deal with pipe return.
387 set_message(outbuf,34,0,True);
389 p = outbuf + smb_vwv2;
393 SIVAL(p,0,FILE_WAS_OPENED);
396 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
399 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
401 SSVAL(p,2, 0x5FF); /* ? */
403 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
405 return chain_reply(inbuf,outbuf,length,bufsize);
408 /****************************************************************************
409 Reply to an NT create and X call for a quota file.
410 ****************************************************************************/
412 int reply_ntcreate_and_X_quota(connection_struct *conn,
417 enum FAKE_FILE_TYPE fake_file_type,
422 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
426 status = open_fake_file(conn, fake_file_type, fname, desired_access,
429 if (!NT_STATUS_IS_OK(status)) {
430 return ERROR_NT(status);
433 set_message(outbuf,34,0,True);
435 p = outbuf + smb_vwv2;
437 /* SCVAL(p,0,NO_OPLOCK_RETURN); */
439 SSVAL(p,0,fsp->fnum);
441 DEBUG(5,("reply_ntcreate_and_X_quota: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
443 result = chain_reply(inbuf,outbuf,length,bufsize);
447 /****************************************************************************
448 Reply to an NT create and X call.
449 ****************************************************************************/
451 int reply_ntcreate_and_X(connection_struct *conn,
452 char *inbuf,char *outbuf,int length,int bufsize)
456 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
457 uint32 access_mask = IVAL(inbuf,smb_ntcreate_DesiredAccess);
458 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
459 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
460 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
461 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
462 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
463 /* Breakout the oplock request bits so we can set the
464 reply bits separately. */
465 int oplock_request = 0;
467 SMB_OFF_T file_len = 0;
468 SMB_STRUCT_STAT sbuf;
470 BOOL bad_path = False;
471 files_struct *fsp=NULL;
473 struct timespec c_timespec;
474 struct timespec a_timespec;
475 struct timespec m_timespec;
476 BOOL extended_oplock_granted = False;
479 START_PROFILE(SMBntcreateX);
481 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
482 "file_attributes = 0x%x, share_access = 0x%x, "
483 "create_disposition = 0x%x create_options = 0x%x "
484 "root_dir_fid = 0x%x\n",
486 (unsigned int)access_mask,
487 (unsigned int)file_attributes,
488 (unsigned int)share_access,
489 (unsigned int)create_disposition,
490 (unsigned int)create_options,
491 (unsigned int)root_dir_fid ));
493 /* If it's an IPC, use the pipe handler. */
496 if (lp_nt_pipe_support()) {
497 END_PROFILE(SMBntcreateX);
498 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
500 END_PROFILE(SMBntcreateX);
501 return(ERROR_DOS(ERRDOS,ERRnoaccess));
505 if (create_options & FILE_OPEN_BY_FILE_ID) {
506 END_PROFILE(SMBntcreateX);
507 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
514 if(root_dir_fid != 0) {
516 * This filename is relative to a directory fid.
519 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
523 END_PROFILE(SMBntcreateX);
524 return(ERROR_DOS(ERRDOS,ERRbadfid));
527 if(!dir_fsp->is_directory) {
529 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
530 if (!NT_STATUS_IS_OK(status)) {
531 END_PROFILE(SMBntcreateX);
532 return ERROR_NT(status);
536 * Check to see if this is a mac fork of some kind.
539 if( is_ntfs_stream_name(fname)) {
540 END_PROFILE(SMBntcreateX);
541 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
545 we need to handle the case when we get a
546 relative open relative to a file and the
547 pathname is blank - this is a reopen!
548 (hint from demyn plantenberg)
551 END_PROFILE(SMBntcreateX);
552 return(ERROR_DOS(ERRDOS,ERRbadfid));
556 * Copy in the base directory name.
559 pstrcpy( fname, dir_fsp->fsp_name );
560 dir_name_len = strlen(fname);
563 * Ensure it ends in a '\'.
566 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
571 srvstr_get_path(inbuf, rel_fname, smb_buf(inbuf), sizeof(rel_fname), 0, STR_TERMINATE, &status);
572 if (!NT_STATUS_IS_OK(status)) {
573 END_PROFILE(SMBntcreateX);
574 return ERROR_NT(status);
576 pstrcat(fname, rel_fname);
578 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
579 if (!NT_STATUS_IS_OK(status)) {
580 END_PROFILE(SMBntcreateX);
581 return ERROR_NT(status);
585 * Check to see if this is a mac fork of some kind.
588 if( is_ntfs_stream_name(fname)) {
589 enum FAKE_FILE_TYPE fake_file_type = is_fake_file(fname);
590 if (fake_file_type!=FAKE_FILE_TYPE_NONE) {
592 * Here we go! support for changing the disk quotas --metze
594 * We need to fake up to open this MAGIC QUOTA file
595 * and return a valid FID.
597 * w2k close this file directly after openening
598 * xp also tries a QUERY_FILE_INFO on the file and then close it
600 result = reply_ntcreate_and_X_quota(conn, inbuf, outbuf, length, bufsize,
601 fake_file_type, fname);
602 END_PROFILE(SMBntcreateX);
605 END_PROFILE(SMBntcreateX);
606 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
612 * Now contruct the smb_open_mode value from the filename,
613 * desired access and the share access.
615 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
617 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
618 if (oplock_request) {
619 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
623 * Ordinary file or directory.
627 * Check if POSIX semantics are wanted.
630 set_posix_case_semantics(conn, file_attributes);
632 unix_convert(fname,conn,0,&bad_path,&sbuf);
635 restore_case_semantics(conn, file_attributes);
636 END_PROFILE(SMBntcreateX);
637 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
639 /* All file access must go through check_name() */
640 if (!check_name(fname,conn)) {
641 restore_case_semantics(conn, file_attributes);
642 END_PROFILE(SMBntcreateX);
643 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
647 /* This is the correct thing to do (check every time) but can_delete is
648 expensive (it may have to read the parent directory permissions). So
649 for now we're not doing it unless we have a strong hint the client
650 is really going to delete this file. */
651 if (desired_access & DELETE_ACCESS) {
653 /* Setting FILE_SHARE_DELETE is the hint. */
654 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE)
655 && (access_mask & DELETE_ACCESS)) {
657 status = can_delete(conn, fname, file_attributes, bad_path, True);
658 /* We're only going to fail here if it's access denied, as that's the
659 only error we care about for "can we delete this ?" questions. */
660 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
661 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
662 restore_case_semantics(conn, file_attributes);
663 END_PROFILE(SMBntcreateX);
664 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
669 * If it's a request for a directory open, deal with it separately.
672 if(create_options & FILE_DIRECTORY_FILE) {
675 /* Can't open a temp directory. IFS kit test. */
676 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
677 END_PROFILE(SMBntcreateX);
678 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
681 status = open_directory(conn, fname, &sbuf,
688 restore_case_semantics(conn, file_attributes);
690 if(!NT_STATUS_IS_OK(status)) {
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 END_PROFILE(SMBntcreateX);
764 return ERROR_NT(status);
768 restore_case_semantics(conn, file_attributes);
769 END_PROFILE(SMBntcreateX);
770 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
771 /* We have re-scheduled this call. */
774 return ERROR_NT(status);
779 restore_case_semantics(conn, file_attributes);
781 file_len = sbuf.st_size;
782 fattr = dos_mode(conn,fname,&sbuf);
784 fattr = FILE_ATTRIBUTE_NORMAL;
786 if (!fsp->is_directory && (fattr & aDIR)) {
787 close_file(fsp,ERROR_CLOSE);
788 END_PROFILE(SMBntcreateX);
789 return ERROR_DOS(ERRDOS,ERRnoaccess);
792 /* Save the requested allocation size. */
793 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
794 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
795 #ifdef LARGE_SMB_OFF_T
796 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
798 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
799 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
800 if (fsp->is_directory) {
801 close_file(fsp,ERROR_CLOSE);
802 END_PROFILE(SMBntcreateX);
803 /* Can't set allocation size on a directory. */
804 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
806 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
807 close_file(fsp,ERROR_CLOSE);
808 END_PROFILE(SMBntcreateX);
809 return ERROR_NT(NT_STATUS_DISK_FULL);
812 fsp->initial_allocation_size = smb_roundup(fsp->conn,(SMB_BIG_UINT)file_len);
817 * If the caller set the extended oplock request bit
818 * and we granted one (by whatever means) - set the
819 * correct bit for extended oplock reply.
822 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
823 extended_oplock_granted = True;
826 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
827 extended_oplock_granted = True;
831 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
832 set_message(outbuf,42,0,True);
834 set_message(outbuf,34,0,True);
837 p = outbuf + smb_vwv2;
840 * Currently as we don't support level II oplocks we just report
841 * exclusive & batch here.
844 if (extended_oplock_granted) {
845 if (flags & REQUEST_BATCH_OPLOCK) {
846 SCVAL(p,0, BATCH_OPLOCK_RETURN);
848 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
850 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
851 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
853 SCVAL(p,0,NO_OPLOCK_RETURN);
857 SSVAL(p,0,fsp->fnum);
859 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
860 SIVAL(p,0,FILE_WAS_SUPERSEDED);
867 c_timespec = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
868 a_timespec = get_atimespec(&sbuf);
869 m_timespec = get_mtimespec(&sbuf);
871 if (lp_dos_filetime_resolution(SNUM(conn))) {
872 dos_filetime_timespec(&c_timespec);
873 dos_filetime_timespec(&a_timespec);
874 dos_filetime_timespec(&m_timespec);
877 put_long_date_timespec(p, c_timespec);
879 put_long_date_timespec(p, a_timespec); /* access time */
881 put_long_date_timespec(p, m_timespec); /* write time */
883 put_long_date_timespec(p, m_timespec); /* change time */
885 SIVAL(p,0,fattr); /* File Attributes. */
887 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
889 SOFF_T(p,0,file_len);
891 if (flags & EXTENDED_RESPONSE_REQUIRED) {
895 SCVAL(p,0,fsp->is_directory ? 1 : 0);
897 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
899 result = chain_reply(inbuf,outbuf,length,bufsize);
900 END_PROFILE(SMBntcreateX);
904 /****************************************************************************
905 Reply to a NT_TRANSACT_CREATE call to open a pipe.
906 ****************************************************************************/
908 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
909 uint16 **ppsetup, uint32 setup_count,
910 char **ppparams, uint32 parameter_count,
911 char **ppdata, uint32 data_count)
914 char *params = *ppparams;
921 * Ensure minimum number of parameters sent.
924 if(parameter_count < 54) {
925 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
926 return ERROR_DOS(ERRDOS,ERRnoaccess);
929 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
930 if (!NT_STATUS_IS_OK(status)) {
931 return ERROR_NT(status);
934 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
938 /* Realloc the size of parameters and data we will return */
939 params = nttrans_realloc(ppparams, 69);
941 return ERROR_DOS(ERRDOS,ERRnomem);
945 SCVAL(p,0,NO_OPLOCK_RETURN);
950 SIVAL(p,0,FILE_WAS_OPENED);
954 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
957 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
959 SSVAL(p,2, 0x5FF); /* ? */
961 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
963 /* Send the required number of replies */
964 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
969 /****************************************************************************
970 Internal fn to set security descriptors.
971 ****************************************************************************/
973 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
976 SEC_DESC *psd = NULL;
980 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
985 * Init the parse struct we will unmarshall from.
988 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
989 DEBUG(0,("set_sd: talloc_init failed.\n"));
990 return NT_STATUS_NO_MEMORY;
993 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
996 * Setup the prs_struct to point at the memory we just
1000 prs_give_memory( &pd, data, sd_len, False);
1003 * Finally, unmarshall from the data buffer.
1006 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1007 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1009 * Return access denied for want of a better error message..
1011 talloc_destroy(mem_ctx);
1012 return NT_STATUS_NO_MEMORY;
1015 if (psd->owner_sid==0) {
1016 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1018 if (psd->group_sid==0) {
1019 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1022 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1025 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1028 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fh->fd, security_info_sent, psd);
1031 talloc_destroy(mem_ctx);
1032 return NT_STATUS_ACCESS_DENIED;
1035 talloc_destroy(mem_ctx);
1037 return NT_STATUS_OK;
1040 /****************************************************************************
1041 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1042 ****************************************************************************/
1044 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
1046 struct ea_list *ea_list_head = NULL;
1049 if (data_size < 4) {
1053 while (offset + 4 <= data_size) {
1054 size_t next_offset = IVAL(pdata,offset);
1055 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
1061 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
1062 if (next_offset == 0) {
1065 offset += next_offset;
1068 return ea_list_head;
1071 /****************************************************************************
1072 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1073 ****************************************************************************/
1075 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1076 uint16 **ppsetup, uint32 setup_count,
1077 char **ppparams, uint32 parameter_count,
1078 char **ppdata, uint32 data_count, uint32 max_data_count)
1081 char *params = *ppparams;
1082 char *data = *ppdata;
1083 /* Breakout the oplock request bits so we can set the reply bits separately. */
1084 int oplock_request = 0;
1086 SMB_OFF_T file_len = 0;
1087 SMB_STRUCT_STAT sbuf;
1089 BOOL bad_path = False;
1090 files_struct *fsp = NULL;
1092 BOOL extended_oplock_granted = False;
1095 uint32 file_attributes;
1096 uint32 share_access;
1097 uint32 create_disposition;
1098 uint32 create_options;
1101 uint16 root_dir_fid;
1102 struct timespec c_timespec;
1103 struct timespec a_timespec;
1104 struct timespec m_timespec;
1105 struct ea_list *ea_list = NULL;
1106 TALLOC_CTX *ctx = NULL;
1110 DEBUG(5,("call_nt_transact_create\n"));
1113 * If it's an IPC, use the pipe handler.
1117 if (lp_nt_pipe_support()) {
1118 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1120 ppsetup, setup_count,
1121 ppparams, parameter_count,
1122 ppdata, data_count);
1124 return ERROR_DOS(ERRDOS,ERRnoaccess);
1129 * Ensure minimum number of parameters sent.
1132 if(parameter_count < 54) {
1133 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1134 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1137 flags = IVAL(params,0);
1138 access_mask = IVAL(params,8);
1139 file_attributes = IVAL(params,20);
1140 share_access = IVAL(params,24);
1141 create_disposition = IVAL(params,28);
1142 create_options = IVAL(params,32);
1143 sd_len = IVAL(params,36);
1144 ea_len = IVAL(params,40);
1145 root_dir_fid = (uint16)IVAL(params,4);
1147 /* Ensure the data_len is correct for the sd and ea values given. */
1148 if ((ea_len + sd_len > data_count) ||
1149 (ea_len > data_count) || (sd_len > data_count) ||
1150 (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
1151 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1152 (unsigned int)ea_len, (unsigned int)sd_len, (unsigned int)data_count ));
1153 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1157 if (!lp_ea_support(SNUM(conn))) {
1158 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1159 (unsigned int)ea_len ));
1160 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
1164 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1165 (unsigned int)ea_len ));
1166 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1170 if (create_options & FILE_OPEN_BY_FILE_ID) {
1171 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1175 * Get the file name.
1178 if(root_dir_fid != 0) {
1180 * This filename is relative to a directory fid.
1182 files_struct *dir_fsp = file_fsp(params,4);
1183 size_t dir_name_len;
1186 return ERROR_DOS(ERRDOS,ERRbadfid);
1189 if(!dir_fsp->is_directory) {
1190 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1191 if (!NT_STATUS_IS_OK(status)) {
1192 return ERROR_NT(status);
1196 * Check to see if this is a mac fork of some kind.
1199 if( is_ntfs_stream_name(fname)) {
1200 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1203 return ERROR_DOS(ERRDOS,ERRbadfid);
1207 * Copy in the base directory name.
1210 pstrcpy( fname, dir_fsp->fsp_name );
1211 dir_name_len = strlen(fname);
1214 * Ensure it ends in a '\'.
1217 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1218 pstrcat(fname, "/");
1224 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status);
1225 if (!NT_STATUS_IS_OK(status)) {
1226 return ERROR_NT(status);
1228 pstrcat(fname, tmpname);
1231 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1232 if (!NT_STATUS_IS_OK(status)) {
1233 return ERROR_NT(status);
1237 * Check to see if this is a mac fork of some kind.
1240 if( is_ntfs_stream_name(fname)) {
1241 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1245 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1246 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1249 * Check if POSIX semantics are wanted.
1252 set_posix_case_semantics(conn, file_attributes);
1254 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1256 unix_convert(fname,conn,0,&bad_path,&sbuf);
1258 restore_case_semantics(conn, file_attributes);
1259 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1261 /* All file access must go through check_name() */
1262 if (!check_name(fname,conn)) {
1263 restore_case_semantics(conn, file_attributes);
1264 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
1268 /* This is the correct thing to do (check every time) but can_delete is
1269 expensive (it may have to read the parent directory permissions). So
1270 for now we're not doing it unless we have a strong hint the client
1271 is really going to delete this file. */
1272 if (desired_access & DELETE_ACCESS) {
1274 /* Setting FILE_SHARE_DELETE is the hint. */
1275 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE) && (access_mask & DELETE_ACCESS)) {
1277 status = can_delete(conn, fname, file_attributes, bad_path, True);
1278 /* We're only going to fail here if it's access denied, as that's the
1279 only error we care about for "can we delete this ?" questions. */
1280 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
1281 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
1282 restore_case_semantics(conn, file_attributes);
1283 return ERROR_NT(status);
1288 ctx = talloc_init("NTTRANS_CREATE_EA");
1290 talloc_destroy(ctx);
1291 restore_case_semantics(conn, file_attributes);
1292 return ERROR_NT(NT_STATUS_NO_MEMORY);
1295 pdata = data + sd_len;
1297 /* We have already checked that ea_len <= data_count here. */
1298 ea_list = read_nttrans_ea_list(ctx, pdata, ea_len);
1300 talloc_destroy(ctx);
1301 restore_case_semantics(conn, file_attributes);
1302 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1307 * If it's a request for a directory open, deal with it separately.
1310 if(create_options & FILE_DIRECTORY_FILE) {
1312 /* Can't open a temp directory. IFS kit test. */
1313 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1314 talloc_destroy(ctx);
1315 restore_case_semantics(conn, file_attributes);
1316 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1322 * We will get a create directory here if the Win32
1323 * app specified a security descriptor in the
1324 * CreateDirectory() call.
1327 status = open_directory(conn, fname, &sbuf,
1333 if(!NT_STATUS_IS_OK(status)) {
1334 talloc_destroy(ctx);
1335 restore_case_semantics(conn, file_attributes);
1336 return ERROR_NT(status);
1342 * Ordinary file case.
1345 status = open_file_ntcreate(conn,fname,&sbuf,
1354 if (!NT_STATUS_IS_OK(status)) {
1355 if (NT_STATUS_EQUAL(status,
1356 NT_STATUS_FILE_IS_A_DIRECTORY)) {
1359 * Fail the open if it was explicitly a non-directory file.
1362 if (create_options & FILE_NON_DIRECTORY_FILE) {
1363 restore_case_semantics(conn, file_attributes);
1364 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1368 status = open_directory(conn, fname, &sbuf,
1374 if(!NT_STATUS_IS_OK(status)) {
1375 talloc_destroy(ctx);
1376 restore_case_semantics(conn, file_attributes);
1377 return ERROR_NT(status);
1380 talloc_destroy(ctx);
1381 restore_case_semantics(conn, file_attributes);
1382 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1383 /* We have re-scheduled this call. */
1386 return ERROR_NT(status);
1392 * According to the MS documentation, the only time the security
1393 * descriptor is applied to the opened file is iff we *created* the
1394 * file; an existing file stays the same.
1396 * Also, it seems (from observation) that you can open the file with
1397 * any access mask but you can still write the sd. We need to override
1398 * the granted access before we call set_sd
1399 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1402 if (lp_nt_acl_support(SNUM(conn)) && sd_len && info == FILE_WAS_CREATED) {
1403 uint32 saved_access_mask = fsp->access_mask;
1405 /* We have already checked that sd_len <= data_count here. */
1407 fsp->access_mask = FILE_GENERIC_ALL;
1409 status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION);
1410 if (!NT_STATUS_IS_OK(status)) {
1411 talloc_destroy(ctx);
1412 close_file(fsp,ERROR_CLOSE);
1413 restore_case_semantics(conn, file_attributes);
1414 return ERROR_NT(status);
1416 fsp->access_mask = saved_access_mask;
1419 if (ea_len && (info == FILE_WAS_CREATED)) {
1420 status = set_ea(conn, fsp, fname, ea_list);
1421 talloc_destroy(ctx);
1422 if (!NT_STATUS_IS_OK(status)) {
1423 close_file(fsp,ERROR_CLOSE);
1424 restore_case_semantics(conn, file_attributes);
1425 return ERROR_NT(status);
1429 restore_case_semantics(conn, file_attributes);
1431 file_len = sbuf.st_size;
1432 fattr = dos_mode(conn,fname,&sbuf);
1434 fattr = FILE_ATTRIBUTE_NORMAL;
1436 if (!fsp->is_directory && (fattr & aDIR)) {
1437 close_file(fsp,ERROR_CLOSE);
1438 return ERROR_DOS(ERRDOS,ERRnoaccess);
1441 /* Save the requested allocation size. */
1442 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
1443 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1444 #ifdef LARGE_SMB_OFF_T
1445 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1447 if (allocation_size && (allocation_size > file_len)) {
1448 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
1449 if (fsp->is_directory) {
1450 close_file(fsp,ERROR_CLOSE);
1451 /* Can't set allocation size on a directory. */
1452 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1454 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1455 close_file(fsp,ERROR_CLOSE);
1456 return ERROR_NT(NT_STATUS_DISK_FULL);
1459 fsp->initial_allocation_size = smb_roundup(fsp->conn, (SMB_BIG_UINT)file_len);
1464 * If the caller set the extended oplock request bit
1465 * and we granted one (by whatever means) - set the
1466 * correct bit for extended oplock reply.
1469 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
1470 extended_oplock_granted = True;
1473 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
1474 extended_oplock_granted = True;
1477 /* Realloc the size of parameters and data we will return */
1478 params = nttrans_realloc(ppparams, 69);
1479 if(params == NULL) {
1480 return ERROR_DOS(ERRDOS,ERRnomem);
1484 if (extended_oplock_granted) {
1485 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1486 } else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
1487 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1489 SCVAL(p,0,NO_OPLOCK_RETURN);
1493 SSVAL(p,0,fsp->fnum);
1495 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
1496 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1503 c_timespec = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1504 a_timespec = get_atimespec(&sbuf);
1505 m_timespec = get_mtimespec(&sbuf);
1507 if (lp_dos_filetime_resolution(SNUM(conn))) {
1508 dos_filetime_timespec(&c_timespec);
1509 dos_filetime_timespec(&a_timespec);
1510 dos_filetime_timespec(&m_timespec);
1513 put_long_date_timespec(p, c_timespec); /* create time. */
1515 put_long_date_timespec(p, a_timespec); /* access time */
1517 put_long_date_timespec(p, m_timespec); /* write time */
1519 put_long_date_timespec(p, m_timespec); /* change time */
1521 SIVAL(p,0,fattr); /* File Attributes. */
1523 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1525 SOFF_T(p,0,file_len);
1527 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1531 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1533 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1535 /* Send the required number of replies */
1536 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1541 /****************************************************************************
1542 Reply to a NT CANCEL request.
1543 conn POINTER CAN BE NULL HERE !
1544 ****************************************************************************/
1546 int reply_ntcancel(connection_struct *conn,
1547 char *inbuf,char *outbuf,int length,int bufsize)
1550 * Go through and cancel any pending change notifies.
1553 int mid = SVAL(inbuf,smb_mid);
1554 START_PROFILE(SMBntcancel);
1555 remove_pending_change_notify_requests_by_mid(mid);
1556 remove_pending_lock_requests_by_mid(mid);
1557 srv_cancel_sign_response(mid);
1559 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1561 END_PROFILE(SMBntcancel);
1565 /****************************************************************************
1567 ****************************************************************************/
1569 static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *newname, uint32 attrs)
1571 BOOL bad_path_oldname = False;
1572 BOOL bad_path_newname = False;
1573 SMB_STRUCT_STAT sbuf1, sbuf2;
1574 pstring last_component_oldname;
1575 pstring last_component_newname;
1576 files_struct *fsp1,*fsp2;
1581 NTSTATUS status = NT_STATUS_OK;
1587 if (ms_has_wild(newname) || ms_has_wild(oldname)) {
1588 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1591 if (!CAN_WRITE(conn))
1592 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1594 unix_convert(oldname,conn,last_component_oldname,&bad_path_oldname,&sbuf1);
1595 if (bad_path_oldname) {
1596 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1599 /* Quick check for "." and ".." */
1600 if (last_component_oldname[0] == '.') {
1601 if (!last_component_oldname[1] || (last_component_oldname[1] == '.' && !last_component_oldname[2])) {
1602 return NT_STATUS_OBJECT_NAME_INVALID;
1606 /* Source must already exist. */
1607 if (!VALID_STAT(sbuf1)) {
1608 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1610 if (!check_name(oldname,conn)) {
1611 return NT_STATUS_ACCESS_DENIED;
1614 /* Ensure attributes match. */
1615 fattr = dos_mode(conn,oldname,&sbuf1);
1616 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1617 return NT_STATUS_NO_SUCH_FILE;
1620 unix_convert(newname,conn,last_component_newname,&bad_path_newname,&sbuf2);
1621 if (bad_path_newname) {
1622 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1625 /* Quick check for "." and ".." */
1626 if (last_component_newname[0] == '.') {
1627 if (!last_component_newname[1] || (last_component_newname[1] == '.' && !last_component_newname[2])) {
1628 return NT_STATUS_OBJECT_NAME_INVALID;
1632 /* Disallow if newname already exists. */
1633 if (VALID_STAT(sbuf2)) {
1634 return NT_STATUS_OBJECT_NAME_COLLISION;
1637 if (!check_name(newname,conn)) {
1638 return NT_STATUS_ACCESS_DENIED;
1641 /* No links from a directory. */
1642 if (S_ISDIR(sbuf1.st_mode)) {
1643 return NT_STATUS_FILE_IS_A_DIRECTORY;
1646 /* Ensure this is within the share. */
1647 if (!reduce_name(conn, oldname) != 0) {
1648 return NT_STATUS_ACCESS_DENIED;
1651 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname, newname));
1653 status = open_file_ntcreate(conn,oldname,&sbuf1,
1654 FILE_READ_DATA, /* Read-only. */
1655 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1657 0, /* No create options. */
1658 FILE_ATTRIBUTE_NORMAL,
1662 if (!NT_STATUS_IS_OK(status)) {
1666 status = open_file_ntcreate(conn,newname,&sbuf2,
1667 FILE_WRITE_DATA, /* Read-only. */
1668 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1670 0, /* No create options. */
1675 if (!NT_STATUS_IS_OK(status)) {
1676 close_file(fsp1,ERROR_CLOSE);
1680 if (sbuf1.st_size) {
1681 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1685 * As we are opening fsp1 read-only we only expect
1686 * an error on close on fsp2 if we are out of space.
1687 * Thus we don't look at the error return from the
1690 close_file(fsp1,NORMAL_CLOSE);
1692 /* Ensure the modtime is set correctly on the destination file. */
1693 fsp_set_pending_modtime(fsp2, sbuf1.st_mtime);
1695 close_ret = close_file(fsp2,NORMAL_CLOSE);
1697 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1698 creates the file. This isn't the correct thing to do in the copy
1700 file_set_dosmode(conn, newname, fattr, &sbuf2, True);
1702 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1703 return NT_STATUS_DISK_FULL;
1706 if (close_ret != 0) {
1707 status = map_nt_error_from_unix(close_ret);
1708 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1709 nt_errstr(status), oldname, newname));
1714 /****************************************************************************
1715 Reply to a NT rename request.
1716 ****************************************************************************/
1718 int reply_ntrename(connection_struct *conn,
1719 char *inbuf,char *outbuf,int length,int bufsize)
1726 BOOL path_contains_wcard = False;
1727 uint32 attrs = SVAL(inbuf,smb_vwv0);
1728 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1730 START_PROFILE(SMBntrename);
1732 p = smb_buf(inbuf) + 1;
1733 p += srvstr_get_path_wcard(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, &path_contains_wcard);
1734 if (!NT_STATUS_IS_OK(status)) {
1735 END_PROFILE(SMBntrename);
1736 return ERROR_NT(status);
1739 if( is_ntfs_stream_name(oldname)) {
1740 /* Can't rename a stream. */
1741 END_PROFILE(SMBntrename);
1742 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1745 if (ms_has_wild(oldname)) {
1746 END_PROFILE(SMBntrename);
1747 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1751 p += srvstr_get_path(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status);
1752 if (!NT_STATUS_IS_OK(status)) {
1753 END_PROFILE(SMBntrename);
1754 return ERROR_NT(status);
1757 RESOLVE_DFSPATH(oldname, conn, inbuf, outbuf);
1758 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1760 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1762 switch(rename_type) {
1763 case RENAME_FLAG_RENAME:
1764 status = rename_internals(conn, oldname, newname, attrs, False, path_contains_wcard);
1766 case RENAME_FLAG_HARD_LINK:
1767 status = hardlink_internals(conn, oldname, newname);
1769 case RENAME_FLAG_COPY:
1770 if (path_contains_wcard) {
1772 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1774 status = copy_internals(conn, oldname, newname, attrs);
1777 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1778 status = NT_STATUS_INVALID_PARAMETER;
1781 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1785 if (!NT_STATUS_IS_OK(status)) {
1786 END_PROFILE(SMBntrename);
1787 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1788 /* We have re-scheduled this call. */
1791 return ERROR_NT(status);
1795 * Win2k needs a changenotify request response before it will
1796 * update after a rename..
1798 process_pending_change_notify_queue((time_t)0);
1799 outsize = set_message(outbuf,0,0,False);
1801 END_PROFILE(SMBntrename);
1805 /****************************************************************************
1806 Reply to a notify change - queue the request and
1807 don't allow a directory to be opened.
1808 ****************************************************************************/
1810 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf,
1811 char *outbuf, int length,
1813 uint16 **ppsetup, uint32 setup_count,
1815 uint32 parameter_count,
1816 char **ppdata, uint32 data_count,
1817 uint32 max_data_count,
1818 uint32 max_param_count)
1820 uint16 *setup = *ppsetup;
1824 if(setup_count < 6) {
1825 return ERROR_DOS(ERRDOS,ERRbadfunc);
1828 fsp = file_fsp((char *)setup,4);
1829 flags = IVAL(setup, 0);
1831 DEBUG(3,("call_nt_transact_notify_change\n"));
1834 return ERROR_DOS(ERRDOS,ERRbadfid);
1837 DEBUG(3,("call_nt_transact_notify_change: notify change called on "
1838 "directory name = %s\n", fsp->fsp_name ));
1840 if((!fsp->is_directory) || (conn != fsp->conn)) {
1841 return ERROR_DOS(ERRDOS,ERRbadfid);
1844 if (!change_notify_set(inbuf, fsp, conn, flags)) {
1845 return(UNIXERROR(ERRDOS,ERRbadfid));
1851 /****************************************************************************
1852 Reply to an NT transact rename command.
1853 ****************************************************************************/
1855 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1856 uint16 **ppsetup, uint32 setup_count,
1857 char **ppparams, uint32 parameter_count,
1858 char **ppdata, uint32 data_count, uint32 max_data_count)
1860 char *params = *ppparams;
1862 files_struct *fsp = NULL;
1863 BOOL replace_if_exists = False;
1864 BOOL path_contains_wcard = False;
1867 if(parameter_count < 4) {
1868 return ERROR_DOS(ERRDOS,ERRbadfunc);
1871 fsp = file_fsp(params, 0);
1872 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1873 CHECK_FSP(fsp, conn);
1874 srvstr_get_path_wcard(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE, &status, &path_contains_wcard);
1875 if (!NT_STATUS_IS_OK(status)) {
1876 return ERROR_NT(status);
1879 status = rename_internals(conn, fsp->fsp_name,
1880 new_name, 0, replace_if_exists, path_contains_wcard);
1881 if (!NT_STATUS_IS_OK(status))
1882 return ERROR_NT(status);
1885 * Rename was successful.
1887 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1889 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1890 fsp->fsp_name, new_name));
1893 * Win2k needs a changenotify request response before it will
1894 * update after a rename..
1897 process_pending_change_notify_queue((time_t)0);
1902 /******************************************************************************
1903 Fake up a completely empty SD.
1904 *******************************************************************************/
1906 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1910 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1912 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1919 /****************************************************************************
1920 Reply to query a security descriptor.
1921 ****************************************************************************/
1923 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1924 uint16 **ppsetup, uint32 setup_count,
1925 char **ppparams, uint32 parameter_count,
1926 char **ppdata, uint32 data_count, uint32 max_data_count)
1928 char *params = *ppparams;
1929 char *data = *ppdata;
1931 SEC_DESC *psd = NULL;
1933 uint32 security_info_wanted;
1934 TALLOC_CTX *mem_ctx;
1935 files_struct *fsp = NULL;
1937 if(parameter_count < 8) {
1938 return ERROR_DOS(ERRDOS,ERRbadfunc);
1941 fsp = file_fsp(params,0);
1943 return ERROR_DOS(ERRDOS,ERRbadfid);
1946 security_info_wanted = IVAL(params,4);
1948 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1949 (unsigned int)security_info_wanted ));
1951 params = nttrans_realloc(ppparams, 4);
1952 if(params == NULL) {
1953 return ERROR_DOS(ERRDOS,ERRnomem);
1956 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1957 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1958 return ERROR_DOS(ERRDOS,ERRnomem);
1962 * Get the permissions to return.
1965 if (!lp_nt_acl_support(SNUM(conn))) {
1966 sd_size = get_null_nt_acl(mem_ctx, &psd);
1968 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fh->fd, security_info_wanted, &psd);
1972 talloc_destroy(mem_ctx);
1973 return(UNIXERROR(ERRDOS,ERRnoaccess));
1976 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1978 SIVAL(params,0,(uint32)sd_size);
1980 if(max_data_count < sd_size) {
1982 send_nt_replies(outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
1983 params, 4, *ppdata, 0);
1984 talloc_destroy(mem_ctx);
1989 * Allocate the data we will point this at.
1992 data = nttrans_realloc(ppdata, sd_size);
1994 talloc_destroy(mem_ctx);
1995 return ERROR_DOS(ERRDOS,ERRnomem);
1999 * Init the parse struct we will marshall into.
2002 prs_init(&pd, 0, mem_ctx, MARSHALL);
2005 * Setup the prs_struct to point at the memory we just
2009 prs_give_memory( &pd, data, (uint32)sd_size, False);
2012 * Finally, linearize into the outgoing buffer.
2015 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2016 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2017 security descriptor.\n"));
2019 * Return access denied for want of a better error message..
2021 talloc_destroy(mem_ctx);
2022 return(UNIXERROR(ERRDOS,ERRnoaccess));
2026 * Now we can delete the security descriptor.
2029 talloc_destroy(mem_ctx);
2031 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 4, data,
2036 /****************************************************************************
2037 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2038 ****************************************************************************/
2040 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2041 uint16 **ppsetup, uint32 setup_count,
2042 char **ppparams, uint32 parameter_count,
2043 char **ppdata, uint32 data_count, uint32 max_data_count)
2045 char *params= *ppparams;
2046 char *data = *ppdata;
2047 files_struct *fsp = NULL;
2048 uint32 security_info_sent = 0;
2051 if(parameter_count < 8) {
2052 return ERROR_DOS(ERRDOS,ERRbadfunc);
2055 if((fsp = file_fsp(params,0)) == NULL) {
2056 return ERROR_DOS(ERRDOS,ERRbadfid);
2059 if(!lp_nt_acl_support(SNUM(conn))) {
2063 security_info_sent = IVAL(params,4);
2065 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
2066 (unsigned int)security_info_sent ));
2068 if (data_count == 0) {
2069 return ERROR_DOS(ERRDOS, ERRnoaccess);
2072 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent))) {
2073 return ERROR_NT(nt_status);
2078 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2082 /****************************************************************************
2084 ****************************************************************************/
2086 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2087 uint16 **ppsetup, uint32 setup_count,
2088 char **ppparams, uint32 parameter_count,
2089 char **ppdata, uint32 data_count, uint32 max_data_count)
2096 static BOOL logged_message;
2097 char *pdata = *ppdata;
2099 if (setup_count != 8) {
2100 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2101 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2104 function = IVAL(*ppsetup, 0);
2105 fidnum = SVAL(*ppsetup, 4);
2106 isFSctl = CVAL(*ppsetup, 6);
2107 compfilter = CVAL(*ppsetup, 7);
2109 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2110 function, fidnum, isFSctl, compfilter));
2112 fsp=file_fsp((char *)*ppsetup, 4);
2113 /* this check is done in each implemented function case for now
2114 because I don't want to break anything... --metze
2115 FSP_BELONGS_CONN(fsp,conn);*/
2118 case FSCTL_SET_SPARSE:
2119 /* pretend this succeeded - tho strictly we should
2120 mark the file sparse (if the local fs supports it)
2121 so we can know if we need to pre-allocate or not */
2123 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2124 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL,
2128 case FSCTL_0x000900C0:
2129 /* pretend this succeeded - don't know what this really is
2130 but works ok like this --metze
2133 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2134 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL,
2138 case FSCTL_GET_REPARSE_POINT:
2139 /* pretend this fail - my winXP does it like this
2143 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2144 send_nt_replies(outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT,
2148 case FSCTL_SET_REPARSE_POINT:
2149 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2153 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2154 send_nt_replies(outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT,
2158 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
2161 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2162 * and return their volume names. If max_data_count is 16, then it is just
2163 * asking for the number of volumes and length of the combined names.
2165 * pdata is the data allocated by our caller, but that uses
2166 * total_data_count (which is 0 in our case) rather than max_data_count.
2167 * Allocate the correct amount and return the pointer to let
2168 * it be deallocated when we return.
2170 SHADOW_COPY_DATA *shadow_data = NULL;
2171 TALLOC_CTX *shadow_mem_ctx = NULL;
2172 BOOL labels = False;
2173 uint32 labels_data_count = 0;
2177 FSP_BELONGS_CONN(fsp,conn);
2179 if (max_data_count < 16) {
2180 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2182 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2185 if (max_data_count > 16) {
2189 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2190 if (shadow_mem_ctx == NULL) {
2191 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2192 return ERROR_NT(NT_STATUS_NO_MEMORY);
2195 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2196 if (shadow_data == NULL) {
2197 DEBUG(0,("talloc_zero() failed!\n"));
2198 talloc_destroy(shadow_mem_ctx);
2199 return ERROR_NT(NT_STATUS_NO_MEMORY);
2202 shadow_data->mem_ctx = shadow_mem_ctx;
2205 * Call the VFS routine to actually do the work.
2207 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2208 talloc_destroy(shadow_data->mem_ctx);
2209 if (errno == ENOSYS) {
2210 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2211 conn->connectpath));
2212 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2214 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2215 conn->connectpath));
2216 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
2220 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2225 data_count = 12+labels_data_count+4;
2228 if (max_data_count<data_count) {
2229 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2230 max_data_count,data_count));
2231 talloc_destroy(shadow_data->mem_ctx);
2232 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
2235 pdata = nttrans_realloc(ppdata, data_count);
2236 if (pdata == NULL) {
2237 talloc_destroy(shadow_data->mem_ctx);
2238 return ERROR_NT(NT_STATUS_NO_MEMORY);
2243 /* num_volumes 4 bytes */
2244 SIVAL(pdata,0,shadow_data->num_volumes);
2247 /* num_labels 4 bytes */
2248 SIVAL(pdata,4,shadow_data->num_volumes);
2251 /* needed_data_count 4 bytes */
2252 SIVAL(pdata,8,labels_data_count);
2256 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2257 shadow_data->num_volumes,fsp->fsp_name));
2258 if (labels && shadow_data->labels) {
2259 for (i=0;i<shadow_data->num_volumes;i++) {
2260 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2261 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2262 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2266 talloc_destroy(shadow_data->mem_ctx);
2268 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0,
2274 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2276 /* pretend this succeeded -
2278 * we have to send back a list with all files owned by this SID
2280 * but I have to check that --metze
2284 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2286 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2288 FSP_BELONGS_CONN(fsp,conn);
2290 /* unknown 4 bytes: this is not the length of the sid :-( */
2291 /*unknown = IVAL(pdata,0);*/
2293 sid_parse(pdata+4,sid_len,&sid);
2294 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2296 if (!sid_to_uid(&sid, &uid)) {
2297 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2298 sid_string_static(&sid),(unsigned long)sid_len));
2302 /* we can take a look at the find source :-)
2304 * find ./ -uid $uid -name '*' is what we need here
2307 * and send 4bytes len and then NULL terminated unicode strings
2310 * but I don't know how to deal with the paged results
2311 * (maybe we can hang the result anywhere in the fsp struct)
2313 * we don't send all files at once
2314 * and at the next we should *not* start from the beginning,
2315 * so we have to cache the result
2320 /* this works for now... */
2321 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0,
2326 if (!logged_message) {
2327 logged_message = True; /* Only print this once... */
2328 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2333 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2337 #ifdef HAVE_SYS_QUOTAS
2338 /****************************************************************************
2339 Reply to get user quota
2340 ****************************************************************************/
2342 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2343 uint16 **ppsetup, uint32 setup_count,
2344 char **ppparams, uint32 parameter_count,
2345 char **ppdata, uint32 data_count, uint32 max_data_count)
2347 NTSTATUS nt_status = NT_STATUS_OK;
2348 char *params = *ppparams;
2349 char *pdata = *ppdata;
2351 int data_len=0,param_len=0;
2354 files_struct *fsp = NULL;
2358 BOOL start_enum = True;
2359 SMB_NTQUOTA_STRUCT qt;
2360 SMB_NTQUOTA_LIST *tmp_list;
2361 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2366 if (current_user.ut.uid != 0) {
2367 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2368 lp_servicename(SNUM(conn)),conn->user));
2369 return ERROR_DOS(ERRDOS,ERRnoaccess);
2373 * Ensure minimum number of parameters sent.
2376 if (parameter_count < 4) {
2377 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2378 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2381 /* maybe we can check the quota_fnum */
2382 fsp = file_fsp(params,0);
2383 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2384 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2385 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2388 /* the NULL pointer checking for fsp->fake_file_handle->pd
2389 * is done by CHECK_NTQUOTA_HANDLE_OK()
2391 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2393 level = SVAL(params,2);
2395 /* unknown 12 bytes leading in params */
2398 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2399 /* seems that we should continue with the enum here --metze */
2401 if (qt_handle->quota_list!=NULL &&
2402 qt_handle->tmp_list==NULL) {
2405 free_ntquota_list(&(qt_handle->quota_list));
2407 /* Realloc the size of parameters and data we will return */
2409 params = nttrans_realloc(ppparams, param_len);
2410 if(params == NULL) {
2411 return ERROR_DOS(ERRDOS,ERRnomem);
2415 SIVAL(params,0,data_len);
2422 case TRANSACT_GET_USER_QUOTA_LIST_START:
2424 if (qt_handle->quota_list==NULL &&
2425 qt_handle->tmp_list==NULL) {
2429 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2430 return ERROR_DOS(ERRSRV,ERRerror);
2432 /* Realloc the size of parameters and data we will return */
2434 params = nttrans_realloc(ppparams, param_len);
2435 if(params == NULL) {
2436 return ERROR_DOS(ERRDOS,ERRnomem);
2439 /* we should not trust the value in max_data_count*/
2440 max_data_count = MIN(max_data_count,2048);
2442 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2444 return ERROR_DOS(ERRDOS,ERRnomem);
2449 /* set params Size of returned Quota Data 4 bytes*/
2450 /* but set it later when we know it */
2452 /* for each entry push the data */
2455 qt_handle->tmp_list = qt_handle->quota_list;
2458 tmp_list = qt_handle->tmp_list;
2460 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2461 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2463 sid_len = sid_size(&tmp_list->quotas->sid);
2464 entry_len = 40 + sid_len;
2466 /* nextoffset entry 4 bytes */
2467 SIVAL(entry,0,entry_len);
2469 /* then the len of the SID 4 bytes */
2470 SIVAL(entry,4,sid_len);
2472 /* unknown data 8 bytes SMB_BIG_UINT */
2473 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2475 /* the used disk space 8 bytes SMB_BIG_UINT */
2476 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2478 /* the soft quotas 8 bytes SMB_BIG_UINT */
2479 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2481 /* the hard quotas 8 bytes SMB_BIG_UINT */
2482 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2484 /* and now the SID */
2485 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2488 qt_handle->tmp_list = tmp_list;
2490 /* overwrite the offset of the last entry */
2491 SIVAL(entry-entry_len,0,0);
2493 data_len = 4+qt_len;
2494 /* overwrite the params quota_data_len */
2495 SIVAL(params,0,data_len);
2499 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2501 /* unknown 4 bytes IVAL(pdata,0) */
2503 if (data_count < 8) {
2504 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2505 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2508 sid_len = IVAL(pdata,4);
2509 /* Ensure this is less than 1mb. */
2510 if (sid_len > (1024*1024)) {
2511 return ERROR_DOS(ERRDOS,ERRnomem);
2514 if (data_count < 8+sid_len) {
2515 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2516 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2519 data_len = 4+40+sid_len;
2521 if (max_data_count < data_len) {
2522 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2523 max_data_count, data_len));
2525 SIVAL(params,0,data_len);
2527 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2531 sid_parse(pdata+8,sid_len,&sid);
2533 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2536 * we have to return zero's in all fields
2537 * instead of returning an error here
2542 /* Realloc the size of parameters and data we will return */
2544 params = nttrans_realloc(ppparams, param_len);
2545 if(params == NULL) {
2546 return ERROR_DOS(ERRDOS,ERRnomem);
2549 pdata = nttrans_realloc(ppdata, data_len);
2551 return ERROR_DOS(ERRDOS,ERRnomem);
2556 /* set params Size of returned Quota Data 4 bytes*/
2557 SIVAL(params,0,data_len);
2559 /* nextoffset entry 4 bytes */
2562 /* then the len of the SID 4 bytes */
2563 SIVAL(entry,4,sid_len);
2565 /* unknown data 8 bytes SMB_BIG_UINT */
2566 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2568 /* the used disk space 8 bytes SMB_BIG_UINT */
2569 SBIG_UINT(entry,16,qt.usedspace);
2571 /* the soft quotas 8 bytes SMB_BIG_UINT */
2572 SBIG_UINT(entry,24,qt.softlim);
2574 /* the hard quotas 8 bytes SMB_BIG_UINT */
2575 SBIG_UINT(entry,32,qt.hardlim);
2577 /* and now the SID */
2578 sid_linearize(entry+40, sid_len, &sid);
2583 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2584 return ERROR_DOS(ERRSRV,ERRerror);
2588 send_nt_replies(outbuf, bufsize, nt_status, params, param_len,
2594 /****************************************************************************
2595 Reply to set user quota
2596 ****************************************************************************/
2598 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2599 uint16 **ppsetup, uint32 setup_count,
2600 char **ppparams, uint32 parameter_count,
2601 char **ppdata, uint32 data_count, uint32 max_data_count)
2603 char *params = *ppparams;
2604 char *pdata = *ppdata;
2605 int data_len=0,param_len=0;
2606 SMB_NTQUOTA_STRUCT qt;
2609 files_struct *fsp = NULL;
2614 if (current_user.ut.uid != 0) {
2615 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2616 lp_servicename(SNUM(conn)),conn->user));
2617 return ERROR_DOS(ERRDOS,ERRnoaccess);
2621 * Ensure minimum number of parameters sent.
2624 if (parameter_count < 2) {
2625 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2626 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2629 /* maybe we can check the quota_fnum */
2630 fsp = file_fsp(params,0);
2631 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2632 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2633 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2636 if (data_count < 40) {
2637 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2638 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2641 /* offset to next quota record.
2642 * 4 bytes IVAL(pdata,0)
2647 sid_len = IVAL(pdata,4);
2649 if (data_count < 40+sid_len) {
2650 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2651 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2654 /* unknown 8 bytes in pdata
2655 * maybe its the change time in NTTIME
2658 /* the used space 8 bytes (SMB_BIG_UINT)*/
2659 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2660 #ifdef LARGE_SMB_OFF_T
2661 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2662 #else /* LARGE_SMB_OFF_T */
2663 if ((IVAL(pdata,20) != 0)&&
2664 ((qt.usedspace != 0xFFFFFFFF)||
2665 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2666 /* more than 32 bits? */
2667 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2669 #endif /* LARGE_SMB_OFF_T */
2671 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2672 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2673 #ifdef LARGE_SMB_OFF_T
2674 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2675 #else /* LARGE_SMB_OFF_T */
2676 if ((IVAL(pdata,28) != 0)&&
2677 ((qt.softlim != 0xFFFFFFFF)||
2678 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2679 /* more than 32 bits? */
2680 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2682 #endif /* LARGE_SMB_OFF_T */
2684 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2685 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2686 #ifdef LARGE_SMB_OFF_T
2687 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2688 #else /* LARGE_SMB_OFF_T */
2689 if ((IVAL(pdata,36) != 0)&&
2690 ((qt.hardlim != 0xFFFFFFFF)||
2691 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2692 /* more than 32 bits? */
2693 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2695 #endif /* LARGE_SMB_OFF_T */
2697 sid_parse(pdata+40,sid_len,&sid);
2698 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2700 /* 44 unknown bytes left... */
2702 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2703 return ERROR_DOS(ERRSRV,ERRerror);
2706 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, param_len,
2711 #endif /* HAVE_SYS_QUOTAS */
2713 static int handle_nttrans(connection_struct *conn,
2714 struct trans_state *state,
2715 char *inbuf, char *outbuf, int size, int bufsize)
2719 if (Protocol >= PROTOCOL_NT1) {
2720 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | 0x40); /* IS_LONG_NAME */
2723 /* Now we must call the relevant NT_TRANS function */
2724 switch(state->call) {
2725 case NT_TRANSACT_CREATE:
2727 START_PROFILE_NESTED(NT_transact_create);
2728 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2730 &state->setup, state->setup_count,
2731 &state->param, state->total_param,
2732 &state->data, state->total_data,
2733 state->max_data_return);
2734 END_PROFILE_NESTED(NT_transact_create);
2738 case NT_TRANSACT_IOCTL:
2740 START_PROFILE_NESTED(NT_transact_ioctl);
2741 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2743 &state->setup, state->setup_count,
2744 &state->param, state->total_param,
2745 &state->data, state->total_data, state->max_data_return);
2746 END_PROFILE_NESTED(NT_transact_ioctl);
2750 case NT_TRANSACT_SET_SECURITY_DESC:
2752 START_PROFILE_NESTED(NT_transact_set_security_desc);
2753 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2755 &state->setup, state->setup_count,
2756 &state->param, state->total_param,
2757 &state->data, state->total_data, state->max_data_return);
2758 END_PROFILE_NESTED(NT_transact_set_security_desc);
2762 case NT_TRANSACT_NOTIFY_CHANGE:
2764 START_PROFILE_NESTED(NT_transact_notify_change);
2765 outsize = call_nt_transact_notify_change(
2766 conn, inbuf, outbuf, size, bufsize,
2767 &state->setup, state->setup_count,
2768 &state->param, state->total_param,
2769 &state->data, state->total_data,
2770 state->max_data_return,
2771 state->max_param_return);
2772 END_PROFILE_NESTED(NT_transact_notify_change);
2776 case NT_TRANSACT_RENAME:
2778 START_PROFILE_NESTED(NT_transact_rename);
2779 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2781 &state->setup, state->setup_count,
2782 &state->param, state->total_param,
2783 &state->data, state->total_data, state->max_data_return);
2784 END_PROFILE_NESTED(NT_transact_rename);
2788 case NT_TRANSACT_QUERY_SECURITY_DESC:
2790 START_PROFILE_NESTED(NT_transact_query_security_desc);
2791 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
2793 &state->setup, state->setup_count,
2794 &state->param, state->total_param,
2795 &state->data, state->total_data, state->max_data_return);
2796 END_PROFILE_NESTED(NT_transact_query_security_desc);
2800 #ifdef HAVE_SYS_QUOTAS
2801 case NT_TRANSACT_GET_USER_QUOTA:
2803 START_PROFILE_NESTED(NT_transact_get_user_quota);
2804 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
2806 &state->setup, state->setup_count,
2807 &state->param, state->total_param,
2808 &state->data, state->total_data, state->max_data_return);
2809 END_PROFILE_NESTED(NT_transact_get_user_quota);
2813 case NT_TRANSACT_SET_USER_QUOTA:
2815 START_PROFILE_NESTED(NT_transact_set_user_quota);
2816 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
2818 &state->setup, state->setup_count,
2819 &state->param, state->total_param,
2820 &state->data, state->total_data, state->max_data_return);
2821 END_PROFILE_NESTED(NT_transact_set_user_quota);
2824 #endif /* HAVE_SYS_QUOTAS */
2827 /* Error in request */
2828 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n",
2830 return ERROR_DOS(ERRSRV,ERRerror);
2835 /****************************************************************************
2836 Reply to a SMBNTtrans.
2837 ****************************************************************************/
2839 int reply_nttrans(connection_struct *conn,
2840 char *inbuf,char *outbuf,int size,int bufsize)
2843 uint32 pscnt = IVAL(inbuf,smb_nt_ParameterCount);
2844 uint32 psoff = IVAL(inbuf,smb_nt_ParameterOffset);
2845 uint32 dscnt = IVAL(inbuf,smb_nt_DataCount);
2846 uint32 dsoff = IVAL(inbuf,smb_nt_DataOffset);
2848 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2850 struct trans_state *state;
2852 START_PROFILE(SMBnttrans);
2854 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2855 END_PROFILE(SMBnttrans);
2856 return ERROR_DOS(ERRSRV,ERRaccess);
2859 result = allow_new_trans(conn->pending_trans, SVAL(inbuf, smb_mid));
2860 if (!NT_STATUS_IS_OK(result)) {
2861 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2862 END_PROFILE(SMBnttrans);
2863 return ERROR_NT(result);
2866 if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
2867 END_PROFILE(SMBnttrans);
2868 return ERROR_DOS(ERRSRV,ERRaccess);
2871 state->cmd = SMBnttrans;
2873 state->mid = SVAL(inbuf,smb_mid);
2874 state->vuid = SVAL(inbuf,smb_uid);
2875 state->total_data = IVAL(inbuf, smb_nt_TotalDataCount);
2877 state->total_param = IVAL(inbuf, smb_nt_TotalParameterCount);
2878 state->param = NULL;
2879 state->max_data_return = IVAL(inbuf,smb_nt_MaxDataCount);
2880 state->max_param_return = IVAL(inbuf,smb_nt_MaxParameterCount);
2882 /* setup count is in *words* */
2883 state->setup_count = 2*CVAL(inbuf,smb_nt_SetupCount);
2884 state->setup = NULL;
2885 state->call = function_code;
2888 * All nttrans messages we handle have smb_wct == 19 +
2889 * state->setup_count. Ensure this is so as a sanity check.
2892 if(CVAL(inbuf, smb_wct) != 19 + (state->setup_count/2)) {
2893 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2894 CVAL(inbuf, smb_wct), 19 + (state->setup_count/2)));
2898 /* Don't allow more than 128mb for each value. */
2899 if ((state->total_data > (1024*1024*128)) ||
2900 (state->total_param > (1024*1024*128))) {
2901 END_PROFILE(SMBnttrans);
2902 return ERROR_DOS(ERRDOS,ERRnomem);
2905 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2908 if (state->total_data) {
2909 /* Can't use talloc here, the core routines do realloc on the
2910 * params and data. */
2911 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2912 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2913 "bytes !\n", (unsigned int)state->total_data));
2915 END_PROFILE(SMBnttrans);
2916 return(ERROR_DOS(ERRDOS,ERRnomem));
2918 if ((dsoff+dscnt < dsoff) || (dsoff+dscnt < dscnt))
2920 if ((smb_base(inbuf)+dsoff+dscnt > inbuf + size) ||
2921 (smb_base(inbuf)+dsoff+dscnt < smb_base(inbuf)))
2924 memcpy(state->data,smb_base(inbuf)+dsoff,dscnt);
2927 if (state->total_param) {
2928 /* Can't use talloc here, the core routines do realloc on the
2929 * params and data. */
2930 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2931 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2932 "bytes !\n", (unsigned int)state->total_param));
2933 SAFE_FREE(state->data);
2935 END_PROFILE(SMBnttrans);
2936 return(ERROR_DOS(ERRDOS,ERRnomem));
2938 if ((psoff+pscnt < psoff) || (psoff+pscnt < pscnt))
2940 if ((smb_base(inbuf)+psoff+pscnt > inbuf + size) ||
2941 (smb_base(inbuf)+psoff+pscnt < smb_base(inbuf)))
2944 memcpy(state->param,smb_base(inbuf)+psoff,pscnt);
2947 state->received_data = dscnt;
2948 state->received_param = pscnt;
2950 if(state->setup_count > 0) {
2951 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2952 state->setup_count));
2953 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2954 if (state->setup == NULL) {
2955 DEBUG(0,("reply_nttrans : Out of memory\n"));
2956 SAFE_FREE(state->data);
2957 SAFE_FREE(state->param);
2959 END_PROFILE(SMBnttrans);
2960 return ERROR_DOS(ERRDOS,ERRnomem);
2963 if ((smb_nt_SetupStart + state->setup_count < smb_nt_SetupStart) ||
2964 (smb_nt_SetupStart + state->setup_count < state->setup_count)) {
2967 if (smb_nt_SetupStart + state->setup_count > size) {
2971 memcpy( state->setup, &inbuf[smb_nt_SetupStart], state->setup_count);
2972 dump_data(10, (char *)state->setup, state->setup_count);
2975 if ((state->received_data == state->total_data) &&
2976 (state->received_param == state->total_param)) {
2977 outsize = handle_nttrans(conn, state, inbuf, outbuf,
2979 SAFE_FREE(state->param);
2980 SAFE_FREE(state->data);
2982 END_PROFILE(SMBnttrans);
2986 DLIST_ADD(conn->pending_trans, state);
2988 /* We need to send an interim response then receive the rest
2989 of the parameter/data bytes */
2990 outsize = set_message(outbuf,0,0,False);
2992 END_PROFILE(SMBnttrans);
2997 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2998 SAFE_FREE(state->data);
2999 SAFE_FREE(state->param);
3001 END_PROFILE(SMBnttrans);
3002 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
3005 /****************************************************************************
3006 Reply to a SMBnttranss
3007 ****************************************************************************/
3009 int reply_nttranss(connection_struct *conn, char *inbuf,char *outbuf,
3010 int size,int bufsize)
3013 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
3014 struct trans_state *state;
3016 START_PROFILE(SMBnttranss);
3020 for (state = conn->pending_trans; state != NULL;
3021 state = state->next) {
3022 if (state->mid == SVAL(inbuf,smb_mid)) {
3027 if ((state == NULL) || (state->cmd != SMBnttrans)) {
3028 END_PROFILE(SMBnttranss);
3029 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
3032 /* Revise state->total_param and state->total_data in case they have
3033 changed downwards */
3034 if (IVAL(inbuf, smb_nts_TotalParameterCount) < state->total_param) {
3035 state->total_param = IVAL(inbuf, smb_nts_TotalParameterCount);
3037 if (IVAL(inbuf, smb_nts_TotalDataCount) < state->total_data) {
3038 state->total_data = IVAL(inbuf, smb_nts_TotalDataCount);
3041 pcnt = IVAL(inbuf,smb_nts_ParameterCount);
3042 poff = IVAL(inbuf, smb_nts_ParameterOffset);
3043 pdisp = IVAL(inbuf, smb_nts_ParameterDisplacement);
3045 dcnt = IVAL(inbuf, smb_nts_DataCount);
3046 ddisp = IVAL(inbuf, smb_nts_DataDisplacement);
3047 doff = IVAL(inbuf, smb_nts_DataOffset);
3049 state->received_param += pcnt;
3050 state->received_data += dcnt;
3052 if ((state->received_data > state->total_data) ||
3053 (state->received_param > state->total_param))
3057 if (pdisp+pcnt > state->total_param)
3059 if ((pdisp+pcnt < pdisp) || (pdisp+pcnt < pcnt))
3061 if (pdisp > state->total_param)
3063 if ((smb_base(inbuf) + poff + pcnt > inbuf + size) ||
3064 (smb_base(inbuf) + poff + pcnt < smb_base(inbuf)))
3066 if (state->param + pdisp < state->param)
3069 memcpy(state->param+pdisp,smb_base(inbuf)+poff,
3074 if (ddisp+dcnt > state->total_data)
3076 if ((ddisp+dcnt < ddisp) || (ddisp+dcnt < dcnt))
3078 if (ddisp > state->total_data)
3080 if ((smb_base(inbuf) + doff + dcnt > inbuf + size) ||
3081 (smb_base(inbuf) + doff + dcnt < smb_base(inbuf)))
3083 if (state->data + ddisp < state->data)
3086 memcpy(state->data+ddisp, smb_base(inbuf)+doff,
3090 if ((state->received_param < state->total_param) ||
3091 (state->received_data < state->total_data)) {
3092 END_PROFILE(SMBnttranss);
3096 /* construct_reply_common has done us the favor to pre-fill the
3097 * command field with SMBnttranss which is wrong :-)
3099 SCVAL(outbuf,smb_com,SMBnttrans);
3101 outsize = handle_nttrans(conn, state, inbuf, outbuf,
3104 DLIST_REMOVE(conn->pending_trans, state);
3105 SAFE_FREE(state->data);
3106 SAFE_FREE(state->param);
3110 END_PROFILE(SMBnttranss);
3111 return(ERROR_DOS(ERRSRV,ERRnosupport));
3114 END_PROFILE(SMBnttranss);
3119 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3120 DLIST_REMOVE(conn->pending_trans, state);
3121 SAFE_FREE(state->data);
3122 SAFE_FREE(state->param);
3124 END_PROFILE(SMBnttranss);
3125 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);