2 Unix SMB/CIFS implementation.
3 SMB NT transaction handling
4 Copyright (C) Jeremy Allison 1994-2007
5 Copyright (C) Stefan (metze) Metzmacher 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "smbd/globals.h"
24 extern enum protocol_types Protocol;
25 extern const struct generic_mapping file_generic_mapping;
27 static char *nttrans_realloc(char **ptr, size_t size)
30 smb_panic("nttrans_realloc() called with NULL ptr");
33 *ptr = (char *)SMB_REALLOC(*ptr, size);
37 memset(*ptr,'\0',size);
41 /****************************************************************************
42 Send the required number of replies back.
43 We assume all fields other than the data fields are
44 set correctly for the type of call.
45 HACK ! Always assumes smb_setup field is zero.
46 ****************************************************************************/
48 void send_nt_replies(connection_struct *conn,
49 struct smb_request *req, NTSTATUS nt_error,
50 char *params, int paramsize,
51 char *pdata, int datasize)
53 int data_to_send = datasize;
54 int params_to_send = paramsize;
58 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
59 int alignment_offset = 3;
60 int data_alignment_offset = 0;
61 struct smbd_server_connection *sconn = smbd_server_conn;
62 int max_send = sconn->smb1.sessions.max_send;
65 * If there genuinely are no parameters or data to send just send
69 if(params_to_send == 0 && data_to_send == 0) {
70 reply_outbuf(req, 18, 0);
71 show_msg((char *)req->outbuf);
76 * When sending params and data ensure that both are nicely aligned.
77 * Only do this alignment when there is also data to send - else
78 * can cause NT redirector problems.
81 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
82 data_alignment_offset = 4 - (params_to_send % 4);
86 * Space is bufsize minus Netbios over TCP header minus SMB header.
87 * The alignment_offset is to align the param bytes on a four byte
88 * boundary (2 bytes for data len, one byte pad).
89 * NT needs this to work correctly.
92 useable_space = max_send - (smb_size
95 + data_alignment_offset);
97 if (useable_space < 0) {
98 char *msg = talloc_asprintf(
100 "send_nt_replies failed sanity useable_space = %d!!!",
102 DEBUG(0, ("%s\n", msg));
103 exit_server_cleanly(msg);
106 while (params_to_send || data_to_send) {
109 * Calculate whether we will totally or partially fill this packet.
112 total_sent_thistime = params_to_send + data_to_send;
115 * We can never send more than useable_space.
118 total_sent_thistime = MIN(total_sent_thistime, useable_space);
120 reply_outbuf(req, 18,
121 total_sent_thistime + alignment_offset
122 + data_alignment_offset);
125 * We might have had SMBnttranss in req->inbuf, fix that.
127 SCVAL(req->outbuf, smb_com, SMBnttrans);
130 * Set total params and data to be sent.
133 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
134 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
137 * Calculate how many parameters and data we can fit into
138 * this packet. Parameters get precedence.
141 params_sent_thistime = MIN(params_to_send,useable_space);
142 data_sent_thistime = useable_space - params_sent_thistime;
143 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
145 SIVAL(req->outbuf, smb_ntr_ParameterCount,
146 params_sent_thistime);
148 if(params_sent_thistime == 0) {
149 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
150 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
153 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
154 * parameter bytes, however the first 4 bytes of outbuf are
155 * the Netbios over TCP header. Thus use smb_base() to subtract
156 * them from the calculation.
159 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
160 ((smb_buf(req->outbuf)+alignment_offset)
161 - smb_base(req->outbuf)));
163 * Absolute displacement of param bytes sent in this packet.
166 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
171 * Deal with the data portion.
174 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
176 if(data_sent_thistime == 0) {
177 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
178 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
181 * The offset of the data bytes is the offset of the
182 * parameter bytes plus the number of parameters being sent this time.
185 SIVAL(req->outbuf, smb_ntr_DataOffset,
186 ((smb_buf(req->outbuf)+alignment_offset) -
187 smb_base(req->outbuf))
188 + params_sent_thistime + data_alignment_offset);
189 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
193 * Copy the param bytes into the packet.
196 if(params_sent_thistime) {
197 if (alignment_offset != 0) {
198 memset(smb_buf(req->outbuf), 0,
201 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
202 params_sent_thistime);
206 * Copy in the data bytes
209 if(data_sent_thistime) {
210 if (data_alignment_offset != 0) {
211 memset((smb_buf(req->outbuf)+alignment_offset+
212 params_sent_thistime), 0,
213 data_alignment_offset);
215 memcpy(smb_buf(req->outbuf)+alignment_offset
216 +params_sent_thistime+data_alignment_offset,
217 pd,data_sent_thistime);
220 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
221 params_sent_thistime, data_sent_thistime, useable_space));
222 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
223 params_to_send, data_to_send, paramsize, datasize));
225 if (NT_STATUS_V(nt_error)) {
226 error_packet_set((char *)req->outbuf,
231 /* Send the packet */
232 show_msg((char *)req->outbuf);
233 if (!srv_send_smb(smbd_server_fd(),
236 IS_CONN_ENCRYPTED(conn),
238 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
241 TALLOC_FREE(req->outbuf);
243 pp += params_sent_thistime;
244 pd += data_sent_thistime;
246 params_to_send -= params_sent_thistime;
247 data_to_send -= data_sent_thistime;
253 if(params_to_send < 0 || data_to_send < 0) {
254 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
255 params_to_send, data_to_send));
256 exit_server_cleanly("send_nt_replies: internal error");
261 /****************************************************************************
262 Is it an NTFS stream name ?
263 An NTFS file name is <path>.<extention>:<stream name>:<stream type>
264 $DATA can be used as both a stream name and a stream type. A missing stream
265 name or type implies $DATA.
267 Both Windows stream names and POSIX files can contain the ':' character.
268 This function first checks for the existence of a colon in the last component
269 of the given name. If the name contains a colon we differentiate between a
270 stream and POSIX file by checking if the latter exists through a POSIX stat.
272 Function assumes we've already chdir() to the "root" directory of fname.
273 ****************************************************************************/
275 bool is_ntfs_stream_name(const char *fname)
277 const char *lastcomp;
278 SMB_STRUCT_STAT sbuf;
280 /* If all pathnames are treated as POSIX we ignore streams. */
281 if (lp_posix_pathnames()) {
285 /* Find the last component of the name. */
286 if ((lastcomp = strrchr_m(fname, '/')) != NULL)
291 /* If there is no colon in the last component, it's not a stream. */
292 if (strchr_m(lastcomp, ':') == NULL)
296 * If file already exists on disk, it's not a stream. The stat must
297 * bypass the vfs layer so streams modules don't intefere.
299 if (sys_stat(fname, &sbuf) == 0) {
300 DEBUG(5, ("is_ntfs_stream_name: file %s contains a ':' but is "
301 "not a stream\n", fname));
308 /****************************************************************************
309 Simple check to determine if the filename is a stream.
310 ***************************************************************************/
311 bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
313 if (lp_posix_pathnames()) {
317 return smb_fname->stream_name;
320 /****************************************************************************
321 Returns true if the filename's stream == "::$DATA"
322 ***************************************************************************/
323 bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname)
325 if (lp_posix_pathnames()) {
329 if (!smb_fname->stream_name) {
333 return StrCaseCmp(smb_fname->stream_name, "::$DATA") == 0;
336 /****************************************************************************
337 Reply to an NT create and X call on a pipe
338 ****************************************************************************/
340 static void nt_open_pipe(char *fname, connection_struct *conn,
341 struct smb_request *req, int *ppnum)
346 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
348 /* Strip \\ off the name. */
351 status = open_np_file(req, fname, &fsp);
352 if (!NT_STATUS_IS_OK(status)) {
353 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
354 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
358 reply_nterror(req, status);
366 /****************************************************************************
367 Reply to an NT create and X call for pipes.
368 ****************************************************************************/
370 static void do_ntcreate_pipe_open(connection_struct *conn,
371 struct smb_request *req)
376 uint32 flags = IVAL(req->vwv+3, 1);
377 TALLOC_CTX *ctx = talloc_tos();
379 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
382 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
386 nt_open_pipe(fname, conn, req, &pnum);
394 * Deal with pipe return.
397 if (flags & EXTENDED_RESPONSE_REQUIRED) {
398 /* This is very strange. We
399 * return 50 words, but only set
400 * the wcnt to 42 ? It's definately
401 * what happens on the wire....
403 reply_outbuf(req, 50, 0);
404 SCVAL(req->outbuf,smb_wct,42);
406 reply_outbuf(req, 34, 0);
409 p = (char *)req->outbuf + smb_vwv2;
413 SIVAL(p,0,FILE_WAS_OPENED);
416 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
419 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
421 SSVAL(p,2, 0x5FF); /* ? */
424 if (flags & EXTENDED_RESPONSE_REQUIRED) {
426 SIVAL(p,0,FILE_GENERIC_ALL);
428 * For pipes W2K3 seems to return
430 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
432 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
435 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
440 /****************************************************************************
441 Reply to an NT create and X call.
442 ****************************************************************************/
444 void reply_ntcreate_and_X(struct smb_request *req)
446 connection_struct *conn = req->conn;
447 struct smb_filename *smb_fname = NULL;
451 uint32 file_attributes;
453 uint32 create_disposition;
454 uint32 create_options;
456 uint64_t allocation_size;
457 /* Breakout the oplock request bits so we can set the
458 reply bits separately. */
460 SMB_OFF_T file_len = 0;
462 files_struct *fsp = NULL;
464 struct timespec c_timespec;
465 struct timespec a_timespec;
466 struct timespec m_timespec;
469 uint8_t oplock_granted = NO_OPLOCK_RETURN;
470 TALLOC_CTX *ctx = talloc_tos();
472 START_PROFILE(SMBntcreateX);
475 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
479 flags = IVAL(req->vwv+3, 1);
480 access_mask = IVAL(req->vwv+7, 1);
481 file_attributes = IVAL(req->vwv+13, 1);
482 share_access = IVAL(req->vwv+15, 1);
483 create_disposition = IVAL(req->vwv+17, 1);
484 create_options = IVAL(req->vwv+19, 1);
485 root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
487 allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
488 #ifdef LARGE_SMB_OFF_T
489 allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
492 srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
493 STR_TERMINATE, &status);
495 if (!NT_STATUS_IS_OK(status)) {
496 reply_nterror(req, status);
500 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
501 "file_attributes = 0x%x, share_access = 0x%x, "
502 "create_disposition = 0x%x create_options = 0x%x "
503 "root_dir_fid = 0x%x, fname = %s\n",
505 (unsigned int)access_mask,
506 (unsigned int)file_attributes,
507 (unsigned int)share_access,
508 (unsigned int)create_disposition,
509 (unsigned int)create_options,
510 (unsigned int)root_dir_fid,
514 * we need to remove ignored bits when they come directly from the client
515 * because we reuse some of them for internal stuff
517 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
520 * If it's an IPC, use the pipe handler.
524 if (lp_nt_pipe_support()) {
525 do_ntcreate_pipe_open(conn, req);
528 reply_doserror(req, ERRDOS, ERRnoaccess);
532 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
533 if (oplock_request) {
534 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
538 status = filename_convert(ctx,
540 req->flags2 & FLAGS2_DFS_PATHNAMES,
545 if (!NT_STATUS_IS_OK(status)) {
546 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
548 NT_STATUS_PATH_NOT_COVERED,
552 reply_nterror(req, status);
556 status = SMB_VFS_CREATE_FILE(
559 root_dir_fid, /* root_dir_fid */
560 smb_fname, /* fname */
561 access_mask, /* access_mask */
562 share_access, /* share_access */
563 create_disposition, /* create_disposition*/
564 create_options, /* create_options */
565 file_attributes, /* file_attributes */
566 oplock_request, /* oplock_request */
567 allocation_size, /* allocation_size */
573 if (!NT_STATUS_IS_OK(status)) {
574 if (open_was_deferred(req->mid)) {
575 /* We have re-scheduled this call, no error. */
578 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
579 reply_botherror(req, status, ERRDOS, ERRfilexists);
582 reply_nterror(req, status);
588 * If the caller set the extended oplock request bit
589 * and we granted one (by whatever means) - set the
590 * correct bit for extended oplock reply.
593 if (oplock_request &&
594 (lp_fake_oplocks(SNUM(conn))
595 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
598 * Exclusive oplock granted
601 if (flags & REQUEST_BATCH_OPLOCK) {
602 oplock_granted = BATCH_OPLOCK_RETURN;
604 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
606 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
607 oplock_granted = LEVEL_II_OPLOCK_RETURN;
609 oplock_granted = NO_OPLOCK_RETURN;
612 file_len = smb_fname->st.st_ex_size;
613 fattr = dos_mode(conn,fsp->fsp_name,&smb_fname->st);
615 fattr = FILE_ATTRIBUTE_NORMAL;
618 if (flags & EXTENDED_RESPONSE_REQUIRED) {
619 /* This is very strange. We
620 * return 50 words, but only set
621 * the wcnt to 42 ? It's definately
622 * what happens on the wire....
624 reply_outbuf(req, 50, 0);
625 SCVAL(req->outbuf,smb_wct,42);
627 reply_outbuf(req, 34, 0);
630 p = (char *)req->outbuf + smb_vwv2;
632 SCVAL(p, 0, oplock_granted);
635 SSVAL(p,0,fsp->fnum);
637 if ((create_disposition == FILE_SUPERSEDE)
638 && (info == FILE_WAS_OVERWRITTEN)) {
639 SIVAL(p,0,FILE_WAS_SUPERSEDED);
646 c_timespec = smb_fname->st.st_ex_btime;
647 a_timespec = smb_fname->st.st_ex_atime;
648 m_timespec = smb_fname->st.st_ex_mtime;
650 if (lp_dos_filetime_resolution(SNUM(conn))) {
651 dos_filetime_timespec(&c_timespec);
652 dos_filetime_timespec(&a_timespec);
653 dos_filetime_timespec(&m_timespec);
656 put_long_date_timespec(p, c_timespec); /* create time. */
658 put_long_date_timespec(p, a_timespec); /* access time */
660 put_long_date_timespec(p, m_timespec); /* write time */
662 put_long_date_timespec(p, m_timespec); /* change time */
664 SIVAL(p,0,fattr); /* File Attributes. */
666 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
668 SOFF_T(p,0,file_len);
670 if (flags & EXTENDED_RESPONSE_REQUIRED) {
674 SCVAL(p,0,fsp->is_directory ? 1 : 0);
676 if (flags & EXTENDED_RESPONSE_REQUIRED) {
679 if (fsp->is_directory ||
680 can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
681 perms = FILE_GENERIC_ALL;
683 perms = FILE_GENERIC_READ|FILE_EXECUTE;
688 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
689 fsp->fnum, fsp->fsp_name));
693 TALLOC_FREE(smb_fname);
694 END_PROFILE(SMBntcreateX);
698 /****************************************************************************
699 Reply to a NT_TRANSACT_CREATE call to open a pipe.
700 ****************************************************************************/
702 static void do_nt_transact_create_pipe(connection_struct *conn,
703 struct smb_request *req,
704 uint16 **ppsetup, uint32 setup_count,
705 char **ppparams, uint32 parameter_count,
706 char **ppdata, uint32 data_count)
709 char *params = *ppparams;
715 TALLOC_CTX *ctx = talloc_tos();
718 * Ensure minimum number of parameters sent.
721 if(parameter_count < 54) {
722 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
723 reply_doserror(req, ERRDOS, ERRnoaccess);
727 flags = IVAL(params,0);
729 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
730 parameter_count-53, STR_TERMINATE,
732 if (!NT_STATUS_IS_OK(status)) {
733 reply_nterror(req, status);
737 nt_open_pipe(fname, conn, req, &pnum);
744 /* Realloc the size of parameters and data we will return */
745 if (flags & EXTENDED_RESPONSE_REQUIRED) {
746 /* Extended response is 32 more byyes. */
751 params = nttrans_realloc(ppparams, param_len);
753 reply_doserror(req, ERRDOS, ERRnomem);
758 SCVAL(p,0,NO_OPLOCK_RETURN);
763 SIVAL(p,0,FILE_WAS_OPENED);
767 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
770 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
772 SSVAL(p,2, 0x5FF); /* ? */
775 if (flags & EXTENDED_RESPONSE_REQUIRED) {
777 SIVAL(p,0,FILE_GENERIC_ALL);
779 * For pipes W2K3 seems to return
781 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
783 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
786 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
788 /* Send the required number of replies */
789 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
794 /****************************************************************************
795 Internal fn to set security descriptors.
796 ****************************************************************************/
798 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
799 uint32 security_info_sent)
801 SEC_DESC *psd = NULL;
804 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
808 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
810 if (!NT_STATUS_IS_OK(status)) {
814 if (psd->owner_sid == NULL) {
815 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
817 if (psd->group_sid == NULL) {
818 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
821 /* Convert all the generic bits. */
822 security_acl_map_generic(psd->dacl, &file_generic_mapping);
823 security_acl_map_generic(psd->sacl, &file_generic_mapping);
825 if (DEBUGLEVEL >= 10) {
826 DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
827 NDR_PRINT_DEBUG(security_descriptor, psd);
830 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
837 /****************************************************************************
838 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
839 ****************************************************************************/
841 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
843 struct ea_list *ea_list_head = NULL;
850 while (offset + 4 <= data_size) {
851 size_t next_offset = IVAL(pdata,offset);
852 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
858 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
859 if (next_offset == 0) {
862 offset += next_offset;
868 /****************************************************************************
869 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
870 ****************************************************************************/
872 static void call_nt_transact_create(connection_struct *conn,
873 struct smb_request *req,
874 uint16 **ppsetup, uint32 setup_count,
875 char **ppparams, uint32 parameter_count,
876 char **ppdata, uint32 data_count,
877 uint32 max_data_count)
879 struct smb_filename *smb_fname = NULL;
881 char *params = *ppparams;
882 char *data = *ppdata;
883 /* Breakout the oplock request bits so we can set the reply bits separately. */
885 SMB_OFF_T file_len = 0;
887 files_struct *fsp = NULL;
891 uint32 file_attributes;
893 uint32 create_disposition;
894 uint32 create_options;
896 struct security_descriptor *sd = NULL;
899 struct timespec c_timespec;
900 struct timespec a_timespec;
901 struct timespec m_timespec;
902 struct ea_list *ea_list = NULL;
905 uint64_t allocation_size;
907 uint8_t oplock_granted;
908 TALLOC_CTX *ctx = talloc_tos();
910 DEBUG(5,("call_nt_transact_create\n"));
913 * If it's an IPC, use the pipe handler.
917 if (lp_nt_pipe_support()) {
918 do_nt_transact_create_pipe(
920 ppsetup, setup_count,
921 ppparams, parameter_count,
925 reply_doserror(req, ERRDOS, ERRnoaccess);
930 * Ensure minimum number of parameters sent.
933 if(parameter_count < 54) {
934 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
935 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
939 flags = IVAL(params,0);
940 access_mask = IVAL(params,8);
941 file_attributes = IVAL(params,20);
942 share_access = IVAL(params,24);
943 create_disposition = IVAL(params,28);
944 create_options = IVAL(params,32);
945 sd_len = IVAL(params,36);
946 ea_len = IVAL(params,40);
947 root_dir_fid = (uint16)IVAL(params,4);
948 allocation_size = (uint64_t)IVAL(params,12);
949 #ifdef LARGE_SMB_OFF_T
950 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
954 * we need to remove ignored bits when they come directly from the client
955 * because we reuse some of them for internal stuff
957 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
959 /* Ensure the data_len is correct for the sd and ea values given. */
960 if ((ea_len + sd_len > data_count)
961 || (ea_len > data_count) || (sd_len > data_count)
962 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
963 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
964 "%u, data_count = %u\n", (unsigned int)ea_len,
965 (unsigned int)sd_len, (unsigned int)data_count));
966 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
971 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
974 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
976 if (!NT_STATUS_IS_OK(status)) {
977 DEBUG(10, ("call_nt_transact_create: "
978 "unmarshall_sec_desc failed: %s\n",
980 reply_nterror(req, status);
986 if (!lp_ea_support(SNUM(conn))) {
987 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
988 "EA's not supported.\n",
989 (unsigned int)ea_len));
990 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
995 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
996 "too small (should be more than 10)\n",
997 (unsigned int)ea_len ));
998 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1002 /* We have already checked that ea_len <= data_count here. */
1003 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
1005 if (ea_list == NULL) {
1006 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1011 srvstr_get_path(ctx, params, req->flags2, &fname,
1012 params+53, parameter_count-53,
1013 STR_TERMINATE, &status);
1014 if (!NT_STATUS_IS_OK(status)) {
1015 reply_nterror(req, status);
1019 status = filename_convert(ctx,
1021 req->flags2 & FLAGS2_DFS_PATHNAMES,
1026 if (!NT_STATUS_IS_OK(status)) {
1027 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1028 reply_botherror(req,
1029 NT_STATUS_PATH_NOT_COVERED,
1030 ERRSRV, ERRbadpath);
1033 reply_nterror(req, status);
1037 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1038 if (oplock_request) {
1039 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
1043 status = SMB_VFS_CREATE_FILE(
1046 root_dir_fid, /* root_dir_fid */
1047 smb_fname, /* fname */
1048 access_mask, /* access_mask */
1049 share_access, /* share_access */
1050 create_disposition, /* create_disposition*/
1051 create_options, /* create_options */
1052 file_attributes, /* file_attributes */
1053 oplock_request, /* oplock_request */
1054 allocation_size, /* allocation_size */
1056 ea_list, /* ea_list */
1060 if(!NT_STATUS_IS_OK(status)) {
1061 if (open_was_deferred(req->mid)) {
1062 /* We have re-scheduled this call, no error. */
1065 reply_openerror(req, status);
1070 * If the caller set the extended oplock request bit
1071 * and we granted one (by whatever means) - set the
1072 * correct bit for extended oplock reply.
1075 if (oplock_request &&
1076 (lp_fake_oplocks(SNUM(conn))
1077 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1080 * Exclusive oplock granted
1083 if (flags & REQUEST_BATCH_OPLOCK) {
1084 oplock_granted = BATCH_OPLOCK_RETURN;
1086 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1088 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1089 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1091 oplock_granted = NO_OPLOCK_RETURN;
1094 file_len = smb_fname->st.st_ex_size;
1095 fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
1097 fattr = FILE_ATTRIBUTE_NORMAL;
1100 /* Realloc the size of parameters and data we will return */
1101 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1102 /* Extended response is 32 more byyes. */
1107 params = nttrans_realloc(ppparams, param_len);
1108 if(params == NULL) {
1109 reply_doserror(req, ERRDOS, ERRnomem);
1114 SCVAL(p, 0, oplock_granted);
1117 SSVAL(p,0,fsp->fnum);
1119 if ((create_disposition == FILE_SUPERSEDE)
1120 && (info == FILE_WAS_OVERWRITTEN)) {
1121 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1128 c_timespec = smb_fname->st.st_ex_btime;
1129 a_timespec = smb_fname->st.st_ex_atime;
1130 m_timespec = smb_fname->st.st_ex_mtime;
1132 if (lp_dos_filetime_resolution(SNUM(conn))) {
1133 dos_filetime_timespec(&c_timespec);
1134 dos_filetime_timespec(&a_timespec);
1135 dos_filetime_timespec(&m_timespec);
1138 put_long_date_timespec(p, c_timespec); /* create time. */
1140 put_long_date_timespec(p, a_timespec); /* access time */
1142 put_long_date_timespec(p, m_timespec); /* write time */
1144 put_long_date_timespec(p, m_timespec); /* change time */
1146 SIVAL(p,0,fattr); /* File Attributes. */
1148 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1150 SOFF_T(p,0,file_len);
1152 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1156 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1158 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1161 if (fsp->is_directory ||
1162 can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
1163 perms = FILE_GENERIC_ALL;
1165 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1170 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp->fsp_name));
1172 /* Send the required number of replies */
1173 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1175 TALLOC_FREE(smb_fname);
1179 /****************************************************************************
1180 Reply to a NT CANCEL request.
1181 conn POINTER CAN BE NULL HERE !
1182 ****************************************************************************/
1184 void reply_ntcancel(struct smb_request *req)
1187 * Go through and cancel any pending change notifies.
1190 START_PROFILE(SMBntcancel);
1191 srv_cancel_sign_response(smbd_server_conn);
1192 remove_pending_change_notify_requests_by_mid(req->mid);
1193 remove_pending_lock_requests_by_mid(req->mid);
1195 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1197 END_PROFILE(SMBntcancel);
1201 /****************************************************************************
1203 ****************************************************************************/
1205 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1206 connection_struct *conn,
1207 struct smb_request *req,
1208 const char *oldname_in,
1209 const char *newname_in,
1212 struct smb_filename *smb_fname_src = NULL;
1213 struct smb_filename *smb_fname_dst = NULL;
1214 char *oldname = NULL;
1215 char *newname = NULL;
1216 files_struct *fsp1,*fsp2;
1220 NTSTATUS status = NT_STATUS_OK;
1223 if (!CAN_WRITE(conn)) {
1224 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1228 status = unix_convert(ctx, conn, oldname_in, &smb_fname_src, 0);
1229 if (!NT_STATUS_IS_OK(status)) {
1233 status = check_name(conn, smb_fname_src->base_name);
1234 if (!NT_STATUS_IS_OK(status)) {
1238 /* Source must already exist. */
1239 if (!VALID_STAT(smb_fname_src->st)) {
1240 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1244 status = get_full_smb_filename(ctx, smb_fname_src, &oldname);
1245 if (!NT_STATUS_IS_OK(status)) {
1249 /* Ensure attributes match. */
1250 fattr = dos_mode(conn, oldname, &smb_fname_src->st);
1251 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1252 status = NT_STATUS_NO_SUCH_FILE;
1256 status = unix_convert(ctx, conn, newname_in, &smb_fname_dst, 0);
1257 if (!NT_STATUS_IS_OK(status)) {
1261 status = check_name(conn, smb_fname_dst->base_name);
1262 if (!NT_STATUS_IS_OK(status)) {
1266 /* Disallow if dst file already exists. */
1267 if (VALID_STAT(smb_fname_dst->st)) {
1268 status = NT_STATUS_OBJECT_NAME_COLLISION;
1272 /* No links from a directory. */
1273 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1274 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1278 /* Ensure this is within the share. */
1279 status = check_reduced_name(conn, smb_fname_src->base_name);
1280 if (!NT_STATUS_IS_OK(status)) {
1284 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1285 smb_fname_str_dbg(smb_fname_src),
1286 smb_fname_str_dbg(smb_fname_dst)));
1288 status = SMB_VFS_CREATE_FILE(
1291 0, /* root_dir_fid */
1292 smb_fname_src, /* fname */
1293 FILE_READ_DATA, /* access_mask */
1294 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1296 FILE_OPEN, /* create_disposition*/
1297 0, /* create_options */
1298 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1299 NO_OPLOCK, /* oplock_request */
1300 0, /* allocation_size */
1306 if (!NT_STATUS_IS_OK(status)) {
1310 status = SMB_VFS_CREATE_FILE(
1313 0, /* root_dir_fid */
1314 smb_fname_dst, /* fname */
1315 FILE_WRITE_DATA, /* access_mask */
1316 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1318 FILE_CREATE, /* create_disposition*/
1319 0, /* create_options */
1320 fattr, /* file_attributes */
1321 NO_OPLOCK, /* oplock_request */
1322 0, /* allocation_size */
1328 if (!NT_STATUS_IS_OK(status)) {
1329 close_file(NULL, fsp1, ERROR_CLOSE);
1333 if (smb_fname_src->st.st_ex_size) {
1334 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1338 * As we are opening fsp1 read-only we only expect
1339 * an error on close on fsp2 if we are out of space.
1340 * Thus we don't look at the error return from the
1343 close_file(NULL, fsp1, NORMAL_CLOSE);
1345 /* Ensure the modtime is set correctly on the destination file. */
1346 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1348 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1350 status = get_full_smb_filename(ctx, smb_fname_dst, &newname);
1351 if (!NT_STATUS_IS_OK(status)) {
1355 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1356 creates the file. This isn't the correct thing to do in the copy
1358 if (!parent_dirname(talloc_tos(), newname, &parent, NULL)) {
1359 status = NT_STATUS_NO_MEMORY;
1362 file_set_dosmode(conn, newname, fattr, &smb_fname_dst->st, parent,
1364 TALLOC_FREE(parent);
1366 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1367 status = NT_STATUS_DISK_FULL;
1371 if (!NT_STATUS_IS_OK(status)) {
1372 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1373 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1374 smb_fname_str_dbg(smb_fname_dst)));
1377 TALLOC_FREE(smb_fname_src);
1378 TALLOC_FREE(smb_fname_dst);
1379 TALLOC_FREE(oldname);
1380 TALLOC_FREE(newname);
1385 /****************************************************************************
1386 Reply to a NT rename request.
1387 ****************************************************************************/
1389 void reply_ntrename(struct smb_request *req)
1391 connection_struct *conn = req->conn;
1392 struct smb_filename *smb_fname_old = NULL;
1393 struct smb_filename *smb_fname_new = NULL;
1394 char *oldname = NULL;
1395 char *newname = NULL;
1398 bool src_has_wcard = False;
1399 bool dest_has_wcard = False;
1402 TALLOC_CTX *ctx = talloc_tos();
1404 START_PROFILE(SMBntrename);
1407 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1408 END_PROFILE(SMBntrename);
1412 attrs = SVAL(req->vwv+0, 0);
1413 rename_type = SVAL(req->vwv+1, 0);
1415 p = (const char *)req->buf + 1;
1416 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1417 &status, &src_has_wcard);
1418 if (!NT_STATUS_IS_OK(status)) {
1419 reply_nterror(req, status);
1420 END_PROFILE(SMBntrename);
1424 if (ms_has_wild(oldname)) {
1425 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1426 END_PROFILE(SMBntrename);
1431 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1432 &status, &dest_has_wcard);
1433 if (!NT_STATUS_IS_OK(status)) {
1434 reply_nterror(req, status);
1435 END_PROFILE(SMBntrename);
1439 status = filename_convert(ctx, conn,
1440 req->flags2 & FLAGS2_DFS_PATHNAMES,
1444 if (!NT_STATUS_IS_OK(status)) {
1445 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1446 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1447 ERRSRV, ERRbadpath);
1448 END_PROFILE(SMBntrename);
1451 reply_nterror(req, status);
1452 END_PROFILE(SMBntrename);
1456 status = filename_convert(ctx, conn,
1457 req->flags2 & FLAGS2_DFS_PATHNAMES,
1461 if (!NT_STATUS_IS_OK(status)) {
1462 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1463 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1464 ERRSRV, ERRbadpath);
1465 END_PROFILE(SMBntrename);
1468 reply_nterror(req, status);
1469 END_PROFILE(SMBntrename);
1473 /* The new name must begin with a ':' if the old name is a stream. */
1474 if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
1475 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1476 END_PROFILE(SMBntrename);
1480 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1482 switch(rename_type) {
1483 case RENAME_FLAG_RENAME:
1484 status = rename_internals(ctx, conn, req, oldname,
1485 newname, attrs, False, src_has_wcard,
1486 dest_has_wcard, DELETE_ACCESS);
1488 case RENAME_FLAG_HARD_LINK:
1489 if (src_has_wcard || dest_has_wcard) {
1491 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1493 status = hardlink_internals(ctx,
1499 case RENAME_FLAG_COPY:
1500 if (src_has_wcard || dest_has_wcard) {
1502 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1504 status = copy_internals(ctx, conn, req, oldname,
1508 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1509 status = NT_STATUS_INVALID_PARAMETER;
1512 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1516 if (!NT_STATUS_IS_OK(status)) {
1517 if (open_was_deferred(req->mid)) {
1518 /* We have re-scheduled this call. */
1519 END_PROFILE(SMBntrename);
1523 reply_nterror(req, status);
1524 END_PROFILE(SMBntrename);
1528 reply_outbuf(req, 0, 0);
1530 END_PROFILE(SMBntrename);
1534 /****************************************************************************
1535 Reply to a notify change - queue the request and
1536 don't allow a directory to be opened.
1537 ****************************************************************************/
1539 static void call_nt_transact_notify_change(connection_struct *conn,
1540 struct smb_request *req,
1544 uint32 parameter_count,
1545 char **ppdata, uint32 data_count,
1546 uint32 max_data_count,
1547 uint32 max_param_count)
1549 uint16 *setup = *ppsetup;
1555 if(setup_count < 6) {
1556 reply_doserror(req, ERRDOS, ERRbadfunc);
1560 fsp = file_fsp(req, SVAL(setup,4));
1561 filter = IVAL(setup, 0);
1562 recursive = (SVAL(setup, 6) != 0) ? True : False;
1564 DEBUG(3,("call_nt_transact_notify_change\n"));
1567 reply_doserror(req, ERRDOS, ERRbadfid);
1572 char *filter_string;
1574 if (!(filter_string = notify_filter_string(NULL, filter))) {
1575 reply_nterror(req,NT_STATUS_NO_MEMORY);
1579 DEBUG(3,("call_nt_transact_notify_change: notify change "
1580 "called on %s, filter = %s, recursive = %d\n",
1581 fsp->fsp_name, filter_string, recursive));
1583 TALLOC_FREE(filter_string);
1586 if((!fsp->is_directory) || (conn != fsp->conn)) {
1587 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1591 if (fsp->notify == NULL) {
1593 status = change_notify_create(fsp, filter, recursive);
1595 if (!NT_STATUS_IS_OK(status)) {
1596 DEBUG(10, ("change_notify_create returned %s\n",
1597 nt_errstr(status)));
1598 reply_nterror(req, status);
1603 if (fsp->notify->num_changes != 0) {
1606 * We've got changes pending, respond immediately
1610 * TODO: write a torture test to check the filtering behaviour
1614 change_notify_reply(fsp->conn, req, max_param_count,
1618 * change_notify_reply() above has independently sent its
1625 * No changes pending, queue the request
1628 status = change_notify_add_request(req,
1632 if (!NT_STATUS_IS_OK(status)) {
1633 reply_nterror(req, status);
1638 /****************************************************************************
1639 Reply to an NT transact rename command.
1640 ****************************************************************************/
1642 static void call_nt_transact_rename(connection_struct *conn,
1643 struct smb_request *req,
1644 uint16 **ppsetup, uint32 setup_count,
1645 char **ppparams, uint32 parameter_count,
1646 char **ppdata, uint32 data_count,
1647 uint32 max_data_count)
1649 char *params = *ppparams;
1650 char *new_name = NULL;
1651 files_struct *fsp = NULL;
1652 bool dest_has_wcard = False;
1654 TALLOC_CTX *ctx = talloc_tos();
1656 if(parameter_count < 5) {
1657 reply_doserror(req, ERRDOS, ERRbadfunc);
1661 fsp = file_fsp(req, SVAL(params, 0));
1662 if (!check_fsp(conn, req, fsp)) {
1665 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1666 parameter_count - 4,
1667 STR_TERMINATE, &status, &dest_has_wcard);
1668 if (!NT_STATUS_IS_OK(status)) {
1669 reply_nterror(req, status);
1674 * W2K3 ignores this request as the RAW-RENAME test
1675 * demonstrates, so we do.
1677 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1679 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1680 fsp->fsp_name, new_name));
1685 /******************************************************************************
1686 Fake up a completely empty SD.
1687 *******************************************************************************/
1689 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1693 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1695 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1696 return NT_STATUS_NO_MEMORY;
1699 return NT_STATUS_OK;
1702 /****************************************************************************
1703 Reply to query a security descriptor.
1704 ****************************************************************************/
1706 static void call_nt_transact_query_security_desc(connection_struct *conn,
1707 struct smb_request *req,
1711 uint32 parameter_count,
1714 uint32 max_data_count)
1716 char *params = *ppparams;
1717 char *data = *ppdata;
1718 SEC_DESC *psd = NULL;
1720 uint32 security_info_wanted;
1721 files_struct *fsp = NULL;
1725 if(parameter_count < 8) {
1726 reply_doserror(req, ERRDOS, ERRbadfunc);
1730 fsp = file_fsp(req, SVAL(params,0));
1732 reply_doserror(req, ERRDOS, ERRbadfid);
1736 security_info_wanted = IVAL(params,4);
1738 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1739 (unsigned int)security_info_wanted ));
1741 params = nttrans_realloc(ppparams, 4);
1742 if(params == NULL) {
1743 reply_doserror(req, ERRDOS, ERRnomem);
1748 * Get the permissions to return.
1751 if (!lp_nt_acl_support(SNUM(conn))) {
1752 status = get_null_nt_acl(talloc_tos(), &psd);
1754 status = SMB_VFS_FGET_NT_ACL(
1755 fsp, security_info_wanted, &psd);
1757 if (!NT_STATUS_IS_OK(status)) {
1758 reply_nterror(req, status);
1762 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1763 * present in the reply to match Windows behavior */
1764 if (psd->sacl == NULL &&
1765 security_info_wanted & SACL_SECURITY_INFORMATION)
1766 psd->type |= SEC_DESC_SACL_PRESENT;
1767 if (psd->dacl == NULL &&
1768 security_info_wanted & DACL_SECURITY_INFORMATION)
1769 psd->type |= SEC_DESC_DACL_PRESENT;
1771 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1773 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1775 if (DEBUGLEVEL >= 10) {
1776 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name));
1777 NDR_PRINT_DEBUG(security_descriptor, psd);
1780 SIVAL(params,0,(uint32)sd_size);
1782 if (max_data_count < sd_size) {
1783 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1784 params, 4, *ppdata, 0);
1789 * Allocate the data we will point this at.
1792 data = nttrans_realloc(ppdata, sd_size);
1794 reply_doserror(req, ERRDOS, ERRnomem);
1798 status = marshall_sec_desc(talloc_tos(), psd,
1799 &blob.data, &blob.length);
1801 if (!NT_STATUS_IS_OK(status)) {
1802 reply_nterror(req, status);
1806 SMB_ASSERT(sd_size == blob.length);
1807 memcpy(data, blob.data, sd_size);
1809 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1814 /****************************************************************************
1815 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1816 ****************************************************************************/
1818 static void call_nt_transact_set_security_desc(connection_struct *conn,
1819 struct smb_request *req,
1823 uint32 parameter_count,
1826 uint32 max_data_count)
1828 char *params= *ppparams;
1829 char *data = *ppdata;
1830 files_struct *fsp = NULL;
1831 uint32 security_info_sent = 0;
1834 if(parameter_count < 8) {
1835 reply_doserror(req, ERRDOS, ERRbadfunc);
1839 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1840 reply_doserror(req, ERRDOS, ERRbadfid);
1844 if(!lp_nt_acl_support(SNUM(conn))) {
1848 security_info_sent = IVAL(params,4);
1850 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1851 (unsigned int)security_info_sent ));
1853 if (data_count == 0) {
1854 reply_doserror(req, ERRDOS, ERRnoaccess);
1858 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1860 if (!NT_STATUS_IS_OK(status)) {
1861 reply_nterror(req, status);
1866 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1870 /****************************************************************************
1872 ****************************************************************************/
1874 static void call_nt_transact_ioctl(connection_struct *conn,
1875 struct smb_request *req,
1876 uint16 **ppsetup, uint32 setup_count,
1877 char **ppparams, uint32 parameter_count,
1878 char **ppdata, uint32 data_count,
1879 uint32 max_data_count)
1886 char *pdata = *ppdata;
1888 if (setup_count != 8) {
1889 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1890 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1894 function = IVAL(*ppsetup, 0);
1895 fidnum = SVAL(*ppsetup, 4);
1896 isFSctl = CVAL(*ppsetup, 6);
1897 compfilter = CVAL(*ppsetup, 7);
1899 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1900 function, fidnum, isFSctl, compfilter));
1902 fsp=file_fsp(req, fidnum);
1903 /* this check is done in each implemented function case for now
1904 because I don't want to break anything... --metze
1905 FSP_BELONGS_CONN(fsp,conn);*/
1907 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1910 case FSCTL_SET_SPARSE:
1911 /* pretend this succeeded - tho strictly we should
1912 mark the file sparse (if the local fs supports it)
1913 so we can know if we need to pre-allocate or not */
1915 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1916 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1919 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1921 unsigned char objid[16];
1923 /* This should return the object-id on this file.
1924 * I think I'll make this be the inode+dev. JRA.
1927 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1929 if (!fsp_belongs_conn(conn, req, fsp)) {
1934 pdata = nttrans_realloc(ppdata, data_count);
1935 if (pdata == NULL) {
1936 reply_nterror(req, NT_STATUS_NO_MEMORY);
1940 /* For backwards compatibility only store the dev/inode. */
1941 push_file_id_16(pdata, &fsp->file_id);
1942 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1943 push_file_id_16(pdata+32, &fsp->file_id);
1944 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1949 case FSCTL_GET_REPARSE_POINT:
1950 /* pretend this fail - my winXP does it like this
1954 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1955 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1958 case FSCTL_SET_REPARSE_POINT:
1959 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1963 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1964 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1967 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1970 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1971 * and return their volume names. If max_data_count is 16, then it is just
1972 * asking for the number of volumes and length of the combined names.
1974 * pdata is the data allocated by our caller, but that uses
1975 * total_data_count (which is 0 in our case) rather than max_data_count.
1976 * Allocate the correct amount and return the pointer to let
1977 * it be deallocated when we return.
1979 SHADOW_COPY_DATA *shadow_data = NULL;
1980 TALLOC_CTX *shadow_mem_ctx = NULL;
1981 bool labels = False;
1982 uint32 labels_data_count = 0;
1986 if (!fsp_belongs_conn(conn, req, fsp)) {
1990 if (max_data_count < 16) {
1991 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1993 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1997 if (max_data_count > 16) {
2001 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2002 if (shadow_mem_ctx == NULL) {
2003 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2004 reply_nterror(req, NT_STATUS_NO_MEMORY);
2008 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2009 if (shadow_data == NULL) {
2010 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2011 talloc_destroy(shadow_mem_ctx);
2012 reply_nterror(req, NT_STATUS_NO_MEMORY);
2016 shadow_data->mem_ctx = shadow_mem_ctx;
2019 * Call the VFS routine to actually do the work.
2021 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2022 talloc_destroy(shadow_data->mem_ctx);
2023 if (errno == ENOSYS) {
2024 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2025 conn->connectpath));
2026 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2029 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2030 conn->connectpath));
2031 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
2036 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2041 data_count = 12+labels_data_count+4;
2044 if (max_data_count<data_count) {
2045 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2046 max_data_count,data_count));
2047 talloc_destroy(shadow_data->mem_ctx);
2048 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2052 pdata = nttrans_realloc(ppdata, data_count);
2053 if (pdata == NULL) {
2054 talloc_destroy(shadow_data->mem_ctx);
2055 reply_nterror(req, NT_STATUS_NO_MEMORY);
2061 /* num_volumes 4 bytes */
2062 SIVAL(pdata,0,shadow_data->num_volumes);
2065 /* num_labels 4 bytes */
2066 SIVAL(pdata,4,shadow_data->num_volumes);
2069 /* needed_data_count 4 bytes */
2070 SIVAL(pdata,8,labels_data_count);
2074 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2075 shadow_data->num_volumes,fsp->fsp_name));
2076 if (labels && shadow_data->labels) {
2077 for (i=0;i<shadow_data->num_volumes;i++) {
2078 srvstr_push(pdata, req->flags2,
2079 cur_pdata, shadow_data->labels[i],
2080 2*sizeof(SHADOW_COPY_LABEL),
2081 STR_UNICODE|STR_TERMINATE);
2082 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2083 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2087 talloc_destroy(shadow_data->mem_ctx);
2089 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2095 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2097 /* pretend this succeeded -
2099 * we have to send back a list with all files owned by this SID
2101 * but I have to check that --metze
2105 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2107 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2109 if (!fsp_belongs_conn(conn, req, fsp)) {
2113 /* unknown 4 bytes: this is not the length of the sid :-( */
2114 /*unknown = IVAL(pdata,0);*/
2116 sid_parse(pdata+4,sid_len,&sid);
2117 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2119 if (!sid_to_uid(&sid, &uid)) {
2120 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2121 sid_string_dbg(&sid),
2122 (unsigned long)sid_len));
2126 /* we can take a look at the find source :-)
2128 * find ./ -uid $uid -name '*' is what we need here
2131 * and send 4bytes len and then NULL terminated unicode strings
2134 * but I don't know how to deal with the paged results
2135 * (maybe we can hang the result anywhere in the fsp struct)
2137 * we don't send all files at once
2138 * and at the next we should *not* start from the beginning,
2139 * so we have to cache the result
2144 /* this works for now... */
2145 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2149 if (!logged_ioctl_message) {
2150 logged_ioctl_message = true; /* Only print this once... */
2151 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2156 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2160 #ifdef HAVE_SYS_QUOTAS
2161 /****************************************************************************
2162 Reply to get user quota
2163 ****************************************************************************/
2165 static void call_nt_transact_get_user_quota(connection_struct *conn,
2166 struct smb_request *req,
2170 uint32 parameter_count,
2173 uint32 max_data_count)
2175 NTSTATUS nt_status = NT_STATUS_OK;
2176 char *params = *ppparams;
2177 char *pdata = *ppdata;
2179 int data_len=0,param_len=0;
2182 files_struct *fsp = NULL;
2186 bool start_enum = True;
2187 SMB_NTQUOTA_STRUCT qt;
2188 SMB_NTQUOTA_LIST *tmp_list;
2189 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2194 if (conn->server_info->utok.uid != 0) {
2195 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2196 "[%s]\n", lp_servicename(SNUM(conn)),
2197 conn->server_info->unix_name));
2198 reply_doserror(req, ERRDOS, ERRnoaccess);
2203 * Ensure minimum number of parameters sent.
2206 if (parameter_count < 4) {
2207 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2208 reply_doserror(req, ERRDOS, ERRinvalidparam);
2212 /* maybe we can check the quota_fnum */
2213 fsp = file_fsp(req, SVAL(params,0));
2214 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2215 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2216 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2220 /* the NULL pointer checking for fsp->fake_file_handle->pd
2221 * is done by CHECK_NTQUOTA_HANDLE_OK()
2223 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2225 level = SVAL(params,2);
2227 /* unknown 12 bytes leading in params */
2230 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2231 /* seems that we should continue with the enum here --metze */
2233 if (qt_handle->quota_list!=NULL &&
2234 qt_handle->tmp_list==NULL) {
2237 free_ntquota_list(&(qt_handle->quota_list));
2239 /* Realloc the size of parameters and data we will return */
2241 params = nttrans_realloc(ppparams, param_len);
2242 if(params == NULL) {
2243 reply_doserror(req, ERRDOS, ERRnomem);
2248 SIVAL(params,0,data_len);
2255 case TRANSACT_GET_USER_QUOTA_LIST_START:
2257 if (qt_handle->quota_list==NULL &&
2258 qt_handle->tmp_list==NULL) {
2262 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2263 reply_doserror(req, ERRSRV, ERRerror);
2267 /* Realloc the size of parameters and data we will return */
2269 params = nttrans_realloc(ppparams, param_len);
2270 if(params == NULL) {
2271 reply_doserror(req, ERRDOS, ERRnomem);
2275 /* we should not trust the value in max_data_count*/
2276 max_data_count = MIN(max_data_count,2048);
2278 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2280 reply_doserror(req, ERRDOS, ERRnomem);
2286 /* set params Size of returned Quota Data 4 bytes*/
2287 /* but set it later when we know it */
2289 /* for each entry push the data */
2292 qt_handle->tmp_list = qt_handle->quota_list;
2295 tmp_list = qt_handle->tmp_list;
2297 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2298 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2300 sid_len = ndr_size_dom_sid(
2301 &tmp_list->quotas->sid, NULL, 0);
2302 entry_len = 40 + sid_len;
2304 /* nextoffset entry 4 bytes */
2305 SIVAL(entry,0,entry_len);
2307 /* then the len of the SID 4 bytes */
2308 SIVAL(entry,4,sid_len);
2310 /* unknown data 8 bytes uint64_t */
2311 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2313 /* the used disk space 8 bytes uint64_t */
2314 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2316 /* the soft quotas 8 bytes uint64_t */
2317 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2319 /* the hard quotas 8 bytes uint64_t */
2320 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2322 /* and now the SID */
2323 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2326 qt_handle->tmp_list = tmp_list;
2328 /* overwrite the offset of the last entry */
2329 SIVAL(entry-entry_len,0,0);
2331 data_len = 4+qt_len;
2332 /* overwrite the params quota_data_len */
2333 SIVAL(params,0,data_len);
2337 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2339 /* unknown 4 bytes IVAL(pdata,0) */
2341 if (data_count < 8) {
2342 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2343 reply_doserror(req, ERRDOS, ERRunknownlevel);
2347 sid_len = IVAL(pdata,4);
2348 /* Ensure this is less than 1mb. */
2349 if (sid_len > (1024*1024)) {
2350 reply_doserror(req, ERRDOS, ERRnomem);
2354 if (data_count < 8+sid_len) {
2355 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2356 reply_doserror(req, ERRDOS, ERRunknownlevel);
2360 data_len = 4+40+sid_len;
2362 if (max_data_count < data_len) {
2363 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2364 max_data_count, data_len));
2366 SIVAL(params,0,data_len);
2368 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2372 sid_parse(pdata+8,sid_len,&sid);
2374 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2377 * we have to return zero's in all fields
2378 * instead of returning an error here
2383 /* Realloc the size of parameters and data we will return */
2385 params = nttrans_realloc(ppparams, param_len);
2386 if(params == NULL) {
2387 reply_doserror(req, ERRDOS, ERRnomem);
2391 pdata = nttrans_realloc(ppdata, data_len);
2393 reply_doserror(req, ERRDOS, ERRnomem);
2399 /* set params Size of returned Quota Data 4 bytes*/
2400 SIVAL(params,0,data_len);
2402 /* nextoffset entry 4 bytes */
2405 /* then the len of the SID 4 bytes */
2406 SIVAL(entry,4,sid_len);
2408 /* unknown data 8 bytes uint64_t */
2409 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2411 /* the used disk space 8 bytes uint64_t */
2412 SBIG_UINT(entry,16,qt.usedspace);
2414 /* the soft quotas 8 bytes uint64_t */
2415 SBIG_UINT(entry,24,qt.softlim);
2417 /* the hard quotas 8 bytes uint64_t */
2418 SBIG_UINT(entry,32,qt.hardlim);
2420 /* and now the SID */
2421 sid_linearize(entry+40, sid_len, &sid);
2426 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2427 reply_doserror(req, ERRSRV, ERRerror);
2432 send_nt_replies(conn, req, nt_status, params, param_len,
2436 /****************************************************************************
2437 Reply to set user quota
2438 ****************************************************************************/
2440 static void call_nt_transact_set_user_quota(connection_struct *conn,
2441 struct smb_request *req,
2445 uint32 parameter_count,
2448 uint32 max_data_count)
2450 char *params = *ppparams;
2451 char *pdata = *ppdata;
2452 int data_len=0,param_len=0;
2453 SMB_NTQUOTA_STRUCT qt;
2456 files_struct *fsp = NULL;
2461 if (conn->server_info->utok.uid != 0) {
2462 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2463 "[%s]\n", lp_servicename(SNUM(conn)),
2464 conn->server_info->unix_name));
2465 reply_doserror(req, ERRDOS, ERRnoaccess);
2470 * Ensure minimum number of parameters sent.
2473 if (parameter_count < 2) {
2474 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2475 reply_doserror(req, ERRDOS, ERRinvalidparam);
2479 /* maybe we can check the quota_fnum */
2480 fsp = file_fsp(req, SVAL(params,0));
2481 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2482 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2483 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2487 if (data_count < 40) {
2488 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2489 reply_doserror(req, ERRDOS, ERRunknownlevel);
2493 /* offset to next quota record.
2494 * 4 bytes IVAL(pdata,0)
2499 sid_len = IVAL(pdata,4);
2501 if (data_count < 40+sid_len) {
2502 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2503 reply_doserror(req, ERRDOS, ERRunknownlevel);
2507 /* unknown 8 bytes in pdata
2508 * maybe its the change time in NTTIME
2511 /* the used space 8 bytes (uint64_t)*/
2512 qt.usedspace = (uint64_t)IVAL(pdata,16);
2513 #ifdef LARGE_SMB_OFF_T
2514 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2515 #else /* LARGE_SMB_OFF_T */
2516 if ((IVAL(pdata,20) != 0)&&
2517 ((qt.usedspace != 0xFFFFFFFF)||
2518 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2519 /* more than 32 bits? */
2520 reply_doserror(req, ERRDOS, ERRunknownlevel);
2523 #endif /* LARGE_SMB_OFF_T */
2525 /* the soft quotas 8 bytes (uint64_t)*/
2526 qt.softlim = (uint64_t)IVAL(pdata,24);
2527 #ifdef LARGE_SMB_OFF_T
2528 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2529 #else /* LARGE_SMB_OFF_T */
2530 if ((IVAL(pdata,28) != 0)&&
2531 ((qt.softlim != 0xFFFFFFFF)||
2532 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2533 /* more than 32 bits? */
2534 reply_doserror(req, ERRDOS, ERRunknownlevel);
2537 #endif /* LARGE_SMB_OFF_T */
2539 /* the hard quotas 8 bytes (uint64_t)*/
2540 qt.hardlim = (uint64_t)IVAL(pdata,32);
2541 #ifdef LARGE_SMB_OFF_T
2542 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2543 #else /* LARGE_SMB_OFF_T */
2544 if ((IVAL(pdata,36) != 0)&&
2545 ((qt.hardlim != 0xFFFFFFFF)||
2546 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2547 /* more than 32 bits? */
2548 reply_doserror(req, ERRDOS, ERRunknownlevel);
2551 #endif /* LARGE_SMB_OFF_T */
2553 sid_parse(pdata+40,sid_len,&sid);
2554 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2556 /* 44 unknown bytes left... */
2558 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2559 reply_doserror(req, ERRSRV, ERRerror);
2563 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2566 #endif /* HAVE_SYS_QUOTAS */
2568 static void handle_nttrans(connection_struct *conn,
2569 struct trans_state *state,
2570 struct smb_request *req)
2572 if (Protocol >= PROTOCOL_NT1) {
2573 req->flags2 |= 0x40; /* IS_LONG_NAME */
2574 SSVAL(req->inbuf,smb_flg2,req->flags2);
2578 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2580 /* Now we must call the relevant NT_TRANS function */
2581 switch(state->call) {
2582 case NT_TRANSACT_CREATE:
2584 START_PROFILE(NT_transact_create);
2585 call_nt_transact_create(
2587 &state->setup, state->setup_count,
2588 &state->param, state->total_param,
2589 &state->data, state->total_data,
2590 state->max_data_return);
2591 END_PROFILE(NT_transact_create);
2595 case NT_TRANSACT_IOCTL:
2597 START_PROFILE(NT_transact_ioctl);
2598 call_nt_transact_ioctl(
2600 &state->setup, state->setup_count,
2601 &state->param, state->total_param,
2602 &state->data, state->total_data,
2603 state->max_data_return);
2604 END_PROFILE(NT_transact_ioctl);
2608 case NT_TRANSACT_SET_SECURITY_DESC:
2610 START_PROFILE(NT_transact_set_security_desc);
2611 call_nt_transact_set_security_desc(
2613 &state->setup, state->setup_count,
2614 &state->param, state->total_param,
2615 &state->data, state->total_data,
2616 state->max_data_return);
2617 END_PROFILE(NT_transact_set_security_desc);
2621 case NT_TRANSACT_NOTIFY_CHANGE:
2623 START_PROFILE(NT_transact_notify_change);
2624 call_nt_transact_notify_change(
2626 &state->setup, state->setup_count,
2627 &state->param, state->total_param,
2628 &state->data, state->total_data,
2629 state->max_data_return,
2630 state->max_param_return);
2631 END_PROFILE(NT_transact_notify_change);
2635 case NT_TRANSACT_RENAME:
2637 START_PROFILE(NT_transact_rename);
2638 call_nt_transact_rename(
2640 &state->setup, state->setup_count,
2641 &state->param, state->total_param,
2642 &state->data, state->total_data,
2643 state->max_data_return);
2644 END_PROFILE(NT_transact_rename);
2648 case NT_TRANSACT_QUERY_SECURITY_DESC:
2650 START_PROFILE(NT_transact_query_security_desc);
2651 call_nt_transact_query_security_desc(
2653 &state->setup, state->setup_count,
2654 &state->param, state->total_param,
2655 &state->data, state->total_data,
2656 state->max_data_return);
2657 END_PROFILE(NT_transact_query_security_desc);
2661 #ifdef HAVE_SYS_QUOTAS
2662 case NT_TRANSACT_GET_USER_QUOTA:
2664 START_PROFILE(NT_transact_get_user_quota);
2665 call_nt_transact_get_user_quota(
2667 &state->setup, state->setup_count,
2668 &state->param, state->total_param,
2669 &state->data, state->total_data,
2670 state->max_data_return);
2671 END_PROFILE(NT_transact_get_user_quota);
2675 case NT_TRANSACT_SET_USER_QUOTA:
2677 START_PROFILE(NT_transact_set_user_quota);
2678 call_nt_transact_set_user_quota(
2680 &state->setup, state->setup_count,
2681 &state->param, state->total_param,
2682 &state->data, state->total_data,
2683 state->max_data_return);
2684 END_PROFILE(NT_transact_set_user_quota);
2687 #endif /* HAVE_SYS_QUOTAS */
2690 /* Error in request */
2691 DEBUG(0,("handle_nttrans: Unknown request %d in "
2692 "nttrans call\n", state->call));
2693 reply_doserror(req, ERRSRV, ERRerror);
2699 /****************************************************************************
2700 Reply to a SMBNTtrans.
2701 ****************************************************************************/
2703 void reply_nttrans(struct smb_request *req)
2705 connection_struct *conn = req->conn;
2710 uint16 function_code;
2712 struct trans_state *state;
2714 START_PROFILE(SMBnttrans);
2716 if (req->wct < 19) {
2717 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2718 END_PROFILE(SMBnttrans);
2722 pscnt = IVAL(req->vwv+9, 1);
2723 psoff = IVAL(req->vwv+11, 1);
2724 dscnt = IVAL(req->vwv+13, 1);
2725 dsoff = IVAL(req->vwv+15, 1);
2726 function_code = SVAL(req->vwv+18, 0);
2728 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2729 reply_doserror(req, ERRSRV, ERRaccess);
2730 END_PROFILE(SMBnttrans);
2734 result = allow_new_trans(conn->pending_trans, req->mid);
2735 if (!NT_STATUS_IS_OK(result)) {
2736 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2737 reply_nterror(req, result);
2738 END_PROFILE(SMBnttrans);
2742 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2743 reply_doserror(req, ERRSRV, ERRaccess);
2744 END_PROFILE(SMBnttrans);
2748 state->cmd = SMBnttrans;
2750 state->mid = req->mid;
2751 state->vuid = req->vuid;
2752 state->total_data = IVAL(req->vwv+3, 1);
2754 state->total_param = IVAL(req->vwv+1, 1);
2755 state->param = NULL;
2756 state->max_data_return = IVAL(req->vwv+7, 1);
2757 state->max_param_return = IVAL(req->vwv+5, 1);
2759 /* setup count is in *words* */
2760 state->setup_count = 2*CVAL(req->vwv+17, 1);
2761 state->setup = NULL;
2762 state->call = function_code;
2764 DEBUG(10, ("num_setup=%u, "
2765 "param_total=%u, this_param=%u, max_param=%u, "
2766 "data_total=%u, this_data=%u, max_data=%u, "
2767 "param_offset=%u, data_offset=%u\n",
2768 (unsigned)state->setup_count,
2769 (unsigned)state->total_param, (unsigned)pscnt,
2770 (unsigned)state->max_param_return,
2771 (unsigned)state->total_data, (unsigned)dscnt,
2772 (unsigned)state->max_data_return,
2773 (unsigned)psoff, (unsigned)dsoff));
2776 * All nttrans messages we handle have smb_wct == 19 +
2777 * state->setup_count. Ensure this is so as a sanity check.
2780 if(req->wct != 19 + (state->setup_count/2)) {
2781 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2782 req->wct, 19 + (state->setup_count/2)));
2786 /* Don't allow more than 128mb for each value. */
2787 if ((state->total_data > (1024*1024*128)) ||
2788 (state->total_param > (1024*1024*128))) {
2789 reply_doserror(req, ERRDOS, ERRnomem);
2790 END_PROFILE(SMBnttrans);
2794 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2797 if (state->total_data) {
2799 if (trans_oob(state->total_data, 0, dscnt)
2800 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2804 /* Can't use talloc here, the core routines do realloc on the
2805 * params and data. */
2806 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2807 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2808 "bytes !\n", (unsigned int)state->total_data));
2810 reply_doserror(req, ERRDOS, ERRnomem);
2811 END_PROFILE(SMBnttrans);
2815 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2818 if (state->total_param) {
2820 if (trans_oob(state->total_param, 0, pscnt)
2821 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2825 /* Can't use talloc here, the core routines do realloc on the
2826 * params and data. */
2827 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2828 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2829 "bytes !\n", (unsigned int)state->total_param));
2830 SAFE_FREE(state->data);
2832 reply_doserror(req, ERRDOS, ERRnomem);
2833 END_PROFILE(SMBnttrans);
2837 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2840 state->received_data = dscnt;
2841 state->received_param = pscnt;
2843 if(state->setup_count > 0) {
2844 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2845 state->setup_count));
2848 * No overflow possible here, state->setup_count is an
2849 * unsigned int, being filled by a single byte from
2850 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2851 * below is not necessary, it's here to clarify things. The
2852 * validity of req->vwv and req->wct has been checked in
2853 * init_smb_request already.
2855 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2859 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2860 if (state->setup == NULL) {
2861 DEBUG(0,("reply_nttrans : Out of memory\n"));
2862 SAFE_FREE(state->data);
2863 SAFE_FREE(state->param);
2865 reply_doserror(req, ERRDOS, ERRnomem);
2866 END_PROFILE(SMBnttrans);
2870 memcpy(state->setup, req->vwv+19, state->setup_count);
2871 dump_data(10, (uint8 *)state->setup, state->setup_count);
2874 if ((state->received_data == state->total_data) &&
2875 (state->received_param == state->total_param)) {
2876 handle_nttrans(conn, state, req);
2877 SAFE_FREE(state->param);
2878 SAFE_FREE(state->data);
2880 END_PROFILE(SMBnttrans);
2884 DLIST_ADD(conn->pending_trans, state);
2886 /* We need to send an interim response then receive the rest
2887 of the parameter/data bytes */
2888 reply_outbuf(req, 0, 0);
2889 show_msg((char *)req->outbuf);
2890 END_PROFILE(SMBnttrans);
2895 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2896 SAFE_FREE(state->data);
2897 SAFE_FREE(state->param);
2899 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2900 END_PROFILE(SMBnttrans);
2904 /****************************************************************************
2905 Reply to a SMBnttranss
2906 ****************************************************************************/
2908 void reply_nttranss(struct smb_request *req)
2910 connection_struct *conn = req->conn;
2911 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2912 struct trans_state *state;
2914 START_PROFILE(SMBnttranss);
2916 show_msg((char *)req->inbuf);
2918 if (req->wct < 18) {
2919 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2920 END_PROFILE(SMBnttranss);
2924 for (state = conn->pending_trans; state != NULL;
2925 state = state->next) {
2926 if (state->mid == req->mid) {
2931 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2932 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2933 END_PROFILE(SMBnttranss);
2937 /* Revise state->total_param and state->total_data in case they have
2938 changed downwards */
2939 if (IVAL(req->vwv+1, 1) < state->total_param) {
2940 state->total_param = IVAL(req->vwv+1, 1);
2942 if (IVAL(req->vwv+3, 1) < state->total_data) {
2943 state->total_data = IVAL(req->vwv+3, 1);
2946 pcnt = IVAL(req->vwv+5, 1);
2947 poff = IVAL(req->vwv+7, 1);
2948 pdisp = IVAL(req->vwv+9, 1);
2950 dcnt = IVAL(req->vwv+11, 1);
2951 doff = IVAL(req->vwv+13, 1);
2952 ddisp = IVAL(req->vwv+15, 1);
2954 state->received_param += pcnt;
2955 state->received_data += dcnt;
2957 if ((state->received_data > state->total_data) ||
2958 (state->received_param > state->total_param))
2962 if (trans_oob(state->total_param, pdisp, pcnt)
2963 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2966 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2970 if (trans_oob(state->total_data, ddisp, dcnt)
2971 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2974 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2977 if ((state->received_param < state->total_param) ||
2978 (state->received_data < state->total_data)) {
2979 END_PROFILE(SMBnttranss);
2983 handle_nttrans(conn, state, req);
2985 DLIST_REMOVE(conn->pending_trans, state);
2986 SAFE_FREE(state->data);
2987 SAFE_FREE(state->param);
2989 END_PROFILE(SMBnttranss);
2994 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2995 DLIST_REMOVE(conn->pending_trans, state);
2996 SAFE_FREE(state->data);
2997 SAFE_FREE(state->param);
2999 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3000 END_PROFILE(SMBnttranss);