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)
53 smb_panic("nttrans_realloc() called with NULL ptr\n");
56 tptr = SMB_REALLOC(*ptr, size);
61 memset(tptr,'\0',size);
68 /****************************************************************************
69 Send the required number of replies back.
70 We assume all fields other than the data fields are
71 set correctly for the type of call.
72 HACK ! Always assumes smb_setup field is zero.
73 ****************************************************************************/
75 static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, NTSTATUS nt_error, char *params,
76 int paramsize, char *pdata, int datasize)
78 int data_to_send = datasize;
79 int params_to_send = paramsize;
83 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
84 int alignment_offset = 3;
85 int data_alignment_offset = 0;
88 * Initially set the wcnt area to be 18 - this is true for all
92 set_message(outbuf,18,0,True);
94 if (NT_STATUS_V(nt_error)) {
99 * If there genuinely are no parameters or data to send just send
103 if(params_to_send == 0 && data_to_send == 0) {
105 if (!send_smb(smbd_server_fd(),outbuf)) {
106 exit_server("send_nt_replies: send_smb failed.");
112 * When sending params and data ensure that both are nicely aligned.
113 * Only do this alignment when there is also data to send - else
114 * can cause NT redirector problems.
117 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
118 data_alignment_offset = 4 - (params_to_send % 4);
122 * Space is bufsize minus Netbios over TCP header minus SMB header.
123 * The alignment_offset is to align the param bytes on a four byte
124 * boundary (2 bytes for data len, one byte pad).
125 * NT needs this to work correctly.
128 useable_space = bufsize - ((smb_buf(outbuf)+
129 alignment_offset+data_alignment_offset) -
133 * useable_space can never be more than max_send minus the
137 useable_space = MIN(useable_space,
138 max_send - (alignment_offset+data_alignment_offset));
141 while (params_to_send || data_to_send) {
144 * Calculate whether we will totally or partially fill this packet.
147 total_sent_thistime = params_to_send + data_to_send +
148 alignment_offset + data_alignment_offset;
151 * We can never send more than useable_space.
154 total_sent_thistime = MIN(total_sent_thistime, useable_space);
156 set_message(outbuf, 18, total_sent_thistime, True);
159 * Set total params and data to be sent.
162 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
163 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
166 * Calculate how many parameters and data we can fit into
167 * this packet. Parameters get precedence.
170 params_sent_thistime = MIN(params_to_send,useable_space);
171 data_sent_thistime = useable_space - params_sent_thistime;
172 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
174 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
176 if(params_sent_thistime == 0) {
177 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
178 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
181 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
182 * parameter bytes, however the first 4 bytes of outbuf are
183 * the Netbios over TCP header. Thus use smb_base() to subtract
184 * them from the calculation.
187 SIVAL(outbuf,smb_ntr_ParameterOffset,
188 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
190 * Absolute displacement of param bytes sent in this packet.
193 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
197 * Deal with the data portion.
200 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
202 if(data_sent_thistime == 0) {
203 SIVAL(outbuf,smb_ntr_DataOffset,0);
204 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
207 * The offset of the data bytes is the offset of the
208 * parameter bytes plus the number of parameters being sent this time.
211 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
212 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
213 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
217 * Copy the param bytes into the packet.
220 if(params_sent_thistime) {
221 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
225 * Copy in the data bytes
228 if(data_sent_thistime) {
229 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
230 data_alignment_offset,pd,data_sent_thistime);
233 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
234 params_sent_thistime, data_sent_thistime, useable_space));
235 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
236 params_to_send, data_to_send, paramsize, datasize));
238 /* Send the packet */
240 if (!send_smb(smbd_server_fd(),outbuf)) {
241 exit_server("send_nt_replies: send_smb failed.");
244 pp += params_sent_thistime;
245 pd += data_sent_thistime;
247 params_to_send -= params_sent_thistime;
248 data_to_send -= data_sent_thistime;
254 if(params_to_send < 0 || data_to_send < 0) {
255 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
256 params_to_send, data_to_send));
264 /****************************************************************************
265 Is it an NTFS stream name ?
266 ****************************************************************************/
268 BOOL is_ntfs_stream_name(const char *fname)
270 if (lp_posix_pathnames()) {
273 return (strchr_m(fname, ':') != NULL) ? True : False;
276 /****************************************************************************
278 ****************************************************************************/
280 static BOOL saved_case_sensitive;
281 static BOOL saved_case_preserve;
282 static BOOL saved_short_case_preserve;
284 /****************************************************************************
286 ****************************************************************************/
288 static void set_posix_case_semantics(connection_struct *conn, uint32 file_attributes)
290 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
294 saved_case_sensitive = conn->case_sensitive;
295 saved_case_preserve = conn->case_preserve;
296 saved_short_case_preserve = conn->short_case_preserve;
299 conn->case_sensitive = True;
300 conn->case_preserve = True;
301 conn->short_case_preserve = True;
304 /****************************************************************************
305 Restore case semantics.
306 ****************************************************************************/
308 static void restore_case_semantics(connection_struct *conn, uint32 file_attributes)
310 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
314 conn->case_sensitive = saved_case_sensitive;
315 conn->case_preserve = saved_case_preserve;
316 conn->short_case_preserve = saved_short_case_preserve;
319 /****************************************************************************
320 Reply to an NT create and X call on a pipe.
321 ****************************************************************************/
323 static int nt_open_pipe(char *fname, connection_struct *conn,
324 char *inbuf, char *outbuf, int *ppnum)
326 smb_np_struct *p = NULL;
327 uint16 vuid = SVAL(inbuf, smb_uid);
330 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
332 /* See if it is one we want to handle. */
334 if (lp_disable_spoolss() && strequal(fname, "\\spoolss")) {
335 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
338 for( i = 0; known_nt_pipes[i]; i++ ) {
339 if( strequal(fname,known_nt_pipes[i])) {
344 if ( known_nt_pipes[i] == NULL ) {
345 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
348 /* Strip \\ off the name. */
351 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
353 p = open_rpc_pipe_p(fname, conn, vuid);
355 return(ERROR_DOS(ERRSRV,ERRnofids));
362 /****************************************************************************
363 Reply to an NT create and X call for pipes.
364 ****************************************************************************/
366 static int do_ntcreate_pipe_open(connection_struct *conn,
367 char *inbuf,char *outbuf,int length,int bufsize)
374 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
376 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
381 * Deal with pipe return.
384 set_message(outbuf,34,0,True);
386 p = outbuf + smb_vwv2;
390 SIVAL(p,0,FILE_WAS_OPENED);
393 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
396 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
398 SSVAL(p,2, 0x5FF); /* ? */
400 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
402 return chain_reply(inbuf,outbuf,length,bufsize);
405 /****************************************************************************
406 Reply to an NT create and X call for a quota file.
407 ****************************************************************************/
409 int reply_ntcreate_and_X_quota(connection_struct *conn,
414 enum FAKE_FILE_TYPE fake_file_type,
419 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
420 files_struct *fsp = open_fake_file(conn, fake_file_type, fname, desired_access);
423 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
426 set_message(outbuf,34,0,True);
428 p = outbuf + smb_vwv2;
430 /* SCVAL(p,0,NO_OPLOCK_RETURN); */
432 SSVAL(p,0,fsp->fnum);
435 SIVAL(p,0,smb_action);
439 put_long_date(p,c_time);
441 put_long_date(p,sbuf.st_atime); /* access time */
443 put_long_date(p,sbuf.st_mtime); /* write time */
445 put_long_date(p,sbuf.st_mtime); /* change time */
447 SIVAL(p,0,fattr); /* File Attributes. */
449 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
451 SOFF_T(p,0,file_len);
453 if (flags & EXTENDED_RESPONSE_REQUIRED)
456 SCVAL(p,0,fsp->is_directory ? 1 : 0);
459 DEBUG(5,("reply_ntcreate_and_X_quota: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
461 result = chain_reply(inbuf,outbuf,length,bufsize);
465 /****************************************************************************
466 Reply to an NT create and X call.
467 ****************************************************************************/
469 int reply_ntcreate_and_X(connection_struct *conn,
470 char *inbuf,char *outbuf,int length,int bufsize)
474 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
475 uint32 access_mask = IVAL(inbuf,smb_ntcreate_DesiredAccess);
476 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
477 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
478 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
479 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
480 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
481 /* Breakout the oplock request bits so we can set the
482 reply bits separately. */
483 int oplock_request = 0;
485 SMB_OFF_T file_len = 0;
486 SMB_STRUCT_STAT sbuf;
488 BOOL bad_path = False;
489 files_struct *fsp=NULL;
492 BOOL extended_oplock_granted = False;
495 START_PROFILE(SMBntcreateX);
497 DEBUG(10,("reply_ntcreateX: flags = 0x%x, access_mask = 0x%x \
498 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
499 create_options = 0x%x root_dir_fid = 0x%x\n",
501 (unsigned int)access_mask,
502 (unsigned int)file_attributes,
503 (unsigned int)share_access,
504 (unsigned int)create_disposition,
505 (unsigned int)create_options,
506 (unsigned int)root_dir_fid ));
508 /* If it's an IPC, use the pipe handler. */
511 if (lp_nt_pipe_support()) {
512 END_PROFILE(SMBntcreateX);
513 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
515 END_PROFILE(SMBntcreateX);
516 return(ERROR_DOS(ERRDOS,ERRnoaccess));
520 if (create_options & FILE_OPEN_BY_FILE_ID) {
521 END_PROFILE(SMBntcreateX);
522 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
529 if(root_dir_fid != 0) {
531 * This filename is relative to a directory fid.
534 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
538 END_PROFILE(SMBntcreateX);
539 return(ERROR_DOS(ERRDOS,ERRbadfid));
542 if(!dir_fsp->is_directory) {
544 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
545 if (!NT_STATUS_IS_OK(status)) {
546 END_PROFILE(SMBntcreateX);
547 return ERROR_NT(status);
551 * Check to see if this is a mac fork of some kind.
554 if( is_ntfs_stream_name(fname)) {
555 END_PROFILE(SMBntcreateX);
556 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
560 we need to handle the case when we get a
561 relative open relative to a file and the
562 pathname is blank - this is a reopen!
563 (hint from demyn plantenberg)
566 END_PROFILE(SMBntcreateX);
567 return(ERROR_DOS(ERRDOS,ERRbadfid));
571 * Copy in the base directory name.
574 pstrcpy( fname, dir_fsp->fsp_name );
575 dir_name_len = strlen(fname);
578 * Ensure it ends in a '\'.
581 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
586 srvstr_get_path(inbuf, rel_fname, smb_buf(inbuf), sizeof(rel_fname), 0, STR_TERMINATE, &status);
587 if (!NT_STATUS_IS_OK(status)) {
588 END_PROFILE(SMBntcreateX);
589 return ERROR_NT(status);
591 pstrcat(fname, rel_fname);
593 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
594 if (!NT_STATUS_IS_OK(status)) {
595 END_PROFILE(SMBntcreateX);
596 return ERROR_NT(status);
600 * Check to see if this is a mac fork of some kind.
603 if( is_ntfs_stream_name(fname)) {
604 enum FAKE_FILE_TYPE fake_file_type = is_fake_file(fname);
605 if (fake_file_type!=FAKE_FILE_TYPE_NONE) {
607 * Here we go! support for changing the disk quotas --metze
609 * We need to fake up to open this MAGIC QUOTA file
610 * and return a valid FID.
612 * w2k close this file directly after openening
613 * xp also tries a QUERY_FILE_INFO on the file and then close it
615 result = reply_ntcreate_and_X_quota(conn, inbuf, outbuf, length, bufsize,
616 fake_file_type, fname);
617 END_PROFILE(SMBntcreateX);
620 END_PROFILE(SMBntcreateX);
621 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
627 * Now contruct the smb_open_mode value from the filename,
628 * desired access and the share access.
630 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
632 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
633 if (oplock_request) {
634 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
638 * Ordinary file or directory.
642 * Check if POSIX semantics are wanted.
645 set_posix_case_semantics(conn, file_attributes);
647 unix_convert(fname,conn,0,&bad_path,&sbuf);
650 restore_case_semantics(conn, file_attributes);
651 END_PROFILE(SMBntcreateX);
652 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
654 /* All file access must go through check_name() */
655 if (!check_name(fname,conn)) {
656 restore_case_semantics(conn, file_attributes);
657 END_PROFILE(SMBntcreateX);
658 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
662 /* This is the correct thing to do (check every time) but can_delete is
663 expensive (it may have to read the parent directory permissions). So
664 for now we're not doing it unless we have a strong hint the client
665 is really going to delete this file. */
666 if (desired_access & DELETE_ACCESS) {
668 /* Setting FILE_SHARE_DELETE is the hint. */
669 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE)
670 && (access_mask & DELETE_ACCESS)) {
672 status = can_delete(conn, fname, file_attributes, bad_path, True);
673 /* We're only going to fail here if it's access denied, as that's the
674 only error we care about for "can we delete this ?" questions. */
675 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
676 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
677 restore_case_semantics(conn, file_attributes);
678 END_PROFILE(SMBntcreateX);
679 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
684 * If it's a request for a directory open, deal with it separately.
687 if(create_options & FILE_DIRECTORY_FILE) {
690 /* Can't open a temp directory. IFS kit test. */
691 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
692 END_PROFILE(SMBntcreateX);
693 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
696 fsp = open_directory(conn, fname, &sbuf,
703 restore_case_semantics(conn, file_attributes);
706 END_PROFILE(SMBntcreateX);
707 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
711 * Ordinary file case.
714 /* NB. We have a potential bug here. If we
715 * cause an oplock break to ourselves, then we
716 * could end up processing filename related
717 * SMB requests whilst we await the oplock
718 * break response. As we may have changed the
719 * filename case semantics to be POSIX-like,
720 * this could mean a filename request could
721 * fail when it should succeed. This is a rare
722 * condition, but eventually we must arrange
723 * to restore the correct case semantics
724 * before issuing an oplock break request to
725 * our client. JRA. */
727 fsp = open_file_ntcreate(conn,fname,&sbuf,
736 /* We cheat here. There are two cases we
737 * care about. One is a directory rename,
738 * where the NT client will attempt to
739 * open the source directory for
740 * DELETE access. Note that when the
741 * NT client does this it does *not*
742 * set the directory bit in the
743 * request packet. This is translated
744 * into a read/write open
745 * request. POSIX states that any open
746 * for write request on a directory
747 * will generate an EISDIR error, so
748 * we can catch this here and open a
749 * pseudo handle that is flagged as a
750 * directory. The second is an open
751 * for a permissions read only, which
752 * we handle in the open_file_stat case. JRA.
755 if(errno == EISDIR) {
758 * Fail the open if it was explicitly a non-directory file.
761 if (create_options & FILE_NON_DIRECTORY_FILE) {
762 restore_case_semantics(conn, file_attributes);
763 END_PROFILE(SMBntcreateX);
764 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
768 fsp = open_directory(conn, fname, &sbuf,
776 restore_case_semantics(conn, file_attributes);
777 END_PROFILE(SMBntcreateX);
778 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
782 restore_case_semantics(conn, file_attributes);
783 END_PROFILE(SMBntcreateX);
784 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
785 /* We have re-scheduled this call. */
788 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
793 restore_case_semantics(conn, file_attributes);
795 file_len = sbuf.st_size;
796 fattr = dos_mode(conn,fname,&sbuf);
798 fattr = FILE_ATTRIBUTE_NORMAL;
800 if (!fsp->is_directory && (fattr & aDIR)) {
801 close_file(fsp,False);
802 END_PROFILE(SMBntcreateX);
803 return ERROR_DOS(ERRDOS,ERRnoaccess);
806 /* Save the requested allocation size. */
807 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
808 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
809 #ifdef LARGE_SMB_OFF_T
810 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
812 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
813 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
814 if (fsp->is_directory) {
815 close_file(fsp,False);
816 END_PROFILE(SMBntcreateX);
817 /* Can't set allocation size on a directory. */
818 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
820 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
821 close_file(fsp,False);
822 END_PROFILE(SMBntcreateX);
823 return ERROR_NT(NT_STATUS_DISK_FULL);
826 fsp->initial_allocation_size = smb_roundup(fsp->conn,(SMB_BIG_UINT)file_len);
831 * If the caller set the extended oplock request bit
832 * and we granted one (by whatever means) - set the
833 * correct bit for extended oplock reply.
836 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
837 extended_oplock_granted = True;
840 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
841 extended_oplock_granted = True;
845 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
846 set_message(outbuf,42,0,True);
848 set_message(outbuf,34,0,True);
851 p = outbuf + smb_vwv2;
854 * Currently as we don't support level II oplocks we just report
855 * exclusive & batch here.
858 if (extended_oplock_granted) {
859 if (flags & REQUEST_BATCH_OPLOCK) {
860 SCVAL(p,0, BATCH_OPLOCK_RETURN);
862 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
864 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
865 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
867 SCVAL(p,0,NO_OPLOCK_RETURN);
871 SSVAL(p,0,fsp->fnum);
873 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
874 SIVAL(p,0,FILE_WAS_SUPERSEDED);
881 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
883 if (lp_dos_filetime_resolution(SNUM(conn))) {
890 put_long_date(p,c_time);
892 put_long_date(p,sbuf.st_atime); /* access time */
894 put_long_date(p,sbuf.st_mtime); /* write time */
896 put_long_date(p,sbuf.st_mtime); /* change time */
898 SIVAL(p,0,fattr); /* File Attributes. */
900 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
902 SOFF_T(p,0,file_len);
904 if (flags & EXTENDED_RESPONSE_REQUIRED) {
908 SCVAL(p,0,fsp->is_directory ? 1 : 0);
910 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
912 result = chain_reply(inbuf,outbuf,length,bufsize);
913 END_PROFILE(SMBntcreateX);
917 /****************************************************************************
918 Reply to a NT_TRANSACT_CREATE call to open a pipe.
919 ****************************************************************************/
921 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
922 char **ppsetup, uint32 setup_count,
923 char **ppparams, uint32 parameter_count,
924 char **ppdata, uint32 data_count)
927 char *params = *ppparams;
934 * Ensure minimum number of parameters sent.
937 if(parameter_count < 54) {
938 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
939 return ERROR_DOS(ERRDOS,ERRnoaccess);
942 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
943 if (!NT_STATUS_IS_OK(status)) {
944 return ERROR_NT(status);
947 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
951 /* Realloc the size of parameters and data we will return */
952 params = nttrans_realloc(ppparams, 69);
954 return ERROR_DOS(ERRDOS,ERRnomem);
958 SCVAL(p,0,NO_OPLOCK_RETURN);
963 SIVAL(p,0,FILE_WAS_OPENED);
967 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
970 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
972 SSVAL(p,2, 0x5FF); /* ? */
974 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
976 /* Send the required number of replies */
977 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
982 /****************************************************************************
983 Internal fn to set security descriptors.
984 ****************************************************************************/
986 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
989 SEC_DESC *psd = NULL;
993 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
998 * Init the parse struct we will unmarshall from.
1001 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
1002 DEBUG(0,("set_sd: talloc_init failed.\n"));
1003 return NT_STATUS_NO_MEMORY;
1006 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1009 * Setup the prs_struct to point at the memory we just
1013 prs_give_memory( &pd, data, sd_len, False);
1016 * Finally, unmarshall from the data buffer.
1019 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1020 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1022 * Return access denied for want of a better error message..
1024 talloc_destroy(mem_ctx);
1025 return NT_STATUS_NO_MEMORY;
1028 if (psd->off_owner_sid==0) {
1029 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1031 if (psd->off_grp_sid==0) {
1032 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1034 if (psd->off_sacl==0) {
1035 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1037 if (psd->off_dacl==0) {
1038 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1041 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fh->fd, security_info_sent, psd);
1044 talloc_destroy(mem_ctx);
1045 return NT_STATUS_ACCESS_DENIED;
1048 talloc_destroy(mem_ctx);
1050 return NT_STATUS_OK;
1053 /****************************************************************************
1054 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1055 ****************************************************************************/
1057 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
1059 struct ea_list *ea_list_head = NULL;
1062 if (data_size < 4) {
1066 while (offset + 4 <= data_size) {
1067 size_t next_offset = IVAL(pdata,offset);
1068 struct ea_list *tmp;
1069 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
1071 DLIST_ADD_END(ea_list_head, eal, tmp);
1072 if (next_offset == 0) {
1075 offset += next_offset;
1078 return ea_list_head;
1081 /****************************************************************************
1082 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1083 ****************************************************************************/
1085 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1086 char **ppsetup, uint32 setup_count,
1087 char **ppparams, uint32 parameter_count,
1088 char **ppdata, uint32 data_count, uint32 max_data_count)
1091 char *params = *ppparams;
1092 char *data = *ppdata;
1093 /* Breakout the oplock request bits so we can set the reply bits separately. */
1094 int oplock_request = 0;
1096 SMB_OFF_T file_len = 0;
1097 SMB_STRUCT_STAT sbuf;
1099 BOOL bad_path = False;
1100 files_struct *fsp = NULL;
1102 BOOL extended_oplock_granted = False;
1105 uint32 file_attributes;
1106 uint32 share_access;
1107 uint32 create_disposition;
1108 uint32 create_options;
1111 uint16 root_dir_fid;
1113 struct ea_list *ea_list = NULL;
1114 TALLOC_CTX *ctx = NULL;
1118 DEBUG(5,("call_nt_transact_create\n"));
1121 * If it's an IPC, use the pipe handler.
1125 if (lp_nt_pipe_support()) {
1126 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1128 ppsetup, setup_count,
1129 ppparams, parameter_count,
1130 ppdata, data_count);
1132 return ERROR_DOS(ERRDOS,ERRnoaccess);
1137 * Ensure minimum number of parameters sent.
1140 if(parameter_count < 54) {
1141 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1142 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1145 flags = IVAL(params,0);
1146 access_mask = IVAL(params,8);
1147 file_attributes = IVAL(params,20);
1148 share_access = IVAL(params,24);
1149 create_disposition = IVAL(params,28);
1150 create_options = IVAL(params,32);
1151 sd_len = IVAL(params,36);
1152 ea_len = IVAL(params,40);
1153 root_dir_fid = (uint16)IVAL(params,4);
1155 /* Ensure the data_len is correct for the sd and ea values given. */
1156 if ((ea_len + sd_len > data_count) ||
1157 (ea_len > data_count) || (sd_len > data_count) ||
1158 (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
1159 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1160 (unsigned int)ea_len, (unsigned int)sd_len, (unsigned int)data_count ));
1161 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1165 if (!lp_ea_support(SNUM(conn))) {
1166 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1167 (unsigned int)ea_len ));
1168 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
1172 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1173 (unsigned int)ea_len ));
1174 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1178 if (create_options & FILE_OPEN_BY_FILE_ID) {
1179 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1183 * Get the file name.
1186 if(root_dir_fid != 0) {
1188 * This filename is relative to a directory fid.
1190 files_struct *dir_fsp = file_fsp(params,4);
1191 size_t dir_name_len;
1194 return ERROR_DOS(ERRDOS,ERRbadfid);
1197 if(!dir_fsp->is_directory) {
1198 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1199 if (!NT_STATUS_IS_OK(status)) {
1200 return ERROR_NT(status);
1204 * Check to see if this is a mac fork of some kind.
1207 if( is_ntfs_stream_name(fname)) {
1208 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1211 return ERROR_DOS(ERRDOS,ERRbadfid);
1215 * Copy in the base directory name.
1218 pstrcpy( fname, dir_fsp->fsp_name );
1219 dir_name_len = strlen(fname);
1222 * Ensure it ends in a '\'.
1225 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1226 pstrcat(fname, "/");
1232 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status);
1233 if (!NT_STATUS_IS_OK(status)) {
1234 return ERROR_NT(status);
1236 pstrcat(fname, tmpname);
1239 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1240 if (!NT_STATUS_IS_OK(status)) {
1241 return ERROR_NT(status);
1245 * Check to see if this is a mac fork of some kind.
1248 if( is_ntfs_stream_name(fname)) {
1249 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1253 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1254 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1257 * Check if POSIX semantics are wanted.
1260 set_posix_case_semantics(conn, file_attributes);
1262 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1264 unix_convert(fname,conn,0,&bad_path,&sbuf);
1266 restore_case_semantics(conn, file_attributes);
1267 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1269 /* All file access must go through check_name() */
1270 if (!check_name(fname,conn)) {
1271 restore_case_semantics(conn, file_attributes);
1272 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRbadpath);
1276 /* This is the correct thing to do (check every time) but can_delete is
1277 expensive (it may have to read the parent directory permissions). So
1278 for now we're not doing it unless we have a strong hint the client
1279 is really going to delete this file. */
1280 if (desired_access & DELETE_ACCESS) {
1282 /* Setting FILE_SHARE_DELETE is the hint. */
1283 if (lp_acl_check_permissions(SNUM(conn)) && (share_access & FILE_SHARE_DELETE) && (access_mask & DELETE_ACCESS)) {
1285 status = can_delete(conn, fname, file_attributes, bad_path, True);
1286 /* We're only going to fail here if it's access denied, as that's the
1287 only error we care about for "can we delete this ?" questions. */
1288 if (!NT_STATUS_IS_OK(status) && (NT_STATUS_EQUAL(status,NT_STATUS_ACCESS_DENIED) ||
1289 NT_STATUS_EQUAL(status,NT_STATUS_CANNOT_DELETE))) {
1290 restore_case_semantics(conn, file_attributes);
1291 return ERROR_NT(status);
1296 ctx = talloc_init("NTTRANS_CREATE_EA");
1298 talloc_destroy(ctx);
1299 restore_case_semantics(conn, file_attributes);
1300 return ERROR_NT(NT_STATUS_NO_MEMORY);
1303 pdata = data + sd_len;
1305 /* We have already checked that ea_len <= data_count here. */
1306 ea_list = read_nttrans_ea_list(ctx, pdata, ea_len);
1308 talloc_destroy(ctx);
1309 restore_case_semantics(conn, file_attributes);
1310 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1315 * If it's a request for a directory open, deal with it separately.
1318 if(create_options & FILE_DIRECTORY_FILE) {
1320 /* Can't open a temp directory. IFS kit test. */
1321 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1322 talloc_destroy(ctx);
1323 restore_case_semantics(conn, file_attributes);
1324 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1330 * We will get a create directory here if the Win32
1331 * app specified a security descriptor in the
1332 * CreateDirectory() call.
1335 fsp = open_directory(conn, fname, &sbuf,
1342 talloc_destroy(ctx);
1343 restore_case_semantics(conn, file_attributes);
1344 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1350 * Ordinary file case.
1353 fsp = open_file_ntcreate(conn,fname,&sbuf,
1363 if(errno == EISDIR) {
1366 * Fail the open if it was explicitly a non-directory file.
1369 if (create_options & FILE_NON_DIRECTORY_FILE) {
1370 restore_case_semantics(conn, file_attributes);
1371 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1375 fsp = open_directory(conn, fname, &sbuf,
1382 talloc_destroy(ctx);
1383 restore_case_semantics(conn, file_attributes);
1384 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1387 talloc_destroy(ctx);
1388 restore_case_semantics(conn, file_attributes);
1389 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1390 /* We have re-scheduled this call. */
1393 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1399 * According to the MS documentation, the only time the security
1400 * descriptor is applied to the opened file is iff we *created* the
1401 * file; an existing file stays the same.
1403 * Also, it seems (from observation) that you can open the file with
1404 * any access mask but you can still write the sd. We need to override
1405 * the granted access before we call set_sd
1406 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1409 if (lp_nt_acl_support(SNUM(conn)) && sd_len && info == FILE_WAS_CREATED) {
1410 uint32 saved_access_mask = fsp->access_mask;
1412 /* We have already checked that sd_len <= data_count here. */
1414 fsp->access_mask = FILE_GENERIC_ALL;
1416 status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION);
1417 if (!NT_STATUS_IS_OK(status)) {
1418 talloc_destroy(ctx);
1419 close_file(fsp,False);
1420 restore_case_semantics(conn, file_attributes);
1421 return ERROR_NT(status);
1423 fsp->access_mask = saved_access_mask;
1426 if (ea_len && (info == FILE_WAS_CREATED)) {
1427 status = set_ea(conn, fsp, fname, ea_list);
1428 talloc_destroy(ctx);
1429 if (!NT_STATUS_IS_OK(status)) {
1430 close_file(fsp,False);
1431 restore_case_semantics(conn, file_attributes);
1432 return ERROR_NT(status);
1436 restore_case_semantics(conn, file_attributes);
1438 file_len = sbuf.st_size;
1439 fattr = dos_mode(conn,fname,&sbuf);
1441 fattr = FILE_ATTRIBUTE_NORMAL;
1443 if (!fsp->is_directory && (fattr & aDIR)) {
1444 close_file(fsp,False);
1445 return ERROR_DOS(ERRDOS,ERRnoaccess);
1448 /* Save the requested allocation size. */
1449 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
1450 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1451 #ifdef LARGE_SMB_OFF_T
1452 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1454 if (allocation_size && (allocation_size > file_len)) {
1455 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
1456 if (fsp->is_directory) {
1457 close_file(fsp,False);
1458 /* Can't set allocation size on a directory. */
1459 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1461 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1462 close_file(fsp,False);
1463 return ERROR_NT(NT_STATUS_DISK_FULL);
1466 fsp->initial_allocation_size = smb_roundup(fsp->conn, (SMB_BIG_UINT)file_len);
1471 * If the caller set the extended oplock request bit
1472 * and we granted one (by whatever means) - set the
1473 * correct bit for extended oplock reply.
1476 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
1477 extended_oplock_granted = True;
1480 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
1481 extended_oplock_granted = True;
1484 /* Realloc the size of parameters and data we will return */
1485 params = nttrans_realloc(ppparams, 69);
1486 if(params == NULL) {
1487 return ERROR_DOS(ERRDOS,ERRnomem);
1491 if (extended_oplock_granted) {
1492 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1493 } else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
1494 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1496 SCVAL(p,0,NO_OPLOCK_RETURN);
1500 SSVAL(p,0,fsp->fnum);
1502 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
1503 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1510 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1512 if (lp_dos_filetime_resolution(SNUM(conn))) {
1514 sbuf.st_atime &= ~1;
1515 sbuf.st_mtime &= ~1;
1516 sbuf.st_mtime &= ~1;
1519 put_long_date(p,c_time);
1521 put_long_date(p,sbuf.st_atime); /* access time */
1523 put_long_date(p,sbuf.st_mtime); /* write time */
1525 put_long_date(p,sbuf.st_mtime); /* change time */
1527 SIVAL(p,0,fattr); /* File Attributes. */
1529 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1531 SOFF_T(p,0,file_len);
1533 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1537 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1539 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1541 /* Send the required number of replies */
1542 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1547 /****************************************************************************
1548 Reply to a NT CANCEL request.
1549 ****************************************************************************/
1551 int reply_ntcancel(connection_struct *conn,
1552 char *inbuf,char *outbuf,int length,int bufsize)
1555 * Go through and cancel any pending change notifies.
1558 int mid = SVAL(inbuf,smb_mid);
1559 START_PROFILE(SMBntcancel);
1560 remove_pending_change_notify_requests_by_mid(mid);
1561 remove_pending_lock_requests_by_mid(mid);
1562 srv_cancel_sign_response(mid);
1564 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1566 END_PROFILE(SMBntcancel);
1570 /****************************************************************************
1572 ****************************************************************************/
1574 static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *newname, uint32 attrs)
1576 BOOL bad_path_oldname = False;
1577 BOOL bad_path_newname = False;
1578 SMB_STRUCT_STAT sbuf1, sbuf2;
1579 pstring last_component_oldname;
1580 pstring last_component_newname;
1581 files_struct *fsp1,*fsp2;
1586 NTSTATUS status = NT_STATUS_OK;
1592 if (ms_has_wild(newname) || ms_has_wild(oldname)) {
1593 return NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1596 if (!CAN_WRITE(conn))
1597 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1599 unix_convert(oldname,conn,last_component_oldname,&bad_path_oldname,&sbuf1);
1600 if (bad_path_oldname) {
1601 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1604 /* Quick check for "." and ".." */
1605 if (last_component_oldname[0] == '.') {
1606 if (!last_component_oldname[1] || (last_component_oldname[1] == '.' && !last_component_oldname[2])) {
1607 return NT_STATUS_OBJECT_NAME_INVALID;
1611 /* Source must already exist. */
1612 if (!VALID_STAT(sbuf1)) {
1613 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1615 if (!check_name(oldname,conn)) {
1616 return NT_STATUS_ACCESS_DENIED;
1619 /* Ensure attributes match. */
1620 fattr = dos_mode(conn,oldname,&sbuf1);
1621 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1622 return NT_STATUS_NO_SUCH_FILE;
1625 unix_convert(newname,conn,last_component_newname,&bad_path_newname,&sbuf2);
1626 if (bad_path_newname) {
1627 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
1630 /* Quick check for "." and ".." */
1631 if (last_component_newname[0] == '.') {
1632 if (!last_component_newname[1] || (last_component_newname[1] == '.' && !last_component_newname[2])) {
1633 return NT_STATUS_OBJECT_NAME_INVALID;
1637 /* Disallow if newname already exists. */
1638 if (VALID_STAT(sbuf2)) {
1639 return NT_STATUS_OBJECT_NAME_COLLISION;
1642 if (!check_name(newname,conn)) {
1643 return NT_STATUS_ACCESS_DENIED;
1646 /* No links from a directory. */
1647 if (S_ISDIR(sbuf1.st_mode)) {
1648 return NT_STATUS_FILE_IS_A_DIRECTORY;
1651 /* Ensure this is within the share. */
1652 if (!reduce_name(conn, oldname) != 0) {
1653 return NT_STATUS_ACCESS_DENIED;
1656 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname, newname));
1658 fsp1 = open_file_ntcreate(conn,oldname,&sbuf1,
1659 FILE_READ_DATA, /* Read-only. */
1660 0, /* No sharing. */
1662 0, /* No create options. */
1663 FILE_ATTRIBUTE_NORMAL,
1668 status = get_saved_ntstatus();
1669 if (NT_STATUS_IS_OK(status)) {
1670 status = NT_STATUS_ACCESS_DENIED;
1672 set_saved_ntstatus(NT_STATUS_OK);
1676 fsp2 = open_file_ntcreate(conn,newname,&sbuf2,
1677 FILE_WRITE_DATA, /* Read-only. */
1678 0, /* No sharing. */
1680 0, /* No create options. */
1686 status = get_saved_ntstatus();
1687 if (NT_STATUS_IS_OK(status)) {
1688 status = NT_STATUS_ACCESS_DENIED;
1690 set_saved_ntstatus(NT_STATUS_OK);
1691 close_file(fsp1,False);
1695 if (sbuf1.st_size) {
1696 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1700 * As we are opening fsp1 read-only we only expect
1701 * an error on close on fsp2 if we are out of space.
1702 * Thus we don't look at the error return from the
1705 close_file(fsp1,False);
1707 /* Ensure the modtime is set correctly on the destination file. */
1708 fsp_set_pending_modtime(fsp2, sbuf1.st_mtime);
1710 close_ret = close_file(fsp2,False);
1712 /* Grrr. We have to do this as open_file_shared1 adds aARCH when it
1713 creates the file. This isn't the correct thing to do in the copy case. JRA */
1714 file_set_dosmode(conn, newname, fattr, &sbuf2, True);
1716 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1717 return NT_STATUS_DISK_FULL;
1720 if (close_ret != 0) {
1721 status = map_nt_error_from_unix(close_ret);
1722 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1723 nt_errstr(status), oldname, newname));
1728 /****************************************************************************
1729 Reply to a NT rename request.
1730 ****************************************************************************/
1732 int reply_ntrename(connection_struct *conn,
1733 char *inbuf,char *outbuf,int length,int bufsize)
1740 BOOL path_contains_wcard = False;
1741 uint32 attrs = SVAL(inbuf,smb_vwv0);
1742 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1744 START_PROFILE(SMBntrename);
1746 p = smb_buf(inbuf) + 1;
1747 p += srvstr_get_path_wcard(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, &path_contains_wcard);
1748 if (!NT_STATUS_IS_OK(status)) {
1749 END_PROFILE(SMBntrename);
1750 return ERROR_NT(status);
1753 if( is_ntfs_stream_name(oldname)) {
1754 /* Can't rename a stream. */
1755 END_PROFILE(SMBntrename);
1756 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1759 if (ms_has_wild(oldname)) {
1760 END_PROFILE(SMBntrename);
1761 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1765 p += srvstr_get_path(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status);
1766 if (!NT_STATUS_IS_OK(status)) {
1767 END_PROFILE(SMBntrename);
1768 return ERROR_NT(status);
1771 RESOLVE_DFSPATH(oldname, conn, inbuf, outbuf);
1772 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1774 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1776 switch(rename_type) {
1777 case RENAME_FLAG_RENAME:
1778 status = rename_internals(conn, oldname, newname, attrs, False, path_contains_wcard);
1780 case RENAME_FLAG_HARD_LINK:
1781 status = hardlink_internals(conn, oldname, newname);
1783 case RENAME_FLAG_COPY:
1784 if (path_contains_wcard) {
1786 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1788 status = copy_internals(conn, oldname, newname, attrs);
1791 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1792 status = NT_STATUS_INVALID_PARAMETER;
1795 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1799 if (!NT_STATUS_IS_OK(status)) {
1800 END_PROFILE(SMBntrename);
1801 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1802 /* We have re-scheduled this call. */
1805 return ERROR_NT(status);
1809 * Win2k needs a changenotify request response before it will
1810 * update after a rename..
1812 process_pending_change_notify_queue((time_t)0);
1813 outsize = set_message(outbuf,0,0,True);
1815 END_PROFILE(SMBntrename);
1819 /****************************************************************************
1820 Reply to an unsolicited SMBNTtranss - just ignore it!
1821 ****************************************************************************/
1823 int reply_nttranss(connection_struct *conn,
1824 char *inbuf,char *outbuf,int length,int bufsize)
1826 START_PROFILE(SMBnttranss);
1827 DEBUG(4,("Ignoring nttranss of length %d\n",length));
1828 END_PROFILE(SMBnttranss);
1832 /****************************************************************************
1833 Reply to a notify change - queue the request and
1834 don't allow a directory to be opened.
1835 ****************************************************************************/
1837 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1838 char **ppsetup, uint32 setup_count,
1839 char **ppparams, uint32 parameter_count,
1840 char **ppdata, uint32 data_count, uint32 max_data_count)
1842 char *setup = *ppsetup;
1846 if(setup_count < 6) {
1847 return ERROR_DOS(ERRDOS,ERRbadfunc);
1850 fsp = file_fsp(setup,4);
1851 flags = IVAL(setup, 0);
1853 DEBUG(3,("call_nt_transact_notify_change\n"));
1856 return ERROR_DOS(ERRDOS,ERRbadfid);
1859 if((!fsp->is_directory) || (conn != fsp->conn)) {
1860 return ERROR_DOS(ERRDOS,ERRbadfid);
1863 if (!change_notify_set(inbuf, fsp, conn, flags)) {
1864 return(UNIXERROR(ERRDOS,ERRbadfid));
1867 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1868 name = %s\n", fsp->fsp_name ));
1873 /****************************************************************************
1874 Reply to an NT transact rename command.
1875 ****************************************************************************/
1877 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1878 char **ppsetup, uint32 setup_count,
1879 char **ppparams, uint32 parameter_count,
1880 char **ppdata, uint32 data_count, uint32 max_data_count)
1882 char *params = *ppparams;
1884 files_struct *fsp = NULL;
1885 BOOL replace_if_exists = False;
1886 BOOL path_contains_wcard = False;
1889 if(parameter_count < 4) {
1890 return ERROR_DOS(ERRDOS,ERRbadfunc);
1893 fsp = file_fsp(params, 0);
1894 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1895 CHECK_FSP(fsp, conn);
1896 srvstr_get_path_wcard(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE, &status, &path_contains_wcard);
1897 if (!NT_STATUS_IS_OK(status)) {
1898 return ERROR_NT(status);
1901 status = rename_internals(conn, fsp->fsp_name,
1902 new_name, 0, replace_if_exists, path_contains_wcard);
1903 if (!NT_STATUS_IS_OK(status))
1904 return ERROR_NT(status);
1907 * Rename was successful.
1909 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1911 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1912 fsp->fsp_name, new_name));
1915 * Win2k needs a changenotify request response before it will
1916 * update after a rename..
1919 process_pending_change_notify_queue((time_t)0);
1924 /******************************************************************************
1925 Fake up a completely empty SD.
1926 *******************************************************************************/
1928 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1932 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1934 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1941 /****************************************************************************
1942 Reply to query a security descriptor.
1943 ****************************************************************************/
1945 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1946 char **ppsetup, uint32 setup_count,
1947 char **ppparams, uint32 parameter_count,
1948 char **ppdata, uint32 data_count, uint32 max_data_count)
1950 char *params = *ppparams;
1951 char *data = *ppdata;
1953 SEC_DESC *psd = NULL;
1955 uint32 security_info_wanted;
1956 TALLOC_CTX *mem_ctx;
1957 files_struct *fsp = NULL;
1959 if(parameter_count < 8) {
1960 return ERROR_DOS(ERRDOS,ERRbadfunc);
1963 fsp = file_fsp(params,0);
1965 return ERROR_DOS(ERRDOS,ERRbadfid);
1968 security_info_wanted = IVAL(params,4);
1970 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1971 (unsigned int)security_info_wanted ));
1973 params = nttrans_realloc(ppparams, 4);
1974 if(params == NULL) {
1975 return ERROR_DOS(ERRDOS,ERRnomem);
1978 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1979 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1980 return ERROR_DOS(ERRDOS,ERRnomem);
1984 * Get the permissions to return.
1987 if (!lp_nt_acl_support(SNUM(conn))) {
1988 sd_size = get_null_nt_acl(mem_ctx, &psd);
1990 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fh->fd, security_info_wanted, &psd);
1994 talloc_destroy(mem_ctx);
1995 return(UNIXERROR(ERRDOS,ERRnoaccess));
1998 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
2000 SIVAL(params,0,(uint32)sd_size);
2002 if(max_data_count < sd_size) {
2004 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
2005 params, 4, *ppdata, 0);
2006 talloc_destroy(mem_ctx);
2011 * Allocate the data we will point this at.
2014 data = nttrans_realloc(ppdata, sd_size);
2016 talloc_destroy(mem_ctx);
2017 return ERROR_DOS(ERRDOS,ERRnomem);
2021 * Init the parse struct we will marshall into.
2024 prs_init(&pd, 0, mem_ctx, MARSHALL);
2027 * Setup the prs_struct to point at the memory we just
2031 prs_give_memory( &pd, data, (uint32)sd_size, False);
2034 * Finally, linearize into the outgoing buffer.
2037 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2038 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2039 security descriptor.\n"));
2041 * Return access denied for want of a better error message..
2043 talloc_destroy(mem_ctx);
2044 return(UNIXERROR(ERRDOS,ERRnoaccess));
2048 * Now we can delete the security descriptor.
2051 talloc_destroy(mem_ctx);
2053 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 4, data, (int)sd_size);
2057 /****************************************************************************
2058 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2059 ****************************************************************************/
2061 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2062 char **ppsetup, uint32 setup_count,
2063 char **ppparams, uint32 parameter_count,
2064 char **ppdata, uint32 data_count, uint32 max_data_count)
2066 char *params= *ppparams;
2067 char *data = *ppdata;
2068 files_struct *fsp = NULL;
2069 uint32 security_info_sent = 0;
2072 if(parameter_count < 8) {
2073 return ERROR_DOS(ERRDOS,ERRbadfunc);
2076 if((fsp = file_fsp(params,0)) == NULL) {
2077 return ERROR_DOS(ERRDOS,ERRbadfid);
2080 if(!lp_nt_acl_support(SNUM(conn))) {
2084 security_info_sent = IVAL(params,4);
2086 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
2087 (unsigned int)security_info_sent ));
2089 if (data_count == 0) {
2090 return ERROR_DOS(ERRDOS, ERRnoaccess);
2093 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent))) {
2094 return ERROR_NT(nt_status);
2099 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2103 /****************************************************************************
2105 ****************************************************************************/
2107 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2108 char **ppsetup, uint32 setup_count,
2109 char **ppparams, uint32 parameter_count,
2110 char **ppdata, uint32 data_count, uint32 max_data_count)
2117 static BOOL logged_message;
2118 char *pdata = *ppdata;
2120 if (setup_count != 8) {
2121 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2122 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2125 function = IVAL(*ppsetup, 0);
2126 fidnum = SVAL(*ppsetup, 4);
2127 isFSctl = CVAL(*ppsetup, 6);
2128 compfilter = CVAL(*ppsetup, 7);
2130 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2131 function, fidnum, isFSctl, compfilter));
2133 fsp=file_fsp(*ppsetup, 4);
2134 /* this check is done in each implemented function case for now
2135 because I don't want to break anything... --metze
2136 FSP_BELONGS_CONN(fsp,conn);*/
2139 case FSCTL_SET_SPARSE:
2140 /* pretend this succeeded - tho strictly we should
2141 mark the file sparse (if the local fs supports it)
2142 so we can know if we need to pre-allocate or not */
2144 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2145 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2148 case FSCTL_0x000900C0:
2149 /* pretend this succeeded - don't know what this really is
2150 but works ok like this --metze
2153 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2154 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2157 case FSCTL_GET_REPARSE_POINT:
2158 /* pretend this fail - my winXP does it like this
2162 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2163 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2166 case FSCTL_SET_REPARSE_POINT:
2167 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2171 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2172 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
2175 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
2178 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2179 * and return their volume names. If max_data_count is 16, then it is just
2180 * asking for the number of volumes and length of the combined names.
2182 * pdata is the data allocated by our caller, but that uses
2183 * total_data_count (which is 0 in our case) rather than max_data_count.
2184 * Allocate the correct amount and return the pointer to let
2185 * it be deallocated when we return.
2187 SHADOW_COPY_DATA *shadow_data = NULL;
2188 TALLOC_CTX *shadow_mem_ctx = NULL;
2189 BOOL labels = False;
2190 uint32 labels_data_count = 0;
2194 FSP_BELONGS_CONN(fsp,conn);
2196 if (max_data_count < 16) {
2197 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2199 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2202 if (max_data_count > 16) {
2206 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2207 if (shadow_mem_ctx == NULL) {
2208 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2209 return ERROR_NT(NT_STATUS_NO_MEMORY);
2212 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2213 if (shadow_data == NULL) {
2214 DEBUG(0,("talloc_zero() failed!\n"));
2215 talloc_destroy(shadow_mem_ctx);
2216 return ERROR_NT(NT_STATUS_NO_MEMORY);
2219 shadow_data->mem_ctx = shadow_mem_ctx;
2222 * Call the VFS routine to actually do the work.
2224 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2225 talloc_destroy(shadow_data->mem_ctx);
2226 if (errno == ENOSYS) {
2227 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2228 conn->connectpath));
2229 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2231 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2232 conn->connectpath));
2233 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
2237 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2242 data_count = 12+labels_data_count+4;
2245 if (max_data_count<data_count) {
2246 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2247 max_data_count,data_count));
2248 talloc_destroy(shadow_data->mem_ctx);
2249 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
2252 pdata = nttrans_realloc(ppdata, data_count);
2253 if (pdata == NULL) {
2254 talloc_destroy(shadow_data->mem_ctx);
2255 return ERROR_NT(NT_STATUS_NO_MEMORY);
2260 /* num_volumes 4 bytes */
2261 SIVAL(pdata,0,shadow_data->num_volumes);
2264 /* num_labels 4 bytes */
2265 SIVAL(pdata,4,shadow_data->num_volumes);
2268 /* needed_data_count 4 bytes */
2269 SIVAL(pdata,8,labels_data_count);
2273 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2274 shadow_data->num_volumes,fsp->fsp_name));
2275 if (labels && shadow_data->labels) {
2276 for (i=0;i<shadow_data->num_volumes;i++) {
2277 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2278 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2279 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2283 talloc_destroy(shadow_data->mem_ctx);
2285 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
2290 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2292 /* pretend this succeeded -
2294 * we have to send back a list with all files owned by this SID
2296 * but I have to check that --metze
2300 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2302 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2304 FSP_BELONGS_CONN(fsp,conn);
2306 /* unknown 4 bytes: this is not the length of the sid :-( */
2307 /*unknown = IVAL(pdata,0);*/
2309 sid_parse(pdata+4,sid_len,&sid);
2310 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2312 if (!NT_STATUS_IS_OK(sid_to_uid(&sid, &uid))) {
2313 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2314 sid_string_static(&sid),(unsigned long)sid_len));
2318 /* we can take a look at the find source :-)
2320 * find ./ -uid $uid -name '*' is what we need here
2323 * and send 4bytes len and then NULL terminated unicode strings
2326 * but I don't know how to deal with the paged results
2327 * (maybe we can hang the result anywhere in the fsp struct)
2329 * we don't send all files at once
2330 * and at the next we should *not* start from the beginning,
2331 * so we have to cache the result
2336 /* this works for now... */
2337 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2341 if (!logged_message) {
2342 logged_message = True; /* Only print this once... */
2343 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2348 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2352 #ifdef HAVE_SYS_QUOTAS
2353 /****************************************************************************
2354 Reply to get user quota
2355 ****************************************************************************/
2357 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2358 char **ppsetup, uint32 setup_count,
2359 char **ppparams, uint32 parameter_count,
2360 char **ppdata, uint32 data_count, uint32 max_data_count)
2362 NTSTATUS nt_status = NT_STATUS_OK;
2363 char *params = *ppparams;
2364 char *pdata = *ppdata;
2366 int data_len=0,param_len=0;
2369 files_struct *fsp = NULL;
2373 BOOL start_enum = True;
2374 SMB_NTQUOTA_STRUCT qt;
2375 SMB_NTQUOTA_LIST *tmp_list;
2376 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2377 extern struct current_user current_user;
2382 if (current_user.uid != 0) {
2383 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2384 lp_servicename(SNUM(conn)),conn->user));
2385 return ERROR_DOS(ERRDOS,ERRnoaccess);
2389 * Ensure minimum number of parameters sent.
2392 if (parameter_count < 4) {
2393 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2394 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2397 /* maybe we can check the quota_fnum */
2398 fsp = file_fsp(params,0);
2399 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2400 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2401 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2404 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2405 * is done by CHECK_NTQUOTA_HANDLE_OK()
2407 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2409 level = SVAL(params,2);
2411 /* unknown 12 bytes leading in params */
2414 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2415 /* seems that we should continue with the enum here --metze */
2417 if (qt_handle->quota_list!=NULL &&
2418 qt_handle->tmp_list==NULL) {
2421 free_ntquota_list(&(qt_handle->quota_list));
2423 /* Realloc the size of parameters and data we will return */
2425 params = nttrans_realloc(ppparams, param_len);
2426 if(params == NULL) {
2427 return ERROR_DOS(ERRDOS,ERRnomem);
2431 SIVAL(params,0,data_len);
2438 case TRANSACT_GET_USER_QUOTA_LIST_START:
2440 if (qt_handle->quota_list==NULL &&
2441 qt_handle->tmp_list==NULL) {
2445 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2446 return ERROR_DOS(ERRSRV,ERRerror);
2448 /* Realloc the size of parameters and data we will return */
2450 params = nttrans_realloc(ppparams, param_len);
2451 if(params == NULL) {
2452 return ERROR_DOS(ERRDOS,ERRnomem);
2455 /* we should not trust the value in max_data_count*/
2456 max_data_count = MIN(max_data_count,2048);
2458 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2460 return ERROR_DOS(ERRDOS,ERRnomem);
2465 /* set params Size of returned Quota Data 4 bytes*/
2466 /* but set it later when we know it */
2468 /* for each entry push the data */
2471 qt_handle->tmp_list = qt_handle->quota_list;
2474 tmp_list = qt_handle->tmp_list;
2476 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2477 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2479 sid_len = sid_size(&tmp_list->quotas->sid);
2480 entry_len = 40 + sid_len;
2482 /* nextoffset entry 4 bytes */
2483 SIVAL(entry,0,entry_len);
2485 /* then the len of the SID 4 bytes */
2486 SIVAL(entry,4,sid_len);
2488 /* unknown data 8 bytes SMB_BIG_UINT */
2489 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2491 /* the used disk space 8 bytes SMB_BIG_UINT */
2492 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2494 /* the soft quotas 8 bytes SMB_BIG_UINT */
2495 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2497 /* the hard quotas 8 bytes SMB_BIG_UINT */
2498 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2500 /* and now the SID */
2501 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2504 qt_handle->tmp_list = tmp_list;
2506 /* overwrite the offset of the last entry */
2507 SIVAL(entry-entry_len,0,0);
2509 data_len = 4+qt_len;
2510 /* overwrite the params quota_data_len */
2511 SIVAL(params,0,data_len);
2515 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2517 /* unknown 4 bytes IVAL(pdata,0) */
2519 if (data_count < 8) {
2520 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2521 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2524 sid_len = IVAL(pdata,4);
2525 /* Ensure this is less than 1mb. */
2526 if (sid_len > (1024*1024)) {
2527 return ERROR_DOS(ERRDOS,ERRnomem);
2530 if (data_count < 8+sid_len) {
2531 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2532 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2535 data_len = 4+40+sid_len;
2537 if (max_data_count < data_len) {
2538 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2539 max_data_count, data_len));
2541 SIVAL(params,0,data_len);
2543 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2547 sid_parse(pdata+8,sid_len,&sid);
2549 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2552 * we have to return zero's in all fields
2553 * instead of returning an error here
2558 /* Realloc the size of parameters and data we will return */
2560 params = nttrans_realloc(ppparams, param_len);
2561 if(params == NULL) {
2562 return ERROR_DOS(ERRDOS,ERRnomem);
2565 pdata = nttrans_realloc(ppdata, data_len);
2567 return ERROR_DOS(ERRDOS,ERRnomem);
2572 /* set params Size of returned Quota Data 4 bytes*/
2573 SIVAL(params,0,data_len);
2575 /* nextoffset entry 4 bytes */
2578 /* then the len of the SID 4 bytes */
2579 SIVAL(entry,4,sid_len);
2581 /* unknown data 8 bytes SMB_BIG_UINT */
2582 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2584 /* the used disk space 8 bytes SMB_BIG_UINT */
2585 SBIG_UINT(entry,16,qt.usedspace);
2587 /* the soft quotas 8 bytes SMB_BIG_UINT */
2588 SBIG_UINT(entry,24,qt.softlim);
2590 /* the hard quotas 8 bytes SMB_BIG_UINT */
2591 SBIG_UINT(entry,32,qt.hardlim);
2593 /* and now the SID */
2594 sid_linearize(entry+40, sid_len, &sid);
2599 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2600 return ERROR_DOS(ERRSRV,ERRerror);
2604 send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
2609 /****************************************************************************
2610 Reply to set user quota
2611 ****************************************************************************/
2613 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2614 char **ppsetup, uint32 setup_count,
2615 char **ppparams, uint32 parameter_count,
2616 char **ppdata, uint32 data_count, uint32 max_data_count)
2618 char *params = *ppparams;
2619 char *pdata = *ppdata;
2620 int data_len=0,param_len=0;
2621 SMB_NTQUOTA_STRUCT qt;
2624 files_struct *fsp = NULL;
2629 if (current_user.uid != 0) {
2630 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2631 lp_servicename(SNUM(conn)),conn->user));
2632 return ERROR_DOS(ERRDOS,ERRnoaccess);
2636 * Ensure minimum number of parameters sent.
2639 if (parameter_count < 2) {
2640 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2641 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2644 /* maybe we can check the quota_fnum */
2645 fsp = file_fsp(params,0);
2646 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2647 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2648 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2651 if (data_count < 40) {
2652 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2653 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2656 /* offset to next quota record.
2657 * 4 bytes IVAL(pdata,0)
2662 sid_len = IVAL(pdata,4);
2664 if (data_count < 40+sid_len) {
2665 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2666 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2669 /* unknown 8 bytes in pdata
2670 * maybe its the change time in NTTIME
2673 /* the used space 8 bytes (SMB_BIG_UINT)*/
2674 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2675 #ifdef LARGE_SMB_OFF_T
2676 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2677 #else /* LARGE_SMB_OFF_T */
2678 if ((IVAL(pdata,20) != 0)&&
2679 ((qt.usedspace != 0xFFFFFFFF)||
2680 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2681 /* more than 32 bits? */
2682 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2684 #endif /* LARGE_SMB_OFF_T */
2686 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2687 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2688 #ifdef LARGE_SMB_OFF_T
2689 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2690 #else /* LARGE_SMB_OFF_T */
2691 if ((IVAL(pdata,28) != 0)&&
2692 ((qt.softlim != 0xFFFFFFFF)||
2693 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2694 /* more than 32 bits? */
2695 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2697 #endif /* LARGE_SMB_OFF_T */
2699 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2700 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2701 #ifdef LARGE_SMB_OFF_T
2702 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2703 #else /* LARGE_SMB_OFF_T */
2704 if ((IVAL(pdata,36) != 0)&&
2705 ((qt.hardlim != 0xFFFFFFFF)||
2706 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2707 /* more than 32 bits? */
2708 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2710 #endif /* LARGE_SMB_OFF_T */
2712 sid_parse(pdata+40,sid_len,&sid);
2713 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2715 /* 44 unknown bytes left... */
2717 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2718 return ERROR_DOS(ERRSRV,ERRerror);
2721 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
2725 #endif /* HAVE_SYS_QUOTAS */
2727 /****************************************************************************
2728 Reply to a SMBNTtrans.
2729 ****************************************************************************/
2731 int reply_nttrans(connection_struct *conn,
2732 char *inbuf,char *outbuf,int length,int bufsize)
2735 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2736 #if 0 /* Not used. */
2737 uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount);
2738 uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
2739 #endif /* Not used. */
2740 uint32 total_parameter_count = IVAL(inbuf, smb_nt_TotalParameterCount);
2741 uint32 total_data_count = IVAL(inbuf, smb_nt_TotalDataCount);
2742 uint32 parameter_count = IVAL(inbuf,smb_nt_ParameterCount);
2743 uint32 parameter_offset = IVAL(inbuf,smb_nt_ParameterOffset);
2744 uint32 data_count = IVAL(inbuf,smb_nt_DataCount);
2745 uint32 data_offset = IVAL(inbuf,smb_nt_DataOffset);
2746 uint16 setup_count = 2*CVAL(inbuf,smb_nt_SetupCount); /* setup count is in *words* */
2747 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2748 char *params = NULL, *data = NULL, *setup = NULL;
2749 uint32 num_params_sofar, num_data_sofar;
2750 START_PROFILE(SMBnttrans);
2752 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2753 END_PROFILE(SMBnttrans);
2754 return ERROR_DOS(ERRSRV,ERRaccess);
2757 outsize = set_message(outbuf,0,0,True);
2760 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2761 * Ensure this is so as a sanity check.
2764 if(CVAL(inbuf, smb_wct) != 19 + (setup_count/2)) {
2765 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2766 CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
2770 /* Don't allow more than 128mb for each value. */
2771 if ((total_parameter_count > (1024*1024*128)) || (total_data_count > (1024*1024*128))) {
2772 END_PROFILE(SMBnttrans);
2773 return ERROR_DOS(ERRDOS,ERRnomem);
2776 /* Allocate the space for the setup, the maximum needed parameters and data */
2778 if(setup_count > 0) {
2779 setup = (char *)SMB_MALLOC(setup_count);
2781 if (total_parameter_count > 0) {
2782 params = (char *)SMB_MALLOC(total_parameter_count);
2784 if (total_data_count > 0) {
2785 data = (char *)SMB_MALLOC(total_data_count);
2788 if ((total_parameter_count && !params) || (total_data_count && !data) ||
2789 (setup_count && !setup)) {
2793 DEBUG(0,("reply_nttrans : Out of memory\n"));
2794 END_PROFILE(SMBnttrans);
2795 return ERROR_DOS(ERRDOS,ERRnomem);
2798 /* Copy the param and data bytes sent with this request into the params buffer */
2799 num_params_sofar = parameter_count;
2800 num_data_sofar = data_count;
2802 if (parameter_count > total_parameter_count || data_count > total_data_count)
2806 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
2807 if ((smb_nt_SetupStart + setup_count < smb_nt_SetupStart) ||
2808 (smb_nt_SetupStart + setup_count < setup_count)) {
2811 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)) {
2824 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length)||
2825 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf))) {
2829 memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
2830 dump_data(10, params, parameter_count);
2833 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
2834 if ((data_offset + data_count < data_offset) || (data_offset + data_count < data_count)) {
2837 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2838 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf))) {
2842 memcpy( data, smb_base(inbuf) + data_offset, data_count);
2843 dump_data(10, data, data_count);
2846 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2848 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2849 /* We need to send an interim response then receive the rest
2850 of the parameter/data bytes */
2851 outsize = set_message(outbuf,0,0,True);
2852 srv_signing_trans_stop();
2854 if (!send_smb(smbd_server_fd(),outbuf)) {
2855 exit_server("reply_nttrans: send_smb failed.");
2858 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2860 uint32 parameter_displacement;
2861 uint32 data_displacement;
2863 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
2865 /* We need to re-calcuate the new length after we've read the secondary packet. */
2866 length = smb_len(inbuf) + 4;
2869 * The sequence number for the trans reply is always
2870 * based on the last secondary received.
2873 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2875 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
2876 outsize = set_message(outbuf,0,0,True);
2878 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2880 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2881 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
2886 /* Revise total_params and total_data in case they have changed downwards */
2887 if (IVAL(inbuf, smb_nts_TotalParameterCount) < total_parameter_count) {
2888 total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
2890 if (IVAL(inbuf, smb_nts_TotalDataCount) < total_data_count) {
2891 total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
2894 parameter_count = IVAL(inbuf,smb_nts_ParameterCount);
2895 parameter_offset = IVAL(inbuf, smb_nts_ParameterOffset);
2896 parameter_displacement = IVAL(inbuf, smb_nts_ParameterDisplacement);
2897 num_params_sofar += parameter_count;
2899 data_count = IVAL(inbuf, smb_nts_DataCount);
2900 data_displacement = IVAL(inbuf, smb_nts_DataDisplacement);
2901 data_offset = IVAL(inbuf, smb_nts_DataOffset);
2902 num_data_sofar += data_count;
2904 if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count) {
2905 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2909 if (parameter_count) {
2910 if (parameter_displacement + parameter_count > total_parameter_count) {
2913 if ((parameter_displacement + parameter_count < parameter_displacement) ||
2914 (parameter_displacement + parameter_count < parameter_count)) {
2917 if (parameter_displacement > total_parameter_count) {
2920 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length) ||
2921 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf))) {
2924 if (parameter_displacement + params < params) {
2928 memcpy( ¶ms[parameter_displacement], smb_base(inbuf) + parameter_offset, parameter_count);
2932 if (data_displacement + data_count > total_data_count) {
2935 if ((data_displacement + data_count < data_displacement) ||
2936 (data_displacement + data_count < data_count)) {
2939 if (data_displacement > total_data_count) {
2942 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2943 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf))) {
2946 if (data_displacement + data < data) {
2950 memcpy( &data[data_displacement], smb_base(inbuf)+ data_offset, data_count);
2955 if (Protocol >= PROTOCOL_NT1) {
2956 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_IS_LONG_NAME);
2959 /* Now we must call the relevant NT_TRANS function */
2960 switch(function_code) {
2961 case NT_TRANSACT_CREATE:
2962 START_PROFILE_NESTED(NT_transact_create);
2963 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2965 &setup, setup_count,
2966 ¶ms, total_parameter_count,
2967 &data, total_data_count, max_data_count);
2968 END_PROFILE_NESTED(NT_transact_create);
2970 case NT_TRANSACT_IOCTL:
2971 START_PROFILE_NESTED(NT_transact_ioctl);
2972 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2974 &setup, setup_count,
2975 ¶ms, total_parameter_count,
2976 &data, total_data_count, max_data_count);
2977 END_PROFILE_NESTED(NT_transact_ioctl);
2979 case NT_TRANSACT_SET_SECURITY_DESC:
2980 START_PROFILE_NESTED(NT_transact_set_security_desc);
2981 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2983 &setup, setup_count,
2984 ¶ms, total_parameter_count,
2985 &data, total_data_count, max_data_count);
2986 END_PROFILE_NESTED(NT_transact_set_security_desc);
2988 case NT_TRANSACT_NOTIFY_CHANGE:
2989 START_PROFILE_NESTED(NT_transact_notify_change);
2990 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
2992 &setup, setup_count,
2993 ¶ms, total_parameter_count,
2994 &data, total_data_count, max_data_count);
2995 END_PROFILE_NESTED(NT_transact_notify_change);
2997 case NT_TRANSACT_RENAME:
2998 START_PROFILE_NESTED(NT_transact_rename);
2999 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
3001 &setup, setup_count,
3002 ¶ms, total_parameter_count,
3003 &data, total_data_count, max_data_count);
3004 END_PROFILE_NESTED(NT_transact_rename);
3007 case NT_TRANSACT_QUERY_SECURITY_DESC:
3008 START_PROFILE_NESTED(NT_transact_query_security_desc);
3009 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
3011 &setup, setup_count,
3012 ¶ms, total_parameter_count,
3013 &data, total_data_count, max_data_count);
3014 END_PROFILE_NESTED(NT_transact_query_security_desc);
3016 #ifdef HAVE_SYS_QUOTAS
3017 case NT_TRANSACT_GET_USER_QUOTA:
3018 START_PROFILE_NESTED(NT_transact_get_user_quota);
3019 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
3021 &setup, setup_count,
3022 ¶ms, total_parameter_count,
3023 &data, total_data_count, max_data_count);
3024 END_PROFILE_NESTED(NT_transact_get_user_quota);
3026 case NT_TRANSACT_SET_USER_QUOTA:
3027 START_PROFILE_NESTED(NT_transact_set_user_quota);
3028 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
3030 &setup, setup_count,
3031 ¶ms, total_parameter_count,
3032 &data, total_data_count, max_data_count);
3033 END_PROFILE_NESTED(NT_transact_set_user_quota);
3035 #endif /* HAVE_SYS_QUOTAS */
3037 /* Error in request */
3038 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
3042 END_PROFILE(SMBnttrans);
3043 srv_signing_trans_stop();
3044 return ERROR_DOS(ERRSRV,ERRerror);
3047 /* As we do not know how many data packets will need to be
3048 returned here the various call_nt_transact_xxxx calls
3049 must send their own. Thus a call_nt_transact_xxxx routine only
3050 returns a value other than -1 when it wants to send
3054 srv_signing_trans_stop();
3059 END_PROFILE(SMBnttrans);
3060 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
3061 calls have already sent it. If outsize != -1 then it is
3062 returning an error packet. */
3066 srv_signing_trans_stop();
3070 END_PROFILE(SMBnttrans);
3071 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);