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 3 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, see <http://www.gnu.org/licenses/>.
24 extern enum protocol_types Protocol
;
25 extern int smb_read_error
;
26 extern struct current_user current_user
;
28 static const char *known_nt_pipes
[] = {
49 static char *nttrans_realloc(char **ptr
, size_t size
)
52 smb_panic("nttrans_realloc() called with NULL ptr");
55 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
59 memset(*ptr
,'\0',size
);
63 /****************************************************************************
64 Send the required number of replies back.
65 We assume all fields other than the data fields are
66 set correctly for the type of call.
67 HACK ! Always assumes smb_setup field is zero.
68 ****************************************************************************/
70 int send_nt_replies(const char *inbuf
,
79 int data_to_send
= datasize
;
80 int params_to_send
= paramsize
;
84 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
85 int alignment_offset
= 3;
86 int data_alignment_offset
= 0;
89 * Initially set the wcnt area to be 18 - this is true for all
93 set_message(inbuf
,outbuf
,18,0,True
);
95 if (NT_STATUS_V(nt_error
)) {
100 * If there genuinely are no parameters or data to send just send
104 if(params_to_send
== 0 && data_to_send
== 0) {
106 if (!send_smb(smbd_server_fd(),outbuf
)) {
107 exit_server_cleanly("send_nt_replies: send_smb failed.");
113 * When sending params and data ensure that both are nicely aligned.
114 * Only do this alignment when there is also data to send - else
115 * can cause NT redirector problems.
118 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
119 data_alignment_offset
= 4 - (params_to_send
% 4);
123 * Space is bufsize minus Netbios over TCP header minus SMB header.
124 * The alignment_offset is to align the param bytes on a four byte
125 * boundary (2 bytes for data len, one byte pad).
126 * NT needs this to work correctly.
129 useable_space
= bufsize
- ((smb_buf(outbuf
)+
130 alignment_offset
+data_alignment_offset
) -
134 * useable_space can never be more than max_send minus the
138 useable_space
= MIN(useable_space
,
139 max_send
- (alignment_offset
+data_alignment_offset
));
142 while (params_to_send
|| data_to_send
) {
145 * Calculate whether we will totally or partially fill this packet.
148 total_sent_thistime
= params_to_send
+ data_to_send
+
149 alignment_offset
+ data_alignment_offset
;
152 * We can never send more than useable_space.
155 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
157 set_message(inbuf
,outbuf
, 18, total_sent_thistime
, True
);
160 * Set total params and data to be sent.
163 SIVAL(outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
164 SIVAL(outbuf
,smb_ntr_TotalDataCount
,datasize
);
167 * Calculate how many parameters and data we can fit into
168 * this packet. Parameters get precedence.
171 params_sent_thistime
= MIN(params_to_send
,useable_space
);
172 data_sent_thistime
= useable_space
- params_sent_thistime
;
173 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
175 SIVAL(outbuf
,smb_ntr_ParameterCount
,params_sent_thistime
);
177 if(params_sent_thistime
== 0) {
178 SIVAL(outbuf
,smb_ntr_ParameterOffset
,0);
179 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,0);
182 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
183 * parameter bytes, however the first 4 bytes of outbuf are
184 * the Netbios over TCP header. Thus use smb_base() to subtract
185 * them from the calculation.
188 SIVAL(outbuf
,smb_ntr_ParameterOffset
,
189 ((smb_buf(outbuf
)+alignment_offset
) - smb_base(outbuf
)));
191 * Absolute displacement of param bytes sent in this packet.
194 SIVAL(outbuf
,smb_ntr_ParameterDisplacement
,pp
- params
);
198 * Deal with the data portion.
201 SIVAL(outbuf
,smb_ntr_DataCount
, data_sent_thistime
);
203 if(data_sent_thistime
== 0) {
204 SIVAL(outbuf
,smb_ntr_DataOffset
,0);
205 SIVAL(outbuf
,smb_ntr_DataDisplacement
, 0);
208 * The offset of the data bytes is the offset of the
209 * parameter bytes plus the number of parameters being sent this time.
212 SIVAL(outbuf
,smb_ntr_DataOffset
,((smb_buf(outbuf
)+alignment_offset
) -
213 smb_base(outbuf
)) + params_sent_thistime
+ data_alignment_offset
);
214 SIVAL(outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
218 * Copy the param bytes into the packet.
221 if(params_sent_thistime
) {
222 memcpy((smb_buf(outbuf
)+alignment_offset
),pp
,params_sent_thistime
);
226 * Copy in the data bytes
229 if(data_sent_thistime
) {
230 memcpy(smb_buf(outbuf
)+alignment_offset
+params_sent_thistime
+
231 data_alignment_offset
,pd
,data_sent_thistime
);
234 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
235 params_sent_thistime
, data_sent_thistime
, useable_space
));
236 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
237 params_to_send
, data_to_send
, paramsize
, datasize
));
239 /* Send the packet */
241 if (!send_smb(smbd_server_fd(),outbuf
)) {
242 exit_server_cleanly("send_nt_replies: send_smb failed.");
245 pp
+= params_sent_thistime
;
246 pd
+= data_sent_thistime
;
248 params_to_send
-= params_sent_thistime
;
249 data_to_send
-= data_sent_thistime
;
255 if(params_to_send
< 0 || data_to_send
< 0) {
256 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
257 params_to_send
, data_to_send
));
265 /****************************************************************************
266 Is it an NTFS stream name ?
267 ****************************************************************************/
269 BOOL
is_ntfs_stream_name(const char *fname
)
271 if (lp_posix_pathnames()) {
274 return (strchr_m(fname
, ':') != NULL
) ? True
: False
;
277 struct case_semantics_state
{
278 connection_struct
*conn
;
281 BOOL short_case_preserve
;
284 /****************************************************************************
285 Restore case semantics.
286 ****************************************************************************/
287 static int restore_case_semantics(struct case_semantics_state
*state
)
289 state
->conn
->case_sensitive
= state
->case_sensitive
;
290 state
->conn
->case_preserve
= state
->case_preserve
;
291 state
->conn
->short_case_preserve
= state
->short_case_preserve
;
295 /****************************************************************************
297 ****************************************************************************/
298 static struct case_semantics_state
*set_posix_case_semantics(TALLOC_CTX
*mem_ctx
,
299 connection_struct
*conn
)
301 struct case_semantics_state
*result
;
303 if (!(result
= talloc(mem_ctx
, struct case_semantics_state
))) {
304 DEBUG(0, ("talloc failed\n"));
309 result
->case_sensitive
= conn
->case_sensitive
;
310 result
->case_preserve
= conn
->case_preserve
;
311 result
->short_case_preserve
= conn
->short_case_preserve
;
314 conn
->case_sensitive
= True
;
315 conn
->case_preserve
= True
;
316 conn
->short_case_preserve
= True
;
318 talloc_set_destructor(result
, restore_case_semantics
);
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 share_access
= IVAL(inbuf
,smb_ntcreate_ShareAccess
);
491 uint32 create_disposition
= IVAL(inbuf
,smb_ntcreate_CreateDisposition
);
492 uint32 create_options
= IVAL(inbuf
,smb_ntcreate_CreateOptions
);
493 uint16 root_dir_fid
= (uint16
)IVAL(inbuf
,smb_ntcreate_RootDirectoryFid
);
494 /* Breakout the oplock request bits so we can set the
495 reply bits separately. */
496 int oplock_request
= 0;
498 SMB_OFF_T file_len
= 0;
499 SMB_STRUCT_STAT sbuf
;
501 files_struct
*fsp
= NULL
;
503 struct timespec c_timespec
;
504 struct timespec a_timespec
;
505 struct timespec m_timespec
;
506 BOOL extended_oplock_granted
= False
;
508 struct smb_request req
;
509 struct case_semantics_state
*case_state
= NULL
;
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 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
680 case_state
= set_posix_case_semantics(NULL
, conn
);
681 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
684 status
= unix_convert(conn
, fname
, False
, NULL
, &sbuf
);
685 if (!NT_STATUS_IS_OK(status
)) {
686 TALLOC_FREE(case_state
);
687 END_PROFILE(SMBntcreateX
);
688 return ERROR_NT(status
);
690 /* All file access must go through check_name() */
691 status
= check_name(conn
, fname
);
692 if (!NT_STATUS_IS_OK(status
)) {
693 TALLOC_FREE(case_state
);
694 END_PROFILE(SMBntcreateX
);
695 return ERROR_NT(status
);
698 /* This is the correct thing to do (check every time) but can_delete is
699 expensive (it may have to read the parent directory permissions). So
700 for now we're not doing it unless we have a strong hint the client
701 is really going to delete this file. If the client is forcing FILE_CREATE
702 let the filesystem take care of the permissions. */
704 /* Setting FILE_SHARE_DELETE is the hint. */
706 if (lp_acl_check_permissions(SNUM(conn
))
707 && (create_disposition
!= FILE_CREATE
)
708 && (share_access
& FILE_SHARE_DELETE
)
709 && (access_mask
& DELETE_ACCESS
)) {
710 if ((dos_mode(conn
, fname
, &sbuf
) & FILE_ATTRIBUTE_READONLY
) ||
711 !can_delete_file_in_directory(conn
, fname
)) {
712 TALLOC_FREE(case_state
);
713 END_PROFILE(SMBntcreateX
);
714 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
719 /* We need to support SeSecurityPrivilege for this. */
720 if ((access_mask
& SEC_RIGHT_SYSTEM_SECURITY
) &&
721 !user_has_privileges(current_user
.nt_user_token
,
723 TALLOC_FREE(case_state
);
724 END_PROFILE(SMBntcreateX
);
725 return ERROR_NT(NT_STATUS_PRIVILEGE_NOT_HELD
);
730 * If it's a request for a directory open, deal with it separately.
733 if(create_options
& FILE_DIRECTORY_FILE
) {
735 /* Can't open a temp directory. IFS kit test. */
736 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
737 TALLOC_FREE(case_state
);
738 END_PROFILE(SMBntcreateX
);
739 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
743 status
= open_directory(conn
, &req
, fname
, &sbuf
,
751 TALLOC_FREE(case_state
);
753 if(!NT_STATUS_IS_OK(status
)) {
754 if (!use_nt_status() && NT_STATUS_EQUAL(
755 status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
756 status
= NT_STATUS_DOS(ERRDOS
, ERRfilexists
);
758 END_PROFILE(SMBntcreateX
);
759 return ERROR_NT(status
);
765 * Ordinary file case.
768 /* NB. We have a potential bug here. If we
769 * cause an oplock break to ourselves, then we
770 * could end up processing filename related
771 * SMB requests whilst we await the oplock
772 * break response. As we may have changed the
773 * filename case semantics to be POSIX-like,
774 * this could mean a filename request could
775 * fail when it should succeed. This is a rare
776 * condition, but eventually we must arrange
777 * to restore the correct case semantics
778 * before issuing an oplock break request to
779 * our client. JRA. */
781 status
= open_file_ntcreate(conn
, &req
, fname
, &sbuf
,
790 if (!NT_STATUS_IS_OK(status
)) {
791 /* We cheat here. There are two cases we
792 * care about. One is a directory rename,
793 * where the NT client will attempt to
794 * open the source directory for
795 * DELETE access. Note that when the
796 * NT client does this it does *not*
797 * set the directory bit in the
798 * request packet. This is translated
799 * into a read/write open
800 * request. POSIX states that any open
801 * for write request on a directory
802 * will generate an EISDIR error, so
803 * we can catch this here and open a
804 * pseudo handle that is flagged as a
805 * directory. The second is an open
806 * for a permissions read only, which
807 * we handle in the open_file_stat case. JRA.
810 if (NT_STATUS_EQUAL(status
,
811 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
814 * Fail the open if it was explicitly a non-directory file.
817 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
818 TALLOC_FREE(case_state
);
819 END_PROFILE(SMBntcreateX
);
820 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
824 status
= open_directory(conn
, &req
, fname
,
833 if(!NT_STATUS_IS_OK(status
)) {
834 TALLOC_FREE(case_state
);
835 if (!use_nt_status() && NT_STATUS_EQUAL(
836 status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
837 status
= NT_STATUS_DOS(ERRDOS
, ERRfilexists
);
839 END_PROFILE(SMBntcreateX
);
840 return ERROR_NT(status
);
843 TALLOC_FREE(case_state
);
844 END_PROFILE(SMBntcreateX
);
845 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
846 /* We have re-scheduled this call. */
849 return ERROR_NT(status
);
854 TALLOC_FREE(case_state
);
856 file_len
= sbuf
.st_size
;
857 fattr
= dos_mode(conn
,fname
,&sbuf
);
859 fattr
= FILE_ATTRIBUTE_NORMAL
;
861 if (!fsp
->is_directory
&& (fattr
& aDIR
)) {
862 close_file(fsp
,ERROR_CLOSE
);
863 END_PROFILE(SMBntcreateX
);
864 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
867 /* Save the requested allocation size. */
868 if ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
)) {
869 SMB_BIG_UINT allocation_size
= (SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
);
870 #ifdef LARGE_SMB_OFF_T
871 allocation_size
|= (((SMB_BIG_UINT
)IVAL(inbuf
,smb_ntcreate_AllocationSize
+ 4)) << 32);
873 if (allocation_size
&& (allocation_size
> (SMB_BIG_UINT
)file_len
)) {
874 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, allocation_size
);
875 if (fsp
->is_directory
) {
876 close_file(fsp
,ERROR_CLOSE
);
877 END_PROFILE(SMBntcreateX
);
878 /* Can't set allocation size on a directory. */
879 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
881 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
882 close_file(fsp
,ERROR_CLOSE
);
883 END_PROFILE(SMBntcreateX
);
884 return ERROR_NT(NT_STATUS_DISK_FULL
);
887 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
,(SMB_BIG_UINT
)file_len
);
892 * If the caller set the extended oplock request bit
893 * and we granted one (by whatever means) - set the
894 * correct bit for extended oplock reply.
897 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
898 extended_oplock_granted
= True
;
901 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
)) {
902 extended_oplock_granted
= True
;
905 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
906 /* This is very strange. We
907 * return 50 words, but only set
908 * the wcnt to 42 ? It's definately
909 * what happens on the wire....
911 set_message(inbuf
,outbuf
,50,0,True
);
912 SCVAL(outbuf
,smb_wct
,42);
914 set_message(inbuf
,outbuf
,34,0,True
);
917 p
= outbuf
+ smb_vwv2
;
920 * Currently as we don't support level II oplocks we just report
921 * exclusive & batch here.
924 if (extended_oplock_granted
) {
925 if (flags
& REQUEST_BATCH_OPLOCK
) {
926 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
928 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
930 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
931 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
933 SCVAL(p
,0,NO_OPLOCK_RETURN
);
937 SSVAL(p
,0,fsp
->fnum
);
939 if ((create_disposition
== FILE_SUPERSEDE
) && (info
== FILE_WAS_OVERWRITTEN
)) {
940 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
947 c_timespec
= get_create_timespec(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
948 a_timespec
= get_atimespec(&sbuf
);
949 m_timespec
= get_mtimespec(&sbuf
);
951 if (lp_dos_filetime_resolution(SNUM(conn
))) {
952 dos_filetime_timespec(&c_timespec
);
953 dos_filetime_timespec(&a_timespec
);
954 dos_filetime_timespec(&m_timespec
);
957 put_long_date_timespec(p
, c_timespec
); /* create time. */
959 put_long_date_timespec(p
, a_timespec
); /* access time */
961 put_long_date_timespec(p
, m_timespec
); /* write time */
963 put_long_date_timespec(p
, m_timespec
); /* change time */
965 SIVAL(p
,0,fattr
); /* File Attributes. */
967 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
969 SOFF_T(p
,0,file_len
);
971 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
975 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
977 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
980 if (fsp
->is_directory
|| can_write_to_file(conn
, fname
, &sbuf
)) {
981 perms
= FILE_GENERIC_ALL
;
983 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
988 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp
->fnum
, fsp
->fsp_name
));
990 result
= chain_reply(inbuf
,outbuf
,length
,bufsize
);
991 END_PROFILE(SMBntcreateX
);
995 /****************************************************************************
996 Reply to a NT_TRANSACT_CREATE call to open a pipe.
997 ****************************************************************************/
999 static int do_nt_transact_create_pipe( connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1000 uint16
**ppsetup
, uint32 setup_count
,
1001 char **ppparams
, uint32 parameter_count
,
1002 char **ppdata
, uint32 data_count
)
1005 char *params
= *ppparams
;
1014 * Ensure minimum number of parameters sent.
1017 if(parameter_count
< 54) {
1018 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1019 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1022 flags
= IVAL(params
,0);
1024 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
, params
+53,
1025 sizeof(fname
), parameter_count
-53, STR_TERMINATE
,
1027 if (!NT_STATUS_IS_OK(status
)) {
1028 return ERROR_NT(status
);
1031 if ((ret
= nt_open_pipe(fname
, conn
, inbuf
, outbuf
, &pnum
)) != 0) {
1035 /* Realloc the size of parameters and data we will return */
1036 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1037 /* Extended response is 32 more byyes. */
1042 params
= nttrans_realloc(ppparams
, param_len
);
1043 if(params
== NULL
) {
1044 return ERROR_DOS(ERRDOS
,ERRnomem
);
1048 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1053 SIVAL(p
,0,FILE_WAS_OPENED
);
1057 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
1060 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
1062 SSVAL(p
,2, 0x5FF); /* ? */
1065 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1067 SIVAL(p
,0,FILE_GENERIC_ALL
);
1069 * For pipes W2K3 seems to return
1071 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
1073 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
1076 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
1078 /* Send the required number of replies */
1079 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1084 /****************************************************************************
1085 Internal fn to set security descriptors.
1086 ****************************************************************************/
1088 static NTSTATUS
set_sd(files_struct
*fsp
, char *data
, uint32 sd_len
, uint32 security_info_sent
)
1091 SEC_DESC
*psd
= NULL
;
1092 TALLOC_CTX
*mem_ctx
;
1095 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
1096 return NT_STATUS_OK
;
1100 * Init the parse struct we will unmarshall from.
1103 if ((mem_ctx
= talloc_init("set_sd")) == NULL
) {
1104 DEBUG(0,("set_sd: talloc_init failed.\n"));
1105 return NT_STATUS_NO_MEMORY
;
1108 prs_init(&pd
, 0, mem_ctx
, UNMARSHALL
);
1111 * Setup the prs_struct to point at the memory we just
1115 prs_give_memory( &pd
, data
, sd_len
, False
);
1118 * Finally, unmarshall from the data buffer.
1121 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
1122 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1124 * Return access denied for want of a better error message..
1126 talloc_destroy(mem_ctx
);
1127 return NT_STATUS_NO_MEMORY
;
1130 if (psd
->owner_sid
==0) {
1131 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
1133 if (psd
->group_sid
==0) {
1134 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
1137 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
1140 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
1143 status
= SMB_VFS_FSET_NT_ACL( fsp
, fsp
->fh
->fd
, security_info_sent
, psd
);
1145 talloc_destroy(mem_ctx
);
1149 /****************************************************************************
1150 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
1151 ****************************************************************************/
1153 static struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
1155 struct ea_list
*ea_list_head
= NULL
;
1158 if (data_size
< 4) {
1162 while (offset
+ 4 <= data_size
) {
1163 size_t next_offset
= IVAL(pdata
,offset
);
1164 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
1170 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
1171 if (next_offset
== 0) {
1174 offset
+= next_offset
;
1177 return ea_list_head
;
1180 /****************************************************************************
1181 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1182 ****************************************************************************/
1184 static int call_nt_transact_create(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
1185 uint16
**ppsetup
, uint32 setup_count
,
1186 char **ppparams
, uint32 parameter_count
,
1187 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
1190 char *params
= *ppparams
;
1191 char *data
= *ppdata
;
1192 /* Breakout the oplock request bits so we can set the reply bits separately. */
1193 int oplock_request
= 0;
1195 SMB_OFF_T file_len
= 0;
1196 SMB_STRUCT_STAT sbuf
;
1198 files_struct
*fsp
= NULL
;
1200 BOOL extended_oplock_granted
= False
;
1203 uint32 file_attributes
;
1204 uint32 share_access
;
1205 uint32 create_disposition
;
1206 uint32 create_options
;
1209 uint16 root_dir_fid
;
1210 struct timespec c_timespec
;
1211 struct timespec a_timespec
;
1212 struct timespec m_timespec
;
1213 struct ea_list
*ea_list
= NULL
;
1214 TALLOC_CTX
*ctx
= NULL
;
1218 struct smb_request req
;
1219 struct case_semantics_state
*case_state
= NULL
;
1221 DEBUG(5,("call_nt_transact_create\n"));
1224 * If it's an IPC, use the pipe handler.
1228 if (lp_nt_pipe_support()) {
1229 return do_nt_transact_create_pipe(conn
, inbuf
, outbuf
, length
,
1231 ppsetup
, setup_count
,
1232 ppparams
, parameter_count
,
1233 ppdata
, data_count
);
1235 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1240 * Ensure minimum number of parameters sent.
1243 if(parameter_count
< 54) {
1244 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
1245 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1248 init_smb_request(&req
, (uint8
*)inbuf
);
1250 flags
= IVAL(params
,0);
1251 access_mask
= IVAL(params
,8);
1252 file_attributes
= IVAL(params
,20);
1253 share_access
= IVAL(params
,24);
1254 create_disposition
= IVAL(params
,28);
1255 create_options
= IVAL(params
,32);
1256 sd_len
= IVAL(params
,36);
1257 ea_len
= IVAL(params
,40);
1258 root_dir_fid
= (uint16
)IVAL(params
,4);
1260 /* Ensure the data_len is correct for the sd and ea values given. */
1261 if ((ea_len
+ sd_len
> data_count
) ||
1262 (ea_len
> data_count
) || (sd_len
> data_count
) ||
1263 (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
1264 DEBUG(10,("call_nt_transact_create - ea_len = %u, sd_len = %u, data_count = %u\n",
1265 (unsigned int)ea_len
, (unsigned int)sd_len
, (unsigned int)data_count
));
1266 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1270 if (!lp_ea_support(SNUM(conn
))) {
1271 DEBUG(10,("call_nt_transact_create - ea_len = %u but EA's not supported.\n",
1272 (unsigned int)ea_len
));
1273 return ERROR_NT(NT_STATUS_EAS_NOT_SUPPORTED
);
1277 DEBUG(10,("call_nt_transact_create - ea_len = %u - too small (should be more than 10)\n",
1278 (unsigned int)ea_len
));
1279 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1283 if (create_options
& FILE_OPEN_BY_FILE_ID
) {
1284 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
1288 * Get the file name.
1291 if(root_dir_fid
!= 0) {
1293 * This filename is relative to a directory fid.
1295 files_struct
*dir_fsp
= file_fsp(params
,4);
1296 size_t dir_name_len
;
1299 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1302 if(!dir_fsp
->is_directory
) {
1303 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
,
1304 params
+53, sizeof(fname
),
1305 parameter_count
-53, STR_TERMINATE
,
1307 if (!NT_STATUS_IS_OK(status
)) {
1308 return ERROR_NT(status
);
1312 * Check to see if this is a mac fork of some kind.
1315 if( is_ntfs_stream_name(fname
)) {
1316 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1319 return ERROR_DOS(ERRDOS
,ERRbadfid
);
1323 * Copy in the base directory name.
1326 pstrcpy( fname
, dir_fsp
->fsp_name
);
1327 dir_name_len
= strlen(fname
);
1330 * Ensure it ends in a '\'.
1333 if((fname
[dir_name_len
-1] != '\\') && (fname
[dir_name_len
-1] != '/')) {
1334 pstrcat(fname
, "/");
1340 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), tmpname
,
1341 params
+53, sizeof(tmpname
),
1342 parameter_count
-53, STR_TERMINATE
,
1344 if (!NT_STATUS_IS_OK(status
)) {
1345 return ERROR_NT(status
);
1347 pstrcat(fname
, tmpname
);
1350 srvstr_get_path(inbuf
, SVAL(inbuf
,smb_flg2
), fname
, params
+53,
1351 sizeof(fname
), parameter_count
-53,
1352 STR_TERMINATE
, &status
);
1353 if (!NT_STATUS_IS_OK(status
)) {
1354 return ERROR_NT(status
);
1358 * Check to see if this is a mac fork of some kind.
1361 if( is_ntfs_stream_name(fname
)) {
1362 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND
);
1366 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1367 if (oplock_request
) {
1368 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
) ? BATCH_OPLOCK
: 0;
1372 * Ordinary file or directory.
1376 * Check if POSIX semantics are wanted.
1379 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1380 case_state
= set_posix_case_semantics(NULL
, conn
);
1381 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1384 status
= resolve_dfspath(conn
, SVAL(inbuf
,smb_flg2
) & FLAGS2_DFS_PATHNAMES
, fname
);
1385 if (!NT_STATUS_IS_OK(status
)) {
1386 TALLOC_FREE(case_state
);
1387 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1388 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
1390 return ERROR_NT(status
);
1393 status
= unix_convert(conn
, fname
, False
, NULL
, &sbuf
);
1394 if (!NT_STATUS_IS_OK(status
)) {
1395 TALLOC_FREE(case_state
);
1396 return ERROR_NT(status
);
1398 /* All file access must go through check_name() */
1399 status
= check_name(conn
, fname
);
1400 if (!NT_STATUS_IS_OK(status
)) {
1401 TALLOC_FREE(case_state
);
1402 return ERROR_NT(status
);
1405 /* This is the correct thing to do (check every time) but can_delete is
1406 expensive (it may have to read the parent directory permissions). So
1407 for now we're not doing it unless we have a strong hint the client
1408 is really going to delete this file. If the client is forcing FILE_CREATE
1409 let the filesystem take care of the permissions. */
1411 /* Setting FILE_SHARE_DELETE is the hint. */
1413 if (lp_acl_check_permissions(SNUM(conn
))
1414 && (create_disposition
!= FILE_CREATE
)
1415 && (share_access
& FILE_SHARE_DELETE
)
1416 && (access_mask
& DELETE_ACCESS
)) {
1417 if ((dos_mode(conn
, fname
, &sbuf
) & FILE_ATTRIBUTE_READONLY
) ||
1418 !can_delete_file_in_directory(conn
, fname
)) {
1419 TALLOC_FREE(case_state
);
1420 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1425 /* We need to support SeSecurityPrivilege for this. */
1426 if ((access_mask
& SEC_RIGHT_SYSTEM_SECURITY
) &&
1427 !user_has_privileges(current_user
.nt_user_token
,
1429 TALLOC_FREE(case_state
);
1430 return ERROR_NT(NT_STATUS_PRIVILEGE_NOT_HELD
);
1435 pdata
= data
+ sd_len
;
1437 /* We have already checked that ea_len <= data_count here. */
1438 ea_list
= read_nttrans_ea_list(tmp_talloc_ctx(), pdata
,
1441 TALLOC_FREE(case_state
);
1442 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1447 * If it's a request for a directory open, deal with it separately.
1450 if(create_options
& FILE_DIRECTORY_FILE
) {
1452 /* Can't open a temp directory. IFS kit test. */
1453 if (file_attributes
& FILE_ATTRIBUTE_TEMPORARY
) {
1454 TALLOC_FREE(case_state
);
1455 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
1459 * We will get a create directory here if the Win32
1460 * app specified a security descriptor in the
1461 * CreateDirectory() call.
1465 status
= open_directory(conn
, &req
, fname
, &sbuf
,
1472 if(!NT_STATUS_IS_OK(status
)) {
1473 TALLOC_FREE(case_state
);
1474 return ERROR_NT(status
);
1480 * Ordinary file case.
1483 status
= open_file_ntcreate(conn
,&req
,fname
,&sbuf
,
1492 if (!NT_STATUS_IS_OK(status
)) {
1493 if (NT_STATUS_EQUAL(status
,
1494 NT_STATUS_FILE_IS_A_DIRECTORY
)) {
1497 * Fail the open if it was explicitly a non-directory file.
1500 if (create_options
& FILE_NON_DIRECTORY_FILE
) {
1501 TALLOC_FREE(case_state
);
1502 return ERROR_FORCE_NT(NT_STATUS_FILE_IS_A_DIRECTORY
);
1506 status
= open_directory(conn
, &req
, fname
,
1514 if(!NT_STATUS_IS_OK(status
)) {
1515 TALLOC_FREE(case_state
);
1516 return ERROR_NT(status
);
1519 TALLOC_FREE(case_state
);
1520 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1521 /* We have re-scheduled this call. */
1524 return ERROR_NT(status
);
1530 * According to the MS documentation, the only time the security
1531 * descriptor is applied to the opened file is iff we *created* the
1532 * file; an existing file stays the same.
1534 * Also, it seems (from observation) that you can open the file with
1535 * any access mask but you can still write the sd. We need to override
1536 * the granted access before we call set_sd
1537 * Patch for bug #2242 from Tom Lackemann <cessnatomny@yahoo.com>.
1540 if (lp_nt_acl_support(SNUM(conn
)) && sd_len
&& info
== FILE_WAS_CREATED
) {
1541 uint32 saved_access_mask
= fsp
->access_mask
;
1543 /* We have already checked that sd_len <= data_count here. */
1545 fsp
->access_mask
= FILE_GENERIC_ALL
;
1547 status
= set_sd( fsp
, data
, sd_len
, ALL_SECURITY_INFORMATION
);
1548 if (!NT_STATUS_IS_OK(status
)) {
1549 talloc_destroy(ctx
);
1550 close_file(fsp
,ERROR_CLOSE
);
1551 TALLOC_FREE(case_state
);
1552 return ERROR_NT(status
);
1554 fsp
->access_mask
= saved_access_mask
;
1557 if (ea_len
&& (info
== FILE_WAS_CREATED
)) {
1558 status
= set_ea(conn
, fsp
, fname
, ea_list
);
1559 if (!NT_STATUS_IS_OK(status
)) {
1560 close_file(fsp
,ERROR_CLOSE
);
1561 TALLOC_FREE(case_state
);
1562 return ERROR_NT(status
);
1566 TALLOC_FREE(case_state
);
1568 file_len
= sbuf
.st_size
;
1569 fattr
= dos_mode(conn
,fname
,&sbuf
);
1571 fattr
= FILE_ATTRIBUTE_NORMAL
;
1573 if (!fsp
->is_directory
&& (fattr
& aDIR
)) {
1574 close_file(fsp
,ERROR_CLOSE
);
1575 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
1578 /* Save the requested allocation size. */
1579 if ((info
== FILE_WAS_CREATED
) || (info
== FILE_WAS_OVERWRITTEN
)) {
1580 SMB_BIG_UINT allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
1581 #ifdef LARGE_SMB_OFF_T
1582 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
1584 if (allocation_size
&& (allocation_size
> file_len
)) {
1585 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, allocation_size
);
1586 if (fsp
->is_directory
) {
1587 close_file(fsp
,ERROR_CLOSE
);
1588 /* Can't set allocation size on a directory. */
1589 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1591 if (vfs_allocate_file_space(fsp
, fsp
->initial_allocation_size
) == -1) {
1592 close_file(fsp
,ERROR_CLOSE
);
1593 return ERROR_NT(NT_STATUS_DISK_FULL
);
1596 fsp
->initial_allocation_size
= smb_roundup(fsp
->conn
, (SMB_BIG_UINT
)file_len
);
1601 * If the caller set the extended oplock request bit
1602 * and we granted one (by whatever means) - set the
1603 * correct bit for extended oplock reply.
1606 if (oplock_request
&& lp_fake_oplocks(SNUM(conn
))) {
1607 extended_oplock_granted
= True
;
1610 if(oplock_request
&& EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
)) {
1611 extended_oplock_granted
= True
;
1614 /* Realloc the size of parameters and data we will return */
1615 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1616 /* Extended response is 32 more byyes. */
1621 params
= nttrans_realloc(ppparams
, param_len
);
1622 if(params
== NULL
) {
1623 return ERROR_DOS(ERRDOS
,ERRnomem
);
1627 if (extended_oplock_granted
) {
1628 if (flags
& REQUEST_BATCH_OPLOCK
) {
1629 SCVAL(p
,0, BATCH_OPLOCK_RETURN
);
1631 SCVAL(p
,0, EXCLUSIVE_OPLOCK_RETURN
);
1633 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1634 SCVAL(p
,0, LEVEL_II_OPLOCK_RETURN
);
1636 SCVAL(p
,0,NO_OPLOCK_RETURN
);
1640 SSVAL(p
,0,fsp
->fnum
);
1642 if ((create_disposition
== FILE_SUPERSEDE
) && (info
== FILE_WAS_OVERWRITTEN
)) {
1643 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1650 c_timespec
= get_create_timespec(&sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1651 a_timespec
= get_atimespec(&sbuf
);
1652 m_timespec
= get_mtimespec(&sbuf
);
1654 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1655 dos_filetime_timespec(&c_timespec
);
1656 dos_filetime_timespec(&a_timespec
);
1657 dos_filetime_timespec(&m_timespec
);
1660 put_long_date_timespec(p
, c_timespec
); /* create time. */
1662 put_long_date_timespec(p
, a_timespec
); /* access time */
1664 put_long_date_timespec(p
, m_timespec
); /* write time */
1666 put_long_date_timespec(p
, m_timespec
); /* change time */
1668 SIVAL(p
,0,fattr
); /* File Attributes. */
1670 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
1672 SOFF_T(p
,0,file_len
);
1674 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1678 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1680 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1683 if (fsp
->is_directory
|| can_write_to_file(conn
, fname
, &sbuf
)) {
1684 perms
= FILE_GENERIC_ALL
;
1686 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1691 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname
));
1693 /* Send the required number of replies */
1694 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1699 /****************************************************************************
1700 Reply to a NT CANCEL request.
1701 conn POINTER CAN BE NULL HERE !
1702 ****************************************************************************/
1704 int reply_ntcancel(connection_struct
*conn
,
1705 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1708 * Go through and cancel any pending change notifies.
1711 int mid
= SVAL(inbuf
,smb_mid
);
1712 START_PROFILE(SMBntcancel
);
1713 remove_pending_change_notify_requests_by_mid(mid
);
1714 remove_pending_lock_requests_by_mid(mid
);
1715 srv_cancel_sign_response(mid
);
1717 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid
));
1719 END_PROFILE(SMBntcancel
);
1723 /****************************************************************************
1725 ****************************************************************************/
1727 static NTSTATUS
copy_internals(connection_struct
*conn
,
1728 struct smb_request
*req
,
1729 char *oldname
, char *newname
, uint32 attrs
)
1731 SMB_STRUCT_STAT sbuf1
, sbuf2
;
1732 pstring last_component_oldname
;
1733 pstring last_component_newname
;
1734 files_struct
*fsp1
,*fsp2
;
1738 NTSTATUS status
= NT_STATUS_OK
;
1743 if (!CAN_WRITE(conn
)) {
1744 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1747 status
= unix_convert(conn
, oldname
, False
, last_component_oldname
, &sbuf1
);
1748 if (!NT_STATUS_IS_OK(status
)) {
1752 status
= check_name(conn
, oldname
);
1753 if (!NT_STATUS_IS_OK(status
)) {
1757 /* Source must already exist. */
1758 if (!VALID_STAT(sbuf1
)) {
1759 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1761 /* Ensure attributes match. */
1762 fattr
= dos_mode(conn
,oldname
,&sbuf1
);
1763 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1764 return NT_STATUS_NO_SUCH_FILE
;
1767 status
= unix_convert(conn
, newname
, False
, last_component_newname
, &sbuf2
);
1768 if (!NT_STATUS_IS_OK(status
)) {
1772 status
= check_name(conn
, newname
);
1773 if (!NT_STATUS_IS_OK(status
)) {
1777 /* Disallow if newname already exists. */
1778 if (VALID_STAT(sbuf2
)) {
1779 return NT_STATUS_OBJECT_NAME_COLLISION
;
1782 /* No links from a directory. */
1783 if (S_ISDIR(sbuf1
.st_mode
)) {
1784 return NT_STATUS_FILE_IS_A_DIRECTORY
;
1787 /* Ensure this is within the share. */
1788 status
= check_reduced_name(conn
, oldname
);
1789 if (!NT_STATUS_IS_OK(status
)) {
1793 DEBUG(10,("copy_internals: doing file copy %s to %s\n", oldname
, newname
));
1795 status
= open_file_ntcreate(conn
, req
, oldname
, &sbuf1
,
1796 FILE_READ_DATA
, /* Read-only. */
1797 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1799 0, /* No create options. */
1800 FILE_ATTRIBUTE_NORMAL
,
1804 if (!NT_STATUS_IS_OK(status
)) {
1808 status
= open_file_ntcreate(conn
, req
, newname
, &sbuf2
,
1809 FILE_WRITE_DATA
, /* Read-only. */
1810 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1812 0, /* No create options. */
1817 if (!NT_STATUS_IS_OK(status
)) {
1818 close_file(fsp1
,ERROR_CLOSE
);
1822 if (sbuf1
.st_size
) {
1823 ret
= vfs_transfer_file(fsp1
, fsp2
, sbuf1
.st_size
);
1827 * As we are opening fsp1 read-only we only expect
1828 * an error on close on fsp2 if we are out of space.
1829 * Thus we don't look at the error return from the
1832 close_file(fsp1
,NORMAL_CLOSE
);
1834 /* Ensure the modtime is set correctly on the destination file. */
1835 fsp_set_pending_modtime(fsp2
, get_mtimespec(&sbuf1
));
1837 status
= close_file(fsp2
,NORMAL_CLOSE
);
1839 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1840 creates the file. This isn't the correct thing to do in the copy
1842 file_set_dosmode(conn
, newname
, fattr
, &sbuf2
,
1843 parent_dirname(newname
));
1845 if (ret
< (SMB_OFF_T
)sbuf1
.st_size
) {
1846 return NT_STATUS_DISK_FULL
;
1849 if (!NT_STATUS_IS_OK(status
)) {
1850 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1851 nt_errstr(status
), oldname
, newname
));
1856 /****************************************************************************
1857 Reply to a NT rename request.
1858 ****************************************************************************/
1860 int reply_ntrename(connection_struct
*conn
,
1861 char *inbuf
,char *outbuf
,int length
,int bufsize
)
1868 BOOL src_has_wcard
= False
;
1869 BOOL dest_has_wcard
= False
;
1870 uint32 attrs
= SVAL(inbuf
,smb_vwv0
);
1871 uint16 rename_type
= SVAL(inbuf
,smb_vwv1
);
1872 struct smb_request req
;
1874 START_PROFILE(SMBntrename
);
1876 init_smb_request(&req
, (uint8
*)inbuf
);
1878 p
= smb_buf(inbuf
) + 1;
1879 p
+= srvstr_get_path_wcard(inbuf
, SVAL(inbuf
,smb_flg2
), oldname
, p
,
1880 sizeof(oldname
), 0, STR_TERMINATE
, &status
,
1882 if (!NT_STATUS_IS_OK(status
)) {
1883 END_PROFILE(SMBntrename
);
1884 return ERROR_NT(status
);
1887 if( is_ntfs_stream_name(oldname
)) {
1888 /* Can't rename a stream. */
1889 END_PROFILE(SMBntrename
);
1890 return ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1893 if (ms_has_wild(oldname
)) {
1894 END_PROFILE(SMBntrename
);
1895 return ERROR_NT(NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1899 p
+= srvstr_get_path_wcard(inbuf
, SVAL(inbuf
,smb_flg2
), newname
, p
,
1900 sizeof(newname
), 0, STR_TERMINATE
, &status
,
1902 if (!NT_STATUS_IS_OK(status
)) {
1903 END_PROFILE(SMBntrename
);
1904 return ERROR_NT(status
);
1907 status
= resolve_dfspath(conn
, SVAL(inbuf
,smb_flg2
) & FLAGS2_DFS_PATHNAMES
, oldname
);
1908 if (!NT_STATUS_IS_OK(status
)) {
1909 END_PROFILE(SMBntrename
);
1910 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1911 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
1913 return ERROR_NT(status
);
1916 status
= resolve_dfspath(conn
, SVAL(inbuf
,smb_flg2
) & FLAGS2_DFS_PATHNAMES
, newname
);
1917 if (!NT_STATUS_IS_OK(status
)) {
1918 END_PROFILE(SMBntrename
);
1919 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1920 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
1922 return ERROR_NT(status
);
1925 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1927 switch(rename_type
) {
1928 case RENAME_FLAG_RENAME
:
1929 status
= rename_internals(conn
, &req
, oldname
, newname
,
1930 attrs
, False
, src_has_wcard
,
1933 case RENAME_FLAG_HARD_LINK
:
1934 if (src_has_wcard
|| dest_has_wcard
) {
1936 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1938 status
= hardlink_internals(conn
, oldname
, newname
);
1941 case RENAME_FLAG_COPY
:
1942 if (src_has_wcard
|| dest_has_wcard
) {
1944 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1946 status
= copy_internals(conn
, &req
, oldname
,
1950 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1951 status
= NT_STATUS_INVALID_PARAMETER
;
1954 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1958 if (!NT_STATUS_IS_OK(status
)) {
1959 END_PROFILE(SMBntrename
);
1960 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
1961 /* We have re-scheduled this call. */
1964 return ERROR_NT(status
);
1967 outsize
= set_message(inbuf
,outbuf
,0,0,False
);
1969 END_PROFILE(SMBntrename
);
1973 /****************************************************************************
1974 Reply to a notify change - queue the request and
1975 don't allow a directory to be opened.
1976 ****************************************************************************/
1978 static int call_nt_transact_notify_change(connection_struct
*conn
, char *inbuf
,
1979 char *outbuf
, int length
,
1981 uint16
**ppsetup
, uint32 setup_count
,
1983 uint32 parameter_count
,
1984 char **ppdata
, uint32 data_count
,
1985 uint32 max_data_count
,
1986 uint32 max_param_count
)
1988 uint16
*setup
= *ppsetup
;
1994 if(setup_count
< 6) {
1995 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
1998 fsp
= file_fsp((char *)setup
,4);
1999 filter
= IVAL(setup
, 0);
2000 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
2002 DEBUG(3,("call_nt_transact_notify_change\n"));
2005 return ERROR_DOS(ERRDOS
,ERRbadfid
);
2009 char *filter_string
;
2011 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
2012 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2015 DEBUG(3,("call_nt_transact_notify_change: notify change "
2016 "called on %s, filter = %s, recursive = %d\n",
2017 fsp
->fsp_name
, filter_string
, recursive
));
2019 TALLOC_FREE(filter_string
);
2022 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
2023 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
2026 if (fsp
->notify
== NULL
) {
2028 status
= change_notify_create(fsp
, filter
, recursive
);
2030 if (!NT_STATUS_IS_OK(status
)) {
2031 DEBUG(10, ("change_notify_create returned %s\n",
2032 nt_errstr(status
)));
2033 return ERROR_NT(status
);
2037 if (fsp
->notify
->num_changes
!= 0) {
2040 * We've got changes pending, respond immediately
2044 * TODO: write a torture test to check the filtering behaviour
2048 change_notify_reply(inbuf
, max_param_count
, fsp
->notify
);
2051 * change_notify_reply() above has independently sent its
2058 * No changes pending, queue the request
2061 status
= change_notify_add_request(inbuf
, max_param_count
, filter
,
2063 if (!NT_STATUS_IS_OK(status
)) {
2064 return ERROR_NT(status
);
2070 /****************************************************************************
2071 Reply to an NT transact rename command.
2072 ****************************************************************************/
2074 static int call_nt_transact_rename(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2075 uint16
**ppsetup
, uint32 setup_count
,
2076 char **ppparams
, uint32 parameter_count
,
2077 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2079 char *params
= *ppparams
;
2081 files_struct
*fsp
= NULL
;
2082 BOOL replace_if_exists
= False
;
2083 BOOL dest_has_wcard
= False
;
2085 struct smb_request req
;
2087 init_smb_request(&req
, (uint8
*)inbuf
);
2089 if(parameter_count
< 5) {
2090 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2093 fsp
= file_fsp(params
, 0);
2094 replace_if_exists
= (SVAL(params
,2) & RENAME_REPLACE_IF_EXISTS
) ? True
: False
;
2095 CHECK_FSP(fsp
, conn
);
2096 srvstr_get_path_wcard(inbuf
, SVAL(inbuf
,smb_flg2
), new_name
, params
+4,
2097 sizeof(new_name
), parameter_count
- 4,
2098 STR_TERMINATE
, &status
, &dest_has_wcard
);
2099 if (!NT_STATUS_IS_OK(status
)) {
2100 return ERROR_NT(status
);
2103 status
= rename_internals(conn
, &req
, fsp
->fsp_name
,
2104 new_name
, 0, replace_if_exists
, False
, dest_has_wcard
);
2106 if (!NT_STATUS_IS_OK(status
)) {
2107 if (open_was_deferred(SVAL(inbuf
,smb_mid
))) {
2108 /* We have re-scheduled this call. */
2111 return ERROR_NT(status
);
2115 * Rename was successful.
2117 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2119 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
2120 fsp
->fsp_name
, new_name
));
2125 /******************************************************************************
2126 Fake up a completely empty SD.
2127 *******************************************************************************/
2129 static size_t get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
2133 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
2135 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
2142 /****************************************************************************
2143 Reply to query a security descriptor.
2144 ****************************************************************************/
2146 static int call_nt_transact_query_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2147 uint16
**ppsetup
, uint32 setup_count
,
2148 char **ppparams
, uint32 parameter_count
,
2149 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2151 char *params
= *ppparams
;
2152 char *data
= *ppdata
;
2154 SEC_DESC
*psd
= NULL
;
2156 uint32 security_info_wanted
;
2157 TALLOC_CTX
*mem_ctx
;
2158 files_struct
*fsp
= NULL
;
2160 if(parameter_count
< 8) {
2161 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2164 fsp
= file_fsp(params
,0);
2166 return ERROR_DOS(ERRDOS
,ERRbadfid
);
2169 security_info_wanted
= IVAL(params
,4);
2171 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp
->fsp_name
,
2172 (unsigned int)security_info_wanted
));
2174 params
= nttrans_realloc(ppparams
, 4);
2175 if(params
== NULL
) {
2176 return ERROR_DOS(ERRDOS
,ERRnomem
);
2179 if ((mem_ctx
= talloc_init("call_nt_transact_query_security_desc")) == NULL
) {
2180 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
2181 return ERROR_DOS(ERRDOS
,ERRnomem
);
2185 * Get the permissions to return.
2188 if (!lp_nt_acl_support(SNUM(conn
))) {
2189 sd_size
= get_null_nt_acl(mem_ctx
, &psd
);
2191 sd_size
= SMB_VFS_FGET_NT_ACL(fsp
, fsp
->fh
->fd
, security_info_wanted
, &psd
);
2195 talloc_destroy(mem_ctx
);
2196 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
2199 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
2201 SIVAL(params
,0,(uint32
)sd_size
);
2203 if(max_data_count
< sd_size
) {
2205 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_BUFFER_TOO_SMALL
,
2206 params
, 4, *ppdata
, 0);
2207 talloc_destroy(mem_ctx
);
2212 * Allocate the data we will point this at.
2215 data
= nttrans_realloc(ppdata
, sd_size
);
2217 talloc_destroy(mem_ctx
);
2218 return ERROR_DOS(ERRDOS
,ERRnomem
);
2222 * Init the parse struct we will marshall into.
2225 prs_init(&pd
, 0, mem_ctx
, MARSHALL
);
2228 * Setup the prs_struct to point at the memory we just
2232 prs_give_memory( &pd
, data
, (uint32
)sd_size
, False
);
2235 * Finally, linearize into the outgoing buffer.
2238 if(!sec_io_desc( "sd data", &psd
, &pd
, 1)) {
2239 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
2240 security descriptor.\n"));
2242 * Return access denied for want of a better error message..
2244 talloc_destroy(mem_ctx
);
2245 return(UNIXERROR(ERRDOS
,ERRnoaccess
));
2249 * Now we can delete the security descriptor.
2252 talloc_destroy(mem_ctx
);
2254 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, 4, data
,
2259 /****************************************************************************
2260 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2261 ****************************************************************************/
2263 static int call_nt_transact_set_security_desc(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2264 uint16
**ppsetup
, uint32 setup_count
,
2265 char **ppparams
, uint32 parameter_count
,
2266 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2268 char *params
= *ppparams
;
2269 char *data
= *ppdata
;
2270 files_struct
*fsp
= NULL
;
2271 uint32 security_info_sent
= 0;
2274 if(parameter_count
< 8) {
2275 return ERROR_DOS(ERRDOS
,ERRbadfunc
);
2278 if((fsp
= file_fsp(params
,0)) == NULL
) {
2279 return ERROR_DOS(ERRDOS
,ERRbadfid
);
2282 if(!lp_nt_acl_support(SNUM(conn
))) {
2286 security_info_sent
= IVAL(params
,4);
2288 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
2289 (unsigned int)security_info_sent
));
2291 if (data_count
== 0) {
2292 return ERROR_DOS(ERRDOS
, ERRnoaccess
);
2295 if (!NT_STATUS_IS_OK(nt_status
= set_sd( fsp
, data
, data_count
, security_info_sent
))) {
2296 return ERROR_NT(nt_status
);
2301 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2305 /****************************************************************************
2307 ****************************************************************************/
2309 static int call_nt_transact_ioctl(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2310 uint16
**ppsetup
, uint32 setup_count
,
2311 char **ppparams
, uint32 parameter_count
,
2312 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2319 static BOOL logged_message
;
2320 char *pdata
= *ppdata
;
2322 if (setup_count
!= 8) {
2323 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
2324 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2327 function
= IVAL(*ppsetup
, 0);
2328 fidnum
= SVAL(*ppsetup
, 4);
2329 isFSctl
= CVAL(*ppsetup
, 6);
2330 compfilter
= CVAL(*ppsetup
, 7);
2332 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2333 function
, fidnum
, isFSctl
, compfilter
));
2335 fsp
=file_fsp((char *)*ppsetup
, 4);
2336 /* this check is done in each implemented function case for now
2337 because I don't want to break anything... --metze
2338 FSP_BELONGS_CONN(fsp,conn);*/
2341 case FSCTL_SET_SPARSE
:
2342 /* pretend this succeeded - tho strictly we should
2343 mark the file sparse (if the local fs supports it)
2344 so we can know if we need to pre-allocate or not */
2346 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
2347 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, NULL
,
2351 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
2353 unsigned char objid
[16];
2355 /* This should return the object-id on this file.
2356 * I think I'll make this be the inode+dev. JRA.
2359 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
2362 pdata
= nttrans_realloc(ppdata
, data_count
);
2363 if (pdata
== NULL
) {
2364 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2366 push_file_id_16(pdata
, &fsp
->file_id
);
2367 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
2368 push_file_id_16(pdata
+32, &fsp
->file_id
);
2369 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0, pdata
, data_count
);
2373 case FSCTL_GET_REPARSE_POINT
:
2374 /* pretend this fail - my winXP does it like this
2378 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2379 return ERROR_NT(NT_STATUS_NOT_A_REPARSE_POINT
);
2381 case FSCTL_SET_REPARSE_POINT
:
2382 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
2386 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
2387 return ERROR_NT(NT_STATUS_NOT_A_REPARSE_POINT
);
2389 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
2392 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2393 * and return their volume names. If max_data_count is 16, then it is just
2394 * asking for the number of volumes and length of the combined names.
2396 * pdata is the data allocated by our caller, but that uses
2397 * total_data_count (which is 0 in our case) rather than max_data_count.
2398 * Allocate the correct amount and return the pointer to let
2399 * it be deallocated when we return.
2401 SHADOW_COPY_DATA
*shadow_data
= NULL
;
2402 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
2403 BOOL labels
= False
;
2404 uint32 labels_data_count
= 0;
2408 FSP_BELONGS_CONN(fsp
,conn
);
2410 if (max_data_count
< 16) {
2411 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2413 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
2416 if (max_data_count
> 16) {
2420 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
2421 if (shadow_mem_ctx
== NULL
) {
2422 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2423 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2426 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
2427 if (shadow_data
== NULL
) {
2428 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2429 talloc_destroy(shadow_mem_ctx
);
2430 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2433 shadow_data
->mem_ctx
= shadow_mem_ctx
;
2436 * Call the VFS routine to actually do the work.
2438 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2439 talloc_destroy(shadow_data
->mem_ctx
);
2440 if (errno
== ENOSYS
) {
2441 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2442 conn
->connectpath
));
2443 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2445 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2446 conn
->connectpath
));
2447 return ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
2451 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2456 data_count
= 12+labels_data_count
+4;
2459 if (max_data_count
<data_count
) {
2460 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2461 max_data_count
,data_count
));
2462 talloc_destroy(shadow_data
->mem_ctx
);
2463 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL
);
2466 pdata
= nttrans_realloc(ppdata
, data_count
);
2467 if (pdata
== NULL
) {
2468 talloc_destroy(shadow_data
->mem_ctx
);
2469 return ERROR_NT(NT_STATUS_NO_MEMORY
);
2474 /* num_volumes 4 bytes */
2475 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2478 /* num_labels 4 bytes */
2479 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2482 /* needed_data_count 4 bytes */
2483 SIVAL(pdata
,8,labels_data_count
);
2487 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2488 shadow_data
->num_volumes
,fsp
->fsp_name
));
2489 if (labels
&& shadow_data
->labels
) {
2490 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2491 srvstr_push(outbuf
, cur_pdata
, shadow_data
->labels
[i
], 2*sizeof(SHADOW_COPY_LABEL
), STR_UNICODE
|STR_TERMINATE
);
2492 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2493 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2497 talloc_destroy(shadow_data
->mem_ctx
);
2499 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0,
2505 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2507 /* pretend this succeeded -
2509 * we have to send back a list with all files owned by this SID
2511 * but I have to check that --metze
2515 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2517 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2519 FSP_BELONGS_CONN(fsp
,conn
);
2521 /* unknown 4 bytes: this is not the length of the sid :-( */
2522 /*unknown = IVAL(pdata,0);*/
2524 sid_parse(pdata
+4,sid_len
,&sid
);
2525 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid
)));
2527 if (!sid_to_uid(&sid
, &uid
)) {
2528 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2529 sid_string_static(&sid
),(unsigned long)sid_len
));
2533 /* we can take a look at the find source :-)
2535 * find ./ -uid $uid -name '*' is what we need here
2538 * and send 4bytes len and then NULL terminated unicode strings
2541 * but I don't know how to deal with the paged results
2542 * (maybe we can hang the result anywhere in the fsp struct)
2544 * we don't send all files at once
2545 * and at the next we should *not* start from the beginning,
2546 * so we have to cache the result
2551 /* this works for now... */
2552 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, NULL
, 0,
2557 if (!logged_message
) {
2558 logged_message
= True
; /* Only print this once... */
2559 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2564 return ERROR_NT(NT_STATUS_NOT_SUPPORTED
);
2568 #ifdef HAVE_SYS_QUOTAS
2569 /****************************************************************************
2570 Reply to get user quota
2571 ****************************************************************************/
2573 static int call_nt_transact_get_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2574 uint16
**ppsetup
, uint32 setup_count
,
2575 char **ppparams
, uint32 parameter_count
,
2576 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2578 NTSTATUS nt_status
= NT_STATUS_OK
;
2579 char *params
= *ppparams
;
2580 char *pdata
= *ppdata
;
2582 int data_len
=0,param_len
=0;
2585 files_struct
*fsp
= NULL
;
2589 BOOL start_enum
= True
;
2590 SMB_NTQUOTA_STRUCT qt
;
2591 SMB_NTQUOTA_LIST
*tmp_list
;
2592 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2597 if (current_user
.ut
.uid
!= 0) {
2598 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2599 lp_servicename(SNUM(conn
)),conn
->user
));
2600 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2604 * Ensure minimum number of parameters sent.
2607 if (parameter_count
< 4) {
2608 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2609 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2612 /* maybe we can check the quota_fnum */
2613 fsp
= file_fsp(params
,0);
2614 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2615 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2616 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2619 /* the NULL pointer checking for fsp->fake_file_handle->pd
2620 * is done by CHECK_NTQUOTA_HANDLE_OK()
2622 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
2624 level
= SVAL(params
,2);
2626 /* unknown 12 bytes leading in params */
2629 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2630 /* seems that we should continue with the enum here --metze */
2632 if (qt_handle
->quota_list
!=NULL
&&
2633 qt_handle
->tmp_list
==NULL
) {
2636 free_ntquota_list(&(qt_handle
->quota_list
));
2638 /* Realloc the size of parameters and data we will return */
2640 params
= nttrans_realloc(ppparams
, param_len
);
2641 if(params
== NULL
) {
2642 return ERROR_DOS(ERRDOS
,ERRnomem
);
2646 SIVAL(params
,0,data_len
);
2653 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2655 if (qt_handle
->quota_list
==NULL
&&
2656 qt_handle
->tmp_list
==NULL
) {
2660 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0)
2661 return ERROR_DOS(ERRSRV
,ERRerror
);
2663 /* Realloc the size of parameters and data we will return */
2665 params
= nttrans_realloc(ppparams
, param_len
);
2666 if(params
== NULL
) {
2667 return ERROR_DOS(ERRDOS
,ERRnomem
);
2670 /* we should not trust the value in max_data_count*/
2671 max_data_count
= MIN(max_data_count
,2048);
2673 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2675 return ERROR_DOS(ERRDOS
,ERRnomem
);
2680 /* set params Size of returned Quota Data 4 bytes*/
2681 /* but set it later when we know it */
2683 /* for each entry push the data */
2686 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2689 tmp_list
= qt_handle
->tmp_list
;
2691 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2692 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2694 sid_len
= sid_size(&tmp_list
->quotas
->sid
);
2695 entry_len
= 40 + sid_len
;
2697 /* nextoffset entry 4 bytes */
2698 SIVAL(entry
,0,entry_len
);
2700 /* then the len of the SID 4 bytes */
2701 SIVAL(entry
,4,sid_len
);
2703 /* unknown data 8 bytes SMB_BIG_UINT */
2704 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2706 /* the used disk space 8 bytes SMB_BIG_UINT */
2707 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2709 /* the soft quotas 8 bytes SMB_BIG_UINT */
2710 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2712 /* the hard quotas 8 bytes SMB_BIG_UINT */
2713 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2715 /* and now the SID */
2716 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2719 qt_handle
->tmp_list
= tmp_list
;
2721 /* overwrite the offset of the last entry */
2722 SIVAL(entry
-entry_len
,0,0);
2724 data_len
= 4+qt_len
;
2725 /* overwrite the params quota_data_len */
2726 SIVAL(params
,0,data_len
);
2730 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2732 /* unknown 4 bytes IVAL(pdata,0) */
2734 if (data_count
< 8) {
2735 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2736 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2739 sid_len
= IVAL(pdata
,4);
2740 /* Ensure this is less than 1mb. */
2741 if (sid_len
> (1024*1024)) {
2742 return ERROR_DOS(ERRDOS
,ERRnomem
);
2745 if (data_count
< 8+sid_len
) {
2746 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2747 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2750 data_len
= 4+40+sid_len
;
2752 if (max_data_count
< data_len
) {
2753 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2754 max_data_count
, data_len
));
2756 SIVAL(params
,0,data_len
);
2758 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2762 sid_parse(pdata
+8,sid_len
,&sid
);
2764 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2767 * we have to return zero's in all fields
2768 * instead of returning an error here
2773 /* Realloc the size of parameters and data we will return */
2775 params
= nttrans_realloc(ppparams
, param_len
);
2776 if(params
== NULL
) {
2777 return ERROR_DOS(ERRDOS
,ERRnomem
);
2780 pdata
= nttrans_realloc(ppdata
, data_len
);
2782 return ERROR_DOS(ERRDOS
,ERRnomem
);
2787 /* set params Size of returned Quota Data 4 bytes*/
2788 SIVAL(params
,0,data_len
);
2790 /* nextoffset entry 4 bytes */
2793 /* then the len of the SID 4 bytes */
2794 SIVAL(entry
,4,sid_len
);
2796 /* unknown data 8 bytes SMB_BIG_UINT */
2797 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2799 /* the used disk space 8 bytes SMB_BIG_UINT */
2800 SBIG_UINT(entry
,16,qt
.usedspace
);
2802 /* the soft quotas 8 bytes SMB_BIG_UINT */
2803 SBIG_UINT(entry
,24,qt
.softlim
);
2805 /* the hard quotas 8 bytes SMB_BIG_UINT */
2806 SBIG_UINT(entry
,32,qt
.hardlim
);
2808 /* and now the SID */
2809 sid_linearize(entry
+40, sid_len
, &sid
);
2814 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2815 return ERROR_DOS(ERRSRV
,ERRerror
);
2819 send_nt_replies(inbuf
, outbuf
, bufsize
, nt_status
, params
, param_len
,
2825 /****************************************************************************
2826 Reply to set user quota
2827 ****************************************************************************/
2829 static int call_nt_transact_set_user_quota(connection_struct
*conn
, char *inbuf
, char *outbuf
, int length
, int bufsize
,
2830 uint16
**ppsetup
, uint32 setup_count
,
2831 char **ppparams
, uint32 parameter_count
,
2832 char **ppdata
, uint32 data_count
, uint32 max_data_count
)
2834 char *params
= *ppparams
;
2835 char *pdata
= *ppdata
;
2836 int data_len
=0,param_len
=0;
2837 SMB_NTQUOTA_STRUCT qt
;
2840 files_struct
*fsp
= NULL
;
2845 if (current_user
.ut
.uid
!= 0) {
2846 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2847 lp_servicename(SNUM(conn
)),conn
->user
));
2848 return ERROR_DOS(ERRDOS
,ERRnoaccess
);
2852 * Ensure minimum number of parameters sent.
2855 if (parameter_count
< 2) {
2856 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2857 return ERROR_DOS(ERRDOS
,ERRinvalidparam
);
2860 /* maybe we can check the quota_fnum */
2861 fsp
= file_fsp(params
,0);
2862 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2863 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2864 return ERROR_NT(NT_STATUS_INVALID_HANDLE
);
2867 if (data_count
< 40) {
2868 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2869 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2872 /* offset to next quota record.
2873 * 4 bytes IVAL(pdata,0)
2878 sid_len
= IVAL(pdata
,4);
2880 if (data_count
< 40+sid_len
) {
2881 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2882 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2885 /* unknown 8 bytes in pdata
2886 * maybe its the change time in NTTIME
2889 /* the used space 8 bytes (SMB_BIG_UINT)*/
2890 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2891 #ifdef LARGE_SMB_OFF_T
2892 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2893 #else /* LARGE_SMB_OFF_T */
2894 if ((IVAL(pdata
,20) != 0)&&
2895 ((qt
.usedspace
!= 0xFFFFFFFF)||
2896 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2897 /* more than 32 bits? */
2898 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2900 #endif /* LARGE_SMB_OFF_T */
2902 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2903 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2904 #ifdef LARGE_SMB_OFF_T
2905 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2906 #else /* LARGE_SMB_OFF_T */
2907 if ((IVAL(pdata
,28) != 0)&&
2908 ((qt
.softlim
!= 0xFFFFFFFF)||
2909 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2910 /* more than 32 bits? */
2911 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2913 #endif /* LARGE_SMB_OFF_T */
2915 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2916 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2917 #ifdef LARGE_SMB_OFF_T
2918 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2919 #else /* LARGE_SMB_OFF_T */
2920 if ((IVAL(pdata
,36) != 0)&&
2921 ((qt
.hardlim
!= 0xFFFFFFFF)||
2922 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2923 /* more than 32 bits? */
2924 return ERROR_DOS(ERRDOS
,ERRunknownlevel
);
2926 #endif /* LARGE_SMB_OFF_T */
2928 sid_parse(pdata
+40,sid_len
,&sid
);
2929 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid
)));
2931 /* 44 unknown bytes left... */
2933 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2934 return ERROR_DOS(ERRSRV
,ERRerror
);
2937 send_nt_replies(inbuf
, outbuf
, bufsize
, NT_STATUS_OK
, params
, param_len
,
2942 #endif /* HAVE_SYS_QUOTAS */
2944 static int handle_nttrans(connection_struct
*conn
,
2945 struct trans_state
*state
,
2946 char *inbuf
, char *outbuf
, int size
, int bufsize
)
2950 if (Protocol
>= PROTOCOL_NT1
) {
2951 SSVAL(outbuf
,smb_flg2
,SVAL(outbuf
,smb_flg2
) | 0x40); /* IS_LONG_NAME */
2954 /* Now we must call the relevant NT_TRANS function */
2955 switch(state
->call
) {
2956 case NT_TRANSACT_CREATE
:
2958 START_PROFILE(NT_transact_create
);
2959 outsize
= call_nt_transact_create(conn
, inbuf
, outbuf
,
2961 &state
->setup
, state
->setup_count
,
2962 &state
->param
, state
->total_param
,
2963 &state
->data
, state
->total_data
,
2964 state
->max_data_return
);
2965 END_PROFILE(NT_transact_create
);
2969 case NT_TRANSACT_IOCTL
:
2971 START_PROFILE(NT_transact_ioctl
);
2972 outsize
= call_nt_transact_ioctl(conn
, inbuf
, outbuf
,
2974 &state
->setup
, state
->setup_count
,
2975 &state
->param
, state
->total_param
,
2976 &state
->data
, state
->total_data
, state
->max_data_return
);
2977 END_PROFILE(NT_transact_ioctl
);
2981 case NT_TRANSACT_SET_SECURITY_DESC
:
2983 START_PROFILE(NT_transact_set_security_desc
);
2984 outsize
= call_nt_transact_set_security_desc(conn
, inbuf
, outbuf
,
2986 &state
->setup
, state
->setup_count
,
2987 &state
->param
, state
->total_param
,
2988 &state
->data
, state
->total_data
, state
->max_data_return
);
2989 END_PROFILE(NT_transact_set_security_desc
);
2993 case NT_TRANSACT_NOTIFY_CHANGE
:
2995 START_PROFILE(NT_transact_notify_change
);
2996 outsize
= call_nt_transact_notify_change(
2997 conn
, inbuf
, outbuf
, size
, bufsize
,
2998 &state
->setup
, state
->setup_count
,
2999 &state
->param
, state
->total_param
,
3000 &state
->data
, state
->total_data
,
3001 state
->max_data_return
,
3002 state
->max_param_return
);
3003 END_PROFILE(NT_transact_notify_change
);
3007 case NT_TRANSACT_RENAME
:
3009 START_PROFILE(NT_transact_rename
);
3010 outsize
= call_nt_transact_rename(conn
, inbuf
, outbuf
,
3012 &state
->setup
, state
->setup_count
,
3013 &state
->param
, state
->total_param
,
3014 &state
->data
, state
->total_data
, state
->max_data_return
);
3015 END_PROFILE(NT_transact_rename
);
3019 case NT_TRANSACT_QUERY_SECURITY_DESC
:
3021 START_PROFILE(NT_transact_query_security_desc
);
3022 outsize
= call_nt_transact_query_security_desc(conn
, inbuf
, outbuf
,
3024 &state
->setup
, state
->setup_count
,
3025 &state
->param
, state
->total_param
,
3026 &state
->data
, state
->total_data
, state
->max_data_return
);
3027 END_PROFILE(NT_transact_query_security_desc
);
3031 #ifdef HAVE_SYS_QUOTAS
3032 case NT_TRANSACT_GET_USER_QUOTA
:
3034 START_PROFILE(NT_transact_get_user_quota
);
3035 outsize
= call_nt_transact_get_user_quota(conn
, inbuf
, outbuf
,
3037 &state
->setup
, state
->setup_count
,
3038 &state
->param
, state
->total_param
,
3039 &state
->data
, state
->total_data
, state
->max_data_return
);
3040 END_PROFILE(NT_transact_get_user_quota
);
3044 case NT_TRANSACT_SET_USER_QUOTA
:
3046 START_PROFILE(NT_transact_set_user_quota
);
3047 outsize
= call_nt_transact_set_user_quota(conn
, inbuf
, outbuf
,
3049 &state
->setup
, state
->setup_count
,
3050 &state
->param
, state
->total_param
,
3051 &state
->data
, state
->total_data
, state
->max_data_return
);
3052 END_PROFILE(NT_transact_set_user_quota
);
3055 #endif /* HAVE_SYS_QUOTAS */
3058 /* Error in request */
3059 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n",
3061 return ERROR_DOS(ERRSRV
,ERRerror
);
3066 /****************************************************************************
3067 Reply to a SMBNTtrans.
3068 ****************************************************************************/
3070 int reply_nttrans(connection_struct
*conn
,
3071 char *inbuf
,char *outbuf
,int size
,int bufsize
)
3074 uint32 pscnt
= IVAL(inbuf
,smb_nt_ParameterCount
);
3075 uint32 psoff
= IVAL(inbuf
,smb_nt_ParameterOffset
);
3076 uint32 dscnt
= IVAL(inbuf
,smb_nt_DataCount
);
3077 uint32 dsoff
= IVAL(inbuf
,smb_nt_DataOffset
);
3079 uint16 function_code
= SVAL( inbuf
, smb_nt_Function
);
3081 struct trans_state
*state
;
3083 START_PROFILE(SMBnttrans
);
3085 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
3086 END_PROFILE(SMBnttrans
);
3087 return ERROR_DOS(ERRSRV
,ERRaccess
);
3090 result
= allow_new_trans(conn
->pending_trans
, SVAL(inbuf
, smb_mid
));
3091 if (!NT_STATUS_IS_OK(result
)) {
3092 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
3093 END_PROFILE(SMBnttrans
);
3094 return ERROR_NT(result
);
3097 if ((state
= TALLOC_P(conn
->mem_ctx
, struct trans_state
)) == NULL
) {
3098 END_PROFILE(SMBnttrans
);
3099 return ERROR_DOS(ERRSRV
,ERRaccess
);
3102 state
->cmd
= SMBnttrans
;
3104 state
->mid
= SVAL(inbuf
,smb_mid
);
3105 state
->vuid
= SVAL(inbuf
,smb_uid
);
3106 state
->total_data
= IVAL(inbuf
, smb_nt_TotalDataCount
);
3108 state
->total_param
= IVAL(inbuf
, smb_nt_TotalParameterCount
);
3109 state
->param
= NULL
;
3110 state
->max_data_return
= IVAL(inbuf
,smb_nt_MaxDataCount
);
3111 state
->max_param_return
= IVAL(inbuf
,smb_nt_MaxParameterCount
);
3113 /* setup count is in *words* */
3114 state
->setup_count
= 2*CVAL(inbuf
,smb_nt_SetupCount
);
3115 state
->setup
= NULL
;
3116 state
->call
= function_code
;
3119 * All nttrans messages we handle have smb_wct == 19 +
3120 * state->setup_count. Ensure this is so as a sanity check.
3123 if(CVAL(inbuf
, smb_wct
) != 19 + (state
->setup_count
/2)) {
3124 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
3125 CVAL(inbuf
, smb_wct
), 19 + (state
->setup_count
/2)));
3129 /* Don't allow more than 128mb for each value. */
3130 if ((state
->total_data
> (1024*1024*128)) ||
3131 (state
->total_param
> (1024*1024*128))) {
3132 END_PROFILE(SMBnttrans
);
3133 return ERROR_DOS(ERRDOS
,ERRnomem
);
3136 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
3139 if (state
->total_data
) {
3140 /* Can't use talloc here, the core routines do realloc on the
3141 * params and data. */
3142 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
3143 DEBUG(0,("reply_nttrans: data malloc fail for %u "
3144 "bytes !\n", (unsigned int)state
->total_data
));
3146 END_PROFILE(SMBnttrans
);
3147 return(ERROR_DOS(ERRDOS
,ERRnomem
));
3149 if ((dsoff
+dscnt
< dsoff
) || (dsoff
+dscnt
< dscnt
))
3151 if ((smb_base(inbuf
)+dsoff
+dscnt
> inbuf
+ size
) ||
3152 (smb_base(inbuf
)+dsoff
+dscnt
< smb_base(inbuf
)))
3155 memcpy(state
->data
,smb_base(inbuf
)+dsoff
,dscnt
);
3158 if (state
->total_param
) {
3159 /* Can't use talloc here, the core routines do realloc on the
3160 * params and data. */
3161 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
3162 DEBUG(0,("reply_nttrans: param malloc fail for %u "
3163 "bytes !\n", (unsigned int)state
->total_param
));
3164 SAFE_FREE(state
->data
);
3166 END_PROFILE(SMBnttrans
);
3167 return(ERROR_DOS(ERRDOS
,ERRnomem
));
3169 if ((psoff
+pscnt
< psoff
) || (psoff
+pscnt
< pscnt
))
3171 if ((smb_base(inbuf
)+psoff
+pscnt
> inbuf
+ size
) ||
3172 (smb_base(inbuf
)+psoff
+pscnt
< smb_base(inbuf
)))
3175 memcpy(state
->param
,smb_base(inbuf
)+psoff
,pscnt
);
3178 state
->received_data
= dscnt
;
3179 state
->received_param
= pscnt
;
3181 if(state
->setup_count
> 0) {
3182 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
3183 state
->setup_count
));
3184 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
3185 if (state
->setup
== NULL
) {
3186 DEBUG(0,("reply_nttrans : Out of memory\n"));
3187 SAFE_FREE(state
->data
);
3188 SAFE_FREE(state
->param
);
3190 END_PROFILE(SMBnttrans
);
3191 return ERROR_DOS(ERRDOS
,ERRnomem
);
3194 if ((smb_nt_SetupStart
+ state
->setup_count
< smb_nt_SetupStart
) ||
3195 (smb_nt_SetupStart
+ state
->setup_count
< state
->setup_count
)) {
3198 if (smb_nt_SetupStart
+ state
->setup_count
> size
) {
3202 memcpy( state
->setup
, &inbuf
[smb_nt_SetupStart
], state
->setup_count
);
3203 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
3206 if ((state
->received_data
== state
->total_data
) &&
3207 (state
->received_param
== state
->total_param
)) {
3208 outsize
= handle_nttrans(conn
, state
, inbuf
, outbuf
,
3210 SAFE_FREE(state
->param
);
3211 SAFE_FREE(state
->data
);
3213 END_PROFILE(SMBnttrans
);
3217 DLIST_ADD(conn
->pending_trans
, state
);
3219 /* We need to send an interim response then receive the rest
3220 of the parameter/data bytes */
3221 outsize
= set_message(inbuf
,outbuf
,0,0,False
);
3223 END_PROFILE(SMBnttrans
);
3228 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3229 SAFE_FREE(state
->data
);
3230 SAFE_FREE(state
->param
);
3232 END_PROFILE(SMBnttrans
);
3233 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
3236 /****************************************************************************
3237 Reply to a SMBnttranss
3238 ****************************************************************************/
3240 int reply_nttranss(connection_struct
*conn
, char *inbuf
,char *outbuf
,
3241 int size
,int bufsize
)
3244 unsigned int pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
3245 struct trans_state
*state
;
3247 START_PROFILE(SMBnttranss
);
3251 for (state
= conn
->pending_trans
; state
!= NULL
;
3252 state
= state
->next
) {
3253 if (state
->mid
== SVAL(inbuf
,smb_mid
)) {
3258 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
3259 END_PROFILE(SMBnttranss
);
3260 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);
3263 /* Revise state->total_param and state->total_data in case they have
3264 changed downwards */
3265 if (IVAL(inbuf
, smb_nts_TotalParameterCount
) < state
->total_param
) {
3266 state
->total_param
= IVAL(inbuf
, smb_nts_TotalParameterCount
);
3268 if (IVAL(inbuf
, smb_nts_TotalDataCount
) < state
->total_data
) {
3269 state
->total_data
= IVAL(inbuf
, smb_nts_TotalDataCount
);
3272 pcnt
= IVAL(inbuf
,smb_nts_ParameterCount
);
3273 poff
= IVAL(inbuf
, smb_nts_ParameterOffset
);
3274 pdisp
= IVAL(inbuf
, smb_nts_ParameterDisplacement
);
3276 dcnt
= IVAL(inbuf
, smb_nts_DataCount
);
3277 ddisp
= IVAL(inbuf
, smb_nts_DataDisplacement
);
3278 doff
= IVAL(inbuf
, smb_nts_DataOffset
);
3280 state
->received_param
+= pcnt
;
3281 state
->received_data
+= dcnt
;
3283 if ((state
->received_data
> state
->total_data
) ||
3284 (state
->received_param
> state
->total_param
))
3288 if (pdisp
+pcnt
> state
->total_param
)
3290 if ((pdisp
+pcnt
< pdisp
) || (pdisp
+pcnt
< pcnt
))
3292 if (pdisp
> state
->total_param
)
3294 if ((smb_base(inbuf
) + poff
+ pcnt
> inbuf
+ size
) ||
3295 (smb_base(inbuf
) + poff
+ pcnt
< smb_base(inbuf
)))
3297 if (state
->param
+ pdisp
< state
->param
)
3300 memcpy(state
->param
+pdisp
,smb_base(inbuf
)+poff
,
3305 if (ddisp
+dcnt
> state
->total_data
)
3307 if ((ddisp
+dcnt
< ddisp
) || (ddisp
+dcnt
< dcnt
))
3309 if (ddisp
> state
->total_data
)
3311 if ((smb_base(inbuf
) + doff
+ dcnt
> inbuf
+ size
) ||
3312 (smb_base(inbuf
) + doff
+ dcnt
< smb_base(inbuf
)))
3314 if (state
->data
+ ddisp
< state
->data
)
3317 memcpy(state
->data
+ddisp
, smb_base(inbuf
)+doff
,
3321 if ((state
->received_param
< state
->total_param
) ||
3322 (state
->received_data
< state
->total_data
)) {
3323 END_PROFILE(SMBnttranss
);
3327 /* construct_reply_common has done us the favor to pre-fill the
3328 * command field with SMBnttranss which is wrong :-)
3330 SCVAL(outbuf
,smb_com
,SMBnttrans
);
3332 outsize
= handle_nttrans(conn
, state
, inbuf
, outbuf
,
3335 DLIST_REMOVE(conn
->pending_trans
, state
);
3336 SAFE_FREE(state
->data
);
3337 SAFE_FREE(state
->param
);
3341 END_PROFILE(SMBnttranss
);
3342 return(ERROR_DOS(ERRSRV
,ERRnosupport
));
3345 END_PROFILE(SMBnttranss
);
3350 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3351 DLIST_REMOVE(conn
->pending_trans
, state
);
3352 SAFE_FREE(state
->data
);
3353 SAFE_FREE(state
->param
);
3355 END_PROFILE(SMBnttranss
);
3356 return ERROR_NT(NT_STATUS_INVALID_PARAMETER
);