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.
24 extern enum protocol_types Protocol;
25 extern int smb_read_error;
26 extern int global_oplock_break;
27 extern struct current_user current_user;
29 static const char *known_nt_pipes[] = {
48 /* Map generic permissions to file object specific permissions */
50 struct generic_mapping file_generic_mapping = {
57 static char *nttrans_realloc(char **ptr, size_t size)
61 smb_panic("nttrans_realloc() called with NULL ptr\n");
63 tptr = SMB_REALLOC(*ptr, size);
68 memset(tptr,'\0',size);
76 /****************************************************************************
77 Send the required number of replies back.
78 We assume all fields other than the data fields are
79 set correctly for the type of call.
80 HACK ! Always assumes smb_setup field is zero.
81 ****************************************************************************/
83 static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, NTSTATUS nt_error, char *params,
84 int paramsize, char *pdata, int datasize)
87 int data_to_send = datasize;
88 int params_to_send = paramsize;
92 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
93 int alignment_offset = 3;
94 int data_alignment_offset = 0;
97 * Initially set the wcnt area to be 18 - this is true for all
101 set_message(outbuf,18,0,True);
103 if (NT_STATUS_V(nt_error))
107 * If there genuinely are no parameters or data to send just send
111 if(params_to_send == 0 && data_to_send == 0) {
112 if (!send_smb(smbd_server_fd(),outbuf))
113 exit_server("send_nt_replies: send_smb failed.");
118 * When sending params and data ensure that both are nicely aligned.
119 * Only do this alignment when there is also data to send - else
120 * can cause NT redirector problems.
123 if (((params_to_send % 4) != 0) && (data_to_send != 0))
124 data_alignment_offset = 4 - (params_to_send % 4);
127 * Space is bufsize minus Netbios over TCP header minus SMB header.
128 * The alignment_offset is to align the param bytes on a four byte
129 * boundary (2 bytes for data len, one byte pad).
130 * NT needs this to work correctly.
133 useable_space = bufsize - ((smb_buf(outbuf)+
134 alignment_offset+data_alignment_offset) -
138 * useable_space can never be more than max_send minus the
142 useable_space = MIN(useable_space,
143 max_send - (alignment_offset+data_alignment_offset));
146 while (params_to_send || data_to_send) {
149 * Calculate whether we will totally or partially fill this packet.
152 total_sent_thistime = params_to_send + data_to_send +
153 alignment_offset + data_alignment_offset;
156 * We can never send more than useable_space.
159 total_sent_thistime = MIN(total_sent_thistime, useable_space);
161 set_message(outbuf, 18, total_sent_thistime, True);
164 * Set total params and data to be sent.
167 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
168 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
171 * Calculate how many parameters and data we can fit into
172 * this packet. Parameters get precedence.
175 params_sent_thistime = MIN(params_to_send,useable_space);
176 data_sent_thistime = useable_space - params_sent_thistime;
177 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
179 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
181 if(params_sent_thistime == 0) {
182 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
183 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
186 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
187 * parameter bytes, however the first 4 bytes of outbuf are
188 * the Netbios over TCP header. Thus use smb_base() to subtract
189 * them from the calculation.
192 SIVAL(outbuf,smb_ntr_ParameterOffset,
193 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
195 * Absolute displacement of param bytes sent in this packet.
198 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
202 * Deal with the data portion.
205 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
207 if(data_sent_thistime == 0) {
208 SIVAL(outbuf,smb_ntr_DataOffset,0);
209 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
212 * The offset of the data bytes is the offset of the
213 * parameter bytes plus the number of parameters being sent this time.
216 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
217 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
218 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
222 * Copy the param bytes into the packet.
225 if(params_sent_thistime)
226 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
229 * Copy in the data bytes
232 if(data_sent_thistime)
233 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
234 data_alignment_offset,pd,data_sent_thistime);
236 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
237 params_sent_thistime, data_sent_thistime, useable_space));
238 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
239 params_to_send, data_to_send, paramsize, datasize));
241 /* Send the packet */
242 if (!send_smb(smbd_server_fd(),outbuf))
243 exit_server("send_nt_replies: send_smb failed.");
245 pp += params_sent_thistime;
246 pd += data_sent_thistime;
248 params_to_send -= params_sent_thistime;
249 data_to_send -= data_sent_thistime;
255 if(params_to_send < 0 || data_to_send < 0) {
256 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
257 params_to_send, data_to_send));
265 /****************************************************************************
267 ****************************************************************************/
269 static BOOL saved_case_sensitive;
270 static BOOL saved_case_preserve;
271 static BOOL saved_short_case_preserve;
273 /****************************************************************************
275 ****************************************************************************/
277 static void set_posix_case_semantics(connection_struct *conn, uint32 file_attributes)
279 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS))
282 saved_case_sensitive = conn->case_sensitive;
283 saved_case_preserve = conn->case_preserve;
284 saved_short_case_preserve = conn->short_case_preserve;
287 conn->case_sensitive = True;
288 conn->case_preserve = True;
289 conn->short_case_preserve = True;
292 /****************************************************************************
293 Restore case semantics.
294 ****************************************************************************/
296 static void restore_case_semantics(connection_struct *conn, uint32 file_attributes)
298 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS))
301 conn->case_sensitive = saved_case_sensitive;
302 conn->case_preserve = saved_case_preserve;
303 conn->short_case_preserve = saved_short_case_preserve;
306 /****************************************************************************
307 Utility function to map create disposition.
308 ****************************************************************************/
310 static int map_create_disposition( uint32 create_disposition)
314 switch( create_disposition ) {
316 /* create if not exist, fail if exist */
317 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_FAIL);
320 case FILE_OVERWRITE_IF:
321 /* create if not exist, trunc if exist */
322 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
325 /* fail if not exist, open if exists */
326 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN);
329 /* create if not exist, open if exists */
330 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_OPEN);
333 /* fail if not exist, truncate if exists */
334 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
337 DEBUG(0,("map_create_disposition: Incorrect value for create_disposition = %d\n",
338 create_disposition ));
342 DEBUG(10,("map_create_disposition: Mapped create_disposition 0x%lx to 0x%x\n",
343 (unsigned long)create_disposition, ret ));
348 /****************************************************************************
349 Utility function to map share modes.
350 ****************************************************************************/
352 static int map_share_mode( char *fname, uint32 create_options,
353 uint32 *desired_access, uint32 share_access, uint32 file_attributes)
355 int smb_open_mode = -1;
356 uint32 original_desired_access = *desired_access;
358 /* This is a nasty hack - must fix... JRA. */
359 if (*desired_access == MAXIMUM_ALLOWED_ACCESS) {
360 *desired_access = FILE_GENERIC_ALL;
364 * Convert GENERIC bits to specific bits.
367 se_map_generic(desired_access, &file_generic_mapping);
369 switch( *desired_access & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA) ) {
371 smb_open_mode = DOS_OPEN_RDONLY;
373 case FILE_WRITE_DATA:
374 case FILE_APPEND_DATA:
375 case FILE_WRITE_DATA|FILE_APPEND_DATA:
376 smb_open_mode = DOS_OPEN_WRONLY;
378 case FILE_READ_DATA|FILE_WRITE_DATA:
379 case FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA:
380 case FILE_READ_DATA|FILE_APPEND_DATA:
381 smb_open_mode = DOS_OPEN_RDWR;
386 * NB. For DELETE_ACCESS we should really check the
387 * directory permissions, as that is what controls
388 * delete, and for WRITE_DAC_ACCESS we should really
389 * check the ownership, as that is what controls the
390 * chmod. Note that this is *NOT* a security hole (this
391 * note is for you, Andrew) as we are not *allowing*
392 * the access at this point, the actual unlink or
393 * chown or chmod call would do this. We are just helping
394 * clients out by telling them if they have a hope
395 * of any of this succeeding. POSIX acls may still
396 * deny the real call. JRA.
399 if (smb_open_mode == -1) {
401 if(*desired_access & (DELETE_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS|SYNCHRONIZE_ACCESS|
402 FILE_EXECUTE|FILE_READ_ATTRIBUTES|
403 FILE_READ_EA|FILE_WRITE_EA|SYSTEM_SECURITY_ACCESS|
404 FILE_WRITE_ATTRIBUTES|READ_CONTROL_ACCESS)) {
405 smb_open_mode = DOS_OPEN_RDONLY;
406 } else if(*desired_access == 0) {
409 * JRA - NT seems to sometimes send desired_access as zero. play it safe
410 * and map to a stat open.
413 smb_open_mode = DOS_OPEN_RDONLY;
416 DEBUG(0,("map_share_mode: Incorrect value 0x%lx for desired_access to file %s\n",
417 (unsigned long)*desired_access, fname));
423 * Set the special bit that means allow share delete.
424 * This is held outside the normal share mode bits at 1<<15.
428 if(share_access & FILE_SHARE_DELETE) {
429 smb_open_mode |= ALLOW_SHARE_DELETE;
430 DEBUG(10,("map_share_mode: FILE_SHARE_DELETE requested. open_mode = 0x%x\n", smb_open_mode));
433 if(*desired_access & DELETE_ACCESS) {
434 DEBUG(10,("map_share_mode: DELETE_ACCESS requested. open_mode = 0x%x\n", smb_open_mode));
438 * We need to store the intent to open for Delete. This
439 * is what determines if a delete on close flag can be set.
440 * This is the wrong way (and place) to store this, but for 2.2 this
441 * is the only practical way. JRA.
444 if (create_options & FILE_DELETE_ON_CLOSE) {
446 * W2K3 bug compatibility mode... To set delete on close
447 * the redirector must have *specifically* set DELETE_ACCESS
448 * in the desired_access field. Just asking for GENERIC_ALL won't do. JRA.
451 if (!(original_desired_access & DELETE_ACCESS)) {
452 DEBUG(5,("map_share_mode: FILE_DELETE_ON_CLOSE requested without \
453 DELETE_ACCESS for file %s. (desired_access = 0x%lx)\n",
454 fname, (unsigned long)*desired_access));
457 /* Implicit delete access is *NOT* requested... */
458 smb_open_mode |= DELETE_ON_CLOSE_FLAG;
459 DEBUG(10,("map_share_mode: FILE_DELETE_ON_CLOSE requested. open_mode = 0x%x\n", smb_open_mode));
462 /* Add in the requested share mode. */
463 switch( share_access & (FILE_SHARE_READ|FILE_SHARE_WRITE)) {
464 case FILE_SHARE_READ:
465 smb_open_mode |= SET_DENY_MODE(DENY_WRITE);
467 case FILE_SHARE_WRITE:
468 smb_open_mode |= SET_DENY_MODE(DENY_READ);
470 case (FILE_SHARE_READ|FILE_SHARE_WRITE):
471 smb_open_mode |= SET_DENY_MODE(DENY_NONE);
473 case FILE_SHARE_NONE:
474 smb_open_mode |= SET_DENY_MODE(DENY_ALL);
479 * Handle an O_SYNC request.
482 if(file_attributes & FILE_FLAG_WRITE_THROUGH)
483 smb_open_mode |= FILE_SYNC_OPENMODE;
485 DEBUG(10,("map_share_mode: Mapped desired access 0x%lx, share access 0x%lx, file attributes 0x%lx \
486 to open_mode 0x%x\n", (unsigned long)*desired_access, (unsigned long)share_access,
487 (unsigned long)file_attributes, smb_open_mode ));
489 return smb_open_mode;
492 /****************************************************************************
493 Reply to an NT create and X call on a pipe.
494 ****************************************************************************/
496 static int nt_open_pipe(char *fname, connection_struct *conn,
497 char *inbuf, char *outbuf, int *ppnum)
499 smb_np_struct *p = NULL;
501 uint16 vuid = SVAL(inbuf, smb_uid);
504 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
506 /* See if it is one we want to handle. */
508 if (lp_disable_spoolss() && strequal(fname, "\\spoolss"))
509 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
511 for( i = 0; known_nt_pipes[i]; i++ )
512 if( strequal(fname,known_nt_pipes[i]))
515 if ( known_nt_pipes[i] == NULL )
516 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
518 /* Strip \\ off the name. */
521 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
523 p = open_rpc_pipe_p(fname, conn, vuid);
525 return(ERROR_DOS(ERRSRV,ERRnofids));
532 /****************************************************************************
533 Reply to an NT create and X call for pipes.
534 ****************************************************************************/
536 static int do_ntcreate_pipe_open(connection_struct *conn,
537 char *inbuf,char *outbuf,int length,int bufsize)
544 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
546 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
550 * Deal with pipe return.
553 set_message(outbuf,34,0,True);
555 p = outbuf + smb_vwv2;
559 SIVAL(p,0,FILE_WAS_OPENED);
562 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
565 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
567 SSVAL(p,2, 0x5FF); /* ? */
569 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
571 return chain_reply(inbuf,outbuf,length,bufsize);
574 /****************************************************************************
575 Reply to an NT create and X call.
576 ****************************************************************************/
578 int reply_ntcreate_and_X(connection_struct *conn,
579 char *inbuf,char *outbuf,int length,int bufsize)
583 enum FAKE_FILE_TYPE fake_file_type = FAKE_FILE_TYPE_NONE;
584 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
585 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
586 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
587 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
588 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
589 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
590 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
591 SMB_BIG_UINT allocation_size = 0;
594 /* Breakout the oplock request bits so we can set the
595 reply bits separately. */
596 int oplock_request = 0;
598 SMB_OFF_T file_len = 0;
599 SMB_STRUCT_STAT sbuf;
601 BOOL bad_path = False;
602 files_struct *fsp=NULL;
605 BOOL extended_oplock_granted = False;
608 START_PROFILE(SMBntcreateX);
610 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
611 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
612 create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attributes,
613 share_access, create_disposition,
614 create_options, root_dir_fid ));
616 /* If it's an IPC, use the pipe handler. */
619 if (lp_nt_pipe_support()) {
620 END_PROFILE(SMBntcreateX);
621 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
623 END_PROFILE(SMBntcreateX);
624 return(ERROR_DOS(ERRDOS,ERRnoaccess));
628 if (create_options & FILE_OPEN_BY_FILE_ID) {
629 END_PROFILE(SMBntcreateX);
630 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
634 * We need to construct the open_and_X ofun value from the
635 * NT values, as that's what our code is structured to accept.
638 if((smb_ofun = map_create_disposition( create_disposition )) == -1) {
639 END_PROFILE(SMBntcreateX);
640 return(ERROR_DOS(ERRDOS,ERRnoaccess));
647 if(root_dir_fid != 0) {
649 * This filename is relative to a directory fid.
652 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
656 END_PROFILE(SMBntcreateX);
657 return(ERROR_DOS(ERRDOS,ERRbadfid));
660 if(!dir_fsp->is_directory) {
662 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status,False);
663 if (!NT_STATUS_IS_OK(status)) {
664 END_PROFILE(SMBntcreateX);
665 return ERROR_NT(status);
669 * Check to see if this is a mac fork of some kind.
672 if( strchr_m(fname, ':')) {
673 END_PROFILE(SMBntcreateX);
674 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
678 we need to handle the case when we get a
679 relative open relative to a file and the
680 pathname is blank - this is a reopen!
681 (hint from demyn plantenberg)
684 END_PROFILE(SMBntcreateX);
685 return(ERROR_DOS(ERRDOS,ERRbadfid));
689 * Copy in the base directory name.
692 pstrcpy( fname, dir_fsp->fsp_name );
693 dir_name_len = strlen(fname);
696 * Ensure it ends in a '\'.
699 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
704 srvstr_get_path(inbuf, rel_fname, smb_buf(inbuf), sizeof(rel_fname), 0, STR_TERMINATE, &status,False);
705 if (!NT_STATUS_IS_OK(status)) {
706 END_PROFILE(SMBntcreateX);
707 return ERROR_NT(status);
709 pstrcat(fname, rel_fname);
711 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status,False);
712 if (!NT_STATUS_IS_OK(status)) {
713 END_PROFILE(SMBntcreateX);
714 return ERROR_NT(status);
718 * Check to see if this is a mac fork of some kind.
721 if( strchr_m(fname, ':')) {
723 #ifdef HAVE_SYS_QUOTAS
724 if ((fake_file_type=is_fake_file(fname))!=FAKE_FILE_TYPE_NONE) {
726 * here we go! support for changing the disk quotas --metze
728 * we need to fake up to open this MAGIC QUOTA file
729 * and return a valid FID
731 * w2k close this file directly after openening
732 * xp also tries a QUERY_FILE_INFO on the file and then close it
736 END_PROFILE(SMBntcreateX);
737 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
738 #ifdef HAVE_SYS_QUOTAS
745 * Now contruct the smb_open_mode value from the filename,
746 * desired access and the share access.
748 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
750 if((smb_open_mode = map_share_mode(fname, create_options, &desired_access,
752 file_attributes)) == -1) {
753 END_PROFILE(SMBntcreateX);
754 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
757 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
758 if (oplock_request) {
759 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
763 * Ordinary file or directory.
767 * Check if POSIX semantics are wanted.
770 set_posix_case_semantics(conn, file_attributes);
772 unix_convert(fname,conn,0,&bad_path,&sbuf);
774 /* FAKE_FILE is a special case */
775 if (fake_file_type == FAKE_FILE_TYPE_NONE) {
778 restore_case_semantics(conn, file_attributes);
779 END_PROFILE(SMBntcreateX);
780 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
782 /* All file access must go through check_name() */
783 if (!check_name(fname,conn)) {
784 restore_case_semantics(conn, file_attributes);
785 END_PROFILE(SMBntcreateX);
786 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
791 /* This is the correct thing to do (check every time) but can_delete is
792 expensive (it may have to read the parent directory permissions). So
793 for now we're not doing it unless we have a strong hint the client
794 is really going to delete this file. */
795 if (desired_access & DELETE_ACCESS) {
797 /* Setting FILE_SHARE_DELETE is the hint. */
798 if ((share_access & FILE_SHARE_DELETE) && (desired_access & DELETE_ACCESS)) {
800 status = can_delete(conn, fname, file_attributes, bad_path, True);
801 /* We're only going to fail here if it's access denied, as that's the
802 only error we care about for "can we delete this ?" questions. */
803 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
804 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
805 restore_case_semantics(conn, file_attributes);
806 END_PROFILE(SMBntcreateX);
807 return ERROR_NT(status);
812 * If it's a request for a directory open, deal with it separately.
815 if(create_options & FILE_DIRECTORY_FILE) {
818 /* Can't open a temp directory. IFS kit test. */
819 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
820 END_PROFILE(SMBntcreateX);
821 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
824 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
826 restore_case_semantics(conn, file_attributes);
829 END_PROFILE(SMBntcreateX);
830 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
834 * Ordinary file case.
837 /* NB. We have a potential bug here. If we
838 * cause an oplock break to ourselves, then we
839 * could end up processing filename related
840 * SMB requests whilst we await the oplock
841 * break response. As we may have changed the
842 * filename case semantics to be POSIX-like,
843 * this could mean a filename request could
844 * fail when it should succeed. This is a rare
845 * condition, but eventually we must arrange
846 * to restore the correct case semantics
847 * before issuing an oplock break request to
848 * our client. JRA. */
850 if (fake_file_type==FAKE_FILE_TYPE_NONE) {
851 fsp = open_file_shared1(conn,fname,&sbuf,
854 smb_ofun,file_attributes,oplock_request,
857 /* to open a fake_file --metze */
858 fsp = open_fake_file_shared1(fake_file_type,conn,fname,&sbuf,
861 smb_ofun,file_attributes, oplock_request,
866 /* We cheat here. There are two cases we
867 * care about. One is a directory rename,
868 * where the NT client will attempt to
869 * open the source directory for
870 * DELETE access. Note that when the
871 * NT client does this it does *not*
872 * set the directory bit in the
873 * request packet. This is translated
874 * into a read/write open
875 * request. POSIX states that any open
876 * for write request on a directory
877 * will generate an EISDIR error, so
878 * we can catch this here and open a
879 * pseudo handle that is flagged as a
880 * directory. The second is an open
881 * for a permissions read only, which
882 * we handle in the open_file_stat case. JRA.
885 if(errno == EISDIR) {
888 * Fail the open if it was explicitly a non-directory file.
891 if (create_options & FILE_NON_DIRECTORY_FILE) {
892 restore_case_semantics(conn, file_attributes);
893 SSVAL(outbuf, smb_flg2,
894 SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
895 END_PROFILE(SMBntcreateX);
896 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
900 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
903 restore_case_semantics(conn, file_attributes);
904 END_PROFILE(SMBntcreateX);
905 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
909 restore_case_semantics(conn, file_attributes);
910 END_PROFILE(SMBntcreateX);
911 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
912 /* We have re-scheduled this call. */
913 clear_cached_errors();
916 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
921 restore_case_semantics(conn, file_attributes);
923 file_len = sbuf.st_size;
924 fmode = dos_mode(conn,fname,&sbuf);
926 fmode = FILE_ATTRIBUTE_NORMAL;
927 if (!fsp->is_directory && (fmode & aDIR)) {
928 close_file(fsp,False);
929 END_PROFILE(SMBntcreateX);
930 return ERROR_DOS(ERRDOS,ERRnoaccess);
933 /* Save the requested allocation size. */
934 allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
935 #ifdef LARGE_SMB_OFF_T
936 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
938 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
939 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
940 if (fsp->is_directory) {
941 close_file(fsp,False);
942 END_PROFILE(SMBntcreateX);
943 /* Can't set allocation size on a directory. */
944 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
946 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
947 close_file(fsp,False);
948 END_PROFILE(SMBntcreateX);
949 return ERROR_NT(NT_STATUS_DISK_FULL);
952 fsp->initial_allocation_size = smb_roundup(fsp->conn,(SMB_BIG_UINT)file_len);
956 * If the caller set the extended oplock request bit
957 * and we granted one (by whatever means) - set the
958 * correct bit for extended oplock reply.
961 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
962 extended_oplock_granted = True;
964 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
965 extended_oplock_granted = True;
968 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
969 set_message(outbuf,42,0,True);
971 set_message(outbuf,34,0,True);
974 p = outbuf + smb_vwv2;
977 * Currently as we don't support level II oplocks we just report
978 * exclusive & batch here.
981 if (extended_oplock_granted) {
982 if (flags & REQUEST_BATCH_OPLOCK) {
983 SCVAL(p,0, BATCH_OPLOCK_RETURN);
985 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
987 } else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
988 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
990 SCVAL(p,0,NO_OPLOCK_RETURN);
994 SSVAL(p,0,fsp->fnum);
996 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
997 SIVAL(p,0,FILE_WAS_SUPERSEDED);
999 SIVAL(p,0,smb_action);
1003 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1005 if (lp_dos_filetime_resolution(SNUM(conn))) {
1007 sbuf.st_atime &= ~1;
1008 sbuf.st_mtime &= ~1;
1009 sbuf.st_mtime &= ~1;
1012 put_long_date(p,c_time);
1014 put_long_date(p,sbuf.st_atime); /* access time */
1016 put_long_date(p,sbuf.st_mtime); /* write time */
1018 put_long_date(p,sbuf.st_mtime); /* change time */
1020 SIVAL(p,0,fmode); /* File Attributes. */
1022 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1024 SOFF_T(p,0,file_len);
1026 if (flags & EXTENDED_RESPONSE_REQUIRED)
1029 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1031 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
1033 result = chain_reply(inbuf,outbuf,length,bufsize);
1034 END_PROFILE(SMBntcreateX);
1038 /****************************************************************************
1039 Reply to a NT_TRANSACT_CREATE call to open a pipe.
1040 ****************************************************************************/
1042 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1043 char **ppsetup, uint32 setup_count,
1044 char **ppparams, uint32 parameter_count,
1045 char **ppdata, uint32 data_count)
1048 char *params = *ppparams;
1055 * Ensure minimum number of parameters sent.
1058 if(parameter_count < 54) {
1059 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1060 return ERROR_DOS(ERRDOS,ERRnoaccess);
1063 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status, False);
1064 if (!NT_STATUS_IS_OK(status)) {
1065 return ERROR_NT(status);
1068 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
1071 /* Realloc the size of parameters and data we will return */
1072 params = nttrans_realloc(ppparams, 69);
1074 return ERROR_DOS(ERRDOS,ERRnomem);
1077 SCVAL(p,0,NO_OPLOCK_RETURN);
1082 SIVAL(p,0,FILE_WAS_OPENED);
1086 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
1089 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
1091 SSVAL(p,2, 0x5FF); /* ? */
1093 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
1095 /* Send the required number of replies */
1096 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1101 /****************************************************************************
1102 Internal fn to set security descriptors.
1103 ****************************************************************************/
1105 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
1108 SEC_DESC *psd = NULL;
1109 TALLOC_CTX *mem_ctx;
1112 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
1113 return NT_STATUS_OK;
1117 * Init the parse struct we will unmarshall from.
1120 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
1121 DEBUG(0,("set_sd: talloc_init failed.\n"));
1122 return NT_STATUS_NO_MEMORY;
1125 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1128 * Setup the prs_struct to point at the memory we just
1132 prs_give_memory( &pd, data, sd_len, False);
1135 * Finally, unmarshall from the data buffer.
1138 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1139 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1141 * Return access denied for want of a better error message..
1143 talloc_destroy(mem_ctx);
1144 return NT_STATUS_NO_MEMORY;
1147 if (psd->off_owner_sid==0)
1148 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1149 if (psd->off_grp_sid==0)
1150 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1151 if (psd->off_sacl==0)
1152 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1153 if (psd->off_dacl==0)
1154 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1156 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fd, security_info_sent, psd);
1159 talloc_destroy(mem_ctx);
1160 return NT_STATUS_ACCESS_DENIED;
1163 talloc_destroy(mem_ctx);
1165 return NT_STATUS_OK;
1168 /****************************************************************************
1169 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1170 ****************************************************************************/
1172 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1173 char **ppsetup, uint32 setup_count,
1174 char **ppparams, uint32 parameter_count,
1175 char **ppdata, uint32 data_count, uint32 max_data_count)
1178 char *params = *ppparams;
1179 char *data = *ppdata;
1180 /* Breakout the oplock request bits so we can set the reply bits separately. */
1181 int oplock_request = 0;
1182 int fmode=0,rmode=0;
1183 SMB_OFF_T file_len = 0;
1184 SMB_STRUCT_STAT sbuf;
1186 BOOL bad_path = False;
1187 files_struct *fsp = NULL;
1189 BOOL extended_oplock_granted = False;
1191 uint32 desired_access;
1192 uint32 file_attributes;
1193 uint32 share_access;
1194 uint32 create_disposition;
1195 uint32 create_options;
1197 uint16 root_dir_fid;
1198 SMB_BIG_UINT allocation_size = 0;
1204 DEBUG(5,("call_nt_transact_create\n"));
1207 * If it's an IPC, use the pipe handler.
1211 if (lp_nt_pipe_support())
1212 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1214 ppsetup, setup_count,
1215 ppparams, parameter_count,
1216 ppdata, data_count);
1218 return ERROR_DOS(ERRDOS,ERRnoaccess);
1222 * Ensure minimum number of parameters sent.
1225 if(parameter_count < 54) {
1226 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1227 return ERROR_DOS(ERRDOS,ERRnoaccess);
1230 flags = IVAL(params,0);
1231 desired_access = IVAL(params,8);
1232 file_attributes = IVAL(params,20);
1233 share_access = IVAL(params,24);
1234 create_disposition = IVAL(params,28);
1235 create_options = IVAL(params,32);
1236 sd_len = IVAL(params,36);
1237 root_dir_fid = (uint16)IVAL(params,4);
1239 if (create_options & FILE_OPEN_BY_FILE_ID) {
1240 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1244 * We need to construct the open_and_X ofun value from the
1245 * NT values, as that's what our code is structured to accept.
1248 if((smb_ofun = map_create_disposition( create_disposition )) == -1)
1249 return ERROR_DOS(ERRDOS,ERRbadmem);
1252 * Get the file name.
1255 if(root_dir_fid != 0) {
1257 * This filename is relative to a directory fid.
1259 files_struct *dir_fsp = file_fsp(params,4);
1260 size_t dir_name_len;
1263 return ERROR_DOS(ERRDOS,ERRbadfid);
1265 if(!dir_fsp->is_directory) {
1266 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status, False);
1267 if (!NT_STATUS_IS_OK(status)) {
1268 return ERROR_NT(status);
1272 * Check to see if this is a mac fork of some kind.
1275 if( strchr_m(fname, ':'))
1276 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1278 return ERROR_DOS(ERRDOS,ERRbadfid);
1282 * Copy in the base directory name.
1285 pstrcpy( fname, dir_fsp->fsp_name );
1286 dir_name_len = strlen(fname);
1289 * Ensure it ends in a '\'.
1292 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1293 pstrcat(fname, "/");
1299 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status, False);
1300 if (!NT_STATUS_IS_OK(status)) {
1301 return ERROR_NT(status);
1303 pstrcat(fname, tmpname);
1306 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status, False);
1307 if (!NT_STATUS_IS_OK(status)) {
1308 return ERROR_NT(status);
1312 * Check to see if this is a mac fork of some kind.
1315 if( strchr_m(fname, ':'))
1316 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1320 * Now contruct the smb_open_mode value from the desired access
1321 * and the share access.
1324 if((smb_open_mode = map_share_mode( fname, create_options, &desired_access,
1325 share_access, file_attributes)) == -1)
1326 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1328 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1329 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1332 * Check if POSIX semantics are wanted.
1335 set_posix_case_semantics(conn, file_attributes);
1337 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1339 unix_convert(fname,conn,0,&bad_path,&sbuf);
1341 restore_case_semantics(conn, file_attributes);
1342 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1344 /* All file access must go through check_name() */
1345 if (!check_name(fname,conn)) {
1346 restore_case_semantics(conn, file_attributes);
1347 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
1351 /* This is the correct thing to do (check every time) but can_delete is
1352 expensive (it may have to read the parent directory permissions). So
1353 for now we're not doing it unless we have a strong hint the client
1354 is really going to delete this file. */
1355 if (desired_access & DELETE_ACCESS) {
1357 /* Setting FILE_SHARE_DELETE is the hint. */
1358 if ((share_access & FILE_SHARE_DELETE) && (desired_access & DELETE_ACCESS)) {
1360 status = can_delete(conn, fname, file_attributes, bad_path, True);
1361 /* We're only going to fail here if it's access denied, as that's the
1362 only error we care about for "can we delete this ?" questions. */
1363 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
1364 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
1365 restore_case_semantics(conn, file_attributes);
1366 END_PROFILE(SMBntcreateX);
1367 return ERROR_NT(status);
1372 * If it's a request for a directory open, deal with it separately.
1375 if(create_options & FILE_DIRECTORY_FILE) {
1377 /* Can't open a temp directory. IFS kit test. */
1378 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1379 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1385 * We will get a create directory here if the Win32
1386 * app specified a security descriptor in the
1387 * CreateDirectory() call.
1390 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
1393 restore_case_semantics(conn, file_attributes);
1394 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1400 * Ordinary file case.
1403 fsp = open_file_shared1(conn,fname,&sbuf,desired_access,
1404 smb_open_mode,smb_ofun,file_attributes,
1405 oplock_request,&rmode,&smb_action);
1409 if(errno == EISDIR) {
1412 * Fail the open if it was explicitly a non-directory file.
1415 if (create_options & FILE_NON_DIRECTORY_FILE) {
1416 restore_case_semantics(conn, file_attributes);
1417 SSVAL(outbuf, smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
1418 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1422 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, &smb_action);
1425 restore_case_semantics(conn, file_attributes);
1426 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1429 restore_case_semantics(conn, file_attributes);
1430 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1431 /* We have re-scheduled this call. */
1432 clear_cached_errors();
1435 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1439 file_len = sbuf.st_size;
1440 fmode = dos_mode(conn,fname,&sbuf);
1442 fmode = FILE_ATTRIBUTE_NORMAL;
1445 close_file(fsp,False);
1446 restore_case_semantics(conn, file_attributes);
1447 return ERROR_DOS(ERRDOS,ERRnoaccess);
1451 * If the caller set the extended oplock request bit
1452 * and we granted one (by whatever means) - set the
1453 * correct bit for extended oplock reply.
1456 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
1457 extended_oplock_granted = True;
1459 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
1460 extended_oplock_granted = True;
1464 * According to the MS documentation, the only time the security
1465 * descriptor is applied to the opened file is iff we *created* the
1466 * file; an existing file stays the same.
1468 * Also, it seems (from observation) that you can open the file with
1469 * any access mask but you can still write the sd. We need to override
1470 * the granted access before we call set_sd
1471 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1474 if (lp_nt_acl_support(SNUM(conn)) && sd_len && smb_action == FILE_WAS_CREATED) {
1475 uint32 saved_access = fsp->desired_access;
1477 fsp->desired_access = FILE_GENERIC_ALL;
1479 if (!NT_STATUS_IS_OK(status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION))) {
1480 close_file(fsp,False);
1481 restore_case_semantics(conn, file_attributes);
1482 return ERROR_NT(status);
1484 fsp->desired_access = saved_access;
1487 restore_case_semantics(conn, file_attributes);
1489 /* Save the requested allocation size. */
1490 allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1491 #ifdef LARGE_SMB_OFF_T
1492 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1494 if (allocation_size && (allocation_size > file_len)) {
1495 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
1496 if (fsp->is_directory) {
1497 close_file(fsp,False);
1498 END_PROFILE(SMBntcreateX);
1499 /* Can't set allocation size on a directory. */
1500 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1502 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1503 close_file(fsp,False);
1504 return ERROR_NT(NT_STATUS_DISK_FULL);
1507 fsp->initial_allocation_size = smb_roundup(fsp->conn, (SMB_BIG_UINT)file_len);
1510 /* Realloc the size of parameters and data we will return */
1511 params = nttrans_realloc(ppparams, 69);
1513 return ERROR_DOS(ERRDOS,ERRnomem);
1516 if (extended_oplock_granted)
1517 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1518 else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
1519 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1521 SCVAL(p,0,NO_OPLOCK_RETURN);
1524 SSVAL(p,0,fsp->fnum);
1526 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
1527 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1529 SIVAL(p,0,smb_action);
1533 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1535 if (lp_dos_filetime_resolution(SNUM(conn))) {
1537 sbuf.st_atime &= ~1;
1538 sbuf.st_mtime &= ~1;
1539 sbuf.st_mtime &= ~1;
1542 put_long_date(p,c_time);
1544 put_long_date(p,sbuf.st_atime); /* access time */
1546 put_long_date(p,sbuf.st_mtime); /* write time */
1548 put_long_date(p,sbuf.st_mtime); /* change time */
1550 SIVAL(p,0,fmode); /* File Attributes. */
1552 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1554 SOFF_T(p,0,file_len);
1556 if (flags & EXTENDED_RESPONSE_REQUIRED)
1559 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1561 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1563 /* Send the required number of replies */
1564 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1569 /****************************************************************************
1570 Reply to a NT CANCEL request.
1571 ****************************************************************************/
1573 int reply_ntcancel(connection_struct *conn,
1574 char *inbuf,char *outbuf,int length,int bufsize)
1577 * Go through and cancel any pending change notifies.
1580 int mid = SVAL(inbuf,smb_mid);
1581 START_PROFILE(SMBntcancel);
1582 remove_pending_change_notify_requests_by_mid(mid);
1583 remove_pending_lock_requests_by_mid(mid);
1584 srv_cancel_sign_response(mid);
1586 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1588 END_PROFILE(SMBntcancel);
1592 /****************************************************************************
1594 ****************************************************************************/
1596 static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *newname, uint16 attrs)
1598 BOOL bad_path_oldname = False;
1599 BOOL bad_path_newname = False;
1600 SMB_STRUCT_STAT sbuf1, sbuf2;
1601 pstring last_component_oldname;
1602 pstring last_component_newname;
1603 files_struct *fsp1,*fsp2;
1609 NTSTATUS status = NT_STATUS_OK;
1615 if (ms_has_wild(newname) || ms_has_wild(oldname)) {
1616 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1619 if (!CAN_WRITE(conn))
1620 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1622 unix_convert(oldname,conn,last_component_oldname,&bad_path_oldname,&sbuf1);
1623 if (bad_path_oldname) {
1624 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1627 /* Quick check for "." and ".." */
1628 if (last_component_oldname[0] == '.') {
1629 if (!last_component_oldname[1] || (last_component_oldname[1] == '.' && !last_component_oldname[2])) {
1630 return NT_STATUS_OBJECT_NAME_INVALID;
1634 /* Source must already exist. */
1635 if (!VALID_STAT(sbuf1)) {
1636 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1638 if (!check_name(oldname,conn)) {
1639 return NT_STATUS_ACCESS_DENIED;
1642 /* Ensure attributes match. */
1643 fmode = dos_mode(conn,oldname,&sbuf1);
1644 if ((fmode & ~attrs) & (aHIDDEN | aSYSTEM))
1645 return NT_STATUS_NO_SUCH_FILE;
1647 unix_convert(newname,conn,last_component_newname,&bad_path_newname,&sbuf2);
1648 if (bad_path_newname) {
1649 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1652 /* Quick check for "." and ".." */
1653 if (last_component_newname[0] == '.') {
1654 if (!last_component_newname[1] || (last_component_newname[1] == '.' && !last_component_newname[2])) {
1655 return NT_STATUS_OBJECT_NAME_INVALID;
1659 /* Disallow if newname already exists. */
1660 if (VALID_STAT(sbuf2)) {
1661 return NT_STATUS_OBJECT_NAME_COLLISION;
1664 if (!check_name(newname,conn)) {
1665 return NT_STATUS_ACCESS_DENIED;
1668 /* No links from a directory. */
1669 if (S_ISDIR(sbuf1.st_mode)) {
1670 return NT_STATUS_FILE_IS_A_DIRECTORY;
1673 /* Ensure this is within the share. */
1674 if (!reduce_name(conn, oldname) != 0) {
1675 return NT_STATUS_ACCESS_DENIED;
1678 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname, newname));
1680 fsp1 = open_file_shared1(conn,oldname,&sbuf1,FILE_READ_DATA,SET_DENY_MODE(DENY_ALL)|SET_OPEN_MODE(DOS_OPEN_RDONLY),
1681 (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN),FILE_ATTRIBUTE_NORMAL,0,
1682 &access_mode,&smb_action);
1685 status = NT_STATUS_ACCESS_DENIED;
1686 if (unix_ERR_class == ERRDOS && unix_ERR_code == ERRbadshare)
1687 status = NT_STATUS_SHARING_VIOLATION;
1690 unix_ERR_ntstatus = NT_STATUS_OK;
1694 fsp2 = open_file_shared1(conn,newname,&sbuf2,FILE_WRITE_DATA,SET_DENY_MODE(DENY_ALL)|SET_OPEN_MODE(DOS_OPEN_WRONLY),
1695 (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_FAIL),fmode,INTERNAL_OPEN_ONLY,
1696 &access_mode,&smb_action);
1699 status = NT_STATUS_ACCESS_DENIED;
1700 if (unix_ERR_class == ERRDOS && unix_ERR_code == ERRbadshare)
1701 status = NT_STATUS_SHARING_VIOLATION;
1704 unix_ERR_ntstatus = NT_STATUS_OK;
1705 close_file(fsp1,False);
1710 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1713 * As we are opening fsp1 read-only we only expect
1714 * an error on close on fsp2 if we are out of space.
1715 * Thus we don't look at the error return from the
1718 close_file(fsp1,False);
1720 /* Ensure the modtime is set correctly on the destination file. */
1721 fsp_set_pending_modtime(fsp2, sbuf1.st_mtime);
1723 close_ret = close_file(fsp2,False);
1725 /* Grrr. We have to do this as open_file_shared1 adds aARCH when it
1726 creates the file. This isn't the correct thing to do in the copy case. JRA */
1727 file_set_dosmode(conn, newname, fmode, &sbuf2, True);
1729 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1730 return NT_STATUS_DISK_FULL;
1733 if (close_ret != 0) {
1734 status = map_nt_error_from_unix(close_ret);
1735 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1736 nt_errstr(status), oldname, newname));
1741 /****************************************************************************
1742 Reply to a NT rename request.
1743 ****************************************************************************/
1745 int reply_ntrename(connection_struct *conn,
1746 char *inbuf,char *outbuf,int length,int bufsize)
1753 uint16 attrs = SVAL(inbuf,smb_vwv0);
1754 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1756 START_PROFILE(SMBntrename);
1758 p = smb_buf(inbuf) + 1;
1759 p += srvstr_get_path(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, True);
1760 if (!NT_STATUS_IS_OK(status)) {
1761 END_PROFILE(SMBntrename);
1762 return ERROR_NT(status);
1765 if( strchr_m(oldname, ':')) {
1766 /* Can't rename a stream. */
1767 END_PROFILE(SMBntrename);
1768 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1771 if (ms_has_wild(oldname)) {
1772 END_PROFILE(SMBntrename);
1773 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1777 p += srvstr_get_path(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status, False);
1778 if (!NT_STATUS_IS_OK(status)) {
1779 END_PROFILE(SMBntrename);
1780 return ERROR_NT(status);
1783 RESOLVE_DFSPATH(oldname, conn, inbuf, outbuf);
1784 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1786 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1788 switch(rename_type) {
1789 case RENAME_FLAG_RENAME:
1790 status = rename_internals(conn, oldname, newname, attrs, False);
1792 case RENAME_FLAG_HARD_LINK:
1793 status = hardlink_internals(conn, oldname, newname);
1795 case RENAME_FLAG_COPY:
1796 status = copy_internals(conn, oldname, newname, attrs);
1798 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1799 status = NT_STATUS_INVALID_PARAMETER;
1802 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1806 if (!NT_STATUS_IS_OK(status)) {
1807 END_PROFILE(SMBntrename);
1808 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1809 /* We have re-scheduled this call. */
1810 clear_cached_errors();
1813 return ERROR_NT(status);
1817 * Win2k needs a changenotify request response before it will
1818 * update after a rename..
1820 process_pending_change_notify_queue((time_t)0);
1821 outsize = set_message(outbuf,0,0,True);
1823 END_PROFILE(SMBntrename);
1827 /****************************************************************************
1828 Reply to an unsolicited SMBNTtranss - just ignore it!
1829 ****************************************************************************/
1831 int reply_nttranss(connection_struct *conn,
1832 char *inbuf,char *outbuf,int length,int bufsize)
1834 START_PROFILE(SMBnttranss);
1835 DEBUG(4,("Ignoring nttranss of length %d\n",length));
1836 END_PROFILE(SMBnttranss);
1840 /****************************************************************************
1841 Reply to a notify change - queue the request and
1842 don't allow a directory to be opened.
1843 ****************************************************************************/
1845 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1846 char **ppsetup, uint32 setup_count,
1847 char **ppparams, uint32 parameter_count,
1848 char **ppdata, uint32 data_count, uint32 max_data_count)
1850 char *setup = *ppsetup;
1855 return ERROR_DOS(ERRDOS,ERRbadfunc);
1857 fsp = file_fsp(setup,4);
1858 flags = IVAL(setup, 0);
1860 DEBUG(3,("call_nt_transact_notify_change\n"));
1863 return ERROR_DOS(ERRDOS,ERRbadfid);
1865 if((!fsp->is_directory) || (conn != fsp->conn))
1866 return ERROR_DOS(ERRDOS,ERRbadfid);
1868 if (!change_notify_set(inbuf, fsp, conn, flags))
1869 return(UNIXERROR(ERRDOS,ERRbadfid));
1871 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1872 name = %s\n", fsp->fsp_name ));
1877 /****************************************************************************
1878 Reply to an NT transact rename command.
1879 ****************************************************************************/
1881 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1882 char **ppsetup, uint32 setup_count,
1883 char **ppparams, uint32 parameter_count,
1884 char **ppdata, uint32 data_count, uint32 max_data_count)
1886 char *params = *ppparams;
1888 files_struct *fsp = NULL;
1889 BOOL replace_if_exists = False;
1892 if(parameter_count < 4)
1893 return ERROR_DOS(ERRDOS,ERRbadfunc);
1895 fsp = file_fsp(params, 0);
1896 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1897 CHECK_FSP(fsp, conn);
1898 srvstr_get_path(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE, &status, True);
1899 if (!NT_STATUS_IS_OK(status)) {
1900 return ERROR_NT(status);
1903 status = rename_internals(conn, fsp->fsp_name,
1904 new_name, 0, replace_if_exists);
1905 if (!NT_STATUS_IS_OK(status))
1906 return ERROR_NT(status);
1909 * Rename was successful.
1911 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1913 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1914 fsp->fsp_name, new_name));
1917 * Win2k needs a changenotify request response before it will
1918 * update after a rename..
1921 process_pending_change_notify_queue((time_t)0);
1926 /******************************************************************************
1927 Fake up a completely empty SD.
1928 *******************************************************************************/
1930 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1932 extern DOM_SID global_sid_World;
1935 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1937 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1944 /****************************************************************************
1945 Reply to query a security descriptor.
1946 ****************************************************************************/
1948 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1949 char **ppsetup, uint32 setup_count,
1950 char **ppparams, uint32 parameter_count,
1951 char **ppdata, uint32 data_count, uint32 max_data_count)
1953 char *params = *ppparams;
1954 char *data = *ppdata;
1956 SEC_DESC *psd = NULL;
1958 uint32 security_info_wanted;
1959 TALLOC_CTX *mem_ctx;
1960 files_struct *fsp = NULL;
1962 if(parameter_count < 8)
1963 return ERROR_DOS(ERRDOS,ERRbadfunc);
1965 fsp = file_fsp(params,0);
1967 return ERROR_DOS(ERRDOS,ERRbadfid);
1969 security_info_wanted = IVAL(params,4);
1971 DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp->fsp_name ));
1973 params = nttrans_realloc(ppparams, 4);
1975 return ERROR_DOS(ERRDOS,ERRnomem);
1977 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1978 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1979 return ERROR_DOS(ERRDOS,ERRnomem);
1983 * Get the permissions to return.
1986 if (!lp_nt_acl_support(SNUM(conn)))
1987 sd_size = get_null_nt_acl(mem_ctx, &psd);
1989 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fd, security_info_wanted, &psd);
1992 talloc_destroy(mem_ctx);
1993 return(UNIXERROR(ERRDOS,ERRnoaccess));
1996 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size));
1998 SIVAL(params,0,(uint32)sd_size);
2000 if(max_data_count < sd_size) {
2002 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
2003 params, 4, *ppdata, 0);
2004 talloc_destroy(mem_ctx);
2009 * Allocate the data we will point this at.
2012 data = nttrans_realloc(ppdata, sd_size);
2014 talloc_destroy(mem_ctx);
2015 return ERROR_DOS(ERRDOS,ERRnomem);
2019 * Init the parse struct we will marshall into.
2022 prs_init(&pd, 0, mem_ctx, MARSHALL);
2025 * Setup the prs_struct to point at the memory we just
2029 prs_give_memory( &pd, data, (uint32)sd_size, False);
2032 * Finally, linearize into the outgoing buffer.
2035 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2036 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2037 security descriptor.\n"));
2039 * Return access denied for want of a better error message..
2041 talloc_destroy(mem_ctx);
2042 return(UNIXERROR(ERRDOS,ERRnoaccess));
2046 * Now we can delete the security descriptor.
2049 talloc_destroy(mem_ctx);
2051 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 4, data, (int)sd_size);
2055 /****************************************************************************
2056 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2057 ****************************************************************************/
2059 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2060 char **ppsetup, uint32 setup_count,
2061 char **ppparams, uint32 parameter_count,
2062 char **ppdata, uint32 data_count, uint32 max_data_count)
2064 char *params= *ppparams;
2065 char *data = *ppdata;
2066 files_struct *fsp = NULL;
2067 uint32 security_info_sent = 0;
2070 if(parameter_count < 8)
2071 return ERROR_DOS(ERRDOS,ERRbadfunc);
2073 if((fsp = file_fsp(params,0)) == NULL)
2074 return ERROR_DOS(ERRDOS,ERRbadfid);
2076 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);
2087 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent)))
2088 return ERROR_NT(nt_status);
2092 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2096 /****************************************************************************
2098 ****************************************************************************/
2100 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2101 char **ppsetup, uint32 setup_count,
2102 char **ppparams, uint32 parameter_count,
2103 char **ppdata, uint32 data_count, uint32 max_data_count)
2110 static BOOL logged_message;
2111 char *pdata = *ppdata;
2113 if (setup_count != 8) {
2114 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2115 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2118 function = IVAL(*ppsetup, 0);
2119 fidnum = SVAL(*ppsetup, 4);
2120 isFSctl = CVAL(*ppsetup, 6);
2121 compfilter = CVAL(*ppsetup, 7);
2123 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2124 function, fidnum, isFSctl, compfilter));
2126 fsp=file_fsp(*ppsetup, 4);
2127 /* this check is done in each implemented function case for now
2128 because I don't want to break anything... --metze
2129 FSP_BELONGS_CONN(fsp,conn);*/
2132 case FSCTL_SET_SPARSE:
2133 /* pretend this succeeded - tho strictly we should
2134 mark the file sparse (if the local fs supports it)
2135 so we can know if we need to pre-allocate or not */
2137 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2138 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2141 case FSCTL_0x000900C0:
2142 /* pretend this succeeded - don't know what this really is
2143 but works ok like this --metze
2146 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2147 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2150 case FSCTL_GET_REPARSE_POINT:
2151 /* pretend this fail - my winXP does it like this
2155 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2156 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2159 case FSCTL_SET_REPARSE_POINT:
2160 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2164 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2165 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2168 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
2171 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2172 * and return their volume names. If max_data_count is 16, then it is just
2173 * asking for the number of volumes and length of the combined names.
2175 * pdata is the data allocated by our caller, but that uses
2176 * total_data_count (which is 0 in our case) rather than max_data_count.
2177 * Allocate the correct amount and return the pointer to let
2178 * it be deallocated when we return.
2180 SHADOW_COPY_DATA *shadow_data = NULL;
2181 TALLOC_CTX *shadow_mem_ctx = NULL;
2182 BOOL labels = False;
2183 uint32 labels_data_count = 0;
2187 FSP_BELONGS_CONN(fsp,conn);
2189 if (max_data_count < 16) {
2190 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2192 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2195 if (max_data_count > 16) {
2199 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2200 if (shadow_mem_ctx == NULL) {
2201 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2202 return ERROR_NT(NT_STATUS_NO_MEMORY);
2205 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2206 if (shadow_data == NULL) {
2207 DEBUG(0,("talloc_zero() failed!\n"));
2208 talloc_destroy(shadow_mem_ctx);
2209 return ERROR_NT(NT_STATUS_NO_MEMORY);
2212 shadow_data->mem_ctx = shadow_mem_ctx;
2215 * Call the VFS routine to actually do the work.
2217 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2218 talloc_destroy(shadow_data->mem_ctx);
2219 if (errno == ENOSYS) {
2220 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2221 conn->connectpath));
2222 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2224 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2225 conn->connectpath));
2226 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
2230 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2235 data_count = 12+labels_data_count+4;
2238 if (max_data_count<data_count) {
2239 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2240 max_data_count,data_count));
2241 talloc_destroy(shadow_data->mem_ctx);
2242 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
2245 pdata = nttrans_realloc(ppdata, data_count);
2246 if (pdata == NULL) {
2247 talloc_destroy(shadow_data->mem_ctx);
2248 return ERROR_NT(NT_STATUS_NO_MEMORY);
2253 /* num_volumes 4 bytes */
2254 SIVAL(pdata,0,shadow_data->num_volumes);
2257 /* num_labels 4 bytes */
2258 SIVAL(pdata,4,shadow_data->num_volumes);
2261 /* needed_data_count 4 bytes */
2262 SIVAL(pdata,8,labels_data_count);
2266 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2267 shadow_data->num_volumes,fsp->fsp_name));
2268 if (labels && shadow_data->labels) {
2269 for (i=0;i<shadow_data->num_volumes;i++) {
2270 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2271 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2272 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2276 talloc_destroy(shadow_data->mem_ctx);
2278 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
2283 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2285 /* pretend this succeeded -
2287 * we have to send back a list with all files owned by this SID
2289 * but I have to check that --metze
2293 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2295 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2297 FSP_BELONGS_CONN(fsp,conn);
2299 /* unknown 4 bytes: this is not the length of the sid :-( */
2300 /*unknown = IVAL(pdata,0);*/
2302 sid_parse(pdata+4,sid_len,&sid);
2303 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2305 if (!NT_STATUS_IS_OK(sid_to_uid(&sid, &uid))) {
2306 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2307 sid_string_static(&sid),(unsigned long)sid_len));
2311 /* we can take a look at the find source :-)
2313 * find ./ -uid $uid -name '*' is what we need here
2316 * and send 4bytes len and then NULL terminated unicode strings
2319 * but I don't know how to deal with the paged results
2320 * (maybe we can hang the result anywhere in the fsp struct)
2322 * we don't send all files at once
2323 * and at the next we should *not* start from the beginning,
2324 * so we have to cache the result
2329 /* this works for now... */
2330 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2334 if (!logged_message) {
2335 logged_message = True; /* Only print this once... */
2336 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2341 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2345 #ifdef HAVE_SYS_QUOTAS
2346 /****************************************************************************
2347 Reply to get user quota
2348 ****************************************************************************/
2350 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2351 char **ppsetup, uint32 setup_count,
2352 char **ppparams, uint32 parameter_count,
2353 char **ppdata, uint32 data_count, uint32 max_data_count)
2355 NTSTATUS nt_status = NT_STATUS_OK;
2356 char *params = *ppparams;
2357 char *pdata = *ppdata;
2359 int data_len=0,param_len=0;
2362 files_struct *fsp = NULL;
2366 BOOL start_enum = True;
2367 SMB_NTQUOTA_STRUCT qt;
2368 SMB_NTQUOTA_LIST *tmp_list;
2369 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2370 extern struct current_user current_user;
2375 if (current_user.uid != 0) {
2376 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2377 lp_servicename(SNUM(conn)),conn->user));
2378 return ERROR_DOS(ERRDOS,ERRnoaccess);
2382 * Ensure minimum number of parameters sent.
2385 if (parameter_count < 4) {
2386 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2387 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2390 /* maybe we can check the quota_fnum */
2391 fsp = file_fsp(params,0);
2392 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2393 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2394 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2397 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2398 * is done by CHECK_NTQUOTA_HANDLE_OK()
2400 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2402 level = SVAL(params,2);
2404 /* unknown 12 bytes leading in params */
2407 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2408 /* seems that we should continue with the enum here --metze */
2410 if (qt_handle->quota_list!=NULL &&
2411 qt_handle->tmp_list==NULL) {
2414 free_ntquota_list(&(qt_handle->quota_list));
2416 /* Realloc the size of parameters and data we will return */
2418 params = nttrans_realloc(ppparams, param_len);
2420 return ERROR_DOS(ERRDOS,ERRnomem);
2423 SIVAL(params,0,data_len);
2430 case TRANSACT_GET_USER_QUOTA_LIST_START:
2432 if (qt_handle->quota_list==NULL &&
2433 qt_handle->tmp_list==NULL) {
2437 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2438 return ERROR_DOS(ERRSRV,ERRerror);
2440 /* Realloc the size of parameters and data we will return */
2442 params = nttrans_realloc(ppparams, param_len);
2444 return ERROR_DOS(ERRDOS,ERRnomem);
2446 /* we should not trust the value in max_data_count*/
2447 max_data_count = MIN(max_data_count,2048);
2449 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2451 return ERROR_DOS(ERRDOS,ERRnomem);
2456 /* set params Size of returned Quota Data 4 bytes*/
2457 /* but set it later when we know it */
2459 /* for each entry push the data */
2462 qt_handle->tmp_list = qt_handle->quota_list;
2465 tmp_list = qt_handle->tmp_list;
2467 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2468 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2470 sid_len = sid_size(&tmp_list->quotas->sid);
2471 entry_len = 40 + sid_len;
2473 /* nextoffset entry 4 bytes */
2474 SIVAL(entry,0,entry_len);
2476 /* then the len of the SID 4 bytes */
2477 SIVAL(entry,4,sid_len);
2479 /* unknown data 8 bytes SMB_BIG_UINT */
2480 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2482 /* the used disk space 8 bytes SMB_BIG_UINT */
2483 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2485 /* the soft quotas 8 bytes SMB_BIG_UINT */
2486 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2488 /* the hard quotas 8 bytes SMB_BIG_UINT */
2489 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2491 /* and now the SID */
2492 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2495 qt_handle->tmp_list = tmp_list;
2497 /* overwrite the offset of the last entry */
2498 SIVAL(entry-entry_len,0,0);
2500 data_len = 4+qt_len;
2501 /* overwrite the params quota_data_len */
2502 SIVAL(params,0,data_len);
2506 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2508 /* unknown 4 bytes IVAL(pdata,0) */
2510 if (data_count < 8) {
2511 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2512 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2515 sid_len = IVAL(pdata,4);
2516 /* Ensure this is less than 1mb. */
2517 if (sid_len > (1024*1024)) {
2518 return ERROR_DOS(ERRDOS,ERRnomem);
2521 if (data_count < 8+sid_len) {
2522 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2523 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2526 data_len = 4+40+sid_len;
2528 if (max_data_count < data_len) {
2529 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2530 max_data_count, data_len));
2532 SIVAL(params,0,data_len);
2534 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2538 sid_parse(pdata+8,sid_len,&sid);
2541 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2544 * we have to return zero's in all fields
2545 * instead of returning an error here
2550 /* Realloc the size of parameters and data we will return */
2552 params = nttrans_realloc(ppparams, param_len);
2554 return ERROR_DOS(ERRDOS,ERRnomem);
2556 pdata = nttrans_realloc(ppdata, data_len);
2558 return ERROR_DOS(ERRDOS,ERRnomem);
2562 /* set params Size of returned Quota Data 4 bytes*/
2563 SIVAL(params,0,data_len);
2565 /* nextoffset entry 4 bytes */
2568 /* then the len of the SID 4 bytes */
2569 SIVAL(entry,4,sid_len);
2571 /* unknown data 8 bytes SMB_BIG_UINT */
2572 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2574 /* the used disk space 8 bytes SMB_BIG_UINT */
2575 SBIG_UINT(entry,16,qt.usedspace);
2577 /* the soft quotas 8 bytes SMB_BIG_UINT */
2578 SBIG_UINT(entry,24,qt.softlim);
2580 /* the hard quotas 8 bytes SMB_BIG_UINT */
2581 SBIG_UINT(entry,32,qt.hardlim);
2583 /* and now the SID */
2584 sid_linearize(entry+40, sid_len, &sid);
2589 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2590 return ERROR_DOS(ERRSRV,ERRerror);
2594 send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
2599 /****************************************************************************
2600 Reply to set user quota
2601 ****************************************************************************/
2603 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2604 char **ppsetup, uint32 setup_count,
2605 char **ppparams, uint32 parameter_count,
2606 char **ppdata, uint32 data_count, uint32 max_data_count)
2608 char *params = *ppparams;
2609 char *pdata = *ppdata;
2610 int data_len=0,param_len=0;
2611 SMB_NTQUOTA_STRUCT qt;
2614 files_struct *fsp = NULL;
2619 if (current_user.uid != 0) {
2620 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2621 lp_servicename(SNUM(conn)),conn->user));
2622 return ERROR_DOS(ERRDOS,ERRnoaccess);
2626 * Ensure minimum number of parameters sent.
2629 if (parameter_count < 2) {
2630 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2631 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2634 /* maybe we can check the quota_fnum */
2635 fsp = file_fsp(params,0);
2636 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2637 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2638 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2641 if (data_count < 40) {
2642 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2643 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2646 /* offset to next quota record.
2647 * 4 bytes IVAL(pdata,0)
2652 sid_len = IVAL(pdata,4);
2654 if (data_count < 40+sid_len) {
2655 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2656 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2659 /* unknown 8 bytes in pdata
2660 * maybe its the change time in NTTIME
2663 /* the used space 8 bytes (SMB_BIG_UINT)*/
2664 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2665 #ifdef LARGE_SMB_OFF_T
2666 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2667 #else /* LARGE_SMB_OFF_T */
2668 if ((IVAL(pdata,20) != 0)&&
2669 ((qt.usedspace != 0xFFFFFFFF)||
2670 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2671 /* more than 32 bits? */
2672 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2674 #endif /* LARGE_SMB_OFF_T */
2676 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2677 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2678 #ifdef LARGE_SMB_OFF_T
2679 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2680 #else /* LARGE_SMB_OFF_T */
2681 if ((IVAL(pdata,28) != 0)&&
2682 ((qt.softlim != 0xFFFFFFFF)||
2683 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2684 /* more than 32 bits? */
2685 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2687 #endif /* LARGE_SMB_OFF_T */
2689 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2690 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2691 #ifdef LARGE_SMB_OFF_T
2692 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2693 #else /* LARGE_SMB_OFF_T */
2694 if ((IVAL(pdata,36) != 0)&&
2695 ((qt.hardlim != 0xFFFFFFFF)||
2696 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2697 /* more than 32 bits? */
2698 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2700 #endif /* LARGE_SMB_OFF_T */
2702 sid_parse(pdata+40,sid_len,&sid);
2703 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2705 /* 44 unknown bytes left... */
2707 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2708 return ERROR_DOS(ERRSRV,ERRerror);
2711 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
2715 #endif /* HAVE_SYS_QUOTAS */
2717 /****************************************************************************
2718 Reply to a SMBNTtrans.
2719 ****************************************************************************/
2721 int reply_nttrans(connection_struct *conn,
2722 char *inbuf,char *outbuf,int length,int bufsize)
2725 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2726 #if 0 /* Not used. */
2727 uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount);
2728 uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
2729 #endif /* Not used. */
2730 uint32 total_parameter_count = IVAL(inbuf, smb_nt_TotalParameterCount);
2731 uint32 total_data_count = IVAL(inbuf, smb_nt_TotalDataCount);
2732 uint32 parameter_count = IVAL(inbuf,smb_nt_ParameterCount);
2733 uint32 parameter_offset = IVAL(inbuf,smb_nt_ParameterOffset);
2734 uint32 data_count = IVAL(inbuf,smb_nt_DataCount);
2735 uint32 data_offset = IVAL(inbuf,smb_nt_DataOffset);
2736 uint16 setup_count = 2*CVAL(inbuf,smb_nt_SetupCount); /* setup count is in *words* */
2737 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2738 char *params = NULL, *data = NULL, *setup = NULL;
2739 uint32 num_params_sofar, num_data_sofar;
2740 START_PROFILE(SMBnttrans);
2742 if(global_oplock_break &&
2743 ((function_code == NT_TRANSACT_CREATE) ||
2744 (function_code == NT_TRANSACT_RENAME))) {
2746 * Queue this open message as we are the process of an oplock break.
2749 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2750 due to being in oplock break state.\n", (unsigned int)function_code ));
2752 push_oplock_pending_smb_message( inbuf, length);
2753 END_PROFILE(SMBnttrans);
2757 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2758 END_PROFILE(SMBnttrans);
2759 return ERROR_DOS(ERRSRV,ERRaccess);
2762 outsize = set_message(outbuf,0,0,True);
2765 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2766 * Ensure this is so as a sanity check.
2769 if(CVAL(inbuf, smb_wct) != 19 + (setup_count/2)) {
2770 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2771 CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
2775 /* Don't allow more than 128mb for each value. */
2776 if ((total_parameter_count > (1024*1024*128)) || (total_data_count > (1024*1024*128))) {
2777 END_PROFILE(SMBnttrans);
2778 return ERROR_DOS(ERRDOS,ERRnomem);
2781 /* Allocate the space for the setup, the maximum needed parameters and data */
2784 setup = (char *)SMB_MALLOC(setup_count);
2785 if (total_parameter_count > 0)
2786 params = (char *)SMB_MALLOC(total_parameter_count);
2787 if (total_data_count > 0)
2788 data = (char *)SMB_MALLOC(total_data_count);
2790 if ((total_parameter_count && !params) || (total_data_count && !data) ||
2791 (setup_count && !setup)) {
2795 DEBUG(0,("reply_nttrans : Out of memory\n"));
2796 END_PROFILE(SMBnttrans);
2797 return ERROR_DOS(ERRDOS,ERRnomem);
2800 /* Copy the param and data bytes sent with this request into the params buffer */
2801 num_params_sofar = parameter_count;
2802 num_data_sofar = data_count;
2804 if (parameter_count > total_parameter_count || data_count > total_data_count)
2808 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
2809 if ((smb_nt_SetupStart + setup_count < smb_nt_SetupStart) ||
2810 (smb_nt_SetupStart + setup_count < setup_count))
2812 if (smb_nt_SetupStart + setup_count > length)
2815 memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
2816 dump_data(10, setup, setup_count);
2819 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count));
2820 if ((parameter_offset + parameter_count < parameter_offset) ||
2821 (parameter_offset + parameter_count < parameter_count))
2823 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length)||
2824 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
2827 memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
2828 dump_data(10, params, parameter_count);
2831 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
2832 if ((data_offset + data_count < data_offset) || (data_offset + data_count < data_count))
2834 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2835 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
2838 memcpy( data, smb_base(inbuf) + data_offset, data_count);
2839 dump_data(10, data, data_count);
2842 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2844 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2845 /* We need to send an interim response then receive the rest
2846 of the parameter/data bytes */
2847 outsize = set_message(outbuf,0,0,True);
2848 srv_signing_trans_stop();
2849 if (!send_smb(smbd_server_fd(),outbuf))
2850 exit_server("reply_nttrans: send_smb failed.");
2852 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2854 uint32 parameter_displacement;
2855 uint32 data_displacement;
2857 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
2860 * The sequence number for the trans reply is always
2861 * based on the last secondary received.
2864 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2866 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
2867 outsize = set_message(outbuf,0,0,True);
2869 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2871 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2872 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
2877 /* Revise total_params and total_data in case they have changed downwards */
2878 if (IVAL(inbuf, smb_nts_TotalParameterCount) < total_parameter_count)
2879 total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
2880 if (IVAL(inbuf, smb_nts_TotalDataCount) < total_data_count)
2881 total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
2883 parameter_count = IVAL(inbuf,smb_nts_ParameterCount);
2884 parameter_offset = IVAL(inbuf, smb_nts_ParameterOffset);
2885 parameter_displacement = IVAL(inbuf, smb_nts_ParameterDisplacement);
2886 num_params_sofar += parameter_count;
2888 data_count = IVAL(inbuf, smb_nts_DataCount);
2889 data_displacement = IVAL(inbuf, smb_nts_DataDisplacement);
2890 data_offset = IVAL(inbuf, smb_nts_DataOffset);
2891 num_data_sofar += data_count;
2893 if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count) {
2894 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2898 if (parameter_count) {
2899 if (parameter_displacement + parameter_count > total_parameter_count)
2901 if ((parameter_displacement + parameter_count < parameter_displacement) ||
2902 (parameter_displacement + parameter_count < parameter_count))
2904 if (parameter_displacement > total_parameter_count)
2906 if ((smb_base(inbuf) + parameter_offset + parameter_count >= inbuf + bufsize) ||
2907 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
2909 if (parameter_displacement + params < params)
2912 memcpy( ¶ms[parameter_displacement], smb_base(inbuf) + parameter_offset, parameter_count);
2916 if (data_displacement + data_count > total_data_count)
2918 if ((data_displacement + data_count < data_displacement) ||
2919 (data_displacement + data_count < data_count))
2921 if (data_displacement > total_data_count)
2923 if ((smb_base(inbuf) + data_offset + data_count >= inbuf + bufsize) ||
2924 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
2926 if (data_displacement + data < data)
2929 memcpy( &data[data_displacement], smb_base(inbuf)+ data_offset, data_count);
2934 if (Protocol >= PROTOCOL_NT1)
2935 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_IS_LONG_NAME);
2937 /* Now we must call the relevant NT_TRANS function */
2938 switch(function_code) {
2939 case NT_TRANSACT_CREATE:
2940 START_PROFILE_NESTED(NT_transact_create);
2941 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2943 &setup, setup_count,
2944 ¶ms, total_parameter_count,
2945 &data, total_data_count, max_data_count);
2946 END_PROFILE_NESTED(NT_transact_create);
2948 case NT_TRANSACT_IOCTL:
2949 START_PROFILE_NESTED(NT_transact_ioctl);
2950 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2952 &setup, setup_count,
2953 ¶ms, total_parameter_count,
2954 &data, total_data_count, max_data_count);
2955 END_PROFILE_NESTED(NT_transact_ioctl);
2957 case NT_TRANSACT_SET_SECURITY_DESC:
2958 START_PROFILE_NESTED(NT_transact_set_security_desc);
2959 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2961 &setup, setup_count,
2962 ¶ms, total_parameter_count,
2963 &data, total_data_count, max_data_count);
2964 END_PROFILE_NESTED(NT_transact_set_security_desc);
2966 case NT_TRANSACT_NOTIFY_CHANGE:
2967 START_PROFILE_NESTED(NT_transact_notify_change);
2968 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
2970 &setup, setup_count,
2971 ¶ms, total_parameter_count,
2972 &data, total_data_count, max_data_count);
2973 END_PROFILE_NESTED(NT_transact_notify_change);
2975 case NT_TRANSACT_RENAME:
2976 START_PROFILE_NESTED(NT_transact_rename);
2977 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2979 &setup, setup_count,
2980 ¶ms, total_parameter_count,
2981 &data, total_data_count, max_data_count);
2982 END_PROFILE_NESTED(NT_transact_rename);
2985 case NT_TRANSACT_QUERY_SECURITY_DESC:
2986 START_PROFILE_NESTED(NT_transact_query_security_desc);
2987 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
2989 &setup, setup_count,
2990 ¶ms, total_parameter_count,
2991 &data, total_data_count, max_data_count);
2992 END_PROFILE_NESTED(NT_transact_query_security_desc);
2994 #ifdef HAVE_SYS_QUOTAS
2995 case NT_TRANSACT_GET_USER_QUOTA:
2996 START_PROFILE_NESTED(NT_transact_get_user_quota);
2997 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
2999 &setup, setup_count,
3000 ¶ms, total_parameter_count,
3001 &data, total_data_count, max_data_count);
3002 END_PROFILE_NESTED(NT_transact_get_user_quota);
3004 case NT_TRANSACT_SET_USER_QUOTA:
3005 START_PROFILE_NESTED(NT_transact_set_user_quota);
3006 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
3008 &setup, setup_count,
3009 ¶ms, total_parameter_count,
3010 &data, total_data_count, max_data_count);
3011 END_PROFILE_NESTED(NT_transact_set_user_quota);
3013 #endif /* HAVE_SYS_QUOTAS */
3015 /* Error in request */
3016 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
3020 END_PROFILE(SMBnttrans);
3021 srv_signing_trans_stop();
3022 return ERROR_DOS(ERRSRV,ERRerror);
3025 /* As we do not know how many data packets will need to be
3026 returned here the various call_nt_transact_xxxx calls
3027 must send their own. Thus a call_nt_transact_xxxx routine only
3028 returns a value other than -1 when it wants to send
3032 srv_signing_trans_stop();
3037 END_PROFILE(SMBnttrans);
3038 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
3039 calls have already sent it. If outsize != -1 then it is
3040 returning an error packet. */
3044 srv_signing_trans_stop();
3048 END_PROFILE(SMBnttrans);
3049 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);