2 Unix SMB/CIFS implementation.
3 SMB NT transaction handling
4 Copyright (C) Jeremy Allison 1994-2007
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 struct current_user current_user
;
27 static const char *known_nt_pipes
[] = {
48 static char *nttrans_realloc(char **ptr
, size_t size
)
51 smb_panic("nttrans_realloc() called with NULL ptr");
54 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
58 memset(*ptr
,'\0',size
);
62 /****************************************************************************
63 Send the required number of replies back.
64 We assume all fields other than the data fields are
65 set correctly for the type of call.
66 HACK ! Always assumes smb_setup field is zero.
67 ****************************************************************************/
69 void send_nt_replies(connection_struct
*conn
,
70 struct smb_request
*req
, NTSTATUS nt_error
,
71 char *params
, int paramsize
,
72 char *pdata
, int datasize
)
74 int data_to_send
= datasize
;
75 int params_to_send
= paramsize
;
79 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
80 int alignment_offset
= 3;
81 int data_alignment_offset
= 0;
84 * If there genuinely are no parameters or data to send just send
88 if(params_to_send
== 0 && data_to_send
== 0) {
89 reply_outbuf(req
, 18, 0);
90 show_msg((char *)req
->outbuf
);
95 * When sending params and data ensure that both are nicely aligned.
96 * Only do this alignment when there is also data to send - else
97 * can cause NT redirector problems.
100 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
101 data_alignment_offset
= 4 - (params_to_send
% 4);
105 * Space is bufsize minus Netbios over TCP header minus SMB header.
106 * The alignment_offset is to align the param bytes on a four byte
107 * boundary (2 bytes for data len, one byte pad).
108 * NT needs this to work correctly.
111 useable_space
= max_send
- (smb_size
114 + data_alignment_offset
);
117 * useable_space can never be more than max_send minus the
121 useable_space
= MIN(useable_space
,
122 max_send
- (alignment_offset
+data_alignment_offset
));
125 while (params_to_send
|| data_to_send
) {
128 * Calculate whether we will totally or partially fill this packet.
131 total_sent_thistime
= params_to_send
+ data_to_send
+
132 alignment_offset
+ data_alignment_offset
;
135 * We can never send more than useable_space.
138 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
140 reply_outbuf(req
, 18, total_sent_thistime
);
143 * Set total params and data to be sent.
146 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
147 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
150 * Calculate how many parameters and data we can fit into
151 * this packet. Parameters get precedence.
154 params_sent_thistime
= MIN(params_to_send
,useable_space
);
155 data_sent_thistime
= useable_space
- params_sent_thistime
;
156 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
158 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
159 params_sent_thistime
);
161 if(params_sent_thistime
== 0) {
162 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
163 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
166 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
167 * parameter bytes, however the first 4 bytes of outbuf are
168 * the Netbios over TCP header. Thus use smb_base() to subtract
169 * them from the calculation.
172 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
173 ((smb_buf(req
->outbuf
)+alignment_offset
)
174 - smb_base(req
->outbuf
)));
176 * Absolute displacement of param bytes sent in this packet.
179 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
184 * Deal with the data portion.
187 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
189 if(data_sent_thistime
== 0) {
190 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
191 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
194 * The offset of the data bytes is the offset of the
195 * parameter bytes plus the number of parameters being sent this time.
198 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
199 ((smb_buf(req
->outbuf
)+alignment_offset
) -
200 smb_base(req
->outbuf
))
201 + params_sent_thistime
+ data_alignment_offset
);
202 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
206 * Copy the param bytes into the packet.
209 if(params_sent_thistime
) {
210 if (alignment_offset
!= 0) {
211 memset(smb_buf(req
->outbuf
), 0,
214 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
215 params_sent_thistime
);
219 * Copy in the data bytes
222 if(data_sent_thistime
) {
223 if (data_alignment_offset
!= 0) {
224 memset((smb_buf(req
->outbuf
)+alignment_offset
+
225 params_sent_thistime
), 0,
226 data_alignment_offset
);
228 memcpy(smb_buf(req
->outbuf
)+alignment_offset
229 +params_sent_thistime
+data_alignment_offset
,
230 pd
,data_sent_thistime
);
233 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
234 params_sent_thistime
, data_sent_thistime
, useable_space
));
235 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
236 params_to_send
, data_to_send
, paramsize
, datasize
));
238 if (NT_STATUS_V(nt_error
)) {
239 error_packet_set((char *)req
->outbuf
,
244 /* Send the packet */
245 show_msg((char *)req
->outbuf
);
246 if (!srv_send_smb(smbd_server_fd(),
248 IS_CONN_ENCRYPTED(conn
))) {
249 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
252 TALLOC_FREE(req
->outbuf
);
254 pp
+= params_sent_thistime
;
255 pd
+= data_sent_thistime
;
257 params_to_send
-= params_sent_thistime
;
258 data_to_send
-= data_sent_thistime
;
264 if(params_to_send
< 0 || data_to_send
< 0) {
265 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
266 params_to_send
, data_to_send
));
272 /****************************************************************************
273 Is it an NTFS stream name ?
274 An NTFS file name is <path>.<extention>:<stream name>:<stream type>
275 $DATA can be used as both a stream name and a stream type. A missing stream
276 name or type implies $DATA.
277 ****************************************************************************/
279 bool is_ntfs_stream_name(const char *fname
)
281 if (lp_posix_pathnames()) {
284 return (strchr_m(fname
, ':') != NULL
) ? True
: False
;
287 /****************************************************************************
288 Reply to an NT create and X call on a pipe
289 ****************************************************************************/
291 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
292 struct smb_request
*req
, int *ppnum
)
294 smb_np_struct
*p
= NULL
;
297 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
299 /* See if it is one we want to handle. */
301 if (lp_disable_spoolss() && strequal(fname
, "\\spoolss")) {
302 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
307 for( i
= 0; known_nt_pipes
[i
]; i
++ ) {
308 if( strequal(fname
,known_nt_pipes
[i
])) {
313 if ( known_nt_pipes
[i
] == NULL
) {
314 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
319 /* Strip \\ off the name. */
322 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname
));
324 p
= open_rpc_pipe_p(fname
, conn
, req
->vuid
);
326 reply_doserror(req
, ERRSRV
, ERRnofids
);
330 /* TODO: Add pipe to db */
332 if ( !store_pipe_opendb( p
) ) {
333 DEBUG(3,("nt_open_pipe: failed to store %s pipe open.\n", fname
));
340 /****************************************************************************
341 Reply to an NT create and X call for pipes.
342 ****************************************************************************/
344 static void do_ntcreate_pipe_open(connection_struct
*conn
,
345 struct smb_request
*req
)
350 uint32 flags
= IVAL(req
->inbuf
,smb_ntcreate_Flags
);
351 TALLOC_CTX
*ctx
= talloc_tos();
353 srvstr_pull_buf_talloc(ctx
, (char *)req
->inbuf
, req
->flags2
, &fname
,
354 smb_buf(req
->inbuf
), STR_TERMINATE
);
357 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
361 nt_open_pipe(fname
, conn
, req
, &pnum
);
369 * Deal with pipe return.
372 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
373 /* This is very strange. We
374 * return 50 words, but only set
375 * the wcnt to 42 ? It's definately
376 * what happens on the wire....
378 reply_outbuf(req
, 50, 0);
379 SCVAL(req
->outbuf
,smb_wct
,42);
381 reply_outbuf(req
, 34, 0);
384 p
= (char *)req
->outbuf
+ smb_vwv2
;
388 SIVAL(p
,0,FILE_WAS_OPENED
);
391 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
394 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
396 SSVAL(p
,2, 0x5FF); /* ? */
399 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
401 SIVAL(p
,0,FILE_GENERIC_ALL
);
403 * For pipes W2K3 seems to return
405 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
407 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
410 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
415 /****************************************************************************
416 Reply to an NT create and X call.
417 ****************************************************************************/
419 void reply_ntcreate_and_X(struct smb_request
*req
)
421 connection_struct
*conn
= req
->conn
;
425 uint32 file_attributes
;
427 uint32 create_disposition
;
428 uint32 create_options
;
430 SMB_BIG_UINT allocation_size
;
431 /* Breakout the oplock request bits so we can set the
432 reply bits separately. */
434 SMB_OFF_T file_len
= 0;
435 SMB_STRUCT_STAT sbuf
;
437 files_struct
*fsp
= NULL
;
439 struct timespec c_timespec
;
440 struct timespec a_timespec
;
441 struct timespec m_timespec
;
444 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
445 TALLOC_CTX
*ctx
= talloc_tos();
447 START_PROFILE(SMBntcreateX
);
450 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
454 flags
= IVAL(req
->inbuf
,smb_ntcreate_Flags
);
455 access_mask
= IVAL(req
->inbuf
,smb_ntcreate_DesiredAccess
);
456 file_attributes
= IVAL(req
->inbuf
,smb_ntcreate_FileAttributes
);
457 share_access
= IVAL(req
->inbuf
,smb_ntcreate_ShareAccess
);
458 create_disposition
= IVAL(req
->inbuf
,smb_ntcreate_CreateDisposition
);
459 create_options
= IVAL(req
->inbuf
,smb_ntcreate_CreateOptions
);
460 root_dir_fid
= (uint16
)IVAL(req
->inbuf
,smb_ntcreate_RootDirectoryFid
);
462 allocation_size
= (SMB_BIG_UINT
)IVAL(req
->inbuf
,
463 smb_ntcreate_AllocationSize
);
464 #ifdef LARGE_SMB_OFF_T
465 allocation_size
|= (((SMB_BIG_UINT
)IVAL(
467 smb_ntcreate_AllocationSize
+ 4)) << 32);
470 srvstr_get_path(ctx
, (char *)req
->inbuf
, req
->flags2
, &fname
,
471 smb_buf(req
->inbuf
), 0, STR_TERMINATE
, &status
);
473 if (!NT_STATUS_IS_OK(status
)) {
474 reply_nterror(req
, status
);
475 END_PROFILE(SMBntcreateX
);
479 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
480 "file_attributes = 0x%x, share_access = 0x%x, "
481 "create_disposition = 0x%x create_options = 0x%x "
482 "root_dir_fid = 0x%x, fname = %s\n",
484 (unsigned int)access_mask
,
485 (unsigned int)file_attributes
,
486 (unsigned int)share_access
,
487 (unsigned int)create_disposition
,
488 (unsigned int)create_options
,
489 (unsigned int)root_dir_fid
,
493 * we need to remove ignored bits when they come directly from the client
494 * because we reuse some of them for internal stuff
496 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
499 * If it's an IPC, use the pipe handler.
503 if (lp_nt_pipe_support()) {
504 do_ntcreate_pipe_open(conn
, req
);
505 END_PROFILE(SMBntcreateX
);
508 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
509 END_PROFILE(SMBntcreateX
);
513 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
514 if (oplock_request
) {
515 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
519 status
= create_file(conn
, req
, root_dir_fid
, fname
,
520 access_mask
, share_access
, create_disposition
,
521 create_options
, file_attributes
, oplock_request
,
522 allocation_size
, NULL
, NULL
, &fsp
, &info
, &sbuf
);
524 if (!NT_STATUS_IS_OK(status
)) {
525 if (open_was_deferred(req
->mid
)) {
526 /* We have re-scheduled this call, no error. */
527 END_PROFILE(SMBntcreateX
);
530 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
531 reply_botherror(req
, status
, ERRDOS
, ERRfilexists
);
534 reply_nterror(req
, status
);
536 END_PROFILE(SMBntcreateX
);
541 * If the caller set the extended oplock request bit
542 * and we granted one (by whatever means) - set the
543 * correct bit for extended oplock reply.
546 if (oplock_request
&&
547 (lp_fake_oplocks(SNUM(conn
))
548 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
551 * Exclusive oplock granted
554 if (flags
& REQUEST_BATCH_OPLOCK
) {
555 oplock_granted
= BATCH_OPLOCK_RETURN
;
557 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
559 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
560 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
562 oplock_granted
= NO_OPLOCK_RETURN
;
565 file_len
= sbuf
.st_size
;
566 fattr
= dos_mode(conn
,fsp
->fsp_name
,&sbuf
);
568 fattr
= FILE_ATTRIBUTE_NORMAL
;
571 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
572 /* This is very strange. We
573 * return 50 words, but only set
574 * the wcnt to 42 ? It's definately
575 * what happens on the wire....
577 reply_outbuf(req
, 50, 0);
578 SCVAL(req
->outbuf
,smb_wct
,42);
580 reply_outbuf(req
, 34, 0);
583 p
= (char *)req
->outbuf
+ smb_vwv2
;
585 SCVAL(p
, 0, oplock_granted
);
588 SSVAL(p
,0,fsp
->fnum
);
590 if ((create_disposition
== FILE_SUPERSEDE
)
591 && (info
== FILE_WAS_OVERWRITTEN
)) {
592 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
599 c_timespec
= get_create_timespec(
600 &sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
601 a_timespec
= get_atimespec(&sbuf
);
602 m_timespec
= get_mtimespec(&sbuf
);
604 if (lp_dos_filetime_resolution(SNUM(conn
))) {
605 dos_filetime_timespec(&c_timespec
);
606 dos_filetime_timespec(&a_timespec
);
607 dos_filetime_timespec(&m_timespec
);
610 put_long_date_timespec(p
, c_timespec
); /* create time. */
612 put_long_date_timespec(p
, a_timespec
); /* access time */
614 put_long_date_timespec(p
, m_timespec
); /* write time */
616 put_long_date_timespec(p
, m_timespec
); /* change time */
618 SIVAL(p
,0,fattr
); /* File Attributes. */
620 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
622 SOFF_T(p
,0,file_len
);
624 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
628 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
630 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
633 if (fsp
->is_directory
634 || can_write_to_file(conn
, fsp
->fsp_name
, &sbuf
)) {
635 perms
= FILE_GENERIC_ALL
;
637 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
642 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
643 fsp
->fnum
, fsp
->fsp_name
));
646 END_PROFILE(SMBntcreateX
);
650 /****************************************************************************
651 Reply to a NT_TRANSACT_CREATE call to open a pipe.
652 ****************************************************************************/
654 static void do_nt_transact_create_pipe(connection_struct
*conn
,
655 struct smb_request
*req
,
656 uint16
**ppsetup
, uint32 setup_count
,
657 char **ppparams
, uint32 parameter_count
,
658 char **ppdata
, uint32 data_count
)
661 char *params
= *ppparams
;
667 TALLOC_CTX
*ctx
= talloc_tos();
670 * Ensure minimum number of parameters sent.
673 if(parameter_count
< 54) {
674 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
675 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
679 flags
= IVAL(params
,0);
681 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
682 parameter_count
-53, STR_TERMINATE
,
684 if (!NT_STATUS_IS_OK(status
)) {
685 reply_nterror(req
, status
);
689 nt_open_pipe(fname
, conn
, req
, &pnum
);
696 /* Realloc the size of parameters and data we will return */
697 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
698 /* Extended response is 32 more byyes. */
703 params
= nttrans_realloc(ppparams
, param_len
);
705 reply_doserror(req
, ERRDOS
, ERRnomem
);
710 SCVAL(p
,0,NO_OPLOCK_RETURN
);
715 SIVAL(p
,0,FILE_WAS_OPENED
);
719 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
722 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
724 SSVAL(p
,2, 0x5FF); /* ? */
727 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
729 SIVAL(p
,0,FILE_GENERIC_ALL
);
731 * For pipes W2K3 seems to return
733 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
735 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
738 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
740 /* Send the required number of replies */
741 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
746 /****************************************************************************
747 Internal fn to set security descriptors.
748 ****************************************************************************/
750 static NTSTATUS
set_sd(files_struct
*fsp
, uint8
*data
, uint32 sd_len
,
751 uint32 security_info_sent
)
753 SEC_DESC
*psd
= NULL
;
756 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
760 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
762 if (!NT_STATUS_IS_OK(status
)) {
766 if (psd
->owner_sid
==0) {
767 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
769 if (psd
->group_sid
==0) {
770 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
773 security_info_sent
&= ~SACL_SECURITY_INFORMATION
;
776 security_info_sent
&= ~DACL_SECURITY_INFORMATION
;
779 if (fsp
->fh
->fd
!= -1) {
780 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
783 status
= SMB_VFS_SET_NT_ACL(fsp
, fsp
->fsp_name
,
784 security_info_sent
, psd
);
792 /****************************************************************************
793 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
794 ****************************************************************************/
796 static struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
798 struct ea_list
*ea_list_head
= NULL
;
805 while (offset
+ 4 <= data_size
) {
806 size_t next_offset
= IVAL(pdata
,offset
);
807 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
813 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
814 if (next_offset
== 0) {
817 offset
+= next_offset
;
823 /****************************************************************************
824 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
825 ****************************************************************************/
827 static void call_nt_transact_create(connection_struct
*conn
,
828 struct smb_request
*req
,
829 uint16
**ppsetup
, uint32 setup_count
,
830 char **ppparams
, uint32 parameter_count
,
831 char **ppdata
, uint32 data_count
,
832 uint32 max_data_count
)
835 char *params
= *ppparams
;
836 char *data
= *ppdata
;
837 /* Breakout the oplock request bits so we can set the reply bits separately. */
839 SMB_OFF_T file_len
= 0;
840 SMB_STRUCT_STAT sbuf
;
842 files_struct
*fsp
= NULL
;
846 uint32 file_attributes
;
848 uint32 create_disposition
;
849 uint32 create_options
;
851 struct security_descriptor
*sd
= NULL
;
854 struct timespec c_timespec
;
855 struct timespec a_timespec
;
856 struct timespec m_timespec
;
857 struct ea_list
*ea_list
= NULL
;
860 SMB_BIG_UINT allocation_size
;
862 uint8_t oplock_granted
;
863 TALLOC_CTX
*ctx
= talloc_tos();
865 DEBUG(5,("call_nt_transact_create\n"));
868 * If it's an IPC, use the pipe handler.
872 if (lp_nt_pipe_support()) {
873 do_nt_transact_create_pipe(
875 ppsetup
, setup_count
,
876 ppparams
, parameter_count
,
880 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
885 * Ensure minimum number of parameters sent.
888 if(parameter_count
< 54) {
889 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
890 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
894 flags
= IVAL(params
,0);
895 access_mask
= IVAL(params
,8);
896 file_attributes
= IVAL(params
,20);
897 share_access
= IVAL(params
,24);
898 create_disposition
= IVAL(params
,28);
899 create_options
= IVAL(params
,32);
900 sd_len
= IVAL(params
,36);
901 ea_len
= IVAL(params
,40);
902 root_dir_fid
= (uint16
)IVAL(params
,4);
903 allocation_size
= (SMB_BIG_UINT
)IVAL(params
,12);
904 #ifdef LARGE_SMB_OFF_T
905 allocation_size
|= (((SMB_BIG_UINT
)IVAL(params
,16)) << 32);
909 * we need to remove ignored bits when they come directly from the client
910 * because we reuse some of them for internal stuff
912 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
914 /* Ensure the data_len is correct for the sd and ea values given. */
915 if ((ea_len
+ sd_len
> data_count
)
916 || (ea_len
> data_count
) || (sd_len
> data_count
)
917 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
918 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
919 "%u, data_count = %u\n", (unsigned int)ea_len
,
920 (unsigned int)sd_len
, (unsigned int)data_count
));
921 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
926 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
929 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
931 if (!NT_STATUS_IS_OK(status
)) {
932 DEBUG(10, ("call_nt_transact_create: "
933 "unmarshall_sec_desc failed: %s\n",
935 reply_nterror(req
, status
);
941 if (!lp_ea_support(SNUM(conn
))) {
942 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
943 "EA's not supported.\n",
944 (unsigned int)ea_len
));
945 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
950 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
951 "too small (should be more than 10)\n",
952 (unsigned int)ea_len
));
953 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
957 /* We have already checked that ea_len <= data_count here. */
958 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
960 if (ea_list
== NULL
) {
961 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
966 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
967 params
+53, parameter_count
-53,
968 STR_TERMINATE
, &status
);
969 if (!NT_STATUS_IS_OK(status
)) {
970 reply_nterror(req
, status
);
974 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
975 if (oplock_request
) {
976 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
980 status
= create_file(conn
, req
, root_dir_fid
, fname
,
981 access_mask
, share_access
, create_disposition
,
982 create_options
, file_attributes
, oplock_request
,
983 allocation_size
, sd
, ea_list
, &fsp
, &info
, &sbuf
);
985 if(!NT_STATUS_IS_OK(status
)) {
986 if (open_was_deferred(req
->mid
)) {
987 /* We have re-scheduled this call, no error. */
990 reply_openerror(req
, status
);
995 * If the caller set the extended oplock request bit
996 * and we granted one (by whatever means) - set the
997 * correct bit for extended oplock reply.
1000 if (oplock_request
&&
1001 (lp_fake_oplocks(SNUM(conn
))
1002 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1005 * Exclusive oplock granted
1008 if (flags
& REQUEST_BATCH_OPLOCK
) {
1009 oplock_granted
= BATCH_OPLOCK_RETURN
;
1011 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1013 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1014 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1016 oplock_granted
= NO_OPLOCK_RETURN
;
1019 file_len
= sbuf
.st_size
;
1020 fattr
= dos_mode(conn
,fsp
->fsp_name
,&sbuf
);
1022 fattr
= FILE_ATTRIBUTE_NORMAL
;
1025 /* Realloc the size of parameters and data we will return */
1026 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1027 /* Extended response is 32 more byyes. */
1032 params
= nttrans_realloc(ppparams
, param_len
);
1033 if(params
== NULL
) {
1034 reply_doserror(req
, ERRDOS
, ERRnomem
);
1039 SCVAL(p
, 0, oplock_granted
);
1042 SSVAL(p
,0,fsp
->fnum
);
1044 if ((create_disposition
== FILE_SUPERSEDE
)
1045 && (info
== FILE_WAS_OVERWRITTEN
)) {
1046 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1053 c_timespec
= get_create_timespec(
1054 &sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1055 a_timespec
= get_atimespec(&sbuf
);
1056 m_timespec
= get_mtimespec(&sbuf
);
1058 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1059 dos_filetime_timespec(&c_timespec
);
1060 dos_filetime_timespec(&a_timespec
);
1061 dos_filetime_timespec(&m_timespec
);
1064 put_long_date_timespec(p
, c_timespec
); /* create time. */
1066 put_long_date_timespec(p
, a_timespec
); /* access time */
1068 put_long_date_timespec(p
, m_timespec
); /* write time */
1070 put_long_date_timespec(p
, m_timespec
); /* change time */
1072 SIVAL(p
,0,fattr
); /* File Attributes. */
1074 SOFF_T(p
, 0, get_allocation_size(conn
,fsp
,&sbuf
));
1076 SOFF_T(p
,0,file_len
);
1078 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1082 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1084 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1087 if (fsp
->is_directory
1088 || can_write_to_file(conn
, fsp
->fsp_name
, &sbuf
)) {
1089 perms
= FILE_GENERIC_ALL
;
1091 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1096 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp
->fsp_name
));
1098 /* Send the required number of replies */
1099 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1104 /****************************************************************************
1105 Reply to a NT CANCEL request.
1106 conn POINTER CAN BE NULL HERE !
1107 ****************************************************************************/
1109 void reply_ntcancel(struct smb_request
*req
)
1112 * Go through and cancel any pending change notifies.
1115 START_PROFILE(SMBntcancel
);
1116 remove_pending_change_notify_requests_by_mid(req
->mid
);
1117 remove_pending_lock_requests_by_mid(req
->mid
);
1118 srv_cancel_sign_response(req
->mid
);
1120 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req
->mid
));
1122 END_PROFILE(SMBntcancel
);
1126 /****************************************************************************
1128 ****************************************************************************/
1130 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1131 connection_struct
*conn
,
1132 struct smb_request
*req
,
1133 const char *oldname_in
,
1134 const char *newname_in
,
1137 SMB_STRUCT_STAT sbuf1
, sbuf2
;
1138 char *oldname
= NULL
;
1139 char *newname
= NULL
;
1140 char *last_component_oldname
= NULL
;
1141 char *last_component_newname
= NULL
;
1142 files_struct
*fsp1
,*fsp2
;
1146 NTSTATUS status
= NT_STATUS_OK
;
1151 if (!CAN_WRITE(conn
)) {
1152 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1155 status
= unix_convert(ctx
, conn
, oldname_in
, False
, &oldname
,
1156 &last_component_oldname
, &sbuf1
);
1157 if (!NT_STATUS_IS_OK(status
)) {
1161 status
= check_name(conn
, oldname
);
1162 if (!NT_STATUS_IS_OK(status
)) {
1166 /* Source must already exist. */
1167 if (!VALID_STAT(sbuf1
)) {
1168 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1170 /* Ensure attributes match. */
1171 fattr
= dos_mode(conn
,oldname
,&sbuf1
);
1172 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1173 return NT_STATUS_NO_SUCH_FILE
;
1176 status
= unix_convert(ctx
, conn
, newname_in
, False
, &newname
,
1177 &last_component_newname
, &sbuf2
);
1178 if (!NT_STATUS_IS_OK(status
)) {
1182 status
= check_name(conn
, newname
);
1183 if (!NT_STATUS_IS_OK(status
)) {
1187 /* Disallow if newname already exists. */
1188 if (VALID_STAT(sbuf2
)) {
1189 return NT_STATUS_OBJECT_NAME_COLLISION
;
1192 /* No links from a directory. */
1193 if (S_ISDIR(sbuf1
.st_mode
)) {
1194 return NT_STATUS_FILE_IS_A_DIRECTORY
;
1197 /* Ensure this is within the share. */
1198 status
= check_reduced_name(conn
, oldname
);
1199 if (!NT_STATUS_IS_OK(status
)) {
1203 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1206 status
= open_file_ntcreate(conn
, req
, oldname
, &sbuf1
,
1207 FILE_READ_DATA
, /* Read-only. */
1208 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1210 0, /* No create options. */
1211 FILE_ATTRIBUTE_NORMAL
,
1215 if (!NT_STATUS_IS_OK(status
)) {
1219 status
= open_file_ntcreate(conn
, req
, newname
, &sbuf2
,
1220 FILE_WRITE_DATA
, /* Read-only. */
1221 FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
,
1223 0, /* No create options. */
1228 if (!NT_STATUS_IS_OK(status
)) {
1229 close_file(fsp1
,ERROR_CLOSE
);
1233 if (sbuf1
.st_size
) {
1234 ret
= vfs_transfer_file(fsp1
, fsp2
, sbuf1
.st_size
);
1238 * As we are opening fsp1 read-only we only expect
1239 * an error on close on fsp2 if we are out of space.
1240 * Thus we don't look at the error return from the
1243 close_file(fsp1
,NORMAL_CLOSE
);
1245 /* Ensure the modtime is set correctly on the destination file. */
1246 set_close_write_time(fsp2
, get_mtimespec(&sbuf1
));
1248 status
= close_file(fsp2
,NORMAL_CLOSE
);
1250 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1251 creates the file. This isn't the correct thing to do in the copy
1253 file_set_dosmode(conn
, newname
, fattr
, &sbuf2
,
1254 parent_dirname(newname
),false);
1256 if (ret
< (SMB_OFF_T
)sbuf1
.st_size
) {
1257 return NT_STATUS_DISK_FULL
;
1260 if (!NT_STATUS_IS_OK(status
)) {
1261 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1262 nt_errstr(status
), oldname
, newname
));
1267 /****************************************************************************
1268 Reply to a NT rename request.
1269 ****************************************************************************/
1271 void reply_ntrename(struct smb_request
*req
)
1273 connection_struct
*conn
= req
->conn
;
1274 char *oldname
= NULL
;
1275 char *newname
= NULL
;
1278 bool src_has_wcard
= False
;
1279 bool dest_has_wcard
= False
;
1282 TALLOC_CTX
*ctx
= talloc_tos();
1284 START_PROFILE(SMBntrename
);
1287 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1288 END_PROFILE(SMBntrename
);
1292 attrs
= SVAL(req
->inbuf
,smb_vwv0
);
1293 rename_type
= SVAL(req
->inbuf
,smb_vwv1
);
1295 p
= smb_buf(req
->inbuf
) + 1;
1296 p
+= srvstr_get_path_wcard(ctx
, (char *)req
->inbuf
, req
->flags2
, &oldname
, p
,
1297 0, STR_TERMINATE
, &status
,
1299 if (!NT_STATUS_IS_OK(status
)) {
1300 reply_nterror(req
, status
);
1301 END_PROFILE(SMBntrename
);
1305 if( is_ntfs_stream_name(oldname
)) {
1306 /* Can't rename a stream. */
1307 reply_nterror(req
, NT_STATUS_ACCESS_DENIED
);
1308 END_PROFILE(SMBntrename
);
1312 if (ms_has_wild(oldname
)) {
1313 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1314 END_PROFILE(SMBntrename
);
1319 p
+= srvstr_get_path_wcard(ctx
, (char *)req
->inbuf
, req
->flags2
, &newname
, p
,
1320 0, STR_TERMINATE
, &status
,
1322 if (!NT_STATUS_IS_OK(status
)) {
1323 reply_nterror(req
, status
);
1324 END_PROFILE(SMBntrename
);
1328 status
= resolve_dfspath(ctx
, conn
,
1329 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1332 if (!NT_STATUS_IS_OK(status
)) {
1333 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1334 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
1335 ERRSRV
, ERRbadpath
);
1336 END_PROFILE(SMBntrename
);
1339 reply_nterror(req
, status
);
1340 END_PROFILE(SMBntrename
);
1344 status
= resolve_dfspath(ctx
, conn
,
1345 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1348 if (!NT_STATUS_IS_OK(status
)) {
1349 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1350 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
1351 ERRSRV
, ERRbadpath
);
1352 END_PROFILE(SMBntrename
);
1355 reply_nterror(req
, status
);
1356 END_PROFILE(SMBntrename
);
1360 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1362 switch(rename_type
) {
1363 case RENAME_FLAG_RENAME
:
1364 status
= rename_internals(ctx
, conn
, req
, oldname
,
1365 newname
, attrs
, False
, src_has_wcard
,
1366 dest_has_wcard
, DELETE_ACCESS
);
1368 case RENAME_FLAG_HARD_LINK
:
1369 if (src_has_wcard
|| dest_has_wcard
) {
1371 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1373 status
= hardlink_internals(ctx
,
1379 case RENAME_FLAG_COPY
:
1380 if (src_has_wcard
|| dest_has_wcard
) {
1382 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1384 status
= copy_internals(ctx
, conn
, req
, oldname
,
1388 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1389 status
= NT_STATUS_INVALID_PARAMETER
;
1392 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1396 if (!NT_STATUS_IS_OK(status
)) {
1397 if (open_was_deferred(req
->mid
)) {
1398 /* We have re-scheduled this call. */
1399 END_PROFILE(SMBntrename
);
1403 reply_nterror(req
, status
);
1404 END_PROFILE(SMBntrename
);
1408 reply_outbuf(req
, 0, 0);
1410 END_PROFILE(SMBntrename
);
1414 /****************************************************************************
1415 Reply to a notify change - queue the request and
1416 don't allow a directory to be opened.
1417 ****************************************************************************/
1419 static void call_nt_transact_notify_change(connection_struct
*conn
,
1420 struct smb_request
*req
,
1424 uint32 parameter_count
,
1425 char **ppdata
, uint32 data_count
,
1426 uint32 max_data_count
,
1427 uint32 max_param_count
)
1429 uint16
*setup
= *ppsetup
;
1435 if(setup_count
< 6) {
1436 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1440 fsp
= file_fsp(SVAL(setup
,4));
1441 filter
= IVAL(setup
, 0);
1442 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1444 DEBUG(3,("call_nt_transact_notify_change\n"));
1447 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1452 char *filter_string
;
1454 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1455 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1459 DEBUG(3,("call_nt_transact_notify_change: notify change "
1460 "called on %s, filter = %s, recursive = %d\n",
1461 fsp
->fsp_name
, filter_string
, recursive
));
1463 TALLOC_FREE(filter_string
);
1466 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1467 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1471 if (fsp
->notify
== NULL
) {
1473 status
= change_notify_create(fsp
, filter
, recursive
);
1475 if (!NT_STATUS_IS_OK(status
)) {
1476 DEBUG(10, ("change_notify_create returned %s\n",
1477 nt_errstr(status
)));
1478 reply_nterror(req
, status
);
1483 if (fsp
->notify
->num_changes
!= 0) {
1486 * We've got changes pending, respond immediately
1490 * TODO: write a torture test to check the filtering behaviour
1494 change_notify_reply(fsp
->conn
, req
->inbuf
, max_param_count
, fsp
->notify
);
1497 * change_notify_reply() above has independently sent its
1504 * No changes pending, queue the request
1507 status
= change_notify_add_request(req
,
1511 if (!NT_STATUS_IS_OK(status
)) {
1512 reply_nterror(req
, status
);
1517 /****************************************************************************
1518 Reply to an NT transact rename command.
1519 ****************************************************************************/
1521 static void call_nt_transact_rename(connection_struct
*conn
,
1522 struct smb_request
*req
,
1523 uint16
**ppsetup
, uint32 setup_count
,
1524 char **ppparams
, uint32 parameter_count
,
1525 char **ppdata
, uint32 data_count
,
1526 uint32 max_data_count
)
1528 char *params
= *ppparams
;
1529 char *new_name
= NULL
;
1530 files_struct
*fsp
= NULL
;
1531 bool dest_has_wcard
= False
;
1533 TALLOC_CTX
*ctx
= talloc_tos();
1535 if(parameter_count
< 5) {
1536 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1540 fsp
= file_fsp(SVAL(params
, 0));
1541 if (!check_fsp(conn
, req
, fsp
, ¤t_user
)) {
1544 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1545 parameter_count
- 4,
1546 STR_TERMINATE
, &status
, &dest_has_wcard
);
1547 if (!NT_STATUS_IS_OK(status
)) {
1548 reply_nterror(req
, status
);
1553 * W2K3 ignores this request as the RAW-RENAME test
1554 * demonstrates, so we do.
1556 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1558 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1559 fsp
->fsp_name
, new_name
));
1564 /******************************************************************************
1565 Fake up a completely empty SD.
1566 *******************************************************************************/
1568 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1572 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1574 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1575 return NT_STATUS_NO_MEMORY
;
1578 return NT_STATUS_OK
;
1581 /****************************************************************************
1582 Reply to query a security descriptor.
1583 ****************************************************************************/
1585 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1586 struct smb_request
*req
,
1590 uint32 parameter_count
,
1593 uint32 max_data_count
)
1595 char *params
= *ppparams
;
1596 char *data
= *ppdata
;
1597 SEC_DESC
*psd
= NULL
;
1599 uint32 security_info_wanted
;
1600 files_struct
*fsp
= NULL
;
1604 if(parameter_count
< 8) {
1605 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1609 fsp
= file_fsp(SVAL(params
,0));
1611 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1615 security_info_wanted
= IVAL(params
,4);
1617 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp
->fsp_name
,
1618 (unsigned int)security_info_wanted
));
1620 params
= nttrans_realloc(ppparams
, 4);
1621 if(params
== NULL
) {
1622 reply_doserror(req
, ERRDOS
, ERRnomem
);
1627 * Get the permissions to return.
1630 if (!lp_nt_acl_support(SNUM(conn
))) {
1631 status
= get_null_nt_acl(talloc_tos(), &psd
);
1633 if (fsp
->fh
->fd
!= -1) {
1634 status
= SMB_VFS_FGET_NT_ACL(
1635 fsp
, security_info_wanted
, &psd
);
1638 status
= SMB_VFS_GET_NT_ACL(
1639 conn
, fsp
->fsp_name
, security_info_wanted
, &psd
);
1643 if (!NT_STATUS_IS_OK(status
)) {
1644 reply_nterror(req
, status
);
1648 sd_size
= ndr_size_security_descriptor(psd
, 0);
1650 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
1652 SIVAL(params
,0,(uint32
)sd_size
);
1654 if (max_data_count
< sd_size
) {
1655 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1656 params
, 4, *ppdata
, 0);
1661 * Allocate the data we will point this at.
1664 data
= nttrans_realloc(ppdata
, sd_size
);
1666 reply_doserror(req
, ERRDOS
, ERRnomem
);
1670 status
= marshall_sec_desc(talloc_tos(), psd
,
1671 &blob
.data
, &blob
.length
);
1673 if (!NT_STATUS_IS_OK(status
)) {
1674 reply_nterror(req
, status
);
1678 SMB_ASSERT(sd_size
== blob
.length
);
1679 memcpy(data
, blob
.data
, sd_size
);
1681 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1686 /****************************************************************************
1687 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1688 ****************************************************************************/
1690 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1691 struct smb_request
*req
,
1695 uint32 parameter_count
,
1698 uint32 max_data_count
)
1700 char *params
= *ppparams
;
1701 char *data
= *ppdata
;
1702 files_struct
*fsp
= NULL
;
1703 uint32 security_info_sent
= 0;
1706 if(parameter_count
< 8) {
1707 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1711 if((fsp
= file_fsp(SVAL(params
,0))) == NULL
) {
1712 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1716 if(!lp_nt_acl_support(SNUM(conn
))) {
1720 security_info_sent
= IVAL(params
,4);
1722 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
1723 (unsigned int)security_info_sent
));
1725 if (data_count
== 0) {
1726 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
1730 status
= set_sd(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
1732 if (!NT_STATUS_IS_OK(status
)) {
1733 reply_nterror(req
, status
);
1738 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1742 /****************************************************************************
1744 ****************************************************************************/
1746 static void call_nt_transact_ioctl(connection_struct
*conn
,
1747 struct smb_request
*req
,
1748 uint16
**ppsetup
, uint32 setup_count
,
1749 char **ppparams
, uint32 parameter_count
,
1750 char **ppdata
, uint32 data_count
,
1751 uint32 max_data_count
)
1758 static bool logged_message
;
1759 char *pdata
= *ppdata
;
1761 if (setup_count
!= 8) {
1762 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1763 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1767 function
= IVAL(*ppsetup
, 0);
1768 fidnum
= SVAL(*ppsetup
, 4);
1769 isFSctl
= CVAL(*ppsetup
, 6);
1770 compfilter
= CVAL(*ppsetup
, 7);
1772 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1773 function
, fidnum
, isFSctl
, compfilter
));
1775 fsp
=file_fsp(fidnum
);
1776 /* this check is done in each implemented function case for now
1777 because I don't want to break anything... --metze
1778 FSP_BELONGS_CONN(fsp,conn);*/
1781 case FSCTL_SET_SPARSE
:
1782 /* pretend this succeeded - tho strictly we should
1783 mark the file sparse (if the local fs supports it)
1784 so we can know if we need to pre-allocate or not */
1786 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1787 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1790 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
1792 unsigned char objid
[16];
1794 /* This should return the object-id on this file.
1795 * I think I'll make this be the inode+dev. JRA.
1798 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
1800 if (!fsp_belongs_conn(conn
, req
, fsp
, ¤t_user
)) {
1805 pdata
= nttrans_realloc(ppdata
, data_count
);
1806 if (pdata
== NULL
) {
1807 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1810 push_file_id_16(pdata
, &fsp
->file_id
);
1811 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
1812 push_file_id_16(pdata
+32, &fsp
->file_id
);
1813 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1818 case FSCTL_GET_REPARSE_POINT
:
1819 /* pretend this fail - my winXP does it like this
1823 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1824 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1827 case FSCTL_SET_REPARSE_POINT
:
1828 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1832 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1833 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1836 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
1839 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1840 * and return their volume names. If max_data_count is 16, then it is just
1841 * asking for the number of volumes and length of the combined names.
1843 * pdata is the data allocated by our caller, but that uses
1844 * total_data_count (which is 0 in our case) rather than max_data_count.
1845 * Allocate the correct amount and return the pointer to let
1846 * it be deallocated when we return.
1848 SHADOW_COPY_DATA
*shadow_data
= NULL
;
1849 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
1850 bool labels
= False
;
1851 uint32 labels_data_count
= 0;
1855 if (!fsp_belongs_conn(conn
, req
, fsp
, ¤t_user
)) {
1859 if (max_data_count
< 16) {
1860 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1862 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1866 if (max_data_count
> 16) {
1870 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
1871 if (shadow_mem_ctx
== NULL
) {
1872 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1873 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1877 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
1878 if (shadow_data
== NULL
) {
1879 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1880 talloc_destroy(shadow_mem_ctx
);
1881 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1885 shadow_data
->mem_ctx
= shadow_mem_ctx
;
1888 * Call the VFS routine to actually do the work.
1890 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
1891 talloc_destroy(shadow_data
->mem_ctx
);
1892 if (errno
== ENOSYS
) {
1893 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1894 conn
->connectpath
));
1895 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1898 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1899 conn
->connectpath
));
1900 reply_nterror(req
, NT_STATUS_UNSUCCESSFUL
);
1905 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
1910 data_count
= 12+labels_data_count
+4;
1913 if (max_data_count
<data_count
) {
1914 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1915 max_data_count
,data_count
));
1916 talloc_destroy(shadow_data
->mem_ctx
);
1917 reply_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
1921 pdata
= nttrans_realloc(ppdata
, data_count
);
1922 if (pdata
== NULL
) {
1923 talloc_destroy(shadow_data
->mem_ctx
);
1924 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1930 /* num_volumes 4 bytes */
1931 SIVAL(pdata
,0,shadow_data
->num_volumes
);
1934 /* num_labels 4 bytes */
1935 SIVAL(pdata
,4,shadow_data
->num_volumes
);
1938 /* needed_data_count 4 bytes */
1939 SIVAL(pdata
,8,labels_data_count
);
1943 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
1944 shadow_data
->num_volumes
,fsp
->fsp_name
));
1945 if (labels
&& shadow_data
->labels
) {
1946 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
1947 srvstr_push(pdata
, req
->flags2
,
1948 cur_pdata
, shadow_data
->labels
[i
],
1949 2*sizeof(SHADOW_COPY_LABEL
),
1950 STR_UNICODE
|STR_TERMINATE
);
1951 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
1952 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
1956 talloc_destroy(shadow_data
->mem_ctx
);
1958 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1964 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
1966 /* pretend this succeeded -
1968 * we have to send back a list with all files owned by this SID
1970 * but I have to check that --metze
1974 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
1976 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
1978 if (!fsp_belongs_conn(conn
, req
, fsp
, ¤t_user
)) {
1982 /* unknown 4 bytes: this is not the length of the sid :-( */
1983 /*unknown = IVAL(pdata,0);*/
1985 sid_parse(pdata
+4,sid_len
,&sid
);
1986 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
1988 if (!sid_to_uid(&sid
, &uid
)) {
1989 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
1990 sid_string_dbg(&sid
),
1991 (unsigned long)sid_len
));
1995 /* we can take a look at the find source :-)
1997 * find ./ -uid $uid -name '*' is what we need here
2000 * and send 4bytes len and then NULL terminated unicode strings
2003 * but I don't know how to deal with the paged results
2004 * (maybe we can hang the result anywhere in the fsp struct)
2006 * we don't send all files at once
2007 * and at the next we should *not* start from the beginning,
2008 * so we have to cache the result
2013 /* this works for now... */
2014 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2018 if (!logged_message
) {
2019 logged_message
= True
; /* Only print this once... */
2020 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2025 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2029 #ifdef HAVE_SYS_QUOTAS
2030 /****************************************************************************
2031 Reply to get user quota
2032 ****************************************************************************/
2034 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2035 struct smb_request
*req
,
2039 uint32 parameter_count
,
2042 uint32 max_data_count
)
2044 NTSTATUS nt_status
= NT_STATUS_OK
;
2045 char *params
= *ppparams
;
2046 char *pdata
= *ppdata
;
2048 int data_len
=0,param_len
=0;
2051 files_struct
*fsp
= NULL
;
2055 bool start_enum
= True
;
2056 SMB_NTQUOTA_STRUCT qt
;
2057 SMB_NTQUOTA_LIST
*tmp_list
;
2058 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2063 if (current_user
.ut
.uid
!= 0) {
2064 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2065 lp_servicename(SNUM(conn
)),conn
->user
));
2066 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2071 * Ensure minimum number of parameters sent.
2074 if (parameter_count
< 4) {
2075 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2076 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2080 /* maybe we can check the quota_fnum */
2081 fsp
= file_fsp(SVAL(params
,0));
2082 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2083 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2084 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2088 /* the NULL pointer checking for fsp->fake_file_handle->pd
2089 * is done by CHECK_NTQUOTA_HANDLE_OK()
2091 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->pd
;
2093 level
= SVAL(params
,2);
2095 /* unknown 12 bytes leading in params */
2098 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2099 /* seems that we should continue with the enum here --metze */
2101 if (qt_handle
->quota_list
!=NULL
&&
2102 qt_handle
->tmp_list
==NULL
) {
2105 free_ntquota_list(&(qt_handle
->quota_list
));
2107 /* Realloc the size of parameters and data we will return */
2109 params
= nttrans_realloc(ppparams
, param_len
);
2110 if(params
== NULL
) {
2111 reply_doserror(req
, ERRDOS
, ERRnomem
);
2116 SIVAL(params
,0,data_len
);
2123 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2125 if (qt_handle
->quota_list
==NULL
&&
2126 qt_handle
->tmp_list
==NULL
) {
2130 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2131 reply_doserror(req
, ERRSRV
, ERRerror
);
2135 /* Realloc the size of parameters and data we will return */
2137 params
= nttrans_realloc(ppparams
, param_len
);
2138 if(params
== NULL
) {
2139 reply_doserror(req
, ERRDOS
, ERRnomem
);
2143 /* we should not trust the value in max_data_count*/
2144 max_data_count
= MIN(max_data_count
,2048);
2146 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2148 reply_doserror(req
, ERRDOS
, ERRnomem
);
2154 /* set params Size of returned Quota Data 4 bytes*/
2155 /* but set it later when we know it */
2157 /* for each entry push the data */
2160 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2163 tmp_list
= qt_handle
->tmp_list
;
2165 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2166 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2168 sid_len
= ndr_size_dom_sid(
2169 &tmp_list
->quotas
->sid
, 0);
2170 entry_len
= 40 + sid_len
;
2172 /* nextoffset entry 4 bytes */
2173 SIVAL(entry
,0,entry_len
);
2175 /* then the len of the SID 4 bytes */
2176 SIVAL(entry
,4,sid_len
);
2178 /* unknown data 8 bytes SMB_BIG_UINT */
2179 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-metze*/
2181 /* the used disk space 8 bytes SMB_BIG_UINT */
2182 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2184 /* the soft quotas 8 bytes SMB_BIG_UINT */
2185 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2187 /* the hard quotas 8 bytes SMB_BIG_UINT */
2188 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2190 /* and now the SID */
2191 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2194 qt_handle
->tmp_list
= tmp_list
;
2196 /* overwrite the offset of the last entry */
2197 SIVAL(entry
-entry_len
,0,0);
2199 data_len
= 4+qt_len
;
2200 /* overwrite the params quota_data_len */
2201 SIVAL(params
,0,data_len
);
2205 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2207 /* unknown 4 bytes IVAL(pdata,0) */
2209 if (data_count
< 8) {
2210 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2211 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2215 sid_len
= IVAL(pdata
,4);
2216 /* Ensure this is less than 1mb. */
2217 if (sid_len
> (1024*1024)) {
2218 reply_doserror(req
, ERRDOS
, ERRnomem
);
2222 if (data_count
< 8+sid_len
) {
2223 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2224 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2228 data_len
= 4+40+sid_len
;
2230 if (max_data_count
< data_len
) {
2231 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2232 max_data_count
, data_len
));
2234 SIVAL(params
,0,data_len
);
2236 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2240 sid_parse(pdata
+8,sid_len
,&sid
);
2242 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2245 * we have to return zero's in all fields
2246 * instead of returning an error here
2251 /* Realloc the size of parameters and data we will return */
2253 params
= nttrans_realloc(ppparams
, param_len
);
2254 if(params
== NULL
) {
2255 reply_doserror(req
, ERRDOS
, ERRnomem
);
2259 pdata
= nttrans_realloc(ppdata
, data_len
);
2261 reply_doserror(req
, ERRDOS
, ERRnomem
);
2267 /* set params Size of returned Quota Data 4 bytes*/
2268 SIVAL(params
,0,data_len
);
2270 /* nextoffset entry 4 bytes */
2273 /* then the len of the SID 4 bytes */
2274 SIVAL(entry
,4,sid_len
);
2276 /* unknown data 8 bytes SMB_BIG_UINT */
2277 SBIG_UINT(entry
,8,(SMB_BIG_UINT
)0); /* this is not 0 in windows...-mezte*/
2279 /* the used disk space 8 bytes SMB_BIG_UINT */
2280 SBIG_UINT(entry
,16,qt
.usedspace
);
2282 /* the soft quotas 8 bytes SMB_BIG_UINT */
2283 SBIG_UINT(entry
,24,qt
.softlim
);
2285 /* the hard quotas 8 bytes SMB_BIG_UINT */
2286 SBIG_UINT(entry
,32,qt
.hardlim
);
2288 /* and now the SID */
2289 sid_linearize(entry
+40, sid_len
, &sid
);
2294 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2295 reply_doserror(req
, ERRSRV
, ERRerror
);
2300 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2304 /****************************************************************************
2305 Reply to set user quota
2306 ****************************************************************************/
2308 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2309 struct smb_request
*req
,
2313 uint32 parameter_count
,
2316 uint32 max_data_count
)
2318 char *params
= *ppparams
;
2319 char *pdata
= *ppdata
;
2320 int data_len
=0,param_len
=0;
2321 SMB_NTQUOTA_STRUCT qt
;
2324 files_struct
*fsp
= NULL
;
2329 if (current_user
.ut
.uid
!= 0) {
2330 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2331 lp_servicename(SNUM(conn
)),conn
->user
));
2332 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2337 * Ensure minimum number of parameters sent.
2340 if (parameter_count
< 2) {
2341 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2342 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2346 /* maybe we can check the quota_fnum */
2347 fsp
= file_fsp(SVAL(params
,0));
2348 if (!CHECK_NTQUOTA_HANDLE_OK(fsp
,conn
)) {
2349 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2350 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2354 if (data_count
< 40) {
2355 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2356 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2360 /* offset to next quota record.
2361 * 4 bytes IVAL(pdata,0)
2366 sid_len
= IVAL(pdata
,4);
2368 if (data_count
< 40+sid_len
) {
2369 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2370 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2374 /* unknown 8 bytes in pdata
2375 * maybe its the change time in NTTIME
2378 /* the used space 8 bytes (SMB_BIG_UINT)*/
2379 qt
.usedspace
= (SMB_BIG_UINT
)IVAL(pdata
,16);
2380 #ifdef LARGE_SMB_OFF_T
2381 qt
.usedspace
|= (((SMB_BIG_UINT
)IVAL(pdata
,20)) << 32);
2382 #else /* LARGE_SMB_OFF_T */
2383 if ((IVAL(pdata
,20) != 0)&&
2384 ((qt
.usedspace
!= 0xFFFFFFFF)||
2385 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2386 /* more than 32 bits? */
2387 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2390 #endif /* LARGE_SMB_OFF_T */
2392 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2393 qt
.softlim
= (SMB_BIG_UINT
)IVAL(pdata
,24);
2394 #ifdef LARGE_SMB_OFF_T
2395 qt
.softlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,28)) << 32);
2396 #else /* LARGE_SMB_OFF_T */
2397 if ((IVAL(pdata
,28) != 0)&&
2398 ((qt
.softlim
!= 0xFFFFFFFF)||
2399 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2400 /* more than 32 bits? */
2401 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2404 #endif /* LARGE_SMB_OFF_T */
2406 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2407 qt
.hardlim
= (SMB_BIG_UINT
)IVAL(pdata
,32);
2408 #ifdef LARGE_SMB_OFF_T
2409 qt
.hardlim
|= (((SMB_BIG_UINT
)IVAL(pdata
,36)) << 32);
2410 #else /* LARGE_SMB_OFF_T */
2411 if ((IVAL(pdata
,36) != 0)&&
2412 ((qt
.hardlim
!= 0xFFFFFFFF)||
2413 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2414 /* more than 32 bits? */
2415 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2418 #endif /* LARGE_SMB_OFF_T */
2420 sid_parse(pdata
+40,sid_len
,&sid
);
2421 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2423 /* 44 unknown bytes left... */
2425 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2426 reply_doserror(req
, ERRSRV
, ERRerror
);
2430 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2433 #endif /* HAVE_SYS_QUOTAS */
2435 static void handle_nttrans(connection_struct
*conn
,
2436 struct trans_state
*state
,
2437 struct smb_request
*req
)
2439 if (Protocol
>= PROTOCOL_NT1
) {
2440 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2441 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2444 /* Now we must call the relevant NT_TRANS function */
2445 switch(state
->call
) {
2446 case NT_TRANSACT_CREATE
:
2448 START_PROFILE(NT_transact_create
);
2449 call_nt_transact_create(
2451 &state
->setup
, state
->setup_count
,
2452 &state
->param
, state
->total_param
,
2453 &state
->data
, state
->total_data
,
2454 state
->max_data_return
);
2455 END_PROFILE(NT_transact_create
);
2459 case NT_TRANSACT_IOCTL
:
2461 START_PROFILE(NT_transact_ioctl
);
2462 call_nt_transact_ioctl(
2464 &state
->setup
, state
->setup_count
,
2465 &state
->param
, state
->total_param
,
2466 &state
->data
, state
->total_data
,
2467 state
->max_data_return
);
2468 END_PROFILE(NT_transact_ioctl
);
2472 case NT_TRANSACT_SET_SECURITY_DESC
:
2474 START_PROFILE(NT_transact_set_security_desc
);
2475 call_nt_transact_set_security_desc(
2477 &state
->setup
, state
->setup_count
,
2478 &state
->param
, state
->total_param
,
2479 &state
->data
, state
->total_data
,
2480 state
->max_data_return
);
2481 END_PROFILE(NT_transact_set_security_desc
);
2485 case NT_TRANSACT_NOTIFY_CHANGE
:
2487 START_PROFILE(NT_transact_notify_change
);
2488 call_nt_transact_notify_change(
2490 &state
->setup
, state
->setup_count
,
2491 &state
->param
, state
->total_param
,
2492 &state
->data
, state
->total_data
,
2493 state
->max_data_return
,
2494 state
->max_param_return
);
2495 END_PROFILE(NT_transact_notify_change
);
2499 case NT_TRANSACT_RENAME
:
2501 START_PROFILE(NT_transact_rename
);
2502 call_nt_transact_rename(
2504 &state
->setup
, state
->setup_count
,
2505 &state
->param
, state
->total_param
,
2506 &state
->data
, state
->total_data
,
2507 state
->max_data_return
);
2508 END_PROFILE(NT_transact_rename
);
2512 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2514 START_PROFILE(NT_transact_query_security_desc
);
2515 call_nt_transact_query_security_desc(
2517 &state
->setup
, state
->setup_count
,
2518 &state
->param
, state
->total_param
,
2519 &state
->data
, state
->total_data
,
2520 state
->max_data_return
);
2521 END_PROFILE(NT_transact_query_security_desc
);
2525 #ifdef HAVE_SYS_QUOTAS
2526 case NT_TRANSACT_GET_USER_QUOTA
:
2528 START_PROFILE(NT_transact_get_user_quota
);
2529 call_nt_transact_get_user_quota(
2531 &state
->setup
, state
->setup_count
,
2532 &state
->param
, state
->total_param
,
2533 &state
->data
, state
->total_data
,
2534 state
->max_data_return
);
2535 END_PROFILE(NT_transact_get_user_quota
);
2539 case NT_TRANSACT_SET_USER_QUOTA
:
2541 START_PROFILE(NT_transact_set_user_quota
);
2542 call_nt_transact_set_user_quota(
2544 &state
->setup
, state
->setup_count
,
2545 &state
->param
, state
->total_param
,
2546 &state
->data
, state
->total_data
,
2547 state
->max_data_return
);
2548 END_PROFILE(NT_transact_set_user_quota
);
2551 #endif /* HAVE_SYS_QUOTAS */
2554 /* Error in request */
2555 DEBUG(0,("handle_nttrans: Unknown request %d in "
2556 "nttrans call\n", state
->call
));
2557 reply_doserror(req
, ERRSRV
, ERRerror
);
2563 /****************************************************************************
2564 Reply to a SMBNTtrans.
2565 ****************************************************************************/
2567 void reply_nttrans(struct smb_request
*req
)
2569 connection_struct
*conn
= req
->conn
;
2574 uint16 function_code
;
2576 struct trans_state
*state
;
2580 START_PROFILE(SMBnttrans
);
2582 if (req
->wct
< 19) {
2583 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2584 END_PROFILE(SMBnttrans
);
2588 size
= smb_len(req
->inbuf
) + 4;
2589 av_size
= smb_len(req
->inbuf
);
2590 pscnt
= IVAL(req
->inbuf
,smb_nt_ParameterCount
);
2591 psoff
= IVAL(req
->inbuf
,smb_nt_ParameterOffset
);
2592 dscnt
= IVAL(req
->inbuf
,smb_nt_DataCount
);
2593 dsoff
= IVAL(req
->inbuf
,smb_nt_DataOffset
);
2594 function_code
= SVAL(req
->inbuf
, smb_nt_Function
);
2596 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2597 reply_doserror(req
, ERRSRV
, ERRaccess
);
2598 END_PROFILE(SMBnttrans
);
2602 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2603 if (!NT_STATUS_IS_OK(result
)) {
2604 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2605 reply_nterror(req
, result
);
2606 END_PROFILE(SMBnttrans
);
2610 if ((state
= TALLOC_P(conn
->mem_ctx
, struct trans_state
)) == NULL
) {
2611 reply_doserror(req
, ERRSRV
, ERRaccess
);
2612 END_PROFILE(SMBnttrans
);
2616 state
->cmd
= SMBnttrans
;
2618 state
->mid
= req
->mid
;
2619 state
->vuid
= req
->vuid
;
2620 state
->total_data
= IVAL(req
->inbuf
, smb_nt_TotalDataCount
);
2622 state
->total_param
= IVAL(req
->inbuf
, smb_nt_TotalParameterCount
);
2623 state
->param
= NULL
;
2624 state
->max_data_return
= IVAL(req
->inbuf
,smb_nt_MaxDataCount
);
2625 state
->max_param_return
= IVAL(req
->inbuf
,smb_nt_MaxParameterCount
);
2627 /* setup count is in *words* */
2628 state
->setup_count
= 2*CVAL(req
->inbuf
,smb_nt_SetupCount
);
2629 state
->setup
= NULL
;
2630 state
->call
= function_code
;
2633 * All nttrans messages we handle have smb_wct == 19 +
2634 * state->setup_count. Ensure this is so as a sanity check.
2637 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2638 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2639 req
->wct
, 19 + (state
->setup_count
/2)));
2643 /* Don't allow more than 128mb for each value. */
2644 if ((state
->total_data
> (1024*1024*128)) ||
2645 (state
->total_param
> (1024*1024*128))) {
2646 reply_doserror(req
, ERRDOS
, ERRnomem
);
2647 END_PROFILE(SMBnttrans
);
2651 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2654 if (state
->total_data
) {
2655 /* Can't use talloc here, the core routines do realloc on the
2656 * params and data. */
2657 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2658 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2659 "bytes !\n", (unsigned int)state
->total_data
));
2661 reply_doserror(req
, ERRDOS
, ERRnomem
);
2662 END_PROFILE(SMBnttrans
);
2666 if (dscnt
> state
->total_data
||
2667 dsoff
+dscnt
< dsoff
) {
2671 if (dsoff
> av_size
||
2673 dsoff
+dscnt
> av_size
) {
2677 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2680 if (state
->total_param
) {
2681 /* Can't use talloc here, the core routines do realloc on the
2682 * params and data. */
2683 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2684 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2685 "bytes !\n", (unsigned int)state
->total_param
));
2686 SAFE_FREE(state
->data
);
2688 reply_doserror(req
, ERRDOS
, ERRnomem
);
2689 END_PROFILE(SMBnttrans
);
2693 if (pscnt
> state
->total_param
||
2694 psoff
+pscnt
< psoff
) {
2698 if (psoff
> av_size
||
2700 psoff
+pscnt
> av_size
) {
2704 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2707 state
->received_data
= dscnt
;
2708 state
->received_param
= pscnt
;
2710 if(state
->setup_count
> 0) {
2711 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2712 state
->setup_count
));
2713 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
2714 if (state
->setup
== NULL
) {
2715 DEBUG(0,("reply_nttrans : Out of memory\n"));
2716 SAFE_FREE(state
->data
);
2717 SAFE_FREE(state
->param
);
2719 reply_doserror(req
, ERRDOS
, ERRnomem
);
2720 END_PROFILE(SMBnttrans
);
2724 if ((smb_nt_SetupStart
+ state
->setup_count
< smb_nt_SetupStart
) ||
2725 (smb_nt_SetupStart
+ state
->setup_count
< state
->setup_count
)) {
2728 if (smb_nt_SetupStart
+ state
->setup_count
> size
) {
2732 memcpy( state
->setup
, &req
->inbuf
[smb_nt_SetupStart
],
2733 state
->setup_count
);
2734 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
2737 if ((state
->received_data
== state
->total_data
) &&
2738 (state
->received_param
== state
->total_param
)) {
2739 handle_nttrans(conn
, state
, req
);
2740 SAFE_FREE(state
->param
);
2741 SAFE_FREE(state
->data
);
2743 END_PROFILE(SMBnttrans
);
2747 DLIST_ADD(conn
->pending_trans
, state
);
2749 /* We need to send an interim response then receive the rest
2750 of the parameter/data bytes */
2751 reply_outbuf(req
, 0, 0);
2752 show_msg((char *)req
->outbuf
);
2753 END_PROFILE(SMBnttrans
);
2758 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2759 SAFE_FREE(state
->data
);
2760 SAFE_FREE(state
->param
);
2762 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2763 END_PROFILE(SMBnttrans
);
2767 /****************************************************************************
2768 Reply to a SMBnttranss
2769 ****************************************************************************/
2771 void reply_nttranss(struct smb_request
*req
)
2773 connection_struct
*conn
= req
->conn
;
2774 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2775 struct trans_state
*state
;
2779 START_PROFILE(SMBnttranss
);
2781 show_msg((char *)req
->inbuf
);
2783 if (req
->wct
< 18) {
2784 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2785 END_PROFILE(SMBnttranss
);
2789 for (state
= conn
->pending_trans
; state
!= NULL
;
2790 state
= state
->next
) {
2791 if (state
->mid
== req
->mid
) {
2796 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2797 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2798 END_PROFILE(SMBnttranss
);
2802 /* Revise state->total_param and state->total_data in case they have
2803 changed downwards */
2804 if (IVAL(req
->inbuf
, smb_nts_TotalParameterCount
)
2805 < state
->total_param
) {
2806 state
->total_param
= IVAL(req
->inbuf
,
2807 smb_nts_TotalParameterCount
);
2809 if (IVAL(req
->inbuf
, smb_nts_TotalDataCount
) < state
->total_data
) {
2810 state
->total_data
= IVAL(req
->inbuf
, smb_nts_TotalDataCount
);
2813 size
= smb_len(req
->inbuf
) + 4;
2814 av_size
= smb_len(req
->inbuf
);
2816 pcnt
= IVAL(req
->inbuf
,smb_nts_ParameterCount
);
2817 poff
= IVAL(req
->inbuf
, smb_nts_ParameterOffset
);
2818 pdisp
= IVAL(req
->inbuf
, smb_nts_ParameterDisplacement
);
2820 dcnt
= IVAL(req
->inbuf
, smb_nts_DataCount
);
2821 ddisp
= IVAL(req
->inbuf
, smb_nts_DataDisplacement
);
2822 doff
= IVAL(req
->inbuf
, smb_nts_DataOffset
);
2824 state
->received_param
+= pcnt
;
2825 state
->received_data
+= dcnt
;
2827 if ((state
->received_data
> state
->total_data
) ||
2828 (state
->received_param
> state
->total_param
))
2832 if (pdisp
> state
->total_param
||
2833 pcnt
> state
->total_param
||
2834 pdisp
+pcnt
> state
->total_param
||
2835 pdisp
+pcnt
< pdisp
) {
2839 if (poff
> av_size
||
2841 poff
+pcnt
> av_size
||
2846 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,
2851 if (ddisp
> state
->total_data
||
2852 dcnt
> state
->total_data
||
2853 ddisp
+dcnt
> state
->total_data
||
2854 ddisp
+dcnt
< ddisp
) {
2858 if (ddisp
> av_size
||
2860 ddisp
+dcnt
> av_size
||
2861 ddisp
+dcnt
< ddisp
) {
2865 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,
2869 if ((state
->received_param
< state
->total_param
) ||
2870 (state
->received_data
< state
->total_data
)) {
2871 END_PROFILE(SMBnttranss
);
2876 * construct_reply_common will copy smb_com from inbuf to
2877 * outbuf. SMBnttranss is wrong here.
2879 SCVAL(req
->inbuf
,smb_com
,SMBnttrans
);
2881 handle_nttrans(conn
, state
, req
);
2883 DLIST_REMOVE(conn
->pending_trans
, state
);
2884 SAFE_FREE(state
->data
);
2885 SAFE_FREE(state
->param
);
2887 END_PROFILE(SMBnttranss
);
2892 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2893 DLIST_REMOVE(conn
->pending_trans
, state
);
2894 SAFE_FREE(state
->data
);
2895 SAFE_FREE(state
->param
);
2897 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2898 END_PROFILE(SMBnttranss
);