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 "system/filesys.h"
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "fake_file.h"
26 #include "../libcli/security/security.h"
27 #include "../librpc/gen_ndr/ndr_security.h"
28 #include "passdb/lookup_sid.h"
31 #include "smbprofile.h"
32 #include "libsmb/libsmb.h"
34 extern const struct generic_mapping file_generic_mapping;
36 static char *nttrans_realloc(char **ptr, size_t size)
39 smb_panic("nttrans_realloc() called with NULL ptr");
42 *ptr = (char *)SMB_REALLOC(*ptr, size);
46 memset(*ptr,'\0',size);
50 /****************************************************************************
51 Send the required number of replies back.
52 We assume all fields other than the data fields are
53 set correctly for the type of call.
54 HACK ! Always assumes smb_setup field is zero.
55 ****************************************************************************/
57 void send_nt_replies(connection_struct *conn,
58 struct smb_request *req, NTSTATUS nt_error,
59 char *params, int paramsize,
60 char *pdata, int datasize)
62 int data_to_send = datasize;
63 int params_to_send = paramsize;
67 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
68 int alignment_offset = 1;
69 int data_alignment_offset = 0;
70 struct smbd_server_connection *sconn = req->sconn;
71 int max_send = sconn->smb1.sessions.max_send;
74 * If there genuinely are no parameters or data to send just send
78 if(params_to_send == 0 && data_to_send == 0) {
79 reply_outbuf(req, 18, 0);
80 if (NT_STATUS_V(nt_error)) {
81 error_packet_set((char *)req->outbuf,
85 show_msg((char *)req->outbuf);
86 if (!srv_send_smb(sconn,
89 IS_CONN_ENCRYPTED(conn),
91 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
93 TALLOC_FREE(req->outbuf);
98 * When sending params and data ensure that both are nicely aligned.
99 * Only do this alignment when there is also data to send - else
100 * can cause NT redirector problems.
103 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
104 data_alignment_offset = 4 - (params_to_send % 4);
108 * Space is bufsize minus Netbios over TCP header minus SMB header.
109 * The alignment_offset is to align the param bytes on a four byte
110 * boundary (2 bytes for data len, one byte pad).
111 * NT needs this to work correctly.
114 useable_space = max_send - (smb_size
117 + data_alignment_offset);
119 if (useable_space < 0) {
120 char *msg = talloc_asprintf(
122 "send_nt_replies failed sanity useable_space = %d!!!",
124 DEBUG(0, ("%s\n", msg));
125 exit_server_cleanly(msg);
128 while (params_to_send || data_to_send) {
131 * Calculate whether we will totally or partially fill this packet.
134 total_sent_thistime = params_to_send + data_to_send;
137 * We can never send more than useable_space.
140 total_sent_thistime = MIN(total_sent_thistime, useable_space);
142 reply_outbuf(req, 18,
143 total_sent_thistime + alignment_offset
144 + data_alignment_offset);
147 * Set total params and data to be sent.
150 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
151 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
154 * Calculate how many parameters and data we can fit into
155 * this packet. Parameters get precedence.
158 params_sent_thistime = MIN(params_to_send,useable_space);
159 data_sent_thistime = useable_space - params_sent_thistime;
160 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
162 SIVAL(req->outbuf, smb_ntr_ParameterCount,
163 params_sent_thistime);
165 if(params_sent_thistime == 0) {
166 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
167 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
170 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
171 * parameter bytes, however the first 4 bytes of outbuf are
172 * the Netbios over TCP header. Thus use smb_base() to subtract
173 * them from the calculation.
176 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
177 ((smb_buf(req->outbuf)+alignment_offset)
178 - smb_base(req->outbuf)));
180 * Absolute displacement of param bytes sent in this packet.
183 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
188 * Deal with the data portion.
191 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
193 if(data_sent_thistime == 0) {
194 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
195 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
198 * The offset of the data bytes is the offset of the
199 * parameter bytes plus the number of parameters being sent this time.
202 SIVAL(req->outbuf, smb_ntr_DataOffset,
203 ((smb_buf(req->outbuf)+alignment_offset) -
204 smb_base(req->outbuf))
205 + params_sent_thistime + data_alignment_offset);
206 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
210 * Copy the param bytes into the packet.
213 if(params_sent_thistime) {
214 if (alignment_offset != 0) {
215 memset(smb_buf(req->outbuf), 0,
218 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
219 params_sent_thistime);
223 * Copy in the data bytes
226 if(data_sent_thistime) {
227 if (data_alignment_offset != 0) {
228 memset((smb_buf(req->outbuf)+alignment_offset+
229 params_sent_thistime), 0,
230 data_alignment_offset);
232 memcpy(smb_buf(req->outbuf)+alignment_offset
233 +params_sent_thistime+data_alignment_offset,
234 pd,data_sent_thistime);
237 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
238 params_sent_thistime, data_sent_thistime, useable_space));
239 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
240 params_to_send, data_to_send, paramsize, datasize));
242 if (NT_STATUS_V(nt_error)) {
243 error_packet_set((char *)req->outbuf,
248 /* Send the packet */
249 show_msg((char *)req->outbuf);
250 if (!srv_send_smb(sconn,
253 IS_CONN_ENCRYPTED(conn),
255 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
258 TALLOC_FREE(req->outbuf);
260 pp += params_sent_thistime;
261 pd += data_sent_thistime;
263 params_to_send -= params_sent_thistime;
264 data_to_send -= data_sent_thistime;
270 if(params_to_send < 0 || data_to_send < 0) {
271 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
272 params_to_send, data_to_send));
273 exit_server_cleanly("send_nt_replies: internal error");
278 /****************************************************************************
279 Reply to an NT create and X call on a pipe
280 ****************************************************************************/
282 static void nt_open_pipe(char *fname, connection_struct *conn,
283 struct smb_request *req, int *ppnum)
288 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
290 /* Strip \\ off the name. */
293 status = open_np_file(req, fname, &fsp);
294 if (!NT_STATUS_IS_OK(status)) {
295 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
296 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
300 reply_nterror(req, status);
308 /****************************************************************************
309 Reply to an NT create and X call for pipes.
310 ****************************************************************************/
312 static void do_ntcreate_pipe_open(connection_struct *conn,
313 struct smb_request *req)
318 uint32 flags = IVAL(req->vwv+3, 1);
319 TALLOC_CTX *ctx = talloc_tos();
321 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
324 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
328 nt_open_pipe(fname, conn, req, &pnum);
336 * Deal with pipe return.
339 if (flags & EXTENDED_RESPONSE_REQUIRED) {
340 /* This is very strange. We
341 * return 50 words, but only set
342 * the wcnt to 42 ? It's definately
343 * what happens on the wire....
345 reply_outbuf(req, 50, 0);
346 SCVAL(req->outbuf,smb_wct,42);
348 reply_outbuf(req, 34, 0);
351 p = (char *)req->outbuf + smb_vwv2;
355 SIVAL(p,0,FILE_WAS_OPENED);
358 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
361 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
363 SSVAL(p,2, 0x5FF); /* ? */
366 if (flags & EXTENDED_RESPONSE_REQUIRED) {
368 SIVAL(p,0,FILE_GENERIC_ALL);
370 * For pipes W2K3 seems to return
372 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
374 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
377 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
382 struct case_semantics_state {
383 connection_struct *conn;
386 bool short_case_preserve;
389 /****************************************************************************
390 Restore case semantics.
391 ****************************************************************************/
393 static int restore_case_semantics(struct case_semantics_state *state)
395 state->conn->case_sensitive = state->case_sensitive;
396 state->conn->case_preserve = state->case_preserve;
397 state->conn->short_case_preserve = state->short_case_preserve;
401 /****************************************************************************
403 ****************************************************************************/
405 static struct case_semantics_state *set_posix_case_semantics(TALLOC_CTX *mem_ctx,
406 connection_struct *conn)
408 struct case_semantics_state *result;
410 if (!(result = talloc(mem_ctx, struct case_semantics_state))) {
415 result->case_sensitive = conn->case_sensitive;
416 result->case_preserve = conn->case_preserve;
417 result->short_case_preserve = conn->short_case_preserve;
420 conn->case_sensitive = True;
421 conn->case_preserve = True;
422 conn->short_case_preserve = True;
424 talloc_set_destructor(result, restore_case_semantics);
429 /****************************************************************************
430 Reply to an NT create and X call.
431 ****************************************************************************/
433 void reply_ntcreate_and_X(struct smb_request *req)
435 connection_struct *conn = req->conn;
436 struct smb_filename *smb_fname = NULL;
440 uint32 file_attributes;
442 uint32 create_disposition;
443 uint32 create_options;
445 uint64_t allocation_size;
446 /* Breakout the oplock request bits so we can set the
447 reply bits separately. */
449 SMB_OFF_T file_len = 0;
451 files_struct *fsp = NULL;
453 struct timespec create_timespec;
454 struct timespec c_timespec;
455 struct timespec a_timespec;
456 struct timespec m_timespec;
457 struct timespec write_time_ts;
460 uint8_t oplock_granted = NO_OPLOCK_RETURN;
461 struct case_semantics_state *case_state = NULL;
462 TALLOC_CTX *ctx = talloc_tos();
464 START_PROFILE(SMBntcreateX);
467 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
471 flags = IVAL(req->vwv+3, 1);
472 access_mask = IVAL(req->vwv+7, 1);
473 file_attributes = IVAL(req->vwv+13, 1);
474 share_access = IVAL(req->vwv+15, 1);
475 create_disposition = IVAL(req->vwv+17, 1);
476 create_options = IVAL(req->vwv+19, 1);
477 root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
479 allocation_size = BVAL(req->vwv+9, 1);
481 srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
482 STR_TERMINATE, &status);
484 if (!NT_STATUS_IS_OK(status)) {
485 reply_nterror(req, status);
489 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
490 "file_attributes = 0x%x, share_access = 0x%x, "
491 "create_disposition = 0x%x create_options = 0x%x "
492 "root_dir_fid = 0x%x, fname = %s\n",
494 (unsigned int)access_mask,
495 (unsigned int)file_attributes,
496 (unsigned int)share_access,
497 (unsigned int)create_disposition,
498 (unsigned int)create_options,
499 (unsigned int)root_dir_fid,
503 * we need to remove ignored bits when they come directly from the client
504 * because we reuse some of them for internal stuff
506 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
509 * If it's an IPC, use the pipe handler.
513 if (lp_nt_pipe_support()) {
514 do_ntcreate_pipe_open(conn, req);
517 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
521 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
522 if (oplock_request) {
523 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
527 if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
528 case_state = set_posix_case_semantics(ctx, conn);
530 reply_nterror(req, NT_STATUS_NO_MEMORY);
535 status = filename_convert(ctx,
537 req->flags2 & FLAGS2_DFS_PATHNAMES,
543 TALLOC_FREE(case_state);
545 if (!NT_STATUS_IS_OK(status)) {
546 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
548 NT_STATUS_PATH_NOT_COVERED,
552 reply_nterror(req, status);
557 * Bug #6898 - clients using Windows opens should
558 * never be able to set this attribute into the
561 file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
563 status = SMB_VFS_CREATE_FILE(
566 root_dir_fid, /* root_dir_fid */
567 smb_fname, /* fname */
568 access_mask, /* access_mask */
569 share_access, /* share_access */
570 create_disposition, /* create_disposition*/
571 create_options, /* create_options */
572 file_attributes, /* file_attributes */
573 oplock_request, /* oplock_request */
574 allocation_size, /* allocation_size */
575 0, /* private_flags */
581 if (!NT_STATUS_IS_OK(status)) {
582 if (open_was_deferred(req->mid)) {
583 /* We have re-scheduled this call, no error. */
586 reply_openerror(req, status);
590 /* Ensure we're pointing at the correct stat struct. */
591 TALLOC_FREE(smb_fname);
592 smb_fname = fsp->fsp_name;
595 * If the caller set the extended oplock request bit
596 * and we granted one (by whatever means) - set the
597 * correct bit for extended oplock reply.
600 if (oplock_request &&
601 (lp_fake_oplocks(SNUM(conn))
602 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
605 * Exclusive oplock granted
608 if (flags & REQUEST_BATCH_OPLOCK) {
609 oplock_granted = BATCH_OPLOCK_RETURN;
611 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
613 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
614 oplock_granted = LEVEL_II_OPLOCK_RETURN;
616 oplock_granted = NO_OPLOCK_RETURN;
619 file_len = smb_fname->st.st_ex_size;
621 if (flags & EXTENDED_RESPONSE_REQUIRED) {
622 /* This is very strange. We
623 * return 50 words, but only set
624 * the wcnt to 42 ? It's definately
625 * what happens on the wire....
627 reply_outbuf(req, 50, 0);
628 SCVAL(req->outbuf,smb_wct,42);
630 reply_outbuf(req, 34, 0);
633 p = (char *)req->outbuf + smb_vwv2;
635 SCVAL(p, 0, oplock_granted);
638 SSVAL(p,0,fsp->fnum);
640 if ((create_disposition == FILE_SUPERSEDE)
641 && (info == FILE_WAS_OVERWRITTEN)) {
642 SIVAL(p,0,FILE_WAS_SUPERSEDED);
648 fattr = dos_mode(conn, smb_fname);
650 fattr = FILE_ATTRIBUTE_NORMAL;
653 /* Deal with other possible opens having a modified
655 ZERO_STRUCT(write_time_ts);
656 get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
657 if (!null_timespec(write_time_ts)) {
658 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
662 create_timespec = get_create_timespec(conn, fsp, smb_fname);
663 a_timespec = smb_fname->st.st_ex_atime;
664 m_timespec = smb_fname->st.st_ex_mtime;
665 c_timespec = get_change_timespec(conn, fsp, smb_fname);
667 if (lp_dos_filetime_resolution(SNUM(conn))) {
668 dos_filetime_timespec(&create_timespec);
669 dos_filetime_timespec(&a_timespec);
670 dos_filetime_timespec(&m_timespec);
671 dos_filetime_timespec(&c_timespec);
674 put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
676 put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
678 put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
680 put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
682 SIVAL(p,0,fattr); /* File Attributes. */
684 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
686 SOFF_T(p,0,file_len);
688 if (flags & EXTENDED_RESPONSE_REQUIRED) {
689 uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
690 size_t num_names = 0;
691 unsigned int num_streams = 0;
692 struct stream_struct *streams = NULL;
694 /* Do we have any EA's ? */
695 status = get_ea_names_from_file(ctx, conn, fsp,
696 smb_fname->base_name, NULL, &num_names);
697 if (NT_STATUS_IS_OK(status) && num_names) {
698 file_status &= ~NO_EAS;
700 status = vfs_streaminfo(conn, NULL, smb_fname->base_name, ctx,
701 &num_streams, &streams);
702 /* There is always one stream, ::$DATA. */
703 if (NT_STATUS_IS_OK(status) && num_streams > 1) {
704 file_status &= ~NO_SUBSTREAMS;
706 TALLOC_FREE(streams);
707 SSVAL(p,2,file_status);
710 SCVAL(p,0,fsp->is_directory ? 1 : 0);
712 if (flags & EXTENDED_RESPONSE_REQUIRED) {
715 if (fsp->is_directory ||
716 can_write_to_file(conn, smb_fname)) {
717 perms = FILE_GENERIC_ALL;
719 perms = FILE_GENERIC_READ|FILE_EXECUTE;
724 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
725 fsp->fnum, smb_fname_str_dbg(smb_fname)));
729 END_PROFILE(SMBntcreateX);
733 /****************************************************************************
734 Reply to a NT_TRANSACT_CREATE call to open a pipe.
735 ****************************************************************************/
737 static void do_nt_transact_create_pipe(connection_struct *conn,
738 struct smb_request *req,
739 uint16 **ppsetup, uint32 setup_count,
740 char **ppparams, uint32 parameter_count,
741 char **ppdata, uint32 data_count)
744 char *params = *ppparams;
750 TALLOC_CTX *ctx = talloc_tos();
753 * Ensure minimum number of parameters sent.
756 if(parameter_count < 54) {
757 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
758 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
762 flags = IVAL(params,0);
764 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
765 parameter_count-53, STR_TERMINATE,
767 if (!NT_STATUS_IS_OK(status)) {
768 reply_nterror(req, status);
772 nt_open_pipe(fname, conn, req, &pnum);
779 /* Realloc the size of parameters and data we will return */
780 if (flags & EXTENDED_RESPONSE_REQUIRED) {
781 /* Extended response is 32 more byyes. */
786 params = nttrans_realloc(ppparams, param_len);
788 reply_nterror(req, NT_STATUS_NO_MEMORY);
793 SCVAL(p,0,NO_OPLOCK_RETURN);
798 SIVAL(p,0,FILE_WAS_OPENED);
802 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
805 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
807 SSVAL(p,2, 0x5FF); /* ? */
810 if (flags & EXTENDED_RESPONSE_REQUIRED) {
812 SIVAL(p,0,FILE_GENERIC_ALL);
814 * For pipes W2K3 seems to return
816 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
818 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
821 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
823 /* Send the required number of replies */
824 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
829 /*********************************************************************
830 Windows seems to do canonicalization of inheritance bits. Do the
832 *********************************************************************/
834 static void canonicalize_inheritance_bits(struct security_descriptor *psd)
836 bool set_auto_inherited = false;
839 * We need to filter out the
840 * SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ
841 * bits. If both are set we store SEC_DESC_DACL_AUTO_INHERITED
842 * as this alters whether SEC_ACE_FLAG_INHERITED_ACE is set
843 * when an ACE is inherited. Otherwise we zero these bits out.
846 * http://social.msdn.microsoft.com/Forums/eu/os_fileservices/thread/11f77b68-731e-407d-b1b3-064750716531
851 if ((psd->type & (SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ))
852 == (SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ)) {
853 set_auto_inherited = true;
856 psd->type &= ~(SEC_DESC_DACL_AUTO_INHERITED|SEC_DESC_DACL_AUTO_INHERIT_REQ);
857 if (set_auto_inherited) {
858 psd->type |= SEC_DESC_DACL_AUTO_INHERITED;
862 /****************************************************************************
863 Internal fn to set security descriptors.
864 ****************************************************************************/
866 NTSTATUS set_sd(files_struct *fsp, struct security_descriptor *psd,
867 uint32_t security_info_sent)
871 if (!CAN_WRITE(fsp->conn)) {
872 return NT_STATUS_ACCESS_DENIED;
875 if (!lp_nt_acl_support(SNUM(fsp->conn))) {
879 if (psd->owner_sid == NULL) {
880 security_info_sent &= ~SECINFO_OWNER;
882 if (psd->group_sid == NULL) {
883 security_info_sent &= ~SECINFO_GROUP;
886 /* Ensure we have at least one thing set. */
887 if ((security_info_sent & (SECINFO_OWNER|SECINFO_GROUP|SECINFO_DACL|SECINFO_SACL)) == 0) {
888 if (security_info_sent & SECINFO_LABEL) {
889 /* Only consider SECINFO_LABEL if no other
890 bits are set. Just like W2K3 we don't
894 return NT_STATUS_INVALID_PARAMETER;
897 /* Ensure we have the rights to do this. */
898 if (security_info_sent & SECINFO_OWNER) {
899 if (!(fsp->access_mask & SEC_STD_WRITE_OWNER)) {
900 return NT_STATUS_ACCESS_DENIED;
904 if (security_info_sent & SECINFO_GROUP) {
905 if (!(fsp->access_mask & SEC_STD_WRITE_OWNER)) {
906 return NT_STATUS_ACCESS_DENIED;
910 if (security_info_sent & SECINFO_DACL) {
911 if (!(fsp->access_mask & SEC_STD_WRITE_DAC)) {
912 return NT_STATUS_ACCESS_DENIED;
914 /* Convert all the generic bits. */
916 security_acl_map_generic(psd->dacl, &file_generic_mapping);
920 if (security_info_sent & SECINFO_SACL) {
921 if (!(fsp->access_mask & SEC_FLAG_SYSTEM_SECURITY)) {
922 return NT_STATUS_ACCESS_DENIED;
924 /* Convert all the generic bits. */
926 security_acl_map_generic(psd->sacl, &file_generic_mapping);
930 canonicalize_inheritance_bits(psd);
932 if (DEBUGLEVEL >= 10) {
933 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
934 NDR_PRINT_DEBUG(security_descriptor, psd);
937 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
944 /****************************************************************************
945 Internal fn to set security descriptors from a data blob.
946 ****************************************************************************/
948 NTSTATUS set_sd_blob(files_struct *fsp, uint8_t *data, uint32_t sd_len,
949 uint32_t security_info_sent)
951 struct security_descriptor *psd = NULL;
955 return NT_STATUS_INVALID_PARAMETER;
958 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
960 if (!NT_STATUS_IS_OK(status)) {
964 return set_sd(fsp, psd, security_info_sent);
967 /****************************************************************************
968 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
969 ****************************************************************************/
971 struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
973 struct ea_list *ea_list_head = NULL;
980 while (offset + 4 <= data_size) {
981 size_t next_offset = IVAL(pdata,offset);
982 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
988 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
989 if (next_offset == 0) {
993 /* Integer wrap protection for the increment. */
994 if (offset + next_offset < offset) {
998 offset += next_offset;
1000 /* Integer wrap protection for while loop. */
1001 if (offset + 4 < offset) {
1007 return ea_list_head;
1010 /****************************************************************************
1011 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1012 ****************************************************************************/
1014 static void call_nt_transact_create(connection_struct *conn,
1015 struct smb_request *req,
1016 uint16 **ppsetup, uint32 setup_count,
1017 char **ppparams, uint32 parameter_count,
1018 char **ppdata, uint32 data_count,
1019 uint32 max_data_count)
1021 struct smb_filename *smb_fname = NULL;
1023 char *params = *ppparams;
1024 char *data = *ppdata;
1025 /* Breakout the oplock request bits so we can set the reply bits separately. */
1027 SMB_OFF_T file_len = 0;
1029 files_struct *fsp = NULL;
1033 uint32 file_attributes;
1034 uint32 share_access;
1035 uint32 create_disposition;
1036 uint32 create_options;
1038 struct security_descriptor *sd = NULL;
1040 uint16 root_dir_fid;
1041 struct timespec create_timespec;
1042 struct timespec c_timespec;
1043 struct timespec a_timespec;
1044 struct timespec m_timespec;
1045 struct timespec write_time_ts;
1046 struct ea_list *ea_list = NULL;
1049 uint64_t allocation_size;
1051 uint8_t oplock_granted;
1052 struct case_semantics_state *case_state = NULL;
1053 TALLOC_CTX *ctx = talloc_tos();
1055 DEBUG(5,("call_nt_transact_create\n"));
1058 * If it's an IPC, use the pipe handler.
1062 if (lp_nt_pipe_support()) {
1063 do_nt_transact_create_pipe(
1065 ppsetup, setup_count,
1066 ppparams, parameter_count,
1067 ppdata, data_count);
1070 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
1075 * Ensure minimum number of parameters sent.
1078 if(parameter_count < 54) {
1079 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1080 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1084 flags = IVAL(params,0);
1085 access_mask = IVAL(params,8);
1086 file_attributes = IVAL(params,20);
1087 share_access = IVAL(params,24);
1088 create_disposition = IVAL(params,28);
1089 create_options = IVAL(params,32);
1090 sd_len = IVAL(params,36);
1091 ea_len = IVAL(params,40);
1092 root_dir_fid = (uint16)IVAL(params,4);
1093 allocation_size = BVAL(params,12);
1096 * we need to remove ignored bits when they come directly from the client
1097 * because we reuse some of them for internal stuff
1099 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
1101 /* Ensure the data_len is correct for the sd and ea values given. */
1102 if ((ea_len + sd_len > data_count)
1103 || (ea_len > data_count) || (sd_len > data_count)
1104 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
1105 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
1106 "%u, data_count = %u\n", (unsigned int)ea_len,
1107 (unsigned int)sd_len, (unsigned int)data_count));
1108 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1113 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
1116 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
1118 if (!NT_STATUS_IS_OK(status)) {
1119 DEBUG(10, ("call_nt_transact_create: "
1120 "unmarshall_sec_desc failed: %s\n",
1121 nt_errstr(status)));
1122 reply_nterror(req, status);
1128 if (!lp_ea_support(SNUM(conn))) {
1129 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1130 "EA's not supported.\n",
1131 (unsigned int)ea_len));
1132 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
1137 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1138 "too small (should be more than 10)\n",
1139 (unsigned int)ea_len ));
1140 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1144 /* We have already checked that ea_len <= data_count here. */
1145 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
1147 if (ea_list == NULL) {
1148 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1153 srvstr_get_path(ctx, params, req->flags2, &fname,
1154 params+53, parameter_count-53,
1155 STR_TERMINATE, &status);
1156 if (!NT_STATUS_IS_OK(status)) {
1157 reply_nterror(req, status);
1161 if (file_attributes & FILE_FLAG_POSIX_SEMANTICS) {
1162 case_state = set_posix_case_semantics(ctx, conn);
1164 reply_nterror(req, NT_STATUS_NO_MEMORY);
1169 status = filename_convert(ctx,
1171 req->flags2 & FLAGS2_DFS_PATHNAMES,
1177 TALLOC_FREE(case_state);
1179 if (!NT_STATUS_IS_OK(status)) {
1180 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1181 reply_botherror(req,
1182 NT_STATUS_PATH_NOT_COVERED,
1183 ERRSRV, ERRbadpath);
1186 reply_nterror(req, status);
1190 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1191 if (oplock_request) {
1192 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
1197 * Bug #6898 - clients using Windows opens should
1198 * never be able to set this attribute into the
1201 file_attributes &= ~FILE_FLAG_POSIX_SEMANTICS;
1203 status = SMB_VFS_CREATE_FILE(
1206 root_dir_fid, /* root_dir_fid */
1207 smb_fname, /* fname */
1208 access_mask, /* access_mask */
1209 share_access, /* share_access */
1210 create_disposition, /* create_disposition*/
1211 create_options, /* create_options */
1212 file_attributes, /* file_attributes */
1213 oplock_request, /* oplock_request */
1214 allocation_size, /* allocation_size */
1215 0, /* private_flags */
1217 ea_list, /* ea_list */
1221 if(!NT_STATUS_IS_OK(status)) {
1222 if (open_was_deferred(req->mid)) {
1223 /* We have re-scheduled this call, no error. */
1226 reply_openerror(req, status);
1230 /* Ensure we're pointing at the correct stat struct. */
1231 TALLOC_FREE(smb_fname);
1232 smb_fname = fsp->fsp_name;
1235 * If the caller set the extended oplock request bit
1236 * and we granted one (by whatever means) - set the
1237 * correct bit for extended oplock reply.
1240 if (oplock_request &&
1241 (lp_fake_oplocks(SNUM(conn))
1242 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1245 * Exclusive oplock granted
1248 if (flags & REQUEST_BATCH_OPLOCK) {
1249 oplock_granted = BATCH_OPLOCK_RETURN;
1251 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1253 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1254 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1256 oplock_granted = NO_OPLOCK_RETURN;
1259 file_len = smb_fname->st.st_ex_size;
1261 /* Realloc the size of parameters and data we will return */
1262 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1263 /* Extended response is 32 more byyes. */
1268 params = nttrans_realloc(ppparams, param_len);
1269 if(params == NULL) {
1270 reply_nterror(req, NT_STATUS_NO_MEMORY);
1275 SCVAL(p, 0, oplock_granted);
1278 SSVAL(p,0,fsp->fnum);
1280 if ((create_disposition == FILE_SUPERSEDE)
1281 && (info == FILE_WAS_OVERWRITTEN)) {
1282 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1288 fattr = dos_mode(conn, smb_fname);
1290 fattr = FILE_ATTRIBUTE_NORMAL;
1293 /* Deal with other possible opens having a modified
1295 ZERO_STRUCT(write_time_ts);
1296 get_file_infos(fsp->file_id, 0, NULL, &write_time_ts);
1297 if (!null_timespec(write_time_ts)) {
1298 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
1302 create_timespec = get_create_timespec(conn, fsp, smb_fname);
1303 a_timespec = smb_fname->st.st_ex_atime;
1304 m_timespec = smb_fname->st.st_ex_mtime;
1305 c_timespec = get_change_timespec(conn, fsp, smb_fname);
1307 if (lp_dos_filetime_resolution(SNUM(conn))) {
1308 dos_filetime_timespec(&create_timespec);
1309 dos_filetime_timespec(&a_timespec);
1310 dos_filetime_timespec(&m_timespec);
1311 dos_filetime_timespec(&c_timespec);
1314 put_long_date_timespec(conn->ts_res, p, create_timespec); /* create time. */
1316 put_long_date_timespec(conn->ts_res, p, a_timespec); /* access time */
1318 put_long_date_timespec(conn->ts_res, p, m_timespec); /* write time */
1320 put_long_date_timespec(conn->ts_res, p, c_timespec); /* change time */
1322 SIVAL(p,0,fattr); /* File Attributes. */
1324 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1326 SOFF_T(p,0,file_len);
1328 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1329 uint16_t file_status = (NO_EAS|NO_SUBSTREAMS|NO_REPARSETAG);
1330 size_t num_names = 0;
1331 unsigned int num_streams = 0;
1332 struct stream_struct *streams = NULL;
1334 /* Do we have any EA's ? */
1335 status = get_ea_names_from_file(ctx, conn, fsp,
1336 smb_fname->base_name, NULL, &num_names);
1337 if (NT_STATUS_IS_OK(status) && num_names) {
1338 file_status &= ~NO_EAS;
1340 status = vfs_streaminfo(conn, NULL, smb_fname->base_name, ctx,
1341 &num_streams, &streams);
1342 /* There is always one stream, ::$DATA. */
1343 if (NT_STATUS_IS_OK(status) && num_streams > 1) {
1344 file_status &= ~NO_SUBSTREAMS;
1346 TALLOC_FREE(streams);
1347 SSVAL(p,2,file_status);
1350 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1352 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1355 if (fsp->is_directory ||
1356 can_write_to_file(conn, smb_fname)) {
1357 perms = FILE_GENERIC_ALL;
1359 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1364 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1365 smb_fname_str_dbg(smb_fname)));
1367 /* Send the required number of replies */
1368 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1373 /****************************************************************************
1374 Reply to a NT CANCEL request.
1375 conn POINTER CAN BE NULL HERE !
1376 ****************************************************************************/
1378 void reply_ntcancel(struct smb_request *req)
1381 * Go through and cancel any pending change notifies.
1384 START_PROFILE(SMBntcancel);
1385 srv_cancel_sign_response(req->sconn);
1386 remove_pending_change_notify_requests_by_mid(req->sconn, req->mid);
1387 remove_pending_lock_requests_by_mid_smb1(req->sconn, req->mid);
1389 DEBUG(3,("reply_ntcancel: cancel called on mid = %llu.\n",
1390 (unsigned long long)req->mid));
1392 END_PROFILE(SMBntcancel);
1396 /****************************************************************************
1398 ****************************************************************************/
1400 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1401 connection_struct *conn,
1402 struct smb_request *req,
1403 struct smb_filename *smb_fname_src,
1404 struct smb_filename *smb_fname_dst,
1407 files_struct *fsp1,*fsp2;
1411 NTSTATUS status = NT_STATUS_OK;
1414 if (!CAN_WRITE(conn)) {
1415 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1419 /* Source must already exist. */
1420 if (!VALID_STAT(smb_fname_src->st)) {
1421 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1425 /* Ensure attributes match. */
1426 fattr = dos_mode(conn, smb_fname_src);
1427 if ((fattr & ~attrs) & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) {
1428 status = NT_STATUS_NO_SUCH_FILE;
1432 /* Disallow if dst file already exists. */
1433 if (VALID_STAT(smb_fname_dst->st)) {
1434 status = NT_STATUS_OBJECT_NAME_COLLISION;
1438 /* No links from a directory. */
1439 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1440 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1444 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1445 smb_fname_str_dbg(smb_fname_src),
1446 smb_fname_str_dbg(smb_fname_dst)));
1448 status = SMB_VFS_CREATE_FILE(
1451 0, /* root_dir_fid */
1452 smb_fname_src, /* fname */
1453 FILE_READ_DATA|FILE_READ_ATTRIBUTES|
1454 FILE_READ_EA, /* access_mask */
1455 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1457 FILE_OPEN, /* create_disposition*/
1458 0, /* create_options */
1459 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1460 NO_OPLOCK, /* oplock_request */
1461 0, /* allocation_size */
1462 0, /* private_flags */
1468 if (!NT_STATUS_IS_OK(status)) {
1472 status = SMB_VFS_CREATE_FILE(
1475 0, /* root_dir_fid */
1476 smb_fname_dst, /* fname */
1477 FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|
1478 FILE_WRITE_EA, /* access_mask */
1479 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1481 FILE_CREATE, /* create_disposition*/
1482 0, /* create_options */
1483 fattr, /* file_attributes */
1484 NO_OPLOCK, /* oplock_request */
1485 0, /* allocation_size */
1486 0, /* private_flags */
1492 if (!NT_STATUS_IS_OK(status)) {
1493 close_file(NULL, fsp1, ERROR_CLOSE);
1497 if (smb_fname_src->st.st_ex_size) {
1498 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1502 * As we are opening fsp1 read-only we only expect
1503 * an error on close on fsp2 if we are out of space.
1504 * Thus we don't look at the error return from the
1507 close_file(NULL, fsp1, NORMAL_CLOSE);
1509 /* Ensure the modtime is set correctly on the destination file. */
1510 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1512 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1514 /* Grrr. We have to do this as open_file_ntcreate adds FILE_ATTRIBUTE_ARCHIVE when it
1515 creates the file. This isn't the correct thing to do in the copy
1517 if (!parent_dirname(talloc_tos(), smb_fname_dst->base_name, &parent,
1519 status = NT_STATUS_NO_MEMORY;
1522 file_set_dosmode(conn, smb_fname_dst, fattr, parent, false);
1523 TALLOC_FREE(parent);
1525 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1526 status = NT_STATUS_DISK_FULL;
1530 if (!NT_STATUS_IS_OK(status)) {
1531 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1532 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1533 smb_fname_str_dbg(smb_fname_dst)));
1539 /****************************************************************************
1540 Reply to a NT rename request.
1541 ****************************************************************************/
1543 void reply_ntrename(struct smb_request *req)
1545 connection_struct *conn = req->conn;
1546 struct smb_filename *smb_fname_old = NULL;
1547 struct smb_filename *smb_fname_new = NULL;
1548 char *oldname = NULL;
1549 char *newname = NULL;
1552 bool src_has_wcard = False;
1553 bool dest_has_wcard = False;
1555 uint32_t ucf_flags_src = 0;
1556 uint32_t ucf_flags_dst = 0;
1558 TALLOC_CTX *ctx = talloc_tos();
1559 bool stream_rename = false;
1561 START_PROFILE(SMBntrename);
1564 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1568 attrs = SVAL(req->vwv+0, 0);
1569 rename_type = SVAL(req->vwv+1, 0);
1571 p = (const char *)req->buf + 1;
1572 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1573 &status, &src_has_wcard);
1574 if (!NT_STATUS_IS_OK(status)) {
1575 reply_nterror(req, status);
1579 if (ms_has_wild(oldname)) {
1580 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1585 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1586 &status, &dest_has_wcard);
1587 if (!NT_STATUS_IS_OK(status)) {
1588 reply_nterror(req, status);
1592 if (!lp_posix_pathnames()) {
1593 /* The newname must begin with a ':' if the
1594 oldname contains a ':'. */
1595 if (strchr_m(oldname, ':')) {
1596 if (newname[0] != ':') {
1597 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1600 stream_rename = true;
1605 * If this is a rename operation, allow wildcards and save the
1606 * destination's last component.
1608 if (rename_type == RENAME_FLAG_RENAME) {
1609 ucf_flags_src = UCF_COND_ALLOW_WCARD_LCOMP;
1610 ucf_flags_dst = UCF_COND_ALLOW_WCARD_LCOMP | UCF_SAVE_LCOMP;
1613 /* rename_internals() calls unix_convert(), so don't call it here. */
1614 status = filename_convert(ctx, conn,
1615 req->flags2 & FLAGS2_DFS_PATHNAMES,
1620 if (!NT_STATUS_IS_OK(status)) {
1621 if (NT_STATUS_EQUAL(status,
1622 NT_STATUS_PATH_NOT_COVERED)) {
1623 reply_botherror(req,
1624 NT_STATUS_PATH_NOT_COVERED,
1625 ERRSRV, ERRbadpath);
1628 reply_nterror(req, status);
1632 status = filename_convert(ctx, conn,
1633 req->flags2 & FLAGS2_DFS_PATHNAMES,
1638 if (!NT_STATUS_IS_OK(status)) {
1639 if (NT_STATUS_EQUAL(status,
1640 NT_STATUS_PATH_NOT_COVERED)) {
1641 reply_botherror(req,
1642 NT_STATUS_PATH_NOT_COVERED,
1643 ERRSRV, ERRbadpath);
1646 reply_nterror(req, status);
1650 if (stream_rename) {
1651 /* smb_fname_new must be the same as smb_fname_old. */
1652 TALLOC_FREE(smb_fname_new->base_name);
1653 smb_fname_new->base_name = talloc_strdup(smb_fname_new,
1654 smb_fname_old->base_name);
1655 if (!smb_fname_new->base_name) {
1656 reply_nterror(req, NT_STATUS_NO_MEMORY);
1661 DEBUG(3,("reply_ntrename: %s -> %s\n",
1662 smb_fname_str_dbg(smb_fname_old),
1663 smb_fname_str_dbg(smb_fname_new)));
1665 switch(rename_type) {
1666 case RENAME_FLAG_RENAME:
1667 status = rename_internals(ctx, conn, req,
1668 smb_fname_old, smb_fname_new,
1669 attrs, False, src_has_wcard,
1673 case RENAME_FLAG_HARD_LINK:
1674 if (src_has_wcard || dest_has_wcard) {
1676 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1678 status = hardlink_internals(ctx, conn,
1685 case RENAME_FLAG_COPY:
1686 if (src_has_wcard || dest_has_wcard) {
1688 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1690 status = copy_internals(ctx, conn, req,
1696 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1697 status = NT_STATUS_INVALID_PARAMETER;
1700 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1704 if (!NT_STATUS_IS_OK(status)) {
1705 if (open_was_deferred(req->mid)) {
1706 /* We have re-scheduled this call. */
1710 reply_nterror(req, status);
1714 reply_outbuf(req, 0, 0);
1716 END_PROFILE(SMBntrename);
1720 /****************************************************************************
1721 Reply to a notify change - queue the request and
1722 don't allow a directory to be opened.
1723 ****************************************************************************/
1725 static void smbd_smb1_notify_reply(struct smb_request *req,
1726 NTSTATUS error_code,
1727 uint8_t *buf, size_t len)
1729 send_nt_replies(req->conn, req, error_code, (char *)buf, len, NULL, 0);
1732 static void call_nt_transact_notify_change(connection_struct *conn,
1733 struct smb_request *req,
1737 uint32 parameter_count,
1738 char **ppdata, uint32 data_count,
1739 uint32 max_data_count,
1740 uint32 max_param_count)
1742 uint16 *setup = *ppsetup;
1748 if(setup_count < 6) {
1749 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1753 fsp = file_fsp(req, SVAL(setup,4));
1754 filter = IVAL(setup, 0);
1755 recursive = (SVAL(setup, 6) != 0) ? True : False;
1757 DEBUG(3,("call_nt_transact_notify_change\n"));
1760 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
1765 char *filter_string;
1767 if (!(filter_string = notify_filter_string(NULL, filter))) {
1768 reply_nterror(req,NT_STATUS_NO_MEMORY);
1772 DEBUG(3,("call_nt_transact_notify_change: notify change "
1773 "called on %s, filter = %s, recursive = %d\n",
1774 fsp_str_dbg(fsp), filter_string, recursive));
1776 TALLOC_FREE(filter_string);
1779 if((!fsp->is_directory) || (conn != fsp->conn)) {
1780 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1784 if (fsp->notify == NULL) {
1786 status = change_notify_create(fsp, filter, recursive);
1788 if (!NT_STATUS_IS_OK(status)) {
1789 DEBUG(10, ("change_notify_create returned %s\n",
1790 nt_errstr(status)));
1791 reply_nterror(req, status);
1796 if (fsp->notify->num_changes != 0) {
1799 * We've got changes pending, respond immediately
1803 * TODO: write a torture test to check the filtering behaviour
1807 change_notify_reply(req,
1811 smbd_smb1_notify_reply);
1814 * change_notify_reply() above has independently sent its
1821 * No changes pending, queue the request
1824 status = change_notify_add_request(req,
1828 smbd_smb1_notify_reply);
1829 if (!NT_STATUS_IS_OK(status)) {
1830 reply_nterror(req, status);
1835 /****************************************************************************
1836 Reply to an NT transact rename command.
1837 ****************************************************************************/
1839 static void call_nt_transact_rename(connection_struct *conn,
1840 struct smb_request *req,
1841 uint16 **ppsetup, uint32 setup_count,
1842 char **ppparams, uint32 parameter_count,
1843 char **ppdata, uint32 data_count,
1844 uint32 max_data_count)
1846 char *params = *ppparams;
1847 char *new_name = NULL;
1848 files_struct *fsp = NULL;
1849 bool dest_has_wcard = False;
1851 TALLOC_CTX *ctx = talloc_tos();
1853 if(parameter_count < 5) {
1854 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1858 fsp = file_fsp(req, SVAL(params, 0));
1859 if (!check_fsp(conn, req, fsp)) {
1862 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1863 parameter_count - 4,
1864 STR_TERMINATE, &status, &dest_has_wcard);
1865 if (!NT_STATUS_IS_OK(status)) {
1866 reply_nterror(req, status);
1871 * W2K3 ignores this request as the RAW-RENAME test
1872 * demonstrates, so we do.
1874 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1876 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1877 fsp_str_dbg(fsp), new_name));
1882 /******************************************************************************
1883 Fake up a completely empty SD.
1884 *******************************************************************************/
1886 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, struct security_descriptor **ppsd)
1890 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1892 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1893 return NT_STATUS_NO_MEMORY;
1896 return NT_STATUS_OK;
1899 /****************************************************************************
1900 Reply to query a security descriptor.
1901 Callable from SMB2 and SMB2.
1902 If it returns NT_STATUS_BUFFER_TOO_SMALL, pdata_size is initialized with
1904 ****************************************************************************/
1906 NTSTATUS smbd_do_query_security_desc(connection_struct *conn,
1907 TALLOC_CTX *mem_ctx,
1909 uint32_t security_info_wanted,
1910 uint32_t max_data_count,
1911 uint8_t **ppmarshalled_sd,
1915 struct security_descriptor *psd = NULL;
1918 * Get the permissions to return.
1921 if ((security_info_wanted & SECINFO_SACL) &&
1922 !(fsp->access_mask & SEC_FLAG_SYSTEM_SECURITY)) {
1923 return NT_STATUS_ACCESS_DENIED;
1926 if ((security_info_wanted & (SECINFO_DACL|SECINFO_OWNER|SECINFO_GROUP)) &&
1927 !(fsp->access_mask & SEC_STD_READ_CONTROL)) {
1928 return NT_STATUS_ACCESS_DENIED;
1931 if (security_info_wanted & (SECINFO_DACL|SECINFO_OWNER|
1932 SECINFO_GROUP|SECINFO_SACL)) {
1933 /* Don't return SECINFO_LABEL if anything else was
1934 requested. See bug #8458. */
1935 security_info_wanted &= ~SECINFO_LABEL;
1938 if (!lp_nt_acl_support(SNUM(conn))) {
1939 status = get_null_nt_acl(mem_ctx, &psd);
1940 } else if (security_info_wanted & SECINFO_LABEL) {
1941 /* Like W2K3 return a null object. */
1942 status = get_null_nt_acl(mem_ctx, &psd);
1944 status = SMB_VFS_FGET_NT_ACL(
1945 fsp, security_info_wanted, &psd);
1947 if (!NT_STATUS_IS_OK(status)) {
1951 if (!(security_info_wanted & SECINFO_OWNER)) {
1952 psd->owner_sid = NULL;
1954 if (!(security_info_wanted & SECINFO_GROUP)) {
1955 psd->group_sid = NULL;
1957 if (!(security_info_wanted & SECINFO_DACL)) {
1958 psd->type &= ~SEC_DESC_DACL_PRESENT;
1961 if (!(security_info_wanted & SECINFO_SACL)) {
1962 psd->type &= ~SEC_DESC_SACL_PRESENT;
1966 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1967 * present in the reply to match Windows behavior */
1968 if (psd->sacl == NULL &&
1969 security_info_wanted & SECINFO_SACL)
1970 psd->type |= SEC_DESC_SACL_PRESENT;
1971 if (psd->dacl == NULL &&
1972 security_info_wanted & SECINFO_DACL)
1973 psd->type |= SEC_DESC_DACL_PRESENT;
1975 if (security_info_wanted & SECINFO_LABEL) {
1976 /* Like W2K3 return a null object. */
1977 psd->owner_sid = NULL;
1978 psd->group_sid = NULL;
1981 psd->type &= ~(SEC_DESC_DACL_PRESENT|SEC_DESC_SACL_PRESENT);
1984 *psd_size = ndr_size_security_descriptor(psd, 0);
1986 DEBUG(3,("smbd_do_query_security_desc: sd_size = %lu.\n",
1987 (unsigned long)*psd_size));
1989 if (DEBUGLEVEL >= 10) {
1990 DEBUG(10,("smbd_do_query_security_desc for file %s\n",
1992 NDR_PRINT_DEBUG(security_descriptor, psd);
1995 if (max_data_count < *psd_size) {
1997 return NT_STATUS_BUFFER_TOO_SMALL;
2000 status = marshall_sec_desc(mem_ctx, psd,
2001 ppmarshalled_sd, psd_size);
2003 if (!NT_STATUS_IS_OK(status)) {
2009 return NT_STATUS_OK;
2012 /****************************************************************************
2013 SMB1 reply to query a security descriptor.
2014 ****************************************************************************/
2016 static void call_nt_transact_query_security_desc(connection_struct *conn,
2017 struct smb_request *req,
2021 uint32 parameter_count,
2024 uint32 max_data_count)
2026 char *params = *ppparams;
2027 char *data = *ppdata;
2029 uint32 security_info_wanted;
2030 files_struct *fsp = NULL;
2032 uint8_t *marshalled_sd = NULL;
2034 if(parameter_count < 8) {
2035 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2039 fsp = file_fsp(req, SVAL(params,0));
2041 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2045 security_info_wanted = IVAL(params,4);
2047 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
2048 "info_wanted = 0x%x\n", fsp_str_dbg(fsp),
2049 (unsigned int)security_info_wanted));
2051 params = nttrans_realloc(ppparams, 4);
2052 if(params == NULL) {
2053 reply_nterror(req, NT_STATUS_NO_MEMORY);
2058 * Get the permissions to return.
2061 status = smbd_do_query_security_desc(conn,
2064 security_info_wanted,
2069 if (NT_STATUS_EQUAL(status, NT_STATUS_BUFFER_TOO_SMALL)) {
2070 SIVAL(params,0,(uint32_t)sd_size);
2071 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
2072 params, 4, NULL, 0);
2076 if (!NT_STATUS_IS_OK(status)) {
2077 reply_nterror(req, status);
2081 SMB_ASSERT(sd_size > 0);
2083 SIVAL(params,0,(uint32_t)sd_size);
2085 if (max_data_count < sd_size) {
2086 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
2087 params, 4, NULL, 0);
2092 * Allocate the data we will return.
2095 data = nttrans_realloc(ppdata, sd_size);
2097 reply_nterror(req, NT_STATUS_NO_MEMORY);
2101 memcpy(data, marshalled_sd, sd_size);
2103 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
2108 /****************************************************************************
2109 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
2110 ****************************************************************************/
2112 static void call_nt_transact_set_security_desc(connection_struct *conn,
2113 struct smb_request *req,
2117 uint32 parameter_count,
2120 uint32 max_data_count)
2122 char *params= *ppparams;
2123 char *data = *ppdata;
2124 files_struct *fsp = NULL;
2125 uint32 security_info_sent = 0;
2128 if(parameter_count < 8) {
2129 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2133 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
2134 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2138 if (!CAN_WRITE(fsp->conn)) {
2139 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
2143 if(!lp_nt_acl_support(SNUM(conn))) {
2147 security_info_sent = IVAL(params,4);
2149 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
2150 fsp_str_dbg(fsp), (unsigned int)security_info_sent));
2152 if (data_count == 0) {
2153 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2157 status = set_sd_blob(fsp, (uint8 *)data, data_count, security_info_sent);
2159 if (!NT_STATUS_IS_OK(status)) {
2160 reply_nterror(req, status);
2165 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2170 * Implement the default fsctl operation.
2173 static bool vfswrap_logged_ioctl_message = false;
2176 * In 3.6 we do not have a SMB_VFS_FSCTL() function
2177 * it's just faked to make it more look like
2180 NTSTATUS smb_fsctl(struct files_struct *fsp,
2183 uint16_t req_flags, /* Needed for UNICODE ... */
2184 const uint8_t *_in_data,
2186 uint8_t **_out_data,
2187 uint32_t max_out_len,
2190 const char *in_data = (const char *)_in_data;
2191 char **out_data = (char **)_out_data;
2194 case FSCTL_SET_SPARSE:
2196 bool set_sparse = true;
2199 if (in_len >= 1 && in_data[0] == 0) {
2203 status = file_set_sparse(fsp->conn, fsp, set_sparse);
2205 DEBUG(NT_STATUS_IS_OK(status) ? 10 : 9,
2206 ("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
2207 smb_fname_str_dbg(fsp->fsp_name), set_sparse,
2208 nt_errstr(status)));
2213 case FSCTL_CREATE_OR_GET_OBJECT_ID:
2215 unsigned char objid[16];
2216 char *return_data = NULL;
2218 /* This should return the object-id on this file.
2219 * I think I'll make this be the inode+dev. JRA.
2222 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fsp->fnum));
2224 *out_len = (max_out_len >= 64) ? 64 : max_out_len;
2225 /* Hmmm, will this cause problems if less data asked for? */
2226 return_data = talloc_array(ctx, char, 64);
2227 if (return_data == NULL) {
2228 return NT_STATUS_NO_MEMORY;
2231 /* For backwards compatibility only store the dev/inode. */
2232 push_file_id_16(return_data, &fsp->file_id);
2233 memcpy(return_data+16,create_volume_objectid(fsp->conn,objid),16);
2234 push_file_id_16(return_data+32, &fsp->file_id);
2235 *out_data = return_data;
2236 return NT_STATUS_OK;
2239 case FSCTL_GET_REPARSE_POINT:
2241 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
2242 DEBUG(10, ("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp->fnum));
2243 return NT_STATUS_NOT_A_REPARSE_POINT;
2246 case FSCTL_SET_REPARSE_POINT:
2248 /* Fail it with STATUS_NOT_A_REPARSE_POINT */
2249 DEBUG(10, ("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp->fnum));
2250 return NT_STATUS_NOT_A_REPARSE_POINT;
2253 case FSCTL_GET_SHADOW_COPY_DATA:
2256 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
2257 * and return their volume names. If max_data_count is 16, then it is just
2258 * asking for the number of volumes and length of the combined names.
2260 * pdata is the data allocated by our caller, but that uses
2261 * total_data_count (which is 0 in our case) rather than max_data_count.
2262 * Allocate the correct amount and return the pointer to let
2263 * it be deallocated when we return.
2265 struct shadow_copy_data *shadow_data = NULL;
2266 bool labels = False;
2267 uint32 labels_data_count = 0;
2269 char *cur_pdata = NULL;
2271 if (max_out_len < 16) {
2272 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
2274 return NT_STATUS_INVALID_PARAMETER;
2277 if (max_out_len > 16) {
2281 shadow_data = talloc_zero(ctx, struct shadow_copy_data);
2282 if (shadow_data == NULL) {
2283 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2284 return NT_STATUS_NO_MEMORY;
2288 * Call the VFS routine to actually do the work.
2290 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2291 TALLOC_FREE(shadow_data);
2292 if (errno == ENOSYS) {
2293 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2294 fsp->conn->connectpath));
2295 return NT_STATUS_NOT_SUPPORTED;
2297 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2298 fsp->conn->connectpath));
2299 return NT_STATUS_UNSUCCESSFUL;
2303 labels_data_count = (shadow_data->num_volumes * 2 *
2304 sizeof(SHADOW_COPY_LABEL)) + 2;
2309 *out_len = 12 + labels_data_count + 4;
2312 if (max_out_len < *out_len) {
2313 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2314 max_out_len, *out_len));
2315 TALLOC_FREE(shadow_data);
2316 return NT_STATUS_BUFFER_TOO_SMALL;
2319 cur_pdata = talloc_array(ctx, char, *out_len);
2320 if (cur_pdata == NULL) {
2321 TALLOC_FREE(shadow_data);
2322 return NT_STATUS_NO_MEMORY;
2325 *out_data = cur_pdata;
2327 /* num_volumes 4 bytes */
2328 SIVAL(cur_pdata, 0, shadow_data->num_volumes);
2331 /* num_labels 4 bytes */
2332 SIVAL(cur_pdata, 4, shadow_data->num_volumes);
2335 /* needed_data_count 4 bytes */
2336 SIVAL(cur_pdata, 8, labels_data_count + 4);
2340 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2341 shadow_data->num_volumes, fsp_str_dbg(fsp)));
2342 if (labels && shadow_data->labels) {
2343 for (i=0; i<shadow_data->num_volumes; i++) {
2344 srvstr_push(cur_pdata, req_flags,
2345 cur_pdata, shadow_data->labels[i],
2346 2 * sizeof(SHADOW_COPY_LABEL),
2347 STR_UNICODE|STR_TERMINATE);
2348 cur_pdata += 2 * sizeof(SHADOW_COPY_LABEL);
2349 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2353 TALLOC_FREE(shadow_data);
2355 return NT_STATUS_OK;
2358 case FSCTL_FIND_FILES_BY_SID:
2360 /* pretend this succeeded -
2362 * we have to send back a list with all files owned by this SID
2364 * but I have to check that --metze
2370 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n", fsp->fnum));
2373 /* NT_STATUS_BUFFER_TOO_SMALL maybe? */
2374 return NT_STATUS_INVALID_PARAMETER;
2377 sid_len = MIN(in_len - 4,SID_MAX_SIZE);
2379 /* unknown 4 bytes: this is not the length of the sid :-( */
2380 /*unknown = IVAL(pdata,0);*/
2382 if (!sid_parse(in_data + 4, sid_len, &sid)) {
2383 return NT_STATUS_INVALID_PARAMETER;
2385 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2387 if (!sid_to_uid(&sid, &uid)) {
2388 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2389 sid_string_dbg(&sid),
2390 (unsigned long)sid_len));
2394 /* we can take a look at the find source :-)
2396 * find ./ -uid $uid -name '*' is what we need here
2399 * and send 4bytes len and then NULL terminated unicode strings
2402 * but I don't know how to deal with the paged results
2403 * (maybe we can hang the result anywhere in the fsp struct)
2405 * but I don't know how to deal with the paged results
2406 * (maybe we can hang the result anywhere in the fsp struct)
2408 * we don't send all files at once
2409 * and at the next we should *not* start from the beginning,
2410 * so we have to cache the result
2415 /* this works for now... */
2416 return NT_STATUS_OK;
2419 case FSCTL_QUERY_ALLOCATED_RANGES:
2421 /* FIXME: This is just a dummy reply, telling that all of the
2422 * file is allocated. MKS cp needs that.
2423 * Adding the real allocated ranges via FIEMAP on Linux
2424 * and SEEK_DATA/SEEK_HOLE on Solaris is needed to make
2425 * this FSCTL correct for sparse files.
2428 uint64_t offset, length;
2429 char *out_data_tmp = NULL;
2432 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: data_count(%u) != 16 is invalid!\n",
2434 return NT_STATUS_INVALID_PARAMETER;
2437 if (max_out_len < 16) {
2438 DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_out_len (%u) < 16 is invalid!\n",
2440 return NT_STATUS_INVALID_PARAMETER;
2443 offset = BVAL(in_data,0);
2444 length = BVAL(in_data,8);
2446 if (offset + length < offset) {
2447 /* No 64-bit integer wrap. */
2448 return NT_STATUS_INVALID_PARAMETER;
2451 /* Shouldn't this be SMB_VFS_STAT ... ? */
2452 status = vfs_stat_fsp(fsp);
2453 if (!NT_STATUS_IS_OK(status)) {
2458 out_data_tmp = talloc_array(ctx, char, *out_len);
2459 if (out_data_tmp == NULL) {
2460 DEBUG(10, ("unable to allocate memory for response\n"));
2461 return NT_STATUS_NO_MEMORY;
2464 if (offset > fsp->fsp_name->st.st_ex_size ||
2465 fsp->fsp_name->st.st_ex_size == 0 ||
2467 memset(out_data_tmp, 0, *out_len);
2469 uint64_t end = offset + length;
2470 end = MIN(end, fsp->fsp_name->st.st_ex_size);
2471 SBVAL(out_data_tmp, 0, 0);
2472 SBVAL(out_data_tmp, 8, end);
2475 *out_data = out_data_tmp;
2477 return NT_STATUS_OK;
2480 case FSCTL_IS_VOLUME_DIRTY:
2482 DEBUG(10,("FSCTL_IS_VOLUME_DIRTY: called on FID[0x%04X] "
2483 "(but not implemented)\n", fsp->fnum));
2485 * http://msdn.microsoft.com/en-us/library/cc232128%28PROT.10%29.aspx
2486 * says we have to respond with NT_STATUS_INVALID_PARAMETER
2488 return NT_STATUS_INVALID_PARAMETER;
2493 * Only print once ... unfortunately there could be lots of
2494 * different FSCTLs that are called.
2496 if (!vfswrap_logged_ioctl_message) {
2497 vfswrap_logged_ioctl_message = true;
2498 DEBUG(2, ("%s (0x%x): Currently not implemented.\n",
2499 __FUNCTION__, function));
2503 return NT_STATUS_NOT_SUPPORTED;
2506 /****************************************************************************
2508 ****************************************************************************/
2510 static void call_nt_transact_ioctl(connection_struct *conn,
2511 struct smb_request *req,
2512 uint16 **ppsetup, uint32 setup_count,
2513 char **ppparams, uint32 parameter_count,
2514 char **ppdata, uint32 data_count,
2515 uint32 max_data_count)
2523 char *out_data = NULL;
2524 uint32 out_data_len = 0;
2525 char *pdata = *ppdata;
2526 TALLOC_CTX *ctx = talloc_tos();
2528 if (setup_count != 8) {
2529 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
2530 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2534 function = IVAL(*ppsetup, 0);
2535 fidnum = SVAL(*ppsetup, 4);
2536 isFSctl = CVAL(*ppsetup, 6);
2537 compfilter = CVAL(*ppsetup, 7);
2539 DEBUG(10, ("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
2540 function, fidnum, isFSctl, compfilter));
2542 fsp=file_fsp(req, fidnum);
2545 * We don't really implement IOCTLs, especially on files.
2548 DEBUG(10, ("isFSctl: 0x%02X indicates IOCTL, not FSCTL!\n",
2550 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2554 /* Has to be for an open file! */
2555 if (!check_fsp_open(conn, req, fsp)) {
2560 * out_data might be allocated by the VFS module, but talloc should be
2561 * used, and should be cleaned up when the request ends.
2563 status = smb_fsctl(fsp,
2569 (uint8_t **)&out_data,
2572 if (!NT_STATUS_IS_OK(status)) {
2573 reply_nterror(req, status);
2575 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, out_data, out_data_len);
2580 #ifdef HAVE_SYS_QUOTAS
2581 /****************************************************************************
2582 Reply to get user quota
2583 ****************************************************************************/
2585 static void call_nt_transact_get_user_quota(connection_struct *conn,
2586 struct smb_request *req,
2590 uint32 parameter_count,
2593 uint32 max_data_count)
2595 NTSTATUS nt_status = NT_STATUS_OK;
2596 char *params = *ppparams;
2597 char *pdata = *ppdata;
2599 int data_len=0,param_len=0;
2602 files_struct *fsp = NULL;
2606 bool start_enum = True;
2607 SMB_NTQUOTA_STRUCT qt;
2608 SMB_NTQUOTA_LIST *tmp_list;
2609 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2614 if (get_current_uid(conn) != 0) {
2615 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2616 "[%s]\n", lp_servicename(SNUM(conn)),
2617 conn->session_info->unix_name));
2618 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
2623 * Ensure minimum number of parameters sent.
2626 if (parameter_count < 4) {
2627 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2628 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2632 /* maybe we can check the quota_fnum */
2633 fsp = file_fsp(req, SVAL(params,0));
2634 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2635 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2636 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2640 /* the NULL pointer checking for fsp->fake_file_handle->pd
2641 * is done by CHECK_NTQUOTA_HANDLE_OK()
2643 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2645 level = SVAL(params,2);
2647 /* unknown 12 bytes leading in params */
2650 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2651 /* seems that we should continue with the enum here --metze */
2653 if (qt_handle->quota_list!=NULL &&
2654 qt_handle->tmp_list==NULL) {
2657 free_ntquota_list(&(qt_handle->quota_list));
2659 /* Realloc the size of parameters and data we will return */
2661 params = nttrans_realloc(ppparams, param_len);
2662 if(params == NULL) {
2663 reply_nterror(req, NT_STATUS_NO_MEMORY);
2668 SIVAL(params,0,data_len);
2675 case TRANSACT_GET_USER_QUOTA_LIST_START:
2677 if (qt_handle->quota_list==NULL &&
2678 qt_handle->tmp_list==NULL) {
2682 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2683 reply_nterror(req, NT_STATUS_INTERNAL_ERROR);
2687 /* Realloc the size of parameters and data we will return */
2689 params = nttrans_realloc(ppparams, param_len);
2690 if(params == NULL) {
2691 reply_nterror(req, NT_STATUS_NO_MEMORY);
2695 /* we should not trust the value in max_data_count*/
2696 max_data_count = MIN(max_data_count,2048);
2698 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2700 reply_nterror(req, NT_STATUS_NO_MEMORY);
2706 /* set params Size of returned Quota Data 4 bytes*/
2707 /* but set it later when we know it */
2709 /* for each entry push the data */
2712 qt_handle->tmp_list = qt_handle->quota_list;
2715 tmp_list = qt_handle->tmp_list;
2717 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2718 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2720 sid_len = ndr_size_dom_sid(
2721 &tmp_list->quotas->sid, 0);
2722 entry_len = 40 + sid_len;
2724 /* nextoffset entry 4 bytes */
2725 SIVAL(entry,0,entry_len);
2727 /* then the len of the SID 4 bytes */
2728 SIVAL(entry,4,sid_len);
2730 /* unknown data 8 bytes uint64_t */
2731 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2733 /* the used disk space 8 bytes uint64_t */
2734 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2736 /* the soft quotas 8 bytes uint64_t */
2737 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2739 /* the hard quotas 8 bytes uint64_t */
2740 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2742 /* and now the SID */
2743 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2746 qt_handle->tmp_list = tmp_list;
2748 /* overwrite the offset of the last entry */
2749 SIVAL(entry-entry_len,0,0);
2751 data_len = 4+qt_len;
2752 /* overwrite the params quota_data_len */
2753 SIVAL(params,0,data_len);
2757 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2759 /* unknown 4 bytes IVAL(pdata,0) */
2761 if (data_count < 8) {
2762 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2763 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2767 sid_len = IVAL(pdata,4);
2768 /* Ensure this is less than 1mb. */
2769 if (sid_len > (1024*1024)) {
2770 reply_nterror(req, NT_STATUS_NO_MEMORY);
2774 if (data_count < 8+sid_len) {
2775 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2776 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2780 data_len = 4+40+sid_len;
2782 if (max_data_count < data_len) {
2783 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2784 max_data_count, data_len));
2786 SIVAL(params,0,data_len);
2788 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2792 if (!sid_parse(pdata+8,sid_len,&sid)) {
2793 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2797 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2800 * we have to return zero's in all fields
2801 * instead of returning an error here
2806 /* Realloc the size of parameters and data we will return */
2808 params = nttrans_realloc(ppparams, param_len);
2809 if(params == NULL) {
2810 reply_nterror(req, NT_STATUS_NO_MEMORY);
2814 pdata = nttrans_realloc(ppdata, data_len);
2816 reply_nterror(req, NT_STATUS_NO_MEMORY);
2822 /* set params Size of returned Quota Data 4 bytes*/
2823 SIVAL(params,0,data_len);
2825 /* nextoffset entry 4 bytes */
2828 /* then the len of the SID 4 bytes */
2829 SIVAL(entry,4,sid_len);
2831 /* unknown data 8 bytes uint64_t */
2832 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2834 /* the used disk space 8 bytes uint64_t */
2835 SBIG_UINT(entry,16,qt.usedspace);
2837 /* the soft quotas 8 bytes uint64_t */
2838 SBIG_UINT(entry,24,qt.softlim);
2840 /* the hard quotas 8 bytes uint64_t */
2841 SBIG_UINT(entry,32,qt.hardlim);
2843 /* and now the SID */
2844 sid_linearize(entry+40, sid_len, &sid);
2849 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2850 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
2855 send_nt_replies(conn, req, nt_status, params, param_len,
2859 /****************************************************************************
2860 Reply to set user quota
2861 ****************************************************************************/
2863 static void call_nt_transact_set_user_quota(connection_struct *conn,
2864 struct smb_request *req,
2868 uint32 parameter_count,
2871 uint32 max_data_count)
2873 char *params = *ppparams;
2874 char *pdata = *ppdata;
2875 int data_len=0,param_len=0;
2876 SMB_NTQUOTA_STRUCT qt;
2879 files_struct *fsp = NULL;
2884 if (get_current_uid(conn) != 0) {
2885 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2886 "[%s]\n", lp_servicename(SNUM(conn)),
2887 conn->session_info->unix_name));
2888 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
2893 * Ensure minimum number of parameters sent.
2896 if (parameter_count < 2) {
2897 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2898 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2902 /* maybe we can check the quota_fnum */
2903 fsp = file_fsp(req, SVAL(params,0));
2904 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2905 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2906 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2910 if (data_count < 40) {
2911 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2912 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2916 /* offset to next quota record.
2917 * 4 bytes IVAL(pdata,0)
2922 sid_len = IVAL(pdata,4);
2924 if (data_count < 40+sid_len || (40+sid_len < sid_len)) {
2925 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2926 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2930 /* unknown 8 bytes in pdata
2931 * maybe its the change time in NTTIME
2934 /* the used space 8 bytes (uint64_t)*/
2935 qt.usedspace = BVAL(pdata,16);
2937 /* the soft quotas 8 bytes (uint64_t)*/
2938 qt.softlim = BVAL(pdata,24);
2940 /* the hard quotas 8 bytes (uint64_t)*/
2941 qt.hardlim = BVAL(pdata,32);
2943 if (!sid_parse(pdata+40,sid_len,&sid)) {
2944 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2948 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2950 /* 44 unknown bytes left... */
2952 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2953 reply_nterror(req, NT_STATUS_INTERNAL_ERROR);
2957 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2960 #endif /* HAVE_SYS_QUOTAS */
2962 static void handle_nttrans(connection_struct *conn,
2963 struct trans_state *state,
2964 struct smb_request *req)
2966 if (get_Protocol() >= PROTOCOL_NT1) {
2967 req->flags2 |= 0x40; /* IS_LONG_NAME */
2968 SSVAL(req->inbuf,smb_flg2,req->flags2);
2972 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2974 /* Now we must call the relevant NT_TRANS function */
2975 switch(state->call) {
2976 case NT_TRANSACT_CREATE:
2978 START_PROFILE(NT_transact_create);
2979 call_nt_transact_create(
2981 &state->setup, state->setup_count,
2982 &state->param, state->total_param,
2983 &state->data, state->total_data,
2984 state->max_data_return);
2985 END_PROFILE(NT_transact_create);
2989 case NT_TRANSACT_IOCTL:
2991 START_PROFILE(NT_transact_ioctl);
2992 call_nt_transact_ioctl(
2994 &state->setup, state->setup_count,
2995 &state->param, state->total_param,
2996 &state->data, state->total_data,
2997 state->max_data_return);
2998 END_PROFILE(NT_transact_ioctl);
3002 case NT_TRANSACT_SET_SECURITY_DESC:
3004 START_PROFILE(NT_transact_set_security_desc);
3005 call_nt_transact_set_security_desc(
3007 &state->setup, state->setup_count,
3008 &state->param, state->total_param,
3009 &state->data, state->total_data,
3010 state->max_data_return);
3011 END_PROFILE(NT_transact_set_security_desc);
3015 case NT_TRANSACT_NOTIFY_CHANGE:
3017 START_PROFILE(NT_transact_notify_change);
3018 call_nt_transact_notify_change(
3020 &state->setup, state->setup_count,
3021 &state->param, state->total_param,
3022 &state->data, state->total_data,
3023 state->max_data_return,
3024 state->max_param_return);
3025 END_PROFILE(NT_transact_notify_change);
3029 case NT_TRANSACT_RENAME:
3031 START_PROFILE(NT_transact_rename);
3032 call_nt_transact_rename(
3034 &state->setup, state->setup_count,
3035 &state->param, state->total_param,
3036 &state->data, state->total_data,
3037 state->max_data_return);
3038 END_PROFILE(NT_transact_rename);
3042 case NT_TRANSACT_QUERY_SECURITY_DESC:
3044 START_PROFILE(NT_transact_query_security_desc);
3045 call_nt_transact_query_security_desc(
3047 &state->setup, state->setup_count,
3048 &state->param, state->total_param,
3049 &state->data, state->total_data,
3050 state->max_data_return);
3051 END_PROFILE(NT_transact_query_security_desc);
3055 #ifdef HAVE_SYS_QUOTAS
3056 case NT_TRANSACT_GET_USER_QUOTA:
3058 START_PROFILE(NT_transact_get_user_quota);
3059 call_nt_transact_get_user_quota(
3061 &state->setup, state->setup_count,
3062 &state->param, state->total_param,
3063 &state->data, state->total_data,
3064 state->max_data_return);
3065 END_PROFILE(NT_transact_get_user_quota);
3069 case NT_TRANSACT_SET_USER_QUOTA:
3071 START_PROFILE(NT_transact_set_user_quota);
3072 call_nt_transact_set_user_quota(
3074 &state->setup, state->setup_count,
3075 &state->param, state->total_param,
3076 &state->data, state->total_data,
3077 state->max_data_return);
3078 END_PROFILE(NT_transact_set_user_quota);
3081 #endif /* HAVE_SYS_QUOTAS */
3084 /* Error in request */
3085 DEBUG(0,("handle_nttrans: Unknown request %d in "
3086 "nttrans call\n", state->call));
3087 reply_nterror(req, NT_STATUS_INVALID_LEVEL);
3093 /****************************************************************************
3094 Reply to a SMBNTtrans.
3095 ****************************************************************************/
3097 void reply_nttrans(struct smb_request *req)
3099 connection_struct *conn = req->conn;
3104 uint16 function_code;
3106 struct trans_state *state;
3108 START_PROFILE(SMBnttrans);
3110 if (req->wct < 19) {
3111 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3112 END_PROFILE(SMBnttrans);
3116 pscnt = IVAL(req->vwv+9, 1);
3117 psoff = IVAL(req->vwv+11, 1);
3118 dscnt = IVAL(req->vwv+13, 1);
3119 dsoff = IVAL(req->vwv+15, 1);
3120 function_code = SVAL(req->vwv+18, 0);
3122 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
3123 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
3124 END_PROFILE(SMBnttrans);
3128 result = allow_new_trans(conn->pending_trans, req->mid);
3129 if (!NT_STATUS_IS_OK(result)) {
3130 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
3131 reply_nterror(req, result);
3132 END_PROFILE(SMBnttrans);
3136 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
3137 reply_nterror(req, NT_STATUS_NO_MEMORY);
3138 END_PROFILE(SMBnttrans);
3142 state->cmd = SMBnttrans;
3144 state->mid = req->mid;
3145 state->vuid = req->vuid;
3146 state->total_data = IVAL(req->vwv+3, 1);
3148 state->total_param = IVAL(req->vwv+1, 1);
3149 state->param = NULL;
3150 state->max_data_return = IVAL(req->vwv+7, 1);
3151 state->max_param_return = IVAL(req->vwv+5, 1);
3153 /* setup count is in *words* */
3154 state->setup_count = 2*CVAL(req->vwv+17, 1);
3155 state->setup = NULL;
3156 state->call = function_code;
3158 DEBUG(10, ("num_setup=%u, "
3159 "param_total=%u, this_param=%u, max_param=%u, "
3160 "data_total=%u, this_data=%u, max_data=%u, "
3161 "param_offset=%u, data_offset=%u\n",
3162 (unsigned)state->setup_count,
3163 (unsigned)state->total_param, (unsigned)pscnt,
3164 (unsigned)state->max_param_return,
3165 (unsigned)state->total_data, (unsigned)dscnt,
3166 (unsigned)state->max_data_return,
3167 (unsigned)psoff, (unsigned)dsoff));
3170 * All nttrans messages we handle have smb_wct == 19 +
3171 * state->setup_count. Ensure this is so as a sanity check.
3174 if(req->wct != 19 + (state->setup_count/2)) {
3175 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
3176 req->wct, 19 + (state->setup_count/2)));
3180 /* Don't allow more than 128mb for each value. */
3181 if ((state->total_data > (1024*1024*128)) ||
3182 (state->total_param > (1024*1024*128))) {
3183 reply_nterror(req, NT_STATUS_NO_MEMORY);
3184 END_PROFILE(SMBnttrans);
3188 if ((dscnt > state->total_data) || (pscnt > state->total_param))
3191 if (state->total_data) {
3193 if (trans_oob(state->total_data, 0, dscnt)
3194 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
3198 /* Can't use talloc here, the core routines do realloc on the
3199 * params and data. */
3200 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
3201 DEBUG(0,("reply_nttrans: data malloc fail for %u "
3202 "bytes !\n", (unsigned int)state->total_data));
3204 reply_nterror(req, NT_STATUS_NO_MEMORY);
3205 END_PROFILE(SMBnttrans);
3209 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
3212 if (state->total_param) {
3214 if (trans_oob(state->total_param, 0, pscnt)
3215 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
3219 /* Can't use talloc here, the core routines do realloc on the
3220 * params and data. */
3221 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
3222 DEBUG(0,("reply_nttrans: param malloc fail for %u "
3223 "bytes !\n", (unsigned int)state->total_param));
3224 SAFE_FREE(state->data);
3226 reply_nterror(req, NT_STATUS_NO_MEMORY);
3227 END_PROFILE(SMBnttrans);
3231 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
3234 state->received_data = dscnt;
3235 state->received_param = pscnt;
3237 if(state->setup_count > 0) {
3238 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
3239 state->setup_count));
3242 * No overflow possible here, state->setup_count is an
3243 * unsigned int, being filled by a single byte from
3244 * CVAL(req->vwv+13, 0) above. The cast in the comparison
3245 * below is not necessary, it's here to clarify things. The
3246 * validity of req->vwv and req->wct has been checked in
3247 * init_smb_request already.
3249 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
3253 state->setup = (uint16 *)TALLOC(state, state->setup_count);
3254 if (state->setup == NULL) {
3255 DEBUG(0,("reply_nttrans : Out of memory\n"));
3256 SAFE_FREE(state->data);
3257 SAFE_FREE(state->param);
3259 reply_nterror(req, NT_STATUS_NO_MEMORY);
3260 END_PROFILE(SMBnttrans);
3264 memcpy(state->setup, req->vwv+19, state->setup_count);
3265 dump_data(10, (uint8 *)state->setup, state->setup_count);
3268 if ((state->received_data == state->total_data) &&
3269 (state->received_param == state->total_param)) {
3270 handle_nttrans(conn, state, req);
3271 SAFE_FREE(state->param);
3272 SAFE_FREE(state->data);
3274 END_PROFILE(SMBnttrans);
3278 DLIST_ADD(conn->pending_trans, state);
3280 /* We need to send an interim response then receive the rest
3281 of the parameter/data bytes */
3282 reply_outbuf(req, 0, 0);
3283 show_msg((char *)req->outbuf);
3284 END_PROFILE(SMBnttrans);
3289 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
3290 SAFE_FREE(state->data);
3291 SAFE_FREE(state->param);
3293 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3294 END_PROFILE(SMBnttrans);
3298 /****************************************************************************
3299 Reply to a SMBnttranss
3300 ****************************************************************************/
3302 void reply_nttranss(struct smb_request *req)
3304 connection_struct *conn = req->conn;
3305 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
3306 struct trans_state *state;
3308 START_PROFILE(SMBnttranss);
3310 show_msg((char *)req->inbuf);
3312 /* Windows clients expect all replies to
3313 an NT transact secondary (SMBnttranss 0xA1)
3314 to have a command code of NT transact
3315 (SMBnttrans 0xA0). See bug #8989 for details. */
3316 req->cmd = SMBnttrans;
3318 if (req->wct < 18) {
3319 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3320 END_PROFILE(SMBnttranss);
3324 for (state = conn->pending_trans; state != NULL;
3325 state = state->next) {
3326 if (state->mid == req->mid) {
3331 if ((state == NULL) || (state->cmd != SMBnttrans)) {
3332 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3333 END_PROFILE(SMBnttranss);
3337 /* Revise state->total_param and state->total_data in case they have
3338 changed downwards */
3339 if (IVAL(req->vwv+1, 1) < state->total_param) {
3340 state->total_param = IVAL(req->vwv+1, 1);
3342 if (IVAL(req->vwv+3, 1) < state->total_data) {
3343 state->total_data = IVAL(req->vwv+3, 1);
3346 pcnt = IVAL(req->vwv+5, 1);
3347 poff = IVAL(req->vwv+7, 1);
3348 pdisp = IVAL(req->vwv+9, 1);
3350 dcnt = IVAL(req->vwv+11, 1);
3351 doff = IVAL(req->vwv+13, 1);
3352 ddisp = IVAL(req->vwv+15, 1);
3354 state->received_param += pcnt;
3355 state->received_data += dcnt;
3357 if ((state->received_data > state->total_data) ||
3358 (state->received_param > state->total_param))
3362 if (trans_oob(state->total_param, pdisp, pcnt)
3363 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
3366 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
3370 if (trans_oob(state->total_data, ddisp, dcnt)
3371 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
3374 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
3377 if ((state->received_param < state->total_param) ||
3378 (state->received_data < state->total_data)) {
3379 END_PROFILE(SMBnttranss);
3383 handle_nttrans(conn, state, req);
3385 DLIST_REMOVE(conn->pending_trans, state);
3386 SAFE_FREE(state->data);
3387 SAFE_FREE(state->param);
3389 END_PROFILE(SMBnttranss);
3394 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3395 DLIST_REMOVE(conn->pending_trans, state);
3396 SAFE_FREE(state->data);
3397 SAFE_FREE(state->param);
3399 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3400 END_PROFILE(SMBnttranss);