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/>.
22 #include "smbd/globals.h"
24 extern const struct generic_mapping file_generic_mapping
;
26 static char *nttrans_realloc(char **ptr
, size_t size
)
29 smb_panic("nttrans_realloc() called with NULL ptr");
32 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
36 memset(*ptr
,'\0',size
);
40 /****************************************************************************
41 Send the required number of replies back.
42 We assume all fields other than the data fields are
43 set correctly for the type of call.
44 HACK ! Always assumes smb_setup field is zero.
45 ****************************************************************************/
47 void send_nt_replies(connection_struct
*conn
,
48 struct smb_request
*req
, NTSTATUS nt_error
,
49 char *params
, int paramsize
,
50 char *pdata
, int datasize
)
52 int data_to_send
= datasize
;
53 int params_to_send
= paramsize
;
57 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
58 int alignment_offset
= 3;
59 int data_alignment_offset
= 0;
60 struct smbd_server_connection
*sconn
= smbd_server_conn
;
61 int max_send
= sconn
->smb1
.sessions
.max_send
;
64 * If there genuinely are no parameters or data to send just send
68 if(params_to_send
== 0 && data_to_send
== 0) {
69 reply_outbuf(req
, 18, 0);
70 if (NT_STATUS_V(nt_error
)) {
71 error_packet_set((char *)req
->outbuf
,
75 show_msg((char *)req
->outbuf
);
76 if (!srv_send_smb(smbd_server_fd(),
79 IS_CONN_ENCRYPTED(conn
),
81 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
83 TALLOC_FREE(req
->outbuf
);
88 * When sending params and data ensure that both are nicely aligned.
89 * Only do this alignment when there is also data to send - else
90 * can cause NT redirector problems.
93 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
94 data_alignment_offset
= 4 - (params_to_send
% 4);
98 * Space is bufsize minus Netbios over TCP header minus SMB header.
99 * The alignment_offset is to align the param bytes on a four byte
100 * boundary (2 bytes for data len, one byte pad).
101 * NT needs this to work correctly.
104 useable_space
= max_send
- (smb_size
107 + data_alignment_offset
);
109 if (useable_space
< 0) {
110 char *msg
= talloc_asprintf(
112 "send_nt_replies failed sanity useable_space = %d!!!",
114 DEBUG(0, ("%s\n", msg
));
115 exit_server_cleanly(msg
);
118 while (params_to_send
|| data_to_send
) {
121 * Calculate whether we will totally or partially fill this packet.
124 total_sent_thistime
= params_to_send
+ data_to_send
;
127 * We can never send more than useable_space.
130 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
132 reply_outbuf(req
, 18,
133 total_sent_thistime
+ alignment_offset
134 + data_alignment_offset
);
137 * We might have had SMBnttranss in req->inbuf, fix that.
139 SCVAL(req
->outbuf
, smb_com
, SMBnttrans
);
142 * Set total params and data to be sent.
145 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
146 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
149 * Calculate how many parameters and data we can fit into
150 * this packet. Parameters get precedence.
153 params_sent_thistime
= MIN(params_to_send
,useable_space
);
154 data_sent_thistime
= useable_space
- params_sent_thistime
;
155 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
157 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
158 params_sent_thistime
);
160 if(params_sent_thistime
== 0) {
161 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
162 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
165 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
166 * parameter bytes, however the first 4 bytes of outbuf are
167 * the Netbios over TCP header. Thus use smb_base() to subtract
168 * them from the calculation.
171 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
172 ((smb_buf(req
->outbuf
)+alignment_offset
)
173 - smb_base(req
->outbuf
)));
175 * Absolute displacement of param bytes sent in this packet.
178 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
183 * Deal with the data portion.
186 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
188 if(data_sent_thistime
== 0) {
189 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
190 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
193 * The offset of the data bytes is the offset of the
194 * parameter bytes plus the number of parameters being sent this time.
197 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
198 ((smb_buf(req
->outbuf
)+alignment_offset
) -
199 smb_base(req
->outbuf
))
200 + params_sent_thistime
+ data_alignment_offset
);
201 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
205 * Copy the param bytes into the packet.
208 if(params_sent_thistime
) {
209 if (alignment_offset
!= 0) {
210 memset(smb_buf(req
->outbuf
), 0,
213 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
214 params_sent_thistime
);
218 * Copy in the data bytes
221 if(data_sent_thistime
) {
222 if (data_alignment_offset
!= 0) {
223 memset((smb_buf(req
->outbuf
)+alignment_offset
+
224 params_sent_thistime
), 0,
225 data_alignment_offset
);
227 memcpy(smb_buf(req
->outbuf
)+alignment_offset
228 +params_sent_thistime
+data_alignment_offset
,
229 pd
,data_sent_thistime
);
232 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
233 params_sent_thistime
, data_sent_thistime
, useable_space
));
234 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
235 params_to_send
, data_to_send
, paramsize
, datasize
));
237 if (NT_STATUS_V(nt_error
)) {
238 error_packet_set((char *)req
->outbuf
,
243 /* Send the packet */
244 show_msg((char *)req
->outbuf
);
245 if (!srv_send_smb(smbd_server_fd(),
248 IS_CONN_ENCRYPTED(conn
),
250 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
253 TALLOC_FREE(req
->outbuf
);
255 pp
+= params_sent_thistime
;
256 pd
+= data_sent_thistime
;
258 params_to_send
-= params_sent_thistime
;
259 data_to_send
-= data_sent_thistime
;
265 if(params_to_send
< 0 || data_to_send
< 0) {
266 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
267 params_to_send
, data_to_send
));
268 exit_server_cleanly("send_nt_replies: internal error");
273 /****************************************************************************
274 Reply to an NT create and X call on a pipe
275 ****************************************************************************/
277 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
278 struct smb_request
*req
, int *ppnum
)
283 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
285 /* Strip \\ off the name. */
288 status
= open_np_file(req
, fname
, &fsp
);
289 if (!NT_STATUS_IS_OK(status
)) {
290 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
291 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
295 reply_nterror(req
, status
);
303 /****************************************************************************
304 Reply to an NT create and X call for pipes.
305 ****************************************************************************/
307 static void do_ntcreate_pipe_open(connection_struct
*conn
,
308 struct smb_request
*req
)
313 uint32 flags
= IVAL(req
->vwv
+3, 1);
314 TALLOC_CTX
*ctx
= talloc_tos();
316 srvstr_pull_req_talloc(ctx
, req
, &fname
, req
->buf
, STR_TERMINATE
);
319 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
323 nt_open_pipe(fname
, conn
, req
, &pnum
);
331 * Deal with pipe return.
334 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
335 /* This is very strange. We
336 * return 50 words, but only set
337 * the wcnt to 42 ? It's definately
338 * what happens on the wire....
340 reply_outbuf(req
, 50, 0);
341 SCVAL(req
->outbuf
,smb_wct
,42);
343 reply_outbuf(req
, 34, 0);
346 p
= (char *)req
->outbuf
+ smb_vwv2
;
350 SIVAL(p
,0,FILE_WAS_OPENED
);
353 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
356 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
358 SSVAL(p
,2, 0x5FF); /* ? */
361 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
363 SIVAL(p
,0,FILE_GENERIC_ALL
);
365 * For pipes W2K3 seems to return
367 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
369 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
372 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
377 /****************************************************************************
378 Reply to an NT create and X call.
379 ****************************************************************************/
381 void reply_ntcreate_and_X(struct smb_request
*req
)
383 connection_struct
*conn
= req
->conn
;
384 struct smb_filename
*smb_fname
= NULL
;
388 uint32 file_attributes
;
390 uint32 create_disposition
;
391 uint32 create_options
;
393 uint64_t allocation_size
;
394 /* Breakout the oplock request bits so we can set the
395 reply bits separately. */
397 SMB_OFF_T file_len
= 0;
399 files_struct
*fsp
= NULL
;
401 struct timespec create_timespec
;
402 struct timespec c_timespec
;
403 struct timespec a_timespec
;
404 struct timespec m_timespec
;
405 struct timespec write_time_ts
;
408 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
409 TALLOC_CTX
*ctx
= talloc_tos();
411 START_PROFILE(SMBntcreateX
);
414 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
418 flags
= IVAL(req
->vwv
+3, 1);
419 access_mask
= IVAL(req
->vwv
+7, 1);
420 file_attributes
= IVAL(req
->vwv
+13, 1);
421 share_access
= IVAL(req
->vwv
+15, 1);
422 create_disposition
= IVAL(req
->vwv
+17, 1);
423 create_options
= IVAL(req
->vwv
+19, 1);
424 root_dir_fid
= (uint16
)IVAL(req
->vwv
+5, 1);
426 allocation_size
= (uint64_t)IVAL(req
->vwv
+9, 1);
427 #ifdef LARGE_SMB_OFF_T
428 allocation_size
|= (((uint64_t)IVAL(req
->vwv
+11, 1)) << 32);
431 srvstr_get_path_req(ctx
, req
, &fname
, (const char *)req
->buf
,
432 STR_TERMINATE
, &status
);
434 if (!NT_STATUS_IS_OK(status
)) {
435 reply_nterror(req
, status
);
439 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
440 "file_attributes = 0x%x, share_access = 0x%x, "
441 "create_disposition = 0x%x create_options = 0x%x "
442 "root_dir_fid = 0x%x, fname = %s\n",
444 (unsigned int)access_mask
,
445 (unsigned int)file_attributes
,
446 (unsigned int)share_access
,
447 (unsigned int)create_disposition
,
448 (unsigned int)create_options
,
449 (unsigned int)root_dir_fid
,
453 * we need to remove ignored bits when they come directly from the client
454 * because we reuse some of them for internal stuff
456 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
459 * If it's an IPC, use the pipe handler.
463 if (lp_nt_pipe_support()) {
464 do_ntcreate_pipe_open(conn
, req
);
467 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
471 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
472 if (oplock_request
) {
473 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
477 status
= filename_convert(ctx
,
479 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
485 if (!NT_STATUS_IS_OK(status
)) {
486 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
488 NT_STATUS_PATH_NOT_COVERED
,
492 reply_nterror(req
, status
);
496 status
= SMB_VFS_CREATE_FILE(
499 root_dir_fid
, /* root_dir_fid */
500 smb_fname
, /* fname */
501 access_mask
, /* access_mask */
502 share_access
, /* share_access */
503 create_disposition
, /* create_disposition*/
504 create_options
, /* create_options */
505 file_attributes
, /* file_attributes */
506 oplock_request
, /* oplock_request */
507 allocation_size
, /* allocation_size */
513 if (!NT_STATUS_IS_OK(status
)) {
514 if (open_was_deferred(req
->mid
)) {
515 /* We have re-scheduled this call, no error. */
518 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
519 reply_botherror(req
, status
, ERRDOS
, ERRfilexists
);
522 reply_nterror(req
, status
);
527 /* Ensure we're pointing at the correct stat struct. */
528 TALLOC_FREE(smb_fname
);
529 smb_fname
= fsp
->fsp_name
;
532 * If the caller set the extended oplock request bit
533 * and we granted one (by whatever means) - set the
534 * correct bit for extended oplock reply.
537 if (oplock_request
&&
538 (lp_fake_oplocks(SNUM(conn
))
539 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
542 * Exclusive oplock granted
545 if (flags
& REQUEST_BATCH_OPLOCK
) {
546 oplock_granted
= BATCH_OPLOCK_RETURN
;
548 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
550 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
551 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
553 oplock_granted
= NO_OPLOCK_RETURN
;
556 file_len
= smb_fname
->st
.st_ex_size
;
558 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
559 /* This is very strange. We
560 * return 50 words, but only set
561 * the wcnt to 42 ? It's definately
562 * what happens on the wire....
564 reply_outbuf(req
, 50, 0);
565 SCVAL(req
->outbuf
,smb_wct
,42);
567 reply_outbuf(req
, 34, 0);
570 p
= (char *)req
->outbuf
+ smb_vwv2
;
572 SCVAL(p
, 0, oplock_granted
);
575 SSVAL(p
,0,fsp
->fnum
);
577 if ((create_disposition
== FILE_SUPERSEDE
)
578 && (info
== FILE_WAS_OVERWRITTEN
)) {
579 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
585 fattr
= dos_mode(conn
, smb_fname
);
587 fattr
= FILE_ATTRIBUTE_NORMAL
;
590 /* Deal with other possible opens having a modified
592 ZERO_STRUCT(write_time_ts
);
593 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
594 if (!null_timespec(write_time_ts
)) {
595 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
599 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
600 a_timespec
= smb_fname
->st
.st_ex_atime
;
601 m_timespec
= smb_fname
->st
.st_ex_mtime
;
602 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
604 if (lp_dos_filetime_resolution(SNUM(conn
))) {
605 dos_filetime_timespec(&create_timespec
);
606 dos_filetime_timespec(&a_timespec
);
607 dos_filetime_timespec(&m_timespec
);
608 dos_filetime_timespec(&c_timespec
);
611 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
613 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
615 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
617 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
619 SIVAL(p
,0,fattr
); /* File Attributes. */
621 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
623 SOFF_T(p
,0,file_len
);
625 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
626 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
627 size_t num_names
= 0;
628 unsigned int num_streams
;
629 struct stream_struct
*streams
= NULL
;
631 /* Do we have any EA's ? */
632 status
= get_ea_names_from_file(ctx
, conn
, fsp
,
633 smb_fname
->base_name
, NULL
, &num_names
);
634 if (NT_STATUS_IS_OK(status
) && num_names
) {
635 file_status
&= ~NO_EAS
;
637 status
= SMB_VFS_STREAMINFO(conn
, NULL
, smb_fname
->base_name
, ctx
,
638 &num_streams
, &streams
);
639 /* There is always one stream, ::$DATA. */
640 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
641 file_status
&= ~NO_SUBSTREAMS
;
643 TALLOC_FREE(streams
);
644 SSVAL(p
,2,file_status
);
647 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
649 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
652 if (fsp
->is_directory
||
653 can_write_to_file(conn
, smb_fname
)) {
654 perms
= FILE_GENERIC_ALL
;
656 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
661 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
662 fsp
->fnum
, smb_fname_str_dbg(smb_fname
)));
666 END_PROFILE(SMBntcreateX
);
670 /****************************************************************************
671 Reply to a NT_TRANSACT_CREATE call to open a pipe.
672 ****************************************************************************/
674 static void do_nt_transact_create_pipe(connection_struct
*conn
,
675 struct smb_request
*req
,
676 uint16
**ppsetup
, uint32 setup_count
,
677 char **ppparams
, uint32 parameter_count
,
678 char **ppdata
, uint32 data_count
)
681 char *params
= *ppparams
;
687 TALLOC_CTX
*ctx
= talloc_tos();
690 * Ensure minimum number of parameters sent.
693 if(parameter_count
< 54) {
694 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
695 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
699 flags
= IVAL(params
,0);
701 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
702 parameter_count
-53, STR_TERMINATE
,
704 if (!NT_STATUS_IS_OK(status
)) {
705 reply_nterror(req
, status
);
709 nt_open_pipe(fname
, conn
, req
, &pnum
);
716 /* Realloc the size of parameters and data we will return */
717 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
718 /* Extended response is 32 more byyes. */
723 params
= nttrans_realloc(ppparams
, param_len
);
725 reply_doserror(req
, ERRDOS
, ERRnomem
);
730 SCVAL(p
,0,NO_OPLOCK_RETURN
);
735 SIVAL(p
,0,FILE_WAS_OPENED
);
739 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
742 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
744 SSVAL(p
,2, 0x5FF); /* ? */
747 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
749 SIVAL(p
,0,FILE_GENERIC_ALL
);
751 * For pipes W2K3 seems to return
753 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
755 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
758 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
760 /* Send the required number of replies */
761 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
766 /****************************************************************************
767 Internal fn to set security descriptors.
768 ****************************************************************************/
770 static NTSTATUS
set_sd(files_struct
*fsp
, uint8
*data
, uint32 sd_len
,
771 uint32 security_info_sent
)
773 SEC_DESC
*psd
= NULL
;
776 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
780 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
782 if (!NT_STATUS_IS_OK(status
)) {
786 if (psd
->owner_sid
== NULL
) {
787 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
789 if (psd
->group_sid
== NULL
) {
790 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
793 /* Convert all the generic bits. */
794 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
795 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
797 if (DEBUGLEVEL
>= 10) {
798 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp
)));
799 NDR_PRINT_DEBUG(security_descriptor
, psd
);
802 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
809 /****************************************************************************
810 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
811 ****************************************************************************/
813 struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
815 struct ea_list
*ea_list_head
= NULL
;
822 while (offset
+ 4 <= data_size
) {
823 size_t next_offset
= IVAL(pdata
,offset
);
824 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
830 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
831 if (next_offset
== 0) {
834 offset
+= next_offset
;
840 /****************************************************************************
841 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
842 ****************************************************************************/
844 static void call_nt_transact_create(connection_struct
*conn
,
845 struct smb_request
*req
,
846 uint16
**ppsetup
, uint32 setup_count
,
847 char **ppparams
, uint32 parameter_count
,
848 char **ppdata
, uint32 data_count
,
849 uint32 max_data_count
)
851 struct smb_filename
*smb_fname
= NULL
;
853 char *params
= *ppparams
;
854 char *data
= *ppdata
;
855 /* Breakout the oplock request bits so we can set the reply bits separately. */
857 SMB_OFF_T file_len
= 0;
859 files_struct
*fsp
= NULL
;
863 uint32 file_attributes
;
865 uint32 create_disposition
;
866 uint32 create_options
;
868 struct security_descriptor
*sd
= NULL
;
871 struct timespec create_timespec
;
872 struct timespec c_timespec
;
873 struct timespec a_timespec
;
874 struct timespec m_timespec
;
875 struct timespec write_time_ts
;
876 struct ea_list
*ea_list
= NULL
;
879 uint64_t allocation_size
;
881 uint8_t oplock_granted
;
882 TALLOC_CTX
*ctx
= talloc_tos();
884 DEBUG(5,("call_nt_transact_create\n"));
887 * If it's an IPC, use the pipe handler.
891 if (lp_nt_pipe_support()) {
892 do_nt_transact_create_pipe(
894 ppsetup
, setup_count
,
895 ppparams
, parameter_count
,
899 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
904 * Ensure minimum number of parameters sent.
907 if(parameter_count
< 54) {
908 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
909 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
913 flags
= IVAL(params
,0);
914 access_mask
= IVAL(params
,8);
915 file_attributes
= IVAL(params
,20);
916 share_access
= IVAL(params
,24);
917 create_disposition
= IVAL(params
,28);
918 create_options
= IVAL(params
,32);
919 sd_len
= IVAL(params
,36);
920 ea_len
= IVAL(params
,40);
921 root_dir_fid
= (uint16
)IVAL(params
,4);
922 allocation_size
= (uint64_t)IVAL(params
,12);
923 #ifdef LARGE_SMB_OFF_T
924 allocation_size
|= (((uint64_t)IVAL(params
,16)) << 32);
928 * we need to remove ignored bits when they come directly from the client
929 * because we reuse some of them for internal stuff
931 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
933 /* Ensure the data_len is correct for the sd and ea values given. */
934 if ((ea_len
+ sd_len
> data_count
)
935 || (ea_len
> data_count
) || (sd_len
> data_count
)
936 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
937 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
938 "%u, data_count = %u\n", (unsigned int)ea_len
,
939 (unsigned int)sd_len
, (unsigned int)data_count
));
940 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
945 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
948 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
950 if (!NT_STATUS_IS_OK(status
)) {
951 DEBUG(10, ("call_nt_transact_create: "
952 "unmarshall_sec_desc failed: %s\n",
954 reply_nterror(req
, status
);
960 if (!lp_ea_support(SNUM(conn
))) {
961 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
962 "EA's not supported.\n",
963 (unsigned int)ea_len
));
964 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
969 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
970 "too small (should be more than 10)\n",
971 (unsigned int)ea_len
));
972 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
976 /* We have already checked that ea_len <= data_count here. */
977 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
979 if (ea_list
== NULL
) {
980 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
985 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
986 params
+53, parameter_count
-53,
987 STR_TERMINATE
, &status
);
988 if (!NT_STATUS_IS_OK(status
)) {
989 reply_nterror(req
, status
);
993 status
= filename_convert(ctx
,
995 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1001 if (!NT_STATUS_IS_OK(status
)) {
1002 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1003 reply_botherror(req
,
1004 NT_STATUS_PATH_NOT_COVERED
,
1005 ERRSRV
, ERRbadpath
);
1008 reply_nterror(req
, status
);
1012 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1013 if (oplock_request
) {
1014 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1018 status
= SMB_VFS_CREATE_FILE(
1021 root_dir_fid
, /* root_dir_fid */
1022 smb_fname
, /* fname */
1023 access_mask
, /* access_mask */
1024 share_access
, /* share_access */
1025 create_disposition
, /* create_disposition*/
1026 create_options
, /* create_options */
1027 file_attributes
, /* file_attributes */
1028 oplock_request
, /* oplock_request */
1029 allocation_size
, /* allocation_size */
1031 ea_list
, /* ea_list */
1035 if(!NT_STATUS_IS_OK(status
)) {
1036 if (open_was_deferred(req
->mid
)) {
1037 /* We have re-scheduled this call, no error. */
1040 reply_openerror(req
, status
);
1044 /* Ensure we're pointing at the correct stat struct. */
1045 TALLOC_FREE(smb_fname
);
1046 smb_fname
= fsp
->fsp_name
;
1049 * If the caller set the extended oplock request bit
1050 * and we granted one (by whatever means) - set the
1051 * correct bit for extended oplock reply.
1054 if (oplock_request
&&
1055 (lp_fake_oplocks(SNUM(conn
))
1056 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1059 * Exclusive oplock granted
1062 if (flags
& REQUEST_BATCH_OPLOCK
) {
1063 oplock_granted
= BATCH_OPLOCK_RETURN
;
1065 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1067 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1068 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1070 oplock_granted
= NO_OPLOCK_RETURN
;
1073 file_len
= smb_fname
->st
.st_ex_size
;
1075 /* Realloc the size of parameters and data we will return */
1076 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1077 /* Extended response is 32 more byyes. */
1082 params
= nttrans_realloc(ppparams
, param_len
);
1083 if(params
== NULL
) {
1084 reply_doserror(req
, ERRDOS
, ERRnomem
);
1089 SCVAL(p
, 0, oplock_granted
);
1092 SSVAL(p
,0,fsp
->fnum
);
1094 if ((create_disposition
== FILE_SUPERSEDE
)
1095 && (info
== FILE_WAS_OVERWRITTEN
)) {
1096 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1102 fattr
= dos_mode(conn
, smb_fname
);
1104 fattr
= FILE_ATTRIBUTE_NORMAL
;
1107 /* Deal with other possible opens having a modified
1109 ZERO_STRUCT(write_time_ts
);
1110 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
1111 if (!null_timespec(write_time_ts
)) {
1112 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
1116 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1117 a_timespec
= smb_fname
->st
.st_ex_atime
;
1118 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1119 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1121 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1122 dos_filetime_timespec(&create_timespec
);
1123 dos_filetime_timespec(&a_timespec
);
1124 dos_filetime_timespec(&m_timespec
);
1125 dos_filetime_timespec(&c_timespec
);
1128 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
1130 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
1132 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
1134 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
1136 SIVAL(p
,0,fattr
); /* File Attributes. */
1138 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1140 SOFF_T(p
,0,file_len
);
1142 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1146 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1148 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1151 if (fsp
->is_directory
||
1152 can_write_to_file(conn
, smb_fname
)) {
1153 perms
= FILE_GENERIC_ALL
;
1155 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1160 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1161 smb_fname_str_dbg(smb_fname
)));
1163 /* Send the required number of replies */
1164 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1169 /****************************************************************************
1170 Reply to a NT CANCEL request.
1171 conn POINTER CAN BE NULL HERE !
1172 ****************************************************************************/
1174 void reply_ntcancel(struct smb_request
*req
)
1177 * Go through and cancel any pending change notifies.
1180 START_PROFILE(SMBntcancel
);
1181 srv_cancel_sign_response(smbd_server_conn
);
1182 remove_pending_change_notify_requests_by_mid(req
->mid
);
1183 remove_pending_lock_requests_by_mid(req
->mid
);
1185 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req
->mid
));
1187 END_PROFILE(SMBntcancel
);
1191 /****************************************************************************
1193 ****************************************************************************/
1195 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1196 connection_struct
*conn
,
1197 struct smb_request
*req
,
1198 struct smb_filename
*smb_fname_src
,
1199 struct smb_filename
*smb_fname_dst
,
1202 files_struct
*fsp1
,*fsp2
;
1206 NTSTATUS status
= NT_STATUS_OK
;
1209 if (!CAN_WRITE(conn
)) {
1210 status
= NT_STATUS_MEDIA_WRITE_PROTECTED
;
1214 /* Source must already exist. */
1215 if (!VALID_STAT(smb_fname_src
->st
)) {
1216 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1220 /* Ensure attributes match. */
1221 fattr
= dos_mode(conn
, smb_fname_src
);
1222 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1223 status
= NT_STATUS_NO_SUCH_FILE
;
1227 /* Disallow if dst file already exists. */
1228 if (VALID_STAT(smb_fname_dst
->st
)) {
1229 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
1233 /* No links from a directory. */
1234 if (S_ISDIR(smb_fname_src
->st
.st_ex_mode
)) {
1235 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
1239 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1240 smb_fname_str_dbg(smb_fname_src
),
1241 smb_fname_str_dbg(smb_fname_dst
)));
1243 status
= SMB_VFS_CREATE_FILE(
1246 0, /* root_dir_fid */
1247 smb_fname_src
, /* fname */
1248 FILE_READ_DATA
, /* access_mask */
1249 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1251 FILE_OPEN
, /* create_disposition*/
1252 0, /* create_options */
1253 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
1254 NO_OPLOCK
, /* oplock_request */
1255 0, /* allocation_size */
1261 if (!NT_STATUS_IS_OK(status
)) {
1265 status
= SMB_VFS_CREATE_FILE(
1268 0, /* root_dir_fid */
1269 smb_fname_dst
, /* fname */
1270 FILE_WRITE_DATA
, /* access_mask */
1271 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1273 FILE_CREATE
, /* create_disposition*/
1274 0, /* create_options */
1275 fattr
, /* file_attributes */
1276 NO_OPLOCK
, /* oplock_request */
1277 0, /* allocation_size */
1283 if (!NT_STATUS_IS_OK(status
)) {
1284 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1288 if (smb_fname_src
->st
.st_ex_size
) {
1289 ret
= vfs_transfer_file(fsp1
, fsp2
, smb_fname_src
->st
.st_ex_size
);
1293 * As we are opening fsp1 read-only we only expect
1294 * an error on close on fsp2 if we are out of space.
1295 * Thus we don't look at the error return from the
1298 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1300 /* Ensure the modtime is set correctly on the destination file. */
1301 set_close_write_time(fsp2
, smb_fname_src
->st
.st_ex_mtime
);
1303 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1305 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1306 creates the file. This isn't the correct thing to do in the copy
1308 if (!parent_dirname(talloc_tos(), smb_fname_dst
->base_name
, &parent
,
1310 status
= NT_STATUS_NO_MEMORY
;
1313 file_set_dosmode(conn
, smb_fname_dst
, fattr
, parent
, false);
1314 TALLOC_FREE(parent
);
1316 if (ret
< (SMB_OFF_T
)smb_fname_src
->st
.st_ex_size
) {
1317 status
= NT_STATUS_DISK_FULL
;
1321 if (!NT_STATUS_IS_OK(status
)) {
1322 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1323 nt_errstr(status
), smb_fname_str_dbg(smb_fname_src
),
1324 smb_fname_str_dbg(smb_fname_dst
)));
1330 /****************************************************************************
1331 Reply to a NT rename request.
1332 ****************************************************************************/
1334 void reply_ntrename(struct smb_request
*req
)
1336 connection_struct
*conn
= req
->conn
;
1337 struct smb_filename
*smb_fname_old
= NULL
;
1338 struct smb_filename
*smb_fname_new
= NULL
;
1339 char *oldname
= NULL
;
1340 char *newname
= NULL
;
1343 bool src_has_wcard
= False
;
1344 bool dest_has_wcard
= False
;
1346 uint32_t ucf_flags_src
= 0;
1347 uint32_t ucf_flags_dst
= 0;
1349 TALLOC_CTX
*ctx
= talloc_tos();
1351 START_PROFILE(SMBntrename
);
1354 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1358 attrs
= SVAL(req
->vwv
+0, 0);
1359 rename_type
= SVAL(req
->vwv
+1, 0);
1361 p
= (const char *)req
->buf
+ 1;
1362 p
+= srvstr_get_path_req_wcard(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1363 &status
, &src_has_wcard
);
1364 if (!NT_STATUS_IS_OK(status
)) {
1365 reply_nterror(req
, status
);
1369 if (ms_has_wild(oldname
)) {
1370 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1375 p
+= srvstr_get_path_req_wcard(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1376 &status
, &dest_has_wcard
);
1377 if (!NT_STATUS_IS_OK(status
)) {
1378 reply_nterror(req
, status
);
1382 /* The newname must begin with a ':' if the oldname contains a ':'. */
1383 if (strchr_m(oldname
, ':') && (newname
[0] != ':')) {
1384 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1389 * If this is a rename operation, allow wildcards and save the
1390 * destination's last component.
1392 if (rename_type
== RENAME_FLAG_RENAME
) {
1393 ucf_flags_src
= UCF_COND_ALLOW_WCARD_LCOMP
;
1394 ucf_flags_dst
= UCF_COND_ALLOW_WCARD_LCOMP
| UCF_SAVE_LCOMP
;
1397 /* rename_internals() calls unix_convert(), so don't call it here. */
1398 status
= filename_convert(ctx
, conn
,
1399 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1404 if (!NT_STATUS_IS_OK(status
)) {
1405 if (NT_STATUS_EQUAL(status
,
1406 NT_STATUS_PATH_NOT_COVERED
)) {
1407 reply_botherror(req
,
1408 NT_STATUS_PATH_NOT_COVERED
,
1409 ERRSRV
, ERRbadpath
);
1412 reply_nterror(req
, status
);
1416 status
= filename_convert(ctx
, conn
,
1417 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1422 if (!NT_STATUS_IS_OK(status
)) {
1423 if (NT_STATUS_EQUAL(status
,
1424 NT_STATUS_PATH_NOT_COVERED
)) {
1425 reply_botherror(req
,
1426 NT_STATUS_PATH_NOT_COVERED
,
1427 ERRSRV
, ERRbadpath
);
1430 reply_nterror(req
, status
);
1434 DEBUG(3,("reply_ntrename: %s -> %s\n",
1435 smb_fname_str_dbg(smb_fname_old
),
1436 smb_fname_str_dbg(smb_fname_new
)));
1438 switch(rename_type
) {
1439 case RENAME_FLAG_RENAME
:
1440 status
= rename_internals(ctx
, conn
, req
,
1441 smb_fname_old
, smb_fname_new
,
1442 attrs
, False
, src_has_wcard
,
1446 case RENAME_FLAG_HARD_LINK
:
1447 if (src_has_wcard
|| dest_has_wcard
) {
1449 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1451 status
= hardlink_internals(ctx
, conn
,
1456 case RENAME_FLAG_COPY
:
1457 if (src_has_wcard
|| dest_has_wcard
) {
1459 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1461 status
= copy_internals(ctx
, conn
, req
,
1467 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1468 status
= NT_STATUS_INVALID_PARAMETER
;
1471 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1475 if (!NT_STATUS_IS_OK(status
)) {
1476 if (open_was_deferred(req
->mid
)) {
1477 /* We have re-scheduled this call. */
1481 reply_nterror(req
, status
);
1485 reply_outbuf(req
, 0, 0);
1487 END_PROFILE(SMBntrename
);
1491 /****************************************************************************
1492 Reply to a notify change - queue the request and
1493 don't allow a directory to be opened.
1494 ****************************************************************************/
1496 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1497 NTSTATUS error_code
,
1498 uint8_t *buf
, size_t len
)
1500 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1503 static void call_nt_transact_notify_change(connection_struct
*conn
,
1504 struct smb_request
*req
,
1508 uint32 parameter_count
,
1509 char **ppdata
, uint32 data_count
,
1510 uint32 max_data_count
,
1511 uint32 max_param_count
)
1513 uint16
*setup
= *ppsetup
;
1519 if(setup_count
< 6) {
1520 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1524 fsp
= file_fsp(req
, SVAL(setup
,4));
1525 filter
= IVAL(setup
, 0);
1526 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1528 DEBUG(3,("call_nt_transact_notify_change\n"));
1531 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1536 char *filter_string
;
1538 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1539 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1543 DEBUG(3,("call_nt_transact_notify_change: notify change "
1544 "called on %s, filter = %s, recursive = %d\n",
1545 fsp_str_dbg(fsp
), filter_string
, recursive
));
1547 TALLOC_FREE(filter_string
);
1550 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1551 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1555 if (fsp
->notify
== NULL
) {
1557 status
= change_notify_create(fsp
, filter
, recursive
);
1559 if (!NT_STATUS_IS_OK(status
)) {
1560 DEBUG(10, ("change_notify_create returned %s\n",
1561 nt_errstr(status
)));
1562 reply_nterror(req
, status
);
1567 if (fsp
->notify
->num_changes
!= 0) {
1570 * We've got changes pending, respond immediately
1574 * TODO: write a torture test to check the filtering behaviour
1578 change_notify_reply(fsp
->conn
, req
,
1582 smbd_smb1_notify_reply
);
1585 * change_notify_reply() above has independently sent its
1592 * No changes pending, queue the request
1595 status
= change_notify_add_request(req
,
1599 smbd_smb1_notify_reply
);
1600 if (!NT_STATUS_IS_OK(status
)) {
1601 reply_nterror(req
, status
);
1606 /****************************************************************************
1607 Reply to an NT transact rename command.
1608 ****************************************************************************/
1610 static void call_nt_transact_rename(connection_struct
*conn
,
1611 struct smb_request
*req
,
1612 uint16
**ppsetup
, uint32 setup_count
,
1613 char **ppparams
, uint32 parameter_count
,
1614 char **ppdata
, uint32 data_count
,
1615 uint32 max_data_count
)
1617 char *params
= *ppparams
;
1618 char *new_name
= NULL
;
1619 files_struct
*fsp
= NULL
;
1620 bool dest_has_wcard
= False
;
1622 TALLOC_CTX
*ctx
= talloc_tos();
1624 if(parameter_count
< 5) {
1625 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1629 fsp
= file_fsp(req
, SVAL(params
, 0));
1630 if (!check_fsp(conn
, req
, fsp
)) {
1633 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1634 parameter_count
- 4,
1635 STR_TERMINATE
, &status
, &dest_has_wcard
);
1636 if (!NT_STATUS_IS_OK(status
)) {
1637 reply_nterror(req
, status
);
1642 * W2K3 ignores this request as the RAW-RENAME test
1643 * demonstrates, so we do.
1645 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1647 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1648 fsp_str_dbg(fsp
), new_name
));
1653 /******************************************************************************
1654 Fake up a completely empty SD.
1655 *******************************************************************************/
1657 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1661 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1663 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1664 return NT_STATUS_NO_MEMORY
;
1667 return NT_STATUS_OK
;
1670 /****************************************************************************
1671 Reply to query a security descriptor.
1672 ****************************************************************************/
1674 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1675 struct smb_request
*req
,
1679 uint32 parameter_count
,
1682 uint32 max_data_count
)
1684 char *params
= *ppparams
;
1685 char *data
= *ppdata
;
1686 SEC_DESC
*psd
= NULL
;
1688 uint32 security_info_wanted
;
1689 files_struct
*fsp
= NULL
;
1693 if(parameter_count
< 8) {
1694 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1698 fsp
= file_fsp(req
, SVAL(params
,0));
1700 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1704 security_info_wanted
= IVAL(params
,4);
1706 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1707 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
1708 (unsigned int)security_info_wanted
));
1710 params
= nttrans_realloc(ppparams
, 4);
1711 if(params
== NULL
) {
1712 reply_doserror(req
, ERRDOS
, ERRnomem
);
1717 * Get the permissions to return.
1720 if (!lp_nt_acl_support(SNUM(conn
))) {
1721 status
= get_null_nt_acl(talloc_tos(), &psd
);
1723 status
= SMB_VFS_FGET_NT_ACL(
1724 fsp
, security_info_wanted
, &psd
);
1726 if (!NT_STATUS_IS_OK(status
)) {
1727 reply_nterror(req
, status
);
1731 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1732 * present in the reply to match Windows behavior */
1733 if (psd
->sacl
== NULL
&&
1734 security_info_wanted
& SACL_SECURITY_INFORMATION
)
1735 psd
->type
|= SEC_DESC_SACL_PRESENT
;
1736 if (psd
->dacl
== NULL
&&
1737 security_info_wanted
& DACL_SECURITY_INFORMATION
)
1738 psd
->type
|= SEC_DESC_DACL_PRESENT
;
1740 sd_size
= ndr_size_security_descriptor(psd
, NULL
, 0);
1742 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
1744 if (DEBUGLEVEL
>= 10) {
1745 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
1747 NDR_PRINT_DEBUG(security_descriptor
, psd
);
1750 SIVAL(params
,0,(uint32
)sd_size
);
1752 if (max_data_count
< sd_size
) {
1753 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1754 params
, 4, *ppdata
, 0);
1759 * Allocate the data we will point this at.
1762 data
= nttrans_realloc(ppdata
, sd_size
);
1764 reply_doserror(req
, ERRDOS
, ERRnomem
);
1768 status
= marshall_sec_desc(talloc_tos(), psd
,
1769 &blob
.data
, &blob
.length
);
1771 if (!NT_STATUS_IS_OK(status
)) {
1772 reply_nterror(req
, status
);
1776 SMB_ASSERT(sd_size
== blob
.length
);
1777 memcpy(data
, blob
.data
, sd_size
);
1779 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1784 /****************************************************************************
1785 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1786 ****************************************************************************/
1788 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1789 struct smb_request
*req
,
1793 uint32 parameter_count
,
1796 uint32 max_data_count
)
1798 char *params
= *ppparams
;
1799 char *data
= *ppdata
;
1800 files_struct
*fsp
= NULL
;
1801 uint32 security_info_sent
= 0;
1804 if(parameter_count
< 8) {
1805 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1809 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1810 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1814 if(!lp_nt_acl_support(SNUM(conn
))) {
1818 security_info_sent
= IVAL(params
,4);
1820 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1821 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
1823 if (data_count
== 0) {
1824 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
1828 status
= set_sd(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
1830 if (!NT_STATUS_IS_OK(status
)) {
1831 reply_nterror(req
, status
);
1836 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1840 /****************************************************************************
1842 ****************************************************************************/
1844 static void call_nt_transact_ioctl(connection_struct
*conn
,
1845 struct smb_request
*req
,
1846 uint16
**ppsetup
, uint32 setup_count
,
1847 char **ppparams
, uint32 parameter_count
,
1848 char **ppdata
, uint32 data_count
,
1849 uint32 max_data_count
)
1856 char *pdata
= *ppdata
;
1858 if (setup_count
!= 8) {
1859 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1860 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1864 function
= IVAL(*ppsetup
, 0);
1865 fidnum
= SVAL(*ppsetup
, 4);
1866 isFSctl
= CVAL(*ppsetup
, 6);
1867 compfilter
= CVAL(*ppsetup
, 7);
1869 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1870 function
, fidnum
, isFSctl
, compfilter
));
1872 fsp
=file_fsp(req
, fidnum
);
1873 /* this check is done in each implemented function case for now
1874 because I don't want to break anything... --metze
1875 FSP_BELONGS_CONN(fsp,conn);*/
1877 SMB_PERFCOUNT_SET_IOCTL(&req
->pcd
, function
);
1880 case FSCTL_SET_SPARSE
:
1881 /* pretend this succeeded - tho strictly we should
1882 mark the file sparse (if the local fs supports it)
1883 so we can know if we need to pre-allocate or not */
1885 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1886 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1889 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
1891 unsigned char objid
[16];
1893 /* This should return the object-id on this file.
1894 * I think I'll make this be the inode+dev. JRA.
1897 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
1899 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1904 pdata
= nttrans_realloc(ppdata
, data_count
);
1905 if (pdata
== NULL
) {
1906 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1910 /* For backwards compatibility only store the dev/inode. */
1911 push_file_id_16(pdata
, &fsp
->file_id
);
1912 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
1913 push_file_id_16(pdata
+32, &fsp
->file_id
);
1914 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1919 case FSCTL_GET_REPARSE_POINT
:
1920 /* pretend this fail - my winXP does it like this
1924 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1925 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1928 case FSCTL_SET_REPARSE_POINT
:
1929 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1933 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1934 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1937 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
1940 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1941 * and return their volume names. If max_data_count is 16, then it is just
1942 * asking for the number of volumes and length of the combined names.
1944 * pdata is the data allocated by our caller, but that uses
1945 * total_data_count (which is 0 in our case) rather than max_data_count.
1946 * Allocate the correct amount and return the pointer to let
1947 * it be deallocated when we return.
1949 SHADOW_COPY_DATA
*shadow_data
= NULL
;
1950 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
1951 bool labels
= False
;
1952 uint32 labels_data_count
= 0;
1956 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1960 if (max_data_count
< 16) {
1961 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1963 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1967 if (max_data_count
> 16) {
1971 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
1972 if (shadow_mem_ctx
== NULL
) {
1973 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1974 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1978 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
1979 if (shadow_data
== NULL
) {
1980 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1981 talloc_destroy(shadow_mem_ctx
);
1982 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1986 shadow_data
->mem_ctx
= shadow_mem_ctx
;
1989 * Call the VFS routine to actually do the work.
1991 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
1992 talloc_destroy(shadow_data
->mem_ctx
);
1993 if (errno
== ENOSYS
) {
1994 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1995 conn
->connectpath
));
1996 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1999 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2000 conn
->connectpath
));
2001 reply_nterror(req
, NT_STATUS_UNSUCCESSFUL
);
2006 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2011 data_count
= 12+labels_data_count
+4;
2014 if (max_data_count
<data_count
) {
2015 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2016 max_data_count
,data_count
));
2017 talloc_destroy(shadow_data
->mem_ctx
);
2018 reply_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
2022 pdata
= nttrans_realloc(ppdata
, data_count
);
2023 if (pdata
== NULL
) {
2024 talloc_destroy(shadow_data
->mem_ctx
);
2025 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2031 /* num_volumes 4 bytes */
2032 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2035 /* num_labels 4 bytes */
2036 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2039 /* needed_data_count 4 bytes */
2040 SIVAL(pdata
, 8, labels_data_count
+4);
2044 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2045 shadow_data
->num_volumes
, fsp_str_dbg(fsp
)));
2046 if (labels
&& shadow_data
->labels
) {
2047 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2048 srvstr_push(pdata
, req
->flags2
,
2049 cur_pdata
, shadow_data
->labels
[i
],
2050 2*sizeof(SHADOW_COPY_LABEL
),
2051 STR_UNICODE
|STR_TERMINATE
);
2052 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2053 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2057 talloc_destroy(shadow_data
->mem_ctx
);
2059 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
2065 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2067 /* pretend this succeeded -
2069 * we have to send back a list with all files owned by this SID
2071 * but I have to check that --metze
2075 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2077 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2079 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
2083 /* unknown 4 bytes: this is not the length of the sid :-( */
2084 /*unknown = IVAL(pdata,0);*/
2086 sid_parse(pdata
+4,sid_len
,&sid
);
2087 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
2089 if (!sid_to_uid(&sid
, &uid
)) {
2090 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2091 sid_string_dbg(&sid
),
2092 (unsigned long)sid_len
));
2096 /* we can take a look at the find source :-)
2098 * find ./ -uid $uid -name '*' is what we need here
2101 * and send 4bytes len and then NULL terminated unicode strings
2104 * but I don't know how to deal with the paged results
2105 * (maybe we can hang the result anywhere in the fsp struct)
2107 * we don't send all files at once
2108 * and at the next we should *not* start from the beginning,
2109 * so we have to cache the result
2114 /* this works for now... */
2115 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2119 if (!logged_ioctl_message
) {
2120 logged_ioctl_message
= true; /* Only print this once... */
2121 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2126 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2130 #ifdef HAVE_SYS_QUOTAS
2131 /****************************************************************************
2132 Reply to get user quota
2133 ****************************************************************************/
2135 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2136 struct smb_request
*req
,
2140 uint32 parameter_count
,
2143 uint32 max_data_count
)
2145 NTSTATUS nt_status
= NT_STATUS_OK
;
2146 char *params
= *ppparams
;
2147 char *pdata
= *ppdata
;
2149 int data_len
=0,param_len
=0;
2152 files_struct
*fsp
= NULL
;
2156 bool start_enum
= True
;
2157 SMB_NTQUOTA_STRUCT qt
;
2158 SMB_NTQUOTA_LIST
*tmp_list
;
2159 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2164 if (conn
->server_info
->utok
.uid
!= 0) {
2165 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2166 "[%s]\n", lp_servicename(SNUM(conn
)),
2167 conn
->server_info
->unix_name
));
2168 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2173 * Ensure minimum number of parameters sent.
2176 if (parameter_count
< 4) {
2177 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2178 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2182 /* maybe we can check the quota_fnum */
2183 fsp
= file_fsp(req
, SVAL(params
,0));
2184 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2185 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2186 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2190 /* the NULL pointer checking for fsp->fake_file_handle->pd
2191 * is done by CHECK_NTQUOTA_HANDLE_OK()
2193 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2195 level
= SVAL(params
,2);
2197 /* unknown 12 bytes leading in params */
2200 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2201 /* seems that we should continue with the enum here --metze */
2203 if (qt_handle
->quota_list
!=NULL
&&
2204 qt_handle
->tmp_list
==NULL
) {
2207 free_ntquota_list(&(qt_handle
->quota_list
));
2209 /* Realloc the size of parameters and data we will return */
2211 params
= nttrans_realloc(ppparams
, param_len
);
2212 if(params
== NULL
) {
2213 reply_doserror(req
, ERRDOS
, ERRnomem
);
2218 SIVAL(params
,0,data_len
);
2225 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2227 if (qt_handle
->quota_list
==NULL
&&
2228 qt_handle
->tmp_list
==NULL
) {
2232 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2233 reply_doserror(req
, ERRSRV
, ERRerror
);
2237 /* Realloc the size of parameters and data we will return */
2239 params
= nttrans_realloc(ppparams
, param_len
);
2240 if(params
== NULL
) {
2241 reply_doserror(req
, ERRDOS
, ERRnomem
);
2245 /* we should not trust the value in max_data_count*/
2246 max_data_count
= MIN(max_data_count
,2048);
2248 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2250 reply_doserror(req
, ERRDOS
, ERRnomem
);
2256 /* set params Size of returned Quota Data 4 bytes*/
2257 /* but set it later when we know it */
2259 /* for each entry push the data */
2262 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2265 tmp_list
= qt_handle
->tmp_list
;
2267 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2268 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2270 sid_len
= ndr_size_dom_sid(
2271 &tmp_list
->quotas
->sid
, NULL
, 0);
2272 entry_len
= 40 + sid_len
;
2274 /* nextoffset entry 4 bytes */
2275 SIVAL(entry
,0,entry_len
);
2277 /* then the len of the SID 4 bytes */
2278 SIVAL(entry
,4,sid_len
);
2280 /* unknown data 8 bytes uint64_t */
2281 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2283 /* the used disk space 8 bytes uint64_t */
2284 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2286 /* the soft quotas 8 bytes uint64_t */
2287 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2289 /* the hard quotas 8 bytes uint64_t */
2290 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2292 /* and now the SID */
2293 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2296 qt_handle
->tmp_list
= tmp_list
;
2298 /* overwrite the offset of the last entry */
2299 SIVAL(entry
-entry_len
,0,0);
2301 data_len
= 4+qt_len
;
2302 /* overwrite the params quota_data_len */
2303 SIVAL(params
,0,data_len
);
2307 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2309 /* unknown 4 bytes IVAL(pdata,0) */
2311 if (data_count
< 8) {
2312 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2313 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2317 sid_len
= IVAL(pdata
,4);
2318 /* Ensure this is less than 1mb. */
2319 if (sid_len
> (1024*1024)) {
2320 reply_doserror(req
, ERRDOS
, ERRnomem
);
2324 if (data_count
< 8+sid_len
) {
2325 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2326 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2330 data_len
= 4+40+sid_len
;
2332 if (max_data_count
< data_len
) {
2333 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2334 max_data_count
, data_len
));
2336 SIVAL(params
,0,data_len
);
2338 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2342 sid_parse(pdata
+8,sid_len
,&sid
);
2344 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2347 * we have to return zero's in all fields
2348 * instead of returning an error here
2353 /* Realloc the size of parameters and data we will return */
2355 params
= nttrans_realloc(ppparams
, param_len
);
2356 if(params
== NULL
) {
2357 reply_doserror(req
, ERRDOS
, ERRnomem
);
2361 pdata
= nttrans_realloc(ppdata
, data_len
);
2363 reply_doserror(req
, ERRDOS
, ERRnomem
);
2369 /* set params Size of returned Quota Data 4 bytes*/
2370 SIVAL(params
,0,data_len
);
2372 /* nextoffset entry 4 bytes */
2375 /* then the len of the SID 4 bytes */
2376 SIVAL(entry
,4,sid_len
);
2378 /* unknown data 8 bytes uint64_t */
2379 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2381 /* the used disk space 8 bytes uint64_t */
2382 SBIG_UINT(entry
,16,qt
.usedspace
);
2384 /* the soft quotas 8 bytes uint64_t */
2385 SBIG_UINT(entry
,24,qt
.softlim
);
2387 /* the hard quotas 8 bytes uint64_t */
2388 SBIG_UINT(entry
,32,qt
.hardlim
);
2390 /* and now the SID */
2391 sid_linearize(entry
+40, sid_len
, &sid
);
2396 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2397 reply_doserror(req
, ERRSRV
, ERRerror
);
2402 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2406 /****************************************************************************
2407 Reply to set user quota
2408 ****************************************************************************/
2410 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2411 struct smb_request
*req
,
2415 uint32 parameter_count
,
2418 uint32 max_data_count
)
2420 char *params
= *ppparams
;
2421 char *pdata
= *ppdata
;
2422 int data_len
=0,param_len
=0;
2423 SMB_NTQUOTA_STRUCT qt
;
2426 files_struct
*fsp
= NULL
;
2431 if (conn
->server_info
->utok
.uid
!= 0) {
2432 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2433 "[%s]\n", lp_servicename(SNUM(conn
)),
2434 conn
->server_info
->unix_name
));
2435 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2440 * Ensure minimum number of parameters sent.
2443 if (parameter_count
< 2) {
2444 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2445 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2449 /* maybe we can check the quota_fnum */
2450 fsp
= file_fsp(req
, SVAL(params
,0));
2451 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2452 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2453 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2457 if (data_count
< 40) {
2458 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2459 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2463 /* offset to next quota record.
2464 * 4 bytes IVAL(pdata,0)
2469 sid_len
= IVAL(pdata
,4);
2471 if (data_count
< 40+sid_len
) {
2472 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2473 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2477 /* unknown 8 bytes in pdata
2478 * maybe its the change time in NTTIME
2481 /* the used space 8 bytes (uint64_t)*/
2482 qt
.usedspace
= (uint64_t)IVAL(pdata
,16);
2483 #ifdef LARGE_SMB_OFF_T
2484 qt
.usedspace
|= (((uint64_t)IVAL(pdata
,20)) << 32);
2485 #else /* LARGE_SMB_OFF_T */
2486 if ((IVAL(pdata
,20) != 0)&&
2487 ((qt
.usedspace
!= 0xFFFFFFFF)||
2488 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2489 /* more than 32 bits? */
2490 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2493 #endif /* LARGE_SMB_OFF_T */
2495 /* the soft quotas 8 bytes (uint64_t)*/
2496 qt
.softlim
= (uint64_t)IVAL(pdata
,24);
2497 #ifdef LARGE_SMB_OFF_T
2498 qt
.softlim
|= (((uint64_t)IVAL(pdata
,28)) << 32);
2499 #else /* LARGE_SMB_OFF_T */
2500 if ((IVAL(pdata
,28) != 0)&&
2501 ((qt
.softlim
!= 0xFFFFFFFF)||
2502 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2503 /* more than 32 bits? */
2504 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2507 #endif /* LARGE_SMB_OFF_T */
2509 /* the hard quotas 8 bytes (uint64_t)*/
2510 qt
.hardlim
= (uint64_t)IVAL(pdata
,32);
2511 #ifdef LARGE_SMB_OFF_T
2512 qt
.hardlim
|= (((uint64_t)IVAL(pdata
,36)) << 32);
2513 #else /* LARGE_SMB_OFF_T */
2514 if ((IVAL(pdata
,36) != 0)&&
2515 ((qt
.hardlim
!= 0xFFFFFFFF)||
2516 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2517 /* more than 32 bits? */
2518 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2521 #endif /* LARGE_SMB_OFF_T */
2523 sid_parse(pdata
+40,sid_len
,&sid
);
2524 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2526 /* 44 unknown bytes left... */
2528 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2529 reply_doserror(req
, ERRSRV
, ERRerror
);
2533 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2536 #endif /* HAVE_SYS_QUOTAS */
2538 static void handle_nttrans(connection_struct
*conn
,
2539 struct trans_state
*state
,
2540 struct smb_request
*req
)
2542 if (get_Protocol() >= PROTOCOL_NT1
) {
2543 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2544 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2548 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2550 /* Now we must call the relevant NT_TRANS function */
2551 switch(state
->call
) {
2552 case NT_TRANSACT_CREATE
:
2554 START_PROFILE(NT_transact_create
);
2555 call_nt_transact_create(
2557 &state
->setup
, state
->setup_count
,
2558 &state
->param
, state
->total_param
,
2559 &state
->data
, state
->total_data
,
2560 state
->max_data_return
);
2561 END_PROFILE(NT_transact_create
);
2565 case NT_TRANSACT_IOCTL
:
2567 START_PROFILE(NT_transact_ioctl
);
2568 call_nt_transact_ioctl(
2570 &state
->setup
, state
->setup_count
,
2571 &state
->param
, state
->total_param
,
2572 &state
->data
, state
->total_data
,
2573 state
->max_data_return
);
2574 END_PROFILE(NT_transact_ioctl
);
2578 case NT_TRANSACT_SET_SECURITY_DESC
:
2580 START_PROFILE(NT_transact_set_security_desc
);
2581 call_nt_transact_set_security_desc(
2583 &state
->setup
, state
->setup_count
,
2584 &state
->param
, state
->total_param
,
2585 &state
->data
, state
->total_data
,
2586 state
->max_data_return
);
2587 END_PROFILE(NT_transact_set_security_desc
);
2591 case NT_TRANSACT_NOTIFY_CHANGE
:
2593 START_PROFILE(NT_transact_notify_change
);
2594 call_nt_transact_notify_change(
2596 &state
->setup
, state
->setup_count
,
2597 &state
->param
, state
->total_param
,
2598 &state
->data
, state
->total_data
,
2599 state
->max_data_return
,
2600 state
->max_param_return
);
2601 END_PROFILE(NT_transact_notify_change
);
2605 case NT_TRANSACT_RENAME
:
2607 START_PROFILE(NT_transact_rename
);
2608 call_nt_transact_rename(
2610 &state
->setup
, state
->setup_count
,
2611 &state
->param
, state
->total_param
,
2612 &state
->data
, state
->total_data
,
2613 state
->max_data_return
);
2614 END_PROFILE(NT_transact_rename
);
2618 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2620 START_PROFILE(NT_transact_query_security_desc
);
2621 call_nt_transact_query_security_desc(
2623 &state
->setup
, state
->setup_count
,
2624 &state
->param
, state
->total_param
,
2625 &state
->data
, state
->total_data
,
2626 state
->max_data_return
);
2627 END_PROFILE(NT_transact_query_security_desc
);
2631 #ifdef HAVE_SYS_QUOTAS
2632 case NT_TRANSACT_GET_USER_QUOTA
:
2634 START_PROFILE(NT_transact_get_user_quota
);
2635 call_nt_transact_get_user_quota(
2637 &state
->setup
, state
->setup_count
,
2638 &state
->param
, state
->total_param
,
2639 &state
->data
, state
->total_data
,
2640 state
->max_data_return
);
2641 END_PROFILE(NT_transact_get_user_quota
);
2645 case NT_TRANSACT_SET_USER_QUOTA
:
2647 START_PROFILE(NT_transact_set_user_quota
);
2648 call_nt_transact_set_user_quota(
2650 &state
->setup
, state
->setup_count
,
2651 &state
->param
, state
->total_param
,
2652 &state
->data
, state
->total_data
,
2653 state
->max_data_return
);
2654 END_PROFILE(NT_transact_set_user_quota
);
2657 #endif /* HAVE_SYS_QUOTAS */
2660 /* Error in request */
2661 DEBUG(0,("handle_nttrans: Unknown request %d in "
2662 "nttrans call\n", state
->call
));
2663 reply_doserror(req
, ERRSRV
, ERRerror
);
2669 /****************************************************************************
2670 Reply to a SMBNTtrans.
2671 ****************************************************************************/
2673 void reply_nttrans(struct smb_request
*req
)
2675 connection_struct
*conn
= req
->conn
;
2680 uint16 function_code
;
2682 struct trans_state
*state
;
2684 START_PROFILE(SMBnttrans
);
2686 if (req
->wct
< 19) {
2687 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2688 END_PROFILE(SMBnttrans
);
2692 pscnt
= IVAL(req
->vwv
+9, 1);
2693 psoff
= IVAL(req
->vwv
+11, 1);
2694 dscnt
= IVAL(req
->vwv
+13, 1);
2695 dsoff
= IVAL(req
->vwv
+15, 1);
2696 function_code
= SVAL(req
->vwv
+18, 0);
2698 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2699 reply_doserror(req
, ERRSRV
, ERRaccess
);
2700 END_PROFILE(SMBnttrans
);
2704 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2705 if (!NT_STATUS_IS_OK(result
)) {
2706 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2707 reply_nterror(req
, result
);
2708 END_PROFILE(SMBnttrans
);
2712 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
2713 reply_doserror(req
, ERRSRV
, ERRaccess
);
2714 END_PROFILE(SMBnttrans
);
2718 state
->cmd
= SMBnttrans
;
2720 state
->mid
= req
->mid
;
2721 state
->vuid
= req
->vuid
;
2722 state
->total_data
= IVAL(req
->vwv
+3, 1);
2724 state
->total_param
= IVAL(req
->vwv
+1, 1);
2725 state
->param
= NULL
;
2726 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2727 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2729 /* setup count is in *words* */
2730 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2731 state
->setup
= NULL
;
2732 state
->call
= function_code
;
2734 DEBUG(10, ("num_setup=%u, "
2735 "param_total=%u, this_param=%u, max_param=%u, "
2736 "data_total=%u, this_data=%u, max_data=%u, "
2737 "param_offset=%u, data_offset=%u\n",
2738 (unsigned)state
->setup_count
,
2739 (unsigned)state
->total_param
, (unsigned)pscnt
,
2740 (unsigned)state
->max_param_return
,
2741 (unsigned)state
->total_data
, (unsigned)dscnt
,
2742 (unsigned)state
->max_data_return
,
2743 (unsigned)psoff
, (unsigned)dsoff
));
2746 * All nttrans messages we handle have smb_wct == 19 +
2747 * state->setup_count. Ensure this is so as a sanity check.
2750 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2751 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2752 req
->wct
, 19 + (state
->setup_count
/2)));
2756 /* Don't allow more than 128mb for each value. */
2757 if ((state
->total_data
> (1024*1024*128)) ||
2758 (state
->total_param
> (1024*1024*128))) {
2759 reply_doserror(req
, ERRDOS
, ERRnomem
);
2760 END_PROFILE(SMBnttrans
);
2764 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2767 if (state
->total_data
) {
2769 if (trans_oob(state
->total_data
, 0, dscnt
)
2770 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
2774 /* Can't use talloc here, the core routines do realloc on the
2775 * params and data. */
2776 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2777 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2778 "bytes !\n", (unsigned int)state
->total_data
));
2780 reply_doserror(req
, ERRDOS
, ERRnomem
);
2781 END_PROFILE(SMBnttrans
);
2785 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2788 if (state
->total_param
) {
2790 if (trans_oob(state
->total_param
, 0, pscnt
)
2791 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
2795 /* Can't use talloc here, the core routines do realloc on the
2796 * params and data. */
2797 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2798 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2799 "bytes !\n", (unsigned int)state
->total_param
));
2800 SAFE_FREE(state
->data
);
2802 reply_doserror(req
, ERRDOS
, ERRnomem
);
2803 END_PROFILE(SMBnttrans
);
2807 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2810 state
->received_data
= dscnt
;
2811 state
->received_param
= pscnt
;
2813 if(state
->setup_count
> 0) {
2814 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2815 state
->setup_count
));
2818 * No overflow possible here, state->setup_count is an
2819 * unsigned int, being filled by a single byte from
2820 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2821 * below is not necessary, it's here to clarify things. The
2822 * validity of req->vwv and req->wct has been checked in
2823 * init_smb_request already.
2825 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
2829 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
2830 if (state
->setup
== NULL
) {
2831 DEBUG(0,("reply_nttrans : Out of memory\n"));
2832 SAFE_FREE(state
->data
);
2833 SAFE_FREE(state
->param
);
2835 reply_doserror(req
, ERRDOS
, ERRnomem
);
2836 END_PROFILE(SMBnttrans
);
2840 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
2841 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
2844 if ((state
->received_data
== state
->total_data
) &&
2845 (state
->received_param
== state
->total_param
)) {
2846 handle_nttrans(conn
, state
, req
);
2847 SAFE_FREE(state
->param
);
2848 SAFE_FREE(state
->data
);
2850 END_PROFILE(SMBnttrans
);
2854 DLIST_ADD(conn
->pending_trans
, state
);
2856 /* We need to send an interim response then receive the rest
2857 of the parameter/data bytes */
2858 reply_outbuf(req
, 0, 0);
2859 show_msg((char *)req
->outbuf
);
2860 END_PROFILE(SMBnttrans
);
2865 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2866 SAFE_FREE(state
->data
);
2867 SAFE_FREE(state
->param
);
2869 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2870 END_PROFILE(SMBnttrans
);
2874 /****************************************************************************
2875 Reply to a SMBnttranss
2876 ****************************************************************************/
2878 void reply_nttranss(struct smb_request
*req
)
2880 connection_struct
*conn
= req
->conn
;
2881 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2882 struct trans_state
*state
;
2884 START_PROFILE(SMBnttranss
);
2886 show_msg((char *)req
->inbuf
);
2888 if (req
->wct
< 18) {
2889 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2890 END_PROFILE(SMBnttranss
);
2894 for (state
= conn
->pending_trans
; state
!= NULL
;
2895 state
= state
->next
) {
2896 if (state
->mid
== req
->mid
) {
2901 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2902 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2903 END_PROFILE(SMBnttranss
);
2907 /* Revise state->total_param and state->total_data in case they have
2908 changed downwards */
2909 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
2910 state
->total_param
= IVAL(req
->vwv
+1, 1);
2912 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
2913 state
->total_data
= IVAL(req
->vwv
+3, 1);
2916 pcnt
= IVAL(req
->vwv
+5, 1);
2917 poff
= IVAL(req
->vwv
+7, 1);
2918 pdisp
= IVAL(req
->vwv
+9, 1);
2920 dcnt
= IVAL(req
->vwv
+11, 1);
2921 doff
= IVAL(req
->vwv
+13, 1);
2922 ddisp
= IVAL(req
->vwv
+15, 1);
2924 state
->received_param
+= pcnt
;
2925 state
->received_data
+= dcnt
;
2927 if ((state
->received_data
> state
->total_data
) ||
2928 (state
->received_param
> state
->total_param
))
2932 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
2933 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
2936 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
2940 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
2941 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
2944 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
2947 if ((state
->received_param
< state
->total_param
) ||
2948 (state
->received_data
< state
->total_data
)) {
2949 END_PROFILE(SMBnttranss
);
2953 handle_nttrans(conn
, state
, req
);
2955 DLIST_REMOVE(conn
->pending_trans
, state
);
2956 SAFE_FREE(state
->data
);
2957 SAFE_FREE(state
->param
);
2959 END_PROFILE(SMBnttranss
);
2964 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2965 DLIST_REMOVE(conn
->pending_trans
, state
);
2966 SAFE_FREE(state
->data
);
2967 SAFE_FREE(state
->param
);
2969 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2970 END_PROFILE(SMBnttranss
);