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 0, /* No sharing. */
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, /* Read-only. */
1673 0, /* No sharing. */
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_shared1 adds aARCH when it
1708 creates the file. This isn't the correct thing to do in the copy case. JRA */
1709 file_set_dosmode(conn, newname, fattr, &sbuf2, True);
1711 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1712 return NT_STATUS_DISK_FULL;
1715 if (close_ret != 0) {
1716 status = map_nt_error_from_unix(close_ret);
1717 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1718 nt_errstr(status), oldname, newname));
1723 /****************************************************************************
1724 Reply to a NT rename request.
1725 ****************************************************************************/
1727 int reply_ntrename(connection_struct *conn,
1728 char *inbuf,char *outbuf,int length,int bufsize)
1735 BOOL path_contains_wcard = False;
1736 uint32 attrs = SVAL(inbuf,smb_vwv0);
1737 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1739 START_PROFILE(SMBntrename);
1741 p = smb_buf(inbuf) + 1;
1742 p += srvstr_get_path_wcard(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, &path_contains_wcard);
1743 if (!NT_STATUS_IS_OK(status)) {
1744 END_PROFILE(SMBntrename);
1745 return ERROR_NT(status);
1748 if( is_ntfs_stream_name(oldname)) {
1749 /* Can't rename a stream. */
1750 END_PROFILE(SMBntrename);
1751 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1754 if (ms_has_wild(oldname)) {
1755 END_PROFILE(SMBntrename);
1756 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1760 p += srvstr_get_path(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status);
1761 if (!NT_STATUS_IS_OK(status)) {
1762 END_PROFILE(SMBntrename);
1763 return ERROR_NT(status);
1766 RESOLVE_DFSPATH(oldname, conn, inbuf, outbuf);
1767 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1769 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1771 switch(rename_type) {
1772 case RENAME_FLAG_RENAME:
1773 status = rename_internals(conn, oldname, newname, attrs, False, path_contains_wcard);
1775 case RENAME_FLAG_HARD_LINK:
1776 status = hardlink_internals(conn, oldname, newname);
1778 case RENAME_FLAG_COPY:
1779 if (path_contains_wcard) {
1781 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1783 status = copy_internals(conn, oldname, newname, attrs);
1786 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1787 status = NT_STATUS_INVALID_PARAMETER;
1790 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1794 if (!NT_STATUS_IS_OK(status)) {
1795 END_PROFILE(SMBntrename);
1796 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1797 /* We have re-scheduled this call. */
1800 return ERROR_NT(status);
1804 * Win2k needs a changenotify request response before it will
1805 * update after a rename..
1807 process_pending_change_notify_queue((time_t)0);
1808 outsize = set_message(outbuf,0,0,True);
1810 END_PROFILE(SMBntrename);
1814 /****************************************************************************
1815 Reply to an unsolicited SMBNTtranss - just ignore it!
1816 ****************************************************************************/
1818 int reply_nttranss(connection_struct *conn,
1819 char *inbuf,char *outbuf,int length,int bufsize)
1821 START_PROFILE(SMBnttranss);
1822 DEBUG(4,("Ignoring nttranss of length %d\n",length));
1823 END_PROFILE(SMBnttranss);
1827 /****************************************************************************
1828 Reply to a notify change - queue the request and
1829 don't allow a directory to be opened.
1830 ****************************************************************************/
1832 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1833 char **ppsetup, uint32 setup_count,
1834 char **ppparams, uint32 parameter_count,
1835 char **ppdata, uint32 data_count, uint32 max_data_count)
1837 char *setup = *ppsetup;
1841 if(setup_count < 6) {
1842 return ERROR_DOS(ERRDOS,ERRbadfunc);
1845 fsp = file_fsp(setup,4);
1846 flags = IVAL(setup, 0);
1848 DEBUG(3,("call_nt_transact_notify_change\n"));
1851 return ERROR_DOS(ERRDOS,ERRbadfid);
1854 if((!fsp->is_directory) || (conn != fsp->conn)) {
1855 return ERROR_DOS(ERRDOS,ERRbadfid);
1858 if (!change_notify_set(inbuf, fsp, conn, flags)) {
1859 return(UNIXERROR(ERRDOS,ERRbadfid));
1862 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1863 name = %s\n", fsp->fsp_name ));
1868 /****************************************************************************
1869 Reply to an NT transact rename command.
1870 ****************************************************************************/
1872 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1873 char **ppsetup, uint32 setup_count,
1874 char **ppparams, uint32 parameter_count,
1875 char **ppdata, uint32 data_count, uint32 max_data_count)
1877 char *params = *ppparams;
1879 files_struct *fsp = NULL;
1880 BOOL replace_if_exists = False;
1881 BOOL path_contains_wcard = False;
1884 if(parameter_count < 4) {
1885 return ERROR_DOS(ERRDOS,ERRbadfunc);
1888 fsp = file_fsp(params, 0);
1889 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1890 CHECK_FSP(fsp, conn);
1891 srvstr_get_path_wcard(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE, &status, &path_contains_wcard);
1892 if (!NT_STATUS_IS_OK(status)) {
1893 return ERROR_NT(status);
1896 status = rename_internals(conn, fsp->fsp_name,
1897 new_name, 0, replace_if_exists, path_contains_wcard);
1898 if (!NT_STATUS_IS_OK(status))
1899 return ERROR_NT(status);
1902 * Rename was successful.
1904 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1906 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1907 fsp->fsp_name, new_name));
1910 * Win2k needs a changenotify request response before it will
1911 * update after a rename..
1914 process_pending_change_notify_queue((time_t)0);
1919 /******************************************************************************
1920 Fake up a completely empty SD.
1921 *******************************************************************************/
1923 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1927 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1929 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1936 /****************************************************************************
1937 Reply to query a security descriptor.
1938 ****************************************************************************/
1940 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1941 char **ppsetup, uint32 setup_count,
1942 char **ppparams, uint32 parameter_count,
1943 char **ppdata, uint32 data_count, uint32 max_data_count)
1945 char *params = *ppparams;
1946 char *data = *ppdata;
1948 SEC_DESC *psd = NULL;
1950 uint32 security_info_wanted;
1951 TALLOC_CTX *mem_ctx;
1952 files_struct *fsp = NULL;
1954 if(parameter_count < 8) {
1955 return ERROR_DOS(ERRDOS,ERRbadfunc);
1958 fsp = file_fsp(params,0);
1960 return ERROR_DOS(ERRDOS,ERRbadfid);
1963 security_info_wanted = IVAL(params,4);
1965 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1966 (unsigned int)security_info_wanted ));
1968 params = nttrans_realloc(ppparams, 4);
1969 if(params == NULL) {
1970 return ERROR_DOS(ERRDOS,ERRnomem);
1973 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1974 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1975 return ERROR_DOS(ERRDOS,ERRnomem);
1979 * Get the permissions to return.
1982 if (!lp_nt_acl_support(SNUM(conn))) {
1983 sd_size = get_null_nt_acl(mem_ctx, &psd);
1985 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fh->fd, security_info_wanted, &psd);
1989 talloc_destroy(mem_ctx);
1990 return(UNIXERROR(ERRDOS,ERRnoaccess));
1993 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1995 SIVAL(params,0,(uint32)sd_size);
1997 if(max_data_count < sd_size) {
1999 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
2000 params, 4, *ppdata, 0);
2001 talloc_destroy(mem_ctx);
2006 * Allocate the data we will point this at.
2009 data = nttrans_realloc(ppdata, sd_size);
2011 talloc_destroy(mem_ctx);
2012 return ERROR_DOS(ERRDOS,ERRnomem);
2016 * Init the parse struct we will marshall into.
2019 prs_init(&pd, 0, mem_ctx, MARSHALL);
2022 * Setup the prs_struct to point at the memory we just
2026 prs_give_memory( &pd, data, (uint32)sd_size, False);
2029 * Finally, linearize into the outgoing buffer.
2032 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2033 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2034 security descriptor.\n"));
2036 * Return access denied for want of a better error message..
2038 talloc_destroy(mem_ctx);
2039 return(UNIXERROR(ERRDOS,ERRnoaccess));
2043 * Now we can delete the security descriptor.
2046 talloc_destroy(mem_ctx);
2048 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 4, data, (int)sd_size);
2052 /****************************************************************************
2053 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2054 ****************************************************************************/
2056 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2057 char **ppsetup, uint32 setup_count,
2058 char **ppparams, uint32 parameter_count,
2059 char **ppdata, uint32 data_count, uint32 max_data_count)
2061 char *params= *ppparams;
2062 char *data = *ppdata;
2063 files_struct *fsp = NULL;
2064 uint32 security_info_sent = 0;
2067 if(parameter_count < 8) {
2068 return ERROR_DOS(ERRDOS,ERRbadfunc);
2071 if((fsp = file_fsp(params,0)) == NULL) {
2072 return ERROR_DOS(ERRDOS,ERRbadfid);
2075 if(!lp_nt_acl_support(SNUM(conn))) {
2079 security_info_sent = IVAL(params,4);
2081 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
2082 (unsigned int)security_info_sent ));
2084 if (data_count == 0) {
2085 return ERROR_DOS(ERRDOS, ERRnoaccess);
2088 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent))) {
2089 return ERROR_NT(nt_status);
2094 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2098 /****************************************************************************
2100 ****************************************************************************/
2102 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2103 char **ppsetup, uint32 setup_count,
2104 char **ppparams, uint32 parameter_count,
2105 char **ppdata, uint32 data_count, uint32 max_data_count)
2112 static BOOL logged_message;
2113 char *pdata = *ppdata;
2115 if (setup_count != 8) {
2116 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2117 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2120 function = IVAL(*ppsetup, 0);
2121 fidnum = SVAL(*ppsetup, 4);
2122 isFSctl = CVAL(*ppsetup, 6);
2123 compfilter = CVAL(*ppsetup, 7);
2125 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2126 function, fidnum, isFSctl, compfilter));
2128 fsp=file_fsp(*ppsetup, 4);
2129 /* this check is done in each implemented function case for now
2130 because I don't want to break anything... --metze
2131 FSP_BELONGS_CONN(fsp,conn);*/
2134 case FSCTL_SET_SPARSE:
2135 /* pretend this succeeded - tho strictly we should
2136 mark the file sparse (if the local fs supports it)
2137 so we can know if we need to pre-allocate or not */
2139 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2140 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2143 case FSCTL_0x000900C0:
2144 /* pretend this succeeded - don't know what this really is
2145 but works ok like this --metze
2148 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2149 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2152 case FSCTL_GET_REPARSE_POINT:
2153 /* pretend this fail - my winXP does it like this
2157 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2158 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2161 case FSCTL_SET_REPARSE_POINT:
2162 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2166 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2167 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2170 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
2173 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2174 * and return their volume names. If max_data_count is 16, then it is just
2175 * asking for the number of volumes and length of the combined names.
2177 * pdata is the data allocated by our caller, but that uses
2178 * total_data_count (which is 0 in our case) rather than max_data_count.
2179 * Allocate the correct amount and return the pointer to let
2180 * it be deallocated when we return.
2182 SHADOW_COPY_DATA *shadow_data = NULL;
2183 TALLOC_CTX *shadow_mem_ctx = NULL;
2184 BOOL labels = False;
2185 uint32 labels_data_count = 0;
2189 FSP_BELONGS_CONN(fsp,conn);
2191 if (max_data_count < 16) {
2192 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2194 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2197 if (max_data_count > 16) {
2201 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2202 if (shadow_mem_ctx == NULL) {
2203 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2204 return ERROR_NT(NT_STATUS_NO_MEMORY);
2207 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2208 if (shadow_data == NULL) {
2209 DEBUG(0,("talloc_zero() failed!\n"));
2210 talloc_destroy(shadow_mem_ctx);
2211 return ERROR_NT(NT_STATUS_NO_MEMORY);
2214 shadow_data->mem_ctx = shadow_mem_ctx;
2217 * Call the VFS routine to actually do the work.
2219 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2220 talloc_destroy(shadow_data->mem_ctx);
2221 if (errno == ENOSYS) {
2222 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2223 conn->connectpath));
2224 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2226 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2227 conn->connectpath));
2228 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
2232 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2237 data_count = 12+labels_data_count+4;
2240 if (max_data_count<data_count) {
2241 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2242 max_data_count,data_count));
2243 talloc_destroy(shadow_data->mem_ctx);
2244 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
2247 pdata = nttrans_realloc(ppdata, data_count);
2248 if (pdata == NULL) {
2249 talloc_destroy(shadow_data->mem_ctx);
2250 return ERROR_NT(NT_STATUS_NO_MEMORY);
2255 /* num_volumes 4 bytes */
2256 SIVAL(pdata,0,shadow_data->num_volumes);
2259 /* num_labels 4 bytes */
2260 SIVAL(pdata,4,shadow_data->num_volumes);
2263 /* needed_data_count 4 bytes */
2264 SIVAL(pdata,8,labels_data_count);
2268 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2269 shadow_data->num_volumes,fsp->fsp_name));
2270 if (labels && shadow_data->labels) {
2271 for (i=0;i<shadow_data->num_volumes;i++) {
2272 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2273 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2274 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2278 talloc_destroy(shadow_data->mem_ctx);
2280 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
2285 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2287 /* pretend this succeeded -
2289 * we have to send back a list with all files owned by this SID
2291 * but I have to check that --metze
2295 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2297 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2299 FSP_BELONGS_CONN(fsp,conn);
2301 /* unknown 4 bytes: this is not the length of the sid :-( */
2302 /*unknown = IVAL(pdata,0);*/
2304 sid_parse(pdata+4,sid_len,&sid);
2305 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2307 if (!sid_to_uid(&sid, &uid)) {
2308 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2309 sid_string_static(&sid),(unsigned long)sid_len));
2313 /* we can take a look at the find source :-)
2315 * find ./ -uid $uid -name '*' is what we need here
2318 * and send 4bytes len and then NULL terminated unicode strings
2321 * but I don't know how to deal with the paged results
2322 * (maybe we can hang the result anywhere in the fsp struct)
2324 * we don't send all files at once
2325 * and at the next we should *not* start from the beginning,
2326 * so we have to cache the result
2331 /* this works for now... */
2332 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2336 if (!logged_message) {
2337 logged_message = True; /* Only print this once... */
2338 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2343 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2347 #ifdef HAVE_SYS_QUOTAS
2348 /****************************************************************************
2349 Reply to get user quota
2350 ****************************************************************************/
2352 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2353 char **ppsetup, uint32 setup_count,
2354 char **ppparams, uint32 parameter_count,
2355 char **ppdata, uint32 data_count, uint32 max_data_count)
2357 NTSTATUS nt_status = NT_STATUS_OK;
2358 char *params = *ppparams;
2359 char *pdata = *ppdata;
2361 int data_len=0,param_len=0;
2364 files_struct *fsp = NULL;
2368 BOOL start_enum = True;
2369 SMB_NTQUOTA_STRUCT qt;
2370 SMB_NTQUOTA_LIST *tmp_list;
2371 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2372 extern struct current_user current_user;
2377 if (current_user.ut.uid != 0) {
2378 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2379 lp_servicename(SNUM(conn)),conn->user));
2380 return ERROR_DOS(ERRDOS,ERRnoaccess);
2384 * Ensure minimum number of parameters sent.
2387 if (parameter_count < 4) {
2388 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2389 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2392 /* maybe we can check the quota_fnum */
2393 fsp = file_fsp(params,0);
2394 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2395 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2396 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2399 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2400 * is done by CHECK_NTQUOTA_HANDLE_OK()
2402 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2404 level = SVAL(params,2);
2406 /* unknown 12 bytes leading in params */
2409 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2410 /* seems that we should continue with the enum here --metze */
2412 if (qt_handle->quota_list!=NULL &&
2413 qt_handle->tmp_list==NULL) {
2416 free_ntquota_list(&(qt_handle->quota_list));
2418 /* Realloc the size of parameters and data we will return */
2420 params = nttrans_realloc(ppparams, param_len);
2421 if(params == NULL) {
2422 return ERROR_DOS(ERRDOS,ERRnomem);
2426 SIVAL(params,0,data_len);
2433 case TRANSACT_GET_USER_QUOTA_LIST_START:
2435 if (qt_handle->quota_list==NULL &&
2436 qt_handle->tmp_list==NULL) {
2440 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2441 return ERROR_DOS(ERRSRV,ERRerror);
2443 /* Realloc the size of parameters and data we will return */
2445 params = nttrans_realloc(ppparams, param_len);
2446 if(params == NULL) {
2447 return ERROR_DOS(ERRDOS,ERRnomem);
2450 /* we should not trust the value in max_data_count*/
2451 max_data_count = MIN(max_data_count,2048);
2453 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2455 return ERROR_DOS(ERRDOS,ERRnomem);
2460 /* set params Size of returned Quota Data 4 bytes*/
2461 /* but set it later when we know it */
2463 /* for each entry push the data */
2466 qt_handle->tmp_list = qt_handle->quota_list;
2469 tmp_list = qt_handle->tmp_list;
2471 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2472 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2474 sid_len = sid_size(&tmp_list->quotas->sid);
2475 entry_len = 40 + sid_len;
2477 /* nextoffset entry 4 bytes */
2478 SIVAL(entry,0,entry_len);
2480 /* then the len of the SID 4 bytes */
2481 SIVAL(entry,4,sid_len);
2483 /* unknown data 8 bytes SMB_BIG_UINT */
2484 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2486 /* the used disk space 8 bytes SMB_BIG_UINT */
2487 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2489 /* the soft quotas 8 bytes SMB_BIG_UINT */
2490 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2492 /* the hard quotas 8 bytes SMB_BIG_UINT */
2493 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2495 /* and now the SID */
2496 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2499 qt_handle->tmp_list = tmp_list;
2501 /* overwrite the offset of the last entry */
2502 SIVAL(entry-entry_len,0,0);
2504 data_len = 4+qt_len;
2505 /* overwrite the params quota_data_len */
2506 SIVAL(params,0,data_len);
2510 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2512 /* unknown 4 bytes IVAL(pdata,0) */
2514 if (data_count < 8) {
2515 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2516 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2519 sid_len = IVAL(pdata,4);
2520 /* Ensure this is less than 1mb. */
2521 if (sid_len > (1024*1024)) {
2522 return ERROR_DOS(ERRDOS,ERRnomem);
2525 if (data_count < 8+sid_len) {
2526 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2527 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2530 data_len = 4+40+sid_len;
2532 if (max_data_count < data_len) {
2533 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2534 max_data_count, data_len));
2536 SIVAL(params,0,data_len);
2538 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2542 sid_parse(pdata+8,sid_len,&sid);
2544 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2547 * we have to return zero's in all fields
2548 * instead of returning an error here
2553 /* Realloc the size of parameters and data we will return */
2555 params = nttrans_realloc(ppparams, param_len);
2556 if(params == NULL) {
2557 return ERROR_DOS(ERRDOS,ERRnomem);
2560 pdata = nttrans_realloc(ppdata, data_len);
2562 return ERROR_DOS(ERRDOS,ERRnomem);
2567 /* set params Size of returned Quota Data 4 bytes*/
2568 SIVAL(params,0,data_len);
2570 /* nextoffset entry 4 bytes */
2573 /* then the len of the SID 4 bytes */
2574 SIVAL(entry,4,sid_len);
2576 /* unknown data 8 bytes SMB_BIG_UINT */
2577 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2579 /* the used disk space 8 bytes SMB_BIG_UINT */
2580 SBIG_UINT(entry,16,qt.usedspace);
2582 /* the soft quotas 8 bytes SMB_BIG_UINT */
2583 SBIG_UINT(entry,24,qt.softlim);
2585 /* the hard quotas 8 bytes SMB_BIG_UINT */
2586 SBIG_UINT(entry,32,qt.hardlim);
2588 /* and now the SID */
2589 sid_linearize(entry+40, sid_len, &sid);
2594 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2595 return ERROR_DOS(ERRSRV,ERRerror);
2599 send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
2604 /****************************************************************************
2605 Reply to set user quota
2606 ****************************************************************************/
2608 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2609 char **ppsetup, uint32 setup_count,
2610 char **ppparams, uint32 parameter_count,
2611 char **ppdata, uint32 data_count, uint32 max_data_count)
2613 char *params = *ppparams;
2614 char *pdata = *ppdata;
2615 int data_len=0,param_len=0;
2616 SMB_NTQUOTA_STRUCT qt;
2619 files_struct *fsp = NULL;
2624 if (current_user.ut.uid != 0) {
2625 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2626 lp_servicename(SNUM(conn)),conn->user));
2627 return ERROR_DOS(ERRDOS,ERRnoaccess);
2631 * Ensure minimum number of parameters sent.
2634 if (parameter_count < 2) {
2635 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2636 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2639 /* maybe we can check the quota_fnum */
2640 fsp = file_fsp(params,0);
2641 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2642 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2643 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2646 if (data_count < 40) {
2647 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2648 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2651 /* offset to next quota record.
2652 * 4 bytes IVAL(pdata,0)
2657 sid_len = IVAL(pdata,4);
2659 if (data_count < 40+sid_len) {
2660 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2661 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2664 /* unknown 8 bytes in pdata
2665 * maybe its the change time in NTTIME
2668 /* the used space 8 bytes (SMB_BIG_UINT)*/
2669 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2670 #ifdef LARGE_SMB_OFF_T
2671 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2672 #else /* LARGE_SMB_OFF_T */
2673 if ((IVAL(pdata,20) != 0)&&
2674 ((qt.usedspace != 0xFFFFFFFF)||
2675 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2676 /* more than 32 bits? */
2677 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2679 #endif /* LARGE_SMB_OFF_T */
2681 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2682 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2683 #ifdef LARGE_SMB_OFF_T
2684 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2685 #else /* LARGE_SMB_OFF_T */
2686 if ((IVAL(pdata,28) != 0)&&
2687 ((qt.softlim != 0xFFFFFFFF)||
2688 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2689 /* more than 32 bits? */
2690 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2692 #endif /* LARGE_SMB_OFF_T */
2694 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2695 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2696 #ifdef LARGE_SMB_OFF_T
2697 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2698 #else /* LARGE_SMB_OFF_T */
2699 if ((IVAL(pdata,36) != 0)&&
2700 ((qt.hardlim != 0xFFFFFFFF)||
2701 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2702 /* more than 32 bits? */
2703 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2705 #endif /* LARGE_SMB_OFF_T */
2707 sid_parse(pdata+40,sid_len,&sid);
2708 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2710 /* 44 unknown bytes left... */
2712 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2713 return ERROR_DOS(ERRSRV,ERRerror);
2716 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
2720 #endif /* HAVE_SYS_QUOTAS */
2722 /****************************************************************************
2723 Reply to a SMBNTtrans.
2724 ****************************************************************************/
2726 int reply_nttrans(connection_struct *conn,
2727 char *inbuf,char *outbuf,int length,int bufsize)
2730 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2731 #if 0 /* Not used. */
2732 uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount);
2733 uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
2734 #endif /* Not used. */
2735 uint32 total_parameter_count = IVAL(inbuf, smb_nt_TotalParameterCount);
2736 uint32 total_data_count = IVAL(inbuf, smb_nt_TotalDataCount);
2737 uint32 parameter_count = IVAL(inbuf,smb_nt_ParameterCount);
2738 uint32 parameter_offset = IVAL(inbuf,smb_nt_ParameterOffset);
2739 uint32 data_count = IVAL(inbuf,smb_nt_DataCount);
2740 uint32 data_offset = IVAL(inbuf,smb_nt_DataOffset);
2741 uint16 setup_count = 2*CVAL(inbuf,smb_nt_SetupCount); /* setup count is in *words* */
2742 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2743 char *params = NULL, *data = NULL, *setup = NULL;
2744 uint32 num_params_sofar, num_data_sofar;
2745 START_PROFILE(SMBnttrans);
2747 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2748 END_PROFILE(SMBnttrans);
2749 return ERROR_DOS(ERRSRV,ERRaccess);
2752 outsize = set_message(outbuf,0,0,True);
2755 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2756 * Ensure this is so as a sanity check.
2759 if(CVAL(inbuf, smb_wct) != 19 + (setup_count/2)) {
2760 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2761 CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
2765 /* Don't allow more than 128mb for each value. */
2766 if ((total_parameter_count > (1024*1024*128)) || (total_data_count > (1024*1024*128))) {
2767 END_PROFILE(SMBnttrans);
2768 return ERROR_DOS(ERRDOS,ERRnomem);
2771 /* Allocate the space for the setup, the maximum needed parameters and data */
2773 if(setup_count > 0) {
2774 setup = (char *)SMB_MALLOC(setup_count);
2776 if (total_parameter_count > 0) {
2777 params = (char *)SMB_MALLOC(total_parameter_count);
2779 if (total_data_count > 0) {
2780 data = (char *)SMB_MALLOC(total_data_count);
2783 if ((total_parameter_count && !params) || (total_data_count && !data) ||
2784 (setup_count && !setup)) {
2788 DEBUG(0,("reply_nttrans : Out of memory\n"));
2789 END_PROFILE(SMBnttrans);
2790 return ERROR_DOS(ERRDOS,ERRnomem);
2793 /* Copy the param and data bytes sent with this request into the params buffer */
2794 num_params_sofar = parameter_count;
2795 num_data_sofar = data_count;
2797 if (parameter_count > total_parameter_count || data_count > total_data_count)
2801 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
2802 if ((smb_nt_SetupStart + setup_count < smb_nt_SetupStart) ||
2803 (smb_nt_SetupStart + setup_count < setup_count)) {
2806 if (smb_nt_SetupStart + setup_count > length) {
2810 memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
2811 dump_data(10, setup, setup_count);
2814 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count));
2815 if ((parameter_offset + parameter_count < parameter_offset) ||
2816 (parameter_offset + parameter_count < parameter_count)) {
2819 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length)||
2820 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf))) {
2824 memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
2825 dump_data(10, params, parameter_count);
2828 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
2829 if ((data_offset + data_count < data_offset) || (data_offset + data_count < data_count)) {
2832 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2833 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf))) {
2837 memcpy( data, smb_base(inbuf) + data_offset, data_count);
2838 dump_data(10, data, data_count);
2841 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2843 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2844 /* We need to send an interim response then receive the rest
2845 of the parameter/data bytes */
2846 outsize = set_message(outbuf,0,0,True);
2847 srv_signing_trans_stop();
2849 if (!send_smb(smbd_server_fd(),outbuf)) {
2850 exit_server("reply_nttrans: send_smb failed.");
2853 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2855 uint32 parameter_displacement;
2856 uint32 data_displacement;
2858 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
2860 /* We need to re-calcuate the new length after we've read the secondary packet. */
2861 length = smb_len(inbuf) + 4;
2864 * The sequence number for the trans reply is always
2865 * based on the last secondary received.
2868 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2870 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
2871 outsize = set_message(outbuf,0,0,True);
2873 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2875 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2876 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
2881 /* Revise total_params and total_data in case they have changed downwards */
2882 if (IVAL(inbuf, smb_nts_TotalParameterCount) < total_parameter_count) {
2883 total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
2885 if (IVAL(inbuf, smb_nts_TotalDataCount) < total_data_count) {
2886 total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
2889 parameter_count = IVAL(inbuf,smb_nts_ParameterCount);
2890 parameter_offset = IVAL(inbuf, smb_nts_ParameterOffset);
2891 parameter_displacement = IVAL(inbuf, smb_nts_ParameterDisplacement);
2892 num_params_sofar += parameter_count;
2894 data_count = IVAL(inbuf, smb_nts_DataCount);
2895 data_displacement = IVAL(inbuf, smb_nts_DataDisplacement);
2896 data_offset = IVAL(inbuf, smb_nts_DataOffset);
2897 num_data_sofar += data_count;
2899 if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count) {
2900 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2904 if (parameter_count) {
2905 if (parameter_displacement + parameter_count > total_parameter_count) {
2908 if ((parameter_displacement + parameter_count < parameter_displacement) ||
2909 (parameter_displacement + parameter_count < parameter_count)) {
2912 if (parameter_displacement > total_parameter_count) {
2915 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length) ||
2916 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf))) {
2919 if (parameter_displacement + params < params) {
2923 memcpy( ¶ms[parameter_displacement], smb_base(inbuf) + parameter_offset, parameter_count);
2927 if (data_displacement + data_count > total_data_count) {
2930 if ((data_displacement + data_count < data_displacement) ||
2931 (data_displacement + data_count < data_count)) {
2934 if (data_displacement > total_data_count) {
2937 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2938 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf))) {
2941 if (data_displacement + data < data) {
2945 memcpy( &data[data_displacement], smb_base(inbuf)+ data_offset, data_count);
2950 if (Protocol >= PROTOCOL_NT1) {
2951 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_IS_LONG_NAME);
2954 /* Now we must call the relevant NT_TRANS function */
2955 switch(function_code) {
2956 case NT_TRANSACT_CREATE:
2957 START_PROFILE_NESTED(NT_transact_create);
2958 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2960 &setup, setup_count,
2961 ¶ms, total_parameter_count,
2962 &data, total_data_count, max_data_count);
2963 END_PROFILE_NESTED(NT_transact_create);
2965 case NT_TRANSACT_IOCTL:
2966 START_PROFILE_NESTED(NT_transact_ioctl);
2967 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2969 &setup, setup_count,
2970 ¶ms, total_parameter_count,
2971 &data, total_data_count, max_data_count);
2972 END_PROFILE_NESTED(NT_transact_ioctl);
2974 case NT_TRANSACT_SET_SECURITY_DESC:
2975 START_PROFILE_NESTED(NT_transact_set_security_desc);
2976 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2978 &setup, setup_count,
2979 ¶ms, total_parameter_count,
2980 &data, total_data_count, max_data_count);
2981 END_PROFILE_NESTED(NT_transact_set_security_desc);
2983 case NT_TRANSACT_NOTIFY_CHANGE:
2984 START_PROFILE_NESTED(NT_transact_notify_change);
2985 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
2987 &setup, setup_count,
2988 ¶ms, total_parameter_count,
2989 &data, total_data_count, max_data_count);
2990 END_PROFILE_NESTED(NT_transact_notify_change);
2992 case NT_TRANSACT_RENAME:
2993 START_PROFILE_NESTED(NT_transact_rename);
2994 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2996 &setup, setup_count,
2997 ¶ms, total_parameter_count,
2998 &data, total_data_count, max_data_count);
2999 END_PROFILE_NESTED(NT_transact_rename);
3002 case NT_TRANSACT_QUERY_SECURITY_DESC:
3003 START_PROFILE_NESTED(NT_transact_query_security_desc);
3004 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
3006 &setup, setup_count,
3007 ¶ms, total_parameter_count,
3008 &data, total_data_count, max_data_count);
3009 END_PROFILE_NESTED(NT_transact_query_security_desc);
3011 #ifdef HAVE_SYS_QUOTAS
3012 case NT_TRANSACT_GET_USER_QUOTA:
3013 START_PROFILE_NESTED(NT_transact_get_user_quota);
3014 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
3016 &setup, setup_count,
3017 ¶ms, total_parameter_count,
3018 &data, total_data_count, max_data_count);
3019 END_PROFILE_NESTED(NT_transact_get_user_quota);
3021 case NT_TRANSACT_SET_USER_QUOTA:
3022 START_PROFILE_NESTED(NT_transact_set_user_quota);
3023 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
3025 &setup, setup_count,
3026 ¶ms, total_parameter_count,
3027 &data, total_data_count, max_data_count);
3028 END_PROFILE_NESTED(NT_transact_set_user_quota);
3030 #endif /* HAVE_SYS_QUOTAS */
3032 /* Error in request */
3033 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
3037 END_PROFILE(SMBnttrans);
3038 srv_signing_trans_stop();
3039 return ERROR_DOS(ERRSRV,ERRerror);
3042 /* As we do not know how many data packets will need to be
3043 returned here the various call_nt_transact_xxxx calls
3044 must send their own. Thus a call_nt_transact_xxxx routine only
3045 returns a value other than -1 when it wants to send
3049 srv_signing_trans_stop();
3054 END_PROFILE(SMBnttrans);
3055 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
3056 calls have already sent it. If outsize != -1 then it is
3057 returning an error packet. */
3061 srv_signing_trans_stop();
3065 END_PROFILE(SMBnttrans);
3066 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);