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
,
481 (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) ?
482 UCF_POSIX_PATHNAMES
: 0,
486 if (!NT_STATUS_IS_OK(status
)) {
487 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
489 NT_STATUS_PATH_NOT_COVERED
,
493 reply_nterror(req
, status
);
498 * Bug #6898 - clients using Windows opens should
499 * never be able to set this attribute into the
502 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
504 status
= SMB_VFS_CREATE_FILE(
507 root_dir_fid
, /* root_dir_fid */
508 smb_fname
, /* fname */
509 access_mask
, /* access_mask */
510 share_access
, /* share_access */
511 create_disposition
, /* create_disposition*/
512 create_options
, /* create_options */
513 file_attributes
, /* file_attributes */
514 oplock_request
, /* oplock_request */
515 allocation_size
, /* allocation_size */
521 if (!NT_STATUS_IS_OK(status
)) {
522 if (open_was_deferred(req
->mid
)) {
523 /* We have re-scheduled this call, no error. */
526 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
527 reply_botherror(req
, status
, ERRDOS
, ERRfilexists
);
530 reply_nterror(req
, status
);
535 /* Ensure we're pointing at the correct stat struct. */
536 TALLOC_FREE(smb_fname
);
537 smb_fname
= fsp
->fsp_name
;
540 * If the caller set the extended oplock request bit
541 * and we granted one (by whatever means) - set the
542 * correct bit for extended oplock reply.
545 if (oplock_request
&&
546 (lp_fake_oplocks(SNUM(conn
))
547 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
550 * Exclusive oplock granted
553 if (flags
& REQUEST_BATCH_OPLOCK
) {
554 oplock_granted
= BATCH_OPLOCK_RETURN
;
556 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
558 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
559 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
561 oplock_granted
= NO_OPLOCK_RETURN
;
564 file_len
= smb_fname
->st
.st_ex_size
;
566 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
567 /* This is very strange. We
568 * return 50 words, but only set
569 * the wcnt to 42 ? It's definately
570 * what happens on the wire....
572 reply_outbuf(req
, 50, 0);
573 SCVAL(req
->outbuf
,smb_wct
,42);
575 reply_outbuf(req
, 34, 0);
578 p
= (char *)req
->outbuf
+ smb_vwv2
;
580 SCVAL(p
, 0, oplock_granted
);
583 SSVAL(p
,0,fsp
->fnum
);
585 if ((create_disposition
== FILE_SUPERSEDE
)
586 && (info
== FILE_WAS_OVERWRITTEN
)) {
587 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
593 fattr
= dos_mode(conn
, smb_fname
);
595 fattr
= FILE_ATTRIBUTE_NORMAL
;
598 /* Deal with other possible opens having a modified
600 ZERO_STRUCT(write_time_ts
);
601 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
602 if (!null_timespec(write_time_ts
)) {
603 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
607 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
608 a_timespec
= smb_fname
->st
.st_ex_atime
;
609 m_timespec
= smb_fname
->st
.st_ex_mtime
;
610 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
612 if (lp_dos_filetime_resolution(SNUM(conn
))) {
613 dos_filetime_timespec(&create_timespec
);
614 dos_filetime_timespec(&a_timespec
);
615 dos_filetime_timespec(&m_timespec
);
616 dos_filetime_timespec(&c_timespec
);
619 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
621 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
623 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
625 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
627 SIVAL(p
,0,fattr
); /* File Attributes. */
629 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&smb_fname
->st
));
631 SOFF_T(p
,0,file_len
);
633 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
634 uint16_t file_status
= (NO_EAS
|NO_SUBSTREAMS
|NO_REPARSETAG
);
635 size_t num_names
= 0;
636 unsigned int num_streams
;
637 struct stream_struct
*streams
= NULL
;
639 /* Do we have any EA's ? */
640 status
= get_ea_names_from_file(ctx
, conn
, fsp
,
641 smb_fname
->base_name
, NULL
, &num_names
);
642 if (NT_STATUS_IS_OK(status
) && num_names
) {
643 file_status
&= ~NO_EAS
;
645 status
= SMB_VFS_STREAMINFO(conn
, NULL
, smb_fname
->base_name
, ctx
,
646 &num_streams
, &streams
);
647 /* There is always one stream, ::$DATA. */
648 if (NT_STATUS_IS_OK(status
) && num_streams
> 1) {
649 file_status
&= ~NO_SUBSTREAMS
;
651 TALLOC_FREE(streams
);
652 SSVAL(p
,2,file_status
);
655 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
657 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
660 if (fsp
->is_directory
||
661 can_write_to_file(conn
, smb_fname
)) {
662 perms
= FILE_GENERIC_ALL
;
664 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
669 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
670 fsp
->fnum
, smb_fname_str_dbg(smb_fname
)));
674 END_PROFILE(SMBntcreateX
);
678 /****************************************************************************
679 Reply to a NT_TRANSACT_CREATE call to open a pipe.
680 ****************************************************************************/
682 static void do_nt_transact_create_pipe(connection_struct
*conn
,
683 struct smb_request
*req
,
684 uint16
**ppsetup
, uint32 setup_count
,
685 char **ppparams
, uint32 parameter_count
,
686 char **ppdata
, uint32 data_count
)
689 char *params
= *ppparams
;
695 TALLOC_CTX
*ctx
= talloc_tos();
698 * Ensure minimum number of parameters sent.
701 if(parameter_count
< 54) {
702 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
703 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
707 flags
= IVAL(params
,0);
709 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
710 parameter_count
-53, STR_TERMINATE
,
712 if (!NT_STATUS_IS_OK(status
)) {
713 reply_nterror(req
, status
);
717 nt_open_pipe(fname
, conn
, req
, &pnum
);
724 /* Realloc the size of parameters and data we will return */
725 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
726 /* Extended response is 32 more byyes. */
731 params
= nttrans_realloc(ppparams
, param_len
);
733 reply_doserror(req
, ERRDOS
, ERRnomem
);
738 SCVAL(p
,0,NO_OPLOCK_RETURN
);
743 SIVAL(p
,0,FILE_WAS_OPENED
);
747 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
750 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
752 SSVAL(p
,2, 0x5FF); /* ? */
755 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
757 SIVAL(p
,0,FILE_GENERIC_ALL
);
759 * For pipes W2K3 seems to return
761 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
763 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
766 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
768 /* Send the required number of replies */
769 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
774 /****************************************************************************
775 Internal fn to set security descriptors.
776 ****************************************************************************/
778 static NTSTATUS
set_sd(files_struct
*fsp
, uint8
*data
, uint32 sd_len
,
779 uint32 security_info_sent
)
781 SEC_DESC
*psd
= NULL
;
784 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
788 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
790 if (!NT_STATUS_IS_OK(status
)) {
794 if (psd
->owner_sid
== NULL
) {
795 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
797 if (psd
->group_sid
== NULL
) {
798 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
801 /* Convert all the generic bits. */
802 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
803 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
805 if (DEBUGLEVEL
>= 10) {
806 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp
)));
807 NDR_PRINT_DEBUG(security_descriptor
, psd
);
810 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
817 /****************************************************************************
818 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
819 ****************************************************************************/
821 struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
823 struct ea_list
*ea_list_head
= NULL
;
830 while (offset
+ 4 <= data_size
) {
831 size_t next_offset
= IVAL(pdata
,offset
);
832 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
838 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
839 if (next_offset
== 0) {
842 offset
+= next_offset
;
848 /****************************************************************************
849 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
850 ****************************************************************************/
852 static void call_nt_transact_create(connection_struct
*conn
,
853 struct smb_request
*req
,
854 uint16
**ppsetup
, uint32 setup_count
,
855 char **ppparams
, uint32 parameter_count
,
856 char **ppdata
, uint32 data_count
,
857 uint32 max_data_count
)
859 struct smb_filename
*smb_fname
= NULL
;
861 char *params
= *ppparams
;
862 char *data
= *ppdata
;
863 /* Breakout the oplock request bits so we can set the reply bits separately. */
865 SMB_OFF_T file_len
= 0;
867 files_struct
*fsp
= NULL
;
871 uint32 file_attributes
;
873 uint32 create_disposition
;
874 uint32 create_options
;
876 struct security_descriptor
*sd
= NULL
;
879 struct timespec create_timespec
;
880 struct timespec c_timespec
;
881 struct timespec a_timespec
;
882 struct timespec m_timespec
;
883 struct timespec write_time_ts
;
884 struct ea_list
*ea_list
= NULL
;
887 uint64_t allocation_size
;
889 uint8_t oplock_granted
;
890 TALLOC_CTX
*ctx
= talloc_tos();
892 DEBUG(5,("call_nt_transact_create\n"));
895 * If it's an IPC, use the pipe handler.
899 if (lp_nt_pipe_support()) {
900 do_nt_transact_create_pipe(
902 ppsetup
, setup_count
,
903 ppparams
, parameter_count
,
907 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
912 * Ensure minimum number of parameters sent.
915 if(parameter_count
< 54) {
916 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
917 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
921 flags
= IVAL(params
,0);
922 access_mask
= IVAL(params
,8);
923 file_attributes
= IVAL(params
,20);
924 share_access
= IVAL(params
,24);
925 create_disposition
= IVAL(params
,28);
926 create_options
= IVAL(params
,32);
927 sd_len
= IVAL(params
,36);
928 ea_len
= IVAL(params
,40);
929 root_dir_fid
= (uint16
)IVAL(params
,4);
930 allocation_size
= (uint64_t)IVAL(params
,12);
931 #ifdef LARGE_SMB_OFF_T
932 allocation_size
|= (((uint64_t)IVAL(params
,16)) << 32);
936 * we need to remove ignored bits when they come directly from the client
937 * because we reuse some of them for internal stuff
939 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
941 /* Ensure the data_len is correct for the sd and ea values given. */
942 if ((ea_len
+ sd_len
> data_count
)
943 || (ea_len
> data_count
) || (sd_len
> data_count
)
944 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
945 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
946 "%u, data_count = %u\n", (unsigned int)ea_len
,
947 (unsigned int)sd_len
, (unsigned int)data_count
));
948 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
953 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
956 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
958 if (!NT_STATUS_IS_OK(status
)) {
959 DEBUG(10, ("call_nt_transact_create: "
960 "unmarshall_sec_desc failed: %s\n",
962 reply_nterror(req
, status
);
968 if (!lp_ea_support(SNUM(conn
))) {
969 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
970 "EA's not supported.\n",
971 (unsigned int)ea_len
));
972 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
977 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
978 "too small (should be more than 10)\n",
979 (unsigned int)ea_len
));
980 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
984 /* We have already checked that ea_len <= data_count here. */
985 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
987 if (ea_list
== NULL
) {
988 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
993 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
994 params
+53, parameter_count
-53,
995 STR_TERMINATE
, &status
);
996 if (!NT_STATUS_IS_OK(status
)) {
997 reply_nterror(req
, status
);
1001 status
= filename_convert(ctx
,
1003 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1005 (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) ?
1006 UCF_POSIX_PATHNAMES
: 0,
1010 if (!NT_STATUS_IS_OK(status
)) {
1011 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1012 reply_botherror(req
,
1013 NT_STATUS_PATH_NOT_COVERED
,
1014 ERRSRV
, ERRbadpath
);
1017 reply_nterror(req
, status
);
1021 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1022 if (oplock_request
) {
1023 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1028 * Bug #6898 - clients using Windows opens should
1029 * never be able to set this attribute into the
1032 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1034 status
= SMB_VFS_CREATE_FILE(
1037 root_dir_fid
, /* root_dir_fid */
1038 smb_fname
, /* fname */
1039 access_mask
, /* access_mask */
1040 share_access
, /* share_access */
1041 create_disposition
, /* create_disposition*/
1042 create_options
, /* create_options */
1043 file_attributes
, /* file_attributes */
1044 oplock_request
, /* oplock_request */
1045 allocation_size
, /* allocation_size */
1047 ea_list
, /* ea_list */
1051 if(!NT_STATUS_IS_OK(status
)) {
1052 if (open_was_deferred(req
->mid
)) {
1053 /* We have re-scheduled this call, no error. */
1056 reply_openerror(req
, status
);
1060 /* Ensure we're pointing at the correct stat struct. */
1061 TALLOC_FREE(smb_fname
);
1062 smb_fname
= fsp
->fsp_name
;
1065 * If the caller set the extended oplock request bit
1066 * and we granted one (by whatever means) - set the
1067 * correct bit for extended oplock reply.
1070 if (oplock_request
&&
1071 (lp_fake_oplocks(SNUM(conn
))
1072 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1075 * Exclusive oplock granted
1078 if (flags
& REQUEST_BATCH_OPLOCK
) {
1079 oplock_granted
= BATCH_OPLOCK_RETURN
;
1081 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1083 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1084 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1086 oplock_granted
= NO_OPLOCK_RETURN
;
1089 file_len
= smb_fname
->st
.st_ex_size
;
1091 /* Realloc the size of parameters and data we will return */
1092 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1093 /* Extended response is 32 more byyes. */
1098 params
= nttrans_realloc(ppparams
, param_len
);
1099 if(params
== NULL
) {
1100 reply_doserror(req
, ERRDOS
, ERRnomem
);
1105 SCVAL(p
, 0, oplock_granted
);
1108 SSVAL(p
,0,fsp
->fnum
);
1110 if ((create_disposition
== FILE_SUPERSEDE
)
1111 && (info
== FILE_WAS_OVERWRITTEN
)) {
1112 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1118 fattr
= dos_mode(conn
, smb_fname
);
1120 fattr
= FILE_ATTRIBUTE_NORMAL
;
1123 /* Deal with other possible opens having a modified
1125 ZERO_STRUCT(write_time_ts
);
1126 get_file_infos(fsp
->file_id
, NULL
, &write_time_ts
);
1127 if (!null_timespec(write_time_ts
)) {
1128 update_stat_ex_mtime(&smb_fname
->st
, write_time_ts
);
1132 create_timespec
= get_create_timespec(conn
, fsp
, smb_fname
);
1133 a_timespec
= smb_fname
->st
.st_ex_atime
;
1134 m_timespec
= smb_fname
->st
.st_ex_mtime
;
1135 c_timespec
= get_change_timespec(conn
, fsp
, smb_fname
);
1137 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1138 dos_filetime_timespec(&create_timespec
);
1139 dos_filetime_timespec(&a_timespec
);
1140 dos_filetime_timespec(&m_timespec
);
1141 dos_filetime_timespec(&c_timespec
);
1144 put_long_date_timespec(conn
->ts_res
, p
, create_timespec
); /* create time. */
1146 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
1148 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
1150 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* change time */
1152 SIVAL(p
,0,fattr
); /* File Attributes. */
1154 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
, fsp
, &smb_fname
->st
));
1156 SOFF_T(p
,0,file_len
);
1158 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1162 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1164 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1167 if (fsp
->is_directory
||
1168 can_write_to_file(conn
, smb_fname
)) {
1169 perms
= FILE_GENERIC_ALL
;
1171 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1176 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1177 smb_fname_str_dbg(smb_fname
)));
1179 /* Send the required number of replies */
1180 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1185 /****************************************************************************
1186 Reply to a NT CANCEL request.
1187 conn POINTER CAN BE NULL HERE !
1188 ****************************************************************************/
1190 void reply_ntcancel(struct smb_request
*req
)
1193 * Go through and cancel any pending change notifies.
1196 START_PROFILE(SMBntcancel
);
1197 srv_cancel_sign_response(smbd_server_conn
);
1198 remove_pending_change_notify_requests_by_mid(req
->mid
);
1199 remove_pending_lock_requests_by_mid(req
->mid
);
1201 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req
->mid
));
1203 END_PROFILE(SMBntcancel
);
1207 /****************************************************************************
1209 ****************************************************************************/
1211 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1212 connection_struct
*conn
,
1213 struct smb_request
*req
,
1214 struct smb_filename
*smb_fname_src
,
1215 struct smb_filename
*smb_fname_dst
,
1218 files_struct
*fsp1
,*fsp2
;
1222 NTSTATUS status
= NT_STATUS_OK
;
1225 if (!CAN_WRITE(conn
)) {
1226 status
= NT_STATUS_MEDIA_WRITE_PROTECTED
;
1230 /* Source must already exist. */
1231 if (!VALID_STAT(smb_fname_src
->st
)) {
1232 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1236 /* Ensure attributes match. */
1237 fattr
= dos_mode(conn
, smb_fname_src
);
1238 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1239 status
= NT_STATUS_NO_SUCH_FILE
;
1243 /* Disallow if dst file already exists. */
1244 if (VALID_STAT(smb_fname_dst
->st
)) {
1245 status
= NT_STATUS_OBJECT_NAME_COLLISION
;
1249 /* No links from a directory. */
1250 if (S_ISDIR(smb_fname_src
->st
.st_ex_mode
)) {
1251 status
= NT_STATUS_FILE_IS_A_DIRECTORY
;
1255 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1256 smb_fname_str_dbg(smb_fname_src
),
1257 smb_fname_str_dbg(smb_fname_dst
)));
1259 status
= SMB_VFS_CREATE_FILE(
1262 0, /* root_dir_fid */
1263 smb_fname_src
, /* fname */
1264 FILE_READ_DATA
, /* access_mask */
1265 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1267 FILE_OPEN
, /* create_disposition*/
1268 0, /* create_options */
1269 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
1270 NO_OPLOCK
, /* oplock_request */
1271 0, /* allocation_size */
1277 if (!NT_STATUS_IS_OK(status
)) {
1281 status
= SMB_VFS_CREATE_FILE(
1284 0, /* root_dir_fid */
1285 smb_fname_dst
, /* fname */
1286 FILE_WRITE_DATA
, /* access_mask */
1287 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1289 FILE_CREATE
, /* create_disposition*/
1290 0, /* create_options */
1291 fattr
, /* file_attributes */
1292 NO_OPLOCK
, /* oplock_request */
1293 0, /* allocation_size */
1299 if (!NT_STATUS_IS_OK(status
)) {
1300 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1304 if (smb_fname_src
->st
.st_ex_size
) {
1305 ret
= vfs_transfer_file(fsp1
, fsp2
, smb_fname_src
->st
.st_ex_size
);
1309 * As we are opening fsp1 read-only we only expect
1310 * an error on close on fsp2 if we are out of space.
1311 * Thus we don't look at the error return from the
1314 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1316 /* Ensure the modtime is set correctly on the destination file. */
1317 set_close_write_time(fsp2
, smb_fname_src
->st
.st_ex_mtime
);
1319 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1321 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1322 creates the file. This isn't the correct thing to do in the copy
1324 if (!parent_dirname(talloc_tos(), smb_fname_dst
->base_name
, &parent
,
1326 status
= NT_STATUS_NO_MEMORY
;
1329 file_set_dosmode(conn
, smb_fname_dst
, fattr
, parent
, false);
1330 TALLOC_FREE(parent
);
1332 if (ret
< (SMB_OFF_T
)smb_fname_src
->st
.st_ex_size
) {
1333 status
= NT_STATUS_DISK_FULL
;
1337 if (!NT_STATUS_IS_OK(status
)) {
1338 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1339 nt_errstr(status
), smb_fname_str_dbg(smb_fname_src
),
1340 smb_fname_str_dbg(smb_fname_dst
)));
1346 /****************************************************************************
1347 Reply to a NT rename request.
1348 ****************************************************************************/
1350 void reply_ntrename(struct smb_request
*req
)
1352 connection_struct
*conn
= req
->conn
;
1353 struct smb_filename
*smb_fname_old
= NULL
;
1354 struct smb_filename
*smb_fname_new
= NULL
;
1355 char *oldname
= NULL
;
1356 char *newname
= NULL
;
1359 bool src_has_wcard
= False
;
1360 bool dest_has_wcard
= False
;
1362 uint32_t ucf_flags_src
= 0;
1363 uint32_t ucf_flags_dst
= 0;
1365 TALLOC_CTX
*ctx
= talloc_tos();
1367 START_PROFILE(SMBntrename
);
1370 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1374 attrs
= SVAL(req
->vwv
+0, 0);
1375 rename_type
= SVAL(req
->vwv
+1, 0);
1377 p
= (const char *)req
->buf
+ 1;
1378 p
+= srvstr_get_path_req_wcard(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1379 &status
, &src_has_wcard
);
1380 if (!NT_STATUS_IS_OK(status
)) {
1381 reply_nterror(req
, status
);
1385 if (ms_has_wild(oldname
)) {
1386 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1391 p
+= srvstr_get_path_req_wcard(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1392 &status
, &dest_has_wcard
);
1393 if (!NT_STATUS_IS_OK(status
)) {
1394 reply_nterror(req
, status
);
1398 /* The newname must begin with a ':' if the oldname contains a ':'. */
1399 if (strchr_m(oldname
, ':') && (newname
[0] != ':')) {
1400 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1405 * If this is a rename operation, allow wildcards and save the
1406 * destination's last component.
1408 if (rename_type
== RENAME_FLAG_RENAME
) {
1409 ucf_flags_src
= UCF_COND_ALLOW_WCARD_LCOMP
;
1410 ucf_flags_dst
= UCF_COND_ALLOW_WCARD_LCOMP
| UCF_SAVE_LCOMP
;
1413 /* rename_internals() calls unix_convert(), so don't call it here. */
1414 status
= filename_convert(ctx
, conn
,
1415 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1420 if (!NT_STATUS_IS_OK(status
)) {
1421 if (NT_STATUS_EQUAL(status
,
1422 NT_STATUS_PATH_NOT_COVERED
)) {
1423 reply_botherror(req
,
1424 NT_STATUS_PATH_NOT_COVERED
,
1425 ERRSRV
, ERRbadpath
);
1428 reply_nterror(req
, status
);
1432 status
= filename_convert(ctx
, conn
,
1433 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1438 if (!NT_STATUS_IS_OK(status
)) {
1439 if (NT_STATUS_EQUAL(status
,
1440 NT_STATUS_PATH_NOT_COVERED
)) {
1441 reply_botherror(req
,
1442 NT_STATUS_PATH_NOT_COVERED
,
1443 ERRSRV
, ERRbadpath
);
1446 reply_nterror(req
, status
);
1450 DEBUG(3,("reply_ntrename: %s -> %s\n",
1451 smb_fname_str_dbg(smb_fname_old
),
1452 smb_fname_str_dbg(smb_fname_new
)));
1454 switch(rename_type
) {
1455 case RENAME_FLAG_RENAME
:
1456 status
= rename_internals(ctx
, conn
, req
,
1457 smb_fname_old
, smb_fname_new
,
1458 attrs
, False
, src_has_wcard
,
1462 case RENAME_FLAG_HARD_LINK
:
1463 if (src_has_wcard
|| dest_has_wcard
) {
1465 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1467 status
= hardlink_internals(ctx
, conn
,
1472 case RENAME_FLAG_COPY
:
1473 if (src_has_wcard
|| dest_has_wcard
) {
1475 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1477 status
= copy_internals(ctx
, conn
, req
,
1483 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1484 status
= NT_STATUS_INVALID_PARAMETER
;
1487 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1491 if (!NT_STATUS_IS_OK(status
)) {
1492 if (open_was_deferred(req
->mid
)) {
1493 /* We have re-scheduled this call. */
1497 reply_nterror(req
, status
);
1501 reply_outbuf(req
, 0, 0);
1503 END_PROFILE(SMBntrename
);
1507 /****************************************************************************
1508 Reply to a notify change - queue the request and
1509 don't allow a directory to be opened.
1510 ****************************************************************************/
1512 static void smbd_smb1_notify_reply(struct smb_request
*req
,
1513 NTSTATUS error_code
,
1514 uint8_t *buf
, size_t len
)
1516 send_nt_replies(req
->conn
, req
, error_code
, (char *)buf
, len
, NULL
, 0);
1519 static void call_nt_transact_notify_change(connection_struct
*conn
,
1520 struct smb_request
*req
,
1524 uint32 parameter_count
,
1525 char **ppdata
, uint32 data_count
,
1526 uint32 max_data_count
,
1527 uint32 max_param_count
)
1529 uint16
*setup
= *ppsetup
;
1535 if(setup_count
< 6) {
1536 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1540 fsp
= file_fsp(req
, SVAL(setup
,4));
1541 filter
= IVAL(setup
, 0);
1542 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1544 DEBUG(3,("call_nt_transact_notify_change\n"));
1547 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1552 char *filter_string
;
1554 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1555 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1559 DEBUG(3,("call_nt_transact_notify_change: notify change "
1560 "called on %s, filter = %s, recursive = %d\n",
1561 fsp_str_dbg(fsp
), filter_string
, recursive
));
1563 TALLOC_FREE(filter_string
);
1566 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1567 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1571 if (fsp
->notify
== NULL
) {
1573 status
= change_notify_create(fsp
, filter
, recursive
);
1575 if (!NT_STATUS_IS_OK(status
)) {
1576 DEBUG(10, ("change_notify_create returned %s\n",
1577 nt_errstr(status
)));
1578 reply_nterror(req
, status
);
1583 if (fsp
->notify
->num_changes
!= 0) {
1586 * We've got changes pending, respond immediately
1590 * TODO: write a torture test to check the filtering behaviour
1594 change_notify_reply(fsp
->conn
, req
,
1598 smbd_smb1_notify_reply
);
1601 * change_notify_reply() above has independently sent its
1608 * No changes pending, queue the request
1611 status
= change_notify_add_request(req
,
1615 smbd_smb1_notify_reply
);
1616 if (!NT_STATUS_IS_OK(status
)) {
1617 reply_nterror(req
, status
);
1622 /****************************************************************************
1623 Reply to an NT transact rename command.
1624 ****************************************************************************/
1626 static void call_nt_transact_rename(connection_struct
*conn
,
1627 struct smb_request
*req
,
1628 uint16
**ppsetup
, uint32 setup_count
,
1629 char **ppparams
, uint32 parameter_count
,
1630 char **ppdata
, uint32 data_count
,
1631 uint32 max_data_count
)
1633 char *params
= *ppparams
;
1634 char *new_name
= NULL
;
1635 files_struct
*fsp
= NULL
;
1636 bool dest_has_wcard
= False
;
1638 TALLOC_CTX
*ctx
= talloc_tos();
1640 if(parameter_count
< 5) {
1641 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1645 fsp
= file_fsp(req
, SVAL(params
, 0));
1646 if (!check_fsp(conn
, req
, fsp
)) {
1649 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1650 parameter_count
- 4,
1651 STR_TERMINATE
, &status
, &dest_has_wcard
);
1652 if (!NT_STATUS_IS_OK(status
)) {
1653 reply_nterror(req
, status
);
1658 * W2K3 ignores this request as the RAW-RENAME test
1659 * demonstrates, so we do.
1661 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1663 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1664 fsp_str_dbg(fsp
), new_name
));
1669 /******************************************************************************
1670 Fake up a completely empty SD.
1671 *******************************************************************************/
1673 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1677 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1679 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1680 return NT_STATUS_NO_MEMORY
;
1683 return NT_STATUS_OK
;
1686 /****************************************************************************
1687 Reply to query a security descriptor.
1688 ****************************************************************************/
1690 static void call_nt_transact_query_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 SEC_DESC
*psd
= NULL
;
1704 uint32 security_info_wanted
;
1705 files_struct
*fsp
= NULL
;
1709 if(parameter_count
< 8) {
1710 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1714 fsp
= file_fsp(req
, SVAL(params
,0));
1716 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1720 security_info_wanted
= IVAL(params
,4);
1722 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1723 "info_wanted = 0x%x\n", fsp_str_dbg(fsp
),
1724 (unsigned int)security_info_wanted
));
1726 params
= nttrans_realloc(ppparams
, 4);
1727 if(params
== NULL
) {
1728 reply_doserror(req
, ERRDOS
, ERRnomem
);
1733 * Get the permissions to return.
1736 if (!lp_nt_acl_support(SNUM(conn
))) {
1737 status
= get_null_nt_acl(talloc_tos(), &psd
);
1739 status
= SMB_VFS_FGET_NT_ACL(
1740 fsp
, security_info_wanted
, &psd
);
1742 if (!NT_STATUS_IS_OK(status
)) {
1743 reply_nterror(req
, status
);
1747 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1748 * present in the reply to match Windows behavior */
1749 if (psd
->sacl
== NULL
&&
1750 security_info_wanted
& SACL_SECURITY_INFORMATION
)
1751 psd
->type
|= SEC_DESC_SACL_PRESENT
;
1752 if (psd
->dacl
== NULL
&&
1753 security_info_wanted
& DACL_SECURITY_INFORMATION
)
1754 psd
->type
|= SEC_DESC_DACL_PRESENT
;
1756 sd_size
= ndr_size_security_descriptor(psd
, NULL
, 0);
1758 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
1760 if (DEBUGLEVEL
>= 10) {
1761 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
1763 NDR_PRINT_DEBUG(security_descriptor
, psd
);
1766 SIVAL(params
,0,(uint32
)sd_size
);
1768 if (max_data_count
< sd_size
) {
1769 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1770 params
, 4, *ppdata
, 0);
1775 * Allocate the data we will point this at.
1778 data
= nttrans_realloc(ppdata
, sd_size
);
1780 reply_doserror(req
, ERRDOS
, ERRnomem
);
1784 status
= marshall_sec_desc(talloc_tos(), psd
,
1785 &blob
.data
, &blob
.length
);
1787 if (!NT_STATUS_IS_OK(status
)) {
1788 reply_nterror(req
, status
);
1792 SMB_ASSERT(sd_size
== blob
.length
);
1793 memcpy(data
, blob
.data
, sd_size
);
1795 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1800 /****************************************************************************
1801 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1802 ****************************************************************************/
1804 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1805 struct smb_request
*req
,
1809 uint32 parameter_count
,
1812 uint32 max_data_count
)
1814 char *params
= *ppparams
;
1815 char *data
= *ppdata
;
1816 files_struct
*fsp
= NULL
;
1817 uint32 security_info_sent
= 0;
1820 if(parameter_count
< 8) {
1821 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1825 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1826 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1830 if(!lp_nt_acl_support(SNUM(conn
))) {
1834 security_info_sent
= IVAL(params
,4);
1836 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1837 fsp_str_dbg(fsp
), (unsigned int)security_info_sent
));
1839 if (data_count
== 0) {
1840 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
1844 status
= set_sd(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
1846 if (!NT_STATUS_IS_OK(status
)) {
1847 reply_nterror(req
, status
);
1852 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1856 /****************************************************************************
1858 ****************************************************************************/
1860 static void call_nt_transact_ioctl(connection_struct
*conn
,
1861 struct smb_request
*req
,
1862 uint16
**ppsetup
, uint32 setup_count
,
1863 char **ppparams
, uint32 parameter_count
,
1864 char **ppdata
, uint32 data_count
,
1865 uint32 max_data_count
)
1872 char *pdata
= *ppdata
;
1874 if (setup_count
!= 8) {
1875 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1876 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1880 function
= IVAL(*ppsetup
, 0);
1881 fidnum
= SVAL(*ppsetup
, 4);
1882 isFSctl
= CVAL(*ppsetup
, 6);
1883 compfilter
= CVAL(*ppsetup
, 7);
1885 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1886 function
, fidnum
, isFSctl
, compfilter
));
1888 fsp
=file_fsp(req
, fidnum
);
1889 /* this check is done in each implemented function case for now
1890 because I don't want to break anything... --metze
1891 FSP_BELONGS_CONN(fsp,conn);*/
1893 SMB_PERFCOUNT_SET_IOCTL(&req
->pcd
, function
);
1896 case FSCTL_SET_SPARSE
:
1897 /* pretend this succeeded - tho strictly we should
1898 mark the file sparse (if the local fs supports it)
1899 so we can know if we need to pre-allocate or not */
1901 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1902 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1905 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
1907 unsigned char objid
[16];
1909 /* This should return the object-id on this file.
1910 * I think I'll make this be the inode+dev. JRA.
1913 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
1915 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1920 pdata
= nttrans_realloc(ppdata
, data_count
);
1921 if (pdata
== NULL
) {
1922 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1926 /* For backwards compatibility only store the dev/inode. */
1927 push_file_id_16(pdata
, &fsp
->file_id
);
1928 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
1929 push_file_id_16(pdata
+32, &fsp
->file_id
);
1930 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1935 case FSCTL_GET_REPARSE_POINT
:
1936 /* pretend this fail - my winXP does it like this
1940 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1941 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1944 case FSCTL_SET_REPARSE_POINT
:
1945 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1949 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1950 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1953 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
1956 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1957 * and return their volume names. If max_data_count is 16, then it is just
1958 * asking for the number of volumes and length of the combined names.
1960 * pdata is the data allocated by our caller, but that uses
1961 * total_data_count (which is 0 in our case) rather than max_data_count.
1962 * Allocate the correct amount and return the pointer to let
1963 * it be deallocated when we return.
1965 SHADOW_COPY_DATA
*shadow_data
= NULL
;
1966 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
1967 bool labels
= False
;
1968 uint32 labels_data_count
= 0;
1972 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1976 if (max_data_count
< 16) {
1977 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1979 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1983 if (max_data_count
> 16) {
1987 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
1988 if (shadow_mem_ctx
== NULL
) {
1989 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1990 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1994 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
1995 if (shadow_data
== NULL
) {
1996 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1997 talloc_destroy(shadow_mem_ctx
);
1998 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2002 shadow_data
->mem_ctx
= shadow_mem_ctx
;
2005 * Call the VFS routine to actually do the work.
2007 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
2008 talloc_destroy(shadow_data
->mem_ctx
);
2009 if (errno
== ENOSYS
) {
2010 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2011 conn
->connectpath
));
2012 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2015 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2016 conn
->connectpath
));
2017 reply_nterror(req
, NT_STATUS_UNSUCCESSFUL
);
2022 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2027 data_count
= 12+labels_data_count
+4;
2030 if (max_data_count
<data_count
) {
2031 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2032 max_data_count
,data_count
));
2033 talloc_destroy(shadow_data
->mem_ctx
);
2034 reply_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
2038 pdata
= nttrans_realloc(ppdata
, data_count
);
2039 if (pdata
== NULL
) {
2040 talloc_destroy(shadow_data
->mem_ctx
);
2041 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2047 /* num_volumes 4 bytes */
2048 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2051 /* num_labels 4 bytes */
2052 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2055 /* needed_data_count 4 bytes */
2056 SIVAL(pdata
, 8, labels_data_count
+4);
2060 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2061 shadow_data
->num_volumes
, fsp_str_dbg(fsp
)));
2062 if (labels
&& shadow_data
->labels
) {
2063 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2064 srvstr_push(pdata
, req
->flags2
,
2065 cur_pdata
, shadow_data
->labels
[i
],
2066 2*sizeof(SHADOW_COPY_LABEL
),
2067 STR_UNICODE
|STR_TERMINATE
);
2068 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2069 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2073 talloc_destroy(shadow_data
->mem_ctx
);
2075 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
2081 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2083 /* pretend this succeeded -
2085 * we have to send back a list with all files owned by this SID
2087 * but I have to check that --metze
2091 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2093 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2095 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
2099 /* unknown 4 bytes: this is not the length of the sid :-( */
2100 /*unknown = IVAL(pdata,0);*/
2102 sid_parse(pdata
+4,sid_len
,&sid
);
2103 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
2105 if (!sid_to_uid(&sid
, &uid
)) {
2106 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2107 sid_string_dbg(&sid
),
2108 (unsigned long)sid_len
));
2112 /* we can take a look at the find source :-)
2114 * find ./ -uid $uid -name '*' is what we need here
2117 * and send 4bytes len and then NULL terminated unicode strings
2120 * but I don't know how to deal with the paged results
2121 * (maybe we can hang the result anywhere in the fsp struct)
2123 * we don't send all files at once
2124 * and at the next we should *not* start from the beginning,
2125 * so we have to cache the result
2130 /* this works for now... */
2131 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2135 if (!logged_ioctl_message
) {
2136 logged_ioctl_message
= true; /* Only print this once... */
2137 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2142 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2146 #ifdef HAVE_SYS_QUOTAS
2147 /****************************************************************************
2148 Reply to get user quota
2149 ****************************************************************************/
2151 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2152 struct smb_request
*req
,
2156 uint32 parameter_count
,
2159 uint32 max_data_count
)
2161 NTSTATUS nt_status
= NT_STATUS_OK
;
2162 char *params
= *ppparams
;
2163 char *pdata
= *ppdata
;
2165 int data_len
=0,param_len
=0;
2168 files_struct
*fsp
= NULL
;
2172 bool start_enum
= True
;
2173 SMB_NTQUOTA_STRUCT qt
;
2174 SMB_NTQUOTA_LIST
*tmp_list
;
2175 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2180 if (conn
->server_info
->utok
.uid
!= 0) {
2181 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2182 "[%s]\n", lp_servicename(SNUM(conn
)),
2183 conn
->server_info
->unix_name
));
2184 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2189 * Ensure minimum number of parameters sent.
2192 if (parameter_count
< 4) {
2193 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2194 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2198 /* maybe we can check the quota_fnum */
2199 fsp
= file_fsp(req
, SVAL(params
,0));
2200 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2201 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2202 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2206 /* the NULL pointer checking for fsp->fake_file_handle->pd
2207 * is done by CHECK_NTQUOTA_HANDLE_OK()
2209 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2211 level
= SVAL(params
,2);
2213 /* unknown 12 bytes leading in params */
2216 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2217 /* seems that we should continue with the enum here --metze */
2219 if (qt_handle
->quota_list
!=NULL
&&
2220 qt_handle
->tmp_list
==NULL
) {
2223 free_ntquota_list(&(qt_handle
->quota_list
));
2225 /* Realloc the size of parameters and data we will return */
2227 params
= nttrans_realloc(ppparams
, param_len
);
2228 if(params
== NULL
) {
2229 reply_doserror(req
, ERRDOS
, ERRnomem
);
2234 SIVAL(params
,0,data_len
);
2241 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2243 if (qt_handle
->quota_list
==NULL
&&
2244 qt_handle
->tmp_list
==NULL
) {
2248 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2249 reply_doserror(req
, ERRSRV
, ERRerror
);
2253 /* Realloc the size of parameters and data we will return */
2255 params
= nttrans_realloc(ppparams
, param_len
);
2256 if(params
== NULL
) {
2257 reply_doserror(req
, ERRDOS
, ERRnomem
);
2261 /* we should not trust the value in max_data_count*/
2262 max_data_count
= MIN(max_data_count
,2048);
2264 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2266 reply_doserror(req
, ERRDOS
, ERRnomem
);
2272 /* set params Size of returned Quota Data 4 bytes*/
2273 /* but set it later when we know it */
2275 /* for each entry push the data */
2278 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2281 tmp_list
= qt_handle
->tmp_list
;
2283 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2284 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2286 sid_len
= ndr_size_dom_sid(
2287 &tmp_list
->quotas
->sid
, NULL
, 0);
2288 entry_len
= 40 + sid_len
;
2290 /* nextoffset entry 4 bytes */
2291 SIVAL(entry
,0,entry_len
);
2293 /* then the len of the SID 4 bytes */
2294 SIVAL(entry
,4,sid_len
);
2296 /* unknown data 8 bytes uint64_t */
2297 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2299 /* the used disk space 8 bytes uint64_t */
2300 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2302 /* the soft quotas 8 bytes uint64_t */
2303 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2305 /* the hard quotas 8 bytes uint64_t */
2306 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2308 /* and now the SID */
2309 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2312 qt_handle
->tmp_list
= tmp_list
;
2314 /* overwrite the offset of the last entry */
2315 SIVAL(entry
-entry_len
,0,0);
2317 data_len
= 4+qt_len
;
2318 /* overwrite the params quota_data_len */
2319 SIVAL(params
,0,data_len
);
2323 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2325 /* unknown 4 bytes IVAL(pdata,0) */
2327 if (data_count
< 8) {
2328 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2329 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2333 sid_len
= IVAL(pdata
,4);
2334 /* Ensure this is less than 1mb. */
2335 if (sid_len
> (1024*1024)) {
2336 reply_doserror(req
, ERRDOS
, ERRnomem
);
2340 if (data_count
< 8+sid_len
) {
2341 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2342 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2346 data_len
= 4+40+sid_len
;
2348 if (max_data_count
< data_len
) {
2349 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2350 max_data_count
, data_len
));
2352 SIVAL(params
,0,data_len
);
2354 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2358 sid_parse(pdata
+8,sid_len
,&sid
);
2360 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2363 * we have to return zero's in all fields
2364 * instead of returning an error here
2369 /* Realloc the size of parameters and data we will return */
2371 params
= nttrans_realloc(ppparams
, param_len
);
2372 if(params
== NULL
) {
2373 reply_doserror(req
, ERRDOS
, ERRnomem
);
2377 pdata
= nttrans_realloc(ppdata
, data_len
);
2379 reply_doserror(req
, ERRDOS
, ERRnomem
);
2385 /* set params Size of returned Quota Data 4 bytes*/
2386 SIVAL(params
,0,data_len
);
2388 /* nextoffset entry 4 bytes */
2391 /* then the len of the SID 4 bytes */
2392 SIVAL(entry
,4,sid_len
);
2394 /* unknown data 8 bytes uint64_t */
2395 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2397 /* the used disk space 8 bytes uint64_t */
2398 SBIG_UINT(entry
,16,qt
.usedspace
);
2400 /* the soft quotas 8 bytes uint64_t */
2401 SBIG_UINT(entry
,24,qt
.softlim
);
2403 /* the hard quotas 8 bytes uint64_t */
2404 SBIG_UINT(entry
,32,qt
.hardlim
);
2406 /* and now the SID */
2407 sid_linearize(entry
+40, sid_len
, &sid
);
2412 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2413 reply_doserror(req
, ERRSRV
, ERRerror
);
2418 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2422 /****************************************************************************
2423 Reply to set user quota
2424 ****************************************************************************/
2426 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2427 struct smb_request
*req
,
2431 uint32 parameter_count
,
2434 uint32 max_data_count
)
2436 char *params
= *ppparams
;
2437 char *pdata
= *ppdata
;
2438 int data_len
=0,param_len
=0;
2439 SMB_NTQUOTA_STRUCT qt
;
2442 files_struct
*fsp
= NULL
;
2447 if (conn
->server_info
->utok
.uid
!= 0) {
2448 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2449 "[%s]\n", lp_servicename(SNUM(conn
)),
2450 conn
->server_info
->unix_name
));
2451 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2456 * Ensure minimum number of parameters sent.
2459 if (parameter_count
< 2) {
2460 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2461 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2465 /* maybe we can check the quota_fnum */
2466 fsp
= file_fsp(req
, SVAL(params
,0));
2467 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2468 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2469 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2473 if (data_count
< 40) {
2474 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2475 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2479 /* offset to next quota record.
2480 * 4 bytes IVAL(pdata,0)
2485 sid_len
= IVAL(pdata
,4);
2487 if (data_count
< 40+sid_len
) {
2488 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2489 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2493 /* unknown 8 bytes in pdata
2494 * maybe its the change time in NTTIME
2497 /* the used space 8 bytes (uint64_t)*/
2498 qt
.usedspace
= (uint64_t)IVAL(pdata
,16);
2499 #ifdef LARGE_SMB_OFF_T
2500 qt
.usedspace
|= (((uint64_t)IVAL(pdata
,20)) << 32);
2501 #else /* LARGE_SMB_OFF_T */
2502 if ((IVAL(pdata
,20) != 0)&&
2503 ((qt
.usedspace
!= 0xFFFFFFFF)||
2504 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2505 /* more than 32 bits? */
2506 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2509 #endif /* LARGE_SMB_OFF_T */
2511 /* the soft quotas 8 bytes (uint64_t)*/
2512 qt
.softlim
= (uint64_t)IVAL(pdata
,24);
2513 #ifdef LARGE_SMB_OFF_T
2514 qt
.softlim
|= (((uint64_t)IVAL(pdata
,28)) << 32);
2515 #else /* LARGE_SMB_OFF_T */
2516 if ((IVAL(pdata
,28) != 0)&&
2517 ((qt
.softlim
!= 0xFFFFFFFF)||
2518 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2519 /* more than 32 bits? */
2520 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2523 #endif /* LARGE_SMB_OFF_T */
2525 /* the hard quotas 8 bytes (uint64_t)*/
2526 qt
.hardlim
= (uint64_t)IVAL(pdata
,32);
2527 #ifdef LARGE_SMB_OFF_T
2528 qt
.hardlim
|= (((uint64_t)IVAL(pdata
,36)) << 32);
2529 #else /* LARGE_SMB_OFF_T */
2530 if ((IVAL(pdata
,36) != 0)&&
2531 ((qt
.hardlim
!= 0xFFFFFFFF)||
2532 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2533 /* more than 32 bits? */
2534 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2537 #endif /* LARGE_SMB_OFF_T */
2539 sid_parse(pdata
+40,sid_len
,&sid
);
2540 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2542 /* 44 unknown bytes left... */
2544 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2545 reply_doserror(req
, ERRSRV
, ERRerror
);
2549 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2552 #endif /* HAVE_SYS_QUOTAS */
2554 static void handle_nttrans(connection_struct
*conn
,
2555 struct trans_state
*state
,
2556 struct smb_request
*req
)
2558 if (get_Protocol() >= PROTOCOL_NT1
) {
2559 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2560 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2564 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2566 /* Now we must call the relevant NT_TRANS function */
2567 switch(state
->call
) {
2568 case NT_TRANSACT_CREATE
:
2570 START_PROFILE(NT_transact_create
);
2571 call_nt_transact_create(
2573 &state
->setup
, state
->setup_count
,
2574 &state
->param
, state
->total_param
,
2575 &state
->data
, state
->total_data
,
2576 state
->max_data_return
);
2577 END_PROFILE(NT_transact_create
);
2581 case NT_TRANSACT_IOCTL
:
2583 START_PROFILE(NT_transact_ioctl
);
2584 call_nt_transact_ioctl(
2586 &state
->setup
, state
->setup_count
,
2587 &state
->param
, state
->total_param
,
2588 &state
->data
, state
->total_data
,
2589 state
->max_data_return
);
2590 END_PROFILE(NT_transact_ioctl
);
2594 case NT_TRANSACT_SET_SECURITY_DESC
:
2596 START_PROFILE(NT_transact_set_security_desc
);
2597 call_nt_transact_set_security_desc(
2599 &state
->setup
, state
->setup_count
,
2600 &state
->param
, state
->total_param
,
2601 &state
->data
, state
->total_data
,
2602 state
->max_data_return
);
2603 END_PROFILE(NT_transact_set_security_desc
);
2607 case NT_TRANSACT_NOTIFY_CHANGE
:
2609 START_PROFILE(NT_transact_notify_change
);
2610 call_nt_transact_notify_change(
2612 &state
->setup
, state
->setup_count
,
2613 &state
->param
, state
->total_param
,
2614 &state
->data
, state
->total_data
,
2615 state
->max_data_return
,
2616 state
->max_param_return
);
2617 END_PROFILE(NT_transact_notify_change
);
2621 case NT_TRANSACT_RENAME
:
2623 START_PROFILE(NT_transact_rename
);
2624 call_nt_transact_rename(
2626 &state
->setup
, state
->setup_count
,
2627 &state
->param
, state
->total_param
,
2628 &state
->data
, state
->total_data
,
2629 state
->max_data_return
);
2630 END_PROFILE(NT_transact_rename
);
2634 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2636 START_PROFILE(NT_transact_query_security_desc
);
2637 call_nt_transact_query_security_desc(
2639 &state
->setup
, state
->setup_count
,
2640 &state
->param
, state
->total_param
,
2641 &state
->data
, state
->total_data
,
2642 state
->max_data_return
);
2643 END_PROFILE(NT_transact_query_security_desc
);
2647 #ifdef HAVE_SYS_QUOTAS
2648 case NT_TRANSACT_GET_USER_QUOTA
:
2650 START_PROFILE(NT_transact_get_user_quota
);
2651 call_nt_transact_get_user_quota(
2653 &state
->setup
, state
->setup_count
,
2654 &state
->param
, state
->total_param
,
2655 &state
->data
, state
->total_data
,
2656 state
->max_data_return
);
2657 END_PROFILE(NT_transact_get_user_quota
);
2661 case NT_TRANSACT_SET_USER_QUOTA
:
2663 START_PROFILE(NT_transact_set_user_quota
);
2664 call_nt_transact_set_user_quota(
2666 &state
->setup
, state
->setup_count
,
2667 &state
->param
, state
->total_param
,
2668 &state
->data
, state
->total_data
,
2669 state
->max_data_return
);
2670 END_PROFILE(NT_transact_set_user_quota
);
2673 #endif /* HAVE_SYS_QUOTAS */
2676 /* Error in request */
2677 DEBUG(0,("handle_nttrans: Unknown request %d in "
2678 "nttrans call\n", state
->call
));
2679 reply_doserror(req
, ERRSRV
, ERRerror
);
2685 /****************************************************************************
2686 Reply to a SMBNTtrans.
2687 ****************************************************************************/
2689 void reply_nttrans(struct smb_request
*req
)
2691 connection_struct
*conn
= req
->conn
;
2696 uint16 function_code
;
2698 struct trans_state
*state
;
2700 START_PROFILE(SMBnttrans
);
2702 if (req
->wct
< 19) {
2703 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2704 END_PROFILE(SMBnttrans
);
2708 pscnt
= IVAL(req
->vwv
+9, 1);
2709 psoff
= IVAL(req
->vwv
+11, 1);
2710 dscnt
= IVAL(req
->vwv
+13, 1);
2711 dsoff
= IVAL(req
->vwv
+15, 1);
2712 function_code
= SVAL(req
->vwv
+18, 0);
2714 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2715 reply_doserror(req
, ERRSRV
, ERRaccess
);
2716 END_PROFILE(SMBnttrans
);
2720 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2721 if (!NT_STATUS_IS_OK(result
)) {
2722 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2723 reply_nterror(req
, result
);
2724 END_PROFILE(SMBnttrans
);
2728 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
2729 reply_doserror(req
, ERRSRV
, ERRaccess
);
2730 END_PROFILE(SMBnttrans
);
2734 state
->cmd
= SMBnttrans
;
2736 state
->mid
= req
->mid
;
2737 state
->vuid
= req
->vuid
;
2738 state
->total_data
= IVAL(req
->vwv
+3, 1);
2740 state
->total_param
= IVAL(req
->vwv
+1, 1);
2741 state
->param
= NULL
;
2742 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2743 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2745 /* setup count is in *words* */
2746 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2747 state
->setup
= NULL
;
2748 state
->call
= function_code
;
2750 DEBUG(10, ("num_setup=%u, "
2751 "param_total=%u, this_param=%u, max_param=%u, "
2752 "data_total=%u, this_data=%u, max_data=%u, "
2753 "param_offset=%u, data_offset=%u\n",
2754 (unsigned)state
->setup_count
,
2755 (unsigned)state
->total_param
, (unsigned)pscnt
,
2756 (unsigned)state
->max_param_return
,
2757 (unsigned)state
->total_data
, (unsigned)dscnt
,
2758 (unsigned)state
->max_data_return
,
2759 (unsigned)psoff
, (unsigned)dsoff
));
2762 * All nttrans messages we handle have smb_wct == 19 +
2763 * state->setup_count. Ensure this is so as a sanity check.
2766 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2767 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2768 req
->wct
, 19 + (state
->setup_count
/2)));
2772 /* Don't allow more than 128mb for each value. */
2773 if ((state
->total_data
> (1024*1024*128)) ||
2774 (state
->total_param
> (1024*1024*128))) {
2775 reply_doserror(req
, ERRDOS
, ERRnomem
);
2776 END_PROFILE(SMBnttrans
);
2780 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2783 if (state
->total_data
) {
2785 if (trans_oob(state
->total_data
, 0, dscnt
)
2786 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
2790 /* Can't use talloc here, the core routines do realloc on the
2791 * params and data. */
2792 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2793 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2794 "bytes !\n", (unsigned int)state
->total_data
));
2796 reply_doserror(req
, ERRDOS
, ERRnomem
);
2797 END_PROFILE(SMBnttrans
);
2801 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2804 if (state
->total_param
) {
2806 if (trans_oob(state
->total_param
, 0, pscnt
)
2807 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
2811 /* Can't use talloc here, the core routines do realloc on the
2812 * params and data. */
2813 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2814 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2815 "bytes !\n", (unsigned int)state
->total_param
));
2816 SAFE_FREE(state
->data
);
2818 reply_doserror(req
, ERRDOS
, ERRnomem
);
2819 END_PROFILE(SMBnttrans
);
2823 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2826 state
->received_data
= dscnt
;
2827 state
->received_param
= pscnt
;
2829 if(state
->setup_count
> 0) {
2830 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2831 state
->setup_count
));
2834 * No overflow possible here, state->setup_count is an
2835 * unsigned int, being filled by a single byte from
2836 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2837 * below is not necessary, it's here to clarify things. The
2838 * validity of req->vwv and req->wct has been checked in
2839 * init_smb_request already.
2841 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
2845 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
2846 if (state
->setup
== NULL
) {
2847 DEBUG(0,("reply_nttrans : Out of memory\n"));
2848 SAFE_FREE(state
->data
);
2849 SAFE_FREE(state
->param
);
2851 reply_doserror(req
, ERRDOS
, ERRnomem
);
2852 END_PROFILE(SMBnttrans
);
2856 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
2857 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
2860 if ((state
->received_data
== state
->total_data
) &&
2861 (state
->received_param
== state
->total_param
)) {
2862 handle_nttrans(conn
, state
, req
);
2863 SAFE_FREE(state
->param
);
2864 SAFE_FREE(state
->data
);
2866 END_PROFILE(SMBnttrans
);
2870 DLIST_ADD(conn
->pending_trans
, state
);
2872 /* We need to send an interim response then receive the rest
2873 of the parameter/data bytes */
2874 reply_outbuf(req
, 0, 0);
2875 show_msg((char *)req
->outbuf
);
2876 END_PROFILE(SMBnttrans
);
2881 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2882 SAFE_FREE(state
->data
);
2883 SAFE_FREE(state
->param
);
2885 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2886 END_PROFILE(SMBnttrans
);
2890 /****************************************************************************
2891 Reply to a SMBnttranss
2892 ****************************************************************************/
2894 void reply_nttranss(struct smb_request
*req
)
2896 connection_struct
*conn
= req
->conn
;
2897 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2898 struct trans_state
*state
;
2900 START_PROFILE(SMBnttranss
);
2902 show_msg((char *)req
->inbuf
);
2904 if (req
->wct
< 18) {
2905 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2906 END_PROFILE(SMBnttranss
);
2910 for (state
= conn
->pending_trans
; state
!= NULL
;
2911 state
= state
->next
) {
2912 if (state
->mid
== req
->mid
) {
2917 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2918 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2919 END_PROFILE(SMBnttranss
);
2923 /* Revise state->total_param and state->total_data in case they have
2924 changed downwards */
2925 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
2926 state
->total_param
= IVAL(req
->vwv
+1, 1);
2928 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
2929 state
->total_data
= IVAL(req
->vwv
+3, 1);
2932 pcnt
= IVAL(req
->vwv
+5, 1);
2933 poff
= IVAL(req
->vwv
+7, 1);
2934 pdisp
= IVAL(req
->vwv
+9, 1);
2936 dcnt
= IVAL(req
->vwv
+11, 1);
2937 doff
= IVAL(req
->vwv
+13, 1);
2938 ddisp
= IVAL(req
->vwv
+15, 1);
2940 state
->received_param
+= pcnt
;
2941 state
->received_data
+= dcnt
;
2943 if ((state
->received_data
> state
->total_data
) ||
2944 (state
->received_param
> state
->total_param
))
2948 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
2949 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
2952 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
2956 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
2957 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
2960 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
2963 if ((state
->received_param
< state
->total_param
) ||
2964 (state
->received_data
< state
->total_data
)) {
2965 END_PROFILE(SMBnttranss
);
2969 handle_nttrans(conn
, state
, req
);
2971 DLIST_REMOVE(conn
->pending_trans
, state
);
2972 SAFE_FREE(state
->data
);
2973 SAFE_FREE(state
->param
);
2975 END_PROFILE(SMBnttranss
);
2980 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2981 DLIST_REMOVE(conn
->pending_trans
, state
);
2982 SAFE_FREE(state
->data
);
2983 SAFE_FREE(state
->param
);
2985 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2986 END_PROFILE(SMBnttranss
);