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 = resolve_dfspath(ctx,
540 req->flags2 & FLAGS2_DFS_PATHNAMES,
544 if (!NT_STATUS_IS_OK(status)) {
545 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
547 NT_STATUS_PATH_NOT_COVERED,
551 reply_nterror(req, status);
555 status = unix_convert(ctx, conn, fname, &smb_fname, 0);
556 if (!NT_STATUS_IS_OK(status)) {
557 reply_nterror(req, status);
561 status = SMB_VFS_CREATE_FILE(
564 root_dir_fid, /* root_dir_fid */
565 smb_fname, /* fname */
566 access_mask, /* access_mask */
567 share_access, /* share_access */
568 create_disposition, /* create_disposition*/
569 create_options, /* create_options */
570 file_attributes, /* file_attributes */
571 oplock_request, /* oplock_request */
572 allocation_size, /* allocation_size */
578 if (!NT_STATUS_IS_OK(status)) {
579 if (open_was_deferred(req->mid)) {
580 /* We have re-scheduled this call, no error. */
583 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
584 reply_botherror(req, status, ERRDOS, ERRfilexists);
587 reply_nterror(req, status);
593 * If the caller set the extended oplock request bit
594 * and we granted one (by whatever means) - set the
595 * correct bit for extended oplock reply.
598 if (oplock_request &&
599 (lp_fake_oplocks(SNUM(conn))
600 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
603 * Exclusive oplock granted
606 if (flags & REQUEST_BATCH_OPLOCK) {
607 oplock_granted = BATCH_OPLOCK_RETURN;
609 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
611 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
612 oplock_granted = LEVEL_II_OPLOCK_RETURN;
614 oplock_granted = NO_OPLOCK_RETURN;
617 file_len = smb_fname->st.st_ex_size;
618 fattr = dos_mode(conn,fsp->fsp_name,&smb_fname->st);
620 fattr = FILE_ATTRIBUTE_NORMAL;
623 if (flags & EXTENDED_RESPONSE_REQUIRED) {
624 /* This is very strange. We
625 * return 50 words, but only set
626 * the wcnt to 42 ? It's definately
627 * what happens on the wire....
629 reply_outbuf(req, 50, 0);
630 SCVAL(req->outbuf,smb_wct,42);
632 reply_outbuf(req, 34, 0);
635 p = (char *)req->outbuf + smb_vwv2;
637 SCVAL(p, 0, oplock_granted);
640 SSVAL(p,0,fsp->fnum);
642 if ((create_disposition == FILE_SUPERSEDE)
643 && (info == FILE_WAS_OVERWRITTEN)) {
644 SIVAL(p,0,FILE_WAS_SUPERSEDED);
651 c_timespec = smb_fname->st.st_ex_btime;
652 a_timespec = smb_fname->st.st_ex_atime;
653 m_timespec = smb_fname->st.st_ex_mtime;
655 if (lp_dos_filetime_resolution(SNUM(conn))) {
656 dos_filetime_timespec(&c_timespec);
657 dos_filetime_timespec(&a_timespec);
658 dos_filetime_timespec(&m_timespec);
661 put_long_date_timespec(p, c_timespec); /* create time. */
663 put_long_date_timespec(p, a_timespec); /* access time */
665 put_long_date_timespec(p, m_timespec); /* write time */
667 put_long_date_timespec(p, m_timespec); /* change time */
669 SIVAL(p,0,fattr); /* File Attributes. */
671 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
673 SOFF_T(p,0,file_len);
675 if (flags & EXTENDED_RESPONSE_REQUIRED) {
679 SCVAL(p,0,fsp->is_directory ? 1 : 0);
681 if (flags & EXTENDED_RESPONSE_REQUIRED) {
684 if (fsp->is_directory ||
685 can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
686 perms = FILE_GENERIC_ALL;
688 perms = FILE_GENERIC_READ|FILE_EXECUTE;
693 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
694 fsp->fnum, fsp->fsp_name));
698 TALLOC_FREE(smb_fname);
699 END_PROFILE(SMBntcreateX);
703 /****************************************************************************
704 Reply to a NT_TRANSACT_CREATE call to open a pipe.
705 ****************************************************************************/
707 static void do_nt_transact_create_pipe(connection_struct *conn,
708 struct smb_request *req,
709 uint16 **ppsetup, uint32 setup_count,
710 char **ppparams, uint32 parameter_count,
711 char **ppdata, uint32 data_count)
714 char *params = *ppparams;
720 TALLOC_CTX *ctx = talloc_tos();
723 * Ensure minimum number of parameters sent.
726 if(parameter_count < 54) {
727 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
728 reply_doserror(req, ERRDOS, ERRnoaccess);
732 flags = IVAL(params,0);
734 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
735 parameter_count-53, STR_TERMINATE,
737 if (!NT_STATUS_IS_OK(status)) {
738 reply_nterror(req, status);
742 nt_open_pipe(fname, conn, req, &pnum);
749 /* Realloc the size of parameters and data we will return */
750 if (flags & EXTENDED_RESPONSE_REQUIRED) {
751 /* Extended response is 32 more byyes. */
756 params = nttrans_realloc(ppparams, param_len);
758 reply_doserror(req, ERRDOS, ERRnomem);
763 SCVAL(p,0,NO_OPLOCK_RETURN);
768 SIVAL(p,0,FILE_WAS_OPENED);
772 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
775 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
777 SSVAL(p,2, 0x5FF); /* ? */
780 if (flags & EXTENDED_RESPONSE_REQUIRED) {
782 SIVAL(p,0,FILE_GENERIC_ALL);
784 * For pipes W2K3 seems to return
786 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
788 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
791 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
793 /* Send the required number of replies */
794 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
799 /****************************************************************************
800 Internal fn to set security descriptors.
801 ****************************************************************************/
803 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
804 uint32 security_info_sent)
806 SEC_DESC *psd = NULL;
809 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
813 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
815 if (!NT_STATUS_IS_OK(status)) {
819 if (psd->owner_sid == NULL) {
820 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
822 if (psd->group_sid == NULL) {
823 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
826 /* Convert all the generic bits. */
827 security_acl_map_generic(psd->dacl, &file_generic_mapping);
828 security_acl_map_generic(psd->sacl, &file_generic_mapping);
830 if (DEBUGLEVEL >= 10) {
831 DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
832 NDR_PRINT_DEBUG(security_descriptor, psd);
835 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
842 /****************************************************************************
843 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
844 ****************************************************************************/
846 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
848 struct ea_list *ea_list_head = NULL;
855 while (offset + 4 <= data_size) {
856 size_t next_offset = IVAL(pdata,offset);
857 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
863 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
864 if (next_offset == 0) {
867 offset += next_offset;
873 /****************************************************************************
874 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
875 ****************************************************************************/
877 static void call_nt_transact_create(connection_struct *conn,
878 struct smb_request *req,
879 uint16 **ppsetup, uint32 setup_count,
880 char **ppparams, uint32 parameter_count,
881 char **ppdata, uint32 data_count,
882 uint32 max_data_count)
884 struct smb_filename *smb_fname = NULL;
886 char *params = *ppparams;
887 char *data = *ppdata;
888 /* Breakout the oplock request bits so we can set the reply bits separately. */
890 SMB_OFF_T file_len = 0;
892 files_struct *fsp = NULL;
896 uint32 file_attributes;
898 uint32 create_disposition;
899 uint32 create_options;
901 struct security_descriptor *sd = NULL;
904 struct timespec c_timespec;
905 struct timespec a_timespec;
906 struct timespec m_timespec;
907 struct ea_list *ea_list = NULL;
910 uint64_t allocation_size;
912 uint8_t oplock_granted;
913 TALLOC_CTX *ctx = talloc_tos();
915 DEBUG(5,("call_nt_transact_create\n"));
918 * If it's an IPC, use the pipe handler.
922 if (lp_nt_pipe_support()) {
923 do_nt_transact_create_pipe(
925 ppsetup, setup_count,
926 ppparams, parameter_count,
930 reply_doserror(req, ERRDOS, ERRnoaccess);
935 * Ensure minimum number of parameters sent.
938 if(parameter_count < 54) {
939 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
940 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
944 flags = IVAL(params,0);
945 access_mask = IVAL(params,8);
946 file_attributes = IVAL(params,20);
947 share_access = IVAL(params,24);
948 create_disposition = IVAL(params,28);
949 create_options = IVAL(params,32);
950 sd_len = IVAL(params,36);
951 ea_len = IVAL(params,40);
952 root_dir_fid = (uint16)IVAL(params,4);
953 allocation_size = (uint64_t)IVAL(params,12);
954 #ifdef LARGE_SMB_OFF_T
955 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
959 * we need to remove ignored bits when they come directly from the client
960 * because we reuse some of them for internal stuff
962 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
964 /* Ensure the data_len is correct for the sd and ea values given. */
965 if ((ea_len + sd_len > data_count)
966 || (ea_len > data_count) || (sd_len > data_count)
967 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
968 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
969 "%u, data_count = %u\n", (unsigned int)ea_len,
970 (unsigned int)sd_len, (unsigned int)data_count));
971 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
976 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
979 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
981 if (!NT_STATUS_IS_OK(status)) {
982 DEBUG(10, ("call_nt_transact_create: "
983 "unmarshall_sec_desc failed: %s\n",
985 reply_nterror(req, status);
991 if (!lp_ea_support(SNUM(conn))) {
992 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
993 "EA's not supported.\n",
994 (unsigned int)ea_len));
995 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
1000 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1001 "too small (should be more than 10)\n",
1002 (unsigned int)ea_len ));
1003 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1007 /* We have already checked that ea_len <= data_count here. */
1008 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
1010 if (ea_list == NULL) {
1011 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1016 srvstr_get_path(ctx, params, req->flags2, &fname,
1017 params+53, parameter_count-53,
1018 STR_TERMINATE, &status);
1019 if (!NT_STATUS_IS_OK(status)) {
1020 reply_nterror(req, status);
1024 status = resolve_dfspath(ctx,
1026 req->flags2 & FLAGS2_DFS_PATHNAMES,
1030 if (!NT_STATUS_IS_OK(status)) {
1031 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1032 reply_botherror(req,
1033 NT_STATUS_PATH_NOT_COVERED,
1034 ERRSRV, ERRbadpath);
1037 reply_nterror(req, status);
1041 status = unix_convert(ctx, conn, fname, &smb_fname, 0);
1042 if (!NT_STATUS_IS_OK(status)) {
1043 reply_nterror(req, status);
1047 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1048 if (oplock_request) {
1049 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
1053 status = SMB_VFS_CREATE_FILE(
1056 root_dir_fid, /* root_dir_fid */
1057 smb_fname, /* fname */
1058 access_mask, /* access_mask */
1059 share_access, /* share_access */
1060 create_disposition, /* create_disposition*/
1061 create_options, /* create_options */
1062 file_attributes, /* file_attributes */
1063 oplock_request, /* oplock_request */
1064 allocation_size, /* allocation_size */
1066 ea_list, /* ea_list */
1070 if(!NT_STATUS_IS_OK(status)) {
1071 if (open_was_deferred(req->mid)) {
1072 /* We have re-scheduled this call, no error. */
1075 reply_openerror(req, status);
1080 * If the caller set the extended oplock request bit
1081 * and we granted one (by whatever means) - set the
1082 * correct bit for extended oplock reply.
1085 if (oplock_request &&
1086 (lp_fake_oplocks(SNUM(conn))
1087 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1090 * Exclusive oplock granted
1093 if (flags & REQUEST_BATCH_OPLOCK) {
1094 oplock_granted = BATCH_OPLOCK_RETURN;
1096 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1098 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1099 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1101 oplock_granted = NO_OPLOCK_RETURN;
1104 file_len = smb_fname->st.st_ex_size;
1105 fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
1107 fattr = FILE_ATTRIBUTE_NORMAL;
1110 /* Realloc the size of parameters and data we will return */
1111 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1112 /* Extended response is 32 more byyes. */
1117 params = nttrans_realloc(ppparams, param_len);
1118 if(params == NULL) {
1119 reply_doserror(req, ERRDOS, ERRnomem);
1124 SCVAL(p, 0, oplock_granted);
1127 SSVAL(p,0,fsp->fnum);
1129 if ((create_disposition == FILE_SUPERSEDE)
1130 && (info == FILE_WAS_OVERWRITTEN)) {
1131 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1138 c_timespec = smb_fname->st.st_ex_btime;
1139 a_timespec = smb_fname->st.st_ex_atime;
1140 m_timespec = smb_fname->st.st_ex_mtime;
1142 if (lp_dos_filetime_resolution(SNUM(conn))) {
1143 dos_filetime_timespec(&c_timespec);
1144 dos_filetime_timespec(&a_timespec);
1145 dos_filetime_timespec(&m_timespec);
1148 put_long_date_timespec(p, c_timespec); /* create time. */
1150 put_long_date_timespec(p, a_timespec); /* access time */
1152 put_long_date_timespec(p, m_timespec); /* write time */
1154 put_long_date_timespec(p, m_timespec); /* change time */
1156 SIVAL(p,0,fattr); /* File Attributes. */
1158 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1160 SOFF_T(p,0,file_len);
1162 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1166 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1168 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1171 if (fsp->is_directory ||
1172 can_write_to_file(conn, fsp->fsp_name, &smb_fname->st)) {
1173 perms = FILE_GENERIC_ALL;
1175 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1180 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp->fsp_name));
1182 /* Send the required number of replies */
1183 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1185 TALLOC_FREE(smb_fname);
1189 /****************************************************************************
1190 Reply to a NT CANCEL request.
1191 conn POINTER CAN BE NULL HERE !
1192 ****************************************************************************/
1194 void reply_ntcancel(struct smb_request *req)
1197 * Go through and cancel any pending change notifies.
1200 START_PROFILE(SMBntcancel);
1201 srv_cancel_sign_response(smbd_server_conn);
1202 remove_pending_change_notify_requests_by_mid(req->mid);
1203 remove_pending_lock_requests_by_mid(req->mid);
1205 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1207 END_PROFILE(SMBntcancel);
1211 /****************************************************************************
1213 ****************************************************************************/
1215 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1216 connection_struct *conn,
1217 struct smb_request *req,
1218 const char *oldname_in,
1219 const char *newname_in,
1222 struct smb_filename *smb_fname_src = NULL;
1223 struct smb_filename *smb_fname_dst = NULL;
1224 char *oldname = NULL;
1225 char *newname = NULL;
1226 files_struct *fsp1,*fsp2;
1230 NTSTATUS status = NT_STATUS_OK;
1233 if (!CAN_WRITE(conn)) {
1234 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1238 status = unix_convert(ctx, conn, oldname_in, &smb_fname_src, 0);
1239 if (!NT_STATUS_IS_OK(status)) {
1243 status = check_name(conn, smb_fname_src->base_name);
1244 if (!NT_STATUS_IS_OK(status)) {
1248 /* Source must already exist. */
1249 if (!VALID_STAT(smb_fname_src->st)) {
1250 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1254 status = get_full_smb_filename(ctx, smb_fname_src, &oldname);
1255 if (!NT_STATUS_IS_OK(status)) {
1259 /* Ensure attributes match. */
1260 fattr = dos_mode(conn, oldname, &smb_fname_src->st);
1261 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1262 status = NT_STATUS_NO_SUCH_FILE;
1266 status = unix_convert(ctx, conn, newname_in, &smb_fname_dst, 0);
1267 if (!NT_STATUS_IS_OK(status)) {
1271 status = check_name(conn, smb_fname_dst->base_name);
1272 if (!NT_STATUS_IS_OK(status)) {
1276 /* Disallow if dst file already exists. */
1277 if (VALID_STAT(smb_fname_dst->st)) {
1278 status = NT_STATUS_OBJECT_NAME_COLLISION;
1282 /* No links from a directory. */
1283 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1284 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1288 /* Ensure this is within the share. */
1289 status = check_reduced_name(conn, smb_fname_src->base_name);
1290 if (!NT_STATUS_IS_OK(status)) {
1294 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1295 smb_fname_str_dbg(smb_fname_src),
1296 smb_fname_str_dbg(smb_fname_dst)));
1298 status = SMB_VFS_CREATE_FILE(
1301 0, /* root_dir_fid */
1302 smb_fname_src, /* fname */
1303 FILE_READ_DATA, /* access_mask */
1304 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1306 FILE_OPEN, /* create_disposition*/
1307 0, /* create_options */
1308 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1309 NO_OPLOCK, /* oplock_request */
1310 0, /* allocation_size */
1316 if (!NT_STATUS_IS_OK(status)) {
1320 status = SMB_VFS_CREATE_FILE(
1323 0, /* root_dir_fid */
1324 smb_fname_dst, /* fname */
1325 FILE_WRITE_DATA, /* access_mask */
1326 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1328 FILE_CREATE, /* create_disposition*/
1329 0, /* create_options */
1330 fattr, /* file_attributes */
1331 NO_OPLOCK, /* oplock_request */
1332 0, /* allocation_size */
1338 if (!NT_STATUS_IS_OK(status)) {
1339 close_file(NULL, fsp1, ERROR_CLOSE);
1343 if (smb_fname_src->st.st_ex_size) {
1344 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1348 * As we are opening fsp1 read-only we only expect
1349 * an error on close on fsp2 if we are out of space.
1350 * Thus we don't look at the error return from the
1353 close_file(NULL, fsp1, NORMAL_CLOSE);
1355 /* Ensure the modtime is set correctly on the destination file. */
1356 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1358 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1360 status = get_full_smb_filename(ctx, smb_fname_dst, &newname);
1361 if (!NT_STATUS_IS_OK(status)) {
1365 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1366 creates the file. This isn't the correct thing to do in the copy
1368 if (!parent_dirname(talloc_tos(), newname, &parent, NULL)) {
1369 status = NT_STATUS_NO_MEMORY;
1372 file_set_dosmode(conn, newname, fattr, &smb_fname_dst->st, parent,
1374 TALLOC_FREE(parent);
1376 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1377 status = NT_STATUS_DISK_FULL;
1381 if (!NT_STATUS_IS_OK(status)) {
1382 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1383 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1384 smb_fname_str_dbg(smb_fname_dst)));
1387 TALLOC_FREE(smb_fname_src);
1388 TALLOC_FREE(smb_fname_dst);
1389 TALLOC_FREE(oldname);
1390 TALLOC_FREE(newname);
1395 /****************************************************************************
1396 Reply to a NT rename request.
1397 ****************************************************************************/
1399 void reply_ntrename(struct smb_request *req)
1401 connection_struct *conn = req->conn;
1402 char *oldname = NULL;
1403 char *newname = NULL;
1406 bool src_has_wcard = False;
1407 bool dest_has_wcard = False;
1410 TALLOC_CTX *ctx = talloc_tos();
1412 START_PROFILE(SMBntrename);
1415 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1416 END_PROFILE(SMBntrename);
1420 attrs = SVAL(req->vwv+0, 0);
1421 rename_type = SVAL(req->vwv+1, 0);
1423 p = (const char *)req->buf + 1;
1424 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1425 &status, &src_has_wcard);
1426 if (!NT_STATUS_IS_OK(status)) {
1427 reply_nterror(req, status);
1428 END_PROFILE(SMBntrename);
1432 if (ms_has_wild(oldname)) {
1433 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1434 END_PROFILE(SMBntrename);
1439 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1440 &status, &dest_has_wcard);
1441 if (!NT_STATUS_IS_OK(status)) {
1442 reply_nterror(req, status);
1443 END_PROFILE(SMBntrename);
1447 status = resolve_dfspath(ctx, conn,
1448 req->flags2 & FLAGS2_DFS_PATHNAMES,
1451 if (!NT_STATUS_IS_OK(status)) {
1452 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1453 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1454 ERRSRV, ERRbadpath);
1455 END_PROFILE(SMBntrename);
1458 reply_nterror(req, status);
1459 END_PROFILE(SMBntrename);
1463 status = resolve_dfspath(ctx, conn,
1464 req->flags2 & FLAGS2_DFS_PATHNAMES,
1467 if (!NT_STATUS_IS_OK(status)) {
1468 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1469 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1470 ERRSRV, ERRbadpath);
1471 END_PROFILE(SMBntrename);
1474 reply_nterror(req, status);
1475 END_PROFILE(SMBntrename);
1479 /* The new name must begin with a ':' if the old name is a stream. */
1480 if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
1481 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1482 END_PROFILE(SMBntrename);
1486 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1488 switch(rename_type) {
1489 case RENAME_FLAG_RENAME:
1490 status = rename_internals(ctx, conn, req, oldname,
1491 newname, attrs, False, src_has_wcard,
1492 dest_has_wcard, DELETE_ACCESS);
1494 case RENAME_FLAG_HARD_LINK:
1495 if (src_has_wcard || dest_has_wcard) {
1497 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1499 status = hardlink_internals(ctx,
1505 case RENAME_FLAG_COPY:
1506 if (src_has_wcard || dest_has_wcard) {
1508 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1510 status = copy_internals(ctx, conn, req, oldname,
1514 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1515 status = NT_STATUS_INVALID_PARAMETER;
1518 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1522 if (!NT_STATUS_IS_OK(status)) {
1523 if (open_was_deferred(req->mid)) {
1524 /* We have re-scheduled this call. */
1525 END_PROFILE(SMBntrename);
1529 reply_nterror(req, status);
1530 END_PROFILE(SMBntrename);
1534 reply_outbuf(req, 0, 0);
1536 END_PROFILE(SMBntrename);
1540 /****************************************************************************
1541 Reply to a notify change - queue the request and
1542 don't allow a directory to be opened.
1543 ****************************************************************************/
1545 static void call_nt_transact_notify_change(connection_struct *conn,
1546 struct smb_request *req,
1550 uint32 parameter_count,
1551 char **ppdata, uint32 data_count,
1552 uint32 max_data_count,
1553 uint32 max_param_count)
1555 uint16 *setup = *ppsetup;
1561 if(setup_count < 6) {
1562 reply_doserror(req, ERRDOS, ERRbadfunc);
1566 fsp = file_fsp(req, SVAL(setup,4));
1567 filter = IVAL(setup, 0);
1568 recursive = (SVAL(setup, 6) != 0) ? True : False;
1570 DEBUG(3,("call_nt_transact_notify_change\n"));
1573 reply_doserror(req, ERRDOS, ERRbadfid);
1578 char *filter_string;
1580 if (!(filter_string = notify_filter_string(NULL, filter))) {
1581 reply_nterror(req,NT_STATUS_NO_MEMORY);
1585 DEBUG(3,("call_nt_transact_notify_change: notify change "
1586 "called on %s, filter = %s, recursive = %d\n",
1587 fsp->fsp_name, filter_string, recursive));
1589 TALLOC_FREE(filter_string);
1592 if((!fsp->is_directory) || (conn != fsp->conn)) {
1593 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1597 if (fsp->notify == NULL) {
1599 status = change_notify_create(fsp, filter, recursive);
1601 if (!NT_STATUS_IS_OK(status)) {
1602 DEBUG(10, ("change_notify_create returned %s\n",
1603 nt_errstr(status)));
1604 reply_nterror(req, status);
1609 if (fsp->notify->num_changes != 0) {
1612 * We've got changes pending, respond immediately
1616 * TODO: write a torture test to check the filtering behaviour
1620 change_notify_reply(fsp->conn, req, max_param_count,
1624 * change_notify_reply() above has independently sent its
1631 * No changes pending, queue the request
1634 status = change_notify_add_request(req,
1638 if (!NT_STATUS_IS_OK(status)) {
1639 reply_nterror(req, status);
1644 /****************************************************************************
1645 Reply to an NT transact rename command.
1646 ****************************************************************************/
1648 static void call_nt_transact_rename(connection_struct *conn,
1649 struct smb_request *req,
1650 uint16 **ppsetup, uint32 setup_count,
1651 char **ppparams, uint32 parameter_count,
1652 char **ppdata, uint32 data_count,
1653 uint32 max_data_count)
1655 char *params = *ppparams;
1656 char *new_name = NULL;
1657 files_struct *fsp = NULL;
1658 bool dest_has_wcard = False;
1660 TALLOC_CTX *ctx = talloc_tos();
1662 if(parameter_count < 5) {
1663 reply_doserror(req, ERRDOS, ERRbadfunc);
1667 fsp = file_fsp(req, SVAL(params, 0));
1668 if (!check_fsp(conn, req, fsp)) {
1671 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1672 parameter_count - 4,
1673 STR_TERMINATE, &status, &dest_has_wcard);
1674 if (!NT_STATUS_IS_OK(status)) {
1675 reply_nterror(req, status);
1680 * W2K3 ignores this request as the RAW-RENAME test
1681 * demonstrates, so we do.
1683 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1685 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1686 fsp->fsp_name, new_name));
1691 /******************************************************************************
1692 Fake up a completely empty SD.
1693 *******************************************************************************/
1695 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1699 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1701 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1702 return NT_STATUS_NO_MEMORY;
1705 return NT_STATUS_OK;
1708 /****************************************************************************
1709 Reply to query a security descriptor.
1710 ****************************************************************************/
1712 static void call_nt_transact_query_security_desc(connection_struct *conn,
1713 struct smb_request *req,
1717 uint32 parameter_count,
1720 uint32 max_data_count)
1722 char *params = *ppparams;
1723 char *data = *ppdata;
1724 SEC_DESC *psd = NULL;
1726 uint32 security_info_wanted;
1727 files_struct *fsp = NULL;
1731 if(parameter_count < 8) {
1732 reply_doserror(req, ERRDOS, ERRbadfunc);
1736 fsp = file_fsp(req, SVAL(params,0));
1738 reply_doserror(req, ERRDOS, ERRbadfid);
1742 security_info_wanted = IVAL(params,4);
1744 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1745 (unsigned int)security_info_wanted ));
1747 params = nttrans_realloc(ppparams, 4);
1748 if(params == NULL) {
1749 reply_doserror(req, ERRDOS, ERRnomem);
1754 * Get the permissions to return.
1757 if (!lp_nt_acl_support(SNUM(conn))) {
1758 status = get_null_nt_acl(talloc_tos(), &psd);
1760 status = SMB_VFS_FGET_NT_ACL(
1761 fsp, security_info_wanted, &psd);
1763 if (!NT_STATUS_IS_OK(status)) {
1764 reply_nterror(req, status);
1768 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1769 * present in the reply to match Windows behavior */
1770 if (psd->sacl == NULL &&
1771 security_info_wanted & SACL_SECURITY_INFORMATION)
1772 psd->type |= SEC_DESC_SACL_PRESENT;
1773 if (psd->dacl == NULL &&
1774 security_info_wanted & DACL_SECURITY_INFORMATION)
1775 psd->type |= SEC_DESC_DACL_PRESENT;
1777 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1779 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1781 if (DEBUGLEVEL >= 10) {
1782 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name));
1783 NDR_PRINT_DEBUG(security_descriptor, psd);
1786 SIVAL(params,0,(uint32)sd_size);
1788 if (max_data_count < sd_size) {
1789 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1790 params, 4, *ppdata, 0);
1795 * Allocate the data we will point this at.
1798 data = nttrans_realloc(ppdata, sd_size);
1800 reply_doserror(req, ERRDOS, ERRnomem);
1804 status = marshall_sec_desc(talloc_tos(), psd,
1805 &blob.data, &blob.length);
1807 if (!NT_STATUS_IS_OK(status)) {
1808 reply_nterror(req, status);
1812 SMB_ASSERT(sd_size == blob.length);
1813 memcpy(data, blob.data, sd_size);
1815 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1820 /****************************************************************************
1821 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1822 ****************************************************************************/
1824 static void call_nt_transact_set_security_desc(connection_struct *conn,
1825 struct smb_request *req,
1829 uint32 parameter_count,
1832 uint32 max_data_count)
1834 char *params= *ppparams;
1835 char *data = *ppdata;
1836 files_struct *fsp = NULL;
1837 uint32 security_info_sent = 0;
1840 if(parameter_count < 8) {
1841 reply_doserror(req, ERRDOS, ERRbadfunc);
1845 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1846 reply_doserror(req, ERRDOS, ERRbadfid);
1850 if(!lp_nt_acl_support(SNUM(conn))) {
1854 security_info_sent = IVAL(params,4);
1856 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1857 (unsigned int)security_info_sent ));
1859 if (data_count == 0) {
1860 reply_doserror(req, ERRDOS, ERRnoaccess);
1864 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1866 if (!NT_STATUS_IS_OK(status)) {
1867 reply_nterror(req, status);
1872 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1876 /****************************************************************************
1878 ****************************************************************************/
1880 static void call_nt_transact_ioctl(connection_struct *conn,
1881 struct smb_request *req,
1882 uint16 **ppsetup, uint32 setup_count,
1883 char **ppparams, uint32 parameter_count,
1884 char **ppdata, uint32 data_count,
1885 uint32 max_data_count)
1892 char *pdata = *ppdata;
1894 if (setup_count != 8) {
1895 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1896 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1900 function = IVAL(*ppsetup, 0);
1901 fidnum = SVAL(*ppsetup, 4);
1902 isFSctl = CVAL(*ppsetup, 6);
1903 compfilter = CVAL(*ppsetup, 7);
1905 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1906 function, fidnum, isFSctl, compfilter));
1908 fsp=file_fsp(req, fidnum);
1909 /* this check is done in each implemented function case for now
1910 because I don't want to break anything... --metze
1911 FSP_BELONGS_CONN(fsp,conn);*/
1913 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1916 case FSCTL_SET_SPARSE:
1917 /* pretend this succeeded - tho strictly we should
1918 mark the file sparse (if the local fs supports it)
1919 so we can know if we need to pre-allocate or not */
1921 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1922 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1925 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1927 unsigned char objid[16];
1929 /* This should return the object-id on this file.
1930 * I think I'll make this be the inode+dev. JRA.
1933 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1935 if (!fsp_belongs_conn(conn, req, fsp)) {
1940 pdata = nttrans_realloc(ppdata, data_count);
1941 if (pdata == NULL) {
1942 reply_nterror(req, NT_STATUS_NO_MEMORY);
1946 /* For backwards compatibility only store the dev/inode. */
1947 push_file_id_16(pdata, &fsp->file_id);
1948 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1949 push_file_id_16(pdata+32, &fsp->file_id);
1950 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1955 case FSCTL_GET_REPARSE_POINT:
1956 /* pretend this fail - my winXP does it like this
1960 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1961 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1964 case FSCTL_SET_REPARSE_POINT:
1965 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1969 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1970 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1973 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1976 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1977 * and return their volume names. If max_data_count is 16, then it is just
1978 * asking for the number of volumes and length of the combined names.
1980 * pdata is the data allocated by our caller, but that uses
1981 * total_data_count (which is 0 in our case) rather than max_data_count.
1982 * Allocate the correct amount and return the pointer to let
1983 * it be deallocated when we return.
1985 SHADOW_COPY_DATA *shadow_data = NULL;
1986 TALLOC_CTX *shadow_mem_ctx = NULL;
1987 bool labels = False;
1988 uint32 labels_data_count = 0;
1992 if (!fsp_belongs_conn(conn, req, fsp)) {
1996 if (max_data_count < 16) {
1997 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1999 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2003 if (max_data_count > 16) {
2007 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
2008 if (shadow_mem_ctx == NULL) {
2009 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2010 reply_nterror(req, NT_STATUS_NO_MEMORY);
2014 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2015 if (shadow_data == NULL) {
2016 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2017 talloc_destroy(shadow_mem_ctx);
2018 reply_nterror(req, NT_STATUS_NO_MEMORY);
2022 shadow_data->mem_ctx = shadow_mem_ctx;
2025 * Call the VFS routine to actually do the work.
2027 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2028 talloc_destroy(shadow_data->mem_ctx);
2029 if (errno == ENOSYS) {
2030 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2031 conn->connectpath));
2032 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2035 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2036 conn->connectpath));
2037 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
2042 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2047 data_count = 12+labels_data_count+4;
2050 if (max_data_count<data_count) {
2051 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2052 max_data_count,data_count));
2053 talloc_destroy(shadow_data->mem_ctx);
2054 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2058 pdata = nttrans_realloc(ppdata, data_count);
2059 if (pdata == NULL) {
2060 talloc_destroy(shadow_data->mem_ctx);
2061 reply_nterror(req, NT_STATUS_NO_MEMORY);
2067 /* num_volumes 4 bytes */
2068 SIVAL(pdata,0,shadow_data->num_volumes);
2071 /* num_labels 4 bytes */
2072 SIVAL(pdata,4,shadow_data->num_volumes);
2075 /* needed_data_count 4 bytes */
2076 SIVAL(pdata,8,labels_data_count);
2080 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2081 shadow_data->num_volumes,fsp->fsp_name));
2082 if (labels && shadow_data->labels) {
2083 for (i=0;i<shadow_data->num_volumes;i++) {
2084 srvstr_push(pdata, req->flags2,
2085 cur_pdata, shadow_data->labels[i],
2086 2*sizeof(SHADOW_COPY_LABEL),
2087 STR_UNICODE|STR_TERMINATE);
2088 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2089 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2093 talloc_destroy(shadow_data->mem_ctx);
2095 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2101 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2103 /* pretend this succeeded -
2105 * we have to send back a list with all files owned by this SID
2107 * but I have to check that --metze
2111 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2113 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2115 if (!fsp_belongs_conn(conn, req, fsp)) {
2119 /* unknown 4 bytes: this is not the length of the sid :-( */
2120 /*unknown = IVAL(pdata,0);*/
2122 sid_parse(pdata+4,sid_len,&sid);
2123 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2125 if (!sid_to_uid(&sid, &uid)) {
2126 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2127 sid_string_dbg(&sid),
2128 (unsigned long)sid_len));
2132 /* we can take a look at the find source :-)
2134 * find ./ -uid $uid -name '*' is what we need here
2137 * and send 4bytes len and then NULL terminated unicode strings
2140 * but I don't know how to deal with the paged results
2141 * (maybe we can hang the result anywhere in the fsp struct)
2143 * we don't send all files at once
2144 * and at the next we should *not* start from the beginning,
2145 * so we have to cache the result
2150 /* this works for now... */
2151 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2155 if (!logged_ioctl_message) {
2156 logged_ioctl_message = true; /* Only print this once... */
2157 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2162 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2166 #ifdef HAVE_SYS_QUOTAS
2167 /****************************************************************************
2168 Reply to get user quota
2169 ****************************************************************************/
2171 static void call_nt_transact_get_user_quota(connection_struct *conn,
2172 struct smb_request *req,
2176 uint32 parameter_count,
2179 uint32 max_data_count)
2181 NTSTATUS nt_status = NT_STATUS_OK;
2182 char *params = *ppparams;
2183 char *pdata = *ppdata;
2185 int data_len=0,param_len=0;
2188 files_struct *fsp = NULL;
2192 bool start_enum = True;
2193 SMB_NTQUOTA_STRUCT qt;
2194 SMB_NTQUOTA_LIST *tmp_list;
2195 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2200 if (conn->server_info->utok.uid != 0) {
2201 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2202 "[%s]\n", lp_servicename(SNUM(conn)),
2203 conn->server_info->unix_name));
2204 reply_doserror(req, ERRDOS, ERRnoaccess);
2209 * Ensure minimum number of parameters sent.
2212 if (parameter_count < 4) {
2213 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2214 reply_doserror(req, ERRDOS, ERRinvalidparam);
2218 /* maybe we can check the quota_fnum */
2219 fsp = file_fsp(req, SVAL(params,0));
2220 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2221 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2222 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2226 /* the NULL pointer checking for fsp->fake_file_handle->pd
2227 * is done by CHECK_NTQUOTA_HANDLE_OK()
2229 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2231 level = SVAL(params,2);
2233 /* unknown 12 bytes leading in params */
2236 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2237 /* seems that we should continue with the enum here --metze */
2239 if (qt_handle->quota_list!=NULL &&
2240 qt_handle->tmp_list==NULL) {
2243 free_ntquota_list(&(qt_handle->quota_list));
2245 /* Realloc the size of parameters and data we will return */
2247 params = nttrans_realloc(ppparams, param_len);
2248 if(params == NULL) {
2249 reply_doserror(req, ERRDOS, ERRnomem);
2254 SIVAL(params,0,data_len);
2261 case TRANSACT_GET_USER_QUOTA_LIST_START:
2263 if (qt_handle->quota_list==NULL &&
2264 qt_handle->tmp_list==NULL) {
2268 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2269 reply_doserror(req, ERRSRV, ERRerror);
2273 /* Realloc the size of parameters and data we will return */
2275 params = nttrans_realloc(ppparams, param_len);
2276 if(params == NULL) {
2277 reply_doserror(req, ERRDOS, ERRnomem);
2281 /* we should not trust the value in max_data_count*/
2282 max_data_count = MIN(max_data_count,2048);
2284 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2286 reply_doserror(req, ERRDOS, ERRnomem);
2292 /* set params Size of returned Quota Data 4 bytes*/
2293 /* but set it later when we know it */
2295 /* for each entry push the data */
2298 qt_handle->tmp_list = qt_handle->quota_list;
2301 tmp_list = qt_handle->tmp_list;
2303 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2304 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2306 sid_len = ndr_size_dom_sid(
2307 &tmp_list->quotas->sid, NULL, 0);
2308 entry_len = 40 + sid_len;
2310 /* nextoffset entry 4 bytes */
2311 SIVAL(entry,0,entry_len);
2313 /* then the len of the SID 4 bytes */
2314 SIVAL(entry,4,sid_len);
2316 /* unknown data 8 bytes uint64_t */
2317 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2319 /* the used disk space 8 bytes uint64_t */
2320 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2322 /* the soft quotas 8 bytes uint64_t */
2323 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2325 /* the hard quotas 8 bytes uint64_t */
2326 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2328 /* and now the SID */
2329 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2332 qt_handle->tmp_list = tmp_list;
2334 /* overwrite the offset of the last entry */
2335 SIVAL(entry-entry_len,0,0);
2337 data_len = 4+qt_len;
2338 /* overwrite the params quota_data_len */
2339 SIVAL(params,0,data_len);
2343 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2345 /* unknown 4 bytes IVAL(pdata,0) */
2347 if (data_count < 8) {
2348 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2349 reply_doserror(req, ERRDOS, ERRunknownlevel);
2353 sid_len = IVAL(pdata,4);
2354 /* Ensure this is less than 1mb. */
2355 if (sid_len > (1024*1024)) {
2356 reply_doserror(req, ERRDOS, ERRnomem);
2360 if (data_count < 8+sid_len) {
2361 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2362 reply_doserror(req, ERRDOS, ERRunknownlevel);
2366 data_len = 4+40+sid_len;
2368 if (max_data_count < data_len) {
2369 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2370 max_data_count, data_len));
2372 SIVAL(params,0,data_len);
2374 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2378 sid_parse(pdata+8,sid_len,&sid);
2380 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2383 * we have to return zero's in all fields
2384 * instead of returning an error here
2389 /* Realloc the size of parameters and data we will return */
2391 params = nttrans_realloc(ppparams, param_len);
2392 if(params == NULL) {
2393 reply_doserror(req, ERRDOS, ERRnomem);
2397 pdata = nttrans_realloc(ppdata, data_len);
2399 reply_doserror(req, ERRDOS, ERRnomem);
2405 /* set params Size of returned Quota Data 4 bytes*/
2406 SIVAL(params,0,data_len);
2408 /* nextoffset entry 4 bytes */
2411 /* then the len of the SID 4 bytes */
2412 SIVAL(entry,4,sid_len);
2414 /* unknown data 8 bytes uint64_t */
2415 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2417 /* the used disk space 8 bytes uint64_t */
2418 SBIG_UINT(entry,16,qt.usedspace);
2420 /* the soft quotas 8 bytes uint64_t */
2421 SBIG_UINT(entry,24,qt.softlim);
2423 /* the hard quotas 8 bytes uint64_t */
2424 SBIG_UINT(entry,32,qt.hardlim);
2426 /* and now the SID */
2427 sid_linearize(entry+40, sid_len, &sid);
2432 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2433 reply_doserror(req, ERRSRV, ERRerror);
2438 send_nt_replies(conn, req, nt_status, params, param_len,
2442 /****************************************************************************
2443 Reply to set user quota
2444 ****************************************************************************/
2446 static void call_nt_transact_set_user_quota(connection_struct *conn,
2447 struct smb_request *req,
2451 uint32 parameter_count,
2454 uint32 max_data_count)
2456 char *params = *ppparams;
2457 char *pdata = *ppdata;
2458 int data_len=0,param_len=0;
2459 SMB_NTQUOTA_STRUCT qt;
2462 files_struct *fsp = NULL;
2467 if (conn->server_info->utok.uid != 0) {
2468 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2469 "[%s]\n", lp_servicename(SNUM(conn)),
2470 conn->server_info->unix_name));
2471 reply_doserror(req, ERRDOS, ERRnoaccess);
2476 * Ensure minimum number of parameters sent.
2479 if (parameter_count < 2) {
2480 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2481 reply_doserror(req, ERRDOS, ERRinvalidparam);
2485 /* maybe we can check the quota_fnum */
2486 fsp = file_fsp(req, SVAL(params,0));
2487 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2488 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2489 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2493 if (data_count < 40) {
2494 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2495 reply_doserror(req, ERRDOS, ERRunknownlevel);
2499 /* offset to next quota record.
2500 * 4 bytes IVAL(pdata,0)
2505 sid_len = IVAL(pdata,4);
2507 if (data_count < 40+sid_len) {
2508 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2509 reply_doserror(req, ERRDOS, ERRunknownlevel);
2513 /* unknown 8 bytes in pdata
2514 * maybe its the change time in NTTIME
2517 /* the used space 8 bytes (uint64_t)*/
2518 qt.usedspace = (uint64_t)IVAL(pdata,16);
2519 #ifdef LARGE_SMB_OFF_T
2520 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2521 #else /* LARGE_SMB_OFF_T */
2522 if ((IVAL(pdata,20) != 0)&&
2523 ((qt.usedspace != 0xFFFFFFFF)||
2524 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2525 /* more than 32 bits? */
2526 reply_doserror(req, ERRDOS, ERRunknownlevel);
2529 #endif /* LARGE_SMB_OFF_T */
2531 /* the soft quotas 8 bytes (uint64_t)*/
2532 qt.softlim = (uint64_t)IVAL(pdata,24);
2533 #ifdef LARGE_SMB_OFF_T
2534 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2535 #else /* LARGE_SMB_OFF_T */
2536 if ((IVAL(pdata,28) != 0)&&
2537 ((qt.softlim != 0xFFFFFFFF)||
2538 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2539 /* more than 32 bits? */
2540 reply_doserror(req, ERRDOS, ERRunknownlevel);
2543 #endif /* LARGE_SMB_OFF_T */
2545 /* the hard quotas 8 bytes (uint64_t)*/
2546 qt.hardlim = (uint64_t)IVAL(pdata,32);
2547 #ifdef LARGE_SMB_OFF_T
2548 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2549 #else /* LARGE_SMB_OFF_T */
2550 if ((IVAL(pdata,36) != 0)&&
2551 ((qt.hardlim != 0xFFFFFFFF)||
2552 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2553 /* more than 32 bits? */
2554 reply_doserror(req, ERRDOS, ERRunknownlevel);
2557 #endif /* LARGE_SMB_OFF_T */
2559 sid_parse(pdata+40,sid_len,&sid);
2560 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2562 /* 44 unknown bytes left... */
2564 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2565 reply_doserror(req, ERRSRV, ERRerror);
2569 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2572 #endif /* HAVE_SYS_QUOTAS */
2574 static void handle_nttrans(connection_struct *conn,
2575 struct trans_state *state,
2576 struct smb_request *req)
2578 if (Protocol >= PROTOCOL_NT1) {
2579 req->flags2 |= 0x40; /* IS_LONG_NAME */
2580 SSVAL(req->inbuf,smb_flg2,req->flags2);
2584 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2586 /* Now we must call the relevant NT_TRANS function */
2587 switch(state->call) {
2588 case NT_TRANSACT_CREATE:
2590 START_PROFILE(NT_transact_create);
2591 call_nt_transact_create(
2593 &state->setup, state->setup_count,
2594 &state->param, state->total_param,
2595 &state->data, state->total_data,
2596 state->max_data_return);
2597 END_PROFILE(NT_transact_create);
2601 case NT_TRANSACT_IOCTL:
2603 START_PROFILE(NT_transact_ioctl);
2604 call_nt_transact_ioctl(
2606 &state->setup, state->setup_count,
2607 &state->param, state->total_param,
2608 &state->data, state->total_data,
2609 state->max_data_return);
2610 END_PROFILE(NT_transact_ioctl);
2614 case NT_TRANSACT_SET_SECURITY_DESC:
2616 START_PROFILE(NT_transact_set_security_desc);
2617 call_nt_transact_set_security_desc(
2619 &state->setup, state->setup_count,
2620 &state->param, state->total_param,
2621 &state->data, state->total_data,
2622 state->max_data_return);
2623 END_PROFILE(NT_transact_set_security_desc);
2627 case NT_TRANSACT_NOTIFY_CHANGE:
2629 START_PROFILE(NT_transact_notify_change);
2630 call_nt_transact_notify_change(
2632 &state->setup, state->setup_count,
2633 &state->param, state->total_param,
2634 &state->data, state->total_data,
2635 state->max_data_return,
2636 state->max_param_return);
2637 END_PROFILE(NT_transact_notify_change);
2641 case NT_TRANSACT_RENAME:
2643 START_PROFILE(NT_transact_rename);
2644 call_nt_transact_rename(
2646 &state->setup, state->setup_count,
2647 &state->param, state->total_param,
2648 &state->data, state->total_data,
2649 state->max_data_return);
2650 END_PROFILE(NT_transact_rename);
2654 case NT_TRANSACT_QUERY_SECURITY_DESC:
2656 START_PROFILE(NT_transact_query_security_desc);
2657 call_nt_transact_query_security_desc(
2659 &state->setup, state->setup_count,
2660 &state->param, state->total_param,
2661 &state->data, state->total_data,
2662 state->max_data_return);
2663 END_PROFILE(NT_transact_query_security_desc);
2667 #ifdef HAVE_SYS_QUOTAS
2668 case NT_TRANSACT_GET_USER_QUOTA:
2670 START_PROFILE(NT_transact_get_user_quota);
2671 call_nt_transact_get_user_quota(
2673 &state->setup, state->setup_count,
2674 &state->param, state->total_param,
2675 &state->data, state->total_data,
2676 state->max_data_return);
2677 END_PROFILE(NT_transact_get_user_quota);
2681 case NT_TRANSACT_SET_USER_QUOTA:
2683 START_PROFILE(NT_transact_set_user_quota);
2684 call_nt_transact_set_user_quota(
2686 &state->setup, state->setup_count,
2687 &state->param, state->total_param,
2688 &state->data, state->total_data,
2689 state->max_data_return);
2690 END_PROFILE(NT_transact_set_user_quota);
2693 #endif /* HAVE_SYS_QUOTAS */
2696 /* Error in request */
2697 DEBUG(0,("handle_nttrans: Unknown request %d in "
2698 "nttrans call\n", state->call));
2699 reply_doserror(req, ERRSRV, ERRerror);
2705 /****************************************************************************
2706 Reply to a SMBNTtrans.
2707 ****************************************************************************/
2709 void reply_nttrans(struct smb_request *req)
2711 connection_struct *conn = req->conn;
2716 uint16 function_code;
2718 struct trans_state *state;
2720 START_PROFILE(SMBnttrans);
2722 if (req->wct < 19) {
2723 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2724 END_PROFILE(SMBnttrans);
2728 pscnt = IVAL(req->vwv+9, 1);
2729 psoff = IVAL(req->vwv+11, 1);
2730 dscnt = IVAL(req->vwv+13, 1);
2731 dsoff = IVAL(req->vwv+15, 1);
2732 function_code = SVAL(req->vwv+18, 0);
2734 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2735 reply_doserror(req, ERRSRV, ERRaccess);
2736 END_PROFILE(SMBnttrans);
2740 result = allow_new_trans(conn->pending_trans, req->mid);
2741 if (!NT_STATUS_IS_OK(result)) {
2742 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2743 reply_nterror(req, result);
2744 END_PROFILE(SMBnttrans);
2748 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2749 reply_doserror(req, ERRSRV, ERRaccess);
2750 END_PROFILE(SMBnttrans);
2754 state->cmd = SMBnttrans;
2756 state->mid = req->mid;
2757 state->vuid = req->vuid;
2758 state->total_data = IVAL(req->vwv+3, 1);
2760 state->total_param = IVAL(req->vwv+1, 1);
2761 state->param = NULL;
2762 state->max_data_return = IVAL(req->vwv+7, 1);
2763 state->max_param_return = IVAL(req->vwv+5, 1);
2765 /* setup count is in *words* */
2766 state->setup_count = 2*CVAL(req->vwv+17, 1);
2767 state->setup = NULL;
2768 state->call = function_code;
2770 DEBUG(10, ("num_setup=%u, "
2771 "param_total=%u, this_param=%u, max_param=%u, "
2772 "data_total=%u, this_data=%u, max_data=%u, "
2773 "param_offset=%u, data_offset=%u\n",
2774 (unsigned)state->setup_count,
2775 (unsigned)state->total_param, (unsigned)pscnt,
2776 (unsigned)state->max_param_return,
2777 (unsigned)state->total_data, (unsigned)dscnt,
2778 (unsigned)state->max_data_return,
2779 (unsigned)psoff, (unsigned)dsoff));
2782 * All nttrans messages we handle have smb_wct == 19 +
2783 * state->setup_count. Ensure this is so as a sanity check.
2786 if(req->wct != 19 + (state->setup_count/2)) {
2787 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2788 req->wct, 19 + (state->setup_count/2)));
2792 /* Don't allow more than 128mb for each value. */
2793 if ((state->total_data > (1024*1024*128)) ||
2794 (state->total_param > (1024*1024*128))) {
2795 reply_doserror(req, ERRDOS, ERRnomem);
2796 END_PROFILE(SMBnttrans);
2800 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2803 if (state->total_data) {
2805 if (trans_oob(state->total_data, 0, dscnt)
2806 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2810 /* Can't use talloc here, the core routines do realloc on the
2811 * params and data. */
2812 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2813 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2814 "bytes !\n", (unsigned int)state->total_data));
2816 reply_doserror(req, ERRDOS, ERRnomem);
2817 END_PROFILE(SMBnttrans);
2821 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2824 if (state->total_param) {
2826 if (trans_oob(state->total_param, 0, pscnt)
2827 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2831 /* Can't use talloc here, the core routines do realloc on the
2832 * params and data. */
2833 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2834 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2835 "bytes !\n", (unsigned int)state->total_param));
2836 SAFE_FREE(state->data);
2838 reply_doserror(req, ERRDOS, ERRnomem);
2839 END_PROFILE(SMBnttrans);
2843 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2846 state->received_data = dscnt;
2847 state->received_param = pscnt;
2849 if(state->setup_count > 0) {
2850 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2851 state->setup_count));
2854 * No overflow possible here, state->setup_count is an
2855 * unsigned int, being filled by a single byte from
2856 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2857 * below is not necessary, it's here to clarify things. The
2858 * validity of req->vwv and req->wct has been checked in
2859 * init_smb_request already.
2861 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2865 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2866 if (state->setup == NULL) {
2867 DEBUG(0,("reply_nttrans : Out of memory\n"));
2868 SAFE_FREE(state->data);
2869 SAFE_FREE(state->param);
2871 reply_doserror(req, ERRDOS, ERRnomem);
2872 END_PROFILE(SMBnttrans);
2876 memcpy(state->setup, req->vwv+19, state->setup_count);
2877 dump_data(10, (uint8 *)state->setup, state->setup_count);
2880 if ((state->received_data == state->total_data) &&
2881 (state->received_param == state->total_param)) {
2882 handle_nttrans(conn, state, req);
2883 SAFE_FREE(state->param);
2884 SAFE_FREE(state->data);
2886 END_PROFILE(SMBnttrans);
2890 DLIST_ADD(conn->pending_trans, state);
2892 /* We need to send an interim response then receive the rest
2893 of the parameter/data bytes */
2894 reply_outbuf(req, 0, 0);
2895 show_msg((char *)req->outbuf);
2896 END_PROFILE(SMBnttrans);
2901 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2902 SAFE_FREE(state->data);
2903 SAFE_FREE(state->param);
2905 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2906 END_PROFILE(SMBnttrans);
2910 /****************************************************************************
2911 Reply to a SMBnttranss
2912 ****************************************************************************/
2914 void reply_nttranss(struct smb_request *req)
2916 connection_struct *conn = req->conn;
2917 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2918 struct trans_state *state;
2920 START_PROFILE(SMBnttranss);
2922 show_msg((char *)req->inbuf);
2924 if (req->wct < 18) {
2925 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2926 END_PROFILE(SMBnttranss);
2930 for (state = conn->pending_trans; state != NULL;
2931 state = state->next) {
2932 if (state->mid == req->mid) {
2937 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2938 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2939 END_PROFILE(SMBnttranss);
2943 /* Revise state->total_param and state->total_data in case they have
2944 changed downwards */
2945 if (IVAL(req->vwv+1, 1) < state->total_param) {
2946 state->total_param = IVAL(req->vwv+1, 1);
2948 if (IVAL(req->vwv+3, 1) < state->total_data) {
2949 state->total_data = IVAL(req->vwv+3, 1);
2952 pcnt = IVAL(req->vwv+5, 1);
2953 poff = IVAL(req->vwv+7, 1);
2954 pdisp = IVAL(req->vwv+9, 1);
2956 dcnt = IVAL(req->vwv+11, 1);
2957 doff = IVAL(req->vwv+13, 1);
2958 ddisp = IVAL(req->vwv+15, 1);
2960 state->received_param += pcnt;
2961 state->received_data += dcnt;
2963 if ((state->received_data > state->total_data) ||
2964 (state->received_param > state->total_param))
2968 if (trans_oob(state->total_param, pdisp, pcnt)
2969 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2972 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2976 if (trans_oob(state->total_data, ddisp, dcnt)
2977 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2980 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2983 if ((state->received_param < state->total_param) ||
2984 (state->received_data < state->total_data)) {
2985 END_PROFILE(SMBnttranss);
2989 handle_nttrans(conn, state, req);
2991 DLIST_REMOVE(conn->pending_trans, state);
2992 SAFE_FREE(state->data);
2993 SAFE_FREE(state->param);
2995 END_PROFILE(SMBnttranss);
3000 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
3001 DLIST_REMOVE(conn->pending_trans, state);
3002 SAFE_FREE(state->data);
3003 SAFE_FREE(state->param);
3005 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
3006 END_PROFILE(SMBnttranss);