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 if (NT_STATUS_V(nt_error)) {
72 error_packet_set((char *)req->outbuf,
76 show_msg((char *)req->outbuf);
77 if (!srv_send_smb(smbd_server_fd(),
80 IS_CONN_ENCRYPTED(conn),
82 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
84 TALLOC_FREE(req->outbuf);
89 * When sending params and data ensure that both are nicely aligned.
90 * Only do this alignment when there is also data to send - else
91 * can cause NT redirector problems.
94 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
95 data_alignment_offset = 4 - (params_to_send % 4);
99 * Space is bufsize minus Netbios over TCP header minus SMB header.
100 * The alignment_offset is to align the param bytes on a four byte
101 * boundary (2 bytes for data len, one byte pad).
102 * NT needs this to work correctly.
105 useable_space = max_send - (smb_size
108 + data_alignment_offset);
110 if (useable_space < 0) {
111 char *msg = talloc_asprintf(
113 "send_nt_replies failed sanity useable_space = %d!!!",
115 DEBUG(0, ("%s\n", msg));
116 exit_server_cleanly(msg);
119 while (params_to_send || data_to_send) {
122 * Calculate whether we will totally or partially fill this packet.
125 total_sent_thistime = params_to_send + data_to_send;
128 * We can never send more than useable_space.
131 total_sent_thistime = MIN(total_sent_thistime, useable_space);
133 reply_outbuf(req, 18,
134 total_sent_thistime + alignment_offset
135 + data_alignment_offset);
138 * We might have had SMBnttranss in req->inbuf, fix that.
140 SCVAL(req->outbuf, smb_com, SMBnttrans);
143 * Set total params and data to be sent.
146 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
147 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
150 * Calculate how many parameters and data we can fit into
151 * this packet. Parameters get precedence.
154 params_sent_thistime = MIN(params_to_send,useable_space);
155 data_sent_thistime = useable_space - params_sent_thistime;
156 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
158 SIVAL(req->outbuf, smb_ntr_ParameterCount,
159 params_sent_thistime);
161 if(params_sent_thistime == 0) {
162 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
163 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
166 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
167 * parameter bytes, however the first 4 bytes of outbuf are
168 * the Netbios over TCP header. Thus use smb_base() to subtract
169 * them from the calculation.
172 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
173 ((smb_buf(req->outbuf)+alignment_offset)
174 - smb_base(req->outbuf)));
176 * Absolute displacement of param bytes sent in this packet.
179 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
184 * Deal with the data portion.
187 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
189 if(data_sent_thistime == 0) {
190 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
191 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
194 * The offset of the data bytes is the offset of the
195 * parameter bytes plus the number of parameters being sent this time.
198 SIVAL(req->outbuf, smb_ntr_DataOffset,
199 ((smb_buf(req->outbuf)+alignment_offset) -
200 smb_base(req->outbuf))
201 + params_sent_thistime + data_alignment_offset);
202 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
206 * Copy the param bytes into the packet.
209 if(params_sent_thistime) {
210 if (alignment_offset != 0) {
211 memset(smb_buf(req->outbuf), 0,
214 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
215 params_sent_thistime);
219 * Copy in the data bytes
222 if(data_sent_thistime) {
223 if (data_alignment_offset != 0) {
224 memset((smb_buf(req->outbuf)+alignment_offset+
225 params_sent_thistime), 0,
226 data_alignment_offset);
228 memcpy(smb_buf(req->outbuf)+alignment_offset
229 +params_sent_thistime+data_alignment_offset,
230 pd,data_sent_thistime);
233 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
234 params_sent_thistime, data_sent_thistime, useable_space));
235 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
236 params_to_send, data_to_send, paramsize, datasize));
238 if (NT_STATUS_V(nt_error)) {
239 error_packet_set((char *)req->outbuf,
244 /* Send the packet */
245 show_msg((char *)req->outbuf);
246 if (!srv_send_smb(smbd_server_fd(),
249 IS_CONN_ENCRYPTED(conn),
251 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
254 TALLOC_FREE(req->outbuf);
256 pp += params_sent_thistime;
257 pd += data_sent_thistime;
259 params_to_send -= params_sent_thistime;
260 data_to_send -= data_sent_thistime;
266 if(params_to_send < 0 || data_to_send < 0) {
267 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
268 params_to_send, data_to_send));
269 exit_server_cleanly("send_nt_replies: internal error");
274 /****************************************************************************
275 Reply to an NT create and X call on a pipe
276 ****************************************************************************/
278 static void nt_open_pipe(char *fname, connection_struct *conn,
279 struct smb_request *req, int *ppnum)
284 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
286 /* Strip \\ off the name. */
289 status = open_np_file(req, fname, &fsp);
290 if (!NT_STATUS_IS_OK(status)) {
291 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
292 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
296 reply_nterror(req, status);
304 /****************************************************************************
305 Reply to an NT create and X call for pipes.
306 ****************************************************************************/
308 static void do_ntcreate_pipe_open(connection_struct *conn,
309 struct smb_request *req)
314 uint32 flags = IVAL(req->vwv+3, 1);
315 TALLOC_CTX *ctx = talloc_tos();
317 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
320 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
324 nt_open_pipe(fname, conn, req, &pnum);
332 * Deal with pipe return.
335 if (flags & EXTENDED_RESPONSE_REQUIRED) {
336 /* This is very strange. We
337 * return 50 words, but only set
338 * the wcnt to 42 ? It's definately
339 * what happens on the wire....
341 reply_outbuf(req, 50, 0);
342 SCVAL(req->outbuf,smb_wct,42);
344 reply_outbuf(req, 34, 0);
347 p = (char *)req->outbuf + smb_vwv2;
351 SIVAL(p,0,FILE_WAS_OPENED);
354 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
357 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
359 SSVAL(p,2, 0x5FF); /* ? */
362 if (flags & EXTENDED_RESPONSE_REQUIRED) {
364 SIVAL(p,0,FILE_GENERIC_ALL);
366 * For pipes W2K3 seems to return
368 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
370 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
373 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
378 /****************************************************************************
379 Reply to an NT create and X call.
380 ****************************************************************************/
382 void reply_ntcreate_and_X(struct smb_request *req)
384 connection_struct *conn = req->conn;
385 struct smb_filename *smb_fname = NULL;
389 uint32 file_attributes;
391 uint32 create_disposition;
392 uint32 create_options;
394 uint64_t allocation_size;
395 /* Breakout the oplock request bits so we can set the
396 reply bits separately. */
398 SMB_OFF_T file_len = 0;
400 files_struct *fsp = NULL;
402 struct timespec c_timespec;
403 struct timespec a_timespec;
404 struct timespec m_timespec;
405 struct timespec write_time_ts;
408 uint8_t oplock_granted = NO_OPLOCK_RETURN;
409 TALLOC_CTX *ctx = talloc_tos();
411 START_PROFILE(SMBntcreateX);
414 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
418 flags = IVAL(req->vwv+3, 1);
419 access_mask = IVAL(req->vwv+7, 1);
420 file_attributes = IVAL(req->vwv+13, 1);
421 share_access = IVAL(req->vwv+15, 1);
422 create_disposition = IVAL(req->vwv+17, 1);
423 create_options = IVAL(req->vwv+19, 1);
424 root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
426 allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
427 #ifdef LARGE_SMB_OFF_T
428 allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
431 srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
432 STR_TERMINATE, &status);
434 if (!NT_STATUS_IS_OK(status)) {
435 reply_nterror(req, status);
439 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
440 "file_attributes = 0x%x, share_access = 0x%x, "
441 "create_disposition = 0x%x create_options = 0x%x "
442 "root_dir_fid = 0x%x, fname = %s\n",
444 (unsigned int)access_mask,
445 (unsigned int)file_attributes,
446 (unsigned int)share_access,
447 (unsigned int)create_disposition,
448 (unsigned int)create_options,
449 (unsigned int)root_dir_fid,
453 * we need to remove ignored bits when they come directly from the client
454 * because we reuse some of them for internal stuff
456 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
459 * If it's an IPC, use the pipe handler.
463 if (lp_nt_pipe_support()) {
464 do_ntcreate_pipe_open(conn, req);
467 reply_doserror(req, ERRDOS, ERRnoaccess);
471 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
472 if (oplock_request) {
473 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
477 status = filename_convert(ctx,
479 req->flags2 & FLAGS2_DFS_PATHNAMES,
484 if (!NT_STATUS_IS_OK(status)) {
485 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
487 NT_STATUS_PATH_NOT_COVERED,
491 reply_nterror(req, status);
495 status = SMB_VFS_CREATE_FILE(
498 root_dir_fid, /* root_dir_fid */
499 smb_fname, /* fname */
500 access_mask, /* access_mask */
501 share_access, /* share_access */
502 create_disposition, /* create_disposition*/
503 create_options, /* create_options */
504 file_attributes, /* file_attributes */
505 oplock_request, /* oplock_request */
506 allocation_size, /* allocation_size */
512 if (!NT_STATUS_IS_OK(status)) {
513 if (open_was_deferred(req->mid)) {
514 /* We have re-scheduled this call, no error. */
517 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
518 reply_botherror(req, status, ERRDOS, ERRfilexists);
521 reply_nterror(req, status);
527 * If the caller set the extended oplock request bit
528 * and we granted one (by whatever means) - set the
529 * correct bit for extended oplock reply.
532 if (oplock_request &&
533 (lp_fake_oplocks(SNUM(conn))
534 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
537 * Exclusive oplock granted
540 if (flags & REQUEST_BATCH_OPLOCK) {
541 oplock_granted = BATCH_OPLOCK_RETURN;
543 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
545 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
546 oplock_granted = LEVEL_II_OPLOCK_RETURN;
548 oplock_granted = NO_OPLOCK_RETURN;
551 file_len = smb_fname->st.st_ex_size;
552 fattr = dos_mode(conn, smb_fname);
554 fattr = FILE_ATTRIBUTE_NORMAL;
557 if (flags & EXTENDED_RESPONSE_REQUIRED) {
558 /* This is very strange. We
559 * return 50 words, but only set
560 * the wcnt to 42 ? It's definately
561 * what happens on the wire....
563 reply_outbuf(req, 50, 0);
564 SCVAL(req->outbuf,smb_wct,42);
566 reply_outbuf(req, 34, 0);
569 p = (char *)req->outbuf + smb_vwv2;
571 SCVAL(p, 0, oplock_granted);
574 SSVAL(p,0,fsp->fnum);
576 if ((create_disposition == FILE_SUPERSEDE)
577 && (info == FILE_WAS_OVERWRITTEN)) {
578 SIVAL(p,0,FILE_WAS_SUPERSEDED);
584 /* Deal with other possible opens having a modified
586 ZERO_STRUCT(write_time_ts);
587 get_file_infos(fsp->file_id, NULL, &write_time_ts);
588 if (!null_timespec(write_time_ts)) {
589 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
593 c_timespec = smb_fname->st.st_ex_btime;
594 a_timespec = smb_fname->st.st_ex_atime;
595 m_timespec = smb_fname->st.st_ex_mtime;
597 if (lp_dos_filetime_resolution(SNUM(conn))) {
598 dos_filetime_timespec(&c_timespec);
599 dos_filetime_timespec(&a_timespec);
600 dos_filetime_timespec(&m_timespec);
603 put_long_date_timespec(p, c_timespec); /* create time. */
605 put_long_date_timespec(p, a_timespec); /* access time */
607 put_long_date_timespec(p, m_timespec); /* write time */
609 put_long_date_timespec(p, m_timespec); /* change time */
611 SIVAL(p,0,fattr); /* File Attributes. */
613 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
615 SOFF_T(p,0,file_len);
617 if (flags & EXTENDED_RESPONSE_REQUIRED) {
621 SCVAL(p,0,fsp->is_directory ? 1 : 0);
623 if (flags & EXTENDED_RESPONSE_REQUIRED) {
626 if (fsp->is_directory ||
627 can_write_to_file(conn, smb_fname)) {
628 perms = FILE_GENERIC_ALL;
630 perms = FILE_GENERIC_READ|FILE_EXECUTE;
635 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
636 fsp->fnum, smb_fname_str_dbg(smb_fname)));
640 TALLOC_FREE(smb_fname);
641 END_PROFILE(SMBntcreateX);
645 /****************************************************************************
646 Reply to a NT_TRANSACT_CREATE call to open a pipe.
647 ****************************************************************************/
649 static void do_nt_transact_create_pipe(connection_struct *conn,
650 struct smb_request *req,
651 uint16 **ppsetup, uint32 setup_count,
652 char **ppparams, uint32 parameter_count,
653 char **ppdata, uint32 data_count)
656 char *params = *ppparams;
662 TALLOC_CTX *ctx = talloc_tos();
665 * Ensure minimum number of parameters sent.
668 if(parameter_count < 54) {
669 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
670 reply_doserror(req, ERRDOS, ERRnoaccess);
674 flags = IVAL(params,0);
676 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
677 parameter_count-53, STR_TERMINATE,
679 if (!NT_STATUS_IS_OK(status)) {
680 reply_nterror(req, status);
684 nt_open_pipe(fname, conn, req, &pnum);
691 /* Realloc the size of parameters and data we will return */
692 if (flags & EXTENDED_RESPONSE_REQUIRED) {
693 /* Extended response is 32 more byyes. */
698 params = nttrans_realloc(ppparams, param_len);
700 reply_doserror(req, ERRDOS, ERRnomem);
705 SCVAL(p,0,NO_OPLOCK_RETURN);
710 SIVAL(p,0,FILE_WAS_OPENED);
714 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
717 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
719 SSVAL(p,2, 0x5FF); /* ? */
722 if (flags & EXTENDED_RESPONSE_REQUIRED) {
724 SIVAL(p,0,FILE_GENERIC_ALL);
726 * For pipes W2K3 seems to return
728 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
730 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
733 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
735 /* Send the required number of replies */
736 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
741 /****************************************************************************
742 Internal fn to set security descriptors.
743 ****************************************************************************/
745 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
746 uint32 security_info_sent)
748 SEC_DESC *psd = NULL;
751 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
755 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
757 if (!NT_STATUS_IS_OK(status)) {
761 if (psd->owner_sid == NULL) {
762 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
764 if (psd->group_sid == NULL) {
765 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
768 /* Convert all the generic bits. */
769 security_acl_map_generic(psd->dacl, &file_generic_mapping);
770 security_acl_map_generic(psd->sacl, &file_generic_mapping);
772 if (DEBUGLEVEL >= 10) {
773 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
774 NDR_PRINT_DEBUG(security_descriptor, psd);
777 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
784 /****************************************************************************
785 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
786 ****************************************************************************/
788 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
790 struct ea_list *ea_list_head = NULL;
797 while (offset + 4 <= data_size) {
798 size_t next_offset = IVAL(pdata,offset);
799 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
805 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
806 if (next_offset == 0) {
809 offset += next_offset;
815 /****************************************************************************
816 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
817 ****************************************************************************/
819 static void call_nt_transact_create(connection_struct *conn,
820 struct smb_request *req,
821 uint16 **ppsetup, uint32 setup_count,
822 char **ppparams, uint32 parameter_count,
823 char **ppdata, uint32 data_count,
824 uint32 max_data_count)
826 struct smb_filename *smb_fname = NULL;
828 char *params = *ppparams;
829 char *data = *ppdata;
830 /* Breakout the oplock request bits so we can set the reply bits separately. */
832 SMB_OFF_T file_len = 0;
834 files_struct *fsp = NULL;
838 uint32 file_attributes;
840 uint32 create_disposition;
841 uint32 create_options;
843 struct security_descriptor *sd = NULL;
846 struct timespec c_timespec;
847 struct timespec a_timespec;
848 struct timespec m_timespec;
849 struct timespec write_time_ts;
850 struct ea_list *ea_list = NULL;
853 uint64_t allocation_size;
855 uint8_t oplock_granted;
856 TALLOC_CTX *ctx = talloc_tos();
858 DEBUG(5,("call_nt_transact_create\n"));
861 * If it's an IPC, use the pipe handler.
865 if (lp_nt_pipe_support()) {
866 do_nt_transact_create_pipe(
868 ppsetup, setup_count,
869 ppparams, parameter_count,
873 reply_doserror(req, ERRDOS, ERRnoaccess);
878 * Ensure minimum number of parameters sent.
881 if(parameter_count < 54) {
882 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
883 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
887 flags = IVAL(params,0);
888 access_mask = IVAL(params,8);
889 file_attributes = IVAL(params,20);
890 share_access = IVAL(params,24);
891 create_disposition = IVAL(params,28);
892 create_options = IVAL(params,32);
893 sd_len = IVAL(params,36);
894 ea_len = IVAL(params,40);
895 root_dir_fid = (uint16)IVAL(params,4);
896 allocation_size = (uint64_t)IVAL(params,12);
897 #ifdef LARGE_SMB_OFF_T
898 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
902 * we need to remove ignored bits when they come directly from the client
903 * because we reuse some of them for internal stuff
905 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
907 /* Ensure the data_len is correct for the sd and ea values given. */
908 if ((ea_len + sd_len > data_count)
909 || (ea_len > data_count) || (sd_len > data_count)
910 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
911 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
912 "%u, data_count = %u\n", (unsigned int)ea_len,
913 (unsigned int)sd_len, (unsigned int)data_count));
914 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
919 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
922 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
924 if (!NT_STATUS_IS_OK(status)) {
925 DEBUG(10, ("call_nt_transact_create: "
926 "unmarshall_sec_desc failed: %s\n",
928 reply_nterror(req, status);
934 if (!lp_ea_support(SNUM(conn))) {
935 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
936 "EA's not supported.\n",
937 (unsigned int)ea_len));
938 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
943 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
944 "too small (should be more than 10)\n",
945 (unsigned int)ea_len ));
946 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
950 /* We have already checked that ea_len <= data_count here. */
951 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
953 if (ea_list == NULL) {
954 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
959 srvstr_get_path(ctx, params, req->flags2, &fname,
960 params+53, parameter_count-53,
961 STR_TERMINATE, &status);
962 if (!NT_STATUS_IS_OK(status)) {
963 reply_nterror(req, status);
967 status = filename_convert(ctx,
969 req->flags2 & FLAGS2_DFS_PATHNAMES,
974 if (!NT_STATUS_IS_OK(status)) {
975 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
977 NT_STATUS_PATH_NOT_COVERED,
981 reply_nterror(req, status);
985 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
986 if (oplock_request) {
987 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
991 status = SMB_VFS_CREATE_FILE(
994 root_dir_fid, /* root_dir_fid */
995 smb_fname, /* fname */
996 access_mask, /* access_mask */
997 share_access, /* share_access */
998 create_disposition, /* create_disposition*/
999 create_options, /* create_options */
1000 file_attributes, /* file_attributes */
1001 oplock_request, /* oplock_request */
1002 allocation_size, /* allocation_size */
1004 ea_list, /* ea_list */
1008 if(!NT_STATUS_IS_OK(status)) {
1009 if (open_was_deferred(req->mid)) {
1010 /* We have re-scheduled this call, no error. */
1013 reply_openerror(req, status);
1018 * If the caller set the extended oplock request bit
1019 * and we granted one (by whatever means) - set the
1020 * correct bit for extended oplock reply.
1023 if (oplock_request &&
1024 (lp_fake_oplocks(SNUM(conn))
1025 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1028 * Exclusive oplock granted
1031 if (flags & REQUEST_BATCH_OPLOCK) {
1032 oplock_granted = BATCH_OPLOCK_RETURN;
1034 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1036 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1037 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1039 oplock_granted = NO_OPLOCK_RETURN;
1042 file_len = smb_fname->st.st_ex_size;
1043 fattr = dos_mode(conn, smb_fname);
1045 fattr = FILE_ATTRIBUTE_NORMAL;
1048 /* Realloc the size of parameters and data we will return */
1049 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1050 /* Extended response is 32 more byyes. */
1055 params = nttrans_realloc(ppparams, param_len);
1056 if(params == NULL) {
1057 reply_doserror(req, ERRDOS, ERRnomem);
1062 SCVAL(p, 0, oplock_granted);
1065 SSVAL(p,0,fsp->fnum);
1067 if ((create_disposition == FILE_SUPERSEDE)
1068 && (info == FILE_WAS_OVERWRITTEN)) {
1069 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1075 /* Deal with other possible opens having a modified
1077 ZERO_STRUCT(write_time_ts);
1078 get_file_infos(fsp->file_id, NULL, &write_time_ts);
1079 if (!null_timespec(write_time_ts)) {
1080 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
1084 c_timespec = smb_fname->st.st_ex_btime;
1085 a_timespec = smb_fname->st.st_ex_atime;
1086 m_timespec = smb_fname->st.st_ex_mtime;
1088 if (lp_dos_filetime_resolution(SNUM(conn))) {
1089 dos_filetime_timespec(&c_timespec);
1090 dos_filetime_timespec(&a_timespec);
1091 dos_filetime_timespec(&m_timespec);
1094 put_long_date_timespec(p, c_timespec); /* create time. */
1096 put_long_date_timespec(p, a_timespec); /* access time */
1098 put_long_date_timespec(p, m_timespec); /* write time */
1100 put_long_date_timespec(p, m_timespec); /* change time */
1102 SIVAL(p,0,fattr); /* File Attributes. */
1104 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1106 SOFF_T(p,0,file_len);
1108 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1112 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1114 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1117 if (fsp->is_directory ||
1118 can_write_to_file(conn, smb_fname)) {
1119 perms = FILE_GENERIC_ALL;
1121 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1126 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1127 smb_fname_str_dbg(smb_fname)));
1129 /* Send the required number of replies */
1130 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1132 TALLOC_FREE(smb_fname);
1136 /****************************************************************************
1137 Reply to a NT CANCEL request.
1138 conn POINTER CAN BE NULL HERE !
1139 ****************************************************************************/
1141 void reply_ntcancel(struct smb_request *req)
1144 * Go through and cancel any pending change notifies.
1147 START_PROFILE(SMBntcancel);
1148 srv_cancel_sign_response(smbd_server_conn);
1149 remove_pending_change_notify_requests_by_mid(req->mid);
1150 remove_pending_lock_requests_by_mid(req->mid);
1152 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1154 END_PROFILE(SMBntcancel);
1158 /****************************************************************************
1160 ****************************************************************************/
1162 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1163 connection_struct *conn,
1164 struct smb_request *req,
1165 struct smb_filename *smb_fname_src,
1166 struct smb_filename *smb_fname_dst,
1169 files_struct *fsp1,*fsp2;
1173 NTSTATUS status = NT_STATUS_OK;
1176 if (!CAN_WRITE(conn)) {
1177 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1181 /* Source must already exist. */
1182 if (!VALID_STAT(smb_fname_src->st)) {
1183 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1187 /* Ensure attributes match. */
1188 fattr = dos_mode(conn, smb_fname_src);
1189 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1190 status = NT_STATUS_NO_SUCH_FILE;
1194 /* Disallow if dst file already exists. */
1195 if (VALID_STAT(smb_fname_dst->st)) {
1196 status = NT_STATUS_OBJECT_NAME_COLLISION;
1200 /* No links from a directory. */
1201 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1202 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1206 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1207 smb_fname_str_dbg(smb_fname_src),
1208 smb_fname_str_dbg(smb_fname_dst)));
1210 status = SMB_VFS_CREATE_FILE(
1213 0, /* root_dir_fid */
1214 smb_fname_src, /* fname */
1215 FILE_READ_DATA, /* access_mask */
1216 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1218 FILE_OPEN, /* create_disposition*/
1219 0, /* create_options */
1220 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1221 NO_OPLOCK, /* oplock_request */
1222 0, /* allocation_size */
1228 if (!NT_STATUS_IS_OK(status)) {
1232 status = SMB_VFS_CREATE_FILE(
1235 0, /* root_dir_fid */
1236 smb_fname_dst, /* fname */
1237 FILE_WRITE_DATA, /* access_mask */
1238 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1240 FILE_CREATE, /* create_disposition*/
1241 0, /* create_options */
1242 fattr, /* file_attributes */
1243 NO_OPLOCK, /* oplock_request */
1244 0, /* allocation_size */
1250 if (!NT_STATUS_IS_OK(status)) {
1251 close_file(NULL, fsp1, ERROR_CLOSE);
1255 if (smb_fname_src->st.st_ex_size) {
1256 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1260 * As we are opening fsp1 read-only we only expect
1261 * an error on close on fsp2 if we are out of space.
1262 * Thus we don't look at the error return from the
1265 close_file(NULL, fsp1, NORMAL_CLOSE);
1267 /* Ensure the modtime is set correctly on the destination file. */
1268 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1270 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1272 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1273 creates the file. This isn't the correct thing to do in the copy
1275 if (!parent_dirname(talloc_tos(), smb_fname_dst->base_name, &parent,
1277 status = NT_STATUS_NO_MEMORY;
1280 file_set_dosmode(conn, smb_fname_dst, fattr, parent, false);
1281 TALLOC_FREE(parent);
1283 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1284 status = NT_STATUS_DISK_FULL;
1288 if (!NT_STATUS_IS_OK(status)) {
1289 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1290 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1291 smb_fname_str_dbg(smb_fname_dst)));
1297 /****************************************************************************
1298 Reply to a NT rename request.
1299 ****************************************************************************/
1301 void reply_ntrename(struct smb_request *req)
1303 connection_struct *conn = req->conn;
1304 struct smb_filename *smb_fname_old = NULL;
1305 struct smb_filename *smb_fname_new = NULL;
1306 char *oldname = NULL;
1307 char *newname = NULL;
1310 bool src_has_wcard = False;
1311 bool dest_has_wcard = False;
1314 TALLOC_CTX *ctx = talloc_tos();
1316 START_PROFILE(SMBntrename);
1319 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1323 attrs = SVAL(req->vwv+0, 0);
1324 rename_type = SVAL(req->vwv+1, 0);
1326 p = (const char *)req->buf + 1;
1327 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1328 &status, &src_has_wcard);
1329 if (!NT_STATUS_IS_OK(status)) {
1330 reply_nterror(req, status);
1334 if (ms_has_wild(oldname)) {
1335 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1340 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1341 &status, &dest_has_wcard);
1342 if (!NT_STATUS_IS_OK(status)) {
1343 reply_nterror(req, status);
1347 /* The newname must begin with a ':' if the oldname contains a ':'. */
1348 if (strchr_m(oldname, ':') && (newname[0] != ':')) {
1349 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1353 /* rename_internals() calls unix_convert(), so don't call it here. */
1354 if (rename_type != RENAME_FLAG_RENAME) {
1355 status = filename_convert(ctx, conn,
1356 req->flags2 & FLAGS2_DFS_PATHNAMES,
1360 if (!NT_STATUS_IS_OK(status)) {
1361 if (NT_STATUS_EQUAL(status,
1362 NT_STATUS_PATH_NOT_COVERED)) {
1363 reply_botherror(req,
1364 NT_STATUS_PATH_NOT_COVERED,
1365 ERRSRV, ERRbadpath);
1368 reply_nterror(req, status);
1372 status = filename_convert(ctx, conn,
1373 req->flags2 & FLAGS2_DFS_PATHNAMES,
1377 if (!NT_STATUS_IS_OK(status)) {
1378 if (NT_STATUS_EQUAL(status,
1379 NT_STATUS_PATH_NOT_COVERED)) {
1380 reply_botherror(req,
1381 NT_STATUS_PATH_NOT_COVERED,
1382 ERRSRV, ERRbadpath);
1385 reply_nterror(req, status);
1389 DEBUG(3,("reply_ntrename: %s -> %s\n",
1390 smb_fname_str_dbg(smb_fname_old),
1391 smb_fname_str_dbg(smb_fname_new)));
1394 switch(rename_type) {
1395 case RENAME_FLAG_RENAME:
1396 status = resolve_dfspath(ctx, conn,
1398 FLAGS2_DFS_PATHNAMES),
1400 if (!NT_STATUS_IS_OK(status)) {
1401 DEBUG(10,("resolve_dfspath failed for name %s "
1402 "with %s\n", oldname,
1403 nt_errstr(status)));
1404 reply_nterror(req, status);
1408 status = resolve_dfspath(ctx, conn,
1410 FLAGS2_DFS_PATHNAMES),
1412 if (!NT_STATUS_IS_OK(status)) {
1413 DEBUG(10,("resolve_dfspath failed for name %s "
1414 "with %s\n", newname,
1415 nt_errstr(status)));
1416 reply_nterror(req, status);
1420 DEBUG(3,("reply_ntrename: %s -> %s\n", oldname,
1423 status = rename_internals(ctx, conn, req, oldname,
1424 newname, attrs, False, src_has_wcard,
1425 dest_has_wcard, DELETE_ACCESS);
1427 case RENAME_FLAG_HARD_LINK:
1428 if (src_has_wcard || dest_has_wcard) {
1430 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1432 status = hardlink_internals(ctx,
1438 case RENAME_FLAG_COPY:
1439 if (src_has_wcard || dest_has_wcard) {
1441 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1443 status = copy_internals(ctx, conn, req,
1449 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1450 status = NT_STATUS_INVALID_PARAMETER;
1453 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1457 if (!NT_STATUS_IS_OK(status)) {
1458 if (open_was_deferred(req->mid)) {
1459 /* We have re-scheduled this call. */
1463 reply_nterror(req, status);
1467 reply_outbuf(req, 0, 0);
1469 END_PROFILE(SMBntrename);
1473 /****************************************************************************
1474 Reply to a notify change - queue the request and
1475 don't allow a directory to be opened.
1476 ****************************************************************************/
1478 static void smbd_smb1_notify_reply(struct smb_request *req,
1479 NTSTATUS error_code,
1480 uint8_t *buf, size_t len)
1482 send_nt_replies(req->conn, req, error_code, (char *)buf, len, NULL, 0);
1485 static void call_nt_transact_notify_change(connection_struct *conn,
1486 struct smb_request *req,
1490 uint32 parameter_count,
1491 char **ppdata, uint32 data_count,
1492 uint32 max_data_count,
1493 uint32 max_param_count)
1495 uint16 *setup = *ppsetup;
1501 if(setup_count < 6) {
1502 reply_doserror(req, ERRDOS, ERRbadfunc);
1506 fsp = file_fsp(req, SVAL(setup,4));
1507 filter = IVAL(setup, 0);
1508 recursive = (SVAL(setup, 6) != 0) ? True : False;
1510 DEBUG(3,("call_nt_transact_notify_change\n"));
1513 reply_doserror(req, ERRDOS, ERRbadfid);
1518 char *filter_string;
1520 if (!(filter_string = notify_filter_string(NULL, filter))) {
1521 reply_nterror(req,NT_STATUS_NO_MEMORY);
1525 DEBUG(3,("call_nt_transact_notify_change: notify change "
1526 "called on %s, filter = %s, recursive = %d\n",
1527 fsp_str_dbg(fsp), filter_string, recursive));
1529 TALLOC_FREE(filter_string);
1532 if((!fsp->is_directory) || (conn != fsp->conn)) {
1533 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1537 if (fsp->notify == NULL) {
1539 status = change_notify_create(fsp, filter, recursive);
1541 if (!NT_STATUS_IS_OK(status)) {
1542 DEBUG(10, ("change_notify_create returned %s\n",
1543 nt_errstr(status)));
1544 reply_nterror(req, status);
1549 if (fsp->notify->num_changes != 0) {
1552 * We've got changes pending, respond immediately
1556 * TODO: write a torture test to check the filtering behaviour
1560 change_notify_reply(fsp->conn, req,
1564 smbd_smb1_notify_reply);
1567 * change_notify_reply() above has independently sent its
1574 * No changes pending, queue the request
1577 status = change_notify_add_request(req,
1581 smbd_smb1_notify_reply);
1582 if (!NT_STATUS_IS_OK(status)) {
1583 reply_nterror(req, status);
1588 /****************************************************************************
1589 Reply to an NT transact rename command.
1590 ****************************************************************************/
1592 static void call_nt_transact_rename(connection_struct *conn,
1593 struct smb_request *req,
1594 uint16 **ppsetup, uint32 setup_count,
1595 char **ppparams, uint32 parameter_count,
1596 char **ppdata, uint32 data_count,
1597 uint32 max_data_count)
1599 char *params = *ppparams;
1600 char *new_name = NULL;
1601 files_struct *fsp = NULL;
1602 bool dest_has_wcard = False;
1604 TALLOC_CTX *ctx = talloc_tos();
1606 if(parameter_count < 5) {
1607 reply_doserror(req, ERRDOS, ERRbadfunc);
1611 fsp = file_fsp(req, SVAL(params, 0));
1612 if (!check_fsp(conn, req, fsp)) {
1615 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1616 parameter_count - 4,
1617 STR_TERMINATE, &status, &dest_has_wcard);
1618 if (!NT_STATUS_IS_OK(status)) {
1619 reply_nterror(req, status);
1624 * W2K3 ignores this request as the RAW-RENAME test
1625 * demonstrates, so we do.
1627 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1629 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1630 fsp_str_dbg(fsp), new_name));
1635 /******************************************************************************
1636 Fake up a completely empty SD.
1637 *******************************************************************************/
1639 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1643 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1645 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1646 return NT_STATUS_NO_MEMORY;
1649 return NT_STATUS_OK;
1652 /****************************************************************************
1653 Reply to query a security descriptor.
1654 ****************************************************************************/
1656 static void call_nt_transact_query_security_desc(connection_struct *conn,
1657 struct smb_request *req,
1661 uint32 parameter_count,
1664 uint32 max_data_count)
1666 char *params = *ppparams;
1667 char *data = *ppdata;
1668 SEC_DESC *psd = NULL;
1670 uint32 security_info_wanted;
1671 files_struct *fsp = NULL;
1675 if(parameter_count < 8) {
1676 reply_doserror(req, ERRDOS, ERRbadfunc);
1680 fsp = file_fsp(req, SVAL(params,0));
1682 reply_doserror(req, ERRDOS, ERRbadfid);
1686 security_info_wanted = IVAL(params,4);
1688 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1689 "info_wanted = 0x%x\n", fsp_str_dbg(fsp),
1690 (unsigned int)security_info_wanted));
1692 params = nttrans_realloc(ppparams, 4);
1693 if(params == NULL) {
1694 reply_doserror(req, ERRDOS, ERRnomem);
1699 * Get the permissions to return.
1702 if (!lp_nt_acl_support(SNUM(conn))) {
1703 status = get_null_nt_acl(talloc_tos(), &psd);
1705 status = SMB_VFS_FGET_NT_ACL(
1706 fsp, security_info_wanted, &psd);
1708 if (!NT_STATUS_IS_OK(status)) {
1709 reply_nterror(req, status);
1713 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1714 * present in the reply to match Windows behavior */
1715 if (psd->sacl == NULL &&
1716 security_info_wanted & SACL_SECURITY_INFORMATION)
1717 psd->type |= SEC_DESC_SACL_PRESENT;
1718 if (psd->dacl == NULL &&
1719 security_info_wanted & DACL_SECURITY_INFORMATION)
1720 psd->type |= SEC_DESC_DACL_PRESENT;
1722 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1724 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1726 if (DEBUGLEVEL >= 10) {
1727 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
1729 NDR_PRINT_DEBUG(security_descriptor, psd);
1732 SIVAL(params,0,(uint32)sd_size);
1734 if (max_data_count < sd_size) {
1735 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1736 params, 4, *ppdata, 0);
1741 * Allocate the data we will point this at.
1744 data = nttrans_realloc(ppdata, sd_size);
1746 reply_doserror(req, ERRDOS, ERRnomem);
1750 status = marshall_sec_desc(talloc_tos(), psd,
1751 &blob.data, &blob.length);
1753 if (!NT_STATUS_IS_OK(status)) {
1754 reply_nterror(req, status);
1758 SMB_ASSERT(sd_size == blob.length);
1759 memcpy(data, blob.data, sd_size);
1761 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1766 /****************************************************************************
1767 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1768 ****************************************************************************/
1770 static void call_nt_transact_set_security_desc(connection_struct *conn,
1771 struct smb_request *req,
1775 uint32 parameter_count,
1778 uint32 max_data_count)
1780 char *params= *ppparams;
1781 char *data = *ppdata;
1782 files_struct *fsp = NULL;
1783 uint32 security_info_sent = 0;
1786 if(parameter_count < 8) {
1787 reply_doserror(req, ERRDOS, ERRbadfunc);
1791 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1792 reply_doserror(req, ERRDOS, ERRbadfid);
1796 if(!lp_nt_acl_support(SNUM(conn))) {
1800 security_info_sent = IVAL(params,4);
1802 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1803 fsp_str_dbg(fsp), (unsigned int)security_info_sent));
1805 if (data_count == 0) {
1806 reply_doserror(req, ERRDOS, ERRnoaccess);
1810 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1812 if (!NT_STATUS_IS_OK(status)) {
1813 reply_nterror(req, status);
1818 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1822 /****************************************************************************
1824 ****************************************************************************/
1826 static void call_nt_transact_ioctl(connection_struct *conn,
1827 struct smb_request *req,
1828 uint16 **ppsetup, uint32 setup_count,
1829 char **ppparams, uint32 parameter_count,
1830 char **ppdata, uint32 data_count,
1831 uint32 max_data_count)
1838 char *pdata = *ppdata;
1840 if (setup_count != 8) {
1841 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1842 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1846 function = IVAL(*ppsetup, 0);
1847 fidnum = SVAL(*ppsetup, 4);
1848 isFSctl = CVAL(*ppsetup, 6);
1849 compfilter = CVAL(*ppsetup, 7);
1851 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1852 function, fidnum, isFSctl, compfilter));
1854 fsp=file_fsp(req, fidnum);
1855 /* this check is done in each implemented function case for now
1856 because I don't want to break anything... --metze
1857 FSP_BELONGS_CONN(fsp,conn);*/
1859 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1862 case FSCTL_SET_SPARSE:
1863 /* pretend this succeeded - tho strictly we should
1864 mark the file sparse (if the local fs supports it)
1865 so we can know if we need to pre-allocate or not */
1867 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1868 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1871 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1873 unsigned char objid[16];
1875 /* This should return the object-id on this file.
1876 * I think I'll make this be the inode+dev. JRA.
1879 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1881 if (!fsp_belongs_conn(conn, req, fsp)) {
1886 pdata = nttrans_realloc(ppdata, data_count);
1887 if (pdata == NULL) {
1888 reply_nterror(req, NT_STATUS_NO_MEMORY);
1892 /* For backwards compatibility only store the dev/inode. */
1893 push_file_id_16(pdata, &fsp->file_id);
1894 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1895 push_file_id_16(pdata+32, &fsp->file_id);
1896 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1901 case FSCTL_GET_REPARSE_POINT:
1902 /* pretend this fail - my winXP does it like this
1906 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1907 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1910 case FSCTL_SET_REPARSE_POINT:
1911 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1915 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1916 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1919 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1922 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1923 * and return their volume names. If max_data_count is 16, then it is just
1924 * asking for the number of volumes and length of the combined names.
1926 * pdata is the data allocated by our caller, but that uses
1927 * total_data_count (which is 0 in our case) rather than max_data_count.
1928 * Allocate the correct amount and return the pointer to let
1929 * it be deallocated when we return.
1931 SHADOW_COPY_DATA *shadow_data = NULL;
1932 TALLOC_CTX *shadow_mem_ctx = NULL;
1933 bool labels = False;
1934 uint32 labels_data_count = 0;
1938 if (!fsp_belongs_conn(conn, req, fsp)) {
1942 if (max_data_count < 16) {
1943 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1945 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1949 if (max_data_count > 16) {
1953 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1954 if (shadow_mem_ctx == NULL) {
1955 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1956 reply_nterror(req, NT_STATUS_NO_MEMORY);
1960 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
1961 if (shadow_data == NULL) {
1962 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1963 talloc_destroy(shadow_mem_ctx);
1964 reply_nterror(req, NT_STATUS_NO_MEMORY);
1968 shadow_data->mem_ctx = shadow_mem_ctx;
1971 * Call the VFS routine to actually do the work.
1973 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1974 talloc_destroy(shadow_data->mem_ctx);
1975 if (errno == ENOSYS) {
1976 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1977 conn->connectpath));
1978 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1981 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1982 conn->connectpath));
1983 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
1988 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
1993 data_count = 12+labels_data_count+4;
1996 if (max_data_count<data_count) {
1997 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1998 max_data_count,data_count));
1999 talloc_destroy(shadow_data->mem_ctx);
2000 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2004 pdata = nttrans_realloc(ppdata, data_count);
2005 if (pdata == NULL) {
2006 talloc_destroy(shadow_data->mem_ctx);
2007 reply_nterror(req, NT_STATUS_NO_MEMORY);
2013 /* num_volumes 4 bytes */
2014 SIVAL(pdata,0,shadow_data->num_volumes);
2017 /* num_labels 4 bytes */
2018 SIVAL(pdata,4,shadow_data->num_volumes);
2021 /* needed_data_count 4 bytes */
2022 SIVAL(pdata,8,labels_data_count);
2026 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2027 shadow_data->num_volumes, fsp_str_dbg(fsp)));
2028 if (labels && shadow_data->labels) {
2029 for (i=0;i<shadow_data->num_volumes;i++) {
2030 srvstr_push(pdata, req->flags2,
2031 cur_pdata, shadow_data->labels[i],
2032 2*sizeof(SHADOW_COPY_LABEL),
2033 STR_UNICODE|STR_TERMINATE);
2034 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2035 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2039 talloc_destroy(shadow_data->mem_ctx);
2041 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2047 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2049 /* pretend this succeeded -
2051 * we have to send back a list with all files owned by this SID
2053 * but I have to check that --metze
2057 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2059 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2061 if (!fsp_belongs_conn(conn, req, fsp)) {
2065 /* unknown 4 bytes: this is not the length of the sid :-( */
2066 /*unknown = IVAL(pdata,0);*/
2068 sid_parse(pdata+4,sid_len,&sid);
2069 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2071 if (!sid_to_uid(&sid, &uid)) {
2072 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2073 sid_string_dbg(&sid),
2074 (unsigned long)sid_len));
2078 /* we can take a look at the find source :-)
2080 * find ./ -uid $uid -name '*' is what we need here
2083 * and send 4bytes len and then NULL terminated unicode strings
2086 * but I don't know how to deal with the paged results
2087 * (maybe we can hang the result anywhere in the fsp struct)
2089 * we don't send all files at once
2090 * and at the next we should *not* start from the beginning,
2091 * so we have to cache the result
2096 /* this works for now... */
2097 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2101 if (!logged_ioctl_message) {
2102 logged_ioctl_message = true; /* Only print this once... */
2103 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2108 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2112 #ifdef HAVE_SYS_QUOTAS
2113 /****************************************************************************
2114 Reply to get user quota
2115 ****************************************************************************/
2117 static void call_nt_transact_get_user_quota(connection_struct *conn,
2118 struct smb_request *req,
2122 uint32 parameter_count,
2125 uint32 max_data_count)
2127 NTSTATUS nt_status = NT_STATUS_OK;
2128 char *params = *ppparams;
2129 char *pdata = *ppdata;
2131 int data_len=0,param_len=0;
2134 files_struct *fsp = NULL;
2138 bool start_enum = True;
2139 SMB_NTQUOTA_STRUCT qt;
2140 SMB_NTQUOTA_LIST *tmp_list;
2141 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2146 if (conn->server_info->utok.uid != 0) {
2147 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2148 "[%s]\n", lp_servicename(SNUM(conn)),
2149 conn->server_info->unix_name));
2150 reply_doserror(req, ERRDOS, ERRnoaccess);
2155 * Ensure minimum number of parameters sent.
2158 if (parameter_count < 4) {
2159 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2160 reply_doserror(req, ERRDOS, ERRinvalidparam);
2164 /* maybe we can check the quota_fnum */
2165 fsp = file_fsp(req, SVAL(params,0));
2166 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2167 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2168 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2172 /* the NULL pointer checking for fsp->fake_file_handle->pd
2173 * is done by CHECK_NTQUOTA_HANDLE_OK()
2175 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2177 level = SVAL(params,2);
2179 /* unknown 12 bytes leading in params */
2182 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2183 /* seems that we should continue with the enum here --metze */
2185 if (qt_handle->quota_list!=NULL &&
2186 qt_handle->tmp_list==NULL) {
2189 free_ntquota_list(&(qt_handle->quota_list));
2191 /* Realloc the size of parameters and data we will return */
2193 params = nttrans_realloc(ppparams, param_len);
2194 if(params == NULL) {
2195 reply_doserror(req, ERRDOS, ERRnomem);
2200 SIVAL(params,0,data_len);
2207 case TRANSACT_GET_USER_QUOTA_LIST_START:
2209 if (qt_handle->quota_list==NULL &&
2210 qt_handle->tmp_list==NULL) {
2214 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2215 reply_doserror(req, ERRSRV, ERRerror);
2219 /* Realloc the size of parameters and data we will return */
2221 params = nttrans_realloc(ppparams, param_len);
2222 if(params == NULL) {
2223 reply_doserror(req, ERRDOS, ERRnomem);
2227 /* we should not trust the value in max_data_count*/
2228 max_data_count = MIN(max_data_count,2048);
2230 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2232 reply_doserror(req, ERRDOS, ERRnomem);
2238 /* set params Size of returned Quota Data 4 bytes*/
2239 /* but set it later when we know it */
2241 /* for each entry push the data */
2244 qt_handle->tmp_list = qt_handle->quota_list;
2247 tmp_list = qt_handle->tmp_list;
2249 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2250 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2252 sid_len = ndr_size_dom_sid(
2253 &tmp_list->quotas->sid, NULL, 0);
2254 entry_len = 40 + sid_len;
2256 /* nextoffset entry 4 bytes */
2257 SIVAL(entry,0,entry_len);
2259 /* then the len of the SID 4 bytes */
2260 SIVAL(entry,4,sid_len);
2262 /* unknown data 8 bytes uint64_t */
2263 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2265 /* the used disk space 8 bytes uint64_t */
2266 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2268 /* the soft quotas 8 bytes uint64_t */
2269 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2271 /* the hard quotas 8 bytes uint64_t */
2272 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2274 /* and now the SID */
2275 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2278 qt_handle->tmp_list = tmp_list;
2280 /* overwrite the offset of the last entry */
2281 SIVAL(entry-entry_len,0,0);
2283 data_len = 4+qt_len;
2284 /* overwrite the params quota_data_len */
2285 SIVAL(params,0,data_len);
2289 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2291 /* unknown 4 bytes IVAL(pdata,0) */
2293 if (data_count < 8) {
2294 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2295 reply_doserror(req, ERRDOS, ERRunknownlevel);
2299 sid_len = IVAL(pdata,4);
2300 /* Ensure this is less than 1mb. */
2301 if (sid_len > (1024*1024)) {
2302 reply_doserror(req, ERRDOS, ERRnomem);
2306 if (data_count < 8+sid_len) {
2307 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2308 reply_doserror(req, ERRDOS, ERRunknownlevel);
2312 data_len = 4+40+sid_len;
2314 if (max_data_count < data_len) {
2315 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2316 max_data_count, data_len));
2318 SIVAL(params,0,data_len);
2320 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2324 sid_parse(pdata+8,sid_len,&sid);
2326 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2329 * we have to return zero's in all fields
2330 * instead of returning an error here
2335 /* Realloc the size of parameters and data we will return */
2337 params = nttrans_realloc(ppparams, param_len);
2338 if(params == NULL) {
2339 reply_doserror(req, ERRDOS, ERRnomem);
2343 pdata = nttrans_realloc(ppdata, data_len);
2345 reply_doserror(req, ERRDOS, ERRnomem);
2351 /* set params Size of returned Quota Data 4 bytes*/
2352 SIVAL(params,0,data_len);
2354 /* nextoffset entry 4 bytes */
2357 /* then the len of the SID 4 bytes */
2358 SIVAL(entry,4,sid_len);
2360 /* unknown data 8 bytes uint64_t */
2361 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2363 /* the used disk space 8 bytes uint64_t */
2364 SBIG_UINT(entry,16,qt.usedspace);
2366 /* the soft quotas 8 bytes uint64_t */
2367 SBIG_UINT(entry,24,qt.softlim);
2369 /* the hard quotas 8 bytes uint64_t */
2370 SBIG_UINT(entry,32,qt.hardlim);
2372 /* and now the SID */
2373 sid_linearize(entry+40, sid_len, &sid);
2378 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2379 reply_doserror(req, ERRSRV, ERRerror);
2384 send_nt_replies(conn, req, nt_status, params, param_len,
2388 /****************************************************************************
2389 Reply to set user quota
2390 ****************************************************************************/
2392 static void call_nt_transact_set_user_quota(connection_struct *conn,
2393 struct smb_request *req,
2397 uint32 parameter_count,
2400 uint32 max_data_count)
2402 char *params = *ppparams;
2403 char *pdata = *ppdata;
2404 int data_len=0,param_len=0;
2405 SMB_NTQUOTA_STRUCT qt;
2408 files_struct *fsp = NULL;
2413 if (conn->server_info->utok.uid != 0) {
2414 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2415 "[%s]\n", lp_servicename(SNUM(conn)),
2416 conn->server_info->unix_name));
2417 reply_doserror(req, ERRDOS, ERRnoaccess);
2422 * Ensure minimum number of parameters sent.
2425 if (parameter_count < 2) {
2426 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2427 reply_doserror(req, ERRDOS, ERRinvalidparam);
2431 /* maybe we can check the quota_fnum */
2432 fsp = file_fsp(req, SVAL(params,0));
2433 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2434 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2435 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2439 if (data_count < 40) {
2440 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2441 reply_doserror(req, ERRDOS, ERRunknownlevel);
2445 /* offset to next quota record.
2446 * 4 bytes IVAL(pdata,0)
2451 sid_len = IVAL(pdata,4);
2453 if (data_count < 40+sid_len) {
2454 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2455 reply_doserror(req, ERRDOS, ERRunknownlevel);
2459 /* unknown 8 bytes in pdata
2460 * maybe its the change time in NTTIME
2463 /* the used space 8 bytes (uint64_t)*/
2464 qt.usedspace = (uint64_t)IVAL(pdata,16);
2465 #ifdef LARGE_SMB_OFF_T
2466 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2467 #else /* LARGE_SMB_OFF_T */
2468 if ((IVAL(pdata,20) != 0)&&
2469 ((qt.usedspace != 0xFFFFFFFF)||
2470 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2471 /* more than 32 bits? */
2472 reply_doserror(req, ERRDOS, ERRunknownlevel);
2475 #endif /* LARGE_SMB_OFF_T */
2477 /* the soft quotas 8 bytes (uint64_t)*/
2478 qt.softlim = (uint64_t)IVAL(pdata,24);
2479 #ifdef LARGE_SMB_OFF_T
2480 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2481 #else /* LARGE_SMB_OFF_T */
2482 if ((IVAL(pdata,28) != 0)&&
2483 ((qt.softlim != 0xFFFFFFFF)||
2484 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2485 /* more than 32 bits? */
2486 reply_doserror(req, ERRDOS, ERRunknownlevel);
2489 #endif /* LARGE_SMB_OFF_T */
2491 /* the hard quotas 8 bytes (uint64_t)*/
2492 qt.hardlim = (uint64_t)IVAL(pdata,32);
2493 #ifdef LARGE_SMB_OFF_T
2494 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2495 #else /* LARGE_SMB_OFF_T */
2496 if ((IVAL(pdata,36) != 0)&&
2497 ((qt.hardlim != 0xFFFFFFFF)||
2498 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2499 /* more than 32 bits? */
2500 reply_doserror(req, ERRDOS, ERRunknownlevel);
2503 #endif /* LARGE_SMB_OFF_T */
2505 sid_parse(pdata+40,sid_len,&sid);
2506 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2508 /* 44 unknown bytes left... */
2510 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2511 reply_doserror(req, ERRSRV, ERRerror);
2515 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2518 #endif /* HAVE_SYS_QUOTAS */
2520 static void handle_nttrans(connection_struct *conn,
2521 struct trans_state *state,
2522 struct smb_request *req)
2524 if (Protocol >= PROTOCOL_NT1) {
2525 req->flags2 |= 0x40; /* IS_LONG_NAME */
2526 SSVAL(req->inbuf,smb_flg2,req->flags2);
2530 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2532 /* Now we must call the relevant NT_TRANS function */
2533 switch(state->call) {
2534 case NT_TRANSACT_CREATE:
2536 START_PROFILE(NT_transact_create);
2537 call_nt_transact_create(
2539 &state->setup, state->setup_count,
2540 &state->param, state->total_param,
2541 &state->data, state->total_data,
2542 state->max_data_return);
2543 END_PROFILE(NT_transact_create);
2547 case NT_TRANSACT_IOCTL:
2549 START_PROFILE(NT_transact_ioctl);
2550 call_nt_transact_ioctl(
2552 &state->setup, state->setup_count,
2553 &state->param, state->total_param,
2554 &state->data, state->total_data,
2555 state->max_data_return);
2556 END_PROFILE(NT_transact_ioctl);
2560 case NT_TRANSACT_SET_SECURITY_DESC:
2562 START_PROFILE(NT_transact_set_security_desc);
2563 call_nt_transact_set_security_desc(
2565 &state->setup, state->setup_count,
2566 &state->param, state->total_param,
2567 &state->data, state->total_data,
2568 state->max_data_return);
2569 END_PROFILE(NT_transact_set_security_desc);
2573 case NT_TRANSACT_NOTIFY_CHANGE:
2575 START_PROFILE(NT_transact_notify_change);
2576 call_nt_transact_notify_change(
2578 &state->setup, state->setup_count,
2579 &state->param, state->total_param,
2580 &state->data, state->total_data,
2581 state->max_data_return,
2582 state->max_param_return);
2583 END_PROFILE(NT_transact_notify_change);
2587 case NT_TRANSACT_RENAME:
2589 START_PROFILE(NT_transact_rename);
2590 call_nt_transact_rename(
2592 &state->setup, state->setup_count,
2593 &state->param, state->total_param,
2594 &state->data, state->total_data,
2595 state->max_data_return);
2596 END_PROFILE(NT_transact_rename);
2600 case NT_TRANSACT_QUERY_SECURITY_DESC:
2602 START_PROFILE(NT_transact_query_security_desc);
2603 call_nt_transact_query_security_desc(
2605 &state->setup, state->setup_count,
2606 &state->param, state->total_param,
2607 &state->data, state->total_data,
2608 state->max_data_return);
2609 END_PROFILE(NT_transact_query_security_desc);
2613 #ifdef HAVE_SYS_QUOTAS
2614 case NT_TRANSACT_GET_USER_QUOTA:
2616 START_PROFILE(NT_transact_get_user_quota);
2617 call_nt_transact_get_user_quota(
2619 &state->setup, state->setup_count,
2620 &state->param, state->total_param,
2621 &state->data, state->total_data,
2622 state->max_data_return);
2623 END_PROFILE(NT_transact_get_user_quota);
2627 case NT_TRANSACT_SET_USER_QUOTA:
2629 START_PROFILE(NT_transact_set_user_quota);
2630 call_nt_transact_set_user_quota(
2632 &state->setup, state->setup_count,
2633 &state->param, state->total_param,
2634 &state->data, state->total_data,
2635 state->max_data_return);
2636 END_PROFILE(NT_transact_set_user_quota);
2639 #endif /* HAVE_SYS_QUOTAS */
2642 /* Error in request */
2643 DEBUG(0,("handle_nttrans: Unknown request %d in "
2644 "nttrans call\n", state->call));
2645 reply_doserror(req, ERRSRV, ERRerror);
2651 /****************************************************************************
2652 Reply to a SMBNTtrans.
2653 ****************************************************************************/
2655 void reply_nttrans(struct smb_request *req)
2657 connection_struct *conn = req->conn;
2662 uint16 function_code;
2664 struct trans_state *state;
2666 START_PROFILE(SMBnttrans);
2668 if (req->wct < 19) {
2669 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2670 END_PROFILE(SMBnttrans);
2674 pscnt = IVAL(req->vwv+9, 1);
2675 psoff = IVAL(req->vwv+11, 1);
2676 dscnt = IVAL(req->vwv+13, 1);
2677 dsoff = IVAL(req->vwv+15, 1);
2678 function_code = SVAL(req->vwv+18, 0);
2680 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2681 reply_doserror(req, ERRSRV, ERRaccess);
2682 END_PROFILE(SMBnttrans);
2686 result = allow_new_trans(conn->pending_trans, req->mid);
2687 if (!NT_STATUS_IS_OK(result)) {
2688 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2689 reply_nterror(req, result);
2690 END_PROFILE(SMBnttrans);
2694 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2695 reply_doserror(req, ERRSRV, ERRaccess);
2696 END_PROFILE(SMBnttrans);
2700 state->cmd = SMBnttrans;
2702 state->mid = req->mid;
2703 state->vuid = req->vuid;
2704 state->total_data = IVAL(req->vwv+3, 1);
2706 state->total_param = IVAL(req->vwv+1, 1);
2707 state->param = NULL;
2708 state->max_data_return = IVAL(req->vwv+7, 1);
2709 state->max_param_return = IVAL(req->vwv+5, 1);
2711 /* setup count is in *words* */
2712 state->setup_count = 2*CVAL(req->vwv+17, 1);
2713 state->setup = NULL;
2714 state->call = function_code;
2716 DEBUG(10, ("num_setup=%u, "
2717 "param_total=%u, this_param=%u, max_param=%u, "
2718 "data_total=%u, this_data=%u, max_data=%u, "
2719 "param_offset=%u, data_offset=%u\n",
2720 (unsigned)state->setup_count,
2721 (unsigned)state->total_param, (unsigned)pscnt,
2722 (unsigned)state->max_param_return,
2723 (unsigned)state->total_data, (unsigned)dscnt,
2724 (unsigned)state->max_data_return,
2725 (unsigned)psoff, (unsigned)dsoff));
2728 * All nttrans messages we handle have smb_wct == 19 +
2729 * state->setup_count. Ensure this is so as a sanity check.
2732 if(req->wct != 19 + (state->setup_count/2)) {
2733 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2734 req->wct, 19 + (state->setup_count/2)));
2738 /* Don't allow more than 128mb for each value. */
2739 if ((state->total_data > (1024*1024*128)) ||
2740 (state->total_param > (1024*1024*128))) {
2741 reply_doserror(req, ERRDOS, ERRnomem);
2742 END_PROFILE(SMBnttrans);
2746 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2749 if (state->total_data) {
2751 if (trans_oob(state->total_data, 0, dscnt)
2752 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2756 /* Can't use talloc here, the core routines do realloc on the
2757 * params and data. */
2758 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2759 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2760 "bytes !\n", (unsigned int)state->total_data));
2762 reply_doserror(req, ERRDOS, ERRnomem);
2763 END_PROFILE(SMBnttrans);
2767 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2770 if (state->total_param) {
2772 if (trans_oob(state->total_param, 0, pscnt)
2773 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2777 /* Can't use talloc here, the core routines do realloc on the
2778 * params and data. */
2779 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2780 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2781 "bytes !\n", (unsigned int)state->total_param));
2782 SAFE_FREE(state->data);
2784 reply_doserror(req, ERRDOS, ERRnomem);
2785 END_PROFILE(SMBnttrans);
2789 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2792 state->received_data = dscnt;
2793 state->received_param = pscnt;
2795 if(state->setup_count > 0) {
2796 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2797 state->setup_count));
2800 * No overflow possible here, state->setup_count is an
2801 * unsigned int, being filled by a single byte from
2802 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2803 * below is not necessary, it's here to clarify things. The
2804 * validity of req->vwv and req->wct has been checked in
2805 * init_smb_request already.
2807 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2811 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2812 if (state->setup == NULL) {
2813 DEBUG(0,("reply_nttrans : Out of memory\n"));
2814 SAFE_FREE(state->data);
2815 SAFE_FREE(state->param);
2817 reply_doserror(req, ERRDOS, ERRnomem);
2818 END_PROFILE(SMBnttrans);
2822 memcpy(state->setup, req->vwv+19, state->setup_count);
2823 dump_data(10, (uint8 *)state->setup, state->setup_count);
2826 if ((state->received_data == state->total_data) &&
2827 (state->received_param == state->total_param)) {
2828 handle_nttrans(conn, state, req);
2829 SAFE_FREE(state->param);
2830 SAFE_FREE(state->data);
2832 END_PROFILE(SMBnttrans);
2836 DLIST_ADD(conn->pending_trans, state);
2838 /* We need to send an interim response then receive the rest
2839 of the parameter/data bytes */
2840 reply_outbuf(req, 0, 0);
2841 show_msg((char *)req->outbuf);
2842 END_PROFILE(SMBnttrans);
2847 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2848 SAFE_FREE(state->data);
2849 SAFE_FREE(state->param);
2851 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2852 END_PROFILE(SMBnttrans);
2856 /****************************************************************************
2857 Reply to a SMBnttranss
2858 ****************************************************************************/
2860 void reply_nttranss(struct smb_request *req)
2862 connection_struct *conn = req->conn;
2863 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2864 struct trans_state *state;
2866 START_PROFILE(SMBnttranss);
2868 show_msg((char *)req->inbuf);
2870 if (req->wct < 18) {
2871 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2872 END_PROFILE(SMBnttranss);
2876 for (state = conn->pending_trans; state != NULL;
2877 state = state->next) {
2878 if (state->mid == req->mid) {
2883 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2884 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2885 END_PROFILE(SMBnttranss);
2889 /* Revise state->total_param and state->total_data in case they have
2890 changed downwards */
2891 if (IVAL(req->vwv+1, 1) < state->total_param) {
2892 state->total_param = IVAL(req->vwv+1, 1);
2894 if (IVAL(req->vwv+3, 1) < state->total_data) {
2895 state->total_data = IVAL(req->vwv+3, 1);
2898 pcnt = IVAL(req->vwv+5, 1);
2899 poff = IVAL(req->vwv+7, 1);
2900 pdisp = IVAL(req->vwv+9, 1);
2902 dcnt = IVAL(req->vwv+11, 1);
2903 doff = IVAL(req->vwv+13, 1);
2904 ddisp = IVAL(req->vwv+15, 1);
2906 state->received_param += pcnt;
2907 state->received_data += dcnt;
2909 if ((state->received_data > state->total_data) ||
2910 (state->received_param > state->total_param))
2914 if (trans_oob(state->total_param, pdisp, pcnt)
2915 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2918 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2922 if (trans_oob(state->total_data, ddisp, dcnt)
2923 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2926 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2929 if ((state->received_param < state->total_param) ||
2930 (state->received_data < state->total_data)) {
2931 END_PROFILE(SMBnttranss);
2935 handle_nttrans(conn, state, req);
2937 DLIST_REMOVE(conn->pending_trans, state);
2938 SAFE_FREE(state->data);
2939 SAFE_FREE(state->param);
2941 END_PROFILE(SMBnttranss);
2946 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2947 DLIST_REMOVE(conn->pending_trans, state);
2948 SAFE_FREE(state->data);
2949 SAFE_FREE(state->param);
2951 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2952 END_PROFILE(SMBnttranss);