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");
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(const char *inbuf
,
80 int data_to_send
= datasize
;
81 int params_to_send
= paramsize
;
85 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
86 int alignment_offset
= 3;
87 int data_alignment_offset
= 0;
90 * Initially set the wcnt area to be 18 - this is true for all
94 set_message(inbuf
,outbuf
,18,0,True
);
96 if (NT_STATUS_V(nt_error
)) {
101 * If there genuinely are no parameters or data to send just send
105 if(params_to_send
== 0 && data_to_send
== 0) {
107 if (!send_smb(smbd_server_fd(),outbuf
)) {
108 exit_server_cleanly("send_nt_replies: send_smb failed.");
114 * When sending params and data ensure that both are nicely aligned.
115 * Only do this alignment when there is also data to send - else
116 * can cause NT redirector problems.
119 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
120 data_alignment_offset
= 4 - (params_to_send
% 4);
124 * Space is bufsize minus Netbios over TCP header minus SMB header.
125 * The alignment_offset is to align the param bytes on a four byte
126 * boundary (2 bytes for data len, one byte pad).
127 * NT needs this to work correctly.
130 useable_space
= bufsize
- ((smb_buf(outbuf
)+
131 alignment_offset
+data_alignment_offset
) -
135 * useable_space can never be more than max_send minus the
139 useable_space
= MIN(useable_space
,
140 max_send
- (alignment_offset
+data_alignment_offset
));
143 while (params_to_send
|| data_to_send
) {
146 * Calculate whether we will totally or partially fill this packet.
149 total_sent_thistime
= params_to_send
+ data_to_send
+
150 alignment_offset
+ data_alignment_offset
;
153 * We can never send more than useable_space.
156 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
158 set_message(inbuf
,outbuf
, 18, total_sent_thistime
, True
);
161 * Set total params and data to be sent.
164 SIVAL(outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
165 SIVAL(outbuf
,smb_ntr_TotalDataCount
,datasize
);
168 * Calculate how many parameters and data we can fit into
169 * this packet. Parameters get precedence.
172 params_sent_thistime
= MIN(params_to_send
,useable_space
);
173 data_sent_thistime
= useable_space
- params_sent_thistime
;
174 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
176 SIVAL(outbuf
,smb_ntr_ParameterCount
,params_sent_thistime
);
178 if(params_sent_thistime
== 0) {
179 SIVAL(outbuf
,smb_ntr_ParameterOffset
,0);
180 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,0);
183 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
184 * parameter bytes, however the first 4 bytes of outbuf are
185 * the Netbios over TCP header. Thus use smb_base() to subtract
186 * them from the calculation.
189 SIVAL(outbuf
,smb_ntr_ParameterOffset
,
190 ((smb_buf(outbuf
)+alignment_offset
) - smb_base(outbuf
)));
192 * Absolute displacement of param bytes sent in this packet.
195 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,pp
- params
);
199 * Deal with the data portion.
202 SIVAL(outbuf
,smb_ntr_DataCount
, data_sent_thistime
);
204 if(data_sent_thistime
== 0) {
205 SIVAL(outbuf
,smb_ntr_DataOffset
,0);
206 SIVAL(outbuf
,smb_ntr_DataDisplacement
, 0);
209 * The offset of the data bytes is the offset of the
210 * parameter bytes plus the number of parameters being sent this time.
213 SIVAL(outbuf
,smb_ntr_DataOffset
,((smb_buf(outbuf
)+alignment_offset
) -
214 smb_base(outbuf
)) + params_sent_thistime
+ data_alignment_offset
);
215 SIVAL(outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
219 * Copy the param bytes into the packet.
222 if(params_sent_thistime
) {
223 memcpy((smb_buf(outbuf
)+alignment_offset
),pp
,params_sent_thistime
);
227 * Copy in the data bytes
230 if(data_sent_thistime
) {
231 memcpy(smb_buf(outbuf
)+alignment_offset
+params_sent_thistime
+
232 data_alignment_offset
,pd
,data_sent_thistime
);
235 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
236 params_sent_thistime
, data_sent_thistime
, useable_space
));
237 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
238 params_to_send
, data_to_send
, paramsize
, datasize
));
240 /* Send the packet */
242 if (!send_smb(smbd_server_fd(),outbuf
)) {
243 exit_server_cleanly("send_nt_replies: send_smb failed.");
246 pp
+= params_sent_thistime
;
247 pd
+= data_sent_thistime
;
249 params_to_send
-= params_sent_thistime
;
250 data_to_send
-= data_sent_thistime
;
256 if(params_to_send
< 0 || data_to_send
< 0) {
257 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
258 params_to_send
, data_to_send
));
266 /****************************************************************************
267 Is it an NTFS stream name ?
268 ****************************************************************************/
270 BOOL
is_ntfs_stream_name(const char *fname
)
272 if (lp_posix_pathnames()) {
275 return (strchr_m(fname
, ':') != NULL
) ? True
: False
;
278 /****************************************************************************
280 ****************************************************************************/
282 static BOOL saved_case_sensitive
;
283 static BOOL saved_case_preserve
;
284 static BOOL saved_short_case_preserve
;
286 /****************************************************************************
288 ****************************************************************************/
290 static uint32
set_posix_case_semantics(connection_struct
*conn
, uint32 file_attributes
)
292 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
)) {
293 return file_attributes
;
296 saved_case_sensitive
= conn
->case_sensitive
;
297 saved_case_preserve
= conn
->case_preserve
;
298 saved_short_case_preserve
= conn
->short_case_preserve
;
301 conn
->case_sensitive
= True
;
302 conn
->case_preserve
= True
;
303 conn
->short_case_preserve
= True
;
305 return (file_attributes
& ~FILE_FLAG_POSIX_SEMANTICS
);
308 /****************************************************************************
309 Restore case semantics.
310 ****************************************************************************/
312 static void restore_case_semantics(connection_struct
*conn
, uint32 file_attributes
)
314 if(!(file_attributes
& FILE_FLAG_POSIX_SEMANTICS
)) {
318 conn
->case_sensitive
= saved_case_sensitive
;
319 conn
->case_preserve
= saved_case_preserve
;
320 conn
->short_case_preserve
= saved_short_case_preserve
;
323 /****************************************************************************
324 Reply to an NT create and X call on a pipe.
325 ****************************************************************************/
327 static int nt_open_pipe(char *fname
, connection_struct
*conn
,
328 char *inbuf
, char *outbuf
, int *ppnum
)
330 smb_np_struct
*p
= NULL
;
331 uint16 vuid
= SVAL(inbuf
, smb_uid
);
334 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
336 /* See if it is one we want to handle. */
338 if (lp_disable_spoolss() && strequal(fname
, "\\spoolss")) {
339 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
342 for( i
= 0; known_nt_pipes
[i
]; i
++ ) {
343 if( strequal(fname
,known_nt_pipes
[i
])) {
348 if ( known_nt_pipes
[i
] == NULL
) {
349 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND
,ERRDOS
,ERRbadpipe
));
352 /* Strip \\ off the name. */
355 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname
));
357 p
= open_rpc_pipe_p(fname
, conn
, vuid
);
359 return(ERROR_DOS(ERRSRV
,ERRnofids
));
362 /* TODO: Add pipe to db */
364 if ( !store_pipe_opendb( p
) ) {
365 DEBUG(3,("nt_open_pipe: failed to store %s pipe open.\n", fname
));
372 /****************************************************************************
373 Reply to an NT create and X call for pipes.
374 ****************************************************************************/
376 static int do_ntcreate_pipe_open(connection_struct
*conn
,
377 char *inbuf
,char *outbuf
,int length
,int bufsize
)
383 uint32 flags
= IVAL(inbuf
,smb_ntcreate_Flags
);
385 srvstr_pull_buf(inbuf
, SVAL(inbuf
, smb_flg2
), fname
, smb_buf(inbuf
),
386 sizeof(fname
), STR_TERMINATE
);
388 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0) {
393 * Deal with pipe return.
396 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
397 /* This is very strange. We
398 * return 50 words, but only set
399 * the wcnt to 42 ? It's definately
400 * what happens on the wire....
402 set_message(inbuf
,outbuf
,50,0,True
);
403 SCVAL(outbuf
,smb_wct
,42);
405 set_message(inbuf
,outbuf
,34,0,True
);
408 p
= outbuf
+ smb_vwv2
;
412 SIVAL(p
,0,FILE_WAS_OPENED
);
415 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
418 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
420 SSVAL(p
,2, 0x5FF); /* ? */
423 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
425 SIVAL(p
,0,FILE_GENERIC_ALL
);
427 * For pipes W2K3 seems to return
429 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
431 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
434 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
436 return chain_reply(inbuf
,outbuf
,length
,bufsize
);
439 /****************************************************************************
440 Reply to an NT create and X call for a quota file.
441 ****************************************************************************/
443 int reply_ntcreate_and_X_quota(connection_struct
*conn
,
448 enum FAKE_FILE_TYPE fake_file_type
,
453 uint32 desired_access
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
457 status
= open_fake_file(conn
, fake_file_type
, fname
, desired_access
,
460 if (!NT_STATUS_IS_OK(status
)) {
461 return ERROR_NT(status
);
464 set_message(inbuf
,outbuf
,34,0,True
);
466 p
= outbuf
+ smb_vwv2
;
468 /* SCVAL(p,0,NO_OPLOCK_RETURN); */
470 SSVAL(p
,0,fsp
->fnum
);
472 DEBUG(5,("reply_ntcreate_and_X_quota: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
474 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
478 /****************************************************************************
479 Reply to an NT create and X call.
480 ****************************************************************************/
482 int reply_ntcreate_and_X(connection_struct
*conn
,
483 char *inbuf
,char *outbuf
,int length
,int bufsize
)
487 uint32 flags
= IVAL(inbuf
,smb_ntcreate_Flags
);
488 uint32 access_mask
= IVAL(inbuf
,smb_ntcreate_DesiredAccess
);
489 uint32 file_attributes
= IVAL(inbuf
,smb_ntcreate_FileAttributes
);
490 uint32 new_file_attributes
;
491 uint32 share_access
= IVAL(inbuf
,smb_ntcreate_ShareAccess
);
492 uint32 create_disposition
= IVAL(inbuf
,smb_ntcreate_CreateDisposition
);
493 uint32 create_options
= IVAL(inbuf
,smb_ntcreate_CreateOptions
);
494 uint16 root_dir_fid
= (uint16
)IVAL(inbuf
,smb_ntcreate_RootDirectoryFid
);
495 /* Breakout the oplock request bits so we can set the
496 reply bits separately. */
497 int oplock_request
= 0;
499 SMB_OFF_T file_len
= 0;
500 SMB_STRUCT_STAT sbuf
;
502 files_struct
*fsp
= NULL
;
504 struct timespec c_timespec
;
505 struct timespec a_timespec
;
506 struct timespec m_timespec
;
507 BOOL extended_oplock_granted
= False
;
509 struct smb_request req
;
511 START_PROFILE(SMBntcreateX
);
513 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
514 "file_attributes = 0x%x, share_access = 0x%x, "
515 "create_disposition = 0x%x create_options = 0x%x "
516 "root_dir_fid = 0x%x\n",
518 (unsigned int)access_mask
,
519 (unsigned int)file_attributes
,
520 (unsigned int)share_access
,
521 (unsigned int)create_disposition
,
522 (unsigned int)create_options
,
523 (unsigned int)root_dir_fid
));
525 init_smb_request(&req
, (uint8
*)inbuf
);
528 * If it's an IPC, use the pipe handler.
532 if (lp_nt_pipe_support()) {
533 END_PROFILE(SMBntcreateX
);
534 return do_ntcreate_pipe_open(conn
,inbuf
,outbuf
,length
,bufsize
);
536 END_PROFILE(SMBntcreateX
);
537 return(ERROR_DOS(ERRDOS
,ERRnoaccess
));
541 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
542 END_PROFILE(SMBntcreateX
);
543 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
550 if(root_dir_fid
!= 0) {
552 * This filename is relative to a directory fid.
555 files_struct
*dir_fsp
= file_fsp(inbuf
,smb_ntcreate_RootDirectoryFid
);
559 END_PROFILE(SMBntcreateX
);
560 return ERROR_DOS(ERRDOS
,ERRbadfid
);
563 if(!dir_fsp
->is_directory
) {
565 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
,
566 smb_buf(inbuf
), sizeof(fname
), 0,
567 STR_TERMINATE
, &status
);
568 if (!NT_STATUS_IS_OK(status
)) {
569 END_PROFILE(SMBntcreateX
);
570 return ERROR_NT(status
);
574 * Check to see if this is a mac fork of some kind.
577 if( is_ntfs_stream_name(fname
)) {
578 END_PROFILE(SMBntcreateX
);
579 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
583 we need to handle the case when we get a
584 relative open relative to a file and the
585 pathname is blank - this is a reopen!
586 (hint from demyn plantenberg)
589 END_PROFILE(SMBntcreateX
);
590 return(ERROR_DOS(ERRDOS
,ERRbadfid
));
594 * Copy in the base directory name.
597 pstrcpy( fname
, dir_fsp
->fsp_name
);
598 dir_name_len
= strlen(fname
);
601 * Ensure it ends in a '\'.
604 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
609 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), rel_fname
,
610 smb_buf(inbuf
), sizeof(rel_fname
), 0,
611 STR_TERMINATE
, &status
);
612 if (!NT_STATUS_IS_OK(status
)) {
613 END_PROFILE(SMBntcreateX
);
614 return ERROR_NT(status
);
616 pstrcat(fname
, rel_fname
);
618 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
,
619 smb_buf(inbuf
), sizeof(fname
), 0,
620 STR_TERMINATE
, &status
);
621 if (!NT_STATUS_IS_OK(status
)) {
622 END_PROFILE(SMBntcreateX
);
623 return ERROR_NT(status
);
627 * Check to see if this is a mac fork of some kind.
630 if( is_ntfs_stream_name(fname
)) {
631 enum FAKE_FILE_TYPE fake_file_type
= is_fake_file(fname
);
632 if (fake_file_type
!=FAKE_FILE_TYPE_NONE
) {
634 * Here we go! support for changing the disk quotas --metze
636 * We need to fake up to open this MAGIC QUOTA file
637 * and return a valid FID.
639 * w2k close this file directly after openening
640 * xp also tries a QUERY_FILE_INFO on the file and then close it
642 result
= reply_ntcreate_and_X_quota(conn
, inbuf
, outbuf
, length
, bufsize
,
643 fake_file_type
, fname
);
644 END_PROFILE(SMBntcreateX
);
647 END_PROFILE(SMBntcreateX
);
648 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
654 * Now contruct the smb_open_mode value from the filename,
655 * desired access and the share access.
657 status
= resolve_dfspath(conn
, SVAL(inbuf
,smb_flg2
) & FLAGS2_DFS_PATHNAMES
, fname
);
658 if (!NT_STATUS_IS_OK(status
)) {
659 END_PROFILE(SMBntcreateX
);
660 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
661 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
663 return ERROR_NT(status
);
666 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
667 if (oplock_request
) {
668 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
672 * Ordinary file or directory.
676 * Check if POSIX semantics are wanted.
679 new_file_attributes
= set_posix_case_semantics(conn
, file_attributes
);
681 status
= unix_convert(conn
, fname
, False
, NULL
, &sbuf
);
682 if (!NT_STATUS_IS_OK(status
)) {
683 restore_case_semantics(conn
, file_attributes
);
684 END_PROFILE(SMBntcreateX
);
685 return ERROR_NT(status
);
687 /* All file access must go through check_name() */
688 status
= check_name(conn
, fname
);
689 if (!NT_STATUS_IS_OK(status
)) {
690 restore_case_semantics(conn
, file_attributes
);
691 END_PROFILE(SMBntcreateX
);
692 return ERROR_NT(status
);
695 /* This is the correct thing to do (check every time) but can_delete is
696 expensive (it may have to read the parent directory permissions). So
697 for now we're not doing it unless we have a strong hint the client
698 is really going to delete this file. If the client is forcing FILE_CREATE
699 let the filesystem take care of the permissions. */
701 /* Setting FILE_SHARE_DELETE is the hint. */
703 if (lp_acl_check_permissions(SNUM(conn
))
704 && (create_disposition
!= FILE_CREATE
)
705 && (share_access
& FILE_SHARE_DELETE
)
706 && (access_mask
& DELETE_ACCESS
)) {
707 if ((dos_mode(conn
, fname
, &sbuf
) & FILE_ATTRIBUTE_READONLY
) ||
708 !can_delete_file_in_directory(conn
, fname
)) {
709 restore_case_semantics(conn
, file_attributes
);
710 END_PROFILE(SMBntcreateX
);
711 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
716 /* We need to support SeSecurityPrivilege for this. */
717 if ((access_mask
& SEC_RIGHT_SYSTEM_SECURITY
)) &&
718 !user_has_privileges(current_user
.nt_user_token
,
720 restore_case_semantics(conn
, file_attributes
);
721 END_PROFILE(SMBntcreateX
);
722 return ERROR_NT(NT_STATUS_PRIVILEGE_NOT_HELD
);
727 * If it's a request for a directory open, deal with it separately.
730 if(create_options
& FILE_DIRECTORY_FILE
) {
732 /* Can't open a temp directory. IFS kit test. */
733 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
734 END_PROFILE(SMBntcreateX
);
735 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
739 status
= open_directory(conn
, &req
, fname
, &sbuf
,
747 restore_case_semantics(conn
, file_attributes
);
749 if(!NT_STATUS_IS_OK(status
)) {
750 if (!use_nt_status() && NT_STATUS_EQUAL(
751 status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
752 status
= NT_STATUS_DOS(ERRDOS
, ERRfilexists
);
754 END_PROFILE(SMBntcreateX
);
755 return ERROR_NT(status
);
761 * Ordinary file case.
764 /* NB. We have a potential bug here. If we
765 * cause an oplock break to ourselves, then we
766 * could end up processing filename related
767 * SMB requests whilst we await the oplock
768 * break response. As we may have changed the
769 * filename case semantics to be POSIX-like,
770 * this could mean a filename request could
771 * fail when it should succeed. This is a rare
772 * condition, but eventually we must arrange
773 * to restore the correct case semantics
774 * before issuing an oplock break request to
775 * our client. JRA. */
777 status
= open_file_ntcreate(conn
, &req
, fname
, &sbuf
,
786 if (!NT_STATUS_IS_OK(status
)) {
787 /* We cheat here. There are two cases we
788 * care about. One is a directory rename,
789 * where the NT client will attempt to
790 * open the source directory for
791 * DELETE access. Note that when the
792 * NT client does this it does *not*
793 * set the directory bit in the
794 * request packet. This is translated
795 * into a read/write open
796 * request. POSIX states that any open
797 * for write request on a directory
798 * will generate an EISDIR error, so
799 * we can catch this here and open a
800 * pseudo handle that is flagged as a
801 * directory. The second is an open
802 * for a permissions read only, which
803 * we handle in the open_file_stat case. JRA.
806 if (NT_STATUS_EQUAL(status
,
807 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
810 * Fail the open if it was explicitly a non-directory file.
813 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
814 restore_case_semantics(conn
, file_attributes
);
815 END_PROFILE(SMBntcreateX
);
816 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
820 status
= open_directory(conn
, &req
, fname
,
829 if(!NT_STATUS_IS_OK(status
)) {
830 restore_case_semantics(conn
, file_attributes
);
831 if (!use_nt_status() && NT_STATUS_EQUAL(
832 status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
833 status
= NT_STATUS_DOS(ERRDOS
, ERRfilexists
);
835 END_PROFILE(SMBntcreateX
);
836 return ERROR_NT(status
);
839 restore_case_semantics(conn
, file_attributes
);
840 END_PROFILE(SMBntcreateX
);
841 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
842 /* We have re-scheduled this call. */
845 return ERROR_NT(status
);
850 restore_case_semantics(conn
, file_attributes
);
852 file_len
= sbuf
.st_size
;
853 fattr
= dos_mode(conn
,fname
,&sbuf
);
855 fattr
= FILE_ATTRIBUTE_NORMAL
;
857 if (!fsp
->is_directory
&& (fattr
& aDIR
)) {
858 close_file(fsp
,ERROR_CLOSE
);
859 END_PROFILE(SMBntcreateX
);
860 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
863 /* Save the requested allocation size. */
864 if ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
)) {
865 SMB_BIG_UINT allocation_size
= (SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
);
866 #ifdef LARGE_SMB_OFF_T
867 allocation_size
|= (((SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
+ 4)) << 32);
869 if (allocation_size
&& (allocation_size
> (SMB_BIG_UINT
)file_len
)) {
870 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, allocation_size
);
871 if (fsp
->is_directory
) {
872 close_file(fsp
,ERROR_CLOSE
);
873 END_PROFILE(SMBntcreateX
);
874 /* Can't set allocation size on a directory. */
875 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
877 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
878 close_file(fsp
,ERROR_CLOSE
);
879 END_PROFILE(SMBntcreateX
);
880 return ERROR_NT(NT_STATUS_DISK_FULL
);
883 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
,(SMB_BIG_UINT
)file_len
);
888 * If the caller set the extended oplock request bit
889 * and we granted one (by whatever means) - set the
890 * correct bit for extended oplock reply.
893 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
894 extended_oplock_granted
= True
;
897 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
)) {
898 extended_oplock_granted
= True
;
901 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
902 /* This is very strange. We
903 * return 50 words, but only set
904 * the wcnt to 42 ? It's definately
905 * what happens on the wire....
907 set_message(inbuf
,outbuf
,50,0,True
);
908 SCVAL(outbuf
,smb_wct
,42);
910 set_message(inbuf
,outbuf
,34,0,True
);
913 p
= outbuf
+ smb_vwv2
;
916 * Currently as we don't support level II oplocks we just report
917 * exclusive & batch here.
920 if (extended_oplock_granted
) {
921 if (flags
& REQUEST_BATCH_OPLOCK
) {
922 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
924 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
926 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
927 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
929 SCVAL(p
,0,NO_OPLOCK_RETURN
);
933 SSVAL(p
,0,fsp
->fnum
);
935 if ((create_disposition
== FILE_SUPERSEDE
) && (info
== FILE_WAS_OVERWRITTEN
)) {
936 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
943 c_timespec
= get_create_timespec(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
944 a_timespec
= get_atimespec(&sbuf
);
945 m_timespec
= get_mtimespec(&sbuf
);
947 if (lp_dos_filetime_resolution(SNUM(conn
))) {
948 dos_filetime_timespec(&c_timespec
);
949 dos_filetime_timespec(&a_timespec
);
950 dos_filetime_timespec(&m_timespec
);
953 put_long_date_timespec(p
, c_timespec
); /* create time. */
955 put_long_date_timespec(p
, a_timespec
); /* access time */
957 put_long_date_timespec(p
, m_timespec
); /* write time */
959 put_long_date_timespec(p
, m_timespec
); /* change time */
961 SIVAL(p
,0,fattr
); /* File Attributes. */
963 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
965 SOFF_T(p
,0,file_len
);
967 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
971 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
973 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
976 if (fsp
->is_directory
|| can_write_to_file(conn
, fname
, &sbuf
)) {
977 perms
= FILE_GENERIC_ALL
;
979 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
984 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
986 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
987 END_PROFILE(SMBntcreateX
);
991 /****************************************************************************
992 Reply to a NT_TRANSACT_CREATE call to open a pipe.
993 ****************************************************************************/
995 static int do_nt_transact_create_pipe( connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
996 uint16
**ppsetup
, uint32 setup_count
,
997 char **ppparams
, uint32 parameter_count
,
998 char **ppdata
, uint32 data_count
)
1001 char *params
= *ppparams
;
1010 * Ensure minimum number of parameters sent.
1013 if(parameter_count
< 54) {
1014 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1015 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1018 flags
= IVAL(params
,0);
1020 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
, params
+53,
1021 sizeof(fname
), parameter_count
-53, STR_TERMINATE
,
1023 if (!NT_STATUS_IS_OK(status
)) {
1024 return ERROR_NT(status
);
1027 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0) {
1031 /* Realloc the size of parameters and data we will return */
1032 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1033 /* Extended response is 32 more byyes. */
1038 params
= nttrans_realloc(ppparams
, param_len
);
1039 if(params
== NULL
) {
1040 return ERROR_DOS(ERRDOS
,ERRnomem
);
1044 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1049 SIVAL(p
,0,FILE_WAS_OPENED
);
1053 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
1056 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
1058 SSVAL(p
,2, 0x5FF); /* ? */
1061 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1063 SIVAL(p
,0,FILE_GENERIC_ALL
);
1065 * For pipes W2K3 seems to return
1067 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
1069 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
1072 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
1074 /* Send the required number of replies */
1075 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1080 /****************************************************************************
1081 Internal fn to set security descriptors.
1082 ****************************************************************************/
1084 static NTSTATUS
set_sd(files_struct
*fsp
, char *data
, uint32 sd_len
, uint32 security_info_sent
)
1087 SEC_DESC
*psd
= NULL
;
1088 TALLOC_CTX
*mem_ctx
;
1091 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
1092 return NT_STATUS_OK
;
1096 * Init the parse struct we will unmarshall from.
1099 if ((mem_ctx
= talloc_init("set_sd")) == NULL
) {
1100 DEBUG(0,("set_sd: talloc_init failed.\n"));
1101 return NT_STATUS_NO_MEMORY
;
1104 prs_init(&pd
, 0, mem_ctx
, UNMARSHALL
);
1107 * Setup the prs_struct to point at the memory we just
1111 prs_give_memory( &pd
, data
, sd_len
, False
);
1114 * Finally, unmarshall from the data buffer.
1117 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1118 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1120 * Return access denied for want of a better error message..
1122 talloc_destroy(mem_ctx
);
1123 return NT_STATUS_NO_MEMORY
;
1126 if (psd
->owner_sid
==0) {
1127 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
1129 if (psd
->group_sid
==0) {
1130 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
1133 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
1136 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
1139 status
= SMB_VFS_FSET_NT_ACL( fsp
, fsp
->fh
->fd
, security_info_sent
, psd
);
1141 talloc_destroy(mem_ctx
);
1145 /****************************************************************************
1146 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1147 ****************************************************************************/
1149 static struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
1151 struct ea_list
*ea_list_head
= NULL
;
1154 if (data_size
< 4) {
1158 while (offset
+ 4 <= data_size
) {
1159 size_t next_offset
= IVAL(pdata
,offset
);
1160 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
1166 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
1167 if (next_offset
== 0) {
1170 offset
+= next_offset
;
1173 return ea_list_head
;
1176 /****************************************************************************
1177 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1178 ****************************************************************************/
1180 static int call_nt_transact_create(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1181 uint16
**ppsetup
, uint32 setup_count
,
1182 char **ppparams
, uint32 parameter_count
,
1183 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1186 char *params
= *ppparams
;
1187 char *data
= *ppdata
;
1188 /* Breakout the oplock request bits so we can set the reply bits separately. */
1189 int oplock_request
= 0;
1191 SMB_OFF_T file_len
= 0;
1192 SMB_STRUCT_STAT sbuf
;
1194 files_struct
*fsp
= NULL
;
1196 BOOL extended_oplock_granted
= False
;
1199 uint32 file_attributes
;
1200 uint32 new_file_attributes
;
1201 uint32 share_access
;
1202 uint32 create_disposition
;
1203 uint32 create_options
;
1206 uint16 root_dir_fid
;
1207 struct timespec c_timespec
;
1208 struct timespec a_timespec
;
1209 struct timespec m_timespec
;
1210 struct ea_list
*ea_list
= NULL
;
1211 TALLOC_CTX
*ctx
= NULL
;
1215 struct smb_request req
;
1217 DEBUG(5,("call_nt_transact_create\n"));
1220 * If it's an IPC, use the pipe handler.
1224 if (lp_nt_pipe_support()) {
1225 return do_nt_transact_create_pipe(conn
, inbuf
, outbuf
, length
,
1227 ppsetup
, setup_count
,
1228 ppparams
, parameter_count
,
1229 ppdata
, data_count
);
1231 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1236 * Ensure minimum number of parameters sent.
1239 if(parameter_count
< 54) {
1240 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1241 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1244 init_smb_request(&req
, (uint8
*)inbuf
);
1246 flags
= IVAL(params
,0);
1247 access_mask
= IVAL(params
,8);
1248 file_attributes
= IVAL(params
,20);
1249 share_access
= IVAL(params
,24);
1250 create_disposition
= IVAL(params
,28);
1251 create_options
= IVAL(params
,32);
1252 sd_len
= IVAL(params
,36);
1253 ea_len
= IVAL(params
,40);
1254 root_dir_fid
= (uint16
)IVAL(params
,4);
1256 /* Ensure the data_len is correct for the sd and ea values given. */
1257 if ((ea_len
+ sd_len
> data_count
) ||
1258 (ea_len
> data_count
) || (sd_len
> data_count
) ||
1259 (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1260 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1261 (unsigned int)ea_len
, (unsigned int)sd_len
, (unsigned int)data_count
));
1262 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1266 if (!lp_ea_support(SNUM(conn
))) {
1267 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1268 (unsigned int)ea_len
));
1269 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED
);
1273 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1274 (unsigned int)ea_len
));
1275 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1279 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
1280 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1284 * Get the file name.
1287 if(root_dir_fid
!= 0) {
1289 * This filename is relative to a directory fid.
1291 files_struct
*dir_fsp
= file_fsp(params
,4);
1292 size_t dir_name_len
;
1295 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1298 if(!dir_fsp
->is_directory
) {
1299 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
,
1300 params
+53, sizeof(fname
),
1301 parameter_count
-53, STR_TERMINATE
,
1303 if (!NT_STATUS_IS_OK(status
)) {
1304 return ERROR_NT(status
);
1308 * Check to see if this is a mac fork of some kind.
1311 if( is_ntfs_stream_name(fname
)) {
1312 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1315 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1319 * Copy in the base directory name.
1322 pstrcpy( fname
, dir_fsp
->fsp_name
);
1323 dir_name_len
= strlen(fname
);
1326 * Ensure it ends in a '\'.
1329 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
1330 pstrcat(fname
, "/");
1336 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), tmpname
,
1337 params
+53, sizeof(tmpname
),
1338 parameter_count
-53, STR_TERMINATE
,
1340 if (!NT_STATUS_IS_OK(status
)) {
1341 return ERROR_NT(status
);
1343 pstrcat(fname
, tmpname
);
1346 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
, params
+53,
1347 sizeof(fname
), parameter_count
-53,
1348 STR_TERMINATE
, &status
);
1349 if (!NT_STATUS_IS_OK(status
)) {
1350 return ERROR_NT(status
);
1354 * Check to see if this is a mac fork of some kind.
1357 if( is_ntfs_stream_name(fname
)) {
1358 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1362 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1363 if (oplock_request
) {
1364 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1368 * Ordinary file or directory.
1372 * Check if POSIX semantics are wanted.
1375 new_file_attributes
= set_posix_case_semantics(conn
, file_attributes
);
1377 status
= resolve_dfspath(conn
, SVAL(inbuf
,smb_flg2
) & FLAGS2_DFS_PATHNAMES
, fname
);
1378 if (!NT_STATUS_IS_OK(status
)) {
1379 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1380 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
1382 return ERROR_NT(status
);
1385 status
= unix_convert(conn
, fname
, False
, NULL
, &sbuf
);
1386 if (!NT_STATUS_IS_OK(status
)) {
1387 restore_case_semantics(conn
, file_attributes
);
1388 return ERROR_NT(status
);
1390 /* All file access must go through check_name() */
1391 status
= check_name(conn
, fname
);
1392 if (!NT_STATUS_IS_OK(status
)) {
1393 restore_case_semantics(conn
, file_attributes
);
1394 return ERROR_NT(status
);
1397 /* This is the correct thing to do (check every time) but can_delete is
1398 expensive (it may have to read the parent directory permissions). So
1399 for now we're not doing it unless we have a strong hint the client
1400 is really going to delete this file. If the client is forcing FILE_CREATE
1401 let the filesystem take care of the permissions. */
1403 /* Setting FILE_SHARE_DELETE is the hint. */
1405 if (lp_acl_check_permissions(SNUM(conn
))
1406 && (create_disposition
!= FILE_CREATE
)
1407 && (share_access
& FILE_SHARE_DELETE
)
1408 && (access_mask
& DELETE_ACCESS
)) {
1409 if ((dos_mode(conn
, fname
, &sbuf
) & FILE_ATTRIBUTE_READONLY
) ||
1410 !can_delete_file_in_directory(conn
, fname
)) {
1411 restore_case_semantics(conn
, file_attributes
);
1412 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1417 pdata
= data
+ sd_len
;
1419 /* We have already checked that ea_len <= data_count here. */
1420 ea_list
= read_nttrans_ea_list(tmp_talloc_ctx(), pdata
,
1423 restore_case_semantics(conn
, file_attributes
);
1424 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1429 * If it's a request for a directory open, deal with it separately.
1432 if(create_options
& FILE_DIRECTORY_FILE
) {
1434 /* Can't open a temp directory. IFS kit test. */
1435 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
1436 restore_case_semantics(conn
, file_attributes
);
1437 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1441 * We will get a create directory here if the Win32
1442 * app specified a security descriptor in the
1443 * CreateDirectory() call.
1447 status
= open_directory(conn
, &req
, fname
, &sbuf
,
1452 new_file_attributes
,
1454 if(!NT_STATUS_IS_OK(status
)) {
1455 restore_case_semantics(conn
, file_attributes
);
1456 return ERROR_NT(status
);
1462 * Ordinary file case.
1465 status
= open_file_ntcreate(conn
,&req
,fname
,&sbuf
,
1470 new_file_attributes
,
1474 if (!NT_STATUS_IS_OK(status
)) {
1475 if (NT_STATUS_EQUAL(status
,
1476 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
1479 * Fail the open if it was explicitly a non-directory file.
1482 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
1483 restore_case_semantics(conn
, file_attributes
);
1484 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
1488 status
= open_directory(conn
, &req
, fname
,
1494 new_file_attributes
,
1496 if(!NT_STATUS_IS_OK(status
)) {
1497 restore_case_semantics(conn
, file_attributes
);
1498 return ERROR_NT(status
);
1501 restore_case_semantics(conn
, file_attributes
);
1502 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1503 /* We have re-scheduled this call. */
1506 return ERROR_NT(status
);
1512 * According to the MS documentation, the only time the security
1513 * descriptor is applied to the opened file is iff we *created* the
1514 * file; an existing file stays the same.
1516 * Also, it seems (from observation) that you can open the file with
1517 * any access mask but you can still write the sd. We need to override
1518 * the granted access before we call set_sd
1519 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1522 if (lp_nt_acl_support(SNUM(conn
)) && sd_len
&& info
== FILE_WAS_CREATED
) {
1523 uint32 saved_access_mask
= fsp
->access_mask
;
1525 /* We have already checked that sd_len <= data_count here. */
1527 fsp
->access_mask
= FILE_GENERIC_ALL
;
1529 status
= set_sd( fsp
, data
, sd_len
, ALL_SECURITY_INFORMATION
);
1530 if (!NT_STATUS_IS_OK(status
)) {
1531 talloc_destroy(ctx
);
1532 close_file(fsp
,ERROR_CLOSE
);
1533 restore_case_semantics(conn
, file_attributes
);
1534 return ERROR_NT(status
);
1536 fsp
->access_mask
= saved_access_mask
;
1539 if (ea_len
&& (info
== FILE_WAS_CREATED
)) {
1540 status
= set_ea(conn
, fsp
, fname
, ea_list
);
1541 if (!NT_STATUS_IS_OK(status
)) {
1542 close_file(fsp
,ERROR_CLOSE
);
1543 restore_case_semantics(conn
, file_attributes
);
1544 return ERROR_NT(status
);
1548 restore_case_semantics(conn
, file_attributes
);
1550 file_len
= sbuf
.st_size
;
1551 fattr
= dos_mode(conn
,fname
,&sbuf
);
1553 fattr
= FILE_ATTRIBUTE_NORMAL
;
1555 if (!fsp
->is_directory
&& (fattr
& aDIR
)) {
1556 close_file(fsp
,ERROR_CLOSE
);
1557 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1560 /* Save the requested allocation size. */
1561 if ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
)) {
1562 SMB_BIG_UINT allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
1563 #ifdef LARGE_SMB_OFF_T
1564 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
1566 if (allocation_size
&& (allocation_size
> file_len
)) {
1567 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, allocation_size
);
1568 if (fsp
->is_directory
) {
1569 close_file(fsp
,ERROR_CLOSE
);
1570 /* Can't set allocation size on a directory. */
1571 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1573 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
1574 close_file(fsp
,ERROR_CLOSE
);
1575 return ERROR_NT(NT_STATUS_DISK_FULL
);
1578 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, (SMB_BIG_UINT
)file_len
);
1583 * If the caller set the extended oplock request bit
1584 * and we granted one (by whatever means) - set the
1585 * correct bit for extended oplock reply.
1588 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
1589 extended_oplock_granted
= True
;
1592 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
)) {
1593 extended_oplock_granted
= True
;
1596 /* Realloc the size of parameters and data we will return */
1597 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1598 /* Extended response is 32 more byyes. */
1603 params
= nttrans_realloc(ppparams
, param_len
);
1604 if(params
== NULL
) {
1605 return ERROR_DOS(ERRDOS
,ERRnomem
);
1609 if (extended_oplock_granted
) {
1610 if (flags
& REQUEST_BATCH_OPLOCK
) {
1611 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
1613 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
1615 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1616 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
1618 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1622 SSVAL(p
,0,fsp
->fnum
);
1624 if ((create_disposition
== FILE_SUPERSEDE
) && (info
== FILE_WAS_OVERWRITTEN
)) {
1625 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1632 c_timespec
= get_create_timespec(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1633 a_timespec
= get_atimespec(&sbuf
);
1634 m_timespec
= get_mtimespec(&sbuf
);
1636 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1637 dos_filetime_timespec(&c_timespec
);
1638 dos_filetime_timespec(&a_timespec
);
1639 dos_filetime_timespec(&m_timespec
);
1642 put_long_date_timespec(p
, c_timespec
); /* create time. */
1644 put_long_date_timespec(p
, a_timespec
); /* access time */
1646 put_long_date_timespec(p
, m_timespec
); /* write time */
1648 put_long_date_timespec(p
, m_timespec
); /* change time */
1650 SIVAL(p
,0,fattr
); /* File Attributes. */
1652 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
1654 SOFF_T(p
,0,file_len
);
1656 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1660 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1662 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1665 if (fsp
->is_directory
|| can_write_to_file(conn
, fname
, &sbuf
)) {
1666 perms
= FILE_GENERIC_ALL
;
1668 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1673 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname
));
1675 /* Send the required number of replies */
1676 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1681 /****************************************************************************
1682 Reply to a NT CANCEL request.
1683 conn POINTER CAN BE NULL HERE !
1684 ****************************************************************************/
1686 int reply_ntcancel(connection_struct
*conn
,
1687 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1690 * Go through and cancel any pending change notifies.
1693 int mid
= SVAL(inbuf
,smb_mid
);
1694 START_PROFILE(SMBntcancel
);
1695 remove_pending_change_notify_requests_by_mid(mid
);
1696 remove_pending_lock_requests_by_mid(mid
);
1697 srv_cancel_sign_response(mid
);
1699 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid
));
1701 END_PROFILE(SMBntcancel
);
1705 /****************************************************************************
1707 ****************************************************************************/
1709 static NTSTATUS
copy_internals(connection_struct
*conn
,
1710 struct smb_request
*req
,
1711 char *oldname
, char *newname
, uint32 attrs
)
1713 SMB_STRUCT_STAT sbuf1
, sbuf2
;
1714 pstring last_component_oldname
;
1715 pstring last_component_newname
;
1716 files_struct
*fsp1
,*fsp2
;
1720 NTSTATUS status
= NT_STATUS_OK
;
1725 if (!CAN_WRITE(conn
)) {
1726 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1729 status
= unix_convert(conn
, oldname
, False
, last_component_oldname
, &sbuf1
);
1730 if (!NT_STATUS_IS_OK(status
)) {
1734 status
= check_name(conn
, oldname
);
1735 if (!NT_STATUS_IS_OK(status
)) {
1739 /* Source must already exist. */
1740 if (!VALID_STAT(sbuf1
)) {
1741 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1743 /* Ensure attributes match. */
1744 fattr
= dos_mode(conn
,oldname
,&sbuf1
);
1745 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1746 return NT_STATUS_NO_SUCH_FILE
;
1749 status
= unix_convert(conn
, newname
, False
, last_component_newname
, &sbuf2
);
1750 if (!NT_STATUS_IS_OK(status
)) {
1754 status
= check_name(conn
, newname
);
1755 if (!NT_STATUS_IS_OK(status
)) {
1759 /* Disallow if newname already exists. */
1760 if (VALID_STAT(sbuf2
)) {
1761 return NT_STATUS_OBJECT_NAME_COLLISION
;
1764 /* No links from a directory. */
1765 if (S_ISDIR(sbuf1
.st_mode
)) {
1766 return NT_STATUS_FILE_IS_A_DIRECTORY
;
1769 /* Ensure this is within the share. */
1770 status
= reduce_name(conn
, oldname
);
1771 if (!NT_STATUS_IS_OK(status
)) {
1775 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname
, newname
));
1777 status
= open_file_ntcreate(conn
, req
, oldname
, &sbuf1
,
1778 FILE_READ_DATA
, /* Read-only. */
1779 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1781 0, /* No create options. */
1782 FILE_ATTRIBUTE_NORMAL
,
1786 if (!NT_STATUS_IS_OK(status
)) {
1790 status
= open_file_ntcreate(conn
, req
, newname
, &sbuf2
,
1791 FILE_WRITE_DATA
, /* Read-only. */
1792 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1794 0, /* No create options. */
1799 if (!NT_STATUS_IS_OK(status
)) {
1800 close_file(fsp1
,ERROR_CLOSE
);
1804 if (sbuf1
.st_size
) {
1805 ret
= vfs_transfer_file(fsp1
, fsp2
, sbuf1
.st_size
);
1809 * As we are opening fsp1 read-only we only expect
1810 * an error on close on fsp2 if we are out of space.
1811 * Thus we don't look at the error return from the
1814 close_file(fsp1
,NORMAL_CLOSE
);
1816 /* Ensure the modtime is set correctly on the destination file. */
1817 fsp_set_pending_modtime(fsp2
, get_mtimespec(&sbuf1
));
1819 status
= close_file(fsp2
,NORMAL_CLOSE
);
1821 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1822 creates the file. This isn't the correct thing to do in the copy
1824 file_set_dosmode(conn
, newname
, fattr
, &sbuf2
,
1825 parent_dirname(newname
));
1827 if (ret
< (SMB_OFF_T
)sbuf1
.st_size
) {
1828 return NT_STATUS_DISK_FULL
;
1831 if (!NT_STATUS_IS_OK(status
)) {
1832 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1833 nt_errstr(status
), oldname
, newname
));
1838 /****************************************************************************
1839 Reply to a NT rename request.
1840 ****************************************************************************/
1842 int reply_ntrename(connection_struct
*conn
,
1843 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1850 BOOL src_has_wcard
= False
;
1851 BOOL dest_has_wcard
= False
;
1852 uint32 attrs
= SVAL(inbuf
,smb_vwv0
);
1853 uint16 rename_type
= SVAL(inbuf
,smb_vwv1
);
1854 struct smb_request req
;
1856 START_PROFILE(SMBntrename
);
1858 init_smb_request(&req
, (uint8
*)inbuf
);
1860 p
= smb_buf(inbuf
) + 1;
1861 p
+= srvstr_get_path_wcard(inbuf
, SVAL(inbuf
,smb_flg2
), oldname
, p
,
1862 sizeof(oldname
), 0, STR_TERMINATE
, &status
,
1864 if (!NT_STATUS_IS_OK(status
)) {
1865 END_PROFILE(SMBntrename
);
1866 return ERROR_NT(status
);
1869 if( is_ntfs_stream_name(oldname
)) {
1870 /* Can't rename a stream. */
1871 END_PROFILE(SMBntrename
);
1872 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1875 if (ms_has_wild(oldname
)) {
1876 END_PROFILE(SMBntrename
);
1877 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1881 p
+= srvstr_get_path_wcard(inbuf
, SVAL(inbuf
,smb_flg2
), newname
, p
,
1882 sizeof(newname
), 0, STR_TERMINATE
, &status
,
1884 if (!NT_STATUS_IS_OK(status
)) {
1885 END_PROFILE(SMBntrename
);
1886 return ERROR_NT(status
);
1889 status
= resolve_dfspath(conn
, SVAL(inbuf
,smb_flg2
) & FLAGS2_DFS_PATHNAMES
, oldname
);
1890 if (!NT_STATUS_IS_OK(status
)) {
1891 END_PROFILE(SMBntrename
);
1892 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1893 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
1895 return ERROR_NT(status
);
1898 status
= resolve_dfspath(conn
, SVAL(inbuf
,smb_flg2
) & FLAGS2_DFS_PATHNAMES
, newname
);
1899 if (!NT_STATUS_IS_OK(status
)) {
1900 END_PROFILE(SMBntrename
);
1901 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1902 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
1904 return ERROR_NT(status
);
1907 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1909 switch(rename_type
) {
1910 case RENAME_FLAG_RENAME
:
1911 status
= rename_internals(conn
, &req
, oldname
, newname
,
1912 attrs
, False
, src_has_wcard
,
1915 case RENAME_FLAG_HARD_LINK
:
1916 if (src_has_wcard
|| dest_has_wcard
) {
1918 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1920 status
= hardlink_internals(conn
, oldname
, newname
);
1923 case RENAME_FLAG_COPY
:
1924 if (src_has_wcard
|| dest_has_wcard
) {
1926 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1928 status
= copy_internals(conn
, &req
, oldname
,
1932 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1933 status
= NT_STATUS_INVALID_PARAMETER
;
1936 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1940 if (!NT_STATUS_IS_OK(status
)) {
1941 END_PROFILE(SMBntrename
);
1942 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1943 /* We have re-scheduled this call. */
1946 return ERROR_NT(status
);
1949 outsize
= set_message(inbuf
,outbuf
,0,0,False
);
1951 END_PROFILE(SMBntrename
);
1955 /****************************************************************************
1956 Reply to a notify change - queue the request and
1957 don't allow a directory to be opened.
1958 ****************************************************************************/
1960 static int call_nt_transact_notify_change(connection_struct
*conn
, char *inbuf
,
1961 char *outbuf
, int length
,
1963 uint16
**ppsetup
, uint32 setup_count
,
1965 uint32 parameter_count
,
1966 char **ppdata
, uint32 data_count
,
1967 uint32 max_data_count
,
1968 uint32 max_param_count
)
1970 uint16
*setup
= *ppsetup
;
1976 if(setup_count
< 6) {
1977 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1980 fsp
= file_fsp((char *)setup
,4);
1981 filter
= IVAL(setup
, 0);
1982 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1984 DEBUG(3,("call_nt_transact_notify_change\n"));
1987 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1991 char *filter_string
;
1993 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1994 return ERROR_NT(NT_STATUS_NO_MEMORY
);
1997 DEBUG(3,("call_nt_transact_notify_change: notify change "
1998 "called on %s, filter = %s, recursive = %d\n",
1999 fsp
->fsp_name
, filter_string
, recursive
));
2001 TALLOC_FREE(filter_string
);
2004 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
2005 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
2008 if (fsp
->notify
== NULL
) {
2010 status
= change_notify_create(fsp
, filter
, recursive
);
2012 if (!NT_STATUS_IS_OK(status
)) {
2013 DEBUG(10, ("change_notify_create returned %s\n",
2014 nt_errstr(status
)));
2015 return ERROR_NT(status
);
2019 if (fsp
->notify
->num_changes
!= 0) {
2022 * We've got changes pending, respond immediately
2026 * TODO: write a torture test to check the filtering behaviour
2030 change_notify_reply(inbuf
, fsp
->notify
);
2033 * change_notify_reply() above has independently sent its
2040 * No changes pending, queue the request
2043 status
= change_notify_add_request(inbuf
, filter
, recursive
, fsp
);
2044 if (!NT_STATUS_IS_OK(status
)) {
2045 return ERROR_NT(status
);
2051 /****************************************************************************
2052 Reply to an NT transact rename command.
2053 ****************************************************************************/
2055 static int call_nt_transact_rename(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2056 uint16
**ppsetup
, uint32 setup_count
,
2057 char **ppparams
, uint32 parameter_count
,
2058 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2060 char *params
= *ppparams
;
2062 files_struct
*fsp
= NULL
;
2063 BOOL replace_if_exists
= False
;
2064 BOOL dest_has_wcard
= False
;
2066 struct smb_request req
;
2068 init_smb_request(&req
, (uint8
*)inbuf
);
2070 if(parameter_count
< 5) {
2071 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2074 fsp
= file_fsp(params
, 0);
2075 replace_if_exists
= (SVAL(params
,2) & RENAME_REPLACE_IF_EXISTS
) ? True
: False
;
2076 CHECK_FSP(fsp
, conn
);
2077 srvstr_get_path_wcard(inbuf
, SVAL(inbuf
,smb_flg2
), new_name
, params
+4,
2078 sizeof(new_name
), parameter_count
- 4,
2079 STR_TERMINATE
, &status
, &dest_has_wcard
);
2080 if (!NT_STATUS_IS_OK(status
)) {
2081 return ERROR_NT(status
);
2084 status
= rename_internals(conn
, &req
, fsp
->fsp_name
,
2085 new_name
, 0, replace_if_exists
, False
, dest_has_wcard
);
2087 if (!NT_STATUS_IS_OK(status
)) {
2088 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
2089 /* We have re-scheduled this call. */
2092 return ERROR_NT(status
);
2096 * Rename was successful.
2098 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2100 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
2101 fsp
->fsp_name
, new_name
));
2106 /******************************************************************************
2107 Fake up a completely empty SD.
2108 *******************************************************************************/
2110 static size_t get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
2114 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
2116 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
2123 /****************************************************************************
2124 Reply to query a security descriptor.
2125 ****************************************************************************/
2127 static int call_nt_transact_query_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2128 uint16
**ppsetup
, uint32 setup_count
,
2129 char **ppparams
, uint32 parameter_count
,
2130 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2132 char *params
= *ppparams
;
2133 char *data
= *ppdata
;
2135 SEC_DESC
*psd
= NULL
;
2137 uint32 security_info_wanted
;
2138 TALLOC_CTX
*mem_ctx
;
2139 files_struct
*fsp
= NULL
;
2141 if(parameter_count
< 8) {
2142 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2145 fsp
= file_fsp(params
,0);
2147 return ERROR_DOS(ERRDOS
,ERRbadfid
);
2150 security_info_wanted
= IVAL(params
,4);
2152 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp
->fsp_name
,
2153 (unsigned int)security_info_wanted
));
2155 params
= nttrans_realloc(ppparams
, 4);
2156 if(params
== NULL
) {
2157 return ERROR_DOS(ERRDOS
,ERRnomem
);
2160 if ((mem_ctx
= talloc_init("call_nt_transact_query_security_desc")) == NULL
) {
2161 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
2162 return ERROR_DOS(ERRDOS
,ERRnomem
);
2166 * Get the permissions to return.
2169 if (!lp_nt_acl_support(SNUM(conn
))) {
2170 sd_size
= get_null_nt_acl(mem_ctx
, &psd
);
2172 sd_size
= SMB_VFS_FGET_NT_ACL(fsp
, fsp
->fh
->fd
, security_info_wanted
, &psd
);
2176 talloc_destroy(mem_ctx
);
2177 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
2180 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
2182 SIVAL(params
,0,(uint32
)sd_size
);
2184 if(max_data_count
< sd_size
) {
2186 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_BUFFER_TOO_SMALL
,
2187 params
, 4, *ppdata
, 0);
2188 talloc_destroy(mem_ctx
);
2193 * Allocate the data we will point this at.
2196 data
= nttrans_realloc(ppdata
, sd_size
);
2198 talloc_destroy(mem_ctx
);
2199 return ERROR_DOS(ERRDOS
,ERRnomem
);
2203 * Init the parse struct we will marshall into.
2206 prs_init(&pd
, 0, mem_ctx
, MARSHALL
);
2209 * Setup the prs_struct to point at the memory we just
2213 prs_give_memory( &pd
, data
, (uint32
)sd_size
, False
);
2216 * Finally, linearize into the outgoing buffer.
2219 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
2220 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2221 security descriptor.\n"));
2223 * Return access denied for want of a better error message..
2225 talloc_destroy(mem_ctx
);
2226 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
2230 * Now we can delete the security descriptor.
2233 talloc_destroy(mem_ctx
);
2235 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 4, data
,
2240 /****************************************************************************
2241 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2242 ****************************************************************************/
2244 static int call_nt_transact_set_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2245 uint16
**ppsetup
, uint32 setup_count
,
2246 char **ppparams
, uint32 parameter_count
,
2247 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2249 char *params
= *ppparams
;
2250 char *data
= *ppdata
;
2251 files_struct
*fsp
= NULL
;
2252 uint32 security_info_sent
= 0;
2255 if(parameter_count
< 8) {
2256 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2259 if((fsp
= file_fsp(params
,0)) == NULL
) {
2260 return ERROR_DOS(ERRDOS
,ERRbadfid
);
2263 if(!lp_nt_acl_support(SNUM(conn
))) {
2267 security_info_sent
= IVAL(params
,4);
2269 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
2270 (unsigned int)security_info_sent
));
2272 if (data_count
== 0) {
2273 return ERROR_DOS(ERRDOS
, ERRnoaccess
);
2276 if (!NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, data_count
, security_info_sent
))) {
2277 return ERROR_NT(nt_status
);
2282 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2286 /****************************************************************************
2288 ****************************************************************************/
2290 static int call_nt_transact_ioctl(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2291 uint16
**ppsetup
, uint32 setup_count
,
2292 char **ppparams
, uint32 parameter_count
,
2293 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2300 static BOOL logged_message
;
2301 char *pdata
= *ppdata
;
2303 if (setup_count
!= 8) {
2304 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
2305 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2308 function
= IVAL(*ppsetup
, 0);
2309 fidnum
= SVAL(*ppsetup
, 4);
2310 isFSctl
= CVAL(*ppsetup
, 6);
2311 compfilter
= CVAL(*ppsetup
, 7);
2313 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2314 function
, fidnum
, isFSctl
, compfilter
));
2316 fsp
=file_fsp((char *)*ppsetup
, 4);
2317 /* this check is done in each implemented function case for now
2318 because I don't want to break anything... --metze
2319 FSP_BELONGS_CONN(fsp,conn);*/
2322 case FSCTL_SET_SPARSE
:
2323 /* pretend this succeeded - tho strictly we should
2324 mark the file sparse (if the local fs supports it)
2325 so we can know if we need to pre-allocate or not */
2327 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
2328 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
,
2332 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
2334 unsigned char objid
[16];
2336 /* This should return the object-id on this file.
2337 * I think I'll make this be the inode+dev. JRA.
2340 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
2343 pdata
= nttrans_realloc(ppdata
, data_count
);
2344 if (pdata
== NULL
) {
2345 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2347 push_file_id_16(pdata
, &fsp
->file_id
);
2348 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
2349 push_file_id_16(pdata
+32, &fsp
->file_id
);
2350 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, pdata
, data_count
);
2354 case FSCTL_GET_REPARSE_POINT
:
2355 /* pretend this fail - my winXP does it like this
2359 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2360 return ERROR_NT(NT_STATUS_NOT_A_REPARSE_POINT
);
2362 case FSCTL_SET_REPARSE_POINT
:
2363 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2367 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2368 return ERROR_NT(NT_STATUS_NOT_A_REPARSE_POINT
);
2370 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
2373 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2374 * and return their volume names. If max_data_count is 16, then it is just
2375 * asking for the number of volumes and length of the combined names.
2377 * pdata is the data allocated by our caller, but that uses
2378 * total_data_count (which is 0 in our case) rather than max_data_count.
2379 * Allocate the correct amount and return the pointer to let
2380 * it be deallocated when we return.
2382 SHADOW_COPY_DATA
*shadow_data
= NULL
;
2383 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
2384 BOOL labels
= False
;
2385 uint32 labels_data_count
= 0;
2389 FSP_BELONGS_CONN(fsp
,conn
);
2391 if (max_data_count
< 16) {
2392 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2394 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
2397 if (max_data_count
> 16) {
2401 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
2402 if (shadow_mem_ctx
== NULL
) {
2403 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2404 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2407 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
2408 if (shadow_data
== NULL
) {
2409 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2410 talloc_destroy(shadow_mem_ctx
);
2411 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2414 shadow_data
->mem_ctx
= shadow_mem_ctx
;
2417 * Call the VFS routine to actually do the work.
2419 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2420 talloc_destroy(shadow_data
->mem_ctx
);
2421 if (errno
== ENOSYS
) {
2422 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2423 conn
->connectpath
));
2424 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2426 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2427 conn
->connectpath
));
2428 return ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
2432 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2437 data_count
= 12+labels_data_count
+4;
2440 if (max_data_count
<data_count
) {
2441 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2442 max_data_count
,data_count
));
2443 talloc_destroy(shadow_data
->mem_ctx
);
2444 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL
);
2447 pdata
= nttrans_realloc(ppdata
, data_count
);
2448 if (pdata
== NULL
) {
2449 talloc_destroy(shadow_data
->mem_ctx
);
2450 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2455 /* num_volumes 4 bytes */
2456 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2459 /* num_labels 4 bytes */
2460 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2463 /* needed_data_count 4 bytes */
2464 SIVAL(pdata
,8,labels_data_count
);
2468 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2469 shadow_data
->num_volumes
,fsp
->fsp_name
));
2470 if (labels
&& shadow_data
->labels
) {
2471 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2472 srvstr_push(outbuf
, cur_pdata
, shadow_data
->labels
[i
], 2*sizeof(SHADOW_COPY_LABEL
), STR_UNICODE
|STR_TERMINATE
);
2473 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2474 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2478 talloc_destroy(shadow_data
->mem_ctx
);
2480 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0,
2486 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2488 /* pretend this succeeded -
2490 * we have to send back a list with all files owned by this SID
2492 * but I have to check that --metze
2496 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2498 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2500 FSP_BELONGS_CONN(fsp
,conn
);
2502 /* unknown 4 bytes: this is not the length of the sid :-( */
2503 /*unknown = IVAL(pdata,0);*/
2505 sid_parse(pdata
+4,sid_len
,&sid
);
2506 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid
)));
2508 if (!sid_to_uid(&sid
, &uid
)) {
2509 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2510 sid_string_static(&sid
),(unsigned long)sid_len
));
2514 /* we can take a look at the find source :-)
2516 * find ./ -uid $uid -name '*' is what we need here
2519 * and send 4bytes len and then NULL terminated unicode strings
2522 * but I don't know how to deal with the paged results
2523 * (maybe we can hang the result anywhere in the fsp struct)
2525 * we don't send all files at once
2526 * and at the next we should *not* start from the beginning,
2527 * so we have to cache the result
2532 /* this works for now... */
2533 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0,
2538 if (!logged_message
) {
2539 logged_message
= True
; /* Only print this once... */
2540 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2545 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2549 #ifdef HAVE_SYS_QUOTAS
2550 /****************************************************************************
2551 Reply to get user quota
2552 ****************************************************************************/
2554 static int call_nt_transact_get_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2555 uint16
**ppsetup
, uint32 setup_count
,
2556 char **ppparams
, uint32 parameter_count
,
2557 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2559 NTSTATUS nt_status
= NT_STATUS_OK
;
2560 char *params
= *ppparams
;
2561 char *pdata
= *ppdata
;
2563 int data_len
=0,param_len
=0;
2566 files_struct
*fsp
= NULL
;
2570 BOOL start_enum
= True
;
2571 SMB_NTQUOTA_STRUCT qt
;
2572 SMB_NTQUOTA_LIST
*tmp_list
;
2573 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2578 if (current_user
.ut
.uid
!= 0) {
2579 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2580 lp_servicename(SNUM(conn
)),conn
->user
));
2581 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2585 * Ensure minimum number of parameters sent.
2588 if (parameter_count
< 4) {
2589 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2590 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2593 /* maybe we can check the quota_fnum */
2594 fsp
= file_fsp(params
,0);
2595 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2596 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2597 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2600 /* the NULL pointer checking for fsp->fake_file_handle->pd
2601 * is done by CHECK_NTQUOTA_HANDLE_OK()
2603 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
2605 level
= SVAL(params
,2);
2607 /* unknown 12 bytes leading in params */
2610 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2611 /* seems that we should continue with the enum here --metze */
2613 if (qt_handle
->quota_list
!=NULL
&&
2614 qt_handle
->tmp_list
==NULL
) {
2617 free_ntquota_list(&(qt_handle
->quota_list
));
2619 /* Realloc the size of parameters and data we will return */
2621 params
= nttrans_realloc(ppparams
, param_len
);
2622 if(params
== NULL
) {
2623 return ERROR_DOS(ERRDOS
,ERRnomem
);
2627 SIVAL(params
,0,data_len
);
2634 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2636 if (qt_handle
->quota_list
==NULL
&&
2637 qt_handle
->tmp_list
==NULL
) {
2641 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0)
2642 return ERROR_DOS(ERRSRV
,ERRerror
);
2644 /* Realloc the size of parameters and data we will return */
2646 params
= nttrans_realloc(ppparams
, param_len
);
2647 if(params
== NULL
) {
2648 return ERROR_DOS(ERRDOS
,ERRnomem
);
2651 /* we should not trust the value in max_data_count*/
2652 max_data_count
= MIN(max_data_count
,2048);
2654 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2656 return ERROR_DOS(ERRDOS
,ERRnomem
);
2661 /* set params Size of returned Quota Data 4 bytes*/
2662 /* but set it later when we know it */
2664 /* for each entry push the data */
2667 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2670 tmp_list
= qt_handle
->tmp_list
;
2672 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2673 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2675 sid_len
= sid_size(&tmp_list
->quotas
->sid
);
2676 entry_len
= 40 + sid_len
;
2678 /* nextoffset entry 4 bytes */
2679 SIVAL(entry
,0,entry_len
);
2681 /* then the len of the SID 4 bytes */
2682 SIVAL(entry
,4,sid_len
);
2684 /* unknown data 8 bytes SMB_BIG_UINT */
2685 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2687 /* the used disk space 8 bytes SMB_BIG_UINT */
2688 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2690 /* the soft quotas 8 bytes SMB_BIG_UINT */
2691 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2693 /* the hard quotas 8 bytes SMB_BIG_UINT */
2694 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2696 /* and now the SID */
2697 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2700 qt_handle
->tmp_list
= tmp_list
;
2702 /* overwrite the offset of the last entry */
2703 SIVAL(entry
-entry_len
,0,0);
2705 data_len
= 4+qt_len
;
2706 /* overwrite the params quota_data_len */
2707 SIVAL(params
,0,data_len
);
2711 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2713 /* unknown 4 bytes IVAL(pdata,0) */
2715 if (data_count
< 8) {
2716 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2717 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2720 sid_len
= IVAL(pdata
,4);
2721 /* Ensure this is less than 1mb. */
2722 if (sid_len
> (1024*1024)) {
2723 return ERROR_DOS(ERRDOS
,ERRnomem
);
2726 if (data_count
< 8+sid_len
) {
2727 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2728 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2731 data_len
= 4+40+sid_len
;
2733 if (max_data_count
< data_len
) {
2734 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2735 max_data_count
, data_len
));
2737 SIVAL(params
,0,data_len
);
2739 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2743 sid_parse(pdata
+8,sid_len
,&sid
);
2745 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2748 * we have to return zero's in all fields
2749 * instead of returning an error here
2754 /* Realloc the size of parameters and data we will return */
2756 params
= nttrans_realloc(ppparams
, param_len
);
2757 if(params
== NULL
) {
2758 return ERROR_DOS(ERRDOS
,ERRnomem
);
2761 pdata
= nttrans_realloc(ppdata
, data_len
);
2763 return ERROR_DOS(ERRDOS
,ERRnomem
);
2768 /* set params Size of returned Quota Data 4 bytes*/
2769 SIVAL(params
,0,data_len
);
2771 /* nextoffset entry 4 bytes */
2774 /* then the len of the SID 4 bytes */
2775 SIVAL(entry
,4,sid_len
);
2777 /* unknown data 8 bytes SMB_BIG_UINT */
2778 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2780 /* the used disk space 8 bytes SMB_BIG_UINT */
2781 SBIG_UINT(entry
,16,qt
.usedspace
);
2783 /* the soft quotas 8 bytes SMB_BIG_UINT */
2784 SBIG_UINT(entry
,24,qt
.softlim
);
2786 /* the hard quotas 8 bytes SMB_BIG_UINT */
2787 SBIG_UINT(entry
,32,qt
.hardlim
);
2789 /* and now the SID */
2790 sid_linearize(entry
+40, sid_len
, &sid
);
2795 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2796 return ERROR_DOS(ERRSRV
,ERRerror
);
2800 send_nt_replies(inbuf
, outbuf
, bufsize
, nt_status
, params
, param_len
,
2806 /****************************************************************************
2807 Reply to set user quota
2808 ****************************************************************************/
2810 static int call_nt_transact_set_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2811 uint16
**ppsetup
, uint32 setup_count
,
2812 char **ppparams
, uint32 parameter_count
,
2813 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2815 char *params
= *ppparams
;
2816 char *pdata
= *ppdata
;
2817 int data_len
=0,param_len
=0;
2818 SMB_NTQUOTA_STRUCT qt
;
2821 files_struct
*fsp
= NULL
;
2826 if (current_user
.ut
.uid
!= 0) {
2827 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2828 lp_servicename(SNUM(conn
)),conn
->user
));
2829 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2833 * Ensure minimum number of parameters sent.
2836 if (parameter_count
< 2) {
2837 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2838 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2841 /* maybe we can check the quota_fnum */
2842 fsp
= file_fsp(params
,0);
2843 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2844 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2845 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2848 if (data_count
< 40) {
2849 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2850 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2853 /* offset to next quota record.
2854 * 4 bytes IVAL(pdata,0)
2859 sid_len
= IVAL(pdata
,4);
2861 if (data_count
< 40+sid_len
) {
2862 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2863 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2866 /* unknown 8 bytes in pdata
2867 * maybe its the change time in NTTIME
2870 /* the used space 8 bytes (SMB_BIG_UINT)*/
2871 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2872 #ifdef LARGE_SMB_OFF_T
2873 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2874 #else /* LARGE_SMB_OFF_T */
2875 if ((IVAL(pdata
,20) != 0)&&
2876 ((qt
.usedspace
!= 0xFFFFFFFF)||
2877 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2878 /* more than 32 bits? */
2879 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2881 #endif /* LARGE_SMB_OFF_T */
2883 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2884 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2885 #ifdef LARGE_SMB_OFF_T
2886 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2887 #else /* LARGE_SMB_OFF_T */
2888 if ((IVAL(pdata
,28) != 0)&&
2889 ((qt
.softlim
!= 0xFFFFFFFF)||
2890 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2891 /* more than 32 bits? */
2892 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2894 #endif /* LARGE_SMB_OFF_T */
2896 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2897 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2898 #ifdef LARGE_SMB_OFF_T
2899 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2900 #else /* LARGE_SMB_OFF_T */
2901 if ((IVAL(pdata
,36) != 0)&&
2902 ((qt
.hardlim
!= 0xFFFFFFFF)||
2903 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2904 /* more than 32 bits? */
2905 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2907 #endif /* LARGE_SMB_OFF_T */
2909 sid_parse(pdata
+40,sid_len
,&sid
);
2910 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid
)));
2912 /* 44 unknown bytes left... */
2914 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2915 return ERROR_DOS(ERRSRV
,ERRerror
);
2918 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
,
2923 #endif /* HAVE_SYS_QUOTAS */
2925 static int handle_nttrans(connection_struct
*conn
,
2926 struct trans_state
*state
,
2927 char *inbuf
, char *outbuf
, int size
, int bufsize
)
2931 if (Protocol
>= PROTOCOL_NT1
) {
2932 SSVAL(outbuf
,smb_flg2
,SVAL(outbuf
,smb_flg2
) | 0x40); /* IS_LONG_NAME */
2935 /* Now we must call the relevant NT_TRANS function */
2936 switch(state
->call
) {
2937 case NT_TRANSACT_CREATE
:
2939 START_PROFILE(NT_transact_create
);
2940 outsize
= call_nt_transact_create(conn
, inbuf
, outbuf
,
2942 &state
->setup
, state
->setup_count
,
2943 &state
->param
, state
->total_param
,
2944 &state
->data
, state
->total_data
,
2945 state
->max_data_return
);
2946 END_PROFILE(NT_transact_create
);
2950 case NT_TRANSACT_IOCTL
:
2952 START_PROFILE(NT_transact_ioctl
);
2953 outsize
= call_nt_transact_ioctl(conn
, inbuf
, outbuf
,
2955 &state
->setup
, state
->setup_count
,
2956 &state
->param
, state
->total_param
,
2957 &state
->data
, state
->total_data
, state
->max_data_return
);
2958 END_PROFILE(NT_transact_ioctl
);
2962 case NT_TRANSACT_SET_SECURITY_DESC
:
2964 START_PROFILE(NT_transact_set_security_desc
);
2965 outsize
= call_nt_transact_set_security_desc(conn
, inbuf
, outbuf
,
2967 &state
->setup
, state
->setup_count
,
2968 &state
->param
, state
->total_param
,
2969 &state
->data
, state
->total_data
, state
->max_data_return
);
2970 END_PROFILE(NT_transact_set_security_desc
);
2974 case NT_TRANSACT_NOTIFY_CHANGE
:
2976 START_PROFILE(NT_transact_notify_change
);
2977 outsize
= call_nt_transact_notify_change(
2978 conn
, inbuf
, outbuf
, size
, bufsize
,
2979 &state
->setup
, state
->setup_count
,
2980 &state
->param
, state
->total_param
,
2981 &state
->data
, state
->total_data
,
2982 state
->max_data_return
,
2983 state
->max_param_return
);
2984 END_PROFILE(NT_transact_notify_change
);
2988 case NT_TRANSACT_RENAME
:
2990 START_PROFILE(NT_transact_rename
);
2991 outsize
= call_nt_transact_rename(conn
, inbuf
, outbuf
,
2993 &state
->setup
, state
->setup_count
,
2994 &state
->param
, state
->total_param
,
2995 &state
->data
, state
->total_data
, state
->max_data_return
);
2996 END_PROFILE(NT_transact_rename
);
3000 case NT_TRANSACT_QUERY_SECURITY_DESC
:
3002 START_PROFILE(NT_transact_query_security_desc
);
3003 outsize
= call_nt_transact_query_security_desc(conn
, inbuf
, outbuf
,
3005 &state
->setup
, state
->setup_count
,
3006 &state
->param
, state
->total_param
,
3007 &state
->data
, state
->total_data
, state
->max_data_return
);
3008 END_PROFILE(NT_transact_query_security_desc
);
3012 #ifdef HAVE_SYS_QUOTAS
3013 case NT_TRANSACT_GET_USER_QUOTA
:
3015 START_PROFILE(NT_transact_get_user_quota
);
3016 outsize
= call_nt_transact_get_user_quota(conn
, inbuf
, outbuf
,
3018 &state
->setup
, state
->setup_count
,
3019 &state
->param
, state
->total_param
,
3020 &state
->data
, state
->total_data
, state
->max_data_return
);
3021 END_PROFILE(NT_transact_get_user_quota
);
3025 case NT_TRANSACT_SET_USER_QUOTA
:
3027 START_PROFILE(NT_transact_set_user_quota
);
3028 outsize
= call_nt_transact_set_user_quota(conn
, inbuf
, outbuf
,
3030 &state
->setup
, state
->setup_count
,
3031 &state
->param
, state
->total_param
,
3032 &state
->data
, state
->total_data
, state
->max_data_return
);
3033 END_PROFILE(NT_transact_set_user_quota
);
3036 #endif /* HAVE_SYS_QUOTAS */
3039 /* Error in request */
3040 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n",
3042 return ERROR_DOS(ERRSRV
,ERRerror
);
3047 /****************************************************************************
3048 Reply to a SMBNTtrans.
3049 ****************************************************************************/
3051 int reply_nttrans(connection_struct
*conn
,
3052 char *inbuf
,char *outbuf
,int size
,int bufsize
)
3055 uint32 pscnt
= IVAL(inbuf
,smb_nt_ParameterCount
);
3056 uint32 psoff
= IVAL(inbuf
,smb_nt_ParameterOffset
);
3057 uint32 dscnt
= IVAL(inbuf
,smb_nt_DataCount
);
3058 uint32 dsoff
= IVAL(inbuf
,smb_nt_DataOffset
);
3060 uint16 function_code
= SVAL( inbuf
, smb_nt_Function
);
3062 struct trans_state
*state
;
3064 START_PROFILE(SMBnttrans
);
3066 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
3067 END_PROFILE(SMBnttrans
);
3068 return ERROR_DOS(ERRSRV
,ERRaccess
);
3071 result
= allow_new_trans(conn
->pending_trans
, SVAL(inbuf
, smb_mid
));
3072 if (!NT_STATUS_IS_OK(result
)) {
3073 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
3074 END_PROFILE(SMBnttrans
);
3075 return ERROR_NT(result
);
3078 if ((state
= TALLOC_P(conn
->mem_ctx
, struct trans_state
)) == NULL
) {
3079 END_PROFILE(SMBnttrans
);
3080 return ERROR_DOS(ERRSRV
,ERRaccess
);
3083 state
->cmd
= SMBnttrans
;
3085 state
->mid
= SVAL(inbuf
,smb_mid
);
3086 state
->vuid
= SVAL(inbuf
,smb_uid
);
3087 state
->total_data
= IVAL(inbuf
, smb_nt_TotalDataCount
);
3089 state
->total_param
= IVAL(inbuf
, smb_nt_TotalParameterCount
);
3090 state
->param
= NULL
;
3091 state
->max_data_return
= IVAL(inbuf
,smb_nt_MaxDataCount
);
3092 state
->max_param_return
= IVAL(inbuf
,smb_nt_MaxParameterCount
);
3094 /* setup count is in *words* */
3095 state
->setup_count
= 2*CVAL(inbuf
,smb_nt_SetupCount
);
3096 state
->setup
= NULL
;
3097 state
->call
= function_code
;
3100 * All nttrans messages we handle have smb_wct == 19 +
3101 * state->setup_count. Ensure this is so as a sanity check.
3104 if(CVAL(inbuf
, smb_wct
) != 19 + (state
->setup_count
/2)) {
3105 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
3106 CVAL(inbuf
, smb_wct
), 19 + (state
->setup_count
/2)));
3110 /* Don't allow more than 128mb for each value. */
3111 if ((state
->total_data
> (1024*1024*128)) ||
3112 (state
->total_param
> (1024*1024*128))) {
3113 END_PROFILE(SMBnttrans
);
3114 return ERROR_DOS(ERRDOS
,ERRnomem
);
3117 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
3120 if (state
->total_data
) {
3121 /* Can't use talloc here, the core routines do realloc on the
3122 * params and data. */
3123 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
3124 DEBUG(0,("reply_nttrans: data malloc fail for %u "
3125 "bytes !\n", (unsigned int)state
->total_data
));
3127 END_PROFILE(SMBnttrans
);
3128 return(ERROR_DOS(ERRDOS
,ERRnomem
));
3130 if ((dsoff
+dscnt
< dsoff
) || (dsoff
+dscnt
< dscnt
))
3132 if ((smb_base(inbuf
)+dsoff
+dscnt
> inbuf
+ size
) ||
3133 (smb_base(inbuf
)+dsoff
+dscnt
< smb_base(inbuf
)))
3136 memcpy(state
->data
,smb_base(inbuf
)+dsoff
,dscnt
);
3139 if (state
->total_param
) {
3140 /* Can't use talloc here, the core routines do realloc on the
3141 * params and data. */
3142 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
3143 DEBUG(0,("reply_nttrans: param malloc fail for %u "
3144 "bytes !\n", (unsigned int)state
->total_param
));
3145 SAFE_FREE(state
->data
);
3147 END_PROFILE(SMBnttrans
);
3148 return(ERROR_DOS(ERRDOS
,ERRnomem
));
3150 if ((psoff
+pscnt
< psoff
) || (psoff
+pscnt
< pscnt
))
3152 if ((smb_base(inbuf
)+psoff
+pscnt
> inbuf
+ size
) ||
3153 (smb_base(inbuf
)+psoff
+pscnt
< smb_base(inbuf
)))
3156 memcpy(state
->param
,smb_base(inbuf
)+psoff
,pscnt
);
3159 state
->received_data
= dscnt
;
3160 state
->received_param
= pscnt
;
3162 if(state
->setup_count
> 0) {
3163 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
3164 state
->setup_count
));
3165 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
3166 if (state
->setup
== NULL
) {
3167 DEBUG(0,("reply_nttrans : Out of memory\n"));
3168 SAFE_FREE(state
->data
);
3169 SAFE_FREE(state
->param
);
3171 END_PROFILE(SMBnttrans
);
3172 return ERROR_DOS(ERRDOS
,ERRnomem
);
3175 if ((smb_nt_SetupStart
+ state
->setup_count
< smb_nt_SetupStart
) ||
3176 (smb_nt_SetupStart
+ state
->setup_count
< state
->setup_count
)) {
3179 if (smb_nt_SetupStart
+ state
->setup_count
> size
) {
3183 memcpy( state
->setup
, &inbuf
[smb_nt_SetupStart
], state
->setup_count
);
3184 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
3187 if ((state
->received_data
== state
->total_data
) &&
3188 (state
->received_param
== state
->total_param
)) {
3189 outsize
= handle_nttrans(conn
, state
, inbuf
, outbuf
,
3191 SAFE_FREE(state
->param
);
3192 SAFE_FREE(state
->data
);
3194 END_PROFILE(SMBnttrans
);
3198 DLIST_ADD(conn
->pending_trans
, state
);
3200 /* We need to send an interim response then receive the rest
3201 of the parameter/data bytes */
3202 outsize
= set_message(inbuf
,outbuf
,0,0,False
);
3204 END_PROFILE(SMBnttrans
);
3209 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3210 SAFE_FREE(state
->data
);
3211 SAFE_FREE(state
->param
);
3213 END_PROFILE(SMBnttrans
);
3214 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
3217 /****************************************************************************
3218 Reply to a SMBnttranss
3219 ****************************************************************************/
3221 int reply_nttranss(connection_struct
*conn
, char *inbuf
,char *outbuf
,
3222 int size
,int bufsize
)
3225 unsigned int pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
3226 struct trans_state
*state
;
3228 START_PROFILE(SMBnttranss
);
3232 for (state
= conn
->pending_trans
; state
!= NULL
;
3233 state
= state
->next
) {
3234 if (state
->mid
== SVAL(inbuf
,smb_mid
)) {
3239 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
3240 END_PROFILE(SMBnttranss
);
3241 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
3244 /* Revise state->total_param and state->total_data in case they have
3245 changed downwards */
3246 if (IVAL(inbuf
, smb_nts_TotalParameterCount
) < state
->total_param
) {
3247 state
->total_param
= IVAL(inbuf
, smb_nts_TotalParameterCount
);
3249 if (IVAL(inbuf
, smb_nts_TotalDataCount
) < state
->total_data
) {
3250 state
->total_data
= IVAL(inbuf
, smb_nts_TotalDataCount
);
3253 pcnt
= IVAL(inbuf
,smb_nts_ParameterCount
);
3254 poff
= IVAL(inbuf
, smb_nts_ParameterOffset
);
3255 pdisp
= IVAL(inbuf
, smb_nts_ParameterDisplacement
);
3257 dcnt
= IVAL(inbuf
, smb_nts_DataCount
);
3258 ddisp
= IVAL(inbuf
, smb_nts_DataDisplacement
);
3259 doff
= IVAL(inbuf
, smb_nts_DataOffset
);
3261 state
->received_param
+= pcnt
;
3262 state
->received_data
+= dcnt
;
3264 if ((state
->received_data
> state
->total_data
) ||
3265 (state
->received_param
> state
->total_param
))
3269 if (pdisp
+pcnt
> state
->total_param
)
3271 if ((pdisp
+pcnt
< pdisp
) || (pdisp
+pcnt
< pcnt
))
3273 if (pdisp
> state
->total_param
)
3275 if ((smb_base(inbuf
) + poff
+ pcnt
> inbuf
+ size
) ||
3276 (smb_base(inbuf
) + poff
+ pcnt
< smb_base(inbuf
)))
3278 if (state
->param
+ pdisp
< state
->param
)
3281 memcpy(state
->param
+pdisp
,smb_base(inbuf
)+poff
,
3286 if (ddisp
+dcnt
> state
->total_data
)
3288 if ((ddisp
+dcnt
< ddisp
) || (ddisp
+dcnt
< dcnt
))
3290 if (ddisp
> state
->total_data
)
3292 if ((smb_base(inbuf
) + doff
+ dcnt
> inbuf
+ size
) ||
3293 (smb_base(inbuf
) + doff
+ dcnt
< smb_base(inbuf
)))
3295 if (state
->data
+ ddisp
< state
->data
)
3298 memcpy(state
->data
+ddisp
, smb_base(inbuf
)+doff
,
3302 if ((state
->received_param
< state
->total_param
) ||
3303 (state
->received_data
< state
->total_data
)) {
3304 END_PROFILE(SMBnttranss
);
3308 /* construct_reply_common has done us the favor to pre-fill the
3309 * command field with SMBnttranss which is wrong :-)
3311 SCVAL(outbuf
,smb_com
,SMBnttrans
);
3313 outsize
= handle_nttrans(conn
, state
, inbuf
, outbuf
,
3316 DLIST_REMOVE(conn
->pending_trans
, state
);
3317 SAFE_FREE(state
->data
);
3318 SAFE_FREE(state
->param
);
3322 END_PROFILE(SMBnttranss
);
3323 return(ERROR_DOS(ERRSRV
,ERRnosupport
));
3326 END_PROFILE(SMBnttranss
);
3331 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3332 DLIST_REMOVE(conn
->pending_trans
, state
);
3333 SAFE_FREE(state
->data
);
3334 SAFE_FREE(state
->param
);
3336 END_PROFILE(SMBnttranss
);
3337 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);