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/>.
24 extern enum protocol_types Protocol;
25 extern struct current_user current_user;
27 static const char *known_nt_pipes[] = {
48 static char *nttrans_realloc(char **ptr, size_t size)
51 smb_panic("nttrans_realloc() called with NULL ptr");
54 *ptr = (char *)SMB_REALLOC(*ptr, size);
58 memset(*ptr,'\0',size);
62 /****************************************************************************
63 Send the required number of replies back.
64 We assume all fields other than the data fields are
65 set correctly for the type of call.
66 HACK ! Always assumes smb_setup field is zero.
67 ****************************************************************************/
69 void send_nt_replies(struct smb_request *req, NTSTATUS nt_error,
70 char *params, int paramsize,
71 char *pdata, int datasize)
73 int data_to_send = datasize;
74 int params_to_send = paramsize;
78 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
79 int alignment_offset = 3;
80 int data_alignment_offset = 0;
83 * If there genuinely are no parameters or data to send just send
87 if(params_to_send == 0 && data_to_send == 0) {
88 reply_outbuf(req, 18, 0);
89 show_msg((char *)req->outbuf);
94 * When sending params and data ensure that both are nicely aligned.
95 * Only do this alignment when there is also data to send - else
96 * can cause NT redirector problems.
99 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
100 data_alignment_offset = 4 - (params_to_send % 4);
104 * Space is bufsize minus Netbios over TCP header minus SMB header.
105 * The alignment_offset is to align the param bytes on a four byte
106 * boundary (2 bytes for data len, one byte pad).
107 * NT needs this to work correctly.
110 useable_space = max_send - (smb_size
113 + data_alignment_offset);
116 * useable_space can never be more than max_send minus the
120 useable_space = MIN(useable_space,
121 max_send - (alignment_offset+data_alignment_offset));
124 while (params_to_send || data_to_send) {
127 * Calculate whether we will totally or partially fill this packet.
130 total_sent_thistime = params_to_send + data_to_send +
131 alignment_offset + data_alignment_offset;
134 * We can never send more than useable_space.
137 total_sent_thistime = MIN(total_sent_thistime, useable_space);
139 reply_outbuf(req, 18, total_sent_thistime);
142 * Set total params and data to be sent.
145 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
146 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
149 * Calculate how many parameters and data we can fit into
150 * this packet. Parameters get precedence.
153 params_sent_thistime = MIN(params_to_send,useable_space);
154 data_sent_thistime = useable_space - params_sent_thistime;
155 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
157 SIVAL(req->outbuf, smb_ntr_ParameterCount,
158 params_sent_thistime);
160 if(params_sent_thistime == 0) {
161 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
162 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
165 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
166 * parameter bytes, however the first 4 bytes of outbuf are
167 * the Netbios over TCP header. Thus use smb_base() to subtract
168 * them from the calculation.
171 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
172 ((smb_buf(req->outbuf)+alignment_offset)
173 - smb_base(req->outbuf)));
175 * Absolute displacement of param bytes sent in this packet.
178 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
183 * Deal with the data portion.
186 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
188 if(data_sent_thistime == 0) {
189 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
190 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
193 * The offset of the data bytes is the offset of the
194 * parameter bytes plus the number of parameters being sent this time.
197 SIVAL(req->outbuf, smb_ntr_DataOffset,
198 ((smb_buf(req->outbuf)+alignment_offset) -
199 smb_base(req->outbuf))
200 + params_sent_thistime + data_alignment_offset);
201 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
205 * Copy the param bytes into the packet.
208 if(params_sent_thistime) {
209 if (alignment_offset != 0) {
210 memset(smb_buf(req->outbuf), 0,
213 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
214 params_sent_thistime);
218 * Copy in the data bytes
221 if(data_sent_thistime) {
222 if (data_alignment_offset != 0) {
223 memset((smb_buf(req->outbuf)+alignment_offset+
224 params_sent_thistime), 0,
225 data_alignment_offset);
227 memcpy(smb_buf(req->outbuf)+alignment_offset
228 +params_sent_thistime+data_alignment_offset,
229 pd,data_sent_thistime);
232 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
233 params_sent_thistime, data_sent_thistime, useable_space));
234 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
235 params_to_send, data_to_send, paramsize, datasize));
237 if (NT_STATUS_V(nt_error)) {
238 error_packet_set((char *)req->outbuf,
243 /* Send the packet */
244 show_msg((char *)req->outbuf);
245 if (!send_smb(smbd_server_fd(),(char *)req->outbuf)) {
246 exit_server_cleanly("send_nt_replies: send_smb failed.");
249 TALLOC_FREE(req->outbuf);
251 pp += params_sent_thistime;
252 pd += data_sent_thistime;
254 params_to_send -= params_sent_thistime;
255 data_to_send -= data_sent_thistime;
261 if(params_to_send < 0 || data_to_send < 0) {
262 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
263 params_to_send, data_to_send));
269 /****************************************************************************
270 Is it an NTFS stream name ?
271 ****************************************************************************/
273 bool is_ntfs_stream_name(const char *fname)
275 if (lp_posix_pathnames()) {
278 return (strchr_m(fname, ':') != NULL) ? True : False;
281 /****************************************************************************
282 Reply to an NT create and X call on a pipe
283 ****************************************************************************/
285 static void nt_open_pipe(char *fname, connection_struct *conn,
286 struct smb_request *req, int *ppnum)
288 smb_np_struct *p = NULL;
291 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
293 /* See if it is one we want to handle. */
295 if (lp_disable_spoolss() && strequal(fname, "\\spoolss")) {
296 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
301 for( i = 0; known_nt_pipes[i]; i++ ) {
302 if( strequal(fname,known_nt_pipes[i])) {
307 if ( known_nt_pipes[i] == NULL ) {
308 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
313 /* Strip \\ off the name. */
316 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
318 p = open_rpc_pipe_p(fname, conn, req->vuid);
320 reply_doserror(req, ERRSRV, ERRnofids);
324 /* TODO: Add pipe to db */
326 if ( !store_pipe_opendb( p ) ) {
327 DEBUG(3,("nt_open_pipe: failed to store %s pipe open.\n", fname));
334 /****************************************************************************
335 Reply to an NT create and X call for pipes.
336 ****************************************************************************/
338 static void do_ntcreate_pipe_open(connection_struct *conn,
339 struct smb_request *req)
344 uint32 flags = IVAL(req->inbuf,smb_ntcreate_Flags);
345 TALLOC_CTX *ctx = talloc_tos();
347 srvstr_pull_buf_talloc(ctx, (char *)req->inbuf, req->flags2, &fname,
348 smb_buf(req->inbuf), STR_TERMINATE);
351 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
355 nt_open_pipe(fname, conn, req, &pnum);
363 * Deal with pipe return.
366 if (flags & EXTENDED_RESPONSE_REQUIRED) {
367 /* This is very strange. We
368 * return 50 words, but only set
369 * the wcnt to 42 ? It's definately
370 * what happens on the wire....
372 reply_outbuf(req, 50, 0);
373 SCVAL(req->outbuf,smb_wct,42);
375 reply_outbuf(req, 34, 0);
378 p = (char *)req->outbuf + smb_vwv2;
382 SIVAL(p,0,FILE_WAS_OPENED);
385 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
388 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
390 SSVAL(p,2, 0x5FF); /* ? */
393 if (flags & EXTENDED_RESPONSE_REQUIRED) {
395 SIVAL(p,0,FILE_GENERIC_ALL);
397 * For pipes W2K3 seems to return
399 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
401 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
404 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
409 /****************************************************************************
410 Reply to an NT create and X call.
411 ****************************************************************************/
413 void reply_ntcreate_and_X(connection_struct *conn, struct smb_request *req)
418 uint32 file_attributes;
420 uint32 create_disposition;
421 uint32 create_options;
423 SMB_BIG_UINT allocation_size;
424 /* Breakout the oplock request bits so we can set the
425 reply bits separately. */
427 SMB_OFF_T file_len = 0;
428 SMB_STRUCT_STAT sbuf;
430 files_struct *fsp = NULL;
432 struct timespec c_timespec;
433 struct timespec a_timespec;
434 struct timespec m_timespec;
437 uint8_t oplock_granted = NO_OPLOCK_RETURN;
438 TALLOC_CTX *ctx = talloc_tos();
440 START_PROFILE(SMBntcreateX);
443 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
447 flags = IVAL(req->inbuf,smb_ntcreate_Flags);
448 access_mask = IVAL(req->inbuf,smb_ntcreate_DesiredAccess);
449 file_attributes = IVAL(req->inbuf,smb_ntcreate_FileAttributes);
450 share_access = IVAL(req->inbuf,smb_ntcreate_ShareAccess);
451 create_disposition = IVAL(req->inbuf,smb_ntcreate_CreateDisposition);
452 create_options = IVAL(req->inbuf,smb_ntcreate_CreateOptions);
453 root_dir_fid = (uint16)IVAL(req->inbuf,smb_ntcreate_RootDirectoryFid);
455 allocation_size = (SMB_BIG_UINT)IVAL(req->inbuf,
456 smb_ntcreate_AllocationSize);
457 #ifdef LARGE_SMB_OFF_T
458 allocation_size |= (((SMB_BIG_UINT)IVAL(
460 smb_ntcreate_AllocationSize + 4)) << 32);
463 srvstr_get_path(ctx, (char *)req->inbuf, req->flags2, &fname,
464 smb_buf(req->inbuf), 0, STR_TERMINATE, &status);
466 if (!NT_STATUS_IS_OK(status)) {
467 reply_nterror(req, status);
468 END_PROFILE(SMBntcreateX);
472 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
473 "file_attributes = 0x%x, share_access = 0x%x, "
474 "create_disposition = 0x%x create_options = 0x%x "
475 "root_dir_fid = 0x%x, fname = %s\n",
477 (unsigned int)access_mask,
478 (unsigned int)file_attributes,
479 (unsigned int)share_access,
480 (unsigned int)create_disposition,
481 (unsigned int)create_options,
482 (unsigned int)root_dir_fid,
486 * If it's an IPC, use the pipe handler.
490 if (lp_nt_pipe_support()) {
491 do_ntcreate_pipe_open(conn, req);
492 END_PROFILE(SMBntcreateX);
495 reply_doserror(req, ERRDOS, ERRnoaccess);
496 END_PROFILE(SMBntcreateX);
501 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
502 if (oplock_request) {
503 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
507 status = create_file(conn, req, root_dir_fid, fname,
508 access_mask, share_access, create_disposition,
509 create_options, file_attributes, oplock_request,
510 allocation_size, NULL, NULL, &fsp, &info, &sbuf);
512 if (!NT_STATUS_IS_OK(status)) {
513 if (open_was_deferred(req->mid)) {
514 /* We have re-scheduled this call, no error. */
515 END_PROFILE(SMBntcreateX);
518 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
519 reply_botherror(req, status, ERRDOS, ERRfilexists);
522 reply_nterror(req, status);
524 END_PROFILE(SMBntcreateX);
529 * If the caller set the extended oplock request bit
530 * and we granted one (by whatever means) - set the
531 * correct bit for extended oplock reply.
534 if (oplock_request &&
535 (lp_fake_oplocks(SNUM(conn))
536 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
539 * Exclusive oplock granted
542 if (flags & REQUEST_BATCH_OPLOCK) {
543 oplock_granted = BATCH_OPLOCK_RETURN;
545 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
547 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
548 oplock_granted = LEVEL_II_OPLOCK_RETURN;
550 oplock_granted = NO_OPLOCK_RETURN;
553 file_len = sbuf.st_size;
554 fattr = dos_mode(conn,fname,&sbuf);
556 fattr = FILE_ATTRIBUTE_NORMAL;
559 if (flags & EXTENDED_RESPONSE_REQUIRED) {
560 /* This is very strange. We
561 * return 50 words, but only set
562 * the wcnt to 42 ? It's definately
563 * what happens on the wire....
565 reply_outbuf(req, 50, 0);
566 SCVAL(req->outbuf,smb_wct,42);
568 reply_outbuf(req, 34, 0);
571 p = (char *)req->outbuf + smb_vwv2;
573 SCVAL(p, 0, oplock_granted);
576 SSVAL(p,0,fsp->fnum);
578 if ((create_disposition == FILE_SUPERSEDE)
579 && (info == FILE_WAS_OVERWRITTEN)) {
580 SIVAL(p,0,FILE_WAS_SUPERSEDED);
587 c_timespec = get_create_timespec(
588 &sbuf,lp_fake_dir_create_times(SNUM(conn)));
589 a_timespec = get_atimespec(&sbuf);
590 m_timespec = get_mtimespec(&sbuf);
592 if (lp_dos_filetime_resolution(SNUM(conn))) {
593 dos_filetime_timespec(&c_timespec);
594 dos_filetime_timespec(&a_timespec);
595 dos_filetime_timespec(&m_timespec);
598 put_long_date_timespec(p, c_timespec); /* create time. */
600 put_long_date_timespec(p, a_timespec); /* access time */
602 put_long_date_timespec(p, m_timespec); /* write time */
604 put_long_date_timespec(p, m_timespec); /* change time */
606 SIVAL(p,0,fattr); /* File Attributes. */
608 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
610 SOFF_T(p,0,file_len);
612 if (flags & EXTENDED_RESPONSE_REQUIRED) {
616 SCVAL(p,0,fsp->is_directory ? 1 : 0);
618 if (flags & EXTENDED_RESPONSE_REQUIRED) {
621 if (fsp->is_directory
622 || can_write_to_file(conn, fname, &sbuf)) {
623 perms = FILE_GENERIC_ALL;
625 perms = FILE_GENERIC_READ|FILE_EXECUTE;
630 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
631 fsp->fnum, fsp->fsp_name));
634 END_PROFILE(SMBntcreateX);
638 /****************************************************************************
639 Reply to a NT_TRANSACT_CREATE call to open a pipe.
640 ****************************************************************************/
642 static void do_nt_transact_create_pipe(connection_struct *conn,
643 struct smb_request *req,
644 uint16 **ppsetup, uint32 setup_count,
645 char **ppparams, uint32 parameter_count,
646 char **ppdata, uint32 data_count)
649 char *params = *ppparams;
655 TALLOC_CTX *ctx = talloc_tos();
658 * Ensure minimum number of parameters sent.
661 if(parameter_count < 54) {
662 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
663 reply_doserror(req, ERRDOS, ERRnoaccess);
667 flags = IVAL(params,0);
669 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
670 parameter_count-53, STR_TERMINATE,
672 if (!NT_STATUS_IS_OK(status)) {
673 reply_nterror(req, status);
677 nt_open_pipe(fname, conn, req, &pnum);
684 /* Realloc the size of parameters and data we will return */
685 if (flags & EXTENDED_RESPONSE_REQUIRED) {
686 /* Extended response is 32 more byyes. */
691 params = nttrans_realloc(ppparams, param_len);
693 reply_doserror(req, ERRDOS, ERRnomem);
698 SCVAL(p,0,NO_OPLOCK_RETURN);
703 SIVAL(p,0,FILE_WAS_OPENED);
707 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
710 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
712 SSVAL(p,2, 0x5FF); /* ? */
715 if (flags & EXTENDED_RESPONSE_REQUIRED) {
717 SIVAL(p,0,FILE_GENERIC_ALL);
719 * For pipes W2K3 seems to return
721 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
723 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
726 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
728 /* Send the required number of replies */
729 send_nt_replies(req, NT_STATUS_OK, params, param_len, *ppdata, 0);
734 /****************************************************************************
735 Internal fn to set security descriptors.
736 ****************************************************************************/
738 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
741 SEC_DESC *psd = NULL;
745 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
750 * Init the parse struct we will unmarshall from.
753 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
754 DEBUG(0,("set_sd: talloc_init failed.\n"));
755 return NT_STATUS_NO_MEMORY;
758 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
761 * Setup the prs_struct to point at the memory we just
765 prs_give_memory( &pd, data, sd_len, False);
768 * Finally, unmarshall from the data buffer.
771 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
772 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
774 * Return access denied for want of a better error message..
776 talloc_destroy(mem_ctx);
777 return NT_STATUS_NO_MEMORY;
780 if (psd->owner_sid==0) {
781 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
783 if (psd->group_sid==0) {
784 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
787 security_info_sent &= ~SACL_SECURITY_INFORMATION;
790 security_info_sent &= ~DACL_SECURITY_INFORMATION;
793 status = SMB_VFS_FSET_NT_ACL( fsp, fsp->fh->fd, security_info_sent, psd);
795 talloc_destroy(mem_ctx);
799 /****************************************************************************
800 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
801 ****************************************************************************/
803 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
805 struct ea_list *ea_list_head = NULL;
812 while (offset + 4 <= data_size) {
813 size_t next_offset = IVAL(pdata,offset);
814 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
820 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
821 if (next_offset == 0) {
824 offset += next_offset;
830 /****************************************************************************
831 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
832 ****************************************************************************/
834 static void call_nt_transact_create(connection_struct *conn,
835 struct smb_request *req,
836 uint16 **ppsetup, uint32 setup_count,
837 char **ppparams, uint32 parameter_count,
838 char **ppdata, uint32 data_count,
839 uint32 max_data_count)
842 char *params = *ppparams;
843 char *data = *ppdata;
844 /* Breakout the oplock request bits so we can set the reply bits separately. */
846 SMB_OFF_T file_len = 0;
847 SMB_STRUCT_STAT sbuf;
849 files_struct *fsp = NULL;
853 uint32 file_attributes;
855 uint32 create_disposition;
856 uint32 create_options;
858 struct security_descriptor *sd = NULL;
861 struct timespec c_timespec;
862 struct timespec a_timespec;
863 struct timespec m_timespec;
864 struct ea_list *ea_list = NULL;
867 SMB_BIG_UINT allocation_size;
869 uint8_t oplock_granted;
870 TALLOC_CTX *ctx = talloc_tos();
872 DEBUG(5,("call_nt_transact_create\n"));
875 * If it's an IPC, use the pipe handler.
879 if (lp_nt_pipe_support()) {
880 do_nt_transact_create_pipe(
882 ppsetup, setup_count,
883 ppparams, parameter_count,
887 reply_doserror(req, ERRDOS, ERRnoaccess);
893 * Ensure minimum number of parameters sent.
896 if(parameter_count < 54) {
897 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
898 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
902 flags = IVAL(params,0);
903 access_mask = IVAL(params,8);
904 file_attributes = IVAL(params,20);
905 share_access = IVAL(params,24);
906 create_disposition = IVAL(params,28);
907 create_options = IVAL(params,32);
908 sd_len = IVAL(params,36);
909 ea_len = IVAL(params,40);
910 root_dir_fid = (uint16)IVAL(params,4);
911 allocation_size = (SMB_BIG_UINT)IVAL(params,12);
912 #ifdef LARGE_SMB_OFF_T
913 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
916 /* Ensure the data_len is correct for the sd and ea values given. */
917 if ((ea_len + sd_len > data_count)
918 || (ea_len > data_count) || (sd_len > data_count)
919 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
920 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
921 "%u, data_count = %u\n", (unsigned int)ea_len,
922 (unsigned int)sd_len, (unsigned int)data_count));
923 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
928 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
931 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
933 if (!NT_STATUS_IS_OK(status)) {
934 DEBUG(10, ("call_nt_transact_create: "
935 "unmarshall_sec_desc failed: %s\n",
937 reply_nterror(req, status);
943 if (!lp_ea_support(SNUM(conn))) {
944 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
945 "EA's not supported.\n",
946 (unsigned int)ea_len));
947 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
952 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
953 "too small (should be more than 10)\n",
954 (unsigned int)ea_len ));
955 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
959 /* We have already checked that ea_len <= data_count here. */
960 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
962 if (ea_list == NULL) {
963 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
968 srvstr_get_path(ctx, params, req->flags2, &fname,
969 params+53, parameter_count-53,
970 STR_TERMINATE, &status);
971 if (!NT_STATUS_IS_OK(status)) {
972 reply_nterror(req, status);
976 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
977 if (oplock_request) {
978 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
982 status = create_file(conn, req, root_dir_fid, fname,
983 access_mask, share_access, create_disposition,
984 create_options, file_attributes, oplock_request,
985 allocation_size, sd, ea_list, &fsp, &info, &sbuf);
987 if(!NT_STATUS_IS_OK(status)) {
988 if (open_was_deferred(req->mid)) {
989 /* We have re-scheduled this call, no error. */
992 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
993 reply_botherror(req, status, ERRDOS, ERRfilexists);
996 reply_nterror(req, status);
1002 * If the caller set the extended oplock request bit
1003 * and we granted one (by whatever means) - set the
1004 * correct bit for extended oplock reply.
1007 if (oplock_request &&
1008 (lp_fake_oplocks(SNUM(conn))
1009 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1012 * Exclusive oplock granted
1015 if (flags & REQUEST_BATCH_OPLOCK) {
1016 oplock_granted = BATCH_OPLOCK_RETURN;
1018 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1020 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1021 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1023 oplock_granted = NO_OPLOCK_RETURN;
1026 file_len = sbuf.st_size;
1027 fattr = dos_mode(conn,fname,&sbuf);
1029 fattr = FILE_ATTRIBUTE_NORMAL;
1032 /* Realloc the size of parameters and data we will return */
1033 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1034 /* Extended response is 32 more byyes. */
1039 params = nttrans_realloc(ppparams, param_len);
1040 if(params == NULL) {
1041 reply_doserror(req, ERRDOS, ERRnomem);
1046 SCVAL(p, 0, oplock_granted);
1049 SSVAL(p,0,fsp->fnum);
1051 if ((create_disposition == FILE_SUPERSEDE)
1052 && (info == FILE_WAS_OVERWRITTEN)) {
1053 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1060 c_timespec = get_create_timespec(
1061 &sbuf,lp_fake_dir_create_times(SNUM(conn)));
1062 a_timespec = get_atimespec(&sbuf);
1063 m_timespec = get_mtimespec(&sbuf);
1065 if (lp_dos_filetime_resolution(SNUM(conn))) {
1066 dos_filetime_timespec(&c_timespec);
1067 dos_filetime_timespec(&a_timespec);
1068 dos_filetime_timespec(&m_timespec);
1071 put_long_date_timespec(p, c_timespec); /* create time. */
1073 put_long_date_timespec(p, a_timespec); /* access time */
1075 put_long_date_timespec(p, m_timespec); /* write time */
1077 put_long_date_timespec(p, m_timespec); /* change time */
1079 SIVAL(p,0,fattr); /* File Attributes. */
1081 SOFF_T(p, 0, get_allocation_size(conn,fsp,&sbuf));
1083 SOFF_T(p,0,file_len);
1085 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1089 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1091 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1094 if (fsp->is_directory
1095 || can_write_to_file(conn, fname, &sbuf)) {
1096 perms = FILE_GENERIC_ALL;
1098 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1103 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1105 /* Send the required number of replies */
1106 send_nt_replies(req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1111 /****************************************************************************
1112 Reply to a NT CANCEL request.
1113 conn POINTER CAN BE NULL HERE !
1114 ****************************************************************************/
1116 void reply_ntcancel(connection_struct *conn, struct smb_request *req)
1119 * Go through and cancel any pending change notifies.
1122 START_PROFILE(SMBntcancel);
1123 remove_pending_change_notify_requests_by_mid(req->mid);
1124 remove_pending_lock_requests_by_mid(req->mid);
1125 srv_cancel_sign_response(req->mid);
1127 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1129 END_PROFILE(SMBntcancel);
1133 /****************************************************************************
1135 ****************************************************************************/
1137 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1138 connection_struct *conn,
1139 struct smb_request *req,
1140 const char *oldname_in,
1141 const char *newname_in,
1144 SMB_STRUCT_STAT sbuf1, sbuf2;
1145 char *oldname = NULL;
1146 char *newname = NULL;
1147 char *last_component_oldname = NULL;
1148 char *last_component_newname = NULL;
1149 files_struct *fsp1,*fsp2;
1153 NTSTATUS status = NT_STATUS_OK;
1158 if (!CAN_WRITE(conn)) {
1159 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1162 status = unix_convert(ctx, conn, oldname_in, False, &oldname,
1163 &last_component_oldname, &sbuf1);
1164 if (!NT_STATUS_IS_OK(status)) {
1168 status = check_name(conn, oldname);
1169 if (!NT_STATUS_IS_OK(status)) {
1173 /* Source must already exist. */
1174 if (!VALID_STAT(sbuf1)) {
1175 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1177 /* Ensure attributes match. */
1178 fattr = dos_mode(conn,oldname,&sbuf1);
1179 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1180 return NT_STATUS_NO_SUCH_FILE;
1183 status = unix_convert(ctx, conn, newname_in, False, &newname,
1184 &last_component_newname, &sbuf2);
1185 if (!NT_STATUS_IS_OK(status)) {
1189 status = check_name(conn, newname);
1190 if (!NT_STATUS_IS_OK(status)) {
1194 /* Disallow if newname already exists. */
1195 if (VALID_STAT(sbuf2)) {
1196 return NT_STATUS_OBJECT_NAME_COLLISION;
1199 /* No links from a directory. */
1200 if (S_ISDIR(sbuf1.st_mode)) {
1201 return NT_STATUS_FILE_IS_A_DIRECTORY;
1204 /* Ensure this is within the share. */
1205 status = check_reduced_name(conn, oldname);
1206 if (!NT_STATUS_IS_OK(status)) {
1210 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1213 status = open_file_ntcreate(conn, req, oldname, &sbuf1,
1214 FILE_READ_DATA, /* Read-only. */
1215 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1217 0, /* No create options. */
1218 FILE_ATTRIBUTE_NORMAL,
1222 if (!NT_STATUS_IS_OK(status)) {
1226 status = open_file_ntcreate(conn, req, newname, &sbuf2,
1227 FILE_WRITE_DATA, /* Read-only. */
1228 FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
1230 0, /* No create options. */
1235 if (!NT_STATUS_IS_OK(status)) {
1236 close_file(fsp1,ERROR_CLOSE);
1240 if (sbuf1.st_size) {
1241 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1245 * As we are opening fsp1 read-only we only expect
1246 * an error on close on fsp2 if we are out of space.
1247 * Thus we don't look at the error return from the
1250 close_file(fsp1,NORMAL_CLOSE);
1252 /* Ensure the modtime is set correctly on the destination file. */
1253 fsp_set_pending_modtime(fsp2, get_mtimespec(&sbuf1));
1255 status = close_file(fsp2,NORMAL_CLOSE);
1257 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1258 creates the file. This isn't the correct thing to do in the copy
1260 file_set_dosmode(conn, newname, fattr, &sbuf2,
1261 parent_dirname(newname),false);
1263 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1264 return NT_STATUS_DISK_FULL;
1267 if (!NT_STATUS_IS_OK(status)) {
1268 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1269 nt_errstr(status), oldname, newname));
1274 /****************************************************************************
1275 Reply to a NT rename request.
1276 ****************************************************************************/
1278 void reply_ntrename(connection_struct *conn, struct smb_request *req)
1280 char *oldname = NULL;
1281 char *newname = NULL;
1284 bool src_has_wcard = False;
1285 bool dest_has_wcard = False;
1288 TALLOC_CTX *ctx = talloc_tos();
1290 START_PROFILE(SMBntrename);
1293 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1294 END_PROFILE(SMBntrename);
1298 attrs = SVAL(req->inbuf,smb_vwv0);
1299 rename_type = SVAL(req->inbuf,smb_vwv1);
1301 p = smb_buf(req->inbuf) + 1;
1302 p += srvstr_get_path_wcard(ctx, (char *)req->inbuf, req->flags2, &oldname, p,
1303 0, STR_TERMINATE, &status,
1305 if (!NT_STATUS_IS_OK(status)) {
1306 reply_nterror(req, status);
1307 END_PROFILE(SMBntrename);
1311 if( is_ntfs_stream_name(oldname)) {
1312 /* Can't rename a stream. */
1313 reply_nterror(req, NT_STATUS_ACCESS_DENIED);
1314 END_PROFILE(SMBntrename);
1318 if (ms_has_wild(oldname)) {
1319 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1320 END_PROFILE(SMBntrename);
1325 p += srvstr_get_path_wcard(ctx, (char *)req->inbuf, req->flags2, &newname, p,
1326 0, STR_TERMINATE, &status,
1328 if (!NT_STATUS_IS_OK(status)) {
1329 reply_nterror(req, status);
1330 END_PROFILE(SMBntrename);
1334 status = resolve_dfspath(ctx, conn,
1335 req->flags2 & FLAGS2_DFS_PATHNAMES,
1338 if (!NT_STATUS_IS_OK(status)) {
1339 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1340 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1341 ERRSRV, ERRbadpath);
1342 END_PROFILE(SMBntrename);
1345 reply_nterror(req, status);
1346 END_PROFILE(SMBntrename);
1350 status = resolve_dfspath(ctx, conn,
1351 req->flags2 & FLAGS2_DFS_PATHNAMES,
1354 if (!NT_STATUS_IS_OK(status)) {
1355 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1356 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1357 ERRSRV, ERRbadpath);
1358 END_PROFILE(SMBntrename);
1361 reply_nterror(req, status);
1362 END_PROFILE(SMBntrename);
1366 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1368 switch(rename_type) {
1369 case RENAME_FLAG_RENAME:
1370 status = rename_internals(ctx, conn, req, oldname,
1371 newname, attrs, False, src_has_wcard,
1374 case RENAME_FLAG_HARD_LINK:
1375 if (src_has_wcard || dest_has_wcard) {
1377 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1379 status = hardlink_internals(ctx,
1385 case RENAME_FLAG_COPY:
1386 if (src_has_wcard || dest_has_wcard) {
1388 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1390 status = copy_internals(ctx, conn, req, oldname,
1394 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1395 status = NT_STATUS_INVALID_PARAMETER;
1398 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1402 if (!NT_STATUS_IS_OK(status)) {
1403 if (open_was_deferred(req->mid)) {
1404 /* We have re-scheduled this call. */
1405 END_PROFILE(SMBntrename);
1409 reply_nterror(req, status);
1410 END_PROFILE(SMBntrename);
1414 reply_outbuf(req, 0, 0);
1416 END_PROFILE(SMBntrename);
1420 /****************************************************************************
1421 Reply to a notify change - queue the request and
1422 don't allow a directory to be opened.
1423 ****************************************************************************/
1425 static void call_nt_transact_notify_change(connection_struct *conn,
1426 struct smb_request *req,
1430 uint32 parameter_count,
1431 char **ppdata, uint32 data_count,
1432 uint32 max_data_count,
1433 uint32 max_param_count)
1435 uint16 *setup = *ppsetup;
1441 if(setup_count < 6) {
1442 reply_doserror(req, ERRDOS, ERRbadfunc);
1446 fsp = file_fsp(SVAL(setup,4));
1447 filter = IVAL(setup, 0);
1448 recursive = (SVAL(setup, 6) != 0) ? True : False;
1450 DEBUG(3,("call_nt_transact_notify_change\n"));
1453 reply_doserror(req, ERRDOS, ERRbadfid);
1458 char *filter_string;
1460 if (!(filter_string = notify_filter_string(NULL, filter))) {
1461 reply_nterror(req,NT_STATUS_NO_MEMORY);
1465 DEBUG(3,("call_nt_transact_notify_change: notify change "
1466 "called on %s, filter = %s, recursive = %d\n",
1467 fsp->fsp_name, filter_string, recursive));
1469 TALLOC_FREE(filter_string);
1472 if((!fsp->is_directory) || (conn != fsp->conn)) {
1473 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1477 if (fsp->notify == NULL) {
1479 status = change_notify_create(fsp, filter, recursive);
1481 if (!NT_STATUS_IS_OK(status)) {
1482 DEBUG(10, ("change_notify_create returned %s\n",
1483 nt_errstr(status)));
1484 reply_nterror(req, status);
1489 if (fsp->notify->num_changes != 0) {
1492 * We've got changes pending, respond immediately
1496 * TODO: write a torture test to check the filtering behaviour
1500 change_notify_reply(req->inbuf, max_param_count, fsp->notify);
1503 * change_notify_reply() above has independently sent its
1510 * No changes pending, queue the request
1513 status = change_notify_add_request(req->inbuf, max_param_count, filter,
1515 if (!NT_STATUS_IS_OK(status)) {
1516 reply_nterror(req, status);
1521 /****************************************************************************
1522 Reply to an NT transact rename command.
1523 ****************************************************************************/
1525 static void call_nt_transact_rename(connection_struct *conn,
1526 struct smb_request *req,
1527 uint16 **ppsetup, uint32 setup_count,
1528 char **ppparams, uint32 parameter_count,
1529 char **ppdata, uint32 data_count,
1530 uint32 max_data_count)
1532 char *params = *ppparams;
1533 char *new_name = NULL;
1534 files_struct *fsp = NULL;
1535 bool replace_if_exists = False;
1536 bool dest_has_wcard = False;
1538 TALLOC_CTX *ctx = talloc_tos();
1540 if(parameter_count < 5) {
1541 reply_doserror(req, ERRDOS, ERRbadfunc);
1545 fsp = file_fsp(SVAL(params, 0));
1546 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1547 if (!check_fsp(conn, req, fsp, ¤t_user)) {
1550 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1551 parameter_count - 4,
1552 STR_TERMINATE, &status, &dest_has_wcard);
1553 if (!NT_STATUS_IS_OK(status)) {
1554 reply_nterror(req, status);
1558 status = rename_internals(ctx,
1568 if (!NT_STATUS_IS_OK(status)) {
1569 if (open_was_deferred(req->mid)) {
1570 /* We have re-scheduled this call. */
1573 reply_nterror(req, status);
1578 * Rename was successful.
1580 send_nt_replies(req, NT_STATUS_OK, NULL, 0, NULL, 0);
1582 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1583 fsp->fsp_name, new_name));
1588 /******************************************************************************
1589 Fake up a completely empty SD.
1590 *******************************************************************************/
1592 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1596 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1598 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1599 return NT_STATUS_NO_MEMORY;
1602 return NT_STATUS_OK;
1605 /****************************************************************************
1606 Reply to query a security descriptor.
1607 ****************************************************************************/
1609 static void call_nt_transact_query_security_desc(connection_struct *conn,
1610 struct smb_request *req,
1614 uint32 parameter_count,
1617 uint32 max_data_count)
1619 char *params = *ppparams;
1620 char *data = *ppdata;
1622 SEC_DESC *psd = NULL;
1624 uint32 security_info_wanted;
1625 TALLOC_CTX *mem_ctx;
1626 files_struct *fsp = NULL;
1629 if(parameter_count < 8) {
1630 reply_doserror(req, ERRDOS, ERRbadfunc);
1634 fsp = file_fsp(SVAL(params,0));
1636 reply_doserror(req, ERRDOS, ERRbadfid);
1640 security_info_wanted = IVAL(params,4);
1642 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1643 (unsigned int)security_info_wanted ));
1645 params = nttrans_realloc(ppparams, 4);
1646 if(params == NULL) {
1647 reply_doserror(req, ERRDOS, ERRnomem);
1651 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1652 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1653 reply_doserror(req, ERRDOS, ERRnomem);
1658 * Get the permissions to return.
1661 if (!lp_nt_acl_support(SNUM(conn))) {
1662 status = get_null_nt_acl(mem_ctx, &psd);
1664 status = SMB_VFS_FGET_NT_ACL(fsp, fsp->fh->fd,
1665 security_info_wanted, &psd);
1668 if (!NT_STATUS_IS_OK(status)) {
1669 talloc_destroy(mem_ctx);
1670 reply_nterror(req, status);
1674 sd_size = sec_desc_size(psd);
1676 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1678 SIVAL(params,0,(uint32)sd_size);
1680 if(max_data_count < sd_size) {
1682 send_nt_replies(req, NT_STATUS_BUFFER_TOO_SMALL,
1683 params, 4, *ppdata, 0);
1684 talloc_destroy(mem_ctx);
1689 * Allocate the data we will point this at.
1692 data = nttrans_realloc(ppdata, sd_size);
1694 talloc_destroy(mem_ctx);
1695 reply_doserror(req, ERRDOS, ERRnomem);
1700 * Init the parse struct we will marshall into.
1703 prs_init(&pd, 0, mem_ctx, MARSHALL);
1706 * Setup the prs_struct to point at the memory we just
1710 prs_give_memory( &pd, data, (uint32)sd_size, False);
1713 * Finally, linearize into the outgoing buffer.
1716 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1717 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
1718 security descriptor.\n"));
1720 * Return access denied for want of a better error message..
1722 talloc_destroy(mem_ctx);
1723 reply_unixerror(req, ERRDOS, ERRnoaccess);
1728 * Now we can delete the security descriptor.
1731 talloc_destroy(mem_ctx);
1733 send_nt_replies(req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1737 /****************************************************************************
1738 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1739 ****************************************************************************/
1741 static void call_nt_transact_set_security_desc(connection_struct *conn,
1742 struct smb_request *req,
1746 uint32 parameter_count,
1749 uint32 max_data_count)
1751 char *params= *ppparams;
1752 char *data = *ppdata;
1753 files_struct *fsp = NULL;
1754 uint32 security_info_sent = 0;
1757 if(parameter_count < 8) {
1758 reply_doserror(req, ERRDOS, ERRbadfunc);
1762 if((fsp = file_fsp(SVAL(params,0))) == NULL) {
1763 reply_doserror(req, ERRDOS, ERRbadfid);
1767 if(!lp_nt_acl_support(SNUM(conn))) {
1771 security_info_sent = IVAL(params,4);
1773 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1774 (unsigned int)security_info_sent ));
1776 if (data_count == 0) {
1777 reply_doserror(req, ERRDOS, ERRnoaccess);
1781 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent))) {
1782 reply_nterror(req, nt_status);
1788 send_nt_replies(req, NT_STATUS_OK, NULL, 0, NULL, 0);
1792 /****************************************************************************
1794 ****************************************************************************/
1796 static void call_nt_transact_ioctl(connection_struct *conn,
1797 struct smb_request *req,
1798 uint16 **ppsetup, uint32 setup_count,
1799 char **ppparams, uint32 parameter_count,
1800 char **ppdata, uint32 data_count,
1801 uint32 max_data_count)
1808 static bool logged_message;
1809 char *pdata = *ppdata;
1811 if (setup_count != 8) {
1812 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1813 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1817 function = IVAL(*ppsetup, 0);
1818 fidnum = SVAL(*ppsetup, 4);
1819 isFSctl = CVAL(*ppsetup, 6);
1820 compfilter = CVAL(*ppsetup, 7);
1822 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1823 function, fidnum, isFSctl, compfilter));
1825 fsp=file_fsp(fidnum);
1826 /* this check is done in each implemented function case for now
1827 because I don't want to break anything... --metze
1828 FSP_BELONGS_CONN(fsp,conn);*/
1831 case FSCTL_SET_SPARSE:
1832 /* pretend this succeeded - tho strictly we should
1833 mark the file sparse (if the local fs supports it)
1834 so we can know if we need to pre-allocate or not */
1836 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1837 send_nt_replies(req, NT_STATUS_OK, NULL, 0, NULL, 0);
1840 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1842 unsigned char objid[16];
1844 /* This should return the object-id on this file.
1845 * I think I'll make this be the inode+dev. JRA.
1848 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1850 if (!fsp_belongs_conn(conn, req, fsp, ¤t_user)) {
1855 pdata = nttrans_realloc(ppdata, data_count);
1856 if (pdata == NULL) {
1857 reply_nterror(req, NT_STATUS_NO_MEMORY);
1860 push_file_id_16(pdata, &fsp->file_id);
1861 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1862 push_file_id_16(pdata+32, &fsp->file_id);
1863 send_nt_replies(req, NT_STATUS_OK, NULL, 0,
1868 case FSCTL_GET_REPARSE_POINT:
1869 /* pretend this fail - my winXP does it like this
1873 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1874 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1877 case FSCTL_SET_REPARSE_POINT:
1878 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1882 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1883 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1886 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1889 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1890 * and return their volume names. If max_data_count is 16, then it is just
1891 * asking for the number of volumes and length of the combined names.
1893 * pdata is the data allocated by our caller, but that uses
1894 * total_data_count (which is 0 in our case) rather than max_data_count.
1895 * Allocate the correct amount and return the pointer to let
1896 * it be deallocated when we return.
1898 SHADOW_COPY_DATA *shadow_data = NULL;
1899 TALLOC_CTX *shadow_mem_ctx = NULL;
1900 bool labels = False;
1901 uint32 labels_data_count = 0;
1905 if (!fsp_belongs_conn(conn, req, fsp, ¤t_user)) {
1909 if (max_data_count < 16) {
1910 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1912 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1916 if (max_data_count > 16) {
1920 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1921 if (shadow_mem_ctx == NULL) {
1922 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1923 reply_nterror(req, NT_STATUS_NO_MEMORY);
1927 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
1928 if (shadow_data == NULL) {
1929 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1930 talloc_destroy(shadow_mem_ctx);
1931 reply_nterror(req, NT_STATUS_NO_MEMORY);
1935 shadow_data->mem_ctx = shadow_mem_ctx;
1938 * Call the VFS routine to actually do the work.
1940 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1941 talloc_destroy(shadow_data->mem_ctx);
1942 if (errno == ENOSYS) {
1943 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1944 conn->connectpath));
1945 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1948 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1949 conn->connectpath));
1950 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
1955 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
1960 data_count = 12+labels_data_count+4;
1963 if (max_data_count<data_count) {
1964 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1965 max_data_count,data_count));
1966 talloc_destroy(shadow_data->mem_ctx);
1967 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
1971 pdata = nttrans_realloc(ppdata, data_count);
1972 if (pdata == NULL) {
1973 talloc_destroy(shadow_data->mem_ctx);
1974 reply_nterror(req, NT_STATUS_NO_MEMORY);
1980 /* num_volumes 4 bytes */
1981 SIVAL(pdata,0,shadow_data->num_volumes);
1984 /* num_labels 4 bytes */
1985 SIVAL(pdata,4,shadow_data->num_volumes);
1988 /* needed_data_count 4 bytes */
1989 SIVAL(pdata,8,labels_data_count);
1993 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
1994 shadow_data->num_volumes,fsp->fsp_name));
1995 if (labels && shadow_data->labels) {
1996 for (i=0;i<shadow_data->num_volumes;i++) {
1997 srvstr_push(pdata, req->flags2,
1998 cur_pdata, shadow_data->labels[i],
1999 2*sizeof(SHADOW_COPY_LABEL),
2000 STR_UNICODE|STR_TERMINATE);
2001 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2002 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2006 talloc_destroy(shadow_data->mem_ctx);
2008 send_nt_replies(req, NT_STATUS_OK, NULL, 0,
2014 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2016 /* pretend this succeeded -
2018 * we have to send back a list with all files owned by this SID
2020 * but I have to check that --metze
2024 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2026 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2028 if (!fsp_belongs_conn(conn, req, fsp, ¤t_user)) {
2032 /* unknown 4 bytes: this is not the length of the sid :-( */
2033 /*unknown = IVAL(pdata,0);*/
2035 sid_parse(pdata+4,sid_len,&sid);
2036 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2038 if (!sid_to_uid(&sid, &uid)) {
2039 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2040 sid_string_static(&sid),(unsigned long)sid_len));
2044 /* we can take a look at the find source :-)
2046 * find ./ -uid $uid -name '*' is what we need here
2049 * and send 4bytes len and then NULL terminated unicode strings
2052 * but I don't know how to deal with the paged results
2053 * (maybe we can hang the result anywhere in the fsp struct)
2055 * we don't send all files at once
2056 * and at the next we should *not* start from the beginning,
2057 * so we have to cache the result
2062 /* this works for now... */
2063 send_nt_replies(req, NT_STATUS_OK, NULL, 0, NULL, 0);
2067 if (!logged_message) {
2068 logged_message = True; /* Only print this once... */
2069 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2074 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2078 #ifdef HAVE_SYS_QUOTAS
2079 /****************************************************************************
2080 Reply to get user quota
2081 ****************************************************************************/
2083 static void call_nt_transact_get_user_quota(connection_struct *conn,
2084 struct smb_request *req,
2088 uint32 parameter_count,
2091 uint32 max_data_count)
2093 NTSTATUS nt_status = NT_STATUS_OK;
2094 char *params = *ppparams;
2095 char *pdata = *ppdata;
2097 int data_len=0,param_len=0;
2100 files_struct *fsp = NULL;
2104 bool start_enum = True;
2105 SMB_NTQUOTA_STRUCT qt;
2106 SMB_NTQUOTA_LIST *tmp_list;
2107 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2112 if (current_user.ut.uid != 0) {
2113 DEBUG(1,("get_user_quota: access_denied service [%s] user [%s]\n",
2114 lp_servicename(SNUM(conn)),conn->user));
2115 reply_doserror(req, ERRDOS, ERRnoaccess);
2120 * Ensure minimum number of parameters sent.
2123 if (parameter_count < 4) {
2124 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2125 reply_doserror(req, ERRDOS, ERRinvalidparam);
2129 /* maybe we can check the quota_fnum */
2130 fsp = file_fsp(SVAL(params,0));
2131 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2132 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2133 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2137 /* the NULL pointer checking for fsp->fake_file_handle->pd
2138 * is done by CHECK_NTQUOTA_HANDLE_OK()
2140 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2142 level = SVAL(params,2);
2144 /* unknown 12 bytes leading in params */
2147 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2148 /* seems that we should continue with the enum here --metze */
2150 if (qt_handle->quota_list!=NULL &&
2151 qt_handle->tmp_list==NULL) {
2154 free_ntquota_list(&(qt_handle->quota_list));
2156 /* Realloc the size of parameters and data we will return */
2158 params = nttrans_realloc(ppparams, param_len);
2159 if(params == NULL) {
2160 reply_doserror(req, ERRDOS, ERRnomem);
2165 SIVAL(params,0,data_len);
2172 case TRANSACT_GET_USER_QUOTA_LIST_START:
2174 if (qt_handle->quota_list==NULL &&
2175 qt_handle->tmp_list==NULL) {
2179 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2180 reply_doserror(req, ERRSRV, ERRerror);
2184 /* Realloc the size of parameters and data we will return */
2186 params = nttrans_realloc(ppparams, param_len);
2187 if(params == NULL) {
2188 reply_doserror(req, ERRDOS, ERRnomem);
2192 /* we should not trust the value in max_data_count*/
2193 max_data_count = MIN(max_data_count,2048);
2195 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2197 reply_doserror(req, ERRDOS, ERRnomem);
2203 /* set params Size of returned Quota Data 4 bytes*/
2204 /* but set it later when we know it */
2206 /* for each entry push the data */
2209 qt_handle->tmp_list = qt_handle->quota_list;
2212 tmp_list = qt_handle->tmp_list;
2214 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2215 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2217 sid_len = sid_size(&tmp_list->quotas->sid);
2218 entry_len = 40 + sid_len;
2220 /* nextoffset entry 4 bytes */
2221 SIVAL(entry,0,entry_len);
2223 /* then the len of the SID 4 bytes */
2224 SIVAL(entry,4,sid_len);
2226 /* unknown data 8 bytes SMB_BIG_UINT */
2227 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2229 /* the used disk space 8 bytes SMB_BIG_UINT */
2230 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2232 /* the soft quotas 8 bytes SMB_BIG_UINT */
2233 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2235 /* the hard quotas 8 bytes SMB_BIG_UINT */
2236 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2238 /* and now the SID */
2239 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2242 qt_handle->tmp_list = tmp_list;
2244 /* overwrite the offset of the last entry */
2245 SIVAL(entry-entry_len,0,0);
2247 data_len = 4+qt_len;
2248 /* overwrite the params quota_data_len */
2249 SIVAL(params,0,data_len);
2253 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2255 /* unknown 4 bytes IVAL(pdata,0) */
2257 if (data_count < 8) {
2258 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2259 reply_doserror(req, ERRDOS, ERRunknownlevel);
2263 sid_len = IVAL(pdata,4);
2264 /* Ensure this is less than 1mb. */
2265 if (sid_len > (1024*1024)) {
2266 reply_doserror(req, ERRDOS, ERRnomem);
2270 if (data_count < 8+sid_len) {
2271 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2272 reply_doserror(req, ERRDOS, ERRunknownlevel);
2276 data_len = 4+40+sid_len;
2278 if (max_data_count < data_len) {
2279 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2280 max_data_count, data_len));
2282 SIVAL(params,0,data_len);
2284 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2288 sid_parse(pdata+8,sid_len,&sid);
2290 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2293 * we have to return zero's in all fields
2294 * instead of returning an error here
2299 /* Realloc the size of parameters and data we will return */
2301 params = nttrans_realloc(ppparams, param_len);
2302 if(params == NULL) {
2303 reply_doserror(req, ERRDOS, ERRnomem);
2307 pdata = nttrans_realloc(ppdata, data_len);
2309 reply_doserror(req, ERRDOS, ERRnomem);
2315 /* set params Size of returned Quota Data 4 bytes*/
2316 SIVAL(params,0,data_len);
2318 /* nextoffset entry 4 bytes */
2321 /* then the len of the SID 4 bytes */
2322 SIVAL(entry,4,sid_len);
2324 /* unknown data 8 bytes SMB_BIG_UINT */
2325 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2327 /* the used disk space 8 bytes SMB_BIG_UINT */
2328 SBIG_UINT(entry,16,qt.usedspace);
2330 /* the soft quotas 8 bytes SMB_BIG_UINT */
2331 SBIG_UINT(entry,24,qt.softlim);
2333 /* the hard quotas 8 bytes SMB_BIG_UINT */
2334 SBIG_UINT(entry,32,qt.hardlim);
2336 /* and now the SID */
2337 sid_linearize(entry+40, sid_len, &sid);
2342 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2343 reply_doserror(req, ERRSRV, ERRerror);
2348 send_nt_replies(req, nt_status, params, param_len,
2352 /****************************************************************************
2353 Reply to set user quota
2354 ****************************************************************************/
2356 static void call_nt_transact_set_user_quota(connection_struct *conn,
2357 struct smb_request *req,
2361 uint32 parameter_count,
2364 uint32 max_data_count)
2366 char *params = *ppparams;
2367 char *pdata = *ppdata;
2368 int data_len=0,param_len=0;
2369 SMB_NTQUOTA_STRUCT qt;
2372 files_struct *fsp = NULL;
2377 if (current_user.ut.uid != 0) {
2378 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2379 lp_servicename(SNUM(conn)),conn->user));
2380 reply_doserror(req, ERRDOS, ERRnoaccess);
2385 * Ensure minimum number of parameters sent.
2388 if (parameter_count < 2) {
2389 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2390 reply_doserror(req, ERRDOS, ERRinvalidparam);
2394 /* maybe we can check the quota_fnum */
2395 fsp = file_fsp(SVAL(params,0));
2396 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2397 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2398 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2402 if (data_count < 40) {
2403 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2404 reply_doserror(req, ERRDOS, ERRunknownlevel);
2408 /* offset to next quota record.
2409 * 4 bytes IVAL(pdata,0)
2414 sid_len = IVAL(pdata,4);
2416 if (data_count < 40+sid_len) {
2417 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2418 reply_doserror(req, ERRDOS, ERRunknownlevel);
2422 /* unknown 8 bytes in pdata
2423 * maybe its the change time in NTTIME
2426 /* the used space 8 bytes (SMB_BIG_UINT)*/
2427 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2428 #ifdef LARGE_SMB_OFF_T
2429 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2430 #else /* LARGE_SMB_OFF_T */
2431 if ((IVAL(pdata,20) != 0)&&
2432 ((qt.usedspace != 0xFFFFFFFF)||
2433 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2434 /* more than 32 bits? */
2435 reply_doserror(req, ERRDOS, ERRunknownlevel);
2438 #endif /* LARGE_SMB_OFF_T */
2440 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2441 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2442 #ifdef LARGE_SMB_OFF_T
2443 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2444 #else /* LARGE_SMB_OFF_T */
2445 if ((IVAL(pdata,28) != 0)&&
2446 ((qt.softlim != 0xFFFFFFFF)||
2447 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2448 /* more than 32 bits? */
2449 reply_doserror(req, ERRDOS, ERRunknownlevel);
2452 #endif /* LARGE_SMB_OFF_T */
2454 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2455 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2456 #ifdef LARGE_SMB_OFF_T
2457 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2458 #else /* LARGE_SMB_OFF_T */
2459 if ((IVAL(pdata,36) != 0)&&
2460 ((qt.hardlim != 0xFFFFFFFF)||
2461 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2462 /* more than 32 bits? */
2463 reply_doserror(req, ERRDOS, ERRunknownlevel);
2466 #endif /* LARGE_SMB_OFF_T */
2468 sid_parse(pdata+40,sid_len,&sid);
2469 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2471 /* 44 unknown bytes left... */
2473 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2474 reply_doserror(req, ERRSRV, ERRerror);
2478 send_nt_replies(req, NT_STATUS_OK, params, param_len,
2481 #endif /* HAVE_SYS_QUOTAS */
2483 static void handle_nttrans(connection_struct *conn,
2484 struct trans_state *state,
2485 struct smb_request *req)
2487 if (Protocol >= PROTOCOL_NT1) {
2488 req->flags2 |= 0x40; /* IS_LONG_NAME */
2489 SSVAL(req->inbuf,smb_flg2,req->flags2);
2492 /* Now we must call the relevant NT_TRANS function */
2493 switch(state->call) {
2494 case NT_TRANSACT_CREATE:
2496 START_PROFILE(NT_transact_create);
2497 call_nt_transact_create(
2499 &state->setup, state->setup_count,
2500 &state->param, state->total_param,
2501 &state->data, state->total_data,
2502 state->max_data_return);
2503 END_PROFILE(NT_transact_create);
2507 case NT_TRANSACT_IOCTL:
2509 START_PROFILE(NT_transact_ioctl);
2510 call_nt_transact_ioctl(
2512 &state->setup, state->setup_count,
2513 &state->param, state->total_param,
2514 &state->data, state->total_data,
2515 state->max_data_return);
2516 END_PROFILE(NT_transact_ioctl);
2520 case NT_TRANSACT_SET_SECURITY_DESC:
2522 START_PROFILE(NT_transact_set_security_desc);
2523 call_nt_transact_set_security_desc(
2525 &state->setup, state->setup_count,
2526 &state->param, state->total_param,
2527 &state->data, state->total_data,
2528 state->max_data_return);
2529 END_PROFILE(NT_transact_set_security_desc);
2533 case NT_TRANSACT_NOTIFY_CHANGE:
2535 START_PROFILE(NT_transact_notify_change);
2536 call_nt_transact_notify_change(
2538 &state->setup, state->setup_count,
2539 &state->param, state->total_param,
2540 &state->data, state->total_data,
2541 state->max_data_return,
2542 state->max_param_return);
2543 END_PROFILE(NT_transact_notify_change);
2547 case NT_TRANSACT_RENAME:
2549 START_PROFILE(NT_transact_rename);
2550 call_nt_transact_rename(
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_rename);
2560 case NT_TRANSACT_QUERY_SECURITY_DESC:
2562 START_PROFILE(NT_transact_query_security_desc);
2563 call_nt_transact_query_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_query_security_desc);
2573 #ifdef HAVE_SYS_QUOTAS
2574 case NT_TRANSACT_GET_USER_QUOTA:
2576 START_PROFILE(NT_transact_get_user_quota);
2577 call_nt_transact_get_user_quota(
2579 &state->setup, state->setup_count,
2580 &state->param, state->total_param,
2581 &state->data, state->total_data,
2582 state->max_data_return);
2583 END_PROFILE(NT_transact_get_user_quota);
2587 case NT_TRANSACT_SET_USER_QUOTA:
2589 START_PROFILE(NT_transact_set_user_quota);
2590 call_nt_transact_set_user_quota(
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_set_user_quota);
2599 #endif /* HAVE_SYS_QUOTAS */
2602 /* Error in request */
2603 DEBUG(0,("handle_nttrans: Unknown request %d in "
2604 "nttrans call\n", state->call));
2605 reply_doserror(req, ERRSRV, ERRerror);
2611 /****************************************************************************
2612 Reply to a SMBNTtrans.
2613 ****************************************************************************/
2615 void reply_nttrans(connection_struct *conn, struct smb_request *req)
2621 uint16 function_code;
2623 struct trans_state *state;
2626 START_PROFILE(SMBnttrans);
2628 if (req->wct < 19) {
2629 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2630 END_PROFILE(SMBnttrans);
2634 size = smb_len(req->inbuf) + 4;
2635 pscnt = IVAL(req->inbuf,smb_nt_ParameterCount);
2636 psoff = IVAL(req->inbuf,smb_nt_ParameterOffset);
2637 dscnt = IVAL(req->inbuf,smb_nt_DataCount);
2638 dsoff = IVAL(req->inbuf,smb_nt_DataOffset);
2639 function_code = SVAL(req->inbuf, smb_nt_Function);
2641 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2642 reply_doserror(req, ERRSRV, ERRaccess);
2643 END_PROFILE(SMBnttrans);
2647 result = allow_new_trans(conn->pending_trans, req->mid);
2648 if (!NT_STATUS_IS_OK(result)) {
2649 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2650 reply_nterror(req, result);
2651 END_PROFILE(SMBnttrans);
2655 if ((state = TALLOC_P(conn->mem_ctx, struct trans_state)) == NULL) {
2656 reply_doserror(req, ERRSRV, ERRaccess);
2657 END_PROFILE(SMBnttrans);
2661 state->cmd = SMBnttrans;
2663 state->mid = req->mid;
2664 state->vuid = req->vuid;
2665 state->total_data = IVAL(req->inbuf, smb_nt_TotalDataCount);
2667 state->total_param = IVAL(req->inbuf, smb_nt_TotalParameterCount);
2668 state->param = NULL;
2669 state->max_data_return = IVAL(req->inbuf,smb_nt_MaxDataCount);
2670 state->max_param_return = IVAL(req->inbuf,smb_nt_MaxParameterCount);
2672 /* setup count is in *words* */
2673 state->setup_count = 2*CVAL(req->inbuf,smb_nt_SetupCount);
2674 state->setup = NULL;
2675 state->call = function_code;
2678 * All nttrans messages we handle have smb_wct == 19 +
2679 * state->setup_count. Ensure this is so as a sanity check.
2682 if(req->wct != 19 + (state->setup_count/2)) {
2683 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2684 req->wct, 19 + (state->setup_count/2)));
2688 /* Don't allow more than 128mb for each value. */
2689 if ((state->total_data > (1024*1024*128)) ||
2690 (state->total_param > (1024*1024*128))) {
2691 reply_doserror(req, ERRDOS, ERRnomem);
2692 END_PROFILE(SMBnttrans);
2696 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2699 if (state->total_data) {
2700 /* Can't use talloc here, the core routines do realloc on the
2701 * params and data. */
2702 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2703 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2704 "bytes !\n", (unsigned int)state->total_data));
2706 reply_doserror(req, ERRDOS, ERRnomem);
2707 END_PROFILE(SMBnttrans);
2710 if ((dsoff+dscnt < dsoff) || (dsoff+dscnt < dscnt))
2712 if ((smb_base(req->inbuf)+dsoff+dscnt
2713 > (char *)req->inbuf + size) ||
2714 (smb_base(req->inbuf)+dsoff+dscnt < smb_base(req->inbuf)))
2717 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2720 if (state->total_param) {
2721 /* Can't use talloc here, the core routines do realloc on the
2722 * params and data. */
2723 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2724 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2725 "bytes !\n", (unsigned int)state->total_param));
2726 SAFE_FREE(state->data);
2728 reply_doserror(req, ERRDOS, ERRnomem);
2729 END_PROFILE(SMBnttrans);
2732 if ((psoff+pscnt < psoff) || (psoff+pscnt < pscnt))
2734 if ((smb_base(req->inbuf)+psoff+pscnt
2735 > (char *)req->inbuf + size) ||
2736 (smb_base(req->inbuf)+psoff+pscnt < smb_base(req->inbuf)))
2739 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2742 state->received_data = dscnt;
2743 state->received_param = pscnt;
2745 if(state->setup_count > 0) {
2746 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2747 state->setup_count));
2748 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2749 if (state->setup == NULL) {
2750 DEBUG(0,("reply_nttrans : Out of memory\n"));
2751 SAFE_FREE(state->data);
2752 SAFE_FREE(state->param);
2754 reply_doserror(req, ERRDOS, ERRnomem);
2755 END_PROFILE(SMBnttrans);
2759 if ((smb_nt_SetupStart + state->setup_count < smb_nt_SetupStart) ||
2760 (smb_nt_SetupStart + state->setup_count < state->setup_count)) {
2763 if (smb_nt_SetupStart + state->setup_count > size) {
2767 memcpy( state->setup, &req->inbuf[smb_nt_SetupStart],
2768 state->setup_count);
2769 dump_data(10, (uint8 *)state->setup, state->setup_count);
2772 if ((state->received_data == state->total_data) &&
2773 (state->received_param == state->total_param)) {
2774 handle_nttrans(conn, state, req);
2775 SAFE_FREE(state->param);
2776 SAFE_FREE(state->data);
2778 END_PROFILE(SMBnttrans);
2782 DLIST_ADD(conn->pending_trans, state);
2784 /* We need to send an interim response then receive the rest
2785 of the parameter/data bytes */
2786 reply_outbuf(req, 0, 0);
2787 show_msg((char *)req->outbuf);
2788 END_PROFILE(SMBnttrans);
2793 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2794 SAFE_FREE(state->data);
2795 SAFE_FREE(state->param);
2797 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2798 END_PROFILE(SMBnttrans);
2802 /****************************************************************************
2803 Reply to a SMBnttranss
2804 ****************************************************************************/
2806 void reply_nttranss(connection_struct *conn, struct smb_request *req)
2808 unsigned int pcnt,poff,dcnt,doff,pdisp,ddisp;
2809 struct trans_state *state;
2813 START_PROFILE(SMBnttranss);
2815 show_msg((char *)req->inbuf);
2817 if (req->wct < 18) {
2818 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2819 END_PROFILE(SMBnttranss);
2823 for (state = conn->pending_trans; state != NULL;
2824 state = state->next) {
2825 if (state->mid == req->mid) {
2830 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2831 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2832 END_PROFILE(SMBnttranss);
2836 /* Revise state->total_param and state->total_data in case they have
2837 changed downwards */
2838 if (IVAL(req->inbuf, smb_nts_TotalParameterCount)
2839 < state->total_param) {
2840 state->total_param = IVAL(req->inbuf,
2841 smb_nts_TotalParameterCount);
2843 if (IVAL(req->inbuf, smb_nts_TotalDataCount) < state->total_data) {
2844 state->total_data = IVAL(req->inbuf, smb_nts_TotalDataCount);
2847 size = smb_len(req->inbuf) + 4;
2849 pcnt = IVAL(req->inbuf,smb_nts_ParameterCount);
2850 poff = IVAL(req->inbuf, smb_nts_ParameterOffset);
2851 pdisp = IVAL(req->inbuf, smb_nts_ParameterDisplacement);
2853 dcnt = IVAL(req->inbuf, smb_nts_DataCount);
2854 ddisp = IVAL(req->inbuf, smb_nts_DataDisplacement);
2855 doff = IVAL(req->inbuf, smb_nts_DataOffset);
2857 state->received_param += pcnt;
2858 state->received_data += dcnt;
2860 if ((state->received_data > state->total_data) ||
2861 (state->received_param > state->total_param))
2865 if (pdisp+pcnt > state->total_param)
2867 if ((pdisp+pcnt < pdisp) || (pdisp+pcnt < pcnt))
2869 if (pdisp > state->total_param)
2871 if ((smb_base(req->inbuf) + poff + pcnt
2872 > (char *)req->inbuf + size) ||
2873 (smb_base(req->inbuf) + poff + pcnt
2874 < smb_base(req->inbuf)))
2876 if (state->param + pdisp < state->param)
2879 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,
2884 if (ddisp+dcnt > state->total_data)
2886 if ((ddisp+dcnt < ddisp) || (ddisp+dcnt < dcnt))
2888 if (ddisp > state->total_data)
2890 if ((smb_base(req->inbuf) + doff + dcnt
2891 > (char *)req->inbuf + size) ||
2892 (smb_base(req->inbuf) + doff + dcnt
2893 < smb_base(req->inbuf)))
2895 if (state->data + ddisp < state->data)
2898 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,
2902 if ((state->received_param < state->total_param) ||
2903 (state->received_data < state->total_data)) {
2904 END_PROFILE(SMBnttranss);
2909 * construct_reply_common will copy smb_com from inbuf to
2910 * outbuf. SMBnttranss is wrong here.
2912 SCVAL(req->inbuf,smb_com,SMBnttrans);
2914 handle_nttrans(conn, state, req);
2916 DLIST_REMOVE(conn->pending_trans, state);
2917 SAFE_FREE(state->data);
2918 SAFE_FREE(state->param);
2920 END_PROFILE(SMBnttranss);
2925 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2926 DLIST_REMOVE(conn->pending_trans, state);
2927 SAFE_FREE(state->data);
2928 SAFE_FREE(state->param);
2930 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2931 END_PROFILE(SMBnttranss);