2 Unix SMB/CIFS implementation.
3 SMB NT transaction handling
4 Copyright (C) Jeremy Allison 1994-1998
5 Copyright (C) Stefan (metze) Metzmacher 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 extern enum protocol_types Protocol;
26 extern int smb_read_error;
27 extern struct current_user current_user;
29 static const char *known_nt_pipes[] = {
50 static char *nttrans_realloc(char **ptr, size_t size)
53 smb_panic("nttrans_realloc() called with NULL ptr\n");
56 *ptr = (char *)SMB_REALLOC(*ptr, size);
60 memset(*ptr,'\0',size);
64 /****************************************************************************
65 Send the required number of replies back.
66 We assume all fields other than the data fields are
67 set correctly for the type of call.
68 HACK ! Always assumes smb_setup field is zero.
69 ****************************************************************************/
71 int send_nt_replies(char *outbuf, int bufsize, NTSTATUS nt_error,
72 char *params, int paramsize, char *pdata, int datasize)
74 int data_to_send = datasize;
75 int params_to_send = paramsize;
79 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
80 int alignment_offset = 3;
81 int data_alignment_offset = 0;
84 * Initially set the wcnt area to be 18 - this is true for all
88 set_message(outbuf,18,0,True);
90 if (NT_STATUS_V(nt_error)) {
95 * If there genuinely are no parameters or data to send just send
99 if(params_to_send == 0 && data_to_send == 0) {
101 if (!send_smb(smbd_server_fd(),outbuf)) {
102 exit_server_cleanly("send_nt_replies: send_smb failed.");
108 * When sending params and data ensure that both are nicely aligned.
109 * Only do this alignment when there is also data to send - else
110 * can cause NT redirector problems.
113 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
114 data_alignment_offset = 4 - (params_to_send % 4);
118 * Space is bufsize minus Netbios over TCP header minus SMB header.
119 * The alignment_offset is to align the param bytes on a four byte
120 * boundary (2 bytes for data len, one byte pad).
121 * NT needs this to work correctly.
124 useable_space = bufsize - ((smb_buf(outbuf)+
125 alignment_offset+data_alignment_offset) -
129 * useable_space can never be more than max_send minus the
133 useable_space = MIN(useable_space,
134 max_send - (alignment_offset+data_alignment_offset));
137 while (params_to_send || data_to_send) {
140 * Calculate whether we will totally or partially fill this packet.
143 total_sent_thistime = params_to_send + data_to_send +
144 alignment_offset + data_alignment_offset;
147 * We can never send more than useable_space.
150 total_sent_thistime = MIN(total_sent_thistime, useable_space);
152 set_message(outbuf, 18, total_sent_thistime, True);
155 * Set total params and data to be sent.
158 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
159 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
162 * Calculate how many parameters and data we can fit into
163 * this packet. Parameters get precedence.
166 params_sent_thistime = MIN(params_to_send,useable_space);
167 data_sent_thistime = useable_space - params_sent_thistime;
168 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
170 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
172 if(params_sent_thistime == 0) {
173 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
174 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
177 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
178 * parameter bytes, however the first 4 bytes of outbuf are
179 * the Netbios over TCP header. Thus use smb_base() to subtract
180 * them from the calculation.
183 SIVAL(outbuf,smb_ntr_ParameterOffset,
184 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
186 * Absolute displacement of param bytes sent in this packet.
189 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
193 * Deal with the data portion.
196 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
198 if(data_sent_thistime == 0) {
199 SIVAL(outbuf,smb_ntr_DataOffset,0);
200 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
203 * The offset of the data bytes is the offset of the
204 * parameter bytes plus the number of parameters being sent this time.
207 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
208 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
209 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
213 * Copy the param bytes into the packet.
216 if(params_sent_thistime) {
217 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
221 * Copy in the data bytes
224 if(data_sent_thistime) {
225 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
226 data_alignment_offset,pd,data_sent_thistime);
229 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
230 params_sent_thistime, data_sent_thistime, useable_space));
231 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
232 params_to_send, data_to_send, paramsize, datasize));
234 /* Send the packet */
236 if (!send_smb(smbd_server_fd(),outbuf)) {
237 exit_server_cleanly("send_nt_replies: send_smb failed.");
240 pp += params_sent_thistime;
241 pd += data_sent_thistime;
243 params_to_send -= params_sent_thistime;
244 data_to_send -= data_sent_thistime;
250 if(params_to_send < 0 || data_to_send < 0) {
251 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
252 params_to_send, data_to_send));
260 /****************************************************************************
261 Is it an NTFS stream name ?
262 ****************************************************************************/
264 BOOL is_ntfs_stream_name(const char *fname)
266 if (lp_posix_pathnames()) {
269 return (strchr_m(fname, ':') != NULL) ? True : False;
272 /****************************************************************************
274 ****************************************************************************/
276 static BOOL saved_case_sensitive;
277 static BOOL saved_case_preserve;
278 static BOOL saved_short_case_preserve;
280 /****************************************************************************
282 ****************************************************************************/
284 static uint32 set_posix_case_semantics(connection_struct *conn, uint32 file_attributes)
286 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
287 return file_attributes;
290 saved_case_sensitive = conn->case_sensitive;
291 saved_case_preserve = conn->case_preserve;
292 saved_short_case_preserve = conn->short_case_preserve;
295 conn->case_sensitive = True;
296 conn->case_preserve = True;
297 conn->short_case_preserve = True;
299 return (file_attributes & ~FILE_FLAG_POSIX_SEMANTICS);
302 /****************************************************************************
303 Restore case semantics.
304 ****************************************************************************/
306 static void restore_case_semantics(connection_struct *conn, uint32 file_attributes)
308 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS)) {
312 conn->case_sensitive = saved_case_sensitive;
313 conn->case_preserve = saved_case_preserve;
314 conn->short_case_preserve = saved_short_case_preserve;
317 /****************************************************************************
318 Reply to an NT create and X call on a pipe.
319 ****************************************************************************/
321 static int nt_open_pipe(char *fname, connection_struct *conn,
322 char *inbuf, char *outbuf, int *ppnum)
324 smb_np_struct *p = NULL;
325 uint16 vuid = SVAL(inbuf, smb_uid);
328 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
330 /* See if it is one we want to handle. */
332 if (lp_disable_spoolss() && strequal(fname, "\\spoolss")) {
333 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
336 for( i = 0; known_nt_pipes[i]; i++ ) {
337 if( strequal(fname,known_nt_pipes[i])) {
342 if ( known_nt_pipes[i] == NULL ) {
343 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
346 /* Strip \\ off the name. */
349 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
351 p = open_rpc_pipe_p(fname, conn, vuid);
353 return(ERROR_DOS(ERRSRV,ERRnofids));
356 /* TODO: Add pipe to db */
358 if ( !store_pipe_opendb( p ) ) {
359 DEBUG(3,("nt_open_pipe: failed to store %s pipe open.\n", fname));
366 /****************************************************************************
367 Reply to an NT create and X call for pipes.
368 ****************************************************************************/
370 static int do_ntcreate_pipe_open(connection_struct *conn,
371 char *inbuf,char *outbuf,int length,int bufsize)
378 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
380 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
385 * Deal with pipe return.
388 set_message(outbuf,34,0,True);
390 p = outbuf + smb_vwv2;
394 SIVAL(p,0,FILE_WAS_OPENED);
397 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
400 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
402 SSVAL(p,2, 0x5FF); /* ? */
404 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
406 return chain_reply(inbuf,outbuf,length,bufsize);
409 /****************************************************************************
410 Reply to an NT create and X call for a quota file.
411 ****************************************************************************/
413 int reply_ntcreate_and_X_quota(connection_struct *conn,
418 enum FAKE_FILE_TYPE fake_file_type,
423 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
427 status = open_fake_file(conn, fake_file_type, fname, desired_access,
430 if (!NT_STATUS_IS_OK(status)) {
431 return ERROR_NT(status);
434 set_message(outbuf,34,0,True);
436 p = outbuf + smb_vwv2;
438 /* SCVAL(p,0,NO_OPLOCK_RETURN); */
440 SSVAL(p,0,fsp->fnum);
442 DEBUG(5,("reply_ntcreate_and_X_quota: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
444 result = chain_reply(inbuf,outbuf,length,bufsize);
448 /****************************************************************************
449 Reply to an NT create and X call.
450 ****************************************************************************/
452 int reply_ntcreate_and_X(connection_struct *conn,
453 char *inbuf,char *outbuf,int length,int bufsize)
457 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
458 uint32 access_mask = IVAL(inbuf,smb_ntcreate_DesiredAccess);
459 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
460 uint32 new_file_attributes;
461 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
462 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
463 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
464 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
465 /* Breakout the oplock request bits so we can set the
466 reply bits separately. */
467 int oplock_request = 0;
469 SMB_OFF_T file_len = 0;
470 SMB_STRUCT_STAT sbuf;
472 files_struct *fsp = NULL;
474 struct timespec c_timespec;
475 struct timespec a_timespec;
476 struct timespec m_timespec;
477 BOOL extended_oplock_granted = False;
480 START_PROFILE(SMBntcreateX);
482 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
483 "file_attributes = 0x%x, share_access = 0x%x, "
484 "create_disposition = 0x%x create_options = 0x%x "
485 "root_dir_fid = 0x%x\n",
487 (unsigned int)access_mask,
488 (unsigned int)file_attributes,
489 (unsigned int)share_access,
490 (unsigned int)create_disposition,
491 (unsigned int)create_options,
492 (unsigned int)root_dir_fid ));
495 * If it's an IPC, use the pipe handler.
499 if (lp_nt_pipe_support()) {
500 END_PROFILE(SMBntcreateX);
501 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
503 END_PROFILE(SMBntcreateX);
504 return(ERROR_DOS(ERRDOS,ERRnoaccess));
508 if (create_options & FILE_OPEN_BY_FILE_ID) {
509 END_PROFILE(SMBntcreateX);
510 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
517 if(root_dir_fid != 0) {
519 * This filename is relative to a directory fid.
522 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
526 END_PROFILE(SMBntcreateX);
527 return ERROR_DOS(ERRDOS,ERRbadfid);
530 if(!dir_fsp->is_directory) {
532 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
533 if (!NT_STATUS_IS_OK(status)) {
534 END_PROFILE(SMBntcreateX);
535 return ERROR_NT(status);
539 * Check to see if this is a mac fork of some kind.
542 if( is_ntfs_stream_name(fname)) {
543 END_PROFILE(SMBntcreateX);
544 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
548 we need to handle the case when we get a
549 relative open relative to a file and the
550 pathname is blank - this is a reopen!
551 (hint from demyn plantenberg)
554 END_PROFILE(SMBntcreateX);
555 return(ERROR_DOS(ERRDOS,ERRbadfid));
559 * Copy in the base directory name.
562 pstrcpy( fname, dir_fsp->fsp_name );
563 dir_name_len = strlen(fname);
566 * Ensure it ends in a '\'.
569 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
574 srvstr_get_path(inbuf, rel_fname, smb_buf(inbuf), sizeof(rel_fname), 0, STR_TERMINATE, &status);
575 if (!NT_STATUS_IS_OK(status)) {
576 END_PROFILE(SMBntcreateX);
577 return ERROR_NT(status);
579 pstrcat(fname, rel_fname);
581 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
582 if (!NT_STATUS_IS_OK(status)) {
583 END_PROFILE(SMBntcreateX);
584 return ERROR_NT(status);
588 * Check to see if this is a mac fork of some kind.
591 if( is_ntfs_stream_name(fname)) {
592 enum FAKE_FILE_TYPE fake_file_type = is_fake_file(fname);
593 if (fake_file_type!=FAKE_FILE_TYPE_NONE) {
595 * Here we go! support for changing the disk quotas --metze
597 * We need to fake up to open this MAGIC QUOTA file
598 * and return a valid FID.
600 * w2k close this file directly after openening
601 * xp also tries a QUERY_FILE_INFO on the file and then close it
603 result = reply_ntcreate_and_X_quota(conn, inbuf, outbuf, length, bufsize,
604 fake_file_type, fname);
605 END_PROFILE(SMBntcreateX);
608 END_PROFILE(SMBntcreateX);
609 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
615 * Now contruct the smb_open_mode value from the filename,
616 * desired access and the share access.
618 if (!resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, fname)) {
619 END_PROFILE(SMBntcreateX);
620 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
623 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
624 if (oplock_request) {
625 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
629 * Ordinary file or directory.
633 * Check if POSIX semantics are wanted.
636 new_file_attributes = set_posix_case_semantics(conn, file_attributes);
638 status = unix_convert(conn, fname, False, NULL, &sbuf);
639 if (!NT_STATUS_IS_OK(status)) {
640 restore_case_semantics(conn, file_attributes);
641 END_PROFILE(SMBntcreateX);
642 return ERROR_NT(status);
644 /* All file access must go through check_name() */
645 status = check_name(conn, fname);
646 if (!NT_STATUS_IS_OK(status)) {
647 restore_case_semantics(conn, file_attributes);
648 END_PROFILE(SMBntcreateX);
649 return ERROR_NT(status);
652 /* This is the correct thing to do (check every time) but can_delete is
653 expensive (it may have to read the parent directory permissions). So
654 for now we're not doing it unless we have a strong hint the client
655 is really going to delete this file. If the client is forcing FILE_CREATE
656 let the filesystem take care of the permissions. */
658 /* Setting FILE_SHARE_DELETE is the hint. */
660 if (lp_acl_check_permissions(SNUM(conn))
661 && (create_disposition != FILE_CREATE)
662 && (share_access & FILE_SHARE_DELETE)
663 && (access_mask & DELETE_ACCESS)) {
664 if ((dos_mode(conn, fname, &sbuf) & FILE_ATTRIBUTE_READONLY) ||
665 !can_delete_file_in_directory(conn, fname)) {
666 restore_case_semantics(conn, file_attributes);
667 END_PROFILE(SMBntcreateX);
668 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
673 * If it's a request for a directory open, deal with it separately.
676 if(create_options & FILE_DIRECTORY_FILE) {
678 /* Can't open a temp directory. IFS kit test. */
679 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
680 END_PROFILE(SMBntcreateX);
681 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
685 status = open_directory(conn, fname, &sbuf,
693 restore_case_semantics(conn, file_attributes);
695 if(!NT_STATUS_IS_OK(status)) {
696 if (!use_nt_status() && NT_STATUS_EQUAL(
697 status, NT_STATUS_OBJECT_NAME_COLLISION)) {
698 status = NT_STATUS_DOS(ERRDOS, ERRfilexists);
700 END_PROFILE(SMBntcreateX);
701 return ERROR_NT(status);
707 * Ordinary file case.
710 /* NB. We have a potential bug here. If we
711 * cause an oplock break to ourselves, then we
712 * could end up processing filename related
713 * SMB requests whilst we await the oplock
714 * break response. As we may have changed the
715 * filename case semantics to be POSIX-like,
716 * this could mean a filename request could
717 * fail when it should succeed. This is a rare
718 * condition, but eventually we must arrange
719 * to restore the correct case semantics
720 * before issuing an oplock break request to
721 * our client. JRA. */
723 status = open_file_ntcreate(conn,fname,&sbuf,
732 if (!NT_STATUS_IS_OK(status)) {
733 /* We cheat here. There are two cases we
734 * care about. One is a directory rename,
735 * where the NT client will attempt to
736 * open the source directory for
737 * DELETE access. Note that when the
738 * NT client does this it does *not*
739 * set the directory bit in the
740 * request packet. This is translated
741 * into a read/write open
742 * request. POSIX states that any open
743 * for write request on a directory
744 * will generate an EISDIR error, so
745 * we can catch this here and open a
746 * pseudo handle that is flagged as a
747 * directory. The second is an open
748 * for a permissions read only, which
749 * we handle in the open_file_stat case. JRA.
752 if (NT_STATUS_EQUAL(status,
753 NT_STATUS_FILE_IS_A_DIRECTORY)) {
756 * Fail the open if it was explicitly a non-directory file.
759 if (create_options & FILE_NON_DIRECTORY_FILE) {
760 restore_case_semantics(conn, file_attributes);
761 END_PROFILE(SMBntcreateX);
762 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
766 status = open_directory(conn, fname, &sbuf,
774 if(!NT_STATUS_IS_OK(status)) {
775 restore_case_semantics(conn, file_attributes);
776 if (!use_nt_status() && NT_STATUS_EQUAL(
777 status, NT_STATUS_OBJECT_NAME_COLLISION)) {
778 status = NT_STATUS_DOS(ERRDOS, ERRfilexists);
780 END_PROFILE(SMBntcreateX);
781 return ERROR_NT(status);
784 restore_case_semantics(conn, file_attributes);
785 END_PROFILE(SMBntcreateX);
786 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
787 /* We have re-scheduled this call. */
790 return ERROR_NT(status);
795 restore_case_semantics(conn, file_attributes);
797 file_len = sbuf.st_size;
798 fattr = dos_mode(conn,fname,&sbuf);
800 fattr = FILE_ATTRIBUTE_NORMAL;
802 if (!fsp->is_directory && (fattr & aDIR)) {
803 close_file(fsp,ERROR_CLOSE);
804 END_PROFILE(SMBntcreateX);
805 return ERROR_DOS(ERRDOS,ERRnoaccess);
808 /* Save the requested allocation size. */
809 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
810 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
811 #ifdef LARGE_SMB_OFF_T
812 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
814 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
815 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
816 if (fsp->is_directory) {
817 close_file(fsp,ERROR_CLOSE);
818 END_PROFILE(SMBntcreateX);
819 /* Can't set allocation size on a directory. */
820 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
822 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
823 close_file(fsp,ERROR_CLOSE);
824 END_PROFILE(SMBntcreateX);
825 return ERROR_NT(NT_STATUS_DISK_FULL);
828 fsp->initial_allocation_size = smb_roundup(fsp->conn,(SMB_BIG_UINT)file_len);
833 * If the caller set the extended oplock request bit
834 * and we granted one (by whatever means) - set the
835 * correct bit for extended oplock reply.
838 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
839 extended_oplock_granted = True;
842 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
843 extended_oplock_granted = True;
847 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
848 set_message(outbuf,42,0,True);
850 set_message(outbuf,34,0,True);
853 p = outbuf + smb_vwv2;
856 * Currently as we don't support level II oplocks we just report
857 * exclusive & batch here.
860 if (extended_oplock_granted) {
861 if (flags & REQUEST_BATCH_OPLOCK) {
862 SCVAL(p,0, BATCH_OPLOCK_RETURN);
864 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
866 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
867 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
869 SCVAL(p,0,NO_OPLOCK_RETURN);
873 SSVAL(p,0,fsp->fnum);
875 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
876 SIVAL(p,0,FILE_WAS_SUPERSEDED);
883 c_timespec = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
884 a_timespec = get_atimespec(&sbuf);
885 m_timespec = get_mtimespec(&sbuf);
887 if (lp_dos_filetime_resolution(SNUM(conn))) {
888 dos_filetime_timespec(&c_timespec);
889 dos_filetime_timespec(&a_timespec);
890 dos_filetime_timespec(&m_timespec);
893 put_long_date_timespec(p, c_timespec); /* create time. */
895 put_long_date_timespec(p, a_timespec); /* access time */
897 put_long_date_timespec(p, m_timespec); /* write time */
899 put_long_date_timespec(p, m_timespec); /* change time */
901 SIVAL(p,0,fattr); /* File Attributes. */
903 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
905 SOFF_T(p,0,file_len);
907 if (flags & EXTENDED_RESPONSE_REQUIRED) {
911 SCVAL(p,0,fsp->is_directory ? 1 : 0);
913 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
915 result = chain_reply(inbuf,outbuf,length,bufsize);
916 END_PROFILE(SMBntcreateX);
920 /****************************************************************************
921 Reply to a NT_TRANSACT_CREATE call to open a pipe.
922 ****************************************************************************/
924 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
925 uint16 **ppsetup, uint32 setup_count,
926 char **ppparams, uint32 parameter_count,
927 char **ppdata, uint32 data_count)
930 char *params = *ppparams;
937 * Ensure minimum number of parameters sent.
940 if(parameter_count < 54) {
941 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
942 return ERROR_DOS(ERRDOS,ERRnoaccess);
945 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
946 if (!NT_STATUS_IS_OK(status)) {
947 return ERROR_NT(status);
950 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0) {
954 /* Realloc the size of parameters and data we will return */
955 params = nttrans_realloc(ppparams, 69);
957 return ERROR_DOS(ERRDOS,ERRnomem);
961 SCVAL(p,0,NO_OPLOCK_RETURN);
966 SIVAL(p,0,FILE_WAS_OPENED);
970 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
973 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
975 SSVAL(p,2, 0x5FF); /* ? */
977 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
979 /* Send the required number of replies */
980 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
985 /****************************************************************************
986 Internal fn to set security descriptors.
987 ****************************************************************************/
989 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
992 SEC_DESC *psd = NULL;
996 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
1001 * Init the parse struct we will unmarshall from.
1004 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
1005 DEBUG(0,("set_sd: talloc_init failed.\n"));
1006 return NT_STATUS_NO_MEMORY;
1009 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1012 * Setup the prs_struct to point at the memory we just
1016 prs_give_memory( &pd, data, sd_len, False);
1019 * Finally, unmarshall from the data buffer.
1022 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1023 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1025 * Return access denied for want of a better error message..
1027 talloc_destroy(mem_ctx);
1028 return NT_STATUS_NO_MEMORY;
1031 if (psd->owner_sid==0) {
1032 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1034 if (psd->group_sid==0) {
1035 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1038 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1041 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1044 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fh->fd, security_info_sent, psd);
1047 talloc_destroy(mem_ctx);
1048 return NT_STATUS_ACCESS_DENIED;
1051 talloc_destroy(mem_ctx);
1053 return NT_STATUS_OK;
1056 /****************************************************************************
1057 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1058 ****************************************************************************/
1060 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
1062 struct ea_list *ea_list_head = NULL;
1065 if (data_size < 4) {
1069 while (offset + 4 <= data_size) {
1070 size_t next_offset = IVAL(pdata,offset);
1071 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
1077 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
1078 if (next_offset == 0) {
1081 offset += next_offset;
1084 return ea_list_head;
1087 /****************************************************************************
1088 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1089 ****************************************************************************/
1091 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1092 uint16 **ppsetup, uint32 setup_count,
1093 char **ppparams, uint32 parameter_count,
1094 char **ppdata, uint32 data_count, uint32 max_data_count)
1097 char *params = *ppparams;
1098 char *data = *ppdata;
1099 /* Breakout the oplock request bits so we can set the reply bits separately. */
1100 int oplock_request = 0;
1102 SMB_OFF_T file_len = 0;
1103 SMB_STRUCT_STAT sbuf;
1105 files_struct *fsp = NULL;
1107 BOOL extended_oplock_granted = False;
1110 uint32 file_attributes;
1111 uint32 new_file_attributes;
1112 uint32 share_access;
1113 uint32 create_disposition;
1114 uint32 create_options;
1117 uint16 root_dir_fid;
1118 struct timespec c_timespec;
1119 struct timespec a_timespec;
1120 struct timespec m_timespec;
1121 struct ea_list *ea_list = NULL;
1122 TALLOC_CTX *ctx = NULL;
1126 DEBUG(5,("call_nt_transact_create\n"));
1129 * If it's an IPC, use the pipe handler.
1133 if (lp_nt_pipe_support()) {
1134 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1136 ppsetup, setup_count,
1137 ppparams, parameter_count,
1138 ppdata, data_count);
1140 return ERROR_DOS(ERRDOS,ERRnoaccess);
1145 * Ensure minimum number of parameters sent.
1148 if(parameter_count < 54) {
1149 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1150 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1153 flags = IVAL(params,0);
1154 access_mask = IVAL(params,8);
1155 file_attributes = IVAL(params,20);
1156 share_access = IVAL(params,24);
1157 create_disposition = IVAL(params,28);
1158 create_options = IVAL(params,32);
1159 sd_len = IVAL(params,36);
1160 ea_len = IVAL(params,40);
1161 root_dir_fid = (uint16)IVAL(params,4);
1163 /* Ensure the data_len is correct for the sd and ea values given. */
1164 if ((ea_len + sd_len > data_count) ||
1165 (ea_len > data_count) || (sd_len > data_count) ||
1166 (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
1167 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1168 (unsigned int)ea_len, (unsigned int)sd_len, (unsigned int)data_count ));
1169 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1173 if (!lp_ea_support(SNUM(conn))) {
1174 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1175 (unsigned int)ea_len ));
1176 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED);
1180 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1181 (unsigned int)ea_len ));
1182 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1186 if (create_options & FILE_OPEN_BY_FILE_ID) {
1187 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1191 * Get the file name.
1194 if(root_dir_fid != 0) {
1196 * This filename is relative to a directory fid.
1198 files_struct *dir_fsp = file_fsp(params,4);
1199 size_t dir_name_len;
1202 return ERROR_DOS(ERRDOS,ERRbadfid);
1205 if(!dir_fsp->is_directory) {
1206 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1207 if (!NT_STATUS_IS_OK(status)) {
1208 return ERROR_NT(status);
1212 * Check to see if this is a mac fork of some kind.
1215 if( is_ntfs_stream_name(fname)) {
1216 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1219 return ERROR_DOS(ERRDOS,ERRbadfid);
1223 * Copy in the base directory name.
1226 pstrcpy( fname, dir_fsp->fsp_name );
1227 dir_name_len = strlen(fname);
1230 * Ensure it ends in a '\'.
1233 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1234 pstrcat(fname, "/");
1240 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status);
1241 if (!NT_STATUS_IS_OK(status)) {
1242 return ERROR_NT(status);
1244 pstrcat(fname, tmpname);
1247 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1248 if (!NT_STATUS_IS_OK(status)) {
1249 return ERROR_NT(status);
1253 * Check to see if this is a mac fork of some kind.
1256 if( is_ntfs_stream_name(fname)) {
1257 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1261 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1262 if (oplock_request) {
1263 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1267 * Ordinary file or directory.
1271 * Check if POSIX semantics are wanted.
1274 new_file_attributes = set_posix_case_semantics(conn, file_attributes);
1276 if (!resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, fname)) {
1277 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
1280 status = unix_convert(conn, fname, False, NULL, &sbuf);
1281 if (!NT_STATUS_IS_OK(status)) {
1282 restore_case_semantics(conn, file_attributes);
1283 return ERROR_NT(status);
1285 /* All file access must go through check_name() */
1286 status = check_name(conn, fname);
1287 if (!NT_STATUS_IS_OK(status)) {
1288 restore_case_semantics(conn, file_attributes);
1289 return ERROR_NT(status);
1292 /* This is the correct thing to do (check every time) but can_delete is
1293 expensive (it may have to read the parent directory permissions). So
1294 for now we're not doing it unless we have a strong hint the client
1295 is really going to delete this file. If the client is forcing FILE_CREATE
1296 let the filesystem take care of the permissions. */
1298 /* Setting FILE_SHARE_DELETE is the hint. */
1300 if (lp_acl_check_permissions(SNUM(conn))
1301 && (create_disposition != FILE_CREATE)
1302 && (share_access & FILE_SHARE_DELETE)
1303 && (access_mask & DELETE_ACCESS)) {
1304 if ((dos_mode(conn, fname, &sbuf) & FILE_ATTRIBUTE_READONLY) ||
1305 !can_delete_file_in_directory(conn, fname)) {
1306 restore_case_semantics(conn, file_attributes);
1307 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1312 pdata = data + sd_len;
1314 /* We have already checked that ea_len <= data_count here. */
1315 ea_list = read_nttrans_ea_list(tmp_talloc_ctx(), pdata,
1318 restore_case_semantics(conn, file_attributes);
1319 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1324 * If it's a request for a directory open, deal with it separately.
1327 if(create_options & FILE_DIRECTORY_FILE) {
1329 /* Can't open a temp directory. IFS kit test. */
1330 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1331 restore_case_semantics(conn, file_attributes);
1332 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1336 * We will get a create directory here if the Win32
1337 * app specified a security descriptor in the
1338 * CreateDirectory() call.
1342 status = open_directory(conn, fname, &sbuf,
1347 new_file_attributes,
1349 if(!NT_STATUS_IS_OK(status)) {
1350 restore_case_semantics(conn, file_attributes);
1351 return ERROR_NT(status);
1357 * Ordinary file case.
1360 status = open_file_ntcreate(conn,fname,&sbuf,
1365 new_file_attributes,
1369 if (!NT_STATUS_IS_OK(status)) {
1370 if (NT_STATUS_EQUAL(status,
1371 NT_STATUS_FILE_IS_A_DIRECTORY)) {
1374 * Fail the open if it was explicitly a non-directory file.
1377 if (create_options & FILE_NON_DIRECTORY_FILE) {
1378 restore_case_semantics(conn, file_attributes);
1379 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1383 status = open_directory(conn, fname, &sbuf,
1388 new_file_attributes,
1390 if(!NT_STATUS_IS_OK(status)) {
1391 restore_case_semantics(conn, file_attributes);
1392 return ERROR_NT(status);
1395 restore_case_semantics(conn, file_attributes);
1396 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1397 /* We have re-scheduled this call. */
1400 return ERROR_NT(status);
1406 * According to the MS documentation, the only time the security
1407 * descriptor is applied to the opened file is iff we *created* the
1408 * file; an existing file stays the same.
1410 * Also, it seems (from observation) that you can open the file with
1411 * any access mask but you can still write the sd. We need to override
1412 * the granted access before we call set_sd
1413 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1416 if (lp_nt_acl_support(SNUM(conn)) && sd_len && info == FILE_WAS_CREATED) {
1417 uint32 saved_access_mask = fsp->access_mask;
1419 /* We have already checked that sd_len <= data_count here. */
1421 fsp->access_mask = FILE_GENERIC_ALL;
1423 status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION);
1424 if (!NT_STATUS_IS_OK(status)) {
1425 talloc_destroy(ctx);
1426 close_file(fsp,ERROR_CLOSE);
1427 restore_case_semantics(conn, file_attributes);
1428 return ERROR_NT(status);
1430 fsp->access_mask = saved_access_mask;
1433 if (ea_len && (info == FILE_WAS_CREATED)) {
1434 status = set_ea(conn, fsp, fname, ea_list);
1435 if (!NT_STATUS_IS_OK(status)) {
1436 close_file(fsp,ERROR_CLOSE);
1437 restore_case_semantics(conn, file_attributes);
1438 return ERROR_NT(status);
1442 restore_case_semantics(conn, file_attributes);
1444 file_len = sbuf.st_size;
1445 fattr = dos_mode(conn,fname,&sbuf);
1447 fattr = FILE_ATTRIBUTE_NORMAL;
1449 if (!fsp->is_directory && (fattr & aDIR)) {
1450 close_file(fsp,ERROR_CLOSE);
1451 return ERROR_DOS(ERRDOS,ERRnoaccess);
1454 /* Save the requested allocation size. */
1455 if ((info == FILE_WAS_CREATED) || (info == FILE_WAS_OVERWRITTEN)) {
1456 SMB_BIG_UINT allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1457 #ifdef LARGE_SMB_OFF_T
1458 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1460 if (allocation_size && (allocation_size > file_len)) {
1461 fsp->initial_allocation_size = smb_roundup(fsp->conn, allocation_size);
1462 if (fsp->is_directory) {
1463 close_file(fsp,ERROR_CLOSE);
1464 /* Can't set allocation size on a directory. */
1465 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1467 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1468 close_file(fsp,ERROR_CLOSE);
1469 return ERROR_NT(NT_STATUS_DISK_FULL);
1472 fsp->initial_allocation_size = smb_roundup(fsp->conn, (SMB_BIG_UINT)file_len);
1477 * If the caller set the extended oplock request bit
1478 * and we granted one (by whatever means) - set the
1479 * correct bit for extended oplock reply.
1482 if (oplock_request && lp_fake_oplocks(SNUM(conn))) {
1483 extended_oplock_granted = True;
1486 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type)) {
1487 extended_oplock_granted = True;
1490 /* Realloc the size of parameters and data we will return */
1491 params = nttrans_realloc(ppparams, 69);
1492 if(params == NULL) {
1493 return ERROR_DOS(ERRDOS,ERRnomem);
1497 if (extended_oplock_granted) {
1498 if (flags & REQUEST_BATCH_OPLOCK) {
1499 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1501 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
1503 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1504 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1506 SCVAL(p,0,NO_OPLOCK_RETURN);
1510 SSVAL(p,0,fsp->fnum);
1512 if ((create_disposition == FILE_SUPERSEDE) && (info == FILE_WAS_OVERWRITTEN)) {
1513 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1520 c_timespec = get_create_timespec(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1521 a_timespec = get_atimespec(&sbuf);
1522 m_timespec = get_mtimespec(&sbuf);
1524 if (lp_dos_filetime_resolution(SNUM(conn))) {
1525 dos_filetime_timespec(&c_timespec);
1526 dos_filetime_timespec(&a_timespec);
1527 dos_filetime_timespec(&m_timespec);
1530 put_long_date_timespec(p, c_timespec); /* create time. */
1532 put_long_date_timespec(p, a_timespec); /* access time */
1534 put_long_date_timespec(p, m_timespec); /* write time */
1536 put_long_date_timespec(p, m_timespec); /* change time */
1538 SIVAL(p,0,fattr); /* File Attributes. */
1540 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1542 SOFF_T(p,0,file_len);
1544 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1548 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1550 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1552 /* Send the required number of replies */
1553 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1558 /****************************************************************************
1559 Reply to a NT CANCEL request.
1560 conn POINTER CAN BE NULL HERE !
1561 ****************************************************************************/
1563 int reply_ntcancel(connection_struct *conn,
1564 char *inbuf,char *outbuf,int length,int bufsize)
1567 * Go through and cancel any pending change notifies.
1570 int mid = SVAL(inbuf,smb_mid);
1571 START_PROFILE(SMBntcancel);
1572 remove_pending_change_notify_requests_by_mid(mid);
1573 remove_pending_lock_requests_by_mid(mid);
1574 srv_cancel_sign_response(mid);
1576 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1578 END_PROFILE(SMBntcancel);
1582 /****************************************************************************
1584 ****************************************************************************/
1586 static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *newname, uint32 attrs)
1588 SMB_STRUCT_STAT sbuf1, sbuf2;
1589 pstring last_component_oldname;
1590 pstring last_component_newname;
1591 files_struct *fsp1,*fsp2;
1595 NTSTATUS status = NT_STATUS_OK;
1600 if (!CAN_WRITE(conn)) {
1601 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1604 status = unix_convert(conn, oldname, False, last_component_oldname, &sbuf1);
1605 if (!NT_STATUS_IS_OK(status)) {
1609 status = check_name(conn, oldname);
1610 if (!NT_STATUS_IS_OK(status)) {
1614 /* Source must already exist. */
1615 if (!VALID_STAT(sbuf1)) {
1616 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1618 /* Ensure attributes match. */
1619 fattr = dos_mode(conn,oldname,&sbuf1);
1620 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1621 return NT_STATUS_NO_SUCH_FILE;
1624 status = unix_convert(conn, newname, False, last_component_newname, &sbuf2);
1625 if (!NT_STATUS_IS_OK(status)) {
1629 status = check_name(conn, newname);
1630 if (!NT_STATUS_IS_OK(status)) {
1634 /* Disallow if newname already exists. */
1635 if (VALID_STAT(sbuf2)) {
1636 return NT_STATUS_OBJECT_NAME_COLLISION;
1639 /* No links from a directory. */
1640 if (S_ISDIR(sbuf1.st_mode)) {
1641 return NT_STATUS_FILE_IS_A_DIRECTORY;
1644 /* Ensure this is within the share. */
1645 status = reduce_name(conn, oldname);
1646 if (!NT_STATUS_IS_OK(status)) {
1650 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname, newname));
1652 status = open_file_ntcreate(conn,oldname,&sbuf1,
1653 FILE_READ_DATA, /* Read-only. */
1654 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1656 0, /* No create options. */
1657 FILE_ATTRIBUTE_NORMAL,
1661 if (!NT_STATUS_IS_OK(status)) {
1665 status = open_file_ntcreate(conn,newname,&sbuf2,
1666 FILE_WRITE_DATA, /* Read-only. */
1667 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1669 0, /* No create options. */
1674 if (!NT_STATUS_IS_OK(status)) {
1675 close_file(fsp1,ERROR_CLOSE);
1679 if (sbuf1.st_size) {
1680 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1684 * As we are opening fsp1 read-only we only expect
1685 * an error on close on fsp2 if we are out of space.
1686 * Thus we don't look at the error return from the
1689 close_file(fsp1,NORMAL_CLOSE);
1691 /* Ensure the modtime is set correctly on the destination file. */
1692 fsp_set_pending_modtime(fsp2, get_mtimespec(&sbuf1));
1694 status = close_file(fsp2,NORMAL_CLOSE);
1696 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1697 creates the file. This isn't the correct thing to do in the copy
1699 file_set_dosmode(conn, newname, fattr, &sbuf2,
1700 parent_dirname(newname));
1702 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1703 return NT_STATUS_DISK_FULL;
1706 if (!NT_STATUS_IS_OK(status)) {
1707 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1708 nt_errstr(status), oldname, newname));
1713 /****************************************************************************
1714 Reply to a NT rename request.
1715 ****************************************************************************/
1717 int reply_ntrename(connection_struct *conn,
1718 char *inbuf,char *outbuf,int length,int bufsize)
1725 BOOL src_has_wcard = False;
1726 BOOL dest_has_wcard = False;
1727 uint32 attrs = SVAL(inbuf,smb_vwv0);
1728 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1730 START_PROFILE(SMBntrename);
1732 p = smb_buf(inbuf) + 1;
1733 p += srvstr_get_path_wcard(inbuf, oldname, p, sizeof(oldname), 0, STR_TERMINATE, &status, &src_has_wcard);
1734 if (!NT_STATUS_IS_OK(status)) {
1735 END_PROFILE(SMBntrename);
1736 return ERROR_NT(status);
1739 if( is_ntfs_stream_name(oldname)) {
1740 /* Can't rename a stream. */
1741 END_PROFILE(SMBntrename);
1742 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1745 if (ms_has_wild(oldname)) {
1746 END_PROFILE(SMBntrename);
1747 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1751 p += srvstr_get_path_wcard(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status, &dest_has_wcard);
1752 if (!NT_STATUS_IS_OK(status)) {
1753 END_PROFILE(SMBntrename);
1754 return ERROR_NT(status);
1757 if (!resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, oldname)) {
1758 END_PROFILE(SMBntrename);
1759 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
1761 if (!resolve_dfspath(conn, SVAL(inbuf,smb_flg2) & FLAGS2_DFS_PATHNAMES, newname)) {
1762 END_PROFILE(SMBntrename);
1763 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED, ERRSRV, ERRbadpath);
1766 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1768 switch(rename_type) {
1769 case RENAME_FLAG_RENAME:
1770 status = rename_internals(conn, oldname, newname, attrs, False, src_has_wcard, dest_has_wcard);
1772 case RENAME_FLAG_HARD_LINK:
1773 if (src_has_wcard || dest_has_wcard) {
1775 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1777 status = hardlink_internals(conn, oldname, newname);
1780 case RENAME_FLAG_COPY:
1781 if (src_has_wcard || dest_has_wcard) {
1783 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1785 status = copy_internals(conn, oldname, newname, attrs);
1788 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1789 status = NT_STATUS_INVALID_PARAMETER;
1792 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1796 if (!NT_STATUS_IS_OK(status)) {
1797 END_PROFILE(SMBntrename);
1798 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1799 /* We have re-scheduled this call. */
1802 return ERROR_NT(status);
1805 outsize = set_message(outbuf,0,0,False);
1807 END_PROFILE(SMBntrename);
1811 /****************************************************************************
1812 Reply to a notify change - queue the request and
1813 don't allow a directory to be opened.
1814 ****************************************************************************/
1816 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf,
1817 char *outbuf, int length,
1819 uint16 **ppsetup, uint32 setup_count,
1821 uint32 parameter_count,
1822 char **ppdata, uint32 data_count,
1823 uint32 max_data_count,
1824 uint32 max_param_count)
1826 uint16 *setup = *ppsetup;
1832 if(setup_count < 6) {
1833 return ERROR_DOS(ERRDOS,ERRbadfunc);
1836 fsp = file_fsp((char *)setup,4);
1837 filter = IVAL(setup, 0);
1838 recursive = (SVAL(setup, 6) != 0) ? True : False;
1840 DEBUG(3,("call_nt_transact_notify_change\n"));
1843 return ERROR_DOS(ERRDOS,ERRbadfid);
1847 char *filter_string;
1849 if (!(filter_string = notify_filter_string(NULL, filter))) {
1850 return ERROR_NT(NT_STATUS_NO_MEMORY);
1853 DEBUG(3,("call_nt_transact_notify_change: notify change "
1854 "called on %s, filter = %s, recursive = %d\n",
1855 fsp->fsp_name, filter_string, recursive));
1857 TALLOC_FREE(filter_string);
1860 if((!fsp->is_directory) || (conn != fsp->conn)) {
1861 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1864 if (fsp->notify == NULL) {
1866 status = change_notify_create(fsp, filter, recursive);
1868 if (!NT_STATUS_IS_OK(status)) {
1869 DEBUG(10, ("change_notify_create returned %s\n",
1870 nt_errstr(status)));
1871 return ERROR_NT(status);
1875 if (fsp->notify->num_changes != 0) {
1878 * We've got changes pending, respond immediately
1882 * TODO: write a torture test to check the filtering behaviour
1886 change_notify_reply(inbuf, max_param_count,
1890 * change_notify_reply() above has independently sent its
1897 * No changes pending, queue the request
1900 status = change_notify_add_request(inbuf, max_param_count, filter,
1902 if (!NT_STATUS_IS_OK(status)) {
1903 return ERROR_NT(status);
1909 /****************************************************************************
1910 Reply to an NT transact rename command.
1911 ****************************************************************************/
1913 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1914 uint16 **ppsetup, uint32 setup_count,
1915 char **ppparams, uint32 parameter_count,
1916 char **ppdata, uint32 data_count, uint32 max_data_count)
1918 char *params = *ppparams;
1920 files_struct *fsp = NULL;
1921 BOOL replace_if_exists = False;
1922 BOOL dest_has_wcard = False;
1925 if(parameter_count < 5) {
1926 return ERROR_DOS(ERRDOS,ERRbadfunc);
1929 fsp = file_fsp(params, 0);
1930 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1931 CHECK_FSP(fsp, conn);
1932 srvstr_get_path_wcard(inbuf, new_name, params+4, sizeof(new_name), parameter_count - 4,
1933 STR_TERMINATE, &status, &dest_has_wcard);
1934 if (!NT_STATUS_IS_OK(status)) {
1935 return ERROR_NT(status);
1938 status = rename_internals(conn, fsp->fsp_name,
1939 new_name, 0, replace_if_exists, False, dest_has_wcard);
1941 if (!NT_STATUS_IS_OK(status)) {
1942 if (open_was_deferred(SVAL(inbuf,smb_mid))) {
1943 /* We have re-scheduled this call. */
1946 return ERROR_NT(status);
1950 * Rename was successful.
1952 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1954 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1955 fsp->fsp_name, new_name));
1960 /******************************************************************************
1961 Fake up a completely empty SD.
1962 *******************************************************************************/
1964 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1968 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1970 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1977 /****************************************************************************
1978 Reply to query a security descriptor.
1979 ****************************************************************************/
1981 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1982 uint16 **ppsetup, uint32 setup_count,
1983 char **ppparams, uint32 parameter_count,
1984 char **ppdata, uint32 data_count, uint32 max_data_count)
1986 char *params = *ppparams;
1987 char *data = *ppdata;
1989 SEC_DESC *psd = NULL;
1991 uint32 security_info_wanted;
1992 TALLOC_CTX *mem_ctx;
1993 files_struct *fsp = NULL;
1995 if(parameter_count < 8) {
1996 return ERROR_DOS(ERRDOS,ERRbadfunc);
1999 fsp = file_fsp(params,0);
2001 return ERROR_DOS(ERRDOS,ERRbadfid);
2004 security_info_wanted = IVAL(params,4);
2006 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
2007 (unsigned int)security_info_wanted ));
2009 params = nttrans_realloc(ppparams, 4);
2010 if(params == NULL) {
2011 return ERROR_DOS(ERRDOS,ERRnomem);
2014 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
2015 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
2016 return ERROR_DOS(ERRDOS,ERRnomem);
2020 * Get the permissions to return.
2023 if (!lp_nt_acl_support(SNUM(conn))) {
2024 sd_size = get_null_nt_acl(mem_ctx, &psd);
2026 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fh->fd, security_info_wanted, &psd);
2030 talloc_destroy(mem_ctx);
2031 return(UNIXERROR(ERRDOS,ERRnoaccess));
2034 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
2036 SIVAL(params,0,(uint32)sd_size);
2038 if(max_data_count < sd_size) {
2040 send_nt_replies(outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
2041 params, 4, *ppdata, 0);
2042 talloc_destroy(mem_ctx);
2047 * Allocate the data we will point this at.
2050 data = nttrans_realloc(ppdata, sd_size);
2052 talloc_destroy(mem_ctx);
2053 return ERROR_DOS(ERRDOS,ERRnomem);
2057 * Init the parse struct we will marshall into.
2060 prs_init(&pd, 0, mem_ctx, MARSHALL);
2063 * Setup the prs_struct to point at the memory we just
2067 prs_give_memory( &pd, data, (uint32)sd_size, False);
2070 * Finally, linearize into the outgoing buffer.
2073 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
2074 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2075 security descriptor.\n"));
2077 * Return access denied for want of a better error message..
2079 talloc_destroy(mem_ctx);
2080 return(UNIXERROR(ERRDOS,ERRnoaccess));
2084 * Now we can delete the security descriptor.
2087 talloc_destroy(mem_ctx);
2089 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, 4, data,
2094 /****************************************************************************
2095 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2096 ****************************************************************************/
2098 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2099 uint16 **ppsetup, uint32 setup_count,
2100 char **ppparams, uint32 parameter_count,
2101 char **ppdata, uint32 data_count, uint32 max_data_count)
2103 char *params= *ppparams;
2104 char *data = *ppdata;
2105 files_struct *fsp = NULL;
2106 uint32 security_info_sent = 0;
2109 if(parameter_count < 8) {
2110 return ERROR_DOS(ERRDOS,ERRbadfunc);
2113 if((fsp = file_fsp(params,0)) == NULL) {
2114 return ERROR_DOS(ERRDOS,ERRbadfid);
2117 if(!lp_nt_acl_support(SNUM(conn))) {
2121 security_info_sent = IVAL(params,4);
2123 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
2124 (unsigned int)security_info_sent ));
2126 if (data_count == 0) {
2127 return ERROR_DOS(ERRDOS, ERRnoaccess);
2130 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent))) {
2131 return ERROR_NT(nt_status);
2136 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2140 /****************************************************************************
2142 ****************************************************************************/
2144 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2145 uint16 **ppsetup, uint32 setup_count,
2146 char **ppparams, uint32 parameter_count,
2147 char **ppdata, uint32 data_count, uint32 max_data_count)
2154 static BOOL logged_message;
2155 char *pdata = *ppdata;
2157 if (setup_count != 8) {
2158 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2159 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2162 function = IVAL(*ppsetup, 0);
2163 fidnum = SVAL(*ppsetup, 4);
2164 isFSctl = CVAL(*ppsetup, 6);
2165 compfilter = CVAL(*ppsetup, 7);
2167 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2168 function, fidnum, isFSctl, compfilter));
2170 fsp=file_fsp((char *)*ppsetup, 4);
2171 /* this check is done in each implemented function case for now
2172 because I don't want to break anything... --metze
2173 FSP_BELONGS_CONN(fsp,conn);*/
2176 case FSCTL_SET_SPARSE:
2177 /* pretend this succeeded - tho strictly we should
2178 mark the file sparse (if the local fs supports it)
2179 so we can know if we need to pre-allocate or not */
2181 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
2182 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL,
2186 case FSCTL_0x000900C0:
2187 /* pretend this succeeded - don't know what this really is
2188 but works ok like this --metze
2191 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
2192 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL,
2196 case FSCTL_GET_REPARSE_POINT:
2197 /* pretend this fail - my winXP does it like this
2201 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2202 send_nt_replies(outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT,
2206 case FSCTL_SET_REPARSE_POINT:
2207 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2211 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
2212 send_nt_replies(outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT,
2216 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
2219 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2220 * and return their volume names. If max_data_count is 16, then it is just
2221 * asking for the number of volumes and length of the combined names.
2223 * pdata is the data allocated by our caller, but that uses
2224 * total_data_count (which is 0 in our case) rather than max_data_count.
2225 * Allocate the correct amount and return the pointer to let
2226 * it be deallocated when we return.
2228 SHADOW_COPY_DATA *shadow_data = NULL;
2229 TALLOC_CTX *shadow_mem_ctx = NULL;
2230 BOOL labels = False;
2231 uint32 labels_data_count = 0;
2235 FSP_BELONGS_CONN(fsp,conn);
2237 if (max_data_count < 16) {
2238 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2240 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
2243 if (max_data_count > 16) {
2247 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2248 if (shadow_mem_ctx == NULL) {
2249 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2250 return ERROR_NT(NT_STATUS_NO_MEMORY);
2253 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2254 if (shadow_data == NULL) {
2255 DEBUG(0,("talloc_zero() failed!\n"));
2256 talloc_destroy(shadow_mem_ctx);
2257 return ERROR_NT(NT_STATUS_NO_MEMORY);
2260 shadow_data->mem_ctx = shadow_mem_ctx;
2263 * Call the VFS routine to actually do the work.
2265 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2266 talloc_destroy(shadow_data->mem_ctx);
2267 if (errno == ENOSYS) {
2268 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2269 conn->connectpath));
2270 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2272 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2273 conn->connectpath));
2274 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
2278 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2283 data_count = 12+labels_data_count+4;
2286 if (max_data_count<data_count) {
2287 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2288 max_data_count,data_count));
2289 talloc_destroy(shadow_data->mem_ctx);
2290 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
2293 pdata = nttrans_realloc(ppdata, data_count);
2294 if (pdata == NULL) {
2295 talloc_destroy(shadow_data->mem_ctx);
2296 return ERROR_NT(NT_STATUS_NO_MEMORY);
2301 /* num_volumes 4 bytes */
2302 SIVAL(pdata,0,shadow_data->num_volumes);
2305 /* num_labels 4 bytes */
2306 SIVAL(pdata,4,shadow_data->num_volumes);
2309 /* needed_data_count 4 bytes */
2310 SIVAL(pdata,8,labels_data_count);
2314 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2315 shadow_data->num_volumes,fsp->fsp_name));
2316 if (labels && shadow_data->labels) {
2317 for (i=0;i<shadow_data->num_volumes;i++) {
2318 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2319 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2320 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2324 talloc_destroy(shadow_data->mem_ctx);
2326 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0,
2332 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2334 /* pretend this succeeded -
2336 * we have to send back a list with all files owned by this SID
2338 * but I have to check that --metze
2342 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2344 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2346 FSP_BELONGS_CONN(fsp,conn);
2348 /* unknown 4 bytes: this is not the length of the sid :-( */
2349 /*unknown = IVAL(pdata,0);*/
2351 sid_parse(pdata+4,sid_len,&sid);
2352 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2354 if (!sid_to_uid(&sid, &uid)) {
2355 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2356 sid_string_static(&sid),(unsigned long)sid_len));
2360 /* we can take a look at the find source :-)
2362 * find ./ -uid $uid -name '*' is what we need here
2365 * and send 4bytes len and then NULL terminated unicode strings
2368 * but I don't know how to deal with the paged results
2369 * (maybe we can hang the result anywhere in the fsp struct)
2371 * we don't send all files at once
2372 * and at the next we should *not* start from the beginning,
2373 * so we have to cache the result
2378 /* this works for now... */
2379 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, NULL, 0,
2384 if (!logged_message) {
2385 logged_message = True; /* Only print this once... */
2386 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2391 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2395 #ifdef HAVE_SYS_QUOTAS
2396 /****************************************************************************
2397 Reply to get user quota
2398 ****************************************************************************/
2400 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2401 uint16 **ppsetup, uint32 setup_count,
2402 char **ppparams, uint32 parameter_count,
2403 char **ppdata, uint32 data_count, uint32 max_data_count)
2405 NTSTATUS nt_status = NT_STATUS_OK;
2406 char *params = *ppparams;
2407 char *pdata = *ppdata;
2409 int data_len=0,param_len=0;
2412 files_struct *fsp = NULL;
2416 BOOL start_enum = True;
2417 SMB_NTQUOTA_STRUCT qt;
2418 SMB_NTQUOTA_LIST *tmp_list;
2419 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2424 if (current_user.ut.uid != 0) {
2425 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2426 lp_servicename(SNUM(conn)),conn->user));
2427 return ERROR_DOS(ERRDOS,ERRnoaccess);
2431 * Ensure minimum number of parameters sent.
2434 if (parameter_count < 4) {
2435 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2436 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2439 /* maybe we can check the quota_fnum */
2440 fsp = file_fsp(params,0);
2441 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2442 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2443 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2446 /* the NULL pointer checking for fsp->fake_file_handle->pd
2447 * is done by CHECK_NTQUOTA_HANDLE_OK()
2449 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2451 level = SVAL(params,2);
2453 /* unknown 12 bytes leading in params */
2456 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2457 /* seems that we should continue with the enum here --metze */
2459 if (qt_handle->quota_list!=NULL &&
2460 qt_handle->tmp_list==NULL) {
2463 free_ntquota_list(&(qt_handle->quota_list));
2465 /* Realloc the size of parameters and data we will return */
2467 params = nttrans_realloc(ppparams, param_len);
2468 if(params == NULL) {
2469 return ERROR_DOS(ERRDOS,ERRnomem);
2473 SIVAL(params,0,data_len);
2480 case TRANSACT_GET_USER_QUOTA_LIST_START:
2482 if (qt_handle->quota_list==NULL &&
2483 qt_handle->tmp_list==NULL) {
2487 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2488 return ERROR_DOS(ERRSRV,ERRerror);
2490 /* Realloc the size of parameters and data we will return */
2492 params = nttrans_realloc(ppparams, param_len);
2493 if(params == NULL) {
2494 return ERROR_DOS(ERRDOS,ERRnomem);
2497 /* we should not trust the value in max_data_count*/
2498 max_data_count = MIN(max_data_count,2048);
2500 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2502 return ERROR_DOS(ERRDOS,ERRnomem);
2507 /* set params Size of returned Quota Data 4 bytes*/
2508 /* but set it later when we know it */
2510 /* for each entry push the data */
2513 qt_handle->tmp_list = qt_handle->quota_list;
2516 tmp_list = qt_handle->tmp_list;
2518 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2519 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2521 sid_len = sid_size(&tmp_list->quotas->sid);
2522 entry_len = 40 + sid_len;
2524 /* nextoffset entry 4 bytes */
2525 SIVAL(entry,0,entry_len);
2527 /* then the len of the SID 4 bytes */
2528 SIVAL(entry,4,sid_len);
2530 /* unknown data 8 bytes SMB_BIG_UINT */
2531 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2533 /* the used disk space 8 bytes SMB_BIG_UINT */
2534 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2536 /* the soft quotas 8 bytes SMB_BIG_UINT */
2537 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2539 /* the hard quotas 8 bytes SMB_BIG_UINT */
2540 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2542 /* and now the SID */
2543 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2546 qt_handle->tmp_list = tmp_list;
2548 /* overwrite the offset of the last entry */
2549 SIVAL(entry-entry_len,0,0);
2551 data_len = 4+qt_len;
2552 /* overwrite the params quota_data_len */
2553 SIVAL(params,0,data_len);
2557 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2559 /* unknown 4 bytes IVAL(pdata,0) */
2561 if (data_count < 8) {
2562 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2563 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2566 sid_len = IVAL(pdata,4);
2567 /* Ensure this is less than 1mb. */
2568 if (sid_len > (1024*1024)) {
2569 return ERROR_DOS(ERRDOS,ERRnomem);
2572 if (data_count < 8+sid_len) {
2573 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2574 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2577 data_len = 4+40+sid_len;
2579 if (max_data_count < data_len) {
2580 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2581 max_data_count, data_len));
2583 SIVAL(params,0,data_len);
2585 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2589 sid_parse(pdata+8,sid_len,&sid);
2591 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2594 * we have to return zero's in all fields
2595 * instead of returning an error here
2600 /* Realloc the size of parameters and data we will return */
2602 params = nttrans_realloc(ppparams, param_len);
2603 if(params == NULL) {
2604 return ERROR_DOS(ERRDOS,ERRnomem);
2607 pdata = nttrans_realloc(ppdata, data_len);
2609 return ERROR_DOS(ERRDOS,ERRnomem);
2614 /* set params Size of returned Quota Data 4 bytes*/
2615 SIVAL(params,0,data_len);
2617 /* nextoffset entry 4 bytes */
2620 /* then the len of the SID 4 bytes */
2621 SIVAL(entry,4,sid_len);
2623 /* unknown data 8 bytes SMB_BIG_UINT */
2624 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2626 /* the used disk space 8 bytes SMB_BIG_UINT */
2627 SBIG_UINT(entry,16,qt.usedspace);
2629 /* the soft quotas 8 bytes SMB_BIG_UINT */
2630 SBIG_UINT(entry,24,qt.softlim);
2632 /* the hard quotas 8 bytes SMB_BIG_UINT */
2633 SBIG_UINT(entry,32,qt.hardlim);
2635 /* and now the SID */
2636 sid_linearize(entry+40, sid_len, &sid);
2641 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2642 return ERROR_DOS(ERRSRV,ERRerror);
2646 send_nt_replies(outbuf, bufsize, nt_status, params, param_len,
2652 /****************************************************************************
2653 Reply to set user quota
2654 ****************************************************************************/
2656 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2657 uint16 **ppsetup, uint32 setup_count,
2658 char **ppparams, uint32 parameter_count,
2659 char **ppdata, uint32 data_count, uint32 max_data_count)
2661 char *params = *ppparams;
2662 char *pdata = *ppdata;
2663 int data_len=0,param_len=0;
2664 SMB_NTQUOTA_STRUCT qt;
2667 files_struct *fsp = NULL;
2672 if (current_user.ut.uid != 0) {
2673 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2674 lp_servicename(SNUM(conn)),conn->user));
2675 return ERROR_DOS(ERRDOS,ERRnoaccess);
2679 * Ensure minimum number of parameters sent.
2682 if (parameter_count < 2) {
2683 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2684 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2687 /* maybe we can check the quota_fnum */
2688 fsp = file_fsp(params,0);
2689 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2690 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2691 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2694 if (data_count < 40) {
2695 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2696 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2699 /* offset to next quota record.
2700 * 4 bytes IVAL(pdata,0)
2705 sid_len = IVAL(pdata,4);
2707 if (data_count < 40+sid_len) {
2708 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2709 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2712 /* unknown 8 bytes in pdata
2713 * maybe its the change time in NTTIME
2716 /* the used space 8 bytes (SMB_BIG_UINT)*/
2717 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2718 #ifdef LARGE_SMB_OFF_T
2719 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2720 #else /* LARGE_SMB_OFF_T */
2721 if ((IVAL(pdata,20) != 0)&&
2722 ((qt.usedspace != 0xFFFFFFFF)||
2723 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2724 /* more than 32 bits? */
2725 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2727 #endif /* LARGE_SMB_OFF_T */
2729 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2730 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2731 #ifdef LARGE_SMB_OFF_T
2732 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2733 #else /* LARGE_SMB_OFF_T */
2734 if ((IVAL(pdata,28) != 0)&&
2735 ((qt.softlim != 0xFFFFFFFF)||
2736 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2737 /* more than 32 bits? */
2738 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2740 #endif /* LARGE_SMB_OFF_T */
2742 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2743 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2744 #ifdef LARGE_SMB_OFF_T
2745 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2746 #else /* LARGE_SMB_OFF_T */
2747 if ((IVAL(pdata,36) != 0)&&
2748 ((qt.hardlim != 0xFFFFFFFF)||
2749 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2750 /* more than 32 bits? */
2751 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2753 #endif /* LARGE_SMB_OFF_T */
2755 sid_parse(pdata+40,sid_len,&sid);
2756 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2758 /* 44 unknown bytes left... */
2760 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2761 return ERROR_DOS(ERRSRV,ERRerror);
2764 send_nt_replies(outbuf, bufsize, NT_STATUS_OK, params, param_len,
2769 #endif /* HAVE_SYS_QUOTAS */
2771 static int handle_nttrans(connection_struct *conn,
2772 struct trans_state *state,
2773 char *inbuf, char *outbuf, int size, int bufsize)
2777 if (Protocol >= PROTOCOL_NT1) {
2778 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | 0x40); /* IS_LONG_NAME */
2781 /* Now we must call the relevant NT_TRANS function */
2782 switch(state->call) {
2783 case NT_TRANSACT_CREATE:
2785 START_PROFILE(NT_transact_create);
2786 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2788 &state->setup, state->setup_count,
2789 &state->param, state->total_param,
2790 &state->data, state->total_data,
2791 state->max_data_return);
2792 END_PROFILE(NT_transact_create);
2796 case NT_TRANSACT_IOCTL:
2798 START_PROFILE(NT_transact_ioctl);
2799 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2801 &state->setup, state->setup_count,
2802 &state->param, state->total_param,
2803 &state->data, state->total_data, state->max_data_return);
2804 END_PROFILE(NT_transact_ioctl);
2808 case NT_TRANSACT_SET_SECURITY_DESC:
2810 START_PROFILE(NT_transact_set_security_desc);
2811 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2813 &state->setup, state->setup_count,
2814 &state->param, state->total_param,
2815 &state->data, state->total_data, state->max_data_return);
2816 END_PROFILE(NT_transact_set_security_desc);
2820 case NT_TRANSACT_NOTIFY_CHANGE:
2822 START_PROFILE(NT_transact_notify_change);
2823 outsize = call_nt_transact_notify_change(
2824 conn, inbuf, outbuf, size, bufsize,
2825 &state->setup, state->setup_count,
2826 &state->param, state->total_param,
2827 &state->data, state->total_data,
2828 state->max_data_return,
2829 state->max_param_return);
2830 END_PROFILE(NT_transact_notify_change);
2834 case NT_TRANSACT_RENAME:
2836 START_PROFILE(NT_transact_rename);
2837 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2839 &state->setup, state->setup_count,
2840 &state->param, state->total_param,
2841 &state->data, state->total_data, state->max_data_return);
2842 END_PROFILE(NT_transact_rename);
2846 case NT_TRANSACT_QUERY_SECURITY_DESC:
2848 START_PROFILE(NT_transact_query_security_desc);
2849 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
2851 &state->setup, state->setup_count,
2852 &state->param, state->total_param,
2853 &state->data, state->total_data, state->max_data_return);
2854 END_PROFILE(NT_transact_query_security_desc);
2858 #ifdef HAVE_SYS_QUOTAS
2859 case NT_TRANSACT_GET_USER_QUOTA:
2861 START_PROFILE(NT_transact_get_user_quota);
2862 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
2864 &state->setup, state->setup_count,
2865 &state->param, state->total_param,
2866 &state->data, state->total_data, state->max_data_return);
2867 END_PROFILE(NT_transact_get_user_quota);
2871 case NT_TRANSACT_SET_USER_QUOTA:
2873 START_PROFILE(NT_transact_set_user_quota);
2874 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
2876 &state->setup, state->setup_count,
2877 &state->param, state->total_param,
2878 &state->data, state->total_data, state->max_data_return);
2879 END_PROFILE(NT_transact_set_user_quota);
2882 #endif /* HAVE_SYS_QUOTAS */
2885 /* Error in request */
2886 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n",
2888 return ERROR_DOS(ERRSRV,ERRerror);
2893 /****************************************************************************
2894 Reply to a SMBNTtrans.
2895 ****************************************************************************/
2897 int reply_nttrans(connection_struct *conn,
2898 char *inbuf,char *outbuf,int size,int bufsize)
2901 uint32 pscnt = IVAL(inbuf,smb_nt_ParameterCount);
2902 uint32 psoff = IVAL(inbuf,smb_nt_ParameterOffset);
2903 uint32 dscnt = IVAL(inbuf,smb_nt_DataCount);
2904 uint32 dsoff = IVAL(inbuf,smb_nt_DataOffset);
2906 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2908 struct trans_state *state;
2910 START_PROFILE(SMBnttrans);
2912 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2913 END_PROFILE(SMBnttrans);
2914 return ERROR_DOS(ERRSRV,ERRaccess);
2917 result = allow_new_trans(conn->pending_trans, SVAL(inbuf, smb_mid));
2918 if (!NT_STATUS_IS_OK(result)) {
2919 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2920 END_PROFILE(SMBnttrans);
2921 return ERROR_NT(result);
2924 if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
2925 END_PROFILE(SMBnttrans);
2926 return ERROR_DOS(ERRSRV,ERRaccess);
2929 state->cmd = SMBnttrans;
2931 state->mid = SVAL(inbuf,smb_mid);
2932 state->vuid = SVAL(inbuf,smb_uid);
2933 state->total_data = IVAL(inbuf, smb_nt_TotalDataCount);
2935 state->total_param = IVAL(inbuf, smb_nt_TotalParameterCount);
2936 state->param = NULL;
2937 state->max_data_return = IVAL(inbuf,smb_nt_MaxDataCount);
2938 state->max_param_return = IVAL(inbuf,smb_nt_MaxParameterCount);
2940 /* setup count is in *words* */
2941 state->setup_count = 2*CVAL(inbuf,smb_nt_SetupCount);
2942 state->setup = NULL;
2943 state->call = function_code;
2946 * All nttrans messages we handle have smb_wct == 19 +
2947 * state->setup_count. Ensure this is so as a sanity check.
2950 if(CVAL(inbuf, smb_wct) != 19 + (state->setup_count/2)) {
2951 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2952 CVAL(inbuf, smb_wct), 19 + (state->setup_count/2)));
2956 /* Don't allow more than 128mb for each value. */
2957 if ((state->total_data > (1024*1024*128)) ||
2958 (state->total_param > (1024*1024*128))) {
2959 END_PROFILE(SMBnttrans);
2960 return ERROR_DOS(ERRDOS,ERRnomem);
2963 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2966 if (state->total_data) {
2967 /* Can't use talloc here, the core routines do realloc on the
2968 * params and data. */
2969 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2970 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2971 "bytes !\n", (unsigned int)state->total_data));
2973 END_PROFILE(SMBnttrans);
2974 return(ERROR_DOS(ERRDOS,ERRnomem));
2976 if ((dsoff+dscnt < dsoff) || (dsoff+dscnt < dscnt))
2978 if ((smb_base(inbuf)+dsoff+dscnt > inbuf + size) ||
2979 (smb_base(inbuf)+dsoff+dscnt < smb_base(inbuf)))
2982 memcpy(state->data,smb_base(inbuf)+dsoff,dscnt);
2985 if (state->total_param) {
2986 /* Can't use talloc here, the core routines do realloc on the
2987 * params and data. */
2988 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2989 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2990 "bytes !\n", (unsigned int)state->total_param));
2991 SAFE_FREE(state->data);
2993 END_PROFILE(SMBnttrans);
2994 return(ERROR_DOS(ERRDOS,ERRnomem));
2996 if ((psoff+pscnt < psoff) || (psoff+pscnt < pscnt))
2998 if ((smb_base(inbuf)+psoff+pscnt > inbuf + size) ||
2999 (smb_base(inbuf)+psoff+pscnt < smb_base(inbuf)))
3002 memcpy(state->param,smb_base(inbuf)+psoff,pscnt);
3005 state->received_data = dscnt;
3006 state->received_param = pscnt;
3008 if(state->setup_count > 0) {
3009 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
3010 state->setup_count));
3011 state->setup = (uint16 *)TALLOC(state, state->setup_count);
3012 if (state->setup == NULL) {
3013 DEBUG(0,("reply_nttrans : Out of memory\n"));
3014 SAFE_FREE(state->data);
3015 SAFE_FREE(state->param);
3017 END_PROFILE(SMBnttrans);
3018 return ERROR_DOS(ERRDOS,ERRnomem);
3021 if ((smb_nt_SetupStart + state->setup_count < smb_nt_SetupStart) ||
3022 (smb_nt_SetupStart + state->setup_count < state->setup_count)) {
3025 if (smb_nt_SetupStart + state->setup_count > size) {
3029 memcpy( state->setup, &inbuf[smb_nt_SetupStart], state->setup_count);
3030 dump_data(10, (char *)state->setup, state->setup_count);
3033 if ((state->received_data == state->total_data) &&
3034 (state->received_param == state->total_param)) {
3035 outsize = handle_nttrans(conn, state, inbuf, outbuf,
3037 SAFE_FREE(state->param);
3038 SAFE_FREE(state->data);
3040 END_PROFILE(SMBnttrans);
3044 DLIST_ADD(conn->pending_trans, state);
3046 /* We need to send an interim response then receive the rest
3047 of the parameter/data bytes */
3048 outsize = set_message(outbuf,0,0,False);
3050 END_PROFILE(SMBnttrans);
3055 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3056 SAFE_FREE(state->data);
3057 SAFE_FREE(state->param);
3059 END_PROFILE(SMBnttrans);
3060 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
3063 /****************************************************************************
3064 Reply to a SMBnttranss
3065 ****************************************************************************/
3067 int reply_nttranss(connection_struct *conn, char *inbuf,char *outbuf,
3068 int size,int bufsize)
3071 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
3072 struct trans_state *state;
3074 START_PROFILE(SMBnttranss);
3078 for (state = conn->pending_trans; state != NULL;
3079 state = state->next) {
3080 if (state->mid == SVAL(inbuf,smb_mid)) {
3085 if ((state == NULL) || (state->cmd != SMBnttrans)) {
3086 END_PROFILE(SMBnttranss);
3087 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
3090 /* Revise state->total_param and state->total_data in case they have
3091 changed downwards */
3092 if (IVAL(inbuf, smb_nts_TotalParameterCount) < state->total_param) {
3093 state->total_param = IVAL(inbuf, smb_nts_TotalParameterCount);
3095 if (IVAL(inbuf, smb_nts_TotalDataCount) < state->total_data) {
3096 state->total_data = IVAL(inbuf, smb_nts_TotalDataCount);
3099 pcnt = IVAL(inbuf,smb_nts_ParameterCount);
3100 poff = IVAL(inbuf, smb_nts_ParameterOffset);
3101 pdisp = IVAL(inbuf, smb_nts_ParameterDisplacement);
3103 dcnt = IVAL(inbuf, smb_nts_DataCount);
3104 ddisp = IVAL(inbuf, smb_nts_DataDisplacement);
3105 doff = IVAL(inbuf, smb_nts_DataOffset);
3107 state->received_param += pcnt;
3108 state->received_data += dcnt;
3110 if ((state->received_data > state->total_data) ||
3111 (state->received_param > state->total_param))
3115 if (pdisp+pcnt > state->total_param)
3117 if ((pdisp+pcnt < pdisp) || (pdisp+pcnt < pcnt))
3119 if (pdisp > state->total_param)
3121 if ((smb_base(inbuf) + poff + pcnt > inbuf + size) ||
3122 (smb_base(inbuf) + poff + pcnt < smb_base(inbuf)))
3124 if (state->param + pdisp < state->param)
3127 memcpy(state->param+pdisp,smb_base(inbuf)+poff,
3132 if (ddisp+dcnt > state->total_data)
3134 if ((ddisp+dcnt < ddisp) || (ddisp+dcnt < dcnt))
3136 if (ddisp > state->total_data)
3138 if ((smb_base(inbuf) + doff + dcnt > inbuf + size) ||
3139 (smb_base(inbuf) + doff + dcnt < smb_base(inbuf)))
3141 if (state->data + ddisp < state->data)
3144 memcpy(state->data+ddisp, smb_base(inbuf)+doff,
3148 if ((state->received_param < state->total_param) ||
3149 (state->received_data < state->total_data)) {
3150 END_PROFILE(SMBnttranss);
3154 /* construct_reply_common has done us the favor to pre-fill the
3155 * command field with SMBnttranss which is wrong :-)
3157 SCVAL(outbuf,smb_com,SMBnttrans);
3159 outsize = handle_nttrans(conn, state, inbuf, outbuf,
3162 DLIST_REMOVE(conn->pending_trans, state);
3163 SAFE_FREE(state->data);
3164 SAFE_FREE(state->param);
3168 END_PROFILE(SMBnttranss);
3169 return(ERROR_DOS(ERRSRV,ERRnosupport));
3172 END_PROFILE(SMBnttranss);
3177 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3178 DLIST_REMOVE(conn->pending_trans, state);
3179 SAFE_FREE(state->data);
3180 SAFE_FREE(state->param);
3182 END_PROFILE(SMBnttranss);
3183 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);