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,
483 if (!NT_STATUS_IS_OK(status)) {
484 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
486 NT_STATUS_PATH_NOT_COVERED,
490 reply_nterror(req, status);
494 status = SMB_VFS_CREATE_FILE(
497 root_dir_fid, /* root_dir_fid */
498 smb_fname, /* fname */
499 access_mask, /* access_mask */
500 share_access, /* share_access */
501 create_disposition, /* create_disposition*/
502 create_options, /* create_options */
503 file_attributes, /* file_attributes */
504 oplock_request, /* oplock_request */
505 allocation_size, /* allocation_size */
511 if (!NT_STATUS_IS_OK(status)) {
512 if (open_was_deferred(req->mid)) {
513 /* We have re-scheduled this call, no error. */
516 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
517 reply_botherror(req, status, ERRDOS, ERRfilexists);
520 reply_nterror(req, status);
526 * If the caller set the extended oplock request bit
527 * and we granted one (by whatever means) - set the
528 * correct bit for extended oplock reply.
531 if (oplock_request &&
532 (lp_fake_oplocks(SNUM(conn))
533 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
536 * Exclusive oplock granted
539 if (flags & REQUEST_BATCH_OPLOCK) {
540 oplock_granted = BATCH_OPLOCK_RETURN;
542 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
544 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
545 oplock_granted = LEVEL_II_OPLOCK_RETURN;
547 oplock_granted = NO_OPLOCK_RETURN;
550 file_len = smb_fname->st.st_ex_size;
551 fattr = dos_mode(conn, smb_fname);
553 fattr = FILE_ATTRIBUTE_NORMAL;
556 if (flags & EXTENDED_RESPONSE_REQUIRED) {
557 /* This is very strange. We
558 * return 50 words, but only set
559 * the wcnt to 42 ? It's definately
560 * what happens on the wire....
562 reply_outbuf(req, 50, 0);
563 SCVAL(req->outbuf,smb_wct,42);
565 reply_outbuf(req, 34, 0);
568 p = (char *)req->outbuf + smb_vwv2;
570 SCVAL(p, 0, oplock_granted);
573 SSVAL(p,0,fsp->fnum);
575 if ((create_disposition == FILE_SUPERSEDE)
576 && (info == FILE_WAS_OVERWRITTEN)) {
577 SIVAL(p,0,FILE_WAS_SUPERSEDED);
583 /* Deal with other possible opens having a modified
585 ZERO_STRUCT(write_time_ts);
586 get_file_infos(fsp->file_id, NULL, &write_time_ts);
587 if (!null_timespec(write_time_ts)) {
588 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
592 c_timespec = smb_fname->st.st_ex_btime;
593 a_timespec = smb_fname->st.st_ex_atime;
594 m_timespec = smb_fname->st.st_ex_mtime;
596 if (lp_dos_filetime_resolution(SNUM(conn))) {
597 dos_filetime_timespec(&c_timespec);
598 dos_filetime_timespec(&a_timespec);
599 dos_filetime_timespec(&m_timespec);
602 put_long_date_timespec(p, c_timespec); /* create time. */
604 put_long_date_timespec(p, a_timespec); /* access time */
606 put_long_date_timespec(p, m_timespec); /* write time */
608 put_long_date_timespec(p, m_timespec); /* change time */
610 SIVAL(p,0,fattr); /* File Attributes. */
612 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
614 SOFF_T(p,0,file_len);
616 if (flags & EXTENDED_RESPONSE_REQUIRED) {
620 SCVAL(p,0,fsp->is_directory ? 1 : 0);
622 if (flags & EXTENDED_RESPONSE_REQUIRED) {
625 if (fsp->is_directory ||
626 can_write_to_file(conn, smb_fname)) {
627 perms = FILE_GENERIC_ALL;
629 perms = FILE_GENERIC_READ|FILE_EXECUTE;
634 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
635 fsp->fnum, smb_fname_str_dbg(smb_fname)));
639 TALLOC_FREE(smb_fname);
640 END_PROFILE(SMBntcreateX);
644 /****************************************************************************
645 Reply to a NT_TRANSACT_CREATE call to open a pipe.
646 ****************************************************************************/
648 static void do_nt_transact_create_pipe(connection_struct *conn,
649 struct smb_request *req,
650 uint16 **ppsetup, uint32 setup_count,
651 char **ppparams, uint32 parameter_count,
652 char **ppdata, uint32 data_count)
655 char *params = *ppparams;
661 TALLOC_CTX *ctx = talloc_tos();
664 * Ensure minimum number of parameters sent.
667 if(parameter_count < 54) {
668 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
669 reply_doserror(req, ERRDOS, ERRnoaccess);
673 flags = IVAL(params,0);
675 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
676 parameter_count-53, STR_TERMINATE,
678 if (!NT_STATUS_IS_OK(status)) {
679 reply_nterror(req, status);
683 nt_open_pipe(fname, conn, req, &pnum);
690 /* Realloc the size of parameters and data we will return */
691 if (flags & EXTENDED_RESPONSE_REQUIRED) {
692 /* Extended response is 32 more byyes. */
697 params = nttrans_realloc(ppparams, param_len);
699 reply_doserror(req, ERRDOS, ERRnomem);
704 SCVAL(p,0,NO_OPLOCK_RETURN);
709 SIVAL(p,0,FILE_WAS_OPENED);
713 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
716 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
718 SSVAL(p,2, 0x5FF); /* ? */
721 if (flags & EXTENDED_RESPONSE_REQUIRED) {
723 SIVAL(p,0,FILE_GENERIC_ALL);
725 * For pipes W2K3 seems to return
727 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
729 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
732 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
734 /* Send the required number of replies */
735 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
740 /****************************************************************************
741 Internal fn to set security descriptors.
742 ****************************************************************************/
744 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
745 uint32 security_info_sent)
747 SEC_DESC *psd = NULL;
750 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
754 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
756 if (!NT_STATUS_IS_OK(status)) {
760 if (psd->owner_sid == NULL) {
761 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
763 if (psd->group_sid == NULL) {
764 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
767 /* Convert all the generic bits. */
768 security_acl_map_generic(psd->dacl, &file_generic_mapping);
769 security_acl_map_generic(psd->sacl, &file_generic_mapping);
771 if (DEBUGLEVEL >= 10) {
772 DEBUG(10,("set_sd for file %s\n", fsp_str_dbg(fsp)));
773 NDR_PRINT_DEBUG(security_descriptor, psd);
776 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
783 /****************************************************************************
784 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
785 ****************************************************************************/
787 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
789 struct ea_list *ea_list_head = NULL;
796 while (offset + 4 <= data_size) {
797 size_t next_offset = IVAL(pdata,offset);
798 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
804 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
805 if (next_offset == 0) {
808 offset += next_offset;
814 /****************************************************************************
815 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
816 ****************************************************************************/
818 static void call_nt_transact_create(connection_struct *conn,
819 struct smb_request *req,
820 uint16 **ppsetup, uint32 setup_count,
821 char **ppparams, uint32 parameter_count,
822 char **ppdata, uint32 data_count,
823 uint32 max_data_count)
825 struct smb_filename *smb_fname = NULL;
827 char *params = *ppparams;
828 char *data = *ppdata;
829 /* Breakout the oplock request bits so we can set the reply bits separately. */
831 SMB_OFF_T file_len = 0;
833 files_struct *fsp = NULL;
837 uint32 file_attributes;
839 uint32 create_disposition;
840 uint32 create_options;
842 struct security_descriptor *sd = NULL;
845 struct timespec c_timespec;
846 struct timespec a_timespec;
847 struct timespec m_timespec;
848 struct timespec write_time_ts;
849 struct ea_list *ea_list = NULL;
852 uint64_t allocation_size;
854 uint8_t oplock_granted;
855 TALLOC_CTX *ctx = talloc_tos();
857 DEBUG(5,("call_nt_transact_create\n"));
860 * If it's an IPC, use the pipe handler.
864 if (lp_nt_pipe_support()) {
865 do_nt_transact_create_pipe(
867 ppsetup, setup_count,
868 ppparams, parameter_count,
872 reply_doserror(req, ERRDOS, ERRnoaccess);
877 * Ensure minimum number of parameters sent.
880 if(parameter_count < 54) {
881 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
882 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
886 flags = IVAL(params,0);
887 access_mask = IVAL(params,8);
888 file_attributes = IVAL(params,20);
889 share_access = IVAL(params,24);
890 create_disposition = IVAL(params,28);
891 create_options = IVAL(params,32);
892 sd_len = IVAL(params,36);
893 ea_len = IVAL(params,40);
894 root_dir_fid = (uint16)IVAL(params,4);
895 allocation_size = (uint64_t)IVAL(params,12);
896 #ifdef LARGE_SMB_OFF_T
897 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
901 * we need to remove ignored bits when they come directly from the client
902 * because we reuse some of them for internal stuff
904 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
906 /* Ensure the data_len is correct for the sd and ea values given. */
907 if ((ea_len + sd_len > data_count)
908 || (ea_len > data_count) || (sd_len > data_count)
909 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
910 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
911 "%u, data_count = %u\n", (unsigned int)ea_len,
912 (unsigned int)sd_len, (unsigned int)data_count));
913 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
918 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
921 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
923 if (!NT_STATUS_IS_OK(status)) {
924 DEBUG(10, ("call_nt_transact_create: "
925 "unmarshall_sec_desc failed: %s\n",
927 reply_nterror(req, status);
933 if (!lp_ea_support(SNUM(conn))) {
934 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
935 "EA's not supported.\n",
936 (unsigned int)ea_len));
937 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
942 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
943 "too small (should be more than 10)\n",
944 (unsigned int)ea_len ));
945 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
949 /* We have already checked that ea_len <= data_count here. */
950 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
952 if (ea_list == NULL) {
953 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
958 srvstr_get_path(ctx, params, req->flags2, &fname,
959 params+53, parameter_count-53,
960 STR_TERMINATE, &status);
961 if (!NT_STATUS_IS_OK(status)) {
962 reply_nterror(req, status);
966 status = filename_convert(ctx,
968 req->flags2 & FLAGS2_DFS_PATHNAMES,
972 if (!NT_STATUS_IS_OK(status)) {
973 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
975 NT_STATUS_PATH_NOT_COVERED,
979 reply_nterror(req, status);
983 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
984 if (oplock_request) {
985 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
989 status = SMB_VFS_CREATE_FILE(
992 root_dir_fid, /* root_dir_fid */
993 smb_fname, /* fname */
994 access_mask, /* access_mask */
995 share_access, /* share_access */
996 create_disposition, /* create_disposition*/
997 create_options, /* create_options */
998 file_attributes, /* file_attributes */
999 oplock_request, /* oplock_request */
1000 allocation_size, /* allocation_size */
1002 ea_list, /* ea_list */
1006 if(!NT_STATUS_IS_OK(status)) {
1007 if (open_was_deferred(req->mid)) {
1008 /* We have re-scheduled this call, no error. */
1011 reply_openerror(req, status);
1016 * If the caller set the extended oplock request bit
1017 * and we granted one (by whatever means) - set the
1018 * correct bit for extended oplock reply.
1021 if (oplock_request &&
1022 (lp_fake_oplocks(SNUM(conn))
1023 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1026 * Exclusive oplock granted
1029 if (flags & REQUEST_BATCH_OPLOCK) {
1030 oplock_granted = BATCH_OPLOCK_RETURN;
1032 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1034 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1035 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1037 oplock_granted = NO_OPLOCK_RETURN;
1040 file_len = smb_fname->st.st_ex_size;
1041 fattr = dos_mode(conn, smb_fname);
1043 fattr = FILE_ATTRIBUTE_NORMAL;
1046 /* Realloc the size of parameters and data we will return */
1047 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1048 /* Extended response is 32 more byyes. */
1053 params = nttrans_realloc(ppparams, param_len);
1054 if(params == NULL) {
1055 reply_doserror(req, ERRDOS, ERRnomem);
1060 SCVAL(p, 0, oplock_granted);
1063 SSVAL(p,0,fsp->fnum);
1065 if ((create_disposition == FILE_SUPERSEDE)
1066 && (info == FILE_WAS_OVERWRITTEN)) {
1067 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1073 /* Deal with other possible opens having a modified
1075 ZERO_STRUCT(write_time_ts);
1076 get_file_infos(fsp->file_id, NULL, &write_time_ts);
1077 if (!null_timespec(write_time_ts)) {
1078 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
1082 c_timespec = smb_fname->st.st_ex_btime;
1083 a_timespec = smb_fname->st.st_ex_atime;
1084 m_timespec = smb_fname->st.st_ex_mtime;
1086 if (lp_dos_filetime_resolution(SNUM(conn))) {
1087 dos_filetime_timespec(&c_timespec);
1088 dos_filetime_timespec(&a_timespec);
1089 dos_filetime_timespec(&m_timespec);
1092 put_long_date_timespec(p, c_timespec); /* create time. */
1094 put_long_date_timespec(p, a_timespec); /* access time */
1096 put_long_date_timespec(p, m_timespec); /* write time */
1098 put_long_date_timespec(p, m_timespec); /* change time */
1100 SIVAL(p,0,fattr); /* File Attributes. */
1102 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1104 SOFF_T(p,0,file_len);
1106 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1110 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1112 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1115 if (fsp->is_directory ||
1116 can_write_to_file(conn, smb_fname)) {
1117 perms = FILE_GENERIC_ALL;
1119 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1124 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1125 smb_fname_str_dbg(smb_fname)));
1127 /* Send the required number of replies */
1128 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1130 TALLOC_FREE(smb_fname);
1134 /****************************************************************************
1135 Reply to a NT CANCEL request.
1136 conn POINTER CAN BE NULL HERE !
1137 ****************************************************************************/
1139 void reply_ntcancel(struct smb_request *req)
1142 * Go through and cancel any pending change notifies.
1145 START_PROFILE(SMBntcancel);
1146 srv_cancel_sign_response(smbd_server_conn);
1147 remove_pending_change_notify_requests_by_mid(req->mid);
1148 remove_pending_lock_requests_by_mid(req->mid);
1150 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1152 END_PROFILE(SMBntcancel);
1156 /****************************************************************************
1158 ****************************************************************************/
1160 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1161 connection_struct *conn,
1162 struct smb_request *req,
1163 struct smb_filename *smb_fname_src,
1164 struct smb_filename *smb_fname_dst,
1167 files_struct *fsp1,*fsp2;
1171 NTSTATUS status = NT_STATUS_OK;
1174 if (!CAN_WRITE(conn)) {
1175 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1179 /* Source must already exist. */
1180 if (!VALID_STAT(smb_fname_src->st)) {
1181 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1185 /* Ensure attributes match. */
1186 fattr = dos_mode(conn, smb_fname_src);
1187 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1188 status = NT_STATUS_NO_SUCH_FILE;
1192 /* Disallow if dst file already exists. */
1193 if (VALID_STAT(smb_fname_dst->st)) {
1194 status = NT_STATUS_OBJECT_NAME_COLLISION;
1198 /* No links from a directory. */
1199 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1200 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1204 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1205 smb_fname_str_dbg(smb_fname_src),
1206 smb_fname_str_dbg(smb_fname_dst)));
1208 status = SMB_VFS_CREATE_FILE(
1211 0, /* root_dir_fid */
1212 smb_fname_src, /* fname */
1213 FILE_READ_DATA, /* access_mask */
1214 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1216 FILE_OPEN, /* create_disposition*/
1217 0, /* create_options */
1218 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1219 NO_OPLOCK, /* oplock_request */
1220 0, /* allocation_size */
1226 if (!NT_STATUS_IS_OK(status)) {
1230 status = SMB_VFS_CREATE_FILE(
1233 0, /* root_dir_fid */
1234 smb_fname_dst, /* fname */
1235 FILE_WRITE_DATA, /* access_mask */
1236 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1238 FILE_CREATE, /* create_disposition*/
1239 0, /* create_options */
1240 fattr, /* file_attributes */
1241 NO_OPLOCK, /* oplock_request */
1242 0, /* allocation_size */
1248 if (!NT_STATUS_IS_OK(status)) {
1249 close_file(NULL, fsp1, ERROR_CLOSE);
1253 if (smb_fname_src->st.st_ex_size) {
1254 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1258 * As we are opening fsp1 read-only we only expect
1259 * an error on close on fsp2 if we are out of space.
1260 * Thus we don't look at the error return from the
1263 close_file(NULL, fsp1, NORMAL_CLOSE);
1265 /* Ensure the modtime is set correctly on the destination file. */
1266 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1268 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1270 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1271 creates the file. This isn't the correct thing to do in the copy
1273 if (!parent_dirname(talloc_tos(), smb_fname_dst->base_name, &parent,
1275 status = NT_STATUS_NO_MEMORY;
1278 file_set_dosmode(conn, smb_fname_dst, fattr, parent, false);
1279 TALLOC_FREE(parent);
1281 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1282 status = NT_STATUS_DISK_FULL;
1286 if (!NT_STATUS_IS_OK(status)) {
1287 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1288 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1289 smb_fname_str_dbg(smb_fname_dst)));
1295 /****************************************************************************
1296 Reply to a NT rename request.
1297 ****************************************************************************/
1299 void reply_ntrename(struct smb_request *req)
1301 connection_struct *conn = req->conn;
1302 struct smb_filename *smb_fname_old = NULL;
1303 struct smb_filename *smb_fname_new = NULL;
1304 char *oldname = NULL;
1305 char *newname = NULL;
1308 bool src_has_wcard = False;
1309 bool dest_has_wcard = False;
1312 TALLOC_CTX *ctx = talloc_tos();
1314 START_PROFILE(SMBntrename);
1317 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1321 attrs = SVAL(req->vwv+0, 0);
1322 rename_type = SVAL(req->vwv+1, 0);
1324 p = (const char *)req->buf + 1;
1325 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1326 &status, &src_has_wcard);
1327 if (!NT_STATUS_IS_OK(status)) {
1328 reply_nterror(req, status);
1332 if (ms_has_wild(oldname)) {
1333 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1338 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1339 &status, &dest_has_wcard);
1340 if (!NT_STATUS_IS_OK(status)) {
1341 reply_nterror(req, status);
1345 /* The newname must begin with a ':' if the oldname contains a ':'. */
1346 if (strchr_m(oldname, ':') && (newname[0] != ':')) {
1347 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1351 /* rename_internals() calls unix_convert(), so don't call it here. */
1352 if (rename_type != RENAME_FLAG_RENAME) {
1353 status = filename_convert(ctx, conn,
1354 req->flags2 & FLAGS2_DFS_PATHNAMES,
1357 if (!NT_STATUS_IS_OK(status)) {
1358 if (NT_STATUS_EQUAL(status,
1359 NT_STATUS_PATH_NOT_COVERED)) {
1360 reply_botherror(req,
1361 NT_STATUS_PATH_NOT_COVERED,
1362 ERRSRV, ERRbadpath);
1365 reply_nterror(req, status);
1369 status = filename_convert(ctx, conn,
1370 req->flags2 & FLAGS2_DFS_PATHNAMES,
1373 if (!NT_STATUS_IS_OK(status)) {
1374 if (NT_STATUS_EQUAL(status,
1375 NT_STATUS_PATH_NOT_COVERED)) {
1376 reply_botherror(req,
1377 NT_STATUS_PATH_NOT_COVERED,
1378 ERRSRV, ERRbadpath);
1381 reply_nterror(req, status);
1385 DEBUG(3,("reply_ntrename: %s -> %s\n",
1386 smb_fname_str_dbg(smb_fname_old),
1387 smb_fname_str_dbg(smb_fname_new)));
1390 switch(rename_type) {
1391 case RENAME_FLAG_RENAME:
1392 status = resolve_dfspath(ctx, conn,
1394 FLAGS2_DFS_PATHNAMES),
1396 if (!NT_STATUS_IS_OK(status)) {
1397 DEBUG(10,("resolve_dfspath failed for name %s "
1398 "with %s\n", oldname,
1399 nt_errstr(status)));
1400 reply_nterror(req, status);
1404 status = resolve_dfspath(ctx, conn,
1406 FLAGS2_DFS_PATHNAMES),
1408 if (!NT_STATUS_IS_OK(status)) {
1409 DEBUG(10,("resolve_dfspath failed for name %s "
1410 "with %s\n", newname,
1411 nt_errstr(status)));
1412 reply_nterror(req, status);
1416 DEBUG(3,("reply_ntrename: %s -> %s\n", oldname,
1419 status = rename_internals(ctx, conn, req, oldname,
1420 newname, attrs, False, src_has_wcard,
1421 dest_has_wcard, DELETE_ACCESS);
1423 case RENAME_FLAG_HARD_LINK:
1424 if (src_has_wcard || dest_has_wcard) {
1426 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1428 status = hardlink_internals(ctx,
1434 case RENAME_FLAG_COPY:
1435 if (src_has_wcard || dest_has_wcard) {
1437 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1439 status = copy_internals(ctx, conn, req,
1445 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1446 status = NT_STATUS_INVALID_PARAMETER;
1449 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1453 if (!NT_STATUS_IS_OK(status)) {
1454 if (open_was_deferred(req->mid)) {
1455 /* We have re-scheduled this call. */
1459 reply_nterror(req, status);
1463 reply_outbuf(req, 0, 0);
1465 END_PROFILE(SMBntrename);
1469 /****************************************************************************
1470 Reply to a notify change - queue the request and
1471 don't allow a directory to be opened.
1472 ****************************************************************************/
1474 static void smbd_smb1_notify_reply(struct smb_request *req,
1475 NTSTATUS error_code,
1476 uint8_t *buf, size_t len)
1478 send_nt_replies(req->conn, req, error_code, (char *)buf, len, NULL, 0);
1481 static void call_nt_transact_notify_change(connection_struct *conn,
1482 struct smb_request *req,
1486 uint32 parameter_count,
1487 char **ppdata, uint32 data_count,
1488 uint32 max_data_count,
1489 uint32 max_param_count)
1491 uint16 *setup = *ppsetup;
1497 if(setup_count < 6) {
1498 reply_doserror(req, ERRDOS, ERRbadfunc);
1502 fsp = file_fsp(req, SVAL(setup,4));
1503 filter = IVAL(setup, 0);
1504 recursive = (SVAL(setup, 6) != 0) ? True : False;
1506 DEBUG(3,("call_nt_transact_notify_change\n"));
1509 reply_doserror(req, ERRDOS, ERRbadfid);
1514 char *filter_string;
1516 if (!(filter_string = notify_filter_string(NULL, filter))) {
1517 reply_nterror(req,NT_STATUS_NO_MEMORY);
1521 DEBUG(3,("call_nt_transact_notify_change: notify change "
1522 "called on %s, filter = %s, recursive = %d\n",
1523 fsp_str_dbg(fsp), filter_string, recursive));
1525 TALLOC_FREE(filter_string);
1528 if((!fsp->is_directory) || (conn != fsp->conn)) {
1529 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1533 if (fsp->notify == NULL) {
1535 status = change_notify_create(fsp, filter, recursive);
1537 if (!NT_STATUS_IS_OK(status)) {
1538 DEBUG(10, ("change_notify_create returned %s\n",
1539 nt_errstr(status)));
1540 reply_nterror(req, status);
1545 if (fsp->notify->num_changes != 0) {
1548 * We've got changes pending, respond immediately
1552 * TODO: write a torture test to check the filtering behaviour
1556 change_notify_reply(fsp->conn, req,
1560 smbd_smb1_notify_reply);
1563 * change_notify_reply() above has independently sent its
1570 * No changes pending, queue the request
1573 status = change_notify_add_request(req,
1577 smbd_smb1_notify_reply);
1578 if (!NT_STATUS_IS_OK(status)) {
1579 reply_nterror(req, status);
1584 /****************************************************************************
1585 Reply to an NT transact rename command.
1586 ****************************************************************************/
1588 static void call_nt_transact_rename(connection_struct *conn,
1589 struct smb_request *req,
1590 uint16 **ppsetup, uint32 setup_count,
1591 char **ppparams, uint32 parameter_count,
1592 char **ppdata, uint32 data_count,
1593 uint32 max_data_count)
1595 char *params = *ppparams;
1596 char *new_name = NULL;
1597 files_struct *fsp = NULL;
1598 bool dest_has_wcard = False;
1600 TALLOC_CTX *ctx = talloc_tos();
1602 if(parameter_count < 5) {
1603 reply_doserror(req, ERRDOS, ERRbadfunc);
1607 fsp = file_fsp(req, SVAL(params, 0));
1608 if (!check_fsp(conn, req, fsp)) {
1611 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1612 parameter_count - 4,
1613 STR_TERMINATE, &status, &dest_has_wcard);
1614 if (!NT_STATUS_IS_OK(status)) {
1615 reply_nterror(req, status);
1620 * W2K3 ignores this request as the RAW-RENAME test
1621 * demonstrates, so we do.
1623 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1625 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1626 fsp_str_dbg(fsp), new_name));
1631 /******************************************************************************
1632 Fake up a completely empty SD.
1633 *******************************************************************************/
1635 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1639 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1641 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1642 return NT_STATUS_NO_MEMORY;
1645 return NT_STATUS_OK;
1648 /****************************************************************************
1649 Reply to query a security descriptor.
1650 ****************************************************************************/
1652 static void call_nt_transact_query_security_desc(connection_struct *conn,
1653 struct smb_request *req,
1657 uint32 parameter_count,
1660 uint32 max_data_count)
1662 char *params = *ppparams;
1663 char *data = *ppdata;
1664 SEC_DESC *psd = NULL;
1666 uint32 security_info_wanted;
1667 files_struct *fsp = NULL;
1671 if(parameter_count < 8) {
1672 reply_doserror(req, ERRDOS, ERRbadfunc);
1676 fsp = file_fsp(req, SVAL(params,0));
1678 reply_doserror(req, ERRDOS, ERRbadfid);
1682 security_info_wanted = IVAL(params,4);
1684 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, "
1685 "info_wanted = 0x%x\n", fsp_str_dbg(fsp),
1686 (unsigned int)security_info_wanted));
1688 params = nttrans_realloc(ppparams, 4);
1689 if(params == NULL) {
1690 reply_doserror(req, ERRDOS, ERRnomem);
1695 * Get the permissions to return.
1698 if (!lp_nt_acl_support(SNUM(conn))) {
1699 status = get_null_nt_acl(talloc_tos(), &psd);
1701 status = SMB_VFS_FGET_NT_ACL(
1702 fsp, security_info_wanted, &psd);
1704 if (!NT_STATUS_IS_OK(status)) {
1705 reply_nterror(req, status);
1709 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1710 * present in the reply to match Windows behavior */
1711 if (psd->sacl == NULL &&
1712 security_info_wanted & SACL_SECURITY_INFORMATION)
1713 psd->type |= SEC_DESC_SACL_PRESENT;
1714 if (psd->dacl == NULL &&
1715 security_info_wanted & DACL_SECURITY_INFORMATION)
1716 psd->type |= SEC_DESC_DACL_PRESENT;
1718 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1720 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1722 if (DEBUGLEVEL >= 10) {
1723 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n",
1725 NDR_PRINT_DEBUG(security_descriptor, psd);
1728 SIVAL(params,0,(uint32)sd_size);
1730 if (max_data_count < sd_size) {
1731 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1732 params, 4, *ppdata, 0);
1737 * Allocate the data we will point this at.
1740 data = nttrans_realloc(ppdata, sd_size);
1742 reply_doserror(req, ERRDOS, ERRnomem);
1746 status = marshall_sec_desc(talloc_tos(), psd,
1747 &blob.data, &blob.length);
1749 if (!NT_STATUS_IS_OK(status)) {
1750 reply_nterror(req, status);
1754 SMB_ASSERT(sd_size == blob.length);
1755 memcpy(data, blob.data, sd_size);
1757 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1762 /****************************************************************************
1763 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1764 ****************************************************************************/
1766 static void call_nt_transact_set_security_desc(connection_struct *conn,
1767 struct smb_request *req,
1771 uint32 parameter_count,
1774 uint32 max_data_count)
1776 char *params= *ppparams;
1777 char *data = *ppdata;
1778 files_struct *fsp = NULL;
1779 uint32 security_info_sent = 0;
1782 if(parameter_count < 8) {
1783 reply_doserror(req, ERRDOS, ERRbadfunc);
1787 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1788 reply_doserror(req, ERRDOS, ERRbadfid);
1792 if(!lp_nt_acl_support(SNUM(conn))) {
1796 security_info_sent = IVAL(params,4);
1798 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n",
1799 fsp_str_dbg(fsp), (unsigned int)security_info_sent));
1801 if (data_count == 0) {
1802 reply_doserror(req, ERRDOS, ERRnoaccess);
1806 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1808 if (!NT_STATUS_IS_OK(status)) {
1809 reply_nterror(req, status);
1814 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1818 /****************************************************************************
1820 ****************************************************************************/
1822 static void call_nt_transact_ioctl(connection_struct *conn,
1823 struct smb_request *req,
1824 uint16 **ppsetup, uint32 setup_count,
1825 char **ppparams, uint32 parameter_count,
1826 char **ppdata, uint32 data_count,
1827 uint32 max_data_count)
1834 char *pdata = *ppdata;
1836 if (setup_count != 8) {
1837 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1838 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1842 function = IVAL(*ppsetup, 0);
1843 fidnum = SVAL(*ppsetup, 4);
1844 isFSctl = CVAL(*ppsetup, 6);
1845 compfilter = CVAL(*ppsetup, 7);
1847 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1848 function, fidnum, isFSctl, compfilter));
1850 fsp=file_fsp(req, fidnum);
1851 /* this check is done in each implemented function case for now
1852 because I don't want to break anything... --metze
1853 FSP_BELONGS_CONN(fsp,conn);*/
1855 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1858 case FSCTL_SET_SPARSE:
1859 /* pretend this succeeded - tho strictly we should
1860 mark the file sparse (if the local fs supports it)
1861 so we can know if we need to pre-allocate or not */
1863 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1864 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1867 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1869 unsigned char objid[16];
1871 /* This should return the object-id on this file.
1872 * I think I'll make this be the inode+dev. JRA.
1875 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1877 if (!fsp_belongs_conn(conn, req, fsp)) {
1882 pdata = nttrans_realloc(ppdata, data_count);
1883 if (pdata == NULL) {
1884 reply_nterror(req, NT_STATUS_NO_MEMORY);
1888 /* For backwards compatibility only store the dev/inode. */
1889 push_file_id_16(pdata, &fsp->file_id);
1890 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1891 push_file_id_16(pdata+32, &fsp->file_id);
1892 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1897 case FSCTL_GET_REPARSE_POINT:
1898 /* pretend this fail - my winXP does it like this
1902 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1903 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1906 case FSCTL_SET_REPARSE_POINT:
1907 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1911 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1912 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1915 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1918 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1919 * and return their volume names. If max_data_count is 16, then it is just
1920 * asking for the number of volumes and length of the combined names.
1922 * pdata is the data allocated by our caller, but that uses
1923 * total_data_count (which is 0 in our case) rather than max_data_count.
1924 * Allocate the correct amount and return the pointer to let
1925 * it be deallocated when we return.
1927 SHADOW_COPY_DATA *shadow_data = NULL;
1928 TALLOC_CTX *shadow_mem_ctx = NULL;
1929 bool labels = False;
1930 uint32 labels_data_count = 0;
1934 if (!fsp_belongs_conn(conn, req, fsp)) {
1938 if (max_data_count < 16) {
1939 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1941 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1945 if (max_data_count > 16) {
1949 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1950 if (shadow_mem_ctx == NULL) {
1951 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1952 reply_nterror(req, NT_STATUS_NO_MEMORY);
1956 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
1957 if (shadow_data == NULL) {
1958 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1959 talloc_destroy(shadow_mem_ctx);
1960 reply_nterror(req, NT_STATUS_NO_MEMORY);
1964 shadow_data->mem_ctx = shadow_mem_ctx;
1967 * Call the VFS routine to actually do the work.
1969 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1970 talloc_destroy(shadow_data->mem_ctx);
1971 if (errno == ENOSYS) {
1972 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1973 conn->connectpath));
1974 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1977 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1978 conn->connectpath));
1979 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
1984 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
1989 data_count = 12+labels_data_count+4;
1992 if (max_data_count<data_count) {
1993 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1994 max_data_count,data_count));
1995 talloc_destroy(shadow_data->mem_ctx);
1996 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2000 pdata = nttrans_realloc(ppdata, data_count);
2001 if (pdata == NULL) {
2002 talloc_destroy(shadow_data->mem_ctx);
2003 reply_nterror(req, NT_STATUS_NO_MEMORY);
2009 /* num_volumes 4 bytes */
2010 SIVAL(pdata,0,shadow_data->num_volumes);
2013 /* num_labels 4 bytes */
2014 SIVAL(pdata,4,shadow_data->num_volumes);
2017 /* needed_data_count 4 bytes */
2018 SIVAL(pdata,8,labels_data_count);
2022 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2023 shadow_data->num_volumes, fsp_str_dbg(fsp)));
2024 if (labels && shadow_data->labels) {
2025 for (i=0;i<shadow_data->num_volumes;i++) {
2026 srvstr_push(pdata, req->flags2,
2027 cur_pdata, shadow_data->labels[i],
2028 2*sizeof(SHADOW_COPY_LABEL),
2029 STR_UNICODE|STR_TERMINATE);
2030 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2031 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2035 talloc_destroy(shadow_data->mem_ctx);
2037 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2043 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2045 /* pretend this succeeded -
2047 * we have to send back a list with all files owned by this SID
2049 * but I have to check that --metze
2053 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2055 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2057 if (!fsp_belongs_conn(conn, req, fsp)) {
2061 /* unknown 4 bytes: this is not the length of the sid :-( */
2062 /*unknown = IVAL(pdata,0);*/
2064 sid_parse(pdata+4,sid_len,&sid);
2065 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2067 if (!sid_to_uid(&sid, &uid)) {
2068 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2069 sid_string_dbg(&sid),
2070 (unsigned long)sid_len));
2074 /* we can take a look at the find source :-)
2076 * find ./ -uid $uid -name '*' is what we need here
2079 * and send 4bytes len and then NULL terminated unicode strings
2082 * but I don't know how to deal with the paged results
2083 * (maybe we can hang the result anywhere in the fsp struct)
2085 * we don't send all files at once
2086 * and at the next we should *not* start from the beginning,
2087 * so we have to cache the result
2092 /* this works for now... */
2093 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2097 if (!logged_ioctl_message) {
2098 logged_ioctl_message = true; /* Only print this once... */
2099 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2104 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2108 #ifdef HAVE_SYS_QUOTAS
2109 /****************************************************************************
2110 Reply to get user quota
2111 ****************************************************************************/
2113 static void call_nt_transact_get_user_quota(connection_struct *conn,
2114 struct smb_request *req,
2118 uint32 parameter_count,
2121 uint32 max_data_count)
2123 NTSTATUS nt_status = NT_STATUS_OK;
2124 char *params = *ppparams;
2125 char *pdata = *ppdata;
2127 int data_len=0,param_len=0;
2130 files_struct *fsp = NULL;
2134 bool start_enum = True;
2135 SMB_NTQUOTA_STRUCT qt;
2136 SMB_NTQUOTA_LIST *tmp_list;
2137 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2142 if (conn->server_info->utok.uid != 0) {
2143 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2144 "[%s]\n", lp_servicename(SNUM(conn)),
2145 conn->server_info->unix_name));
2146 reply_doserror(req, ERRDOS, ERRnoaccess);
2151 * Ensure minimum number of parameters sent.
2154 if (parameter_count < 4) {
2155 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2156 reply_doserror(req, ERRDOS, ERRinvalidparam);
2160 /* maybe we can check the quota_fnum */
2161 fsp = file_fsp(req, SVAL(params,0));
2162 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2163 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2164 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2168 /* the NULL pointer checking for fsp->fake_file_handle->pd
2169 * is done by CHECK_NTQUOTA_HANDLE_OK()
2171 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2173 level = SVAL(params,2);
2175 /* unknown 12 bytes leading in params */
2178 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2179 /* seems that we should continue with the enum here --metze */
2181 if (qt_handle->quota_list!=NULL &&
2182 qt_handle->tmp_list==NULL) {
2185 free_ntquota_list(&(qt_handle->quota_list));
2187 /* Realloc the size of parameters and data we will return */
2189 params = nttrans_realloc(ppparams, param_len);
2190 if(params == NULL) {
2191 reply_doserror(req, ERRDOS, ERRnomem);
2196 SIVAL(params,0,data_len);
2203 case TRANSACT_GET_USER_QUOTA_LIST_START:
2205 if (qt_handle->quota_list==NULL &&
2206 qt_handle->tmp_list==NULL) {
2210 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2211 reply_doserror(req, ERRSRV, ERRerror);
2215 /* Realloc the size of parameters and data we will return */
2217 params = nttrans_realloc(ppparams, param_len);
2218 if(params == NULL) {
2219 reply_doserror(req, ERRDOS, ERRnomem);
2223 /* we should not trust the value in max_data_count*/
2224 max_data_count = MIN(max_data_count,2048);
2226 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2228 reply_doserror(req, ERRDOS, ERRnomem);
2234 /* set params Size of returned Quota Data 4 bytes*/
2235 /* but set it later when we know it */
2237 /* for each entry push the data */
2240 qt_handle->tmp_list = qt_handle->quota_list;
2243 tmp_list = qt_handle->tmp_list;
2245 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2246 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2248 sid_len = ndr_size_dom_sid(
2249 &tmp_list->quotas->sid, NULL, 0);
2250 entry_len = 40 + sid_len;
2252 /* nextoffset entry 4 bytes */
2253 SIVAL(entry,0,entry_len);
2255 /* then the len of the SID 4 bytes */
2256 SIVAL(entry,4,sid_len);
2258 /* unknown data 8 bytes uint64_t */
2259 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2261 /* the used disk space 8 bytes uint64_t */
2262 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2264 /* the soft quotas 8 bytes uint64_t */
2265 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2267 /* the hard quotas 8 bytes uint64_t */
2268 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2270 /* and now the SID */
2271 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2274 qt_handle->tmp_list = tmp_list;
2276 /* overwrite the offset of the last entry */
2277 SIVAL(entry-entry_len,0,0);
2279 data_len = 4+qt_len;
2280 /* overwrite the params quota_data_len */
2281 SIVAL(params,0,data_len);
2285 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2287 /* unknown 4 bytes IVAL(pdata,0) */
2289 if (data_count < 8) {
2290 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2291 reply_doserror(req, ERRDOS, ERRunknownlevel);
2295 sid_len = IVAL(pdata,4);
2296 /* Ensure this is less than 1mb. */
2297 if (sid_len > (1024*1024)) {
2298 reply_doserror(req, ERRDOS, ERRnomem);
2302 if (data_count < 8+sid_len) {
2303 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2304 reply_doserror(req, ERRDOS, ERRunknownlevel);
2308 data_len = 4+40+sid_len;
2310 if (max_data_count < data_len) {
2311 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2312 max_data_count, data_len));
2314 SIVAL(params,0,data_len);
2316 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2320 sid_parse(pdata+8,sid_len,&sid);
2322 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2325 * we have to return zero's in all fields
2326 * instead of returning an error here
2331 /* Realloc the size of parameters and data we will return */
2333 params = nttrans_realloc(ppparams, param_len);
2334 if(params == NULL) {
2335 reply_doserror(req, ERRDOS, ERRnomem);
2339 pdata = nttrans_realloc(ppdata, data_len);
2341 reply_doserror(req, ERRDOS, ERRnomem);
2347 /* set params Size of returned Quota Data 4 bytes*/
2348 SIVAL(params,0,data_len);
2350 /* nextoffset entry 4 bytes */
2353 /* then the len of the SID 4 bytes */
2354 SIVAL(entry,4,sid_len);
2356 /* unknown data 8 bytes uint64_t */
2357 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2359 /* the used disk space 8 bytes uint64_t */
2360 SBIG_UINT(entry,16,qt.usedspace);
2362 /* the soft quotas 8 bytes uint64_t */
2363 SBIG_UINT(entry,24,qt.softlim);
2365 /* the hard quotas 8 bytes uint64_t */
2366 SBIG_UINT(entry,32,qt.hardlim);
2368 /* and now the SID */
2369 sid_linearize(entry+40, sid_len, &sid);
2374 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2375 reply_doserror(req, ERRSRV, ERRerror);
2380 send_nt_replies(conn, req, nt_status, params, param_len,
2384 /****************************************************************************
2385 Reply to set user quota
2386 ****************************************************************************/
2388 static void call_nt_transact_set_user_quota(connection_struct *conn,
2389 struct smb_request *req,
2393 uint32 parameter_count,
2396 uint32 max_data_count)
2398 char *params = *ppparams;
2399 char *pdata = *ppdata;
2400 int data_len=0,param_len=0;
2401 SMB_NTQUOTA_STRUCT qt;
2404 files_struct *fsp = NULL;
2409 if (conn->server_info->utok.uid != 0) {
2410 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2411 "[%s]\n", lp_servicename(SNUM(conn)),
2412 conn->server_info->unix_name));
2413 reply_doserror(req, ERRDOS, ERRnoaccess);
2418 * Ensure minimum number of parameters sent.
2421 if (parameter_count < 2) {
2422 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2423 reply_doserror(req, ERRDOS, ERRinvalidparam);
2427 /* maybe we can check the quota_fnum */
2428 fsp = file_fsp(req, SVAL(params,0));
2429 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2430 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2431 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2435 if (data_count < 40) {
2436 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2437 reply_doserror(req, ERRDOS, ERRunknownlevel);
2441 /* offset to next quota record.
2442 * 4 bytes IVAL(pdata,0)
2447 sid_len = IVAL(pdata,4);
2449 if (data_count < 40+sid_len) {
2450 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2451 reply_doserror(req, ERRDOS, ERRunknownlevel);
2455 /* unknown 8 bytes in pdata
2456 * maybe its the change time in NTTIME
2459 /* the used space 8 bytes (uint64_t)*/
2460 qt.usedspace = (uint64_t)IVAL(pdata,16);
2461 #ifdef LARGE_SMB_OFF_T
2462 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2463 #else /* LARGE_SMB_OFF_T */
2464 if ((IVAL(pdata,20) != 0)&&
2465 ((qt.usedspace != 0xFFFFFFFF)||
2466 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2467 /* more than 32 bits? */
2468 reply_doserror(req, ERRDOS, ERRunknownlevel);
2471 #endif /* LARGE_SMB_OFF_T */
2473 /* the soft quotas 8 bytes (uint64_t)*/
2474 qt.softlim = (uint64_t)IVAL(pdata,24);
2475 #ifdef LARGE_SMB_OFF_T
2476 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2477 #else /* LARGE_SMB_OFF_T */
2478 if ((IVAL(pdata,28) != 0)&&
2479 ((qt.softlim != 0xFFFFFFFF)||
2480 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2481 /* more than 32 bits? */
2482 reply_doserror(req, ERRDOS, ERRunknownlevel);
2485 #endif /* LARGE_SMB_OFF_T */
2487 /* the hard quotas 8 bytes (uint64_t)*/
2488 qt.hardlim = (uint64_t)IVAL(pdata,32);
2489 #ifdef LARGE_SMB_OFF_T
2490 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2491 #else /* LARGE_SMB_OFF_T */
2492 if ((IVAL(pdata,36) != 0)&&
2493 ((qt.hardlim != 0xFFFFFFFF)||
2494 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2495 /* more than 32 bits? */
2496 reply_doserror(req, ERRDOS, ERRunknownlevel);
2499 #endif /* LARGE_SMB_OFF_T */
2501 sid_parse(pdata+40,sid_len,&sid);
2502 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2504 /* 44 unknown bytes left... */
2506 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2507 reply_doserror(req, ERRSRV, ERRerror);
2511 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2514 #endif /* HAVE_SYS_QUOTAS */
2516 static void handle_nttrans(connection_struct *conn,
2517 struct trans_state *state,
2518 struct smb_request *req)
2520 if (Protocol >= PROTOCOL_NT1) {
2521 req->flags2 |= 0x40; /* IS_LONG_NAME */
2522 SSVAL(req->inbuf,smb_flg2,req->flags2);
2526 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2528 /* Now we must call the relevant NT_TRANS function */
2529 switch(state->call) {
2530 case NT_TRANSACT_CREATE:
2532 START_PROFILE(NT_transact_create);
2533 call_nt_transact_create(
2535 &state->setup, state->setup_count,
2536 &state->param, state->total_param,
2537 &state->data, state->total_data,
2538 state->max_data_return);
2539 END_PROFILE(NT_transact_create);
2543 case NT_TRANSACT_IOCTL:
2545 START_PROFILE(NT_transact_ioctl);
2546 call_nt_transact_ioctl(
2548 &state->setup, state->setup_count,
2549 &state->param, state->total_param,
2550 &state->data, state->total_data,
2551 state->max_data_return);
2552 END_PROFILE(NT_transact_ioctl);
2556 case NT_TRANSACT_SET_SECURITY_DESC:
2558 START_PROFILE(NT_transact_set_security_desc);
2559 call_nt_transact_set_security_desc(
2561 &state->setup, state->setup_count,
2562 &state->param, state->total_param,
2563 &state->data, state->total_data,
2564 state->max_data_return);
2565 END_PROFILE(NT_transact_set_security_desc);
2569 case NT_TRANSACT_NOTIFY_CHANGE:
2571 START_PROFILE(NT_transact_notify_change);
2572 call_nt_transact_notify_change(
2574 &state->setup, state->setup_count,
2575 &state->param, state->total_param,
2576 &state->data, state->total_data,
2577 state->max_data_return,
2578 state->max_param_return);
2579 END_PROFILE(NT_transact_notify_change);
2583 case NT_TRANSACT_RENAME:
2585 START_PROFILE(NT_transact_rename);
2586 call_nt_transact_rename(
2588 &state->setup, state->setup_count,
2589 &state->param, state->total_param,
2590 &state->data, state->total_data,
2591 state->max_data_return);
2592 END_PROFILE(NT_transact_rename);
2596 case NT_TRANSACT_QUERY_SECURITY_DESC:
2598 START_PROFILE(NT_transact_query_security_desc);
2599 call_nt_transact_query_security_desc(
2601 &state->setup, state->setup_count,
2602 &state->param, state->total_param,
2603 &state->data, state->total_data,
2604 state->max_data_return);
2605 END_PROFILE(NT_transact_query_security_desc);
2609 #ifdef HAVE_SYS_QUOTAS
2610 case NT_TRANSACT_GET_USER_QUOTA:
2612 START_PROFILE(NT_transact_get_user_quota);
2613 call_nt_transact_get_user_quota(
2615 &state->setup, state->setup_count,
2616 &state->param, state->total_param,
2617 &state->data, state->total_data,
2618 state->max_data_return);
2619 END_PROFILE(NT_transact_get_user_quota);
2623 case NT_TRANSACT_SET_USER_QUOTA:
2625 START_PROFILE(NT_transact_set_user_quota);
2626 call_nt_transact_set_user_quota(
2628 &state->setup, state->setup_count,
2629 &state->param, state->total_param,
2630 &state->data, state->total_data,
2631 state->max_data_return);
2632 END_PROFILE(NT_transact_set_user_quota);
2635 #endif /* HAVE_SYS_QUOTAS */
2638 /* Error in request */
2639 DEBUG(0,("handle_nttrans: Unknown request %d in "
2640 "nttrans call\n", state->call));
2641 reply_doserror(req, ERRSRV, ERRerror);
2647 /****************************************************************************
2648 Reply to a SMBNTtrans.
2649 ****************************************************************************/
2651 void reply_nttrans(struct smb_request *req)
2653 connection_struct *conn = req->conn;
2658 uint16 function_code;
2660 struct trans_state *state;
2662 START_PROFILE(SMBnttrans);
2664 if (req->wct < 19) {
2665 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2666 END_PROFILE(SMBnttrans);
2670 pscnt = IVAL(req->vwv+9, 1);
2671 psoff = IVAL(req->vwv+11, 1);
2672 dscnt = IVAL(req->vwv+13, 1);
2673 dsoff = IVAL(req->vwv+15, 1);
2674 function_code = SVAL(req->vwv+18, 0);
2676 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2677 reply_doserror(req, ERRSRV, ERRaccess);
2678 END_PROFILE(SMBnttrans);
2682 result = allow_new_trans(conn->pending_trans, req->mid);
2683 if (!NT_STATUS_IS_OK(result)) {
2684 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2685 reply_nterror(req, result);
2686 END_PROFILE(SMBnttrans);
2690 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2691 reply_doserror(req, ERRSRV, ERRaccess);
2692 END_PROFILE(SMBnttrans);
2696 state->cmd = SMBnttrans;
2698 state->mid = req->mid;
2699 state->vuid = req->vuid;
2700 state->total_data = IVAL(req->vwv+3, 1);
2702 state->total_param = IVAL(req->vwv+1, 1);
2703 state->param = NULL;
2704 state->max_data_return = IVAL(req->vwv+7, 1);
2705 state->max_param_return = IVAL(req->vwv+5, 1);
2707 /* setup count is in *words* */
2708 state->setup_count = 2*CVAL(req->vwv+17, 1);
2709 state->setup = NULL;
2710 state->call = function_code;
2712 DEBUG(10, ("num_setup=%u, "
2713 "param_total=%u, this_param=%u, max_param=%u, "
2714 "data_total=%u, this_data=%u, max_data=%u, "
2715 "param_offset=%u, data_offset=%u\n",
2716 (unsigned)state->setup_count,
2717 (unsigned)state->total_param, (unsigned)pscnt,
2718 (unsigned)state->max_param_return,
2719 (unsigned)state->total_data, (unsigned)dscnt,
2720 (unsigned)state->max_data_return,
2721 (unsigned)psoff, (unsigned)dsoff));
2724 * All nttrans messages we handle have smb_wct == 19 +
2725 * state->setup_count. Ensure this is so as a sanity check.
2728 if(req->wct != 19 + (state->setup_count/2)) {
2729 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2730 req->wct, 19 + (state->setup_count/2)));
2734 /* Don't allow more than 128mb for each value. */
2735 if ((state->total_data > (1024*1024*128)) ||
2736 (state->total_param > (1024*1024*128))) {
2737 reply_doserror(req, ERRDOS, ERRnomem);
2738 END_PROFILE(SMBnttrans);
2742 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2745 if (state->total_data) {
2747 if (trans_oob(state->total_data, 0, dscnt)
2748 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2752 /* Can't use talloc here, the core routines do realloc on the
2753 * params and data. */
2754 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2755 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2756 "bytes !\n", (unsigned int)state->total_data));
2758 reply_doserror(req, ERRDOS, ERRnomem);
2759 END_PROFILE(SMBnttrans);
2763 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2766 if (state->total_param) {
2768 if (trans_oob(state->total_param, 0, pscnt)
2769 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2773 /* Can't use talloc here, the core routines do realloc on the
2774 * params and data. */
2775 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2776 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2777 "bytes !\n", (unsigned int)state->total_param));
2778 SAFE_FREE(state->data);
2780 reply_doserror(req, ERRDOS, ERRnomem);
2781 END_PROFILE(SMBnttrans);
2785 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2788 state->received_data = dscnt;
2789 state->received_param = pscnt;
2791 if(state->setup_count > 0) {
2792 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2793 state->setup_count));
2796 * No overflow possible here, state->setup_count is an
2797 * unsigned int, being filled by a single byte from
2798 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2799 * below is not necessary, it's here to clarify things. The
2800 * validity of req->vwv and req->wct has been checked in
2801 * init_smb_request already.
2803 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2807 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2808 if (state->setup == NULL) {
2809 DEBUG(0,("reply_nttrans : Out of memory\n"));
2810 SAFE_FREE(state->data);
2811 SAFE_FREE(state->param);
2813 reply_doserror(req, ERRDOS, ERRnomem);
2814 END_PROFILE(SMBnttrans);
2818 memcpy(state->setup, req->vwv+19, state->setup_count);
2819 dump_data(10, (uint8 *)state->setup, state->setup_count);
2822 if ((state->received_data == state->total_data) &&
2823 (state->received_param == state->total_param)) {
2824 handle_nttrans(conn, state, req);
2825 SAFE_FREE(state->param);
2826 SAFE_FREE(state->data);
2828 END_PROFILE(SMBnttrans);
2832 DLIST_ADD(conn->pending_trans, state);
2834 /* We need to send an interim response then receive the rest
2835 of the parameter/data bytes */
2836 reply_outbuf(req, 0, 0);
2837 show_msg((char *)req->outbuf);
2838 END_PROFILE(SMBnttrans);
2843 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2844 SAFE_FREE(state->data);
2845 SAFE_FREE(state->param);
2847 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2848 END_PROFILE(SMBnttrans);
2852 /****************************************************************************
2853 Reply to a SMBnttranss
2854 ****************************************************************************/
2856 void reply_nttranss(struct smb_request *req)
2858 connection_struct *conn = req->conn;
2859 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2860 struct trans_state *state;
2862 START_PROFILE(SMBnttranss);
2864 show_msg((char *)req->inbuf);
2866 if (req->wct < 18) {
2867 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2868 END_PROFILE(SMBnttranss);
2872 for (state = conn->pending_trans; state != NULL;
2873 state = state->next) {
2874 if (state->mid == req->mid) {
2879 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2880 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2881 END_PROFILE(SMBnttranss);
2885 /* Revise state->total_param and state->total_data in case they have
2886 changed downwards */
2887 if (IVAL(req->vwv+1, 1) < state->total_param) {
2888 state->total_param = IVAL(req->vwv+1, 1);
2890 if (IVAL(req->vwv+3, 1) < state->total_data) {
2891 state->total_data = IVAL(req->vwv+3, 1);
2894 pcnt = IVAL(req->vwv+5, 1);
2895 poff = IVAL(req->vwv+7, 1);
2896 pdisp = IVAL(req->vwv+9, 1);
2898 dcnt = IVAL(req->vwv+11, 1);
2899 doff = IVAL(req->vwv+13, 1);
2900 ddisp = IVAL(req->vwv+15, 1);
2902 state->received_param += pcnt;
2903 state->received_data += dcnt;
2905 if ((state->received_data > state->total_data) ||
2906 (state->received_param > state->total_param))
2910 if (trans_oob(state->total_param, pdisp, pcnt)
2911 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2914 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2918 if (trans_oob(state->total_data, ddisp, dcnt)
2919 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2922 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2925 if ((state->received_param < state->total_param) ||
2926 (state->received_data < state->total_data)) {
2927 END_PROFILE(SMBnttranss);
2931 handle_nttrans(conn, state, req);
2933 DLIST_REMOVE(conn->pending_trans, state);
2934 SAFE_FREE(state->data);
2935 SAFE_FREE(state->param);
2937 END_PROFILE(SMBnttranss);
2942 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2943 DLIST_REMOVE(conn->pending_trans, state);
2944 SAFE_FREE(state->data);
2945 SAFE_FREE(state->param);
2947 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2948 END_PROFILE(SMBnttranss);