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 enum protocol_types Protocol
;
25 extern const struct generic_mapping file_generic_mapping
;
27 static char *nttrans_realloc(char **ptr
, size_t size
)
30 smb_panic("nttrans_realloc() called with NULL ptr");
33 *ptr
= (char *)SMB_REALLOC(*ptr
, size
);
37 memset(*ptr
,'\0',size
);
41 /****************************************************************************
42 Send the required number of replies back.
43 We assume all fields other than the data fields are
44 set correctly for the type of call.
45 HACK ! Always assumes smb_setup field is zero.
46 ****************************************************************************/
48 void send_nt_replies(connection_struct
*conn
,
49 struct smb_request
*req
, NTSTATUS nt_error
,
50 char *params
, int paramsize
,
51 char *pdata
, int datasize
)
53 int data_to_send
= datasize
;
54 int params_to_send
= paramsize
;
58 int params_sent_thistime
, data_sent_thistime
, total_sent_thistime
;
59 int alignment_offset
= 3;
60 int data_alignment_offset
= 0;
63 * If there genuinely are no parameters or data to send just send
67 if(params_to_send
== 0 && data_to_send
== 0) {
68 reply_outbuf(req
, 18, 0);
69 show_msg((char *)req
->outbuf
);
74 * When sending params and data ensure that both are nicely aligned.
75 * Only do this alignment when there is also data to send - else
76 * can cause NT redirector problems.
79 if (((params_to_send
% 4) != 0) && (data_to_send
!= 0)) {
80 data_alignment_offset
= 4 - (params_to_send
% 4);
84 * Space is bufsize minus Netbios over TCP header minus SMB header.
85 * The alignment_offset is to align the param bytes on a four byte
86 * boundary (2 bytes for data len, one byte pad).
87 * NT needs this to work correctly.
90 useable_space
= max_send
- (smb_size
93 + data_alignment_offset
);
95 if (useable_space
< 0) {
96 char *msg
= talloc_asprintf(
98 "send_nt_replies failed sanity useable_space = %d!!!",
100 DEBUG(0, ("%s\n", msg
));
101 exit_server_cleanly(msg
);
104 while (params_to_send
|| data_to_send
) {
107 * Calculate whether we will totally or partially fill this packet.
110 total_sent_thistime
= params_to_send
+ data_to_send
;
113 * We can never send more than useable_space.
116 total_sent_thistime
= MIN(total_sent_thistime
, useable_space
);
118 reply_outbuf(req
, 18,
119 total_sent_thistime
+ alignment_offset
120 + data_alignment_offset
);
123 * We might have had SMBnttranss in req->inbuf, fix that.
125 SCVAL(req
->outbuf
, smb_com
, SMBnttrans
);
128 * Set total params and data to be sent.
131 SIVAL(req
->outbuf
,smb_ntr_TotalParameterCount
,paramsize
);
132 SIVAL(req
->outbuf
,smb_ntr_TotalDataCount
,datasize
);
135 * Calculate how many parameters and data we can fit into
136 * this packet. Parameters get precedence.
139 params_sent_thistime
= MIN(params_to_send
,useable_space
);
140 data_sent_thistime
= useable_space
- params_sent_thistime
;
141 data_sent_thistime
= MIN(data_sent_thistime
,data_to_send
);
143 SIVAL(req
->outbuf
, smb_ntr_ParameterCount
,
144 params_sent_thistime
);
146 if(params_sent_thistime
== 0) {
147 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,0);
148 SIVAL(req
->outbuf
,smb_ntr_ParameterDisplacement
,0);
151 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
152 * parameter bytes, however the first 4 bytes of outbuf are
153 * the Netbios over TCP header. Thus use smb_base() to subtract
154 * them from the calculation.
157 SIVAL(req
->outbuf
,smb_ntr_ParameterOffset
,
158 ((smb_buf(req
->outbuf
)+alignment_offset
)
159 - smb_base(req
->outbuf
)));
161 * Absolute displacement of param bytes sent in this packet.
164 SIVAL(req
->outbuf
, smb_ntr_ParameterDisplacement
,
169 * Deal with the data portion.
172 SIVAL(req
->outbuf
, smb_ntr_DataCount
, data_sent_thistime
);
174 if(data_sent_thistime
== 0) {
175 SIVAL(req
->outbuf
,smb_ntr_DataOffset
,0);
176 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, 0);
179 * The offset of the data bytes is the offset of the
180 * parameter bytes plus the number of parameters being sent this time.
183 SIVAL(req
->outbuf
, smb_ntr_DataOffset
,
184 ((smb_buf(req
->outbuf
)+alignment_offset
) -
185 smb_base(req
->outbuf
))
186 + params_sent_thistime
+ data_alignment_offset
);
187 SIVAL(req
->outbuf
,smb_ntr_DataDisplacement
, pd
- pdata
);
191 * Copy the param bytes into the packet.
194 if(params_sent_thistime
) {
195 if (alignment_offset
!= 0) {
196 memset(smb_buf(req
->outbuf
), 0,
199 memcpy((smb_buf(req
->outbuf
)+alignment_offset
), pp
,
200 params_sent_thistime
);
204 * Copy in the data bytes
207 if(data_sent_thistime
) {
208 if (data_alignment_offset
!= 0) {
209 memset((smb_buf(req
->outbuf
)+alignment_offset
+
210 params_sent_thistime
), 0,
211 data_alignment_offset
);
213 memcpy(smb_buf(req
->outbuf
)+alignment_offset
214 +params_sent_thistime
+data_alignment_offset
,
215 pd
,data_sent_thistime
);
218 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
219 params_sent_thistime
, data_sent_thistime
, useable_space
));
220 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
221 params_to_send
, data_to_send
, paramsize
, datasize
));
223 if (NT_STATUS_V(nt_error
)) {
224 error_packet_set((char *)req
->outbuf
,
229 /* Send the packet */
230 show_msg((char *)req
->outbuf
);
231 if (!srv_send_smb(smbd_server_fd(),
233 IS_CONN_ENCRYPTED(conn
),
235 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
238 TALLOC_FREE(req
->outbuf
);
240 pp
+= params_sent_thistime
;
241 pd
+= data_sent_thistime
;
243 params_to_send
-= params_sent_thistime
;
244 data_to_send
-= data_sent_thistime
;
250 if(params_to_send
< 0 || data_to_send
< 0) {
251 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
252 params_to_send
, data_to_send
));
253 exit_server_cleanly("send_nt_replies: internal error");
258 /****************************************************************************
259 Is it an NTFS stream name ?
260 An NTFS file name is <path>.<extention>:<stream name>:<stream type>
261 $DATA can be used as both a stream name and a stream type. A missing stream
262 name or type implies $DATA.
264 Both Windows stream names and POSIX files can contain the ':' character.
265 This function first checks for the existence of a colon in the last component
266 of the given name. If the name contains a colon we differentiate between a
267 stream and POSIX file by checking if the latter exists through a POSIX stat.
269 Function assumes we've already chdir() to the "root" directory of fname.
270 ****************************************************************************/
272 bool is_ntfs_stream_name(const char *fname
)
274 const char *lastcomp
;
275 SMB_STRUCT_STAT sbuf
;
277 /* If all pathnames are treated as POSIX we ignore streams. */
278 if (lp_posix_pathnames()) {
282 /* Find the last component of the name. */
283 if ((lastcomp
= strrchr_m(fname
, '/')) != NULL
)
288 /* If there is no colon in the last component, it's not a stream. */
289 if (strchr_m(lastcomp
, ':') == NULL
)
293 * If file already exists on disk, it's not a stream. The stat must
294 * bypass the vfs layer so streams modules don't intefere.
296 if (sys_stat(fname
, &sbuf
) == 0) {
297 DEBUG(5, ("is_ntfs_stream_name: file %s contains a ':' but is "
298 "not a stream\n", fname
));
305 /****************************************************************************
306 Reply to an NT create and X call on a pipe
307 ****************************************************************************/
309 static void nt_open_pipe(char *fname
, connection_struct
*conn
,
310 struct smb_request
*req
, int *ppnum
)
315 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname
));
317 /* Strip \\ off the name. */
320 status
= open_np_file(req
, fname
, &fsp
);
321 if (!NT_STATUS_IS_OK(status
)) {
322 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_NOT_FOUND
)) {
323 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
327 reply_nterror(req
, status
);
335 /****************************************************************************
336 Reply to an NT create and X call for pipes.
337 ****************************************************************************/
339 static void do_ntcreate_pipe_open(connection_struct
*conn
,
340 struct smb_request
*req
)
345 uint32 flags
= IVAL(req
->vwv
+3, 1);
346 TALLOC_CTX
*ctx
= talloc_tos();
348 srvstr_pull_req_talloc(ctx
, req
, &fname
, req
->buf
, STR_TERMINATE
);
351 reply_botherror(req
, NT_STATUS_OBJECT_NAME_NOT_FOUND
,
355 nt_open_pipe(fname
, conn
, req
, &pnum
);
363 * Deal with pipe return.
366 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
367 /* This is very strange. We
368 * return 50 words, but only set
369 * the wcnt to 42 ? It's definately
370 * what happens on the wire....
372 reply_outbuf(req
, 50, 0);
373 SCVAL(req
->outbuf
,smb_wct
,42);
375 reply_outbuf(req
, 34, 0);
378 p
= (char *)req
->outbuf
+ smb_vwv2
;
382 SIVAL(p
,0,FILE_WAS_OPENED
);
385 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
388 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
390 SSVAL(p
,2, 0x5FF); /* ? */
393 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
395 SIVAL(p
,0,FILE_GENERIC_ALL
);
397 * For pipes W2K3 seems to return
399 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
401 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
404 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname
));
409 /****************************************************************************
410 Reply to an NT create and X call.
411 ****************************************************************************/
413 void reply_ntcreate_and_X(struct smb_request
*req
)
415 connection_struct
*conn
= req
->conn
;
419 uint32 file_attributes
;
421 uint32 create_disposition
;
422 uint32 create_options
;
424 uint64_t allocation_size
;
425 /* Breakout the oplock request bits so we can set the
426 reply bits separately. */
428 SMB_OFF_T file_len
= 0;
429 SMB_STRUCT_STAT sbuf
;
431 files_struct
*fsp
= NULL
;
433 struct timespec c_timespec
;
434 struct timespec a_timespec
;
435 struct timespec m_timespec
;
438 uint8_t oplock_granted
= NO_OPLOCK_RETURN
;
439 struct case_semantics_state
*case_state
= NULL
;
440 TALLOC_CTX
*ctx
= talloc_tos();
442 START_PROFILE(SMBntcreateX
);
444 SET_STAT_INVALID(sbuf
);
447 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
451 flags
= IVAL(req
->vwv
+3, 1);
452 access_mask
= IVAL(req
->vwv
+7, 1);
453 file_attributes
= IVAL(req
->vwv
+13, 1);
454 share_access
= IVAL(req
->vwv
+15, 1);
455 create_disposition
= IVAL(req
->vwv
+17, 1);
456 create_options
= IVAL(req
->vwv
+19, 1);
457 root_dir_fid
= (uint16
)IVAL(req
->vwv
+5, 1);
459 allocation_size
= (uint64_t)IVAL(req
->vwv
+9, 1);
460 #ifdef LARGE_SMB_OFF_T
461 allocation_size
|= (((uint64_t)IVAL(req
->vwv
+11, 1)) << 32);
464 srvstr_get_path_req(ctx
, req
, &fname
, (const char *)req
->buf
,
465 STR_TERMINATE
, &status
);
467 if (!NT_STATUS_IS_OK(status
)) {
468 reply_nterror(req
, status
);
469 END_PROFILE(SMBntcreateX
);
473 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
474 "file_attributes = 0x%x, share_access = 0x%x, "
475 "create_disposition = 0x%x create_options = 0x%x "
476 "root_dir_fid = 0x%x, fname = %s\n",
478 (unsigned int)access_mask
,
479 (unsigned int)file_attributes
,
480 (unsigned int)share_access
,
481 (unsigned int)create_disposition
,
482 (unsigned int)create_options
,
483 (unsigned int)root_dir_fid
,
487 * we need to remove ignored bits when they come directly from the client
488 * because we reuse some of them for internal stuff
490 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
493 * If it's an IPC, use the pipe handler.
497 if (lp_nt_pipe_support()) {
498 do_ntcreate_pipe_open(conn
, req
);
499 END_PROFILE(SMBntcreateX
);
502 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
503 END_PROFILE(SMBntcreateX
);
507 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
508 if (oplock_request
) {
509 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
514 * Check if POSIX semantics are wanted.
517 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
518 case_state
= set_posix_case_semantics(ctx
, conn
);
520 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
521 END_PROFILE(SMBntcreateX
);
525 * Bug #6898 - clients using Windows opens should
526 * never be able to set this attribute into the
529 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
532 status
= SMB_VFS_CREATE_FILE(
535 root_dir_fid
, /* root_dir_fid */
537 CFF_DOS_PATH
, /* create_file_flags */
538 access_mask
, /* access_mask */
539 share_access
, /* share_access */
540 create_disposition
, /* create_disposition*/
541 create_options
, /* create_options */
542 file_attributes
, /* file_attributes */
543 oplock_request
, /* oplock_request */
544 allocation_size
, /* allocation_size */
551 TALLOC_FREE(case_state
);
553 if (!NT_STATUS_IS_OK(status
)) {
554 if (open_was_deferred(req
->mid
)) {
555 /* We have re-scheduled this call, no error. */
556 END_PROFILE(SMBntcreateX
);
559 if (NT_STATUS_EQUAL(status
, NT_STATUS_OBJECT_NAME_COLLISION
)) {
560 reply_botherror(req
, status
, ERRDOS
, ERRfilexists
);
563 reply_nterror(req
, status
);
565 END_PROFILE(SMBntcreateX
);
570 * If the caller set the extended oplock request bit
571 * and we granted one (by whatever means) - set the
572 * correct bit for extended oplock reply.
575 if (oplock_request
&&
576 (lp_fake_oplocks(SNUM(conn
))
577 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
580 * Exclusive oplock granted
583 if (flags
& REQUEST_BATCH_OPLOCK
) {
584 oplock_granted
= BATCH_OPLOCK_RETURN
;
586 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
588 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
589 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
591 oplock_granted
= NO_OPLOCK_RETURN
;
594 file_len
= sbuf
.st_size
;
595 fattr
= dos_mode(conn
,fsp
->fsp_name
,&sbuf
);
597 fattr
= FILE_ATTRIBUTE_NORMAL
;
600 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
601 /* This is very strange. We
602 * return 50 words, but only set
603 * the wcnt to 42 ? It's definately
604 * what happens on the wire....
606 reply_outbuf(req
, 50, 0);
607 SCVAL(req
->outbuf
,smb_wct
,42);
609 reply_outbuf(req
, 34, 0);
612 p
= (char *)req
->outbuf
+ smb_vwv2
;
614 SCVAL(p
, 0, oplock_granted
);
617 SSVAL(p
,0,fsp
->fnum
);
619 if ((create_disposition
== FILE_SUPERSEDE
)
620 && (info
== FILE_WAS_OVERWRITTEN
)) {
621 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
628 c_timespec
= get_create_timespec(
629 &sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
630 a_timespec
= get_atimespec(&sbuf
);
631 m_timespec
= get_mtimespec(&sbuf
);
633 if (lp_dos_filetime_resolution(SNUM(conn
))) {
634 dos_filetime_timespec(&c_timespec
);
635 dos_filetime_timespec(&a_timespec
);
636 dos_filetime_timespec(&m_timespec
);
639 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* create time. */
641 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
643 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
645 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* change time */
647 SIVAL(p
,0,fattr
); /* File Attributes. */
649 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&sbuf
));
651 SOFF_T(p
,0,file_len
);
653 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
657 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
659 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
662 if (fsp
->is_directory
663 || can_write_to_file(conn
, fsp
->fsp_name
, &sbuf
)) {
664 perms
= FILE_GENERIC_ALL
;
666 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
671 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
672 fsp
->fnum
, fsp
->fsp_name
));
675 END_PROFILE(SMBntcreateX
);
679 /****************************************************************************
680 Reply to a NT_TRANSACT_CREATE call to open a pipe.
681 ****************************************************************************/
683 static void do_nt_transact_create_pipe(connection_struct
*conn
,
684 struct smb_request
*req
,
685 uint16
**ppsetup
, uint32 setup_count
,
686 char **ppparams
, uint32 parameter_count
,
687 char **ppdata
, uint32 data_count
)
690 char *params
= *ppparams
;
696 TALLOC_CTX
*ctx
= talloc_tos();
699 * Ensure minimum number of parameters sent.
702 if(parameter_count
< 54) {
703 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
704 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
708 flags
= IVAL(params
,0);
710 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
, params
+53,
711 parameter_count
-53, STR_TERMINATE
,
713 if (!NT_STATUS_IS_OK(status
)) {
714 reply_nterror(req
, status
);
718 nt_open_pipe(fname
, conn
, req
, &pnum
);
725 /* Realloc the size of parameters and data we will return */
726 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
727 /* Extended response is 32 more byyes. */
732 params
= nttrans_realloc(ppparams
, param_len
);
734 reply_doserror(req
, ERRDOS
, ERRnomem
);
739 SCVAL(p
,0,NO_OPLOCK_RETURN
);
744 SIVAL(p
,0,FILE_WAS_OPENED
);
748 SIVAL(p
,0,FILE_ATTRIBUTE_NORMAL
); /* File Attributes. */
751 SSVAL(p
,0,FILE_TYPE_MESSAGE_MODE_PIPE
);
753 SSVAL(p
,2, 0x5FF); /* ? */
756 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
758 SIVAL(p
,0,FILE_GENERIC_ALL
);
760 * For pipes W2K3 seems to return
762 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
764 SIVAL(p
,4,(FILE_GENERIC_READ
|FILE_GENERIC_WRITE
)&~FILE_APPEND_DATA
);
767 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname
));
769 /* Send the required number of replies */
770 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
775 /****************************************************************************
776 Internal fn to set security descriptors.
777 ****************************************************************************/
779 static NTSTATUS
set_sd(files_struct
*fsp
, uint8
*data
, uint32 sd_len
,
780 uint32 security_info_sent
)
782 SEC_DESC
*psd
= NULL
;
785 if (sd_len
== 0 || !lp_nt_acl_support(SNUM(fsp
->conn
))) {
789 status
= unmarshall_sec_desc(talloc_tos(), data
, sd_len
, &psd
);
791 if (!NT_STATUS_IS_OK(status
)) {
795 if (psd
->owner_sid
== NULL
) {
796 security_info_sent
&= ~OWNER_SECURITY_INFORMATION
;
798 if (psd
->group_sid
== NULL
) {
799 security_info_sent
&= ~GROUP_SECURITY_INFORMATION
;
802 /* Convert all the generic bits. */
803 security_acl_map_generic(psd
->dacl
, &file_generic_mapping
);
804 security_acl_map_generic(psd
->sacl
, &file_generic_mapping
);
806 if (DEBUGLEVEL
>= 10) {
807 DEBUG(10,("set_sd for file %s\n", fsp
->fsp_name
));
808 NDR_PRINT_DEBUG(security_descriptor
, psd
);
811 status
= SMB_VFS_FSET_NT_ACL(fsp
, security_info_sent
, psd
);
818 /****************************************************************************
819 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
820 ****************************************************************************/
822 static struct ea_list
*read_nttrans_ea_list(TALLOC_CTX
*ctx
, const char *pdata
, size_t data_size
)
824 struct ea_list
*ea_list_head
= NULL
;
831 while (offset
+ 4 <= data_size
) {
832 size_t next_offset
= IVAL(pdata
,offset
);
833 struct ea_list
*eal
= read_ea_list_entry(ctx
, pdata
+ offset
+ 4, data_size
- offset
- 4, NULL
);
839 DLIST_ADD_END(ea_list_head
, eal
, struct ea_list
*);
840 if (next_offset
== 0) {
843 offset
+= next_offset
;
849 /****************************************************************************
850 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
851 ****************************************************************************/
853 static void call_nt_transact_create(connection_struct
*conn
,
854 struct smb_request
*req
,
855 uint16
**ppsetup
, uint32 setup_count
,
856 char **ppparams
, uint32 parameter_count
,
857 char **ppdata
, uint32 data_count
,
858 uint32 max_data_count
)
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;
866 SMB_STRUCT_STAT sbuf
;
868 files_struct
*fsp
= NULL
;
872 uint32 file_attributes
;
874 uint32 create_disposition
;
875 uint32 create_options
;
877 struct security_descriptor
*sd
= NULL
;
880 struct timespec c_timespec
;
881 struct timespec a_timespec
;
882 struct timespec m_timespec
;
883 struct ea_list
*ea_list
= NULL
;
886 uint64_t allocation_size
;
888 uint8_t oplock_granted
;
889 struct case_semantics_state
*case_state
= NULL
;
890 TALLOC_CTX
*ctx
= talloc_tos();
892 SET_STAT_INVALID(sbuf
);
894 DEBUG(5,("call_nt_transact_create\n"));
897 * If it's an IPC, use the pipe handler.
901 if (lp_nt_pipe_support()) {
902 do_nt_transact_create_pipe(
904 ppsetup
, setup_count
,
905 ppparams
, parameter_count
,
909 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
914 * Ensure minimum number of parameters sent.
917 if(parameter_count
< 54) {
918 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count
));
919 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
923 flags
= IVAL(params
,0);
924 access_mask
= IVAL(params
,8);
925 file_attributes
= IVAL(params
,20);
926 share_access
= IVAL(params
,24);
927 create_disposition
= IVAL(params
,28);
928 create_options
= IVAL(params
,32);
929 sd_len
= IVAL(params
,36);
930 ea_len
= IVAL(params
,40);
931 root_dir_fid
= (uint16
)IVAL(params
,4);
932 allocation_size
= (uint64_t)IVAL(params
,12);
933 #ifdef LARGE_SMB_OFF_T
934 allocation_size
|= (((uint64_t)IVAL(params
,16)) << 32);
938 * we need to remove ignored bits when they come directly from the client
939 * because we reuse some of them for internal stuff
941 create_options
&= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK
;
943 /* Ensure the data_len is correct for the sd and ea values given. */
944 if ((ea_len
+ sd_len
> data_count
)
945 || (ea_len
> data_count
) || (sd_len
> data_count
)
946 || (ea_len
+ sd_len
< ea_len
) || (ea_len
+ sd_len
< sd_len
)) {
947 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
948 "%u, data_count = %u\n", (unsigned int)ea_len
,
949 (unsigned int)sd_len
, (unsigned int)data_count
));
950 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
955 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
958 status
= unmarshall_sec_desc(ctx
, (uint8_t *)data
, sd_len
,
960 if (!NT_STATUS_IS_OK(status
)) {
961 DEBUG(10, ("call_nt_transact_create: "
962 "unmarshall_sec_desc failed: %s\n",
964 reply_nterror(req
, status
);
970 if (!lp_ea_support(SNUM(conn
))) {
971 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
972 "EA's not supported.\n",
973 (unsigned int)ea_len
));
974 reply_nterror(req
, NT_STATUS_EAS_NOT_SUPPORTED
);
979 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
980 "too small (should be more than 10)\n",
981 (unsigned int)ea_len
));
982 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
986 /* We have already checked that ea_len <= data_count here. */
987 ea_list
= read_nttrans_ea_list(talloc_tos(), data
+ sd_len
,
989 if (ea_list
== NULL
) {
990 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
995 srvstr_get_path(ctx
, params
, req
->flags2
, &fname
,
996 params
+53, parameter_count
-53,
997 STR_TERMINATE
, &status
);
998 if (!NT_STATUS_IS_OK(status
)) {
999 reply_nterror(req
, status
);
1003 oplock_request
= (flags
& REQUEST_OPLOCK
) ? EXCLUSIVE_OPLOCK
: 0;
1004 if (oplock_request
) {
1005 oplock_request
|= (flags
& REQUEST_BATCH_OPLOCK
)
1010 * Check if POSIX semantics are wanted.
1013 if (file_attributes
& FILE_FLAG_POSIX_SEMANTICS
) {
1014 case_state
= set_posix_case_semantics(ctx
, conn
);
1016 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1020 * Bug #6898 - clients using Windows opens should
1021 * never be able to set this attribute into the
1024 file_attributes
&= ~FILE_FLAG_POSIX_SEMANTICS
;
1027 status
= SMB_VFS_CREATE_FILE(
1030 root_dir_fid
, /* root_dir_fid */
1032 CFF_DOS_PATH
, /* create_file_flags */
1033 access_mask
, /* access_mask */
1034 share_access
, /* share_access */
1035 create_disposition
, /* create_disposition*/
1036 create_options
, /* create_options */
1037 file_attributes
, /* file_attributes */
1038 oplock_request
, /* oplock_request */
1039 allocation_size
, /* allocation_size */
1041 ea_list
, /* ea_list */
1046 TALLOC_FREE(case_state
);
1048 if(!NT_STATUS_IS_OK(status
)) {
1049 if (open_was_deferred(req
->mid
)) {
1050 /* We have re-scheduled this call, no error. */
1053 reply_openerror(req
, status
);
1058 * If the caller set the extended oplock request bit
1059 * and we granted one (by whatever means) - set the
1060 * correct bit for extended oplock reply.
1063 if (oplock_request
&&
1064 (lp_fake_oplocks(SNUM(conn
))
1065 || EXCLUSIVE_OPLOCK_TYPE(fsp
->oplock_type
))) {
1068 * Exclusive oplock granted
1071 if (flags
& REQUEST_BATCH_OPLOCK
) {
1072 oplock_granted
= BATCH_OPLOCK_RETURN
;
1074 oplock_granted
= EXCLUSIVE_OPLOCK_RETURN
;
1076 } else if (fsp
->oplock_type
== LEVEL_II_OPLOCK
) {
1077 oplock_granted
= LEVEL_II_OPLOCK_RETURN
;
1079 oplock_granted
= NO_OPLOCK_RETURN
;
1082 file_len
= sbuf
.st_size
;
1083 fattr
= dos_mode(conn
,fsp
->fsp_name
,&sbuf
);
1085 fattr
= FILE_ATTRIBUTE_NORMAL
;
1088 /* Realloc the size of parameters and data we will return */
1089 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1090 /* Extended response is 32 more byyes. */
1095 params
= nttrans_realloc(ppparams
, param_len
);
1096 if(params
== NULL
) {
1097 reply_doserror(req
, ERRDOS
, ERRnomem
);
1102 SCVAL(p
, 0, oplock_granted
);
1105 SSVAL(p
,0,fsp
->fnum
);
1107 if ((create_disposition
== FILE_SUPERSEDE
)
1108 && (info
== FILE_WAS_OVERWRITTEN
)) {
1109 SIVAL(p
,0,FILE_WAS_SUPERSEDED
);
1116 c_timespec
= get_create_timespec(
1117 &sbuf
,lp_fake_dir_create_times(SNUM(conn
)));
1118 a_timespec
= get_atimespec(&sbuf
);
1119 m_timespec
= get_mtimespec(&sbuf
);
1121 if (lp_dos_filetime_resolution(SNUM(conn
))) {
1122 dos_filetime_timespec(&c_timespec
);
1123 dos_filetime_timespec(&a_timespec
);
1124 dos_filetime_timespec(&m_timespec
);
1127 put_long_date_timespec(conn
->ts_res
, p
, c_timespec
); /* create time. */
1129 put_long_date_timespec(conn
->ts_res
, p
, a_timespec
); /* access time */
1131 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* write time */
1133 put_long_date_timespec(conn
->ts_res
, p
, m_timespec
); /* change time */
1135 SIVAL(p
,0,fattr
); /* File Attributes. */
1137 SOFF_T(p
, 0, SMB_VFS_GET_ALLOC_SIZE(conn
,fsp
,&sbuf
));
1139 SOFF_T(p
,0,file_len
);
1141 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1145 SCVAL(p
,0,fsp
->is_directory
? 1 : 0);
1147 if (flags
& EXTENDED_RESPONSE_REQUIRED
) {
1150 if (fsp
->is_directory
1151 || can_write_to_file(conn
, fsp
->fsp_name
, &sbuf
)) {
1152 perms
= FILE_GENERIC_ALL
;
1154 perms
= FILE_GENERIC_READ
|FILE_EXECUTE
;
1159 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp
->fsp_name
));
1161 /* Send the required number of replies */
1162 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
, *ppdata
, 0);
1167 /****************************************************************************
1168 Reply to a NT CANCEL request.
1169 conn POINTER CAN BE NULL HERE !
1170 ****************************************************************************/
1172 void reply_ntcancel(struct smb_request
*req
)
1175 * Go through and cancel any pending change notifies.
1178 START_PROFILE(SMBntcancel
);
1179 remove_pending_change_notify_requests_by_mid(req
->mid
);
1180 remove_pending_lock_requests_by_mid(req
->mid
);
1181 srv_cancel_sign_response(req
->mid
, true);
1183 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req
->mid
));
1185 END_PROFILE(SMBntcancel
);
1189 /****************************************************************************
1191 ****************************************************************************/
1193 static NTSTATUS
copy_internals(TALLOC_CTX
*ctx
,
1194 connection_struct
*conn
,
1195 struct smb_request
*req
,
1196 const char *oldname_in
,
1197 const char *newname_in
,
1200 SMB_STRUCT_STAT sbuf1
, sbuf2
;
1201 char *oldname
= NULL
;
1202 char *newname
= NULL
;
1203 char *last_component_oldname
= NULL
;
1204 char *last_component_newname
= NULL
;
1205 files_struct
*fsp1
,*fsp2
;
1209 NTSTATUS status
= NT_STATUS_OK
;
1215 if (!CAN_WRITE(conn
)) {
1216 return NT_STATUS_MEDIA_WRITE_PROTECTED
;
1219 status
= unix_convert(ctx
, conn
, oldname_in
, False
, &oldname
,
1220 &last_component_oldname
, &sbuf1
);
1221 if (!NT_STATUS_IS_OK(status
)) {
1225 status
= check_name(conn
, oldname
);
1226 if (!NT_STATUS_IS_OK(status
)) {
1230 /* Source must already exist. */
1231 if (!VALID_STAT(sbuf1
)) {
1232 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1234 /* Ensure attributes match. */
1235 fattr
= dos_mode(conn
,oldname
,&sbuf1
);
1236 if ((fattr
& ~attrs
) & (aHIDDEN
| aSYSTEM
)) {
1237 return NT_STATUS_NO_SUCH_FILE
;
1240 status
= unix_convert(ctx
, conn
, newname_in
, False
, &newname
,
1241 &last_component_newname
, &sbuf2
);
1242 if (!NT_STATUS_IS_OK(status
)) {
1246 status
= check_name(conn
, newname
);
1247 if (!NT_STATUS_IS_OK(status
)) {
1251 /* Disallow if newname already exists. */
1252 if (VALID_STAT(sbuf2
)) {
1253 return NT_STATUS_OBJECT_NAME_COLLISION
;
1256 /* No links from a directory. */
1257 if (S_ISDIR(sbuf1
.st_mode
)) {
1258 return NT_STATUS_FILE_IS_A_DIRECTORY
;
1261 /* Ensure this is within the share. */
1262 status
= check_reduced_name(conn
, oldname
);
1263 if (!NT_STATUS_IS_OK(status
)) {
1267 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1270 status
= SMB_VFS_CREATE_FILE(
1273 0, /* root_dir_fid */
1274 oldname
, /* fname */
1275 0, /* create_file_flags */
1276 FILE_READ_DATA
, /* access_mask */
1277 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1279 FILE_OPEN
, /* create_disposition*/
1280 0, /* create_options */
1281 FILE_ATTRIBUTE_NORMAL
, /* file_attributes */
1282 NO_OPLOCK
, /* oplock_request */
1283 0, /* allocation_size */
1288 &sbuf1
); /* psbuf */
1290 if (!NT_STATUS_IS_OK(status
)) {
1294 status
= SMB_VFS_CREATE_FILE(
1297 0, /* root_dir_fid */
1298 newname
, /* fname */
1299 0, /* create_file_flags */
1300 FILE_WRITE_DATA
, /* access_mask */
1301 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
1303 FILE_CREATE
, /* create_disposition*/
1304 0, /* create_options */
1305 fattr
, /* file_attributes */
1306 NO_OPLOCK
, /* oplock_request */
1307 0, /* allocation_size */
1312 &sbuf2
); /* psbuf */
1314 if (!NT_STATUS_IS_OK(status
)) {
1315 close_file(NULL
, fsp1
, ERROR_CLOSE
);
1319 if (sbuf1
.st_size
) {
1320 ret
= vfs_transfer_file(fsp1
, fsp2
, sbuf1
.st_size
);
1324 * As we are opening fsp1 read-only we only expect
1325 * an error on close on fsp2 if we are out of space.
1326 * Thus we don't look at the error return from the
1329 close_file(NULL
, fsp1
, NORMAL_CLOSE
);
1331 /* Ensure the modtime is set correctly on the destination file. */
1332 set_close_write_time(fsp2
, get_mtimespec(&sbuf1
));
1334 status
= close_file(NULL
, fsp2
, NORMAL_CLOSE
);
1336 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1337 creates the file. This isn't the correct thing to do in the copy
1339 if (!parent_dirname(talloc_tos(), newname
, &parent
, NULL
)) {
1340 return NT_STATUS_NO_MEMORY
;
1342 file_set_dosmode(conn
, newname
, fattr
, &sbuf2
, parent
, false);
1343 TALLOC_FREE(parent
);
1345 if (ret
< (SMB_OFF_T
)sbuf1
.st_size
) {
1346 return NT_STATUS_DISK_FULL
;
1349 if (!NT_STATUS_IS_OK(status
)) {
1350 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1351 nt_errstr(status
), oldname
, newname
));
1356 /****************************************************************************
1357 Reply to a NT rename request.
1358 ****************************************************************************/
1360 void reply_ntrename(struct smb_request
*req
)
1362 connection_struct
*conn
= req
->conn
;
1363 char *oldname
= NULL
;
1364 char *newname
= NULL
;
1367 bool src_has_wcard
= False
;
1368 bool dest_has_wcard
= False
;
1371 TALLOC_CTX
*ctx
= talloc_tos();
1373 START_PROFILE(SMBntrename
);
1376 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1377 END_PROFILE(SMBntrename
);
1381 attrs
= SVAL(req
->vwv
+0, 0);
1382 rename_type
= SVAL(req
->vwv
+1, 0);
1384 p
= (const char *)req
->buf
+ 1;
1385 p
+= srvstr_get_path_req_wcard(ctx
, req
, &oldname
, p
, STR_TERMINATE
,
1386 &status
, &src_has_wcard
);
1387 if (!NT_STATUS_IS_OK(status
)) {
1388 reply_nterror(req
, status
);
1389 END_PROFILE(SMBntrename
);
1393 if (ms_has_wild(oldname
)) {
1394 reply_nterror(req
, NT_STATUS_OBJECT_PATH_SYNTAX_BAD
);
1395 END_PROFILE(SMBntrename
);
1400 p
+= srvstr_get_path_req_wcard(ctx
, req
, &newname
, p
, STR_TERMINATE
,
1401 &status
, &dest_has_wcard
);
1402 if (!NT_STATUS_IS_OK(status
)) {
1403 reply_nterror(req
, status
);
1404 END_PROFILE(SMBntrename
);
1408 status
= resolve_dfspath(ctx
, conn
,
1409 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1412 if (!NT_STATUS_IS_OK(status
)) {
1413 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1414 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
1415 ERRSRV
, ERRbadpath
);
1416 END_PROFILE(SMBntrename
);
1419 reply_nterror(req
, status
);
1420 END_PROFILE(SMBntrename
);
1424 status
= resolve_dfspath(ctx
, conn
,
1425 req
->flags2
& FLAGS2_DFS_PATHNAMES
,
1428 if (!NT_STATUS_IS_OK(status
)) {
1429 if (NT_STATUS_EQUAL(status
,NT_STATUS_PATH_NOT_COVERED
)) {
1430 reply_botherror(req
, NT_STATUS_PATH_NOT_COVERED
,
1431 ERRSRV
, ERRbadpath
);
1432 END_PROFILE(SMBntrename
);
1435 reply_nterror(req
, status
);
1436 END_PROFILE(SMBntrename
);
1440 /* The new name must begin with a ':' if the old name is a stream. */
1441 if (is_ntfs_stream_name(oldname
) && (newname
[0] != ':')) {
1442 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1443 END_PROFILE(SMBntrename
);
1447 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname
,newname
));
1449 switch(rename_type
) {
1450 case RENAME_FLAG_RENAME
:
1451 status
= rename_internals(ctx
, conn
, req
, oldname
,
1452 newname
, attrs
, False
, src_has_wcard
,
1453 dest_has_wcard
, DELETE_ACCESS
);
1455 case RENAME_FLAG_HARD_LINK
:
1456 if (src_has_wcard
|| dest_has_wcard
) {
1458 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1460 status
= hardlink_internals(ctx
,
1466 case RENAME_FLAG_COPY
:
1467 if (src_has_wcard
|| dest_has_wcard
) {
1469 status
= NT_STATUS_OBJECT_PATH_SYNTAX_BAD
;
1471 status
= copy_internals(ctx
, conn
, req
, oldname
,
1475 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION
:
1476 status
= NT_STATUS_INVALID_PARAMETER
;
1479 status
= NT_STATUS_ACCESS_DENIED
; /* Default error. */
1483 if (!NT_STATUS_IS_OK(status
)) {
1484 if (open_was_deferred(req
->mid
)) {
1485 /* We have re-scheduled this call. */
1486 END_PROFILE(SMBntrename
);
1490 reply_nterror(req
, status
);
1491 END_PROFILE(SMBntrename
);
1495 reply_outbuf(req
, 0, 0);
1497 END_PROFILE(SMBntrename
);
1501 /****************************************************************************
1502 Reply to a notify change - queue the request and
1503 don't allow a directory to be opened.
1504 ****************************************************************************/
1506 static void call_nt_transact_notify_change(connection_struct
*conn
,
1507 struct smb_request
*req
,
1511 uint32 parameter_count
,
1512 char **ppdata
, uint32 data_count
,
1513 uint32 max_data_count
,
1514 uint32 max_param_count
)
1516 uint16
*setup
= *ppsetup
;
1522 if(setup_count
< 6) {
1523 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1527 fsp
= file_fsp(req
, SVAL(setup
,4));
1528 filter
= IVAL(setup
, 0);
1529 recursive
= (SVAL(setup
, 6) != 0) ? True
: False
;
1531 DEBUG(3,("call_nt_transact_notify_change\n"));
1534 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1539 char *filter_string
;
1541 if (!(filter_string
= notify_filter_string(NULL
, filter
))) {
1542 reply_nterror(req
,NT_STATUS_NO_MEMORY
);
1546 DEBUG(3,("call_nt_transact_notify_change: notify change "
1547 "called on %s, filter = %s, recursive = %d\n",
1548 fsp
->fsp_name
, filter_string
, recursive
));
1550 TALLOC_FREE(filter_string
);
1553 if((!fsp
->is_directory
) || (conn
!= fsp
->conn
)) {
1554 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1558 if (fsp
->notify
== NULL
) {
1560 status
= change_notify_create(fsp
, filter
, recursive
);
1562 if (!NT_STATUS_IS_OK(status
)) {
1563 DEBUG(10, ("change_notify_create returned %s\n",
1564 nt_errstr(status
)));
1565 reply_nterror(req
, status
);
1570 if (fsp
->notify
->num_changes
!= 0) {
1573 * We've got changes pending, respond immediately
1577 * TODO: write a torture test to check the filtering behaviour
1581 change_notify_reply(fsp
->conn
, req
, max_param_count
,
1585 * change_notify_reply() above has independently sent its
1592 * No changes pending, queue the request
1595 status
= change_notify_add_request(req
,
1599 if (!NT_STATUS_IS_OK(status
)) {
1600 reply_nterror(req
, status
);
1605 /****************************************************************************
1606 Reply to an NT transact rename command.
1607 ****************************************************************************/
1609 static void call_nt_transact_rename(connection_struct
*conn
,
1610 struct smb_request
*req
,
1611 uint16
**ppsetup
, uint32 setup_count
,
1612 char **ppparams
, uint32 parameter_count
,
1613 char **ppdata
, uint32 data_count
,
1614 uint32 max_data_count
)
1616 char *params
= *ppparams
;
1617 char *new_name
= NULL
;
1618 files_struct
*fsp
= NULL
;
1619 bool dest_has_wcard
= False
;
1621 TALLOC_CTX
*ctx
= talloc_tos();
1623 if(parameter_count
< 5) {
1624 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1628 fsp
= file_fsp(req
, SVAL(params
, 0));
1629 if (!check_fsp(conn
, req
, fsp
)) {
1632 srvstr_get_path_wcard(ctx
, params
, req
->flags2
, &new_name
, params
+4,
1633 parameter_count
- 4,
1634 STR_TERMINATE
, &status
, &dest_has_wcard
);
1635 if (!NT_STATUS_IS_OK(status
)) {
1636 reply_nterror(req
, status
);
1641 * W2K3 ignores this request as the RAW-RENAME test
1642 * demonstrates, so we do.
1644 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1646 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1647 fsp
->fsp_name
, new_name
));
1652 /******************************************************************************
1653 Fake up a completely empty SD.
1654 *******************************************************************************/
1656 static NTSTATUS
get_null_nt_acl(TALLOC_CTX
*mem_ctx
, SEC_DESC
**ppsd
)
1660 *ppsd
= make_standard_sec_desc( mem_ctx
, &global_sid_World
, &global_sid_World
, NULL
, &sd_size
);
1662 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1663 return NT_STATUS_NO_MEMORY
;
1666 return NT_STATUS_OK
;
1669 /****************************************************************************
1670 Reply to query a security descriptor.
1671 ****************************************************************************/
1673 static void call_nt_transact_query_security_desc(connection_struct
*conn
,
1674 struct smb_request
*req
,
1678 uint32 parameter_count
,
1681 uint32 max_data_count
)
1683 char *params
= *ppparams
;
1684 char *data
= *ppdata
;
1685 SEC_DESC
*psd
= NULL
;
1687 uint32 security_info_wanted
;
1688 files_struct
*fsp
= NULL
;
1692 if(parameter_count
< 8) {
1693 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1697 fsp
= file_fsp(req
, SVAL(params
,0));
1699 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1703 security_info_wanted
= IVAL(params
,4);
1705 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp
->fsp_name
,
1706 (unsigned int)security_info_wanted
));
1708 params
= nttrans_realloc(ppparams
, 4);
1709 if(params
== NULL
) {
1710 reply_doserror(req
, ERRDOS
, ERRnomem
);
1715 * Get the permissions to return.
1718 if (!lp_nt_acl_support(SNUM(conn
))) {
1719 status
= get_null_nt_acl(talloc_tos(), &psd
);
1721 status
= SMB_VFS_FGET_NT_ACL(
1722 fsp
, security_info_wanted
, &psd
);
1724 if (!NT_STATUS_IS_OK(status
)) {
1725 reply_nterror(req
, status
);
1729 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1730 * present in the reply to match Windows behavior */
1731 if (psd
->sacl
== NULL
&&
1732 security_info_wanted
& SACL_SECURITY_INFORMATION
)
1733 psd
->type
|= SEC_DESC_SACL_PRESENT
;
1734 if (psd
->dacl
== NULL
&&
1735 security_info_wanted
& DACL_SECURITY_INFORMATION
)
1736 psd
->type
|= SEC_DESC_DACL_PRESENT
;
1738 sd_size
= ndr_size_security_descriptor(psd
, NULL
, 0);
1740 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size
));
1742 if (DEBUGLEVEL
>= 10) {
1743 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp
->fsp_name
));
1744 NDR_PRINT_DEBUG(security_descriptor
, psd
);
1747 SIVAL(params
,0,(uint32
)sd_size
);
1749 if (max_data_count
< sd_size
) {
1750 send_nt_replies(conn
, req
, NT_STATUS_BUFFER_TOO_SMALL
,
1751 params
, 4, *ppdata
, 0);
1756 * Allocate the data we will point this at.
1759 data
= nttrans_realloc(ppdata
, sd_size
);
1761 reply_doserror(req
, ERRDOS
, ERRnomem
);
1765 status
= marshall_sec_desc(talloc_tos(), psd
,
1766 &blob
.data
, &blob
.length
);
1768 if (!NT_STATUS_IS_OK(status
)) {
1769 reply_nterror(req
, status
);
1773 SMB_ASSERT(sd_size
== blob
.length
);
1774 memcpy(data
, blob
.data
, sd_size
);
1776 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, 4, data
, (int)sd_size
);
1781 /****************************************************************************
1782 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1783 ****************************************************************************/
1785 static void call_nt_transact_set_security_desc(connection_struct
*conn
,
1786 struct smb_request
*req
,
1790 uint32 parameter_count
,
1793 uint32 max_data_count
)
1795 char *params
= *ppparams
;
1796 char *data
= *ppdata
;
1797 files_struct
*fsp
= NULL
;
1798 uint32 security_info_sent
= 0;
1801 if(parameter_count
< 8) {
1802 reply_doserror(req
, ERRDOS
, ERRbadfunc
);
1806 if((fsp
= file_fsp(req
, SVAL(params
,0))) == NULL
) {
1807 reply_doserror(req
, ERRDOS
, ERRbadfid
);
1811 if(!lp_nt_acl_support(SNUM(conn
))) {
1815 security_info_sent
= IVAL(params
,4);
1817 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp
->fsp_name
,
1818 (unsigned int)security_info_sent
));
1820 if (data_count
== 0) {
1821 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
1825 status
= set_sd(fsp
, (uint8
*)data
, data_count
, security_info_sent
);
1827 if (!NT_STATUS_IS_OK(status
)) {
1828 reply_nterror(req
, status
);
1833 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1837 /****************************************************************************
1839 ****************************************************************************/
1841 static void call_nt_transact_ioctl(connection_struct
*conn
,
1842 struct smb_request
*req
,
1843 uint16
**ppsetup
, uint32 setup_count
,
1844 char **ppparams
, uint32 parameter_count
,
1845 char **ppdata
, uint32 data_count
,
1846 uint32 max_data_count
)
1853 char *pdata
= *ppdata
;
1855 if (setup_count
!= 8) {
1856 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count
));
1857 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1861 function
= IVAL(*ppsetup
, 0);
1862 fidnum
= SVAL(*ppsetup
, 4);
1863 isFSctl
= CVAL(*ppsetup
, 6);
1864 compfilter
= CVAL(*ppsetup
, 7);
1866 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1867 function
, fidnum
, isFSctl
, compfilter
));
1869 fsp
=file_fsp(req
, fidnum
);
1870 /* this check is done in each implemented function case for now
1871 because I don't want to break anything... --metze
1872 FSP_BELONGS_CONN(fsp,conn);*/
1874 SMB_PERFCOUNT_SET_IOCTL(&req
->pcd
, function
);
1877 case FSCTL_SET_SPARSE
:
1878 /* pretend this succeeded - tho strictly we should
1879 mark the file sparse (if the local fs supports it)
1880 so we can know if we need to pre-allocate or not */
1882 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum
));
1883 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
1886 case FSCTL_CREATE_OR_GET_OBJECT_ID
:
1888 unsigned char objid
[16];
1890 /* This should return the object-id on this file.
1891 * I think I'll make this be the inode+dev. JRA.
1894 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum
));
1896 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1901 pdata
= nttrans_realloc(ppdata
, data_count
);
1902 if (pdata
== NULL
) {
1903 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1907 /* For backwards compatibility only store the dev/inode. */
1908 push_file_id_16(pdata
, &fsp
->file_id
);
1909 memcpy(pdata
+16,create_volume_objectid(conn
,objid
),16);
1910 push_file_id_16(pdata
+32, &fsp
->file_id
);
1911 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
1916 case FSCTL_GET_REPARSE_POINT
:
1917 /* pretend this fail - my winXP does it like this
1921 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1922 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1925 case FSCTL_SET_REPARSE_POINT
:
1926 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1930 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum
));
1931 reply_nterror(req
, NT_STATUS_NOT_A_REPARSE_POINT
);
1934 case FSCTL_GET_SHADOW_COPY_DATA
: /* don't know if this name is right...*/
1937 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1938 * and return their volume names. If max_data_count is 16, then it is just
1939 * asking for the number of volumes and length of the combined names.
1941 * pdata is the data allocated by our caller, but that uses
1942 * total_data_count (which is 0 in our case) rather than max_data_count.
1943 * Allocate the correct amount and return the pointer to let
1944 * it be deallocated when we return.
1946 SHADOW_COPY_DATA
*shadow_data
= NULL
;
1947 TALLOC_CTX
*shadow_mem_ctx
= NULL
;
1948 bool labels
= False
;
1949 uint32 labels_data_count
= 0;
1953 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
1957 if (max_data_count
< 16) {
1958 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1960 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
1964 if (max_data_count
> 16) {
1968 shadow_mem_ctx
= talloc_init("SHADOW_COPY_DATA");
1969 if (shadow_mem_ctx
== NULL
) {
1970 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1971 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1975 shadow_data
= TALLOC_ZERO_P(shadow_mem_ctx
,SHADOW_COPY_DATA
);
1976 if (shadow_data
== NULL
) {
1977 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1978 talloc_destroy(shadow_mem_ctx
);
1979 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
1983 shadow_data
->mem_ctx
= shadow_mem_ctx
;
1986 * Call the VFS routine to actually do the work.
1988 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp
, shadow_data
, labels
)!=0) {
1989 talloc_destroy(shadow_data
->mem_ctx
);
1990 if (errno
== ENOSYS
) {
1991 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1992 conn
->connectpath
));
1993 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
1996 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1997 conn
->connectpath
));
1998 reply_nterror(req
, NT_STATUS_UNSUCCESSFUL
);
2003 labels_data_count
= (shadow_data
->num_volumes
*2*sizeof(SHADOW_COPY_LABEL
))+2;
2008 data_count
= 12+labels_data_count
+4;
2011 if (max_data_count
<data_count
) {
2012 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2013 max_data_count
,data_count
));
2014 talloc_destroy(shadow_data
->mem_ctx
);
2015 reply_nterror(req
, NT_STATUS_BUFFER_TOO_SMALL
);
2019 pdata
= nttrans_realloc(ppdata
, data_count
);
2020 if (pdata
== NULL
) {
2021 talloc_destroy(shadow_data
->mem_ctx
);
2022 reply_nterror(req
, NT_STATUS_NO_MEMORY
);
2028 /* num_volumes 4 bytes */
2029 SIVAL(pdata
,0,shadow_data
->num_volumes
);
2032 /* num_labels 4 bytes */
2033 SIVAL(pdata
,4,shadow_data
->num_volumes
);
2036 /* needed_data_count 4 bytes */
2037 SIVAL(pdata
, 8, labels_data_count
+4);
2041 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2042 shadow_data
->num_volumes
,fsp
->fsp_name
));
2043 if (labels
&& shadow_data
->labels
) {
2044 for (i
=0;i
<shadow_data
->num_volumes
;i
++) {
2045 srvstr_push(pdata
, req
->flags2
,
2046 cur_pdata
, shadow_data
->labels
[i
],
2047 2*sizeof(SHADOW_COPY_LABEL
),
2048 STR_UNICODE
|STR_TERMINATE
);
2049 cur_pdata
+=2*sizeof(SHADOW_COPY_LABEL
);
2050 DEBUGADD(10,("Label[%u]: '%s'\n",i
,shadow_data
->labels
[i
]));
2054 talloc_destroy(shadow_data
->mem_ctx
);
2056 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0,
2062 case FSCTL_FIND_FILES_BY_SID
: /* I hope this name is right */
2064 /* pretend this succeeded -
2066 * we have to send back a list with all files owned by this SID
2068 * but I have to check that --metze
2072 size_t sid_len
= MIN(data_count
-4,SID_MAX_SIZE
);
2074 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum
));
2076 if (!fsp_belongs_conn(conn
, req
, fsp
)) {
2080 /* unknown 4 bytes: this is not the length of the sid :-( */
2081 /*unknown = IVAL(pdata,0);*/
2083 if (!sid_parse(pdata
+4,sid_len
,&sid
)) {
2084 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2088 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid
)));
2090 if (!sid_to_uid(&sid
, &uid
)) {
2091 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2092 sid_string_dbg(&sid
),
2093 (unsigned long)sid_len
));
2097 /* we can take a look at the find source :-)
2099 * find ./ -uid $uid -name '*' is what we need here
2102 * and send 4bytes len and then NULL terminated unicode strings
2105 * but I don't know how to deal with the paged results
2106 * (maybe we can hang the result anywhere in the fsp struct)
2108 * we don't send all files at once
2109 * and at the next we should *not* start from the beginning,
2110 * so we have to cache the result
2115 /* this works for now... */
2116 send_nt_replies(conn
, req
, NT_STATUS_OK
, NULL
, 0, NULL
, 0);
2120 if (!logged_ioctl_message
) {
2121 logged_ioctl_message
= true; /* Only print this once... */
2122 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2127 reply_nterror(req
, NT_STATUS_NOT_SUPPORTED
);
2131 #ifdef HAVE_SYS_QUOTAS
2132 /****************************************************************************
2133 Reply to get user quota
2134 ****************************************************************************/
2136 static void call_nt_transact_get_user_quota(connection_struct
*conn
,
2137 struct smb_request
*req
,
2141 uint32 parameter_count
,
2144 uint32 max_data_count
)
2146 NTSTATUS nt_status
= NT_STATUS_OK
;
2147 char *params
= *ppparams
;
2148 char *pdata
= *ppdata
;
2150 int data_len
=0,param_len
=0;
2153 files_struct
*fsp
= NULL
;
2157 bool start_enum
= True
;
2158 SMB_NTQUOTA_STRUCT qt
;
2159 SMB_NTQUOTA_LIST
*tmp_list
;
2160 SMB_NTQUOTA_HANDLE
*qt_handle
= NULL
;
2165 if (conn
->server_info
->utok
.uid
!= 0) {
2166 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2167 "[%s]\n", lp_servicename(SNUM(conn
)),
2168 conn
->server_info
->unix_name
));
2169 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2174 * Ensure minimum number of parameters sent.
2177 if (parameter_count
< 4) {
2178 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count
));
2179 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2183 /* maybe we can check the quota_fnum */
2184 fsp
= file_fsp(req
, SVAL(params
,0));
2185 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2186 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2187 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2191 /* the NULL pointer checking for fsp->fake_file_handle->pd
2192 * is done by CHECK_NTQUOTA_HANDLE_OK()
2194 qt_handle
= (SMB_NTQUOTA_HANDLE
*)fsp
->fake_file_handle
->private_data
;
2196 level
= SVAL(params
,2);
2198 /* unknown 12 bytes leading in params */
2201 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE
:
2202 /* seems that we should continue with the enum here --metze */
2204 if (qt_handle
->quota_list
!=NULL
&&
2205 qt_handle
->tmp_list
==NULL
) {
2208 free_ntquota_list(&(qt_handle
->quota_list
));
2210 /* Realloc the size of parameters and data we will return */
2212 params
= nttrans_realloc(ppparams
, param_len
);
2213 if(params
== NULL
) {
2214 reply_doserror(req
, ERRDOS
, ERRnomem
);
2219 SIVAL(params
,0,data_len
);
2226 case TRANSACT_GET_USER_QUOTA_LIST_START
:
2228 if (qt_handle
->quota_list
==NULL
&&
2229 qt_handle
->tmp_list
==NULL
) {
2233 if (start_enum
&& vfs_get_user_ntquota_list(fsp
,&(qt_handle
->quota_list
))!=0) {
2234 reply_doserror(req
, ERRSRV
, ERRerror
);
2238 /* Realloc the size of parameters and data we will return */
2240 params
= nttrans_realloc(ppparams
, param_len
);
2241 if(params
== NULL
) {
2242 reply_doserror(req
, ERRDOS
, ERRnomem
);
2246 /* we should not trust the value in max_data_count*/
2247 max_data_count
= MIN(max_data_count
,2048);
2249 pdata
= nttrans_realloc(ppdata
, max_data_count
);/* should be max data count from client*/
2251 reply_doserror(req
, ERRDOS
, ERRnomem
);
2257 /* set params Size of returned Quota Data 4 bytes*/
2258 /* but set it later when we know it */
2260 /* for each entry push the data */
2263 qt_handle
->tmp_list
= qt_handle
->quota_list
;
2266 tmp_list
= qt_handle
->tmp_list
;
2268 for (;((tmp_list
!=NULL
)&&((qt_len
+40+SID_MAX_SIZE
)<max_data_count
));
2269 tmp_list
=tmp_list
->next
,entry
+=entry_len
,qt_len
+=entry_len
) {
2271 sid_len
= ndr_size_dom_sid(
2272 &tmp_list
->quotas
->sid
, NULL
, 0);
2273 entry_len
= 40 + sid_len
;
2275 /* nextoffset entry 4 bytes */
2276 SIVAL(entry
,0,entry_len
);
2278 /* then the len of the SID 4 bytes */
2279 SIVAL(entry
,4,sid_len
);
2281 /* unknown data 8 bytes uint64_t */
2282 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2284 /* the used disk space 8 bytes uint64_t */
2285 SBIG_UINT(entry
,16,tmp_list
->quotas
->usedspace
);
2287 /* the soft quotas 8 bytes uint64_t */
2288 SBIG_UINT(entry
,24,tmp_list
->quotas
->softlim
);
2290 /* the hard quotas 8 bytes uint64_t */
2291 SBIG_UINT(entry
,32,tmp_list
->quotas
->hardlim
);
2293 /* and now the SID */
2294 sid_linearize(entry
+40, sid_len
, &tmp_list
->quotas
->sid
);
2297 qt_handle
->tmp_list
= tmp_list
;
2299 /* overwrite the offset of the last entry */
2300 SIVAL(entry
-entry_len
,0,0);
2302 data_len
= 4+qt_len
;
2303 /* overwrite the params quota_data_len */
2304 SIVAL(params
,0,data_len
);
2308 case TRANSACT_GET_USER_QUOTA_FOR_SID
:
2310 /* unknown 4 bytes IVAL(pdata,0) */
2312 if (data_count
< 8) {
2313 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count
,8));
2314 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2318 sid_len
= IVAL(pdata
,4);
2319 /* Ensure this is less than 1mb. */
2320 if (sid_len
> (1024*1024)) {
2321 reply_doserror(req
, ERRDOS
, ERRnomem
);
2325 if (data_count
< 8+sid_len
) {
2326 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count
,(unsigned long)(8+sid_len
)));
2327 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2331 data_len
= 4+40+sid_len
;
2333 if (max_data_count
< data_len
) {
2334 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2335 max_data_count
, data_len
));
2337 SIVAL(params
,0,data_len
);
2339 nt_status
= NT_STATUS_BUFFER_TOO_SMALL
;
2343 if (!sid_parse(pdata
+8,sid_len
,&sid
)) {
2344 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2348 if (vfs_get_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2351 * we have to return zero's in all fields
2352 * instead of returning an error here
2357 /* Realloc the size of parameters and data we will return */
2359 params
= nttrans_realloc(ppparams
, param_len
);
2360 if(params
== NULL
) {
2361 reply_doserror(req
, ERRDOS
, ERRnomem
);
2365 pdata
= nttrans_realloc(ppdata
, data_len
);
2367 reply_doserror(req
, ERRDOS
, ERRnomem
);
2373 /* set params Size of returned Quota Data 4 bytes*/
2374 SIVAL(params
,0,data_len
);
2376 /* nextoffset entry 4 bytes */
2379 /* then the len of the SID 4 bytes */
2380 SIVAL(entry
,4,sid_len
);
2382 /* unknown data 8 bytes uint64_t */
2383 SBIG_UINT(entry
,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2385 /* the used disk space 8 bytes uint64_t */
2386 SBIG_UINT(entry
,16,qt
.usedspace
);
2388 /* the soft quotas 8 bytes uint64_t */
2389 SBIG_UINT(entry
,24,qt
.softlim
);
2391 /* the hard quotas 8 bytes uint64_t */
2392 SBIG_UINT(entry
,32,qt
.hardlim
);
2394 /* and now the SID */
2395 sid_linearize(entry
+40, sid_len
, &sid
);
2400 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp
->fnum
,level
));
2401 reply_doserror(req
, ERRSRV
, ERRerror
);
2406 send_nt_replies(conn
, req
, nt_status
, params
, param_len
,
2410 /****************************************************************************
2411 Reply to set user quota
2412 ****************************************************************************/
2414 static void call_nt_transact_set_user_quota(connection_struct
*conn
,
2415 struct smb_request
*req
,
2419 uint32 parameter_count
,
2422 uint32 max_data_count
)
2424 char *params
= *ppparams
;
2425 char *pdata
= *ppdata
;
2426 int data_len
=0,param_len
=0;
2427 SMB_NTQUOTA_STRUCT qt
;
2430 files_struct
*fsp
= NULL
;
2435 if (conn
->server_info
->utok
.uid
!= 0) {
2436 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2437 "[%s]\n", lp_servicename(SNUM(conn
)),
2438 conn
->server_info
->unix_name
));
2439 reply_doserror(req
, ERRDOS
, ERRnoaccess
);
2444 * Ensure minimum number of parameters sent.
2447 if (parameter_count
< 2) {
2448 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count
));
2449 reply_doserror(req
, ERRDOS
, ERRinvalidparam
);
2453 /* maybe we can check the quota_fnum */
2454 fsp
= file_fsp(req
, SVAL(params
,0));
2455 if (!check_fsp_ntquota_handle(conn
, req
, fsp
)) {
2456 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2457 reply_nterror(req
, NT_STATUS_INVALID_HANDLE
);
2461 if (data_count
< 40) {
2462 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count
,40));
2463 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2467 /* offset to next quota record.
2468 * 4 bytes IVAL(pdata,0)
2473 sid_len
= IVAL(pdata
,4);
2475 if (data_count
< 40+sid_len
) {
2476 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count
,(unsigned long)40+sid_len
));
2477 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2481 /* unknown 8 bytes in pdata
2482 * maybe its the change time in NTTIME
2485 /* the used space 8 bytes (uint64_t)*/
2486 qt
.usedspace
= (uint64_t)IVAL(pdata
,16);
2487 #ifdef LARGE_SMB_OFF_T
2488 qt
.usedspace
|= (((uint64_t)IVAL(pdata
,20)) << 32);
2489 #else /* LARGE_SMB_OFF_T */
2490 if ((IVAL(pdata
,20) != 0)&&
2491 ((qt
.usedspace
!= 0xFFFFFFFF)||
2492 (IVAL(pdata
,20)!=0xFFFFFFFF))) {
2493 /* more than 32 bits? */
2494 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2497 #endif /* LARGE_SMB_OFF_T */
2499 /* the soft quotas 8 bytes (uint64_t)*/
2500 qt
.softlim
= (uint64_t)IVAL(pdata
,24);
2501 #ifdef LARGE_SMB_OFF_T
2502 qt
.softlim
|= (((uint64_t)IVAL(pdata
,28)) << 32);
2503 #else /* LARGE_SMB_OFF_T */
2504 if ((IVAL(pdata
,28) != 0)&&
2505 ((qt
.softlim
!= 0xFFFFFFFF)||
2506 (IVAL(pdata
,28)!=0xFFFFFFFF))) {
2507 /* more than 32 bits? */
2508 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2511 #endif /* LARGE_SMB_OFF_T */
2513 /* the hard quotas 8 bytes (uint64_t)*/
2514 qt
.hardlim
= (uint64_t)IVAL(pdata
,32);
2515 #ifdef LARGE_SMB_OFF_T
2516 qt
.hardlim
|= (((uint64_t)IVAL(pdata
,36)) << 32);
2517 #else /* LARGE_SMB_OFF_T */
2518 if ((IVAL(pdata
,36) != 0)&&
2519 ((qt
.hardlim
!= 0xFFFFFFFF)||
2520 (IVAL(pdata
,36)!=0xFFFFFFFF))) {
2521 /* more than 32 bits? */
2522 reply_doserror(req
, ERRDOS
, ERRunknownlevel
);
2525 #endif /* LARGE_SMB_OFF_T */
2527 if (!sid_parse(pdata
+40,sid_len
,&sid
)) {
2528 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2532 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid
)));
2534 /* 44 unknown bytes left... */
2536 if (vfs_set_ntquota(fsp
, SMB_USER_QUOTA_TYPE
, &sid
, &qt
)!=0) {
2537 reply_doserror(req
, ERRSRV
, ERRerror
);
2541 send_nt_replies(conn
, req
, NT_STATUS_OK
, params
, param_len
,
2544 #endif /* HAVE_SYS_QUOTAS */
2546 static void handle_nttrans(connection_struct
*conn
,
2547 struct trans_state
*state
,
2548 struct smb_request
*req
)
2550 if (Protocol
>= PROTOCOL_NT1
) {
2551 req
->flags2
|= 0x40; /* IS_LONG_NAME */
2552 SSVAL(req
->inbuf
,smb_flg2
,req
->flags2
);
2556 SMB_PERFCOUNT_SET_SUBOP(&req
->pcd
, state
->call
);
2558 /* Now we must call the relevant NT_TRANS function */
2559 switch(state
->call
) {
2560 case NT_TRANSACT_CREATE
:
2562 START_PROFILE(NT_transact_create
);
2563 call_nt_transact_create(
2565 &state
->setup
, state
->setup_count
,
2566 &state
->param
, state
->total_param
,
2567 &state
->data
, state
->total_data
,
2568 state
->max_data_return
);
2569 END_PROFILE(NT_transact_create
);
2573 case NT_TRANSACT_IOCTL
:
2575 START_PROFILE(NT_transact_ioctl
);
2576 call_nt_transact_ioctl(
2578 &state
->setup
, state
->setup_count
,
2579 &state
->param
, state
->total_param
,
2580 &state
->data
, state
->total_data
,
2581 state
->max_data_return
);
2582 END_PROFILE(NT_transact_ioctl
);
2586 case NT_TRANSACT_SET_SECURITY_DESC
:
2588 START_PROFILE(NT_transact_set_security_desc
);
2589 call_nt_transact_set_security_desc(
2591 &state
->setup
, state
->setup_count
,
2592 &state
->param
, state
->total_param
,
2593 &state
->data
, state
->total_data
,
2594 state
->max_data_return
);
2595 END_PROFILE(NT_transact_set_security_desc
);
2599 case NT_TRANSACT_NOTIFY_CHANGE
:
2601 START_PROFILE(NT_transact_notify_change
);
2602 call_nt_transact_notify_change(
2604 &state
->setup
, state
->setup_count
,
2605 &state
->param
, state
->total_param
,
2606 &state
->data
, state
->total_data
,
2607 state
->max_data_return
,
2608 state
->max_param_return
);
2609 END_PROFILE(NT_transact_notify_change
);
2613 case NT_TRANSACT_RENAME
:
2615 START_PROFILE(NT_transact_rename
);
2616 call_nt_transact_rename(
2618 &state
->setup
, state
->setup_count
,
2619 &state
->param
, state
->total_param
,
2620 &state
->data
, state
->total_data
,
2621 state
->max_data_return
);
2622 END_PROFILE(NT_transact_rename
);
2626 case NT_TRANSACT_QUERY_SECURITY_DESC
:
2628 START_PROFILE(NT_transact_query_security_desc
);
2629 call_nt_transact_query_security_desc(
2631 &state
->setup
, state
->setup_count
,
2632 &state
->param
, state
->total_param
,
2633 &state
->data
, state
->total_data
,
2634 state
->max_data_return
);
2635 END_PROFILE(NT_transact_query_security_desc
);
2639 #ifdef HAVE_SYS_QUOTAS
2640 case NT_TRANSACT_GET_USER_QUOTA
:
2642 START_PROFILE(NT_transact_get_user_quota
);
2643 call_nt_transact_get_user_quota(
2645 &state
->setup
, state
->setup_count
,
2646 &state
->param
, state
->total_param
,
2647 &state
->data
, state
->total_data
,
2648 state
->max_data_return
);
2649 END_PROFILE(NT_transact_get_user_quota
);
2653 case NT_TRANSACT_SET_USER_QUOTA
:
2655 START_PROFILE(NT_transact_set_user_quota
);
2656 call_nt_transact_set_user_quota(
2658 &state
->setup
, state
->setup_count
,
2659 &state
->param
, state
->total_param
,
2660 &state
->data
, state
->total_data
,
2661 state
->max_data_return
);
2662 END_PROFILE(NT_transact_set_user_quota
);
2665 #endif /* HAVE_SYS_QUOTAS */
2668 /* Error in request */
2669 DEBUG(0,("handle_nttrans: Unknown request %d in "
2670 "nttrans call\n", state
->call
));
2671 reply_doserror(req
, ERRSRV
, ERRerror
);
2677 /****************************************************************************
2678 Reply to a SMBNTtrans.
2679 ****************************************************************************/
2681 void reply_nttrans(struct smb_request
*req
)
2683 connection_struct
*conn
= req
->conn
;
2688 uint16 function_code
;
2690 struct trans_state
*state
;
2692 START_PROFILE(SMBnttrans
);
2694 if (req
->wct
< 19) {
2695 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2696 END_PROFILE(SMBnttrans
);
2700 pscnt
= IVAL(req
->vwv
+9, 1);
2701 psoff
= IVAL(req
->vwv
+11, 1);
2702 dscnt
= IVAL(req
->vwv
+13, 1);
2703 dsoff
= IVAL(req
->vwv
+15, 1);
2704 function_code
= SVAL(req
->vwv
+18, 0);
2706 if (IS_IPC(conn
) && (function_code
!= NT_TRANSACT_CREATE
)) {
2707 reply_doserror(req
, ERRSRV
, ERRaccess
);
2708 END_PROFILE(SMBnttrans
);
2712 result
= allow_new_trans(conn
->pending_trans
, req
->mid
);
2713 if (!NT_STATUS_IS_OK(result
)) {
2714 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result
)));
2715 reply_nterror(req
, result
);
2716 END_PROFILE(SMBnttrans
);
2720 if ((state
= TALLOC_P(conn
, struct trans_state
)) == NULL
) {
2721 reply_doserror(req
, ERRSRV
, ERRaccess
);
2722 END_PROFILE(SMBnttrans
);
2726 state
->cmd
= SMBnttrans
;
2728 state
->mid
= req
->mid
;
2729 state
->vuid
= req
->vuid
;
2730 state
->total_data
= IVAL(req
->vwv
+3, 1);
2732 state
->total_param
= IVAL(req
->vwv
+1, 1);
2733 state
->param
= NULL
;
2734 state
->max_data_return
= IVAL(req
->vwv
+7, 1);
2735 state
->max_param_return
= IVAL(req
->vwv
+5, 1);
2737 /* setup count is in *words* */
2738 state
->setup_count
= 2*CVAL(req
->vwv
+17, 1);
2739 state
->setup
= NULL
;
2740 state
->call
= function_code
;
2742 DEBUG(10, ("num_setup=%u, "
2743 "param_total=%u, this_param=%u, max_param=%u, "
2744 "data_total=%u, this_data=%u, max_data=%u, "
2745 "param_offset=%u, data_offset=%u\n",
2746 (unsigned)state
->setup_count
,
2747 (unsigned)state
->total_param
, (unsigned)pscnt
,
2748 (unsigned)state
->max_param_return
,
2749 (unsigned)state
->total_data
, (unsigned)dscnt
,
2750 (unsigned)state
->max_data_return
,
2751 (unsigned)psoff
, (unsigned)dsoff
));
2754 * All nttrans messages we handle have smb_wct == 19 +
2755 * state->setup_count. Ensure this is so as a sanity check.
2758 if(req
->wct
!= 19 + (state
->setup_count
/2)) {
2759 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2760 req
->wct
, 19 + (state
->setup_count
/2)));
2764 /* Don't allow more than 128mb for each value. */
2765 if ((state
->total_data
> (1024*1024*128)) ||
2766 (state
->total_param
> (1024*1024*128))) {
2767 reply_doserror(req
, ERRDOS
, ERRnomem
);
2768 END_PROFILE(SMBnttrans
);
2772 if ((dscnt
> state
->total_data
) || (pscnt
> state
->total_param
))
2775 if (state
->total_data
) {
2777 if (trans_oob(state
->total_data
, 0, dscnt
)
2778 || trans_oob(smb_len(req
->inbuf
), dsoff
, dscnt
)) {
2782 /* Can't use talloc here, the core routines do realloc on the
2783 * params and data. */
2784 if ((state
->data
= (char *)SMB_MALLOC(state
->total_data
)) == NULL
) {
2785 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2786 "bytes !\n", (unsigned int)state
->total_data
));
2788 reply_doserror(req
, ERRDOS
, ERRnomem
);
2789 END_PROFILE(SMBnttrans
);
2793 memcpy(state
->data
,smb_base(req
->inbuf
)+dsoff
,dscnt
);
2796 if (state
->total_param
) {
2798 if (trans_oob(state
->total_param
, 0, pscnt
)
2799 || trans_oob(smb_len(req
->inbuf
), psoff
, pscnt
)) {
2803 /* Can't use talloc here, the core routines do realloc on the
2804 * params and data. */
2805 if ((state
->param
= (char *)SMB_MALLOC(state
->total_param
)) == NULL
) {
2806 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2807 "bytes !\n", (unsigned int)state
->total_param
));
2808 SAFE_FREE(state
->data
);
2810 reply_doserror(req
, ERRDOS
, ERRnomem
);
2811 END_PROFILE(SMBnttrans
);
2815 memcpy(state
->param
,smb_base(req
->inbuf
)+psoff
,pscnt
);
2818 state
->received_data
= dscnt
;
2819 state
->received_param
= pscnt
;
2821 if(state
->setup_count
> 0) {
2822 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2823 state
->setup_count
));
2826 * No overflow possible here, state->setup_count is an
2827 * unsigned int, being filled by a single byte from
2828 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2829 * below is not necessary, it's here to clarify things. The
2830 * validity of req->vwv and req->wct has been checked in
2831 * init_smb_request already.
2833 if ((state
->setup_count
/2) + 19 > (unsigned int)req
->wct
) {
2837 state
->setup
= (uint16
*)TALLOC(state
, state
->setup_count
);
2838 if (state
->setup
== NULL
) {
2839 DEBUG(0,("reply_nttrans : Out of memory\n"));
2840 SAFE_FREE(state
->data
);
2841 SAFE_FREE(state
->param
);
2843 reply_doserror(req
, ERRDOS
, ERRnomem
);
2844 END_PROFILE(SMBnttrans
);
2848 memcpy(state
->setup
, req
->vwv
+19, state
->setup_count
);
2849 dump_data(10, (uint8
*)state
->setup
, state
->setup_count
);
2852 if ((state
->received_data
== state
->total_data
) &&
2853 (state
->received_param
== state
->total_param
)) {
2854 handle_nttrans(conn
, state
, req
);
2855 SAFE_FREE(state
->param
);
2856 SAFE_FREE(state
->data
);
2858 END_PROFILE(SMBnttrans
);
2862 DLIST_ADD(conn
->pending_trans
, state
);
2864 /* We need to send an interim response then receive the rest
2865 of the parameter/data bytes */
2866 reply_outbuf(req
, 0, 0);
2867 show_msg((char *)req
->outbuf
);
2868 END_PROFILE(SMBnttrans
);
2873 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2874 SAFE_FREE(state
->data
);
2875 SAFE_FREE(state
->param
);
2877 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2878 END_PROFILE(SMBnttrans
);
2882 /****************************************************************************
2883 Reply to a SMBnttranss
2884 ****************************************************************************/
2886 void reply_nttranss(struct smb_request
*req
)
2888 connection_struct
*conn
= req
->conn
;
2889 uint32_t pcnt
,poff
,dcnt
,doff
,pdisp
,ddisp
;
2890 struct trans_state
*state
;
2892 START_PROFILE(SMBnttranss
);
2894 show_msg((char *)req
->inbuf
);
2896 if (req
->wct
< 18) {
2897 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2898 END_PROFILE(SMBnttranss
);
2902 for (state
= conn
->pending_trans
; state
!= NULL
;
2903 state
= state
->next
) {
2904 if (state
->mid
== req
->mid
) {
2909 if ((state
== NULL
) || (state
->cmd
!= SMBnttrans
)) {
2910 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2911 END_PROFILE(SMBnttranss
);
2915 /* Revise state->total_param and state->total_data in case they have
2916 changed downwards */
2917 if (IVAL(req
->vwv
+1, 1) < state
->total_param
) {
2918 state
->total_param
= IVAL(req
->vwv
+1, 1);
2920 if (IVAL(req
->vwv
+3, 1) < state
->total_data
) {
2921 state
->total_data
= IVAL(req
->vwv
+3, 1);
2924 pcnt
= IVAL(req
->vwv
+5, 1);
2925 poff
= IVAL(req
->vwv
+7, 1);
2926 pdisp
= IVAL(req
->vwv
+9, 1);
2928 dcnt
= IVAL(req
->vwv
+11, 1);
2929 doff
= IVAL(req
->vwv
+13, 1);
2930 ddisp
= IVAL(req
->vwv
+15, 1);
2932 state
->received_param
+= pcnt
;
2933 state
->received_data
+= dcnt
;
2935 if ((state
->received_data
> state
->total_data
) ||
2936 (state
->received_param
> state
->total_param
))
2940 if (trans_oob(state
->total_param
, pdisp
, pcnt
)
2941 || trans_oob(smb_len(req
->inbuf
), poff
, pcnt
)) {
2944 memcpy(state
->param
+pdisp
, smb_base(req
->inbuf
)+poff
,pcnt
);
2948 if (trans_oob(state
->total_data
, ddisp
, dcnt
)
2949 || trans_oob(smb_len(req
->inbuf
), doff
, dcnt
)) {
2952 memcpy(state
->data
+ddisp
, smb_base(req
->inbuf
)+doff
,dcnt
);
2955 if ((state
->received_param
< state
->total_param
) ||
2956 (state
->received_data
< state
->total_data
)) {
2957 END_PROFILE(SMBnttranss
);
2961 handle_nttrans(conn
, state
, req
);
2963 DLIST_REMOVE(conn
->pending_trans
, state
);
2964 SAFE_FREE(state
->data
);
2965 SAFE_FREE(state
->param
);
2967 END_PROFILE(SMBnttranss
);
2972 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2973 DLIST_REMOVE(conn
->pending_trans
, state
);
2974 SAFE_FREE(state
->data
);
2975 SAFE_FREE(state
->param
);
2977 reply_nterror(req
, NT_STATUS_INVALID_PARAMETER
);
2978 END_PROFILE(SMBnttranss
);