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[] = {
49 static char *nttrans_realloc(char **ptr, size_t size)
52 smb_panic("nttrans_realloc() called with NULL ptr\n");
55 *ptr = SMB_REALLOC(*ptr, size);
59 memset(*ptr,'\0',size);
63 /****************************************************************************
64 Send the required number of replies back.
65 We assume all fields other than the data fields are
66 set correctly for the type of call.
67 HACK ! Always assumes smb_setup field is zero.
68 ****************************************************************************/
70 static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, NTSTATUS nt_error, char *params,
71 int paramsize, char *pdata, int datasize)
73 int data_to_send = datasize;
74 int params_to_send = paramsize;
78 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
79 int alignment_offset = 3;
80 int data_alignment_offset = 0;
83 * Initially set the wcnt area to be 18 - this is true for all
87 set_message(outbuf,18,0,True);
89 if (NT_STATUS_V(nt_error)) {
94 * If there genuinely are no parameters or data to send just send
98 if(params_to_send == 0 && data_to_send == 0) {
100 if (!send_smb(smbd_server_fd(),outbuf)) {
101 exit_server("send_nt_replies: send_smb failed.");
107 * When sending params and data ensure that both are nicely aligned.
108 * Only do this alignment when there is also data to send - else
109 * can cause NT redirector problems.
112 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
113 data_alignment_offset = 4 - (params_to_send % 4);
117 * Space is bufsize minus Netbios over TCP header minus SMB header.
118 * The alignment_offset is to align the param bytes on a four byte
119 * boundary (2 bytes for data len, one byte pad).
120 * NT needs this to work correctly.
123 useable_space = bufsize - ((smb_buf(outbuf)+
124 alignment_offset+data_alignment_offset) -
128 * useable_space can never be more than max_send minus the
132 useable_space = MIN(useable_space,
133 max_send - (alignment_offset+data_alignment_offset));
136 while (params_to_send || data_to_send) {
139 * Calculate whether we will totally or partially fill this packet.
142 total_sent_thistime = params_to_send + data_to_send +
143 alignment_offset + data_alignment_offset;
146 * We can never send more than useable_space.
149 total_sent_thistime = MIN(total_sent_thistime, useable_space);
151 set_message(outbuf, 18, total_sent_thistime, True);
154 * Set total params and data to be sent.
157 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
158 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
161 * Calculate how many parameters and data we can fit into
162 * this packet. Parameters get precedence.
165 params_sent_thistime = MIN(params_to_send,useable_space);
166 data_sent_thistime = useable_space - params_sent_thistime;
167 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
169 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
171 if(params_sent_thistime == 0) {
172 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
173 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
176 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
177 * parameter bytes, however the first 4 bytes of outbuf are
178 * the Netbios over TCP header. Thus use smb_base() to subtract
179 * them from the calculation.
182 SIVAL(outbuf,smb_ntr_ParameterOffset,
183 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
185 * Absolute displacement of param bytes sent in this packet.
188 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
192 * Deal with the data portion.
195 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
197 if(data_sent_thistime == 0) {
198 SIVAL(outbuf,smb_ntr_DataOffset,0);
199 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
202 * The offset of the data bytes is the offset of the
203 * parameter bytes plus the number of parameters being sent this time.
206 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
207 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
208 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
212 * Copy the param bytes into the packet.
215 if(params_sent_thistime) {
216 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
220 * Copy in the data bytes
223 if(data_sent_thistime) {
224 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
225 data_alignment_offset,pd,data_sent_thistime);
228 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
229 params_sent_thistime, data_sent_thistime, useable_space));
230 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
231 params_to_send, data_to_send, paramsize, datasize));
233 /* Send the packet */
235 if (!send_smb(smbd_server_fd(),outbuf)) {
236 exit_server("send_nt_replies: send_smb failed.");
239 pp += params_sent_thistime;
240 pd += data_sent_thistime;
242 params_to_send -= params_sent_thistime;
243 data_to_send -= data_sent_thistime;
249 if(params_to_send < 0 || data_to_send < 0) {
250 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
251 params_to_send, data_to_send));
259 /****************************************************************************
260 Is it an NTFS stream name ?
261 ****************************************************************************/
263 BOOL is_ntfs_stream_name(const char *fname)
265 if (lp_posix_pathnames()) {
268 return (strchr_m(fname, ':') != NULL) ? True : False;
271 /****************************************************************************
273 ****************************************************************************/
275 static BOOL saved_case_sensitive;
276 static BOOL saved_case_preserve;
277 static BOOL saved_short_case_preserve;
279 /****************************************************************************
281 ****************************************************************************/
283 static void set_posix_case_semantics(connection_struct *conn, uint32 file_attributes)
285 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
289 saved_case_sensitive = conn->case_sensitive;
290 saved_case_preserve = conn->case_preserve;
291 saved_short_case_preserve = conn->short_case_preserve;
294 conn->case_sensitive = True;
295 conn->case_preserve = True;
296 conn->short_case_preserve = True;
299 /****************************************************************************
300 Restore case semantics.
301 ****************************************************************************/
303 static void restore_case_semantics(connection_struct *conn, uint32 file_attributes)
305 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
309 conn->case_sensitive = saved_case_sensitive;
310 conn->case_preserve = saved_case_preserve;
311 conn->short_case_preserve = saved_short_case_preserve;
314 /****************************************************************************
315 Reply to an NT create and X call on a pipe.
316 ****************************************************************************/
318 static int nt_open_pipe(char *fname, connection_struct *conn,
319 char *inbuf, char *outbuf, int *ppnum)
321 smb_np_struct *p = NULL;
322 uint16 vuid = SVAL(inbuf, smb_uid);
325 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
327 /* See if it is one we want to handle. */
329 if (lp_disable_spoolss() && strequal(fname, "\\spoolss")) {
330 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
333 for( i = 0; known_nt_pipes[i]; i++ ) {
334 if( strequal(fname,known_nt_pipes[i])) {
339 if ( known_nt_pipes[i] == NULL ) {
340 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
343 /* Strip \\ off the name. */
346 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
348 p = open_rpc_pipe_p(fname, conn, vuid);
350 return(ERROR_DOS(ERRSRV,ERRnofids));
357 /****************************************************************************
358 Reply to an NT create and X call for pipes.
359 ****************************************************************************/
361 static int do_ntcreate_pipe_open(connection_struct *conn,
362 char *inbuf,char *outbuf,int length,int bufsize)
369 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
371 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
376 * Deal with pipe return.
379 set_message(outbuf,34,0,True);
381 p = outbuf + smb_vwv2;
385 SIVAL(p,0,FILE_WAS_OPENED);
388 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
391 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
393 SSVAL(p,2, 0x5FF); /* ? */
395 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
397 return chain_reply(inbuf,outbuf,length,bufsize);
400 /****************************************************************************
401 Reply to an NT create and X call for a quota file.
402 ****************************************************************************/
404 int reply_ntcreate_and_X_quota(connection_struct *conn,
409 enum FAKE_FILE_TYPE fake_file_type,
414 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
415 files_struct *fsp = open_fake_file(conn, fake_file_type, fname, desired_access);
418 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
421 set_message(outbuf,34,0,True);
423 p = outbuf + smb_vwv2;
425 /* SCVAL(p,0,NO_OPLOCK_RETURN); */
427 SSVAL(p,0,fsp->fnum);
430 SIVAL(p,0,smb_action);
434 put_long_date(p,c_time);
436 put_long_date(p,sbuf.st_atime); /* access time */
438 put_long_date(p,sbuf.st_mtime); /* write time */
440 put_long_date(p,sbuf.st_mtime); /* change time */
442 SIVAL(p,0,fattr); /* File Attributes. */
444 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
446 SOFF_T(p,0,file_len);
448 if (flags & EXTENDED_RESPONSE_REQUIRED)
451 SCVAL(p,0,fsp->is_directory ? 1 : 0);
454 DEBUG(5,("reply_ntcreate_and_X_quota: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
456 result = chain_reply(inbuf,outbuf,length,bufsize);
460 /****************************************************************************
461 Reply to an NT create and X call.
462 ****************************************************************************/
464 int reply_ntcreate_and_X(connection_struct *conn,
465 char *inbuf,char *outbuf,int length,int bufsize)
469 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
470 uint32 access_mask = IVAL(inbuf,smb_ntcreate_DesiredAccess);
471 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
472 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
473 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
474 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
475 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
476 /* Breakout the oplock request bits so we can set the
477 reply bits separately. */
478 int oplock_request = 0;
480 SMB_OFF_T file_len = 0;
481 SMB_STRUCT_STAT sbuf;
483 BOOL bad_path = False;
484 files_struct *fsp=NULL;
487 BOOL extended_oplock_granted = False;
490 START_PROFILE(SMBntcreateX);
492 DEBUG(10,("reply_ntcreateX: flags = 0x%x, access_mask = 0x%x \
493 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
494 create_options = 0x%x root_dir_fid = 0x%x\n",
496 (unsigned int)access_mask,
497 (unsigned int)file_attributes,
498 (unsigned int)share_access,
499 (unsigned int)create_disposition,
500 (unsigned int)create_options,
501 (unsigned int)root_dir_fid ));
503 /* If it's an IPC, use the pipe handler. */
506 if (lp_nt_pipe_support()) {
507 END_PROFILE(SMBntcreateX);
508 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
510 END_PROFILE(SMBntcreateX);
511 return(ERROR_DOS(ERRDOS,ERRnoaccess));
515 if (create_options & FILE_OPEN_BY_FILE_ID) {
516 END_PROFILE(SMBntcreateX);
517 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
524 if(root_dir_fid != 0) {
526 * This filename is relative to a directory fid.
529 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
533 END_PROFILE(SMBntcreateX);
534 return(ERROR_DOS(ERRDOS,ERRbadfid));
537 if(!dir_fsp->is_directory) {
539 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
540 if (!NT_STATUS_IS_OK(status)) {
541 END_PROFILE(SMBntcreateX);
542 return ERROR_NT(status);
546 * Check to see if this is a mac fork of some kind.
549 if( is_ntfs_stream_name(fname)) {
550 END_PROFILE(SMBntcreateX);
551 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
555 we need to handle the case when we get a
556 relative open relative to a file and the
557 pathname is blank - this is a reopen!
558 (hint from demyn plantenberg)
561 END_PROFILE(SMBntcreateX);
562 return(ERROR_DOS(ERRDOS,ERRbadfid));
566 * Copy in the base directory name.
569 pstrcpy( fname, dir_fsp->fsp_name );
570 dir_name_len = strlen(fname);
573 * Ensure it ends in a '\'.
576 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
581 srvstr_get_path(inbuf, rel_fname, smb_buf(inbuf), sizeof(rel_fname), 0, STR_TERMINATE, &status);
582 if (!NT_STATUS_IS_OK(status)) {
583 END_PROFILE(SMBntcreateX);
584 return ERROR_NT(status);
586 pstrcat(fname, rel_fname);
588 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
589 if (!NT_STATUS_IS_OK(status)) {
590 END_PROFILE(SMBntcreateX);
591 return ERROR_NT(status);
595 * Check to see if this is a mac fork of some kind.
598 if( is_ntfs_stream_name(fname)) {
599 enum FAKE_FILE_TYPE fake_file_type = is_fake_file(fname);
600 if (fake_file_type!=FAKE_FILE_TYPE_NONE) {
602 * Here we go! support for changing the disk quotas --metze
604 * We need to fake up to open this MAGIC QUOTA file
605 * and return a valid FID.
607 * w2k close this file directly after openening
608 * xp also tries a QUERY_FILE_INFO on the file and then close it
610 result = reply_ntcreate_and_X_quota(conn, inbuf, outbuf, length, bufsize,
611 fake_file_type, fname);
612 END_PROFILE(SMBntcreateX);
615 END_PROFILE(SMBntcreateX);
616 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
622 * Now contruct the smb_open_mode value from the filename,
623 * desired access and the share access.
625 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
627 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
628 if (oplock_request) {
629 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
633 * Ordinary file or directory.
637 * Check if POSIX semantics are wanted.
640 set_posix_case_semantics(conn, file_attributes);
642 unix_convert(fname,conn,0,&bad_path,&sbuf);
645 restore_case_semantics(conn, file_attributes);
646 END_PROFILE(SMBntcreateX);
647 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
649 /* All file access must go through check_name() */
650 if (!check_name(fname,conn)) {
651 restore_case_semantics(conn, file_attributes);
652 END_PROFILE(SMBntcreateX);
653 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
657 /* This is the correct thing to do (check every time) but can_delete is
658 expensive (it may have to read the parent directory permissions). So
659 for now we're not doing it unless we have a strong hint the client
660 is really going to delete this file. */
661 if (desired_access & DELETE_ACCESS) {
663 /* Setting FILE_SHARE_DELETE is the hint. */
664 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE)
665 && (access_mask & DELETE_ACCESS)) {
667 status = can_delete(conn, fname, file_attributes, bad_path, True);
668 /* We're only going to fail here if it's access denied, as that's the
669 only error we care about for "can we delete this ?" questions. */
670 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
671 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
672 restore_case_semantics(conn, file_attributes);
673 END_PROFILE(SMBntcreateX);
674 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
679 * If it's a request for a directory open, deal with it separately.
682 if(create_options & FILE_DIRECTORY_FILE) {
685 /* Can't open a temp directory. IFS kit test. */
686 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
687 END_PROFILE(SMBntcreateX);
688 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
691 fsp = open_directory(conn, fname, &sbuf,
698 restore_case_semantics(conn, file_attributes);
701 END_PROFILE(SMBntcreateX);
702 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
706 * Ordinary file case.
709 /* NB. We have a potential bug here. If we
710 * cause an oplock break to ourselves, then we
711 * could end up processing filename related
712 * SMB requests whilst we await the oplock
713 * break response. As we may have changed the
714 * filename case semantics to be POSIX-like,
715 * this could mean a filename request could
716 * fail when it should succeed. This is a rare
717 * condition, but eventually we must arrange
718 * to restore the correct case semantics
719 * before issuing an oplock break request to
720 * our client. JRA. */
722 fsp = open_file_ntcreate(conn,fname,&sbuf,
731 /* We cheat here. There are two cases we
732 * care about. One is a directory rename,
733 * where the NT client will attempt to
734 * open the source directory for
735 * DELETE access. Note that when the
736 * NT client does this it does *not*
737 * set the directory bit in the
738 * request packet. This is translated
739 * into a read/write open
740 * request. POSIX states that any open
741 * for write request on a directory
742 * will generate an EISDIR error, so
743 * we can catch this here and open a
744 * pseudo handle that is flagged as a
745 * directory. The second is an open
746 * for a permissions read only, which
747 * we handle in the open_file_stat case. JRA.
750 if(errno == EISDIR) {
753 * Fail the open if it was explicitly a non-directory file.
756 if (create_options & FILE_NON_DIRECTORY_FILE) {
757 restore_case_semantics(conn, file_attributes);
758 END_PROFILE(SMBntcreateX);
759 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
763 fsp = open_directory(conn, fname, &sbuf,
771 restore_case_semantics(conn, file_attributes);
772 END_PROFILE(SMBntcreateX);
773 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
777 restore_case_semantics(conn, file_attributes);
778 END_PROFILE(SMBntcreateX);
779 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
780 /* We have re-scheduled this call. */
783 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
788 restore_case_semantics(conn, file_attributes);
790 file_len = sbuf.st_size;
791 fattr = dos_mode(conn,fname,&sbuf);
793 fattr = FILE_ATTRIBUTE_NORMAL;
795 if (!fsp->is_directory && (fattr & aDIR)) {
796 close_file(fsp,ERROR_CLOSE);
797 END_PROFILE(SMBntcreateX);
798 return ERROR_DOS(ERRDOS,ERRnoaccess);
801 /* Save the requested allocation size. */
802 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
803 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
804 #ifdef LARGE_SMB_OFF_T
805 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
807 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
808 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
809 if (fsp->is_directory) {
810 close_file(fsp,ERROR_CLOSE);
811 END_PROFILE(SMBntcreateX);
812 /* Can't set allocation size on a directory. */
813 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
815 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
816 close_file(fsp,ERROR_CLOSE);
817 END_PROFILE(SMBntcreateX);
818 return ERROR_NT(NT_STATUS_DISK_FULL);
821 fsp->initial_allocation_size = smb_roundup(fsp->conn,(SMB_BIG_UINT)file_len);
826 * If the caller set the extended oplock request bit
827 * and we granted one (by whatever means) - set the
828 * correct bit for extended oplock reply.
831 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
832 extended_oplock_granted = True;
835 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
836 extended_oplock_granted = True;
840 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
841 set_message(outbuf,42,0,True);
843 set_message(outbuf,34,0,True);
846 p = outbuf + smb_vwv2;
849 * Currently as we don't support level II oplocks we just report
850 * exclusive & batch here.
853 if (extended_oplock_granted) {
854 if (flags & REQUEST_BATCH_OPLOCK) {
855 SCVAL(p,0, BATCH_OPLOCK_RETURN);
857 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
859 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
860 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
862 SCVAL(p,0,NO_OPLOCK_RETURN);
866 SSVAL(p,0,fsp->fnum);
868 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
869 SIVAL(p,0,FILE_WAS_SUPERSEDED);
876 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
878 if (lp_dos_filetime_resolution(SNUM(conn))) {
885 put_long_date(p,c_time);
887 put_long_date(p,sbuf.st_atime); /* access time */
889 put_long_date(p,sbuf.st_mtime); /* write time */
891 put_long_date(p,sbuf.st_mtime); /* change time */
893 SIVAL(p,0,fattr); /* File Attributes. */
895 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
897 SOFF_T(p,0,file_len);
899 if (flags & EXTENDED_RESPONSE_REQUIRED) {
903 SCVAL(p,0,fsp->is_directory ? 1 : 0);
905 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
907 result = chain_reply(inbuf,outbuf,length,bufsize);
908 END_PROFILE(SMBntcreateX);
912 /****************************************************************************
913 Reply to a NT_TRANSACT_CREATE call to open a pipe.
914 ****************************************************************************/
916 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
917 char **ppsetup, uint32 setup_count,
918 char **ppparams, uint32 parameter_count,
919 char **ppdata, uint32 data_count)
922 char *params = *ppparams;
929 * Ensure minimum number of parameters sent.
932 if(parameter_count < 54) {
933 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
934 return ERROR_DOS(ERRDOS,ERRnoaccess);
937 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
938 if (!NT_STATUS_IS_OK(status)) {
939 return ERROR_NT(status);
942 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
946 /* Realloc the size of parameters and data we will return */
947 params = nttrans_realloc(ppparams, 69);
949 return ERROR_DOS(ERRDOS,ERRnomem);
953 SCVAL(p,0,NO_OPLOCK_RETURN);
958 SIVAL(p,0,FILE_WAS_OPENED);
962 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
965 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
967 SSVAL(p,2, 0x5FF); /* ? */
969 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
971 /* Send the required number of replies */
972 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
977 /****************************************************************************
978 Internal fn to set security descriptors.
979 ****************************************************************************/
981 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
984 SEC_DESC *psd = NULL;
988 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
993 * Init the parse struct we will unmarshall from.
996 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
997 DEBUG(0,("set_sd: talloc_init failed.\n"));
998 return NT_STATUS_NO_MEMORY;
1001 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1004 * Setup the prs_struct to point at the memory we just
1008 prs_give_memory( &pd, data, sd_len, False);
1011 * Finally, unmarshall from the data buffer.
1014 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1015 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1017 * Return access denied for want of a better error message..
1019 talloc_destroy(mem_ctx);
1020 return NT_STATUS_NO_MEMORY;
1023 if (psd->off_owner_sid==0) {
1024 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1026 if (psd->off_grp_sid==0) {
1027 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1029 if (psd->off_sacl==0) {
1030 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1032 if (psd->off_dacl==0) {
1033 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1036 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fh->fd, security_info_sent, psd);
1039 talloc_destroy(mem_ctx);
1040 return NT_STATUS_ACCESS_DENIED;
1043 talloc_destroy(mem_ctx);
1045 return NT_STATUS_OK;
1048 /****************************************************************************
1049 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1050 ****************************************************************************/
1052 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
1054 struct ea_list *ea_list_head = NULL;
1057 if (data_size < 4) {
1061 while (offset + 4 <= data_size) {
1062 size_t next_offset = IVAL(pdata,offset);
1063 struct ea_list *tmp;
1064 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
1066 DLIST_ADD_END(ea_list_head, eal, tmp);
1067 if (next_offset == 0) {
1070 offset += next_offset;
1073 return ea_list_head;
1076 /****************************************************************************
1077 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1078 ****************************************************************************/
1080 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1081 char **ppsetup, uint32 setup_count,
1082 char **ppparams, uint32 parameter_count,
1083 char **ppdata, uint32 data_count, uint32 max_data_count)
1086 char *params = *ppparams;
1087 char *data = *ppdata;
1088 /* Breakout the oplock request bits so we can set the reply bits separately. */
1089 int oplock_request = 0;
1091 SMB_OFF_T file_len = 0;
1092 SMB_STRUCT_STAT sbuf;
1094 BOOL bad_path = False;
1095 files_struct *fsp = NULL;
1097 BOOL extended_oplock_granted = False;
1100 uint32 file_attributes;
1101 uint32 share_access;
1102 uint32 create_disposition;
1103 uint32 create_options;
1106 uint16 root_dir_fid;
1108 struct ea_list *ea_list = NULL;
1109 TALLOC_CTX *ctx = NULL;
1113 DEBUG(5,("call_nt_transact_create\n"));
1116 * If it's an IPC, use the pipe handler.
1120 if (lp_nt_pipe_support()) {
1121 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1123 ppsetup, setup_count,
1124 ppparams, parameter_count,
1125 ppdata, data_count);
1127 return ERROR_DOS(ERRDOS,ERRnoaccess);
1132 * Ensure minimum number of parameters sent.
1135 if(parameter_count < 54) {
1136 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1137 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1140 flags = IVAL(params,0);
1141 access_mask = IVAL(params,8);
1142 file_attributes = IVAL(params,20);
1143 share_access = IVAL(params,24);
1144 create_disposition = IVAL(params,28);
1145 create_options = IVAL(params,32);
1146 sd_len = IVAL(params,36);
1147 ea_len = IVAL(params,40);
1148 root_dir_fid = (uint16)IVAL(params,4);
1150 /* Ensure the data_len is correct for the sd and ea values given. */
1151 if ((ea_len + sd_len > data_count) ||
1152 (ea_len > data_count) || (sd_len > data_count) ||
1153 (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
1154 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1155 (unsigned int)ea_len, (unsigned int)sd_len, (unsigned int)data_count ));
1156 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1160 if (!lp_ea_support(SNUM(conn))) {
1161 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1162 (unsigned int)ea_len ));
1163 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
1167 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1168 (unsigned int)ea_len ));
1169 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1173 if (create_options & FILE_OPEN_BY_FILE_ID) {
1174 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1178 * Get the file name.
1181 if(root_dir_fid != 0) {
1183 * This filename is relative to a directory fid.
1185 files_struct *dir_fsp = file_fsp(params,4);
1186 size_t dir_name_len;
1189 return ERROR_DOS(ERRDOS,ERRbadfid);
1192 if(!dir_fsp->is_directory) {
1193 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1194 if (!NT_STATUS_IS_OK(status)) {
1195 return ERROR_NT(status);
1199 * Check to see if this is a mac fork of some kind.
1202 if( is_ntfs_stream_name(fname)) {
1203 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1206 return ERROR_DOS(ERRDOS,ERRbadfid);
1210 * Copy in the base directory name.
1213 pstrcpy( fname, dir_fsp->fsp_name );
1214 dir_name_len = strlen(fname);
1217 * Ensure it ends in a '\'.
1220 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1221 pstrcat(fname, "/");
1227 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status);
1228 if (!NT_STATUS_IS_OK(status)) {
1229 return ERROR_NT(status);
1231 pstrcat(fname, tmpname);
1234 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1235 if (!NT_STATUS_IS_OK(status)) {
1236 return ERROR_NT(status);
1240 * Check to see if this is a mac fork of some kind.
1243 if( is_ntfs_stream_name(fname)) {
1244 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1248 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1249 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1252 * Check if POSIX semantics are wanted.
1255 set_posix_case_semantics(conn, file_attributes);
1257 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1259 unix_convert(fname,conn,0,&bad_path,&sbuf);
1261 restore_case_semantics(conn, file_attributes);
1262 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1264 /* All file access must go through check_name() */
1265 if (!check_name(fname,conn)) {
1266 restore_case_semantics(conn, file_attributes);
1267 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
1271 /* This is the correct thing to do (check every time) but can_delete is
1272 expensive (it may have to read the parent directory permissions). So
1273 for now we're not doing it unless we have a strong hint the client
1274 is really going to delete this file. */
1275 if (desired_access & DELETE_ACCESS) {
1277 /* Setting FILE_SHARE_DELETE is the hint. */
1278 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE) && (access_mask & DELETE_ACCESS)) {
1280 status = can_delete(conn, fname, file_attributes, bad_path, True);
1281 /* We're only going to fail here if it's access denied, as that's the
1282 only error we care about for "can we delete this ?" questions. */
1283 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
1284 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
1285 restore_case_semantics(conn, file_attributes);
1286 return ERROR_NT(status);
1291 ctx = talloc_init("NTTRANS_CREATE_EA");
1293 talloc_destroy(ctx);
1294 restore_case_semantics(conn, file_attributes);
1295 return ERROR_NT(NT_STATUS_NO_MEMORY);
1298 pdata = data + sd_len;
1300 /* We have already checked that ea_len <= data_count here. */
1301 ea_list = read_nttrans_ea_list(ctx, pdata, ea_len);
1303 talloc_destroy(ctx);
1304 restore_case_semantics(conn, file_attributes);
1305 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1310 * If it's a request for a directory open, deal with it separately.
1313 if(create_options & FILE_DIRECTORY_FILE) {
1315 /* Can't open a temp directory. IFS kit test. */
1316 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1317 talloc_destroy(ctx);
1318 restore_case_semantics(conn, file_attributes);
1319 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1325 * We will get a create directory here if the Win32
1326 * app specified a security descriptor in the
1327 * CreateDirectory() call.
1330 fsp = open_directory(conn, fname, &sbuf,
1337 talloc_destroy(ctx);
1338 restore_case_semantics(conn, file_attributes);
1339 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1345 * Ordinary file case.
1348 fsp = open_file_ntcreate(conn,fname,&sbuf,
1358 if(errno == EISDIR) {
1361 * Fail the open if it was explicitly a non-directory file.
1364 if (create_options & FILE_NON_DIRECTORY_FILE) {
1365 restore_case_semantics(conn, file_attributes);
1366 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1370 fsp = open_directory(conn, fname, &sbuf,
1377 talloc_destroy(ctx);
1378 restore_case_semantics(conn, file_attributes);
1379 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1382 talloc_destroy(ctx);
1383 restore_case_semantics(conn, file_attributes);
1384 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1385 /* We have re-scheduled this call. */
1388 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1394 * According to the MS documentation, the only time the security
1395 * descriptor is applied to the opened file is iff we *created* the
1396 * file; an existing file stays the same.
1398 * Also, it seems (from observation) that you can open the file with
1399 * any access mask but you can still write the sd. We need to override
1400 * the granted access before we call set_sd
1401 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1404 if (lp_nt_acl_support(SNUM(conn)) && sd_len && info == FILE_WAS_CREATED) {
1405 uint32 saved_access_mask = fsp->access_mask;
1407 /* We have already checked that sd_len <= data_count here. */
1409 fsp->access_mask = FILE_GENERIC_ALL;
1411 status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION);
1412 if (!NT_STATUS_IS_OK(status)) {
1413 talloc_destroy(ctx);
1414 close_file(fsp,ERROR_CLOSE);
1415 restore_case_semantics(conn, file_attributes);
1416 return ERROR_NT(status);
1418 fsp->access_mask = saved_access_mask;
1421 if (ea_len && (info == FILE_WAS_CREATED)) {
1422 status = set_ea(conn, fsp, fname, ea_list);
1423 talloc_destroy(ctx);
1424 if (!NT_STATUS_IS_OK(status)) {
1425 close_file(fsp,ERROR_CLOSE);
1426 restore_case_semantics(conn, file_attributes);
1427 return ERROR_NT(status);
1431 restore_case_semantics(conn, file_attributes);
1433 file_len = sbuf.st_size;
1434 fattr = dos_mode(conn,fname,&sbuf);
1436 fattr = FILE_ATTRIBUTE_NORMAL;
1438 if (!fsp->is_directory && (fattr & aDIR)) {
1439 close_file(fsp,ERROR_CLOSE);
1440 return ERROR_DOS(ERRDOS,ERRnoaccess);
1443 /* Save the requested allocation size. */
1444 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
1445 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1446 #ifdef LARGE_SMB_OFF_T
1447 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1449 if (allocation_size && (allocation_size > file_len)) {
1450 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
1451 if (fsp->is_directory) {
1452 close_file(fsp,ERROR_CLOSE);
1453 /* Can't set allocation size on a directory. */
1454 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1456 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1457 close_file(fsp,ERROR_CLOSE);
1458 return ERROR_NT(NT_STATUS_DISK_FULL);
1461 fsp->initial_allocation_size = smb_roundup(fsp->conn, (SMB_BIG_UINT)file_len);
1466 * If the caller set the extended oplock request bit
1467 * and we granted one (by whatever means) - set the
1468 * correct bit for extended oplock reply.
1471 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
1472 extended_oplock_granted = True;
1475 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
1476 extended_oplock_granted = True;
1479 /* Realloc the size of parameters and data we will return */
1480 params = nttrans_realloc(ppparams, 69);
1481 if(params == NULL) {
1482 return ERROR_DOS(ERRDOS,ERRnomem);
1486 if (extended_oplock_granted) {
1487 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1488 } else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
1489 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1491 SCVAL(p,0,NO_OPLOCK_RETURN);
1495 SSVAL(p,0,fsp->fnum);
1497 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
1498 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1505 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1507 if (lp_dos_filetime_resolution(SNUM(conn))) {
1509 sbuf.st_atime &= ~1;
1510 sbuf.st_mtime &= ~1;
1511 sbuf.st_mtime &= ~1;
1514 put_long_date(p,c_time);
1516 put_long_date(p,sbuf.st_atime); /* access time */
1518 put_long_date(p,sbuf.st_mtime); /* write time */
1520 put_long_date(p,sbuf.st_mtime); /* change time */
1522 SIVAL(p,0,fattr); /* File Attributes. */
1524 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1526 SOFF_T(p,0,file_len);
1528 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1532 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1534 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1536 /* Send the required number of replies */
1537 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1542 /****************************************************************************
1543 Reply to a NT CANCEL request.
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 fsp1 = 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,
1663 status = get_saved_ntstatus();
1664 if (NT_STATUS_IS_OK(status)) {
1665 status = NT_STATUS_ACCESS_DENIED;
1667 set_saved_ntstatus(NT_STATUS_OK);
1671 fsp2 = open_file_ntcreate(conn,newname,&sbuf2,
1672 FILE_WRITE_DATA, /* Write-only. */
1673 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1675 0, /* No create options. */
1681 status = get_saved_ntstatus();
1682 if (NT_STATUS_IS_OK(status)) {
1683 status = NT_STATUS_ACCESS_DENIED;
1685 set_saved_ntstatus(NT_STATUS_OK);
1686 close_file(fsp1,ERROR_CLOSE);
1690 if (sbuf1.st_size) {
1691 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1695 * As we are opening fsp1 read-only we only expect
1696 * an error on close on fsp2 if we are out of space.
1697 * Thus we don't look at the error return from the
1700 close_file(fsp1,NORMAL_CLOSE);
1702 /* Ensure the modtime is set correctly on the destination file. */
1703 fsp_set_pending_modtime(fsp2, sbuf1.st_mtime);
1705 close_ret = close_file(fsp2,NORMAL_CLOSE);
1707 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1708 creates the file. This isn't the correct thing to do in the copy
1710 file_set_dosmode(conn, newname, fattr, &sbuf2, True);
1712 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1713 return NT_STATUS_DISK_FULL;
1716 if (close_ret != 0) {
1717 status = map_nt_error_from_unix(close_ret);
1718 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1719 nt_errstr(status), oldname, newname));
1724 /****************************************************************************
1725 Reply to a NT rename request.
1726 ****************************************************************************/
1728 int reply_ntrename(connection_struct *conn,
1729 char *inbuf,char *outbuf,int length,int bufsize)
1736 BOOL path_contains_wcard = False;
1737 uint32 attrs = SVAL(inbuf,smb_vwv0);
1738 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1740 START_PROFILE(SMBntrename);
1742 p = smb_buf(inbuf) + 1;
1743 p += srvstr_get_path_wcard(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, &path_contains_wcard);
1744 if (!NT_STATUS_IS_OK(status)) {
1745 END_PROFILE(SMBntrename);
1746 return ERROR_NT(status);
1749 if( is_ntfs_stream_name(oldname)) {
1750 /* Can't rename a stream. */
1751 END_PROFILE(SMBntrename);
1752 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1755 if (ms_has_wild(oldname)) {
1756 END_PROFILE(SMBntrename);
1757 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1761 p += srvstr_get_path(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status);
1762 if (!NT_STATUS_IS_OK(status)) {
1763 END_PROFILE(SMBntrename);
1764 return ERROR_NT(status);
1767 RESOLVE_DFSPATH(oldname, conn, inbuf, outbuf);
1768 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1770 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1772 switch(rename_type) {
1773 case RENAME_FLAG_RENAME:
1774 status = rename_internals(conn, oldname, newname, attrs, False, path_contains_wcard);
1776 case RENAME_FLAG_HARD_LINK:
1777 status = hardlink_internals(conn, oldname, newname);
1779 case RENAME_FLAG_COPY:
1780 if (path_contains_wcard) {
1782 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1784 status = copy_internals(conn, oldname, newname, attrs);
1787 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1788 status = NT_STATUS_INVALID_PARAMETER;
1791 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1795 if (!NT_STATUS_IS_OK(status)) {
1796 END_PROFILE(SMBntrename);
1797 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1798 /* We have re-scheduled this call. */
1801 return ERROR_NT(status);
1805 * Win2k needs a changenotify request response before it will
1806 * update after a rename..
1808 process_pending_change_notify_queue((time_t)0);
1809 outsize = set_message(outbuf,0,0,False);
1811 END_PROFILE(SMBntrename);
1815 /****************************************************************************
1816 Reply to a notify change - queue the request and
1817 don't allow a directory to be opened.
1818 ****************************************************************************/
1820 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1821 char **ppsetup, uint32 setup_count,
1822 char **ppparams, uint32 parameter_count,
1823 char **ppdata, uint32 data_count, uint32 max_data_count)
1825 char *setup = *ppsetup;
1829 if(setup_count < 6) {
1830 return ERROR_DOS(ERRDOS,ERRbadfunc);
1833 fsp = file_fsp(setup,4);
1834 flags = IVAL(setup, 0);
1836 DEBUG(3,("call_nt_transact_notify_change\n"));
1839 return ERROR_DOS(ERRDOS,ERRbadfid);
1842 if((!fsp->is_directory) || (conn != fsp->conn)) {
1843 return ERROR_DOS(ERRDOS,ERRbadfid);
1846 if (!change_notify_set(inbuf, fsp, conn, flags)) {
1847 return(UNIXERROR(ERRDOS,ERRbadfid));
1850 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1851 name = %s\n", fsp->fsp_name ));
1856 /****************************************************************************
1857 Reply to an NT transact rename command.
1858 ****************************************************************************/
1860 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1861 char **ppsetup, uint32 setup_count,
1862 char **ppparams, uint32 parameter_count,
1863 char **ppdata, uint32 data_count, uint32 max_data_count)
1865 char *params = *ppparams;
1867 files_struct *fsp = NULL;
1868 BOOL replace_if_exists = False;
1869 BOOL path_contains_wcard = False;
1872 if(parameter_count < 4) {
1873 return ERROR_DOS(ERRDOS,ERRbadfunc);
1876 fsp = file_fsp(params, 0);
1877 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1878 CHECK_FSP(fsp, conn);
1879 srvstr_get_path_wcard(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE, &status, &path_contains_wcard);
1880 if (!NT_STATUS_IS_OK(status)) {
1881 return ERROR_NT(status);
1884 status = rename_internals(conn, fsp->fsp_name,
1885 new_name, 0, replace_if_exists, path_contains_wcard);
1886 if (!NT_STATUS_IS_OK(status))
1887 return ERROR_NT(status);
1890 * Rename was successful.
1892 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1894 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1895 fsp->fsp_name, new_name));
1898 * Win2k needs a changenotify request response before it will
1899 * update after a rename..
1902 process_pending_change_notify_queue((time_t)0);
1907 /******************************************************************************
1908 Fake up a completely empty SD.
1909 *******************************************************************************/
1911 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1915 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1917 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1924 /****************************************************************************
1925 Reply to query a security descriptor.
1926 ****************************************************************************/
1928 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1929 char **ppsetup, uint32 setup_count,
1930 char **ppparams, uint32 parameter_count,
1931 char **ppdata, uint32 data_count, uint32 max_data_count)
1933 char *params = *ppparams;
1934 char *data = *ppdata;
1936 SEC_DESC *psd = NULL;
1938 uint32 security_info_wanted;
1939 TALLOC_CTX *mem_ctx;
1940 files_struct *fsp = NULL;
1942 if(parameter_count < 8) {
1943 return ERROR_DOS(ERRDOS,ERRbadfunc);
1946 fsp = file_fsp(params,0);
1948 return ERROR_DOS(ERRDOS,ERRbadfid);
1951 security_info_wanted = IVAL(params,4);
1953 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1954 (unsigned int)security_info_wanted ));
1956 params = nttrans_realloc(ppparams, 4);
1957 if(params == NULL) {
1958 return ERROR_DOS(ERRDOS,ERRnomem);
1961 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1962 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1963 return ERROR_DOS(ERRDOS,ERRnomem);
1967 * Get the permissions to return.
1970 if (!lp_nt_acl_support(SNUM(conn))) {
1971 sd_size = get_null_nt_acl(mem_ctx, &psd);
1973 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fh->fd, security_info_wanted, &psd);
1977 talloc_destroy(mem_ctx);
1978 return(UNIXERROR(ERRDOS,ERRnoaccess));
1981 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1983 SIVAL(params,0,(uint32)sd_size);
1985 if(max_data_count < sd_size) {
1987 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
1988 params, 4, *ppdata, 0);
1989 talloc_destroy(mem_ctx);
1994 * Allocate the data we will point this at.
1997 data = nttrans_realloc(ppdata, sd_size);
1999 talloc_destroy(mem_ctx);
2000 return ERROR_DOS(ERRDOS,ERRnomem);
2004 * Init the parse struct we will marshall into.
2007 prs_init(&pd, 0, mem_ctx, MARSHALL);
2010 * Setup the prs_struct to point at the memory we just
2014 prs_give_memory( &pd, data, (uint32)sd_size, False);
2017 * Finally, linearize into the outgoing buffer.
2020 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2021 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2022 security descriptor.\n"));
2024 * Return access denied for want of a better error message..
2026 talloc_destroy(mem_ctx);
2027 return(UNIXERROR(ERRDOS,ERRnoaccess));
2031 * Now we can delete the security descriptor.
2034 talloc_destroy(mem_ctx);
2036 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 4, data, (int)sd_size);
2040 /****************************************************************************
2041 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2042 ****************************************************************************/
2044 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2045 char **ppsetup, uint32 setup_count,
2046 char **ppparams, uint32 parameter_count,
2047 char **ppdata, uint32 data_count, uint32 max_data_count)
2049 char *params= *ppparams;
2050 char *data = *ppdata;
2051 files_struct *fsp = NULL;
2052 uint32 security_info_sent = 0;
2055 if(parameter_count < 8) {
2056 return ERROR_DOS(ERRDOS,ERRbadfunc);
2059 if((fsp = file_fsp(params,0)) == NULL) {
2060 return ERROR_DOS(ERRDOS,ERRbadfid);
2063 if(!lp_nt_acl_support(SNUM(conn))) {
2067 security_info_sent = IVAL(params,4);
2069 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
2070 (unsigned int)security_info_sent ));
2072 if (data_count == 0) {
2073 return ERROR_DOS(ERRDOS, ERRnoaccess);
2076 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent))) {
2077 return ERROR_NT(nt_status);
2082 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2086 /****************************************************************************
2088 ****************************************************************************/
2090 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2091 char **ppsetup, uint32 setup_count,
2092 char **ppparams, uint32 parameter_count,
2093 char **ppdata, uint32 data_count, uint32 max_data_count)
2100 static BOOL logged_message;
2101 char *pdata = *ppdata;
2103 if (setup_count != 8) {
2104 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2105 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2108 function = IVAL(*ppsetup, 0);
2109 fidnum = SVAL(*ppsetup, 4);
2110 isFSctl = CVAL(*ppsetup, 6);
2111 compfilter = CVAL(*ppsetup, 7);
2113 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2114 function, fidnum, isFSctl, compfilter));
2116 fsp=file_fsp(*ppsetup, 4);
2117 /* this check is done in each implemented function case for now
2118 because I don't want to break anything... --metze
2119 FSP_BELONGS_CONN(fsp,conn);*/
2122 case FSCTL_SET_SPARSE:
2123 /* pretend this succeeded - tho strictly we should
2124 mark the file sparse (if the local fs supports it)
2125 so we can know if we need to pre-allocate or not */
2127 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2128 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2131 case FSCTL_0x000900C0:
2132 /* pretend this succeeded - don't know what this really is
2133 but works ok like this --metze
2136 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2137 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2140 case FSCTL_GET_REPARSE_POINT:
2141 /* pretend this fail - my winXP does it like this
2145 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2146 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2149 case FSCTL_SET_REPARSE_POINT:
2150 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2154 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2155 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
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(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
2273 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2275 /* pretend this succeeded -
2277 * we have to send back a list with all files owned by this SID
2279 * but I have to check that --metze
2283 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2285 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2287 FSP_BELONGS_CONN(fsp,conn);
2289 /* unknown 4 bytes: this is not the length of the sid :-( */
2290 /*unknown = IVAL(pdata,0);*/
2292 sid_parse(pdata+4,sid_len,&sid);
2293 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2295 if (!sid_to_uid(&sid, &uid)) {
2296 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2297 sid_string_static(&sid),(unsigned long)sid_len));
2301 /* we can take a look at the find source :-)
2303 * find ./ -uid $uid -name '*' is what we need here
2306 * and send 4bytes len and then NULL terminated unicode strings
2309 * but I don't know how to deal with the paged results
2310 * (maybe we can hang the result anywhere in the fsp struct)
2312 * we don't send all files at once
2313 * and at the next we should *not* start from the beginning,
2314 * so we have to cache the result
2319 /* this works for now... */
2320 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2324 if (!logged_message) {
2325 logged_message = True; /* Only print this once... */
2326 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2331 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2335 #ifdef HAVE_SYS_QUOTAS
2336 /****************************************************************************
2337 Reply to get user quota
2338 ****************************************************************************/
2340 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2341 char **ppsetup, uint32 setup_count,
2342 char **ppparams, uint32 parameter_count,
2343 char **ppdata, uint32 data_count, uint32 max_data_count)
2345 NTSTATUS nt_status = NT_STATUS_OK;
2346 char *params = *ppparams;
2347 char *pdata = *ppdata;
2349 int data_len=0,param_len=0;
2352 files_struct *fsp = NULL;
2356 BOOL start_enum = True;
2357 SMB_NTQUOTA_STRUCT qt;
2358 SMB_NTQUOTA_LIST *tmp_list;
2359 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2360 extern struct current_user current_user;
2365 if (current_user.ut.uid != 0) {
2366 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2367 lp_servicename(SNUM(conn)),conn->user));
2368 return ERROR_DOS(ERRDOS,ERRnoaccess);
2372 * Ensure minimum number of parameters sent.
2375 if (parameter_count < 4) {
2376 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2377 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2380 /* maybe we can check the quota_fnum */
2381 fsp = file_fsp(params,0);
2382 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2383 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2384 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2387 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2388 * is done by CHECK_NTQUOTA_HANDLE_OK()
2390 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2392 level = SVAL(params,2);
2394 /* unknown 12 bytes leading in params */
2397 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2398 /* seems that we should continue with the enum here --metze */
2400 if (qt_handle->quota_list!=NULL &&
2401 qt_handle->tmp_list==NULL) {
2404 free_ntquota_list(&(qt_handle->quota_list));
2406 /* Realloc the size of parameters and data we will return */
2408 params = nttrans_realloc(ppparams, param_len);
2409 if(params == NULL) {
2410 return ERROR_DOS(ERRDOS,ERRnomem);
2414 SIVAL(params,0,data_len);
2421 case TRANSACT_GET_USER_QUOTA_LIST_START:
2423 if (qt_handle->quota_list==NULL &&
2424 qt_handle->tmp_list==NULL) {
2428 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2429 return ERROR_DOS(ERRSRV,ERRerror);
2431 /* Realloc the size of parameters and data we will return */
2433 params = nttrans_realloc(ppparams, param_len);
2434 if(params == NULL) {
2435 return ERROR_DOS(ERRDOS,ERRnomem);
2438 /* we should not trust the value in max_data_count*/
2439 max_data_count = MIN(max_data_count,2048);
2441 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2443 return ERROR_DOS(ERRDOS,ERRnomem);
2448 /* set params Size of returned Quota Data 4 bytes*/
2449 /* but set it later when we know it */
2451 /* for each entry push the data */
2454 qt_handle->tmp_list = qt_handle->quota_list;
2457 tmp_list = qt_handle->tmp_list;
2459 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2460 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2462 sid_len = sid_size(&tmp_list->quotas->sid);
2463 entry_len = 40 + sid_len;
2465 /* nextoffset entry 4 bytes */
2466 SIVAL(entry,0,entry_len);
2468 /* then the len of the SID 4 bytes */
2469 SIVAL(entry,4,sid_len);
2471 /* unknown data 8 bytes SMB_BIG_UINT */
2472 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2474 /* the used disk space 8 bytes SMB_BIG_UINT */
2475 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2477 /* the soft quotas 8 bytes SMB_BIG_UINT */
2478 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2480 /* the hard quotas 8 bytes SMB_BIG_UINT */
2481 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2483 /* and now the SID */
2484 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2487 qt_handle->tmp_list = tmp_list;
2489 /* overwrite the offset of the last entry */
2490 SIVAL(entry-entry_len,0,0);
2492 data_len = 4+qt_len;
2493 /* overwrite the params quota_data_len */
2494 SIVAL(params,0,data_len);
2498 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2500 /* unknown 4 bytes IVAL(pdata,0) */
2502 if (data_count < 8) {
2503 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2504 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2507 sid_len = IVAL(pdata,4);
2508 /* Ensure this is less than 1mb. */
2509 if (sid_len > (1024*1024)) {
2510 return ERROR_DOS(ERRDOS,ERRnomem);
2513 if (data_count < 8+sid_len) {
2514 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2515 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2518 data_len = 4+40+sid_len;
2520 if (max_data_count < data_len) {
2521 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2522 max_data_count, data_len));
2524 SIVAL(params,0,data_len);
2526 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2530 sid_parse(pdata+8,sid_len,&sid);
2532 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2535 * we have to return zero's in all fields
2536 * instead of returning an error here
2541 /* Realloc the size of parameters and data we will return */
2543 params = nttrans_realloc(ppparams, param_len);
2544 if(params == NULL) {
2545 return ERROR_DOS(ERRDOS,ERRnomem);
2548 pdata = nttrans_realloc(ppdata, data_len);
2550 return ERROR_DOS(ERRDOS,ERRnomem);
2555 /* set params Size of returned Quota Data 4 bytes*/
2556 SIVAL(params,0,data_len);
2558 /* nextoffset entry 4 bytes */
2561 /* then the len of the SID 4 bytes */
2562 SIVAL(entry,4,sid_len);
2564 /* unknown data 8 bytes SMB_BIG_UINT */
2565 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2567 /* the used disk space 8 bytes SMB_BIG_UINT */
2568 SBIG_UINT(entry,16,qt.usedspace);
2570 /* the soft quotas 8 bytes SMB_BIG_UINT */
2571 SBIG_UINT(entry,24,qt.softlim);
2573 /* the hard quotas 8 bytes SMB_BIG_UINT */
2574 SBIG_UINT(entry,32,qt.hardlim);
2576 /* and now the SID */
2577 sid_linearize(entry+40, sid_len, &sid);
2582 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2583 return ERROR_DOS(ERRSRV,ERRerror);
2587 send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
2592 /****************************************************************************
2593 Reply to set user quota
2594 ****************************************************************************/
2596 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2597 char **ppsetup, uint32 setup_count,
2598 char **ppparams, uint32 parameter_count,
2599 char **ppdata, uint32 data_count, uint32 max_data_count)
2601 char *params = *ppparams;
2602 char *pdata = *ppdata;
2603 int data_len=0,param_len=0;
2604 SMB_NTQUOTA_STRUCT qt;
2607 files_struct *fsp = NULL;
2612 if (current_user.ut.uid != 0) {
2613 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2614 lp_servicename(SNUM(conn)),conn->user));
2615 return ERROR_DOS(ERRDOS,ERRnoaccess);
2619 * Ensure minimum number of parameters sent.
2622 if (parameter_count < 2) {
2623 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2624 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2627 /* maybe we can check the quota_fnum */
2628 fsp = file_fsp(params,0);
2629 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2630 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2631 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2634 if (data_count < 40) {
2635 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2636 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2639 /* offset to next quota record.
2640 * 4 bytes IVAL(pdata,0)
2645 sid_len = IVAL(pdata,4);
2647 if (data_count < 40+sid_len) {
2648 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2649 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2652 /* unknown 8 bytes in pdata
2653 * maybe its the change time in NTTIME
2656 /* the used space 8 bytes (SMB_BIG_UINT)*/
2657 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2658 #ifdef LARGE_SMB_OFF_T
2659 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2660 #else /* LARGE_SMB_OFF_T */
2661 if ((IVAL(pdata,20) != 0)&&
2662 ((qt.usedspace != 0xFFFFFFFF)||
2663 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2664 /* more than 32 bits? */
2665 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2667 #endif /* LARGE_SMB_OFF_T */
2669 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2670 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2671 #ifdef LARGE_SMB_OFF_T
2672 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2673 #else /* LARGE_SMB_OFF_T */
2674 if ((IVAL(pdata,28) != 0)&&
2675 ((qt.softlim != 0xFFFFFFFF)||
2676 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2677 /* more than 32 bits? */
2678 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2680 #endif /* LARGE_SMB_OFF_T */
2682 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2683 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2684 #ifdef LARGE_SMB_OFF_T
2685 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2686 #else /* LARGE_SMB_OFF_T */
2687 if ((IVAL(pdata,36) != 0)&&
2688 ((qt.hardlim != 0xFFFFFFFF)||
2689 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2690 /* more than 32 bits? */
2691 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2693 #endif /* LARGE_SMB_OFF_T */
2695 sid_parse(pdata+40,sid_len,&sid);
2696 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2698 /* 44 unknown bytes left... */
2700 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2701 return ERROR_DOS(ERRSRV,ERRerror);
2704 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
2708 #endif /* HAVE_SYS_QUOTAS */
2710 static int handle_nttrans(connection_struct *conn,
2711 struct trans_state *state,
2712 char *inbuf, char *outbuf, int size, int bufsize)
2716 if (Protocol >= PROTOCOL_NT1) {
2717 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | 0x40); /* IS_LONG_NAME */
2720 /* Now we must call the relevant NT_TRANS function */
2721 switch(state->call) {
2722 case NT_TRANSACT_CREATE:
2724 START_PROFILE_NESTED(NT_transact_create);
2725 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2727 (char **)&state->setup, state->setup_count,
2728 &state->param, state->total_param,
2729 &state->data, state->total_data,
2730 state->max_data_return);
2731 END_PROFILE_NESTED(NT_transact_create);
2735 case NT_TRANSACT_IOCTL:
2737 START_PROFILE_NESTED(NT_transact_ioctl);
2738 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2740 (char **)&state->setup, state->setup_count,
2741 &state->param, state->total_param,
2742 &state->data, state->total_data, state->max_data_return);
2743 END_PROFILE_NESTED(NT_transact_ioctl);
2747 case NT_TRANSACT_SET_SECURITY_DESC:
2749 START_PROFILE_NESTED(NT_transact_set_security_desc);
2750 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2752 (char **)&state->setup, state->setup_count,
2753 &state->param, state->total_param,
2754 &state->data, state->total_data, state->max_data_return);
2755 END_PROFILE_NESTED(NT_transact_set_security_desc);
2759 case NT_TRANSACT_NOTIFY_CHANGE:
2761 START_PROFILE_NESTED(NT_transact_notify_change);
2762 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
2764 (char **)&state->setup, state->setup_count,
2765 &state->param, state->total_param,
2766 &state->data, state->total_data, state->max_data_return);
2767 END_PROFILE_NESTED(NT_transact_notify_change);
2771 case NT_TRANSACT_RENAME:
2773 START_PROFILE_NESTED(NT_transact_rename);
2774 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2776 (char **)&state->setup, state->setup_count,
2777 &state->param, state->total_param,
2778 &state->data, state->total_data, state->max_data_return);
2779 END_PROFILE_NESTED(NT_transact_rename);
2783 case NT_TRANSACT_QUERY_SECURITY_DESC:
2785 START_PROFILE_NESTED(NT_transact_query_security_desc);
2786 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
2788 (char **)&state->setup, state->setup_count,
2789 &state->param, state->total_param,
2790 &state->data, state->total_data, state->max_data_return);
2791 END_PROFILE_NESTED(NT_transact_query_security_desc);
2795 #ifdef HAVE_SYS_QUOTAS
2796 case NT_TRANSACT_GET_USER_QUOTA:
2798 START_PROFILE_NESTED(NT_transact_get_user_quota);
2799 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
2801 (char **)&state->setup, state->setup_count,
2802 &state->param, state->total_param,
2803 &state->data, state->total_data, state->max_data_return);
2804 END_PROFILE_NESTED(NT_transact_get_user_quota);
2808 case NT_TRANSACT_SET_USER_QUOTA:
2810 START_PROFILE_NESTED(NT_transact_set_user_quota);
2811 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
2813 (char **)&state->setup, state->setup_count,
2814 &state->param, state->total_param,
2815 &state->data, state->total_data, state->max_data_return);
2816 END_PROFILE_NESTED(NT_transact_set_user_quota);
2819 #endif /* HAVE_SYS_QUOTAS */
2822 /* Error in request */
2823 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n",
2825 return ERROR_DOS(ERRSRV,ERRerror);
2830 /****************************************************************************
2831 Reply to a SMBNTtrans.
2832 ****************************************************************************/
2834 int reply_nttrans(connection_struct *conn,
2835 char *inbuf,char *outbuf,int size,int bufsize)
2838 uint32 pscnt = IVAL(inbuf,smb_nt_ParameterCount);
2839 uint32 psoff = IVAL(inbuf,smb_nt_ParameterOffset);
2840 uint32 dscnt = IVAL(inbuf,smb_nt_DataCount);
2841 uint32 dsoff = IVAL(inbuf,smb_nt_DataOffset);
2843 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2845 struct trans_state *state;
2847 START_PROFILE(SMBnttrans);
2849 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2850 END_PROFILE(SMBnttrans);
2851 return ERROR_DOS(ERRSRV,ERRaccess);
2854 result = allow_new_trans(conn->pending_trans, SVAL(inbuf, smb_mid));
2855 if (!NT_STATUS_IS_OK(result)) {
2856 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2857 END_PROFILE(SMBnttrans);
2858 return ERROR_NT(result);
2861 if ((state = TALLOC_P(NULL, struct trans_state)) == NULL) {
2862 END_PROFILE(SMBnttrans);
2863 return ERROR_DOS(ERRSRV,ERRaccess);
2866 state->cmd = SMBnttrans;
2868 state->mid = SVAL(inbuf,smb_mid);
2869 state->vuid = SVAL(inbuf,smb_uid);
2870 state->total_data = IVAL(inbuf, smb_nt_TotalDataCount);
2872 state->total_param = IVAL(inbuf, smb_nt_TotalParameterCount);
2873 state->param = NULL;
2874 state->max_data_return = IVAL(inbuf,smb_nt_MaxDataCount);
2876 /* setup count is in *words* */
2877 state->setup_count = 2*CVAL(inbuf,smb_nt_SetupCount);
2878 state->call = function_code;
2881 * All nttrans messages we handle have smb_wct == 19 +
2882 * state->setup_count. Ensure this is so as a sanity check.
2885 if(CVAL(inbuf, smb_wct) != 19 + (state->setup_count/2)) {
2886 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2887 CVAL(inbuf, smb_wct), 19 + (state->setup_count/2)));
2891 /* Don't allow more than 128mb for each value. */
2892 if ((state->total_data > (1024*1024*128)) ||
2893 (state->total_param > (1024*1024*128))) {
2894 END_PROFILE(SMBnttrans);
2895 return ERROR_DOS(ERRDOS,ERRnomem);
2898 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2901 if (state->total_data) {
2902 /* Can't use talloc here, the core routines do realloc on the
2903 * params and data. */
2904 if ((state->data = SMB_MALLOC(state->total_data)) == NULL) {
2905 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2906 "bytes !\n", state->total_data));
2908 END_PROFILE(SMBnttrans);
2909 return(ERROR_DOS(ERRDOS,ERRnomem));
2911 if ((dsoff+dscnt < dsoff) || (dsoff+dscnt < dscnt))
2913 if ((smb_base(inbuf)+dsoff+dscnt > inbuf + size) ||
2914 (smb_base(inbuf)+dsoff+dscnt < smb_base(inbuf)))
2917 memcpy(state->data,smb_base(inbuf)+dsoff,dscnt);
2920 if (state->total_param) {
2921 /* Can't use talloc here, the core routines do realloc on the
2922 * params and data. */
2923 if ((state->param = SMB_MALLOC(state->total_param)) == NULL) {
2924 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2925 "bytes !\n", state->total_param));
2926 SAFE_FREE(state->data);
2928 END_PROFILE(SMBnttrans);
2929 return(ERROR_DOS(ERRDOS,ERRnomem));
2931 if ((psoff+pscnt < psoff) || (psoff+pscnt < pscnt))
2933 if ((smb_base(inbuf)+psoff+pscnt > inbuf + size) ||
2934 (smb_base(inbuf)+psoff+pscnt < smb_base(inbuf)))
2937 memcpy(state->param,smb_base(inbuf)+psoff,pscnt);
2940 state->received_data = dscnt;
2941 state->received_param = pscnt;
2943 if(state->setup_count > 0) {
2944 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2945 state->setup_count));
2946 state->setup = TALLOC(state, state->setup_count);
2947 if (state->setup == NULL) {
2948 DEBUG(0,("reply_nttrans : Out of memory\n"));
2949 SAFE_FREE(state->data);
2950 SAFE_FREE(state->param);
2952 END_PROFILE(SMBnttrans);
2953 return ERROR_DOS(ERRDOS,ERRnomem);
2956 if ((smb_nt_SetupStart + state->setup_count < smb_nt_SetupStart) ||
2957 (smb_nt_SetupStart + state->setup_count < state->setup_count)) {
2960 if (smb_nt_SetupStart + state->setup_count > size) {
2964 memcpy( state->setup, &inbuf[smb_nt_SetupStart], state->setup_count);
2965 dump_data(10, (char *)state->setup, state->setup_count);
2968 if ((state->received_data == state->total_data) &&
2969 (state->received_param == state->total_param)) {
2970 outsize = handle_nttrans(conn, state, inbuf, outbuf,
2972 SAFE_FREE(state->param);
2973 SAFE_FREE(state->data);
2975 END_PROFILE(SMBnttrans);
2979 DLIST_ADD(conn->pending_trans, state);
2981 /* We need to send an interim response then receive the rest
2982 of the parameter/data bytes */
2983 outsize = set_message(outbuf,0,0,False);
2985 END_PROFILE(SMBnttrans);
2990 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2991 SAFE_FREE(state->data);
2992 SAFE_FREE(state->param);
2994 END_PROFILE(SMBnttrans);
2995 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2998 /****************************************************************************
2999 Reply to a SMBnttranss
3000 ****************************************************************************/
3002 int reply_nttranss(connection_struct *conn, char *inbuf,char *outbuf,
3003 int size,int bufsize)
3006 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
3007 struct trans_state *state;
3009 START_PROFILE(SMBnttranss);
3013 for (state = conn->pending_trans; state != NULL;
3014 state = state->next) {
3015 if (state->mid == SVAL(inbuf,smb_mid)) {
3020 if ((state == NULL) || (state->cmd != SMBnttrans)) {
3021 END_PROFILE(SMBnttranss);
3022 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
3025 /* Revise state->total_param and state->total_data in case they have
3026 changed downwards */
3027 if (IVAL(inbuf, smb_nts_TotalParameterCount) < state->total_param) {
3028 state->total_param = IVAL(inbuf, smb_nts_TotalParameterCount);
3030 if (IVAL(inbuf, smb_nts_TotalDataCount) < state->total_data) {
3031 state->total_data = IVAL(inbuf, smb_nts_TotalDataCount);
3034 pcnt = IVAL(inbuf,smb_nts_ParameterCount);
3035 poff = IVAL(inbuf, smb_nts_ParameterOffset);
3036 pdisp = IVAL(inbuf, smb_nts_ParameterDisplacement);
3038 dcnt = IVAL(inbuf, smb_nts_DataCount);
3039 ddisp = IVAL(inbuf, smb_nts_DataDisplacement);
3040 doff = IVAL(inbuf, smb_nts_DataOffset);
3042 state->received_param += pcnt;
3043 state->received_data += dcnt;
3045 if ((state->received_data > state->total_data) ||
3046 (state->received_param > state->total_param))
3050 if (pdisp+pcnt > state->total_param)
3052 if ((pdisp+pcnt < pdisp) || (pdisp+pcnt < pcnt))
3054 if (pdisp > state->total_param)
3056 if ((smb_base(inbuf) + poff + pcnt > inbuf + size) ||
3057 (smb_base(inbuf) + poff + pcnt < smb_base(inbuf)))
3059 if (state->param + pdisp < state->param)
3062 memcpy(state->param+pdisp,smb_base(inbuf)+poff,
3067 if (ddisp+dcnt > state->total_data)
3069 if ((ddisp+dcnt < ddisp) || (ddisp+dcnt < dcnt))
3071 if (ddisp > state->total_data)
3073 if ((smb_base(inbuf) + doff + dcnt > inbuf + size) ||
3074 (smb_base(inbuf) + doff + dcnt < smb_base(inbuf)))
3076 if (state->data + ddisp < state->data)
3079 memcpy(state->data+ddisp, smb_base(inbuf)+doff,
3083 if ((state->received_param < state->total_param) ||
3084 (state->received_data < state->total_data)) {
3085 END_PROFILE(SMBnttranss);
3089 /* construct_reply_common has done us the favor to pre-fill the
3090 * command field with SMBnttranss which is wrong :-)
3092 SCVAL(outbuf,smb_com,SMBnttrans);
3094 outsize = handle_nttrans(conn, state, inbuf, outbuf,
3097 DLIST_REMOVE(conn->pending_trans, state);
3098 SAFE_FREE(state->data);
3099 SAFE_FREE(state->param);
3103 END_PROFILE(SMBnttranss);
3104 return(ERROR_DOS(ERRSRV,ERRnosupport));
3107 END_PROFILE(SMBnttranss);
3112 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3113 DLIST_REMOVE(conn->pending_trans, state);
3114 SAFE_FREE(state->data);
3115 SAFE_FREE(state->param);
3117 END_PROFILE(SMBnttranss);
3118 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);