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;
61 struct smbd_server_connection *sconn = smbd_server_conn;
62 int max_send = sconn->smb1.sessions.max_send;
65 * If there genuinely are no parameters or data to send just send
69 if(params_to_send == 0 && data_to_send == 0) {
70 reply_outbuf(req, 18, 0);
71 show_msg((char *)req->outbuf);
76 * When sending params and data ensure that both are nicely aligned.
77 * Only do this alignment when there is also data to send - else
78 * can cause NT redirector problems.
81 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
82 data_alignment_offset = 4 - (params_to_send % 4);
86 * Space is bufsize minus Netbios over TCP header minus SMB header.
87 * The alignment_offset is to align the param bytes on a four byte
88 * boundary (2 bytes for data len, one byte pad).
89 * NT needs this to work correctly.
92 useable_space = max_send - (smb_size
95 + data_alignment_offset);
97 if (useable_space < 0) {
98 char *msg = talloc_asprintf(
100 "send_nt_replies failed sanity useable_space = %d!!!",
102 DEBUG(0, ("%s\n", msg));
103 exit_server_cleanly(msg);
106 while (params_to_send || data_to_send) {
109 * Calculate whether we will totally or partially fill this packet.
112 total_sent_thistime = params_to_send + data_to_send;
115 * We can never send more than useable_space.
118 total_sent_thistime = MIN(total_sent_thistime, useable_space);
120 reply_outbuf(req, 18,
121 total_sent_thistime + alignment_offset
122 + data_alignment_offset);
125 * We might have had SMBnttranss in req->inbuf, fix that.
127 SCVAL(req->outbuf, smb_com, SMBnttrans);
130 * Set total params and data to be sent.
133 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
134 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
137 * Calculate how many parameters and data we can fit into
138 * this packet. Parameters get precedence.
141 params_sent_thistime = MIN(params_to_send,useable_space);
142 data_sent_thistime = useable_space - params_sent_thistime;
143 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
145 SIVAL(req->outbuf, smb_ntr_ParameterCount,
146 params_sent_thistime);
148 if(params_sent_thistime == 0) {
149 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
150 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
153 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
154 * parameter bytes, however the first 4 bytes of outbuf are
155 * the Netbios over TCP header. Thus use smb_base() to subtract
156 * them from the calculation.
159 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
160 ((smb_buf(req->outbuf)+alignment_offset)
161 - smb_base(req->outbuf)));
163 * Absolute displacement of param bytes sent in this packet.
166 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
171 * Deal with the data portion.
174 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
176 if(data_sent_thistime == 0) {
177 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
178 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
181 * The offset of the data bytes is the offset of the
182 * parameter bytes plus the number of parameters being sent this time.
185 SIVAL(req->outbuf, smb_ntr_DataOffset,
186 ((smb_buf(req->outbuf)+alignment_offset) -
187 smb_base(req->outbuf))
188 + params_sent_thistime + data_alignment_offset);
189 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
193 * Copy the param bytes into the packet.
196 if(params_sent_thistime) {
197 if (alignment_offset != 0) {
198 memset(smb_buf(req->outbuf), 0,
201 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
202 params_sent_thistime);
206 * Copy in the data bytes
209 if(data_sent_thistime) {
210 if (data_alignment_offset != 0) {
211 memset((smb_buf(req->outbuf)+alignment_offset+
212 params_sent_thistime), 0,
213 data_alignment_offset);
215 memcpy(smb_buf(req->outbuf)+alignment_offset
216 +params_sent_thistime+data_alignment_offset,
217 pd,data_sent_thistime);
220 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
221 params_sent_thistime, data_sent_thistime, useable_space));
222 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
223 params_to_send, data_to_send, paramsize, datasize));
225 if (NT_STATUS_V(nt_error)) {
226 error_packet_set((char *)req->outbuf,
231 /* Send the packet */
232 show_msg((char *)req->outbuf);
233 if (!srv_send_smb(smbd_server_fd(),
236 IS_CONN_ENCRYPTED(conn),
238 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
241 TALLOC_FREE(req->outbuf);
243 pp += params_sent_thistime;
244 pd += data_sent_thistime;
246 params_to_send -= params_sent_thistime;
247 data_to_send -= data_sent_thistime;
253 if(params_to_send < 0 || data_to_send < 0) {
254 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
255 params_to_send, data_to_send));
256 exit_server_cleanly("send_nt_replies: internal error");
261 /****************************************************************************
262 Is it an NTFS stream name ?
263 An NTFS file name is <path>.<extention>:<stream name>:<stream type>
264 $DATA can be used as both a stream name and a stream type. A missing stream
265 name or type implies $DATA.
267 Both Windows stream names and POSIX files can contain the ':' character.
268 This function first checks for the existence of a colon in the last component
269 of the given name. If the name contains a colon we differentiate between a
270 stream and POSIX file by checking if the latter exists through a POSIX stat.
272 Function assumes we've already chdir() to the "root" directory of fname.
273 ****************************************************************************/
275 bool is_ntfs_stream_name(const char *fname)
277 const char *lastcomp;
278 SMB_STRUCT_STAT sbuf;
280 /* If all pathnames are treated as POSIX we ignore streams. */
281 if (lp_posix_pathnames()) {
285 /* Find the last component of the name. */
286 if ((lastcomp = strrchr_m(fname, '/')) != NULL)
291 /* If there is no colon in the last component, it's not a stream. */
292 if (strchr_m(lastcomp, ':') == NULL)
296 * If file already exists on disk, it's not a stream. The stat must
297 * bypass the vfs layer so streams modules don't intefere.
299 if (sys_stat(fname, &sbuf) == 0) {
300 DEBUG(5, ("is_ntfs_stream_name: file %s contains a ':' but is "
301 "not a stream\n", fname));
308 /****************************************************************************
309 Reply to an NT create and X call on a pipe
310 ****************************************************************************/
312 static void nt_open_pipe(char *fname, connection_struct *conn,
313 struct smb_request *req, int *ppnum)
318 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
320 /* Strip \\ off the name. */
323 status = open_np_file(req, fname, &fsp);
324 if (!NT_STATUS_IS_OK(status)) {
325 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
326 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
330 reply_nterror(req, status);
338 /****************************************************************************
339 Reply to an NT create and X call for pipes.
340 ****************************************************************************/
342 static void do_ntcreate_pipe_open(connection_struct *conn,
343 struct smb_request *req)
348 uint32 flags = IVAL(req->vwv+3, 1);
349 TALLOC_CTX *ctx = talloc_tos();
351 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
354 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
358 nt_open_pipe(fname, conn, req, &pnum);
366 * Deal with pipe return.
369 if (flags & EXTENDED_RESPONSE_REQUIRED) {
370 /* This is very strange. We
371 * return 50 words, but only set
372 * the wcnt to 42 ? It's definately
373 * what happens on the wire....
375 reply_outbuf(req, 50, 0);
376 SCVAL(req->outbuf,smb_wct,42);
378 reply_outbuf(req, 34, 0);
381 p = (char *)req->outbuf + smb_vwv2;
385 SIVAL(p,0,FILE_WAS_OPENED);
388 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
391 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
393 SSVAL(p,2, 0x5FF); /* ? */
396 if (flags & EXTENDED_RESPONSE_REQUIRED) {
398 SIVAL(p,0,FILE_GENERIC_ALL);
400 * For pipes W2K3 seems to return
402 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
404 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
407 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
412 /****************************************************************************
413 Reply to an NT create and X call.
414 ****************************************************************************/
416 void reply_ntcreate_and_X(struct smb_request *req)
418 connection_struct *conn = req->conn;
419 struct smb_filename *smb_fname = NULL;
423 uint32 file_attributes;
425 uint32 create_disposition;
426 uint32 create_options;
428 uint64_t allocation_size;
429 /* Breakout the oplock request bits so we can set the
430 reply bits separately. */
432 SMB_OFF_T file_len = 0;
434 files_struct *fsp = NULL;
436 struct timespec c_timespec;
437 struct timespec a_timespec;
438 struct timespec m_timespec;
441 uint8_t oplock_granted = NO_OPLOCK_RETURN;
442 TALLOC_CTX *ctx = talloc_tos();
444 START_PROFILE(SMBntcreateX);
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);
472 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
473 "file_attributes = 0x%x, share_access = 0x%x, "
474 "create_disposition = 0x%x create_options = 0x%x "
475 "root_dir_fid = 0x%x, fname = %s\n",
477 (unsigned int)access_mask,
478 (unsigned int)file_attributes,
479 (unsigned int)share_access,
480 (unsigned int)create_disposition,
481 (unsigned int)create_options,
482 (unsigned int)root_dir_fid,
486 * we need to remove ignored bits when they come directly from the client
487 * because we reuse some of them for internal stuff
489 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
492 * If it's an IPC, use the pipe handler.
496 if (lp_nt_pipe_support()) {
497 do_ntcreate_pipe_open(conn, req);
500 reply_doserror(req, ERRDOS, ERRnoaccess);
504 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
505 if (oplock_request) {
506 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
510 status = unix_convert(ctx, conn, fname, &smb_fname, 0);
511 if (!NT_STATUS_IS_OK(status)) {
512 reply_nterror(req, status);
516 status = get_full_smb_filename(ctx, smb_fname, &fname);
517 if (!NT_STATUS_IS_OK(status)) {
518 reply_nterror(req, status);
522 status = SMB_VFS_CREATE_FILE(
525 root_dir_fid, /* root_dir_fid */
527 0, /* create_file_flags */
528 access_mask, /* access_mask */
529 share_access, /* share_access */
530 create_disposition, /* create_disposition*/
531 create_options, /* create_options */
532 file_attributes, /* file_attributes */
533 oplock_request, /* oplock_request */
534 allocation_size, /* allocation_size */
539 &smb_fname->st); /* psbuf */
541 if (!NT_STATUS_IS_OK(status)) {
542 if (open_was_deferred(req->mid)) {
543 /* We have re-scheduled this call, no error. */
546 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
547 reply_botherror(req, status, ERRDOS, ERRfilexists);
550 reply_nterror(req, status);
556 * If the caller set the extended oplock request bit
557 * and we granted one (by whatever means) - set the
558 * correct bit for extended oplock reply.
561 if (oplock_request &&
562 (lp_fake_oplocks(SNUM(conn))
563 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
566 * Exclusive oplock granted
569 if (flags & REQUEST_BATCH_OPLOCK) {
570 oplock_granted = BATCH_OPLOCK_RETURN;
572 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
574 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
575 oplock_granted = LEVEL_II_OPLOCK_RETURN;
577 oplock_granted = NO_OPLOCK_RETURN;
580 file_len = smb_fname->st.st_ex_size;
581 fattr = dos_mode(conn,fsp->fsp_name,&smb_fname->st);
583 fattr = FILE_ATTRIBUTE_NORMAL;
586 if (flags & EXTENDED_RESPONSE_REQUIRED) {
587 /* This is very strange. We
588 * return 50 words, but only set
589 * the wcnt to 42 ? It's definately
590 * what happens on the wire....
592 reply_outbuf(req, 50, 0);
593 SCVAL(req->outbuf,smb_wct,42);
595 reply_outbuf(req, 34, 0);
598 p = (char *)req->outbuf + smb_vwv2;
600 SCVAL(p, 0, oplock_granted);
603 SSVAL(p,0,fsp->fnum);
605 if ((create_disposition == FILE_SUPERSEDE)
606 && (info == FILE_WAS_OVERWRITTEN)) {
607 SIVAL(p,0,FILE_WAS_SUPERSEDED);
614 c_timespec = smb_fname->st.st_ex_btime;
615 a_timespec = smb_fname->st.st_ex_atime;
616 m_timespec = smb_fname->st.st_ex_mtime;
618 if (lp_dos_filetime_resolution(SNUM(conn))) {
619 dos_filetime_timespec(&c_timespec);
620 dos_filetime_timespec(&a_timespec);
621 dos_filetime_timespec(&m_timespec);
624 put_long_date_timespec(p, c_timespec); /* create time. */
626 put_long_date_timespec(p, a_timespec); /* access time */
628 put_long_date_timespec(p, m_timespec); /* write time */
630 put_long_date_timespec(p, m_timespec); /* change time */
632 SIVAL(p,0,fattr); /* File Attributes. */
634 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
636 SOFF_T(p,0,file_len);
638 if (flags & EXTENDED_RESPONSE_REQUIRED) {
642 SCVAL(p,0,fsp->is_directory ? 1 : 0);
644 if (flags & EXTENDED_RESPONSE_REQUIRED) {
647 if (fsp->is_directory ||
648 can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
649 perms = FILE_GENERIC_ALL;
651 perms = FILE_GENERIC_READ|FILE_EXECUTE;
656 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
657 fsp->fnum, fsp->fsp_name));
661 TALLOC_FREE(smb_fname);
662 END_PROFILE(SMBntcreateX);
666 /****************************************************************************
667 Reply to a NT_TRANSACT_CREATE call to open a pipe.
668 ****************************************************************************/
670 static void do_nt_transact_create_pipe(connection_struct *conn,
671 struct smb_request *req,
672 uint16 **ppsetup, uint32 setup_count,
673 char **ppparams, uint32 parameter_count,
674 char **ppdata, uint32 data_count)
677 char *params = *ppparams;
683 TALLOC_CTX *ctx = talloc_tos();
686 * Ensure minimum number of parameters sent.
689 if(parameter_count < 54) {
690 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
691 reply_doserror(req, ERRDOS, ERRnoaccess);
695 flags = IVAL(params,0);
697 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
698 parameter_count-53, STR_TERMINATE,
700 if (!NT_STATUS_IS_OK(status)) {
701 reply_nterror(req, status);
705 nt_open_pipe(fname, conn, req, &pnum);
712 /* Realloc the size of parameters and data we will return */
713 if (flags & EXTENDED_RESPONSE_REQUIRED) {
714 /* Extended response is 32 more byyes. */
719 params = nttrans_realloc(ppparams, param_len);
721 reply_doserror(req, ERRDOS, ERRnomem);
726 SCVAL(p,0,NO_OPLOCK_RETURN);
731 SIVAL(p,0,FILE_WAS_OPENED);
735 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
738 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
740 SSVAL(p,2, 0x5FF); /* ? */
743 if (flags & EXTENDED_RESPONSE_REQUIRED) {
745 SIVAL(p,0,FILE_GENERIC_ALL);
747 * For pipes W2K3 seems to return
749 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
751 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
754 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
756 /* Send the required number of replies */
757 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
762 /****************************************************************************
763 Internal fn to set security descriptors.
764 ****************************************************************************/
766 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
767 uint32 security_info_sent)
769 SEC_DESC *psd = NULL;
772 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
776 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
778 if (!NT_STATUS_IS_OK(status)) {
782 if (psd->owner_sid == NULL) {
783 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
785 if (psd->group_sid == NULL) {
786 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
789 /* Convert all the generic bits. */
790 security_acl_map_generic(psd->dacl, &file_generic_mapping);
791 security_acl_map_generic(psd->sacl, &file_generic_mapping);
793 if (DEBUGLEVEL >= 10) {
794 DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
795 NDR_PRINT_DEBUG(security_descriptor, psd);
798 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
805 /****************************************************************************
806 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
807 ****************************************************************************/
809 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
811 struct ea_list *ea_list_head = NULL;
818 while (offset + 4 <= data_size) {
819 size_t next_offset = IVAL(pdata,offset);
820 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
826 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
827 if (next_offset == 0) {
830 offset += next_offset;
836 /****************************************************************************
837 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
838 ****************************************************************************/
840 static void call_nt_transact_create(connection_struct *conn,
841 struct smb_request *req,
842 uint16 **ppsetup, uint32 setup_count,
843 char **ppparams, uint32 parameter_count,
844 char **ppdata, uint32 data_count,
845 uint32 max_data_count)
847 struct smb_filename *smb_fname = NULL;
849 char *params = *ppparams;
850 char *data = *ppdata;
851 /* Breakout the oplock request bits so we can set the reply bits separately. */
853 SMB_OFF_T file_len = 0;
855 files_struct *fsp = NULL;
859 uint32 file_attributes;
861 uint32 create_disposition;
862 uint32 create_options;
864 struct security_descriptor *sd = NULL;
867 struct timespec c_timespec;
868 struct timespec a_timespec;
869 struct timespec m_timespec;
870 struct ea_list *ea_list = NULL;
873 uint64_t allocation_size;
875 uint8_t oplock_granted;
876 TALLOC_CTX *ctx = talloc_tos();
878 DEBUG(5,("call_nt_transact_create\n"));
881 * If it's an IPC, use the pipe handler.
885 if (lp_nt_pipe_support()) {
886 do_nt_transact_create_pipe(
888 ppsetup, setup_count,
889 ppparams, parameter_count,
893 reply_doserror(req, ERRDOS, ERRnoaccess);
898 * Ensure minimum number of parameters sent.
901 if(parameter_count < 54) {
902 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
903 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
907 flags = IVAL(params,0);
908 access_mask = IVAL(params,8);
909 file_attributes = IVAL(params,20);
910 share_access = IVAL(params,24);
911 create_disposition = IVAL(params,28);
912 create_options = IVAL(params,32);
913 sd_len = IVAL(params,36);
914 ea_len = IVAL(params,40);
915 root_dir_fid = (uint16)IVAL(params,4);
916 allocation_size = (uint64_t)IVAL(params,12);
917 #ifdef LARGE_SMB_OFF_T
918 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
922 * we need to remove ignored bits when they come directly from the client
923 * because we reuse some of them for internal stuff
925 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
927 /* Ensure the data_len is correct for the sd and ea values given. */
928 if ((ea_len + sd_len > data_count)
929 || (ea_len > data_count) || (sd_len > data_count)
930 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
931 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
932 "%u, data_count = %u\n", (unsigned int)ea_len,
933 (unsigned int)sd_len, (unsigned int)data_count));
934 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
939 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
942 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
944 if (!NT_STATUS_IS_OK(status)) {
945 DEBUG(10, ("call_nt_transact_create: "
946 "unmarshall_sec_desc failed: %s\n",
948 reply_nterror(req, status);
954 if (!lp_ea_support(SNUM(conn))) {
955 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
956 "EA's not supported.\n",
957 (unsigned int)ea_len));
958 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
963 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
964 "too small (should be more than 10)\n",
965 (unsigned int)ea_len ));
966 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
970 /* We have already checked that ea_len <= data_count here. */
971 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
973 if (ea_list == NULL) {
974 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
979 srvstr_get_path(ctx, params, req->flags2, &fname,
980 params+53, parameter_count-53,
981 STR_TERMINATE, &status);
982 if (!NT_STATUS_IS_OK(status)) {
983 reply_nterror(req, status);
987 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
988 if (oplock_request) {
989 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
993 status = unix_convert(ctx, conn, fname, &smb_fname, 0);
994 if (!NT_STATUS_IS_OK(status)) {
995 reply_nterror(req, status);
999 status = get_full_smb_filename(ctx, smb_fname, &fname);
1000 if (!NT_STATUS_IS_OK(status)) {
1001 reply_nterror(req, status);
1005 status = SMB_VFS_CREATE_FILE(
1008 root_dir_fid, /* root_dir_fid */
1010 0, /* create_file_flags */
1011 access_mask, /* access_mask */
1012 share_access, /* share_access */
1013 create_disposition, /* create_disposition*/
1014 create_options, /* create_options */
1015 file_attributes, /* file_attributes */
1016 oplock_request, /* oplock_request */
1017 allocation_size, /* allocation_size */
1019 ea_list, /* ea_list */
1022 &smb_fname->st); /* psbuf */
1024 if(!NT_STATUS_IS_OK(status)) {
1025 if (open_was_deferred(req->mid)) {
1026 /* We have re-scheduled this call, no error. */
1029 reply_openerror(req, status);
1034 * If the caller set the extended oplock request bit
1035 * and we granted one (by whatever means) - set the
1036 * correct bit for extended oplock reply.
1039 if (oplock_request &&
1040 (lp_fake_oplocks(SNUM(conn))
1041 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1044 * Exclusive oplock granted
1047 if (flags & REQUEST_BATCH_OPLOCK) {
1048 oplock_granted = BATCH_OPLOCK_RETURN;
1050 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1052 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1053 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1055 oplock_granted = NO_OPLOCK_RETURN;
1058 file_len = smb_fname->st.st_ex_size;
1059 fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
1061 fattr = FILE_ATTRIBUTE_NORMAL;
1064 /* Realloc the size of parameters and data we will return */
1065 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1066 /* Extended response is 32 more byyes. */
1071 params = nttrans_realloc(ppparams, param_len);
1072 if(params == NULL) {
1073 reply_doserror(req, ERRDOS, ERRnomem);
1078 SCVAL(p, 0, oplock_granted);
1081 SSVAL(p,0,fsp->fnum);
1083 if ((create_disposition == FILE_SUPERSEDE)
1084 && (info == FILE_WAS_OVERWRITTEN)) {
1085 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1092 c_timespec = smb_fname->st.st_ex_btime;
1093 a_timespec = smb_fname->st.st_ex_atime;
1094 m_timespec = smb_fname->st.st_ex_mtime;
1096 if (lp_dos_filetime_resolution(SNUM(conn))) {
1097 dos_filetime_timespec(&c_timespec);
1098 dos_filetime_timespec(&a_timespec);
1099 dos_filetime_timespec(&m_timespec);
1102 put_long_date_timespec(p, c_timespec); /* create time. */
1104 put_long_date_timespec(p, a_timespec); /* access time */
1106 put_long_date_timespec(p, m_timespec); /* write time */
1108 put_long_date_timespec(p, m_timespec); /* change time */
1110 SIVAL(p,0,fattr); /* File Attributes. */
1112 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1114 SOFF_T(p,0,file_len);
1116 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1120 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1122 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1125 if (fsp->is_directory ||
1126 can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
1127 perms = FILE_GENERIC_ALL;
1129 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1134 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp->fsp_name));
1136 /* Send the required number of replies */
1137 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1139 TALLOC_FREE(smb_fname);
1143 /****************************************************************************
1144 Reply to a NT CANCEL request.
1145 conn POINTER CAN BE NULL HERE !
1146 ****************************************************************************/
1148 void reply_ntcancel(struct smb_request *req)
1151 * Go through and cancel any pending change notifies.
1154 START_PROFILE(SMBntcancel);
1155 srv_cancel_sign_response(smbd_server_conn);
1156 remove_pending_change_notify_requests_by_mid(req->mid);
1157 remove_pending_lock_requests_by_mid(req->mid);
1159 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1161 END_PROFILE(SMBntcancel);
1165 /****************************************************************************
1167 ****************************************************************************/
1169 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1170 connection_struct *conn,
1171 struct smb_request *req,
1172 const char *oldname_in,
1173 const char *newname_in,
1176 struct smb_filename *smb_fname = NULL;
1177 struct smb_filename *smb_fname_new = NULL;
1178 char *oldname = NULL;
1179 char *newname = NULL;
1180 files_struct *fsp1,*fsp2;
1184 NTSTATUS status = NT_STATUS_OK;
1187 if (!CAN_WRITE(conn)) {
1188 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1192 status = unix_convert(ctx, conn, oldname_in, &smb_fname, 0);
1193 if (!NT_STATUS_IS_OK(status)) {
1197 status = get_full_smb_filename(ctx, smb_fname, &oldname);
1198 if (!NT_STATUS_IS_OK(status)) {
1202 status = check_name(conn, oldname);
1203 if (!NT_STATUS_IS_OK(status)) {
1207 /* Source must already exist. */
1208 if (!VALID_STAT(smb_fname->st)) {
1209 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1212 /* Ensure attributes match. */
1213 fattr = dos_mode(conn, oldname, &smb_fname->st);
1214 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1215 status = NT_STATUS_NO_SUCH_FILE;
1219 status = unix_convert(ctx, conn, newname_in, &smb_fname_new, 0);
1220 if (!NT_STATUS_IS_OK(status)) {
1224 status = get_full_smb_filename(ctx, smb_fname_new, &newname);
1225 if (!NT_STATUS_IS_OK(status)) {
1229 status = check_name(conn, newname);
1230 if (!NT_STATUS_IS_OK(status)) {
1234 /* Disallow if newname already exists. */
1235 if (VALID_STAT(smb_fname_new->st)) {
1236 status = NT_STATUS_OBJECT_NAME_COLLISION;
1240 /* No links from a directory. */
1241 if (S_ISDIR(smb_fname->st.st_ex_mode)) {
1242 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1246 /* Ensure this is within the share. */
1247 status = check_reduced_name(conn, oldname);
1248 if (!NT_STATUS_IS_OK(status)) {
1252 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1255 status = SMB_VFS_CREATE_FILE(
1258 0, /* root_dir_fid */
1259 oldname, /* fname */
1260 0, /* create_file_flags */
1261 FILE_READ_DATA, /* access_mask */
1262 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1264 FILE_OPEN, /* create_disposition*/
1265 0, /* create_options */
1266 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1267 NO_OPLOCK, /* oplock_request */
1268 0, /* allocation_size */
1273 &smb_fname->st); /* psbuf */
1275 if (!NT_STATUS_IS_OK(status)) {
1279 status = SMB_VFS_CREATE_FILE(
1282 0, /* root_dir_fid */
1283 newname, /* fname */
1284 0, /* create_file_flags */
1285 FILE_WRITE_DATA, /* access_mask */
1286 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1288 FILE_CREATE, /* create_disposition*/
1289 0, /* create_options */
1290 fattr, /* file_attributes */
1291 NO_OPLOCK, /* oplock_request */
1292 0, /* allocation_size */
1297 &smb_fname_new->st); /* psbuf */
1299 if (!NT_STATUS_IS_OK(status)) {
1300 close_file(NULL, fsp1, ERROR_CLOSE);
1304 if (smb_fname->st.st_ex_size) {
1305 ret = vfs_transfer_file(fsp1, fsp2, smb_fname->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->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(), newname, &parent, NULL)) {
1325 status = NT_STATUS_NO_MEMORY;
1328 file_set_dosmode(conn, newname, fattr, &smb_fname_new->st, parent,
1330 TALLOC_FREE(parent);
1332 if (ret < (SMB_OFF_T)smb_fname->st.st_ex_size) {
1333 status = NT_STATUS_DISK_FULL;
1337 TALLOC_FREE(smb_fname);
1338 TALLOC_FREE(smb_fname_new);
1339 if (!NT_STATUS_IS_OK(status)) {
1340 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1341 nt_errstr(status), oldname, newname));
1346 /****************************************************************************
1347 Reply to a NT rename request.
1348 ****************************************************************************/
1350 void reply_ntrename(struct smb_request *req)
1352 connection_struct *conn = req->conn;
1353 char *oldname = NULL;
1354 char *newname = NULL;
1357 bool src_has_wcard = False;
1358 bool dest_has_wcard = False;
1361 TALLOC_CTX *ctx = talloc_tos();
1363 START_PROFILE(SMBntrename);
1366 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1367 END_PROFILE(SMBntrename);
1371 attrs = SVAL(req->vwv+0, 0);
1372 rename_type = SVAL(req->vwv+1, 0);
1374 p = (const char *)req->buf + 1;
1375 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1376 &status, &src_has_wcard);
1377 if (!NT_STATUS_IS_OK(status)) {
1378 reply_nterror(req, status);
1379 END_PROFILE(SMBntrename);
1383 if (ms_has_wild(oldname)) {
1384 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1385 END_PROFILE(SMBntrename);
1390 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1391 &status, &dest_has_wcard);
1392 if (!NT_STATUS_IS_OK(status)) {
1393 reply_nterror(req, status);
1394 END_PROFILE(SMBntrename);
1398 status = resolve_dfspath(ctx, conn,
1399 req->flags2 & FLAGS2_DFS_PATHNAMES,
1402 if (!NT_STATUS_IS_OK(status)) {
1403 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1404 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1405 ERRSRV, ERRbadpath);
1406 END_PROFILE(SMBntrename);
1409 reply_nterror(req, status);
1410 END_PROFILE(SMBntrename);
1414 status = resolve_dfspath(ctx, conn,
1415 req->flags2 & FLAGS2_DFS_PATHNAMES,
1418 if (!NT_STATUS_IS_OK(status)) {
1419 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1420 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1421 ERRSRV, ERRbadpath);
1422 END_PROFILE(SMBntrename);
1425 reply_nterror(req, status);
1426 END_PROFILE(SMBntrename);
1430 /* The new name must begin with a ':' if the old name is a stream. */
1431 if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
1432 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1433 END_PROFILE(SMBntrename);
1437 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1439 switch(rename_type) {
1440 case RENAME_FLAG_RENAME:
1441 status = rename_internals(ctx, conn, req, oldname,
1442 newname, attrs, False, src_has_wcard,
1443 dest_has_wcard, DELETE_ACCESS);
1445 case RENAME_FLAG_HARD_LINK:
1446 if (src_has_wcard || dest_has_wcard) {
1448 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1450 status = hardlink_internals(ctx,
1456 case RENAME_FLAG_COPY:
1457 if (src_has_wcard || dest_has_wcard) {
1459 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1461 status = copy_internals(ctx, conn, req, oldname,
1465 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1466 status = NT_STATUS_INVALID_PARAMETER;
1469 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1473 if (!NT_STATUS_IS_OK(status)) {
1474 if (open_was_deferred(req->mid)) {
1475 /* We have re-scheduled this call. */
1476 END_PROFILE(SMBntrename);
1480 reply_nterror(req, status);
1481 END_PROFILE(SMBntrename);
1485 reply_outbuf(req, 0, 0);
1487 END_PROFILE(SMBntrename);
1491 /****************************************************************************
1492 Reply to a notify change - queue the request and
1493 don't allow a directory to be opened.
1494 ****************************************************************************/
1496 static void call_nt_transact_notify_change(connection_struct *conn,
1497 struct smb_request *req,
1501 uint32 parameter_count,
1502 char **ppdata, uint32 data_count,
1503 uint32 max_data_count,
1504 uint32 max_param_count)
1506 uint16 *setup = *ppsetup;
1512 if(setup_count < 6) {
1513 reply_doserror(req, ERRDOS, ERRbadfunc);
1517 fsp = file_fsp(req, SVAL(setup,4));
1518 filter = IVAL(setup, 0);
1519 recursive = (SVAL(setup, 6) != 0) ? True : False;
1521 DEBUG(3,("call_nt_transact_notify_change\n"));
1524 reply_doserror(req, ERRDOS, ERRbadfid);
1529 char *filter_string;
1531 if (!(filter_string = notify_filter_string(NULL, filter))) {
1532 reply_nterror(req,NT_STATUS_NO_MEMORY);
1536 DEBUG(3,("call_nt_transact_notify_change: notify change "
1537 "called on %s, filter = %s, recursive = %d\n",
1538 fsp->fsp_name, filter_string, recursive));
1540 TALLOC_FREE(filter_string);
1543 if((!fsp->is_directory) || (conn != fsp->conn)) {
1544 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1548 if (fsp->notify == NULL) {
1550 status = change_notify_create(fsp, filter, recursive);
1552 if (!NT_STATUS_IS_OK(status)) {
1553 DEBUG(10, ("change_notify_create returned %s\n",
1554 nt_errstr(status)));
1555 reply_nterror(req, status);
1560 if (fsp->notify->num_changes != 0) {
1563 * We've got changes pending, respond immediately
1567 * TODO: write a torture test to check the filtering behaviour
1571 change_notify_reply(fsp->conn, req, max_param_count,
1575 * change_notify_reply() above has independently sent its
1582 * No changes pending, queue the request
1585 status = change_notify_add_request(req,
1589 if (!NT_STATUS_IS_OK(status)) {
1590 reply_nterror(req, status);
1595 /****************************************************************************
1596 Reply to an NT transact rename command.
1597 ****************************************************************************/
1599 static void call_nt_transact_rename(connection_struct *conn,
1600 struct smb_request *req,
1601 uint16 **ppsetup, uint32 setup_count,
1602 char **ppparams, uint32 parameter_count,
1603 char **ppdata, uint32 data_count,
1604 uint32 max_data_count)
1606 char *params = *ppparams;
1607 char *new_name = NULL;
1608 files_struct *fsp = NULL;
1609 bool dest_has_wcard = False;
1611 TALLOC_CTX *ctx = talloc_tos();
1613 if(parameter_count < 5) {
1614 reply_doserror(req, ERRDOS, ERRbadfunc);
1618 fsp = file_fsp(req, SVAL(params, 0));
1619 if (!check_fsp(conn, req, fsp)) {
1622 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1623 parameter_count - 4,
1624 STR_TERMINATE, &status, &dest_has_wcard);
1625 if (!NT_STATUS_IS_OK(status)) {
1626 reply_nterror(req, status);
1631 * W2K3 ignores this request as the RAW-RENAME test
1632 * demonstrates, so we do.
1634 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1636 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1637 fsp->fsp_name, new_name));
1642 /******************************************************************************
1643 Fake up a completely empty SD.
1644 *******************************************************************************/
1646 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1650 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1652 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1653 return NT_STATUS_NO_MEMORY;
1656 return NT_STATUS_OK;
1659 /****************************************************************************
1660 Reply to query a security descriptor.
1661 ****************************************************************************/
1663 static void call_nt_transact_query_security_desc(connection_struct *conn,
1664 struct smb_request *req,
1668 uint32 parameter_count,
1671 uint32 max_data_count)
1673 char *params = *ppparams;
1674 char *data = *ppdata;
1675 SEC_DESC *psd = NULL;
1677 uint32 security_info_wanted;
1678 files_struct *fsp = NULL;
1682 if(parameter_count < 8) {
1683 reply_doserror(req, ERRDOS, ERRbadfunc);
1687 fsp = file_fsp(req, SVAL(params,0));
1689 reply_doserror(req, ERRDOS, ERRbadfid);
1693 security_info_wanted = IVAL(params,4);
1695 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1696 (unsigned int)security_info_wanted ));
1698 params = nttrans_realloc(ppparams, 4);
1699 if(params == NULL) {
1700 reply_doserror(req, ERRDOS, ERRnomem);
1705 * Get the permissions to return.
1708 if (!lp_nt_acl_support(SNUM(conn))) {
1709 status = get_null_nt_acl(talloc_tos(), &psd);
1711 status = SMB_VFS_FGET_NT_ACL(
1712 fsp, security_info_wanted, &psd);
1714 if (!NT_STATUS_IS_OK(status)) {
1715 reply_nterror(req, status);
1719 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1720 * present in the reply to match Windows behavior */
1721 if (psd->sacl == NULL &&
1722 security_info_wanted & SACL_SECURITY_INFORMATION)
1723 psd->type |= SEC_DESC_SACL_PRESENT;
1724 if (psd->dacl == NULL &&
1725 security_info_wanted & DACL_SECURITY_INFORMATION)
1726 psd->type |= SEC_DESC_DACL_PRESENT;
1728 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1730 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1732 if (DEBUGLEVEL >= 10) {
1733 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name));
1734 NDR_PRINT_DEBUG(security_descriptor, psd);
1737 SIVAL(params,0,(uint32)sd_size);
1739 if (max_data_count < sd_size) {
1740 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1741 params, 4, *ppdata, 0);
1746 * Allocate the data we will point this at.
1749 data = nttrans_realloc(ppdata, sd_size);
1751 reply_doserror(req, ERRDOS, ERRnomem);
1755 status = marshall_sec_desc(talloc_tos(), psd,
1756 &blob.data, &blob.length);
1758 if (!NT_STATUS_IS_OK(status)) {
1759 reply_nterror(req, status);
1763 SMB_ASSERT(sd_size == blob.length);
1764 memcpy(data, blob.data, sd_size);
1766 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1771 /****************************************************************************
1772 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1773 ****************************************************************************/
1775 static void call_nt_transact_set_security_desc(connection_struct *conn,
1776 struct smb_request *req,
1780 uint32 parameter_count,
1783 uint32 max_data_count)
1785 char *params= *ppparams;
1786 char *data = *ppdata;
1787 files_struct *fsp = NULL;
1788 uint32 security_info_sent = 0;
1791 if(parameter_count < 8) {
1792 reply_doserror(req, ERRDOS, ERRbadfunc);
1796 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1797 reply_doserror(req, ERRDOS, ERRbadfid);
1801 if(!lp_nt_acl_support(SNUM(conn))) {
1805 security_info_sent = IVAL(params,4);
1807 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1808 (unsigned int)security_info_sent ));
1810 if (data_count == 0) {
1811 reply_doserror(req, ERRDOS, ERRnoaccess);
1815 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1817 if (!NT_STATUS_IS_OK(status)) {
1818 reply_nterror(req, status);
1823 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1827 /****************************************************************************
1829 ****************************************************************************/
1831 static void call_nt_transact_ioctl(connection_struct *conn,
1832 struct smb_request *req,
1833 uint16 **ppsetup, uint32 setup_count,
1834 char **ppparams, uint32 parameter_count,
1835 char **ppdata, uint32 data_count,
1836 uint32 max_data_count)
1843 char *pdata = *ppdata;
1845 if (setup_count != 8) {
1846 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1847 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1851 function = IVAL(*ppsetup, 0);
1852 fidnum = SVAL(*ppsetup, 4);
1853 isFSctl = CVAL(*ppsetup, 6);
1854 compfilter = CVAL(*ppsetup, 7);
1856 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1857 function, fidnum, isFSctl, compfilter));
1859 fsp=file_fsp(req, fidnum);
1860 /* this check is done in each implemented function case for now
1861 because I don't want to break anything... --metze
1862 FSP_BELONGS_CONN(fsp,conn);*/
1864 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1867 case FSCTL_SET_SPARSE:
1868 /* pretend this succeeded - tho strictly we should
1869 mark the file sparse (if the local fs supports it)
1870 so we can know if we need to pre-allocate or not */
1872 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1873 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1876 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1878 unsigned char objid[16];
1880 /* This should return the object-id on this file.
1881 * I think I'll make this be the inode+dev. JRA.
1884 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1886 if (!fsp_belongs_conn(conn, req, fsp)) {
1891 pdata = nttrans_realloc(ppdata, data_count);
1892 if (pdata == NULL) {
1893 reply_nterror(req, NT_STATUS_NO_MEMORY);
1897 /* For backwards compatibility only store the dev/inode. */
1898 push_file_id_16(pdata, &fsp->file_id);
1899 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1900 push_file_id_16(pdata+32, &fsp->file_id);
1901 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1906 case FSCTL_GET_REPARSE_POINT:
1907 /* pretend this fail - my winXP does it like this
1911 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1912 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1915 case FSCTL_SET_REPARSE_POINT:
1916 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1920 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1921 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1924 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1927 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1928 * and return their volume names. If max_data_count is 16, then it is just
1929 * asking for the number of volumes and length of the combined names.
1931 * pdata is the data allocated by our caller, but that uses
1932 * total_data_count (which is 0 in our case) rather than max_data_count.
1933 * Allocate the correct amount and return the pointer to let
1934 * it be deallocated when we return.
1936 SHADOW_COPY_DATA *shadow_data = NULL;
1937 TALLOC_CTX *shadow_mem_ctx = NULL;
1938 bool labels = False;
1939 uint32 labels_data_count = 0;
1943 if (!fsp_belongs_conn(conn, req, fsp)) {
1947 if (max_data_count < 16) {
1948 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1950 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1954 if (max_data_count > 16) {
1958 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1959 if (shadow_mem_ctx == NULL) {
1960 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1961 reply_nterror(req, NT_STATUS_NO_MEMORY);
1965 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
1966 if (shadow_data == NULL) {
1967 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1968 talloc_destroy(shadow_mem_ctx);
1969 reply_nterror(req, NT_STATUS_NO_MEMORY);
1973 shadow_data->mem_ctx = shadow_mem_ctx;
1976 * Call the VFS routine to actually do the work.
1978 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1979 talloc_destroy(shadow_data->mem_ctx);
1980 if (errno == ENOSYS) {
1981 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1982 conn->connectpath));
1983 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1986 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1987 conn->connectpath));
1988 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
1993 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
1998 data_count = 12+labels_data_count+4;
2001 if (max_data_count<data_count) {
2002 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2003 max_data_count,data_count));
2004 talloc_destroy(shadow_data->mem_ctx);
2005 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2009 pdata = nttrans_realloc(ppdata, data_count);
2010 if (pdata == NULL) {
2011 talloc_destroy(shadow_data->mem_ctx);
2012 reply_nterror(req, NT_STATUS_NO_MEMORY);
2018 /* num_volumes 4 bytes */
2019 SIVAL(pdata,0,shadow_data->num_volumes);
2022 /* num_labels 4 bytes */
2023 SIVAL(pdata,4,shadow_data->num_volumes);
2026 /* needed_data_count 4 bytes */
2027 SIVAL(pdata,8,labels_data_count);
2031 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2032 shadow_data->num_volumes,fsp->fsp_name));
2033 if (labels && shadow_data->labels) {
2034 for (i=0;i<shadow_data->num_volumes;i++) {
2035 srvstr_push(pdata, req->flags2,
2036 cur_pdata, shadow_data->labels[i],
2037 2*sizeof(SHADOW_COPY_LABEL),
2038 STR_UNICODE|STR_TERMINATE);
2039 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2040 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2044 talloc_destroy(shadow_data->mem_ctx);
2046 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2052 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2054 /* pretend this succeeded -
2056 * we have to send back a list with all files owned by this SID
2058 * but I have to check that --metze
2062 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2064 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2066 if (!fsp_belongs_conn(conn, req, fsp)) {
2070 /* unknown 4 bytes: this is not the length of the sid :-( */
2071 /*unknown = IVAL(pdata,0);*/
2073 sid_parse(pdata+4,sid_len,&sid);
2074 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2076 if (!sid_to_uid(&sid, &uid)) {
2077 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2078 sid_string_dbg(&sid),
2079 (unsigned long)sid_len));
2083 /* we can take a look at the find source :-)
2085 * find ./ -uid $uid -name '*' is what we need here
2088 * and send 4bytes len and then NULL terminated unicode strings
2091 * but I don't know how to deal with the paged results
2092 * (maybe we can hang the result anywhere in the fsp struct)
2094 * we don't send all files at once
2095 * and at the next we should *not* start from the beginning,
2096 * so we have to cache the result
2101 /* this works for now... */
2102 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2106 if (!logged_ioctl_message) {
2107 logged_ioctl_message = true; /* Only print this once... */
2108 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2113 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2117 #ifdef HAVE_SYS_QUOTAS
2118 /****************************************************************************
2119 Reply to get user quota
2120 ****************************************************************************/
2122 static void call_nt_transact_get_user_quota(connection_struct *conn,
2123 struct smb_request *req,
2127 uint32 parameter_count,
2130 uint32 max_data_count)
2132 NTSTATUS nt_status = NT_STATUS_OK;
2133 char *params = *ppparams;
2134 char *pdata = *ppdata;
2136 int data_len=0,param_len=0;
2139 files_struct *fsp = NULL;
2143 bool start_enum = True;
2144 SMB_NTQUOTA_STRUCT qt;
2145 SMB_NTQUOTA_LIST *tmp_list;
2146 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2151 if (conn->server_info->utok.uid != 0) {
2152 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2153 "[%s]\n", lp_servicename(SNUM(conn)),
2154 conn->server_info->unix_name));
2155 reply_doserror(req, ERRDOS, ERRnoaccess);
2160 * Ensure minimum number of parameters sent.
2163 if (parameter_count < 4) {
2164 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2165 reply_doserror(req, ERRDOS, ERRinvalidparam);
2169 /* maybe we can check the quota_fnum */
2170 fsp = file_fsp(req, SVAL(params,0));
2171 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2172 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2173 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2177 /* the NULL pointer checking for fsp->fake_file_handle->pd
2178 * is done by CHECK_NTQUOTA_HANDLE_OK()
2180 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2182 level = SVAL(params,2);
2184 /* unknown 12 bytes leading in params */
2187 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2188 /* seems that we should continue with the enum here --metze */
2190 if (qt_handle->quota_list!=NULL &&
2191 qt_handle->tmp_list==NULL) {
2194 free_ntquota_list(&(qt_handle->quota_list));
2196 /* Realloc the size of parameters and data we will return */
2198 params = nttrans_realloc(ppparams, param_len);
2199 if(params == NULL) {
2200 reply_doserror(req, ERRDOS, ERRnomem);
2205 SIVAL(params,0,data_len);
2212 case TRANSACT_GET_USER_QUOTA_LIST_START:
2214 if (qt_handle->quota_list==NULL &&
2215 qt_handle->tmp_list==NULL) {
2219 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2220 reply_doserror(req, ERRSRV, ERRerror);
2224 /* Realloc the size of parameters and data we will return */
2226 params = nttrans_realloc(ppparams, param_len);
2227 if(params == NULL) {
2228 reply_doserror(req, ERRDOS, ERRnomem);
2232 /* we should not trust the value in max_data_count*/
2233 max_data_count = MIN(max_data_count,2048);
2235 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2237 reply_doserror(req, ERRDOS, ERRnomem);
2243 /* set params Size of returned Quota Data 4 bytes*/
2244 /* but set it later when we know it */
2246 /* for each entry push the data */
2249 qt_handle->tmp_list = qt_handle->quota_list;
2252 tmp_list = qt_handle->tmp_list;
2254 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2255 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2257 sid_len = ndr_size_dom_sid(
2258 &tmp_list->quotas->sid, NULL, 0);
2259 entry_len = 40 + sid_len;
2261 /* nextoffset entry 4 bytes */
2262 SIVAL(entry,0,entry_len);
2264 /* then the len of the SID 4 bytes */
2265 SIVAL(entry,4,sid_len);
2267 /* unknown data 8 bytes uint64_t */
2268 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2270 /* the used disk space 8 bytes uint64_t */
2271 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2273 /* the soft quotas 8 bytes uint64_t */
2274 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2276 /* the hard quotas 8 bytes uint64_t */
2277 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2279 /* and now the SID */
2280 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2283 qt_handle->tmp_list = tmp_list;
2285 /* overwrite the offset of the last entry */
2286 SIVAL(entry-entry_len,0,0);
2288 data_len = 4+qt_len;
2289 /* overwrite the params quota_data_len */
2290 SIVAL(params,0,data_len);
2294 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2296 /* unknown 4 bytes IVAL(pdata,0) */
2298 if (data_count < 8) {
2299 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2300 reply_doserror(req, ERRDOS, ERRunknownlevel);
2304 sid_len = IVAL(pdata,4);
2305 /* Ensure this is less than 1mb. */
2306 if (sid_len > (1024*1024)) {
2307 reply_doserror(req, ERRDOS, ERRnomem);
2311 if (data_count < 8+sid_len) {
2312 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2313 reply_doserror(req, ERRDOS, ERRunknownlevel);
2317 data_len = 4+40+sid_len;
2319 if (max_data_count < data_len) {
2320 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2321 max_data_count, data_len));
2323 SIVAL(params,0,data_len);
2325 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2329 sid_parse(pdata+8,sid_len,&sid);
2331 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2334 * we have to return zero's in all fields
2335 * instead of returning an error here
2340 /* Realloc the size of parameters and data we will return */
2342 params = nttrans_realloc(ppparams, param_len);
2343 if(params == NULL) {
2344 reply_doserror(req, ERRDOS, ERRnomem);
2348 pdata = nttrans_realloc(ppdata, data_len);
2350 reply_doserror(req, ERRDOS, ERRnomem);
2356 /* set params Size of returned Quota Data 4 bytes*/
2357 SIVAL(params,0,data_len);
2359 /* nextoffset entry 4 bytes */
2362 /* then the len of the SID 4 bytes */
2363 SIVAL(entry,4,sid_len);
2365 /* unknown data 8 bytes uint64_t */
2366 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2368 /* the used disk space 8 bytes uint64_t */
2369 SBIG_UINT(entry,16,qt.usedspace);
2371 /* the soft quotas 8 bytes uint64_t */
2372 SBIG_UINT(entry,24,qt.softlim);
2374 /* the hard quotas 8 bytes uint64_t */
2375 SBIG_UINT(entry,32,qt.hardlim);
2377 /* and now the SID */
2378 sid_linearize(entry+40, sid_len, &sid);
2383 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2384 reply_doserror(req, ERRSRV, ERRerror);
2389 send_nt_replies(conn, req, nt_status, params, param_len,
2393 /****************************************************************************
2394 Reply to set user quota
2395 ****************************************************************************/
2397 static void call_nt_transact_set_user_quota(connection_struct *conn,
2398 struct smb_request *req,
2402 uint32 parameter_count,
2405 uint32 max_data_count)
2407 char *params = *ppparams;
2408 char *pdata = *ppdata;
2409 int data_len=0,param_len=0;
2410 SMB_NTQUOTA_STRUCT qt;
2413 files_struct *fsp = NULL;
2418 if (conn->server_info->utok.uid != 0) {
2419 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2420 "[%s]\n", lp_servicename(SNUM(conn)),
2421 conn->server_info->unix_name));
2422 reply_doserror(req, ERRDOS, ERRnoaccess);
2427 * Ensure minimum number of parameters sent.
2430 if (parameter_count < 2) {
2431 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2432 reply_doserror(req, ERRDOS, ERRinvalidparam);
2436 /* maybe we can check the quota_fnum */
2437 fsp = file_fsp(req, SVAL(params,0));
2438 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2439 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2440 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2444 if (data_count < 40) {
2445 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2446 reply_doserror(req, ERRDOS, ERRunknownlevel);
2450 /* offset to next quota record.
2451 * 4 bytes IVAL(pdata,0)
2456 sid_len = IVAL(pdata,4);
2458 if (data_count < 40+sid_len) {
2459 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2460 reply_doserror(req, ERRDOS, ERRunknownlevel);
2464 /* unknown 8 bytes in pdata
2465 * maybe its the change time in NTTIME
2468 /* the used space 8 bytes (uint64_t)*/
2469 qt.usedspace = (uint64_t)IVAL(pdata,16);
2470 #ifdef LARGE_SMB_OFF_T
2471 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2472 #else /* LARGE_SMB_OFF_T */
2473 if ((IVAL(pdata,20) != 0)&&
2474 ((qt.usedspace != 0xFFFFFFFF)||
2475 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2476 /* more than 32 bits? */
2477 reply_doserror(req, ERRDOS, ERRunknownlevel);
2480 #endif /* LARGE_SMB_OFF_T */
2482 /* the soft quotas 8 bytes (uint64_t)*/
2483 qt.softlim = (uint64_t)IVAL(pdata,24);
2484 #ifdef LARGE_SMB_OFF_T
2485 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2486 #else /* LARGE_SMB_OFF_T */
2487 if ((IVAL(pdata,28) != 0)&&
2488 ((qt.softlim != 0xFFFFFFFF)||
2489 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2490 /* more than 32 bits? */
2491 reply_doserror(req, ERRDOS, ERRunknownlevel);
2494 #endif /* LARGE_SMB_OFF_T */
2496 /* the hard quotas 8 bytes (uint64_t)*/
2497 qt.hardlim = (uint64_t)IVAL(pdata,32);
2498 #ifdef LARGE_SMB_OFF_T
2499 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2500 #else /* LARGE_SMB_OFF_T */
2501 if ((IVAL(pdata,36) != 0)&&
2502 ((qt.hardlim != 0xFFFFFFFF)||
2503 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2504 /* more than 32 bits? */
2505 reply_doserror(req, ERRDOS, ERRunknownlevel);
2508 #endif /* LARGE_SMB_OFF_T */
2510 sid_parse(pdata+40,sid_len,&sid);
2511 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2513 /* 44 unknown bytes left... */
2515 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2516 reply_doserror(req, ERRSRV, ERRerror);
2520 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2523 #endif /* HAVE_SYS_QUOTAS */
2525 static void handle_nttrans(connection_struct *conn,
2526 struct trans_state *state,
2527 struct smb_request *req)
2529 if (Protocol >= PROTOCOL_NT1) {
2530 req->flags2 |= 0x40; /* IS_LONG_NAME */
2531 SSVAL(req->inbuf,smb_flg2,req->flags2);
2535 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2537 /* Now we must call the relevant NT_TRANS function */
2538 switch(state->call) {
2539 case NT_TRANSACT_CREATE:
2541 START_PROFILE(NT_transact_create);
2542 call_nt_transact_create(
2544 &state->setup, state->setup_count,
2545 &state->param, state->total_param,
2546 &state->data, state->total_data,
2547 state->max_data_return);
2548 END_PROFILE(NT_transact_create);
2552 case NT_TRANSACT_IOCTL:
2554 START_PROFILE(NT_transact_ioctl);
2555 call_nt_transact_ioctl(
2557 &state->setup, state->setup_count,
2558 &state->param, state->total_param,
2559 &state->data, state->total_data,
2560 state->max_data_return);
2561 END_PROFILE(NT_transact_ioctl);
2565 case NT_TRANSACT_SET_SECURITY_DESC:
2567 START_PROFILE(NT_transact_set_security_desc);
2568 call_nt_transact_set_security_desc(
2570 &state->setup, state->setup_count,
2571 &state->param, state->total_param,
2572 &state->data, state->total_data,
2573 state->max_data_return);
2574 END_PROFILE(NT_transact_set_security_desc);
2578 case NT_TRANSACT_NOTIFY_CHANGE:
2580 START_PROFILE(NT_transact_notify_change);
2581 call_nt_transact_notify_change(
2583 &state->setup, state->setup_count,
2584 &state->param, state->total_param,
2585 &state->data, state->total_data,
2586 state->max_data_return,
2587 state->max_param_return);
2588 END_PROFILE(NT_transact_notify_change);
2592 case NT_TRANSACT_RENAME:
2594 START_PROFILE(NT_transact_rename);
2595 call_nt_transact_rename(
2597 &state->setup, state->setup_count,
2598 &state->param, state->total_param,
2599 &state->data, state->total_data,
2600 state->max_data_return);
2601 END_PROFILE(NT_transact_rename);
2605 case NT_TRANSACT_QUERY_SECURITY_DESC:
2607 START_PROFILE(NT_transact_query_security_desc);
2608 call_nt_transact_query_security_desc(
2610 &state->setup, state->setup_count,
2611 &state->param, state->total_param,
2612 &state->data, state->total_data,
2613 state->max_data_return);
2614 END_PROFILE(NT_transact_query_security_desc);
2618 #ifdef HAVE_SYS_QUOTAS
2619 case NT_TRANSACT_GET_USER_QUOTA:
2621 START_PROFILE(NT_transact_get_user_quota);
2622 call_nt_transact_get_user_quota(
2624 &state->setup, state->setup_count,
2625 &state->param, state->total_param,
2626 &state->data, state->total_data,
2627 state->max_data_return);
2628 END_PROFILE(NT_transact_get_user_quota);
2632 case NT_TRANSACT_SET_USER_QUOTA:
2634 START_PROFILE(NT_transact_set_user_quota);
2635 call_nt_transact_set_user_quota(
2637 &state->setup, state->setup_count,
2638 &state->param, state->total_param,
2639 &state->data, state->total_data,
2640 state->max_data_return);
2641 END_PROFILE(NT_transact_set_user_quota);
2644 #endif /* HAVE_SYS_QUOTAS */
2647 /* Error in request */
2648 DEBUG(0,("handle_nttrans: Unknown request %d in "
2649 "nttrans call\n", state->call));
2650 reply_doserror(req, ERRSRV, ERRerror);
2656 /****************************************************************************
2657 Reply to a SMBNTtrans.
2658 ****************************************************************************/
2660 void reply_nttrans(struct smb_request *req)
2662 connection_struct *conn = req->conn;
2667 uint16 function_code;
2669 struct trans_state *state;
2671 START_PROFILE(SMBnttrans);
2673 if (req->wct < 19) {
2674 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2675 END_PROFILE(SMBnttrans);
2679 pscnt = IVAL(req->vwv+9, 1);
2680 psoff = IVAL(req->vwv+11, 1);
2681 dscnt = IVAL(req->vwv+13, 1);
2682 dsoff = IVAL(req->vwv+15, 1);
2683 function_code = SVAL(req->vwv+18, 0);
2685 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2686 reply_doserror(req, ERRSRV, ERRaccess);
2687 END_PROFILE(SMBnttrans);
2691 result = allow_new_trans(conn->pending_trans, req->mid);
2692 if (!NT_STATUS_IS_OK(result)) {
2693 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2694 reply_nterror(req, result);
2695 END_PROFILE(SMBnttrans);
2699 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2700 reply_doserror(req, ERRSRV, ERRaccess);
2701 END_PROFILE(SMBnttrans);
2705 state->cmd = SMBnttrans;
2707 state->mid = req->mid;
2708 state->vuid = req->vuid;
2709 state->total_data = IVAL(req->vwv+3, 1);
2711 state->total_param = IVAL(req->vwv+1, 1);
2712 state->param = NULL;
2713 state->max_data_return = IVAL(req->vwv+7, 1);
2714 state->max_param_return = IVAL(req->vwv+5, 1);
2716 /* setup count is in *words* */
2717 state->setup_count = 2*CVAL(req->vwv+17, 1);
2718 state->setup = NULL;
2719 state->call = function_code;
2721 DEBUG(10, ("num_setup=%u, "
2722 "param_total=%u, this_param=%u, max_param=%u, "
2723 "data_total=%u, this_data=%u, max_data=%u, "
2724 "param_offset=%u, data_offset=%u\n",
2725 (unsigned)state->setup_count,
2726 (unsigned)state->total_param, (unsigned)pscnt,
2727 (unsigned)state->max_param_return,
2728 (unsigned)state->total_data, (unsigned)dscnt,
2729 (unsigned)state->max_data_return,
2730 (unsigned)psoff, (unsigned)dsoff));
2733 * All nttrans messages we handle have smb_wct == 19 +
2734 * state->setup_count. Ensure this is so as a sanity check.
2737 if(req->wct != 19 + (state->setup_count/2)) {
2738 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2739 req->wct, 19 + (state->setup_count/2)));
2743 /* Don't allow more than 128mb for each value. */
2744 if ((state->total_data > (1024*1024*128)) ||
2745 (state->total_param > (1024*1024*128))) {
2746 reply_doserror(req, ERRDOS, ERRnomem);
2747 END_PROFILE(SMBnttrans);
2751 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2754 if (state->total_data) {
2756 if (trans_oob(state->total_data, 0, dscnt)
2757 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2761 /* Can't use talloc here, the core routines do realloc on the
2762 * params and data. */
2763 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2764 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2765 "bytes !\n", (unsigned int)state->total_data));
2767 reply_doserror(req, ERRDOS, ERRnomem);
2768 END_PROFILE(SMBnttrans);
2772 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2775 if (state->total_param) {
2777 if (trans_oob(state->total_param, 0, pscnt)
2778 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2782 /* Can't use talloc here, the core routines do realloc on the
2783 * params and data. */
2784 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2785 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2786 "bytes !\n", (unsigned int)state->total_param));
2787 SAFE_FREE(state->data);
2789 reply_doserror(req, ERRDOS, ERRnomem);
2790 END_PROFILE(SMBnttrans);
2794 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2797 state->received_data = dscnt;
2798 state->received_param = pscnt;
2800 if(state->setup_count > 0) {
2801 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2802 state->setup_count));
2805 * No overflow possible here, state->setup_count is an
2806 * unsigned int, being filled by a single byte from
2807 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2808 * below is not necessary, it's here to clarify things. The
2809 * validity of req->vwv and req->wct has been checked in
2810 * init_smb_request already.
2812 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2816 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2817 if (state->setup == NULL) {
2818 DEBUG(0,("reply_nttrans : Out of memory\n"));
2819 SAFE_FREE(state->data);
2820 SAFE_FREE(state->param);
2822 reply_doserror(req, ERRDOS, ERRnomem);
2823 END_PROFILE(SMBnttrans);
2827 memcpy(state->setup, req->vwv+19, state->setup_count);
2828 dump_data(10, (uint8 *)state->setup, state->setup_count);
2831 if ((state->received_data == state->total_data) &&
2832 (state->received_param == state->total_param)) {
2833 handle_nttrans(conn, state, req);
2834 SAFE_FREE(state->param);
2835 SAFE_FREE(state->data);
2837 END_PROFILE(SMBnttrans);
2841 DLIST_ADD(conn->pending_trans, state);
2843 /* We need to send an interim response then receive the rest
2844 of the parameter/data bytes */
2845 reply_outbuf(req, 0, 0);
2846 show_msg((char *)req->outbuf);
2847 END_PROFILE(SMBnttrans);
2852 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2853 SAFE_FREE(state->data);
2854 SAFE_FREE(state->param);
2856 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2857 END_PROFILE(SMBnttrans);
2861 /****************************************************************************
2862 Reply to a SMBnttranss
2863 ****************************************************************************/
2865 void reply_nttranss(struct smb_request *req)
2867 connection_struct *conn = req->conn;
2868 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2869 struct trans_state *state;
2871 START_PROFILE(SMBnttranss);
2873 show_msg((char *)req->inbuf);
2875 if (req->wct < 18) {
2876 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2877 END_PROFILE(SMBnttranss);
2881 for (state = conn->pending_trans; state != NULL;
2882 state = state->next) {
2883 if (state->mid == req->mid) {
2888 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2889 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2890 END_PROFILE(SMBnttranss);
2894 /* Revise state->total_param and state->total_data in case they have
2895 changed downwards */
2896 if (IVAL(req->vwv+1, 1) < state->total_param) {
2897 state->total_param = IVAL(req->vwv+1, 1);
2899 if (IVAL(req->vwv+3, 1) < state->total_data) {
2900 state->total_data = IVAL(req->vwv+3, 1);
2903 pcnt = IVAL(req->vwv+5, 1);
2904 poff = IVAL(req->vwv+7, 1);
2905 pdisp = IVAL(req->vwv+9, 1);
2907 dcnt = IVAL(req->vwv+11, 1);
2908 doff = IVAL(req->vwv+13, 1);
2909 ddisp = IVAL(req->vwv+15, 1);
2911 state->received_param += pcnt;
2912 state->received_data += dcnt;
2914 if ((state->received_data > state->total_data) ||
2915 (state->received_param > state->total_param))
2919 if (trans_oob(state->total_param, pdisp, pcnt)
2920 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2923 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2927 if (trans_oob(state->total_data, ddisp, dcnt)
2928 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2931 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2934 if ((state->received_param < state->total_param) ||
2935 (state->received_data < state->total_data)) {
2936 END_PROFILE(SMBnttranss);
2940 handle_nttrans(conn, state, req);
2942 DLIST_REMOVE(conn->pending_trans, state);
2943 SAFE_FREE(state->data);
2944 SAFE_FREE(state->param);
2946 END_PROFILE(SMBnttranss);
2951 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2952 DLIST_REMOVE(conn->pending_trans, state);
2953 SAFE_FREE(state->data);
2954 SAFE_FREE(state->param);
2956 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2957 END_PROFILE(SMBnttranss);