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 (!is_ntfs_stream_smb_fname(smb_fname)) {
329 return StrCaseCmp(smb_fname->stream_name, "::$DATA") == 0;
332 /****************************************************************************
333 Reply to an NT create and X call on a pipe
334 ****************************************************************************/
336 static void nt_open_pipe(char *fname, connection_struct *conn,
337 struct smb_request *req, int *ppnum)
342 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
344 /* Strip \\ off the name. */
347 status = open_np_file(req, fname, &fsp);
348 if (!NT_STATUS_IS_OK(status)) {
349 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
350 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
354 reply_nterror(req, status);
362 /****************************************************************************
363 Reply to an NT create and X call for pipes.
364 ****************************************************************************/
366 static void do_ntcreate_pipe_open(connection_struct *conn,
367 struct smb_request *req)
372 uint32 flags = IVAL(req->vwv+3, 1);
373 TALLOC_CTX *ctx = talloc_tos();
375 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
378 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
382 nt_open_pipe(fname, conn, req, &pnum);
390 * Deal with pipe return.
393 if (flags & EXTENDED_RESPONSE_REQUIRED) {
394 /* This is very strange. We
395 * return 50 words, but only set
396 * the wcnt to 42 ? It's definately
397 * what happens on the wire....
399 reply_outbuf(req, 50, 0);
400 SCVAL(req->outbuf,smb_wct,42);
402 reply_outbuf(req, 34, 0);
405 p = (char *)req->outbuf + smb_vwv2;
409 SIVAL(p,0,FILE_WAS_OPENED);
412 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
415 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
417 SSVAL(p,2, 0x5FF); /* ? */
420 if (flags & EXTENDED_RESPONSE_REQUIRED) {
422 SIVAL(p,0,FILE_GENERIC_ALL);
424 * For pipes W2K3 seems to return
426 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
428 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
431 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
436 /****************************************************************************
437 Reply to an NT create and X call.
438 ****************************************************************************/
440 void reply_ntcreate_and_X(struct smb_request *req)
442 connection_struct *conn = req->conn;
443 struct smb_filename *smb_fname = NULL;
447 uint32 file_attributes;
449 uint32 create_disposition;
450 uint32 create_options;
452 uint64_t allocation_size;
453 /* Breakout the oplock request bits so we can set the
454 reply bits separately. */
456 SMB_OFF_T file_len = 0;
458 files_struct *fsp = NULL;
460 struct timespec c_timespec;
461 struct timespec a_timespec;
462 struct timespec m_timespec;
465 uint8_t oplock_granted = NO_OPLOCK_RETURN;
466 TALLOC_CTX *ctx = talloc_tos();
468 START_PROFILE(SMBntcreateX);
471 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
475 flags = IVAL(req->vwv+3, 1);
476 access_mask = IVAL(req->vwv+7, 1);
477 file_attributes = IVAL(req->vwv+13, 1);
478 share_access = IVAL(req->vwv+15, 1);
479 create_disposition = IVAL(req->vwv+17, 1);
480 create_options = IVAL(req->vwv+19, 1);
481 root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
483 allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
484 #ifdef LARGE_SMB_OFF_T
485 allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
488 srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
489 STR_TERMINATE, &status);
491 if (!NT_STATUS_IS_OK(status)) {
492 reply_nterror(req, status);
496 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
497 "file_attributes = 0x%x, share_access = 0x%x, "
498 "create_disposition = 0x%x create_options = 0x%x "
499 "root_dir_fid = 0x%x, fname = %s\n",
501 (unsigned int)access_mask,
502 (unsigned int)file_attributes,
503 (unsigned int)share_access,
504 (unsigned int)create_disposition,
505 (unsigned int)create_options,
506 (unsigned int)root_dir_fid,
510 * we need to remove ignored bits when they come directly from the client
511 * because we reuse some of them for internal stuff
513 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
516 * If it's an IPC, use the pipe handler.
520 if (lp_nt_pipe_support()) {
521 do_ntcreate_pipe_open(conn, req);
524 reply_doserror(req, ERRDOS, ERRnoaccess);
528 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
529 if (oplock_request) {
530 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
534 status = filename_convert(ctx,
536 req->flags2 & FLAGS2_DFS_PATHNAMES,
541 if (!NT_STATUS_IS_OK(status)) {
542 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
544 NT_STATUS_PATH_NOT_COVERED,
548 reply_nterror(req, status);
552 status = SMB_VFS_CREATE_FILE(
555 root_dir_fid, /* root_dir_fid */
556 smb_fname, /* fname */
557 access_mask, /* access_mask */
558 share_access, /* share_access */
559 create_disposition, /* create_disposition*/
560 create_options, /* create_options */
561 file_attributes, /* file_attributes */
562 oplock_request, /* oplock_request */
563 allocation_size, /* allocation_size */
569 if (!NT_STATUS_IS_OK(status)) {
570 if (open_was_deferred(req->mid)) {
571 /* We have re-scheduled this call, no error. */
574 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
575 reply_botherror(req, status, ERRDOS, ERRfilexists);
578 reply_nterror(req, status);
584 * If the caller set the extended oplock request bit
585 * and we granted one (by whatever means) - set the
586 * correct bit for extended oplock reply.
589 if (oplock_request &&
590 (lp_fake_oplocks(SNUM(conn))
591 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
594 * Exclusive oplock granted
597 if (flags & REQUEST_BATCH_OPLOCK) {
598 oplock_granted = BATCH_OPLOCK_RETURN;
600 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
602 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
603 oplock_granted = LEVEL_II_OPLOCK_RETURN;
605 oplock_granted = NO_OPLOCK_RETURN;
608 file_len = smb_fname->st.st_ex_size;
609 fattr = dos_mode(conn,fsp->fsp_name,&smb_fname->st);
611 fattr = FILE_ATTRIBUTE_NORMAL;
614 if (flags & EXTENDED_RESPONSE_REQUIRED) {
615 /* This is very strange. We
616 * return 50 words, but only set
617 * the wcnt to 42 ? It's definately
618 * what happens on the wire....
620 reply_outbuf(req, 50, 0);
621 SCVAL(req->outbuf,smb_wct,42);
623 reply_outbuf(req, 34, 0);
626 p = (char *)req->outbuf + smb_vwv2;
628 SCVAL(p, 0, oplock_granted);
631 SSVAL(p,0,fsp->fnum);
633 if ((create_disposition == FILE_SUPERSEDE)
634 && (info == FILE_WAS_OVERWRITTEN)) {
635 SIVAL(p,0,FILE_WAS_SUPERSEDED);
642 c_timespec = smb_fname->st.st_ex_btime;
643 a_timespec = smb_fname->st.st_ex_atime;
644 m_timespec = smb_fname->st.st_ex_mtime;
646 if (lp_dos_filetime_resolution(SNUM(conn))) {
647 dos_filetime_timespec(&c_timespec);
648 dos_filetime_timespec(&a_timespec);
649 dos_filetime_timespec(&m_timespec);
652 put_long_date_timespec(p, c_timespec); /* create time. */
654 put_long_date_timespec(p, a_timespec); /* access time */
656 put_long_date_timespec(p, m_timespec); /* write time */
658 put_long_date_timespec(p, m_timespec); /* change time */
660 SIVAL(p,0,fattr); /* File Attributes. */
662 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
664 SOFF_T(p,0,file_len);
666 if (flags & EXTENDED_RESPONSE_REQUIRED) {
670 SCVAL(p,0,fsp->is_directory ? 1 : 0);
672 if (flags & EXTENDED_RESPONSE_REQUIRED) {
675 if (fsp->is_directory ||
676 can_write_to_file(conn, smb_fname)) {
677 perms = FILE_GENERIC_ALL;
679 perms = FILE_GENERIC_READ|FILE_EXECUTE;
684 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
685 fsp->fnum, fsp->fsp_name));
689 TALLOC_FREE(smb_fname);
690 END_PROFILE(SMBntcreateX);
694 /****************************************************************************
695 Reply to a NT_TRANSACT_CREATE call to open a pipe.
696 ****************************************************************************/
698 static void do_nt_transact_create_pipe(connection_struct *conn,
699 struct smb_request *req,
700 uint16 **ppsetup, uint32 setup_count,
701 char **ppparams, uint32 parameter_count,
702 char **ppdata, uint32 data_count)
705 char *params = *ppparams;
711 TALLOC_CTX *ctx = talloc_tos();
714 * Ensure minimum number of parameters sent.
717 if(parameter_count < 54) {
718 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
719 reply_doserror(req, ERRDOS, ERRnoaccess);
723 flags = IVAL(params,0);
725 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
726 parameter_count-53, STR_TERMINATE,
728 if (!NT_STATUS_IS_OK(status)) {
729 reply_nterror(req, status);
733 nt_open_pipe(fname, conn, req, &pnum);
740 /* Realloc the size of parameters and data we will return */
741 if (flags & EXTENDED_RESPONSE_REQUIRED) {
742 /* Extended response is 32 more byyes. */
747 params = nttrans_realloc(ppparams, param_len);
749 reply_doserror(req, ERRDOS, ERRnomem);
754 SCVAL(p,0,NO_OPLOCK_RETURN);
759 SIVAL(p,0,FILE_WAS_OPENED);
763 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
766 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
768 SSVAL(p,2, 0x5FF); /* ? */
771 if (flags & EXTENDED_RESPONSE_REQUIRED) {
773 SIVAL(p,0,FILE_GENERIC_ALL);
775 * For pipes W2K3 seems to return
777 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
779 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
782 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
784 /* Send the required number of replies */
785 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
790 /****************************************************************************
791 Internal fn to set security descriptors.
792 ****************************************************************************/
794 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
795 uint32 security_info_sent)
797 SEC_DESC *psd = NULL;
800 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
804 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
806 if (!NT_STATUS_IS_OK(status)) {
810 if (psd->owner_sid == NULL) {
811 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
813 if (psd->group_sid == NULL) {
814 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
817 /* Convert all the generic bits. */
818 security_acl_map_generic(psd->dacl, &file_generic_mapping);
819 security_acl_map_generic(psd->sacl, &file_generic_mapping);
821 if (DEBUGLEVEL >= 10) {
822 DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
823 NDR_PRINT_DEBUG(security_descriptor, psd);
826 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
833 /****************************************************************************
834 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
835 ****************************************************************************/
837 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
839 struct ea_list *ea_list_head = NULL;
846 while (offset + 4 <= data_size) {
847 size_t next_offset = IVAL(pdata,offset);
848 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
854 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
855 if (next_offset == 0) {
858 offset += next_offset;
864 /****************************************************************************
865 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
866 ****************************************************************************/
868 static void call_nt_transact_create(connection_struct *conn,
869 struct smb_request *req,
870 uint16 **ppsetup, uint32 setup_count,
871 char **ppparams, uint32 parameter_count,
872 char **ppdata, uint32 data_count,
873 uint32 max_data_count)
875 struct smb_filename *smb_fname = NULL;
877 char *params = *ppparams;
878 char *data = *ppdata;
879 /* Breakout the oplock request bits so we can set the reply bits separately. */
881 SMB_OFF_T file_len = 0;
883 files_struct *fsp = NULL;
887 uint32 file_attributes;
889 uint32 create_disposition;
890 uint32 create_options;
892 struct security_descriptor *sd = NULL;
895 struct timespec c_timespec;
896 struct timespec a_timespec;
897 struct timespec m_timespec;
898 struct ea_list *ea_list = NULL;
901 uint64_t allocation_size;
903 uint8_t oplock_granted;
904 TALLOC_CTX *ctx = talloc_tos();
906 DEBUG(5,("call_nt_transact_create\n"));
909 * If it's an IPC, use the pipe handler.
913 if (lp_nt_pipe_support()) {
914 do_nt_transact_create_pipe(
916 ppsetup, setup_count,
917 ppparams, parameter_count,
921 reply_doserror(req, ERRDOS, ERRnoaccess);
926 * Ensure minimum number of parameters sent.
929 if(parameter_count < 54) {
930 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
931 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
935 flags = IVAL(params,0);
936 access_mask = IVAL(params,8);
937 file_attributes = IVAL(params,20);
938 share_access = IVAL(params,24);
939 create_disposition = IVAL(params,28);
940 create_options = IVAL(params,32);
941 sd_len = IVAL(params,36);
942 ea_len = IVAL(params,40);
943 root_dir_fid = (uint16)IVAL(params,4);
944 allocation_size = (uint64_t)IVAL(params,12);
945 #ifdef LARGE_SMB_OFF_T
946 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
950 * we need to remove ignored bits when they come directly from the client
951 * because we reuse some of them for internal stuff
953 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
955 /* Ensure the data_len is correct for the sd and ea values given. */
956 if ((ea_len + sd_len > data_count)
957 || (ea_len > data_count) || (sd_len > data_count)
958 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
959 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
960 "%u, data_count = %u\n", (unsigned int)ea_len,
961 (unsigned int)sd_len, (unsigned int)data_count));
962 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
967 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
970 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
972 if (!NT_STATUS_IS_OK(status)) {
973 DEBUG(10, ("call_nt_transact_create: "
974 "unmarshall_sec_desc failed: %s\n",
976 reply_nterror(req, status);
982 if (!lp_ea_support(SNUM(conn))) {
983 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
984 "EA's not supported.\n",
985 (unsigned int)ea_len));
986 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
991 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
992 "too small (should be more than 10)\n",
993 (unsigned int)ea_len ));
994 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
998 /* We have already checked that ea_len <= data_count here. */
999 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
1001 if (ea_list == NULL) {
1002 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1007 srvstr_get_path(ctx, params, req->flags2, &fname,
1008 params+53, parameter_count-53,
1009 STR_TERMINATE, &status);
1010 if (!NT_STATUS_IS_OK(status)) {
1011 reply_nterror(req, status);
1015 status = filename_convert(ctx,
1017 req->flags2 & FLAGS2_DFS_PATHNAMES,
1022 if (!NT_STATUS_IS_OK(status)) {
1023 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1024 reply_botherror(req,
1025 NT_STATUS_PATH_NOT_COVERED,
1026 ERRSRV, ERRbadpath);
1029 reply_nterror(req, status);
1033 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1034 if (oplock_request) {
1035 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
1039 status = SMB_VFS_CREATE_FILE(
1042 root_dir_fid, /* root_dir_fid */
1043 smb_fname, /* fname */
1044 access_mask, /* access_mask */
1045 share_access, /* share_access */
1046 create_disposition, /* create_disposition*/
1047 create_options, /* create_options */
1048 file_attributes, /* file_attributes */
1049 oplock_request, /* oplock_request */
1050 allocation_size, /* allocation_size */
1052 ea_list, /* ea_list */
1056 if(!NT_STATUS_IS_OK(status)) {
1057 if (open_was_deferred(req->mid)) {
1058 /* We have re-scheduled this call, no error. */
1061 reply_openerror(req, status);
1066 * If the caller set the extended oplock request bit
1067 * and we granted one (by whatever means) - set the
1068 * correct bit for extended oplock reply.
1071 if (oplock_request &&
1072 (lp_fake_oplocks(SNUM(conn))
1073 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1076 * Exclusive oplock granted
1079 if (flags & REQUEST_BATCH_OPLOCK) {
1080 oplock_granted = BATCH_OPLOCK_RETURN;
1082 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1084 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1085 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1087 oplock_granted = NO_OPLOCK_RETURN;
1090 file_len = smb_fname->st.st_ex_size;
1091 fattr = dos_mode(conn, fsp->fsp_name, &smb_fname->st);
1093 fattr = FILE_ATTRIBUTE_NORMAL;
1096 /* Realloc the size of parameters and data we will return */
1097 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1098 /* Extended response is 32 more byyes. */
1103 params = nttrans_realloc(ppparams, param_len);
1104 if(params == NULL) {
1105 reply_doserror(req, ERRDOS, ERRnomem);
1110 SCVAL(p, 0, oplock_granted);
1113 SSVAL(p,0,fsp->fnum);
1115 if ((create_disposition == FILE_SUPERSEDE)
1116 && (info == FILE_WAS_OVERWRITTEN)) {
1117 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1124 c_timespec = smb_fname->st.st_ex_btime;
1125 a_timespec = smb_fname->st.st_ex_atime;
1126 m_timespec = smb_fname->st.st_ex_mtime;
1128 if (lp_dos_filetime_resolution(SNUM(conn))) {
1129 dos_filetime_timespec(&c_timespec);
1130 dos_filetime_timespec(&a_timespec);
1131 dos_filetime_timespec(&m_timespec);
1134 put_long_date_timespec(p, c_timespec); /* create time. */
1136 put_long_date_timespec(p, a_timespec); /* access time */
1138 put_long_date_timespec(p, m_timespec); /* write time */
1140 put_long_date_timespec(p, m_timespec); /* change time */
1142 SIVAL(p,0,fattr); /* File Attributes. */
1144 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1146 SOFF_T(p,0,file_len);
1148 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1152 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1154 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1157 if (fsp->is_directory ||
1158 can_write_to_file(conn, smb_fname)) {
1159 perms = FILE_GENERIC_ALL;
1161 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1166 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp->fsp_name));
1168 /* Send the required number of replies */
1169 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1171 TALLOC_FREE(smb_fname);
1175 /****************************************************************************
1176 Reply to a NT CANCEL request.
1177 conn POINTER CAN BE NULL HERE !
1178 ****************************************************************************/
1180 void reply_ntcancel(struct smb_request *req)
1183 * Go through and cancel any pending change notifies.
1186 START_PROFILE(SMBntcancel);
1187 srv_cancel_sign_response(smbd_server_conn);
1188 remove_pending_change_notify_requests_by_mid(req->mid);
1189 remove_pending_lock_requests_by_mid(req->mid);
1191 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1193 END_PROFILE(SMBntcancel);
1197 /****************************************************************************
1199 ****************************************************************************/
1201 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1202 connection_struct *conn,
1203 struct smb_request *req,
1204 struct smb_filename *smb_fname_src,
1205 struct smb_filename *smb_fname_dst,
1208 char *oldname = NULL;
1209 char *newname = NULL;
1210 files_struct *fsp1,*fsp2;
1214 NTSTATUS status = NT_STATUS_OK;
1217 if (!CAN_WRITE(conn)) {
1218 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1222 /* Source must already exist. */
1223 if (!VALID_STAT(smb_fname_src->st)) {
1224 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1228 status = get_full_smb_filename(ctx, smb_fname_src, &oldname);
1229 if (!NT_STATUS_IS_OK(status)) {
1233 /* Ensure attributes match. */
1234 fattr = dos_mode(conn, oldname, &smb_fname_src->st);
1235 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1236 status = NT_STATUS_NO_SUCH_FILE;
1240 /* Disallow if dst file already exists. */
1241 if (VALID_STAT(smb_fname_dst->st)) {
1242 status = NT_STATUS_OBJECT_NAME_COLLISION;
1246 /* No links from a directory. */
1247 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1248 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1252 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1253 smb_fname_str_dbg(smb_fname_src),
1254 smb_fname_str_dbg(smb_fname_dst)));
1256 status = SMB_VFS_CREATE_FILE(
1259 0, /* root_dir_fid */
1260 smb_fname_src, /* fname */
1261 FILE_READ_DATA, /* access_mask */
1262 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1264 FILE_OPEN, /* create_disposition*/
1265 0, /* create_options */
1266 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1267 NO_OPLOCK, /* oplock_request */
1268 0, /* allocation_size */
1274 if (!NT_STATUS_IS_OK(status)) {
1278 status = SMB_VFS_CREATE_FILE(
1281 0, /* root_dir_fid */
1282 smb_fname_dst, /* fname */
1283 FILE_WRITE_DATA, /* access_mask */
1284 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1286 FILE_CREATE, /* create_disposition*/
1287 0, /* create_options */
1288 fattr, /* file_attributes */
1289 NO_OPLOCK, /* oplock_request */
1290 0, /* allocation_size */
1296 if (!NT_STATUS_IS_OK(status)) {
1297 close_file(NULL, fsp1, ERROR_CLOSE);
1301 if (smb_fname_src->st.st_ex_size) {
1302 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1306 * As we are opening fsp1 read-only we only expect
1307 * an error on close on fsp2 if we are out of space.
1308 * Thus we don't look at the error return from the
1311 close_file(NULL, fsp1, NORMAL_CLOSE);
1313 /* Ensure the modtime is set correctly on the destination file. */
1314 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1316 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1318 status = get_full_smb_filename(ctx, smb_fname_dst, &newname);
1319 if (!NT_STATUS_IS_OK(status)) {
1323 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1324 creates the file. This isn't the correct thing to do in the copy
1326 if (!parent_dirname(talloc_tos(), newname, &parent, NULL)) {
1327 status = NT_STATUS_NO_MEMORY;
1330 file_set_dosmode(conn, newname, fattr, &smb_fname_dst->st, parent,
1332 TALLOC_FREE(parent);
1334 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1335 status = NT_STATUS_DISK_FULL;
1339 if (!NT_STATUS_IS_OK(status)) {
1340 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1341 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1342 smb_fname_str_dbg(smb_fname_dst)));
1345 TALLOC_FREE(oldname);
1346 TALLOC_FREE(newname);
1351 /****************************************************************************
1352 Reply to a NT rename request.
1353 ****************************************************************************/
1355 void reply_ntrename(struct smb_request *req)
1357 connection_struct *conn = req->conn;
1358 struct smb_filename *smb_fname_old = NULL;
1359 struct smb_filename *smb_fname_new = NULL;
1360 char *oldname = NULL;
1361 char *newname = NULL;
1364 bool src_has_wcard = False;
1365 bool dest_has_wcard = False;
1368 TALLOC_CTX *ctx = talloc_tos();
1370 START_PROFILE(SMBntrename);
1373 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1374 END_PROFILE(SMBntrename);
1378 attrs = SVAL(req->vwv+0, 0);
1379 rename_type = SVAL(req->vwv+1, 0);
1381 p = (const char *)req->buf + 1;
1382 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1383 &status, &src_has_wcard);
1384 if (!NT_STATUS_IS_OK(status)) {
1385 reply_nterror(req, status);
1386 END_PROFILE(SMBntrename);
1390 if (ms_has_wild(oldname)) {
1391 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1392 END_PROFILE(SMBntrename);
1397 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1398 &status, &dest_has_wcard);
1399 if (!NT_STATUS_IS_OK(status)) {
1400 reply_nterror(req, status);
1401 END_PROFILE(SMBntrename);
1405 status = filename_convert(ctx, conn,
1406 req->flags2 & FLAGS2_DFS_PATHNAMES,
1410 if (!NT_STATUS_IS_OK(status)) {
1411 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1412 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1413 ERRSRV, ERRbadpath);
1414 END_PROFILE(SMBntrename);
1417 reply_nterror(req, status);
1418 END_PROFILE(SMBntrename);
1422 status = filename_convert(ctx, conn,
1423 req->flags2 & FLAGS2_DFS_PATHNAMES,
1427 if (!NT_STATUS_IS_OK(status)) {
1428 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1429 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1430 ERRSRV, ERRbadpath);
1431 END_PROFILE(SMBntrename);
1434 reply_nterror(req, status);
1435 END_PROFILE(SMBntrename);
1439 /* The new name must begin with a ':' if the old name is a stream. */
1440 if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
1441 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1442 END_PROFILE(SMBntrename);
1446 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1448 switch(rename_type) {
1449 case RENAME_FLAG_RENAME:
1450 status = rename_internals(ctx, conn, req, oldname,
1451 newname, attrs, False, src_has_wcard,
1452 dest_has_wcard, DELETE_ACCESS);
1454 case RENAME_FLAG_HARD_LINK:
1455 if (src_has_wcard || dest_has_wcard) {
1457 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1459 status = hardlink_internals(ctx,
1465 case RENAME_FLAG_COPY:
1466 if (src_has_wcard || dest_has_wcard) {
1468 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1470 status = copy_internals(ctx, conn, req,
1476 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1477 status = NT_STATUS_INVALID_PARAMETER;
1480 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1484 if (!NT_STATUS_IS_OK(status)) {
1485 if (open_was_deferred(req->mid)) {
1486 /* We have re-scheduled this call. */
1487 END_PROFILE(SMBntrename);
1491 reply_nterror(req, status);
1492 END_PROFILE(SMBntrename);
1496 reply_outbuf(req, 0, 0);
1498 END_PROFILE(SMBntrename);
1502 /****************************************************************************
1503 Reply to a notify change - queue the request and
1504 don't allow a directory to be opened.
1505 ****************************************************************************/
1507 static void call_nt_transact_notify_change(connection_struct *conn,
1508 struct smb_request *req,
1512 uint32 parameter_count,
1513 char **ppdata, uint32 data_count,
1514 uint32 max_data_count,
1515 uint32 max_param_count)
1517 uint16 *setup = *ppsetup;
1523 if(setup_count < 6) {
1524 reply_doserror(req, ERRDOS, ERRbadfunc);
1528 fsp = file_fsp(req, SVAL(setup,4));
1529 filter = IVAL(setup, 0);
1530 recursive = (SVAL(setup, 6) != 0) ? True : False;
1532 DEBUG(3,("call_nt_transact_notify_change\n"));
1535 reply_doserror(req, ERRDOS, ERRbadfid);
1540 char *filter_string;
1542 if (!(filter_string = notify_filter_string(NULL, filter))) {
1543 reply_nterror(req,NT_STATUS_NO_MEMORY);
1547 DEBUG(3,("call_nt_transact_notify_change: notify change "
1548 "called on %s, filter = %s, recursive = %d\n",
1549 fsp->fsp_name, filter_string, recursive));
1551 TALLOC_FREE(filter_string);
1554 if((!fsp->is_directory) || (conn != fsp->conn)) {
1555 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1559 if (fsp->notify == NULL) {
1561 status = change_notify_create(fsp, filter, recursive);
1563 if (!NT_STATUS_IS_OK(status)) {
1564 DEBUG(10, ("change_notify_create returned %s\n",
1565 nt_errstr(status)));
1566 reply_nterror(req, status);
1571 if (fsp->notify->num_changes != 0) {
1574 * We've got changes pending, respond immediately
1578 * TODO: write a torture test to check the filtering behaviour
1582 change_notify_reply(fsp->conn, req, max_param_count,
1586 * change_notify_reply() above has independently sent its
1593 * No changes pending, queue the request
1596 status = change_notify_add_request(req,
1600 if (!NT_STATUS_IS_OK(status)) {
1601 reply_nterror(req, status);
1606 /****************************************************************************
1607 Reply to an NT transact rename command.
1608 ****************************************************************************/
1610 static void call_nt_transact_rename(connection_struct *conn,
1611 struct smb_request *req,
1612 uint16 **ppsetup, uint32 setup_count,
1613 char **ppparams, uint32 parameter_count,
1614 char **ppdata, uint32 data_count,
1615 uint32 max_data_count)
1617 char *params = *ppparams;
1618 char *new_name = NULL;
1619 files_struct *fsp = NULL;
1620 bool dest_has_wcard = False;
1622 TALLOC_CTX *ctx = talloc_tos();
1624 if(parameter_count < 5) {
1625 reply_doserror(req, ERRDOS, ERRbadfunc);
1629 fsp = file_fsp(req, SVAL(params, 0));
1630 if (!check_fsp(conn, req, fsp)) {
1633 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1634 parameter_count - 4,
1635 STR_TERMINATE, &status, &dest_has_wcard);
1636 if (!NT_STATUS_IS_OK(status)) {
1637 reply_nterror(req, status);
1642 * W2K3 ignores this request as the RAW-RENAME test
1643 * demonstrates, so we do.
1645 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1647 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1648 fsp->fsp_name, new_name));
1653 /******************************************************************************
1654 Fake up a completely empty SD.
1655 *******************************************************************************/
1657 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1661 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1663 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1664 return NT_STATUS_NO_MEMORY;
1667 return NT_STATUS_OK;
1670 /****************************************************************************
1671 Reply to query a security descriptor.
1672 ****************************************************************************/
1674 static void call_nt_transact_query_security_desc(connection_struct *conn,
1675 struct smb_request *req,
1679 uint32 parameter_count,
1682 uint32 max_data_count)
1684 char *params = *ppparams;
1685 char *data = *ppdata;
1686 SEC_DESC *psd = NULL;
1688 uint32 security_info_wanted;
1689 files_struct *fsp = NULL;
1693 if(parameter_count < 8) {
1694 reply_doserror(req, ERRDOS, ERRbadfunc);
1698 fsp = file_fsp(req, SVAL(params,0));
1700 reply_doserror(req, ERRDOS, ERRbadfid);
1704 security_info_wanted = IVAL(params,4);
1706 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1707 (unsigned int)security_info_wanted ));
1709 params = nttrans_realloc(ppparams, 4);
1710 if(params == NULL) {
1711 reply_doserror(req, ERRDOS, ERRnomem);
1716 * Get the permissions to return.
1719 if (!lp_nt_acl_support(SNUM(conn))) {
1720 status = get_null_nt_acl(talloc_tos(), &psd);
1722 status = SMB_VFS_FGET_NT_ACL(
1723 fsp, security_info_wanted, &psd);
1725 if (!NT_STATUS_IS_OK(status)) {
1726 reply_nterror(req, status);
1730 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1731 * present in the reply to match Windows behavior */
1732 if (psd->sacl == NULL &&
1733 security_info_wanted & SACL_SECURITY_INFORMATION)
1734 psd->type |= SEC_DESC_SACL_PRESENT;
1735 if (psd->dacl == NULL &&
1736 security_info_wanted & DACL_SECURITY_INFORMATION)
1737 psd->type |= SEC_DESC_DACL_PRESENT;
1739 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1741 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1743 if (DEBUGLEVEL >= 10) {
1744 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name));
1745 NDR_PRINT_DEBUG(security_descriptor, psd);
1748 SIVAL(params,0,(uint32)sd_size);
1750 if (max_data_count < sd_size) {
1751 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1752 params, 4, *ppdata, 0);
1757 * Allocate the data we will point this at.
1760 data = nttrans_realloc(ppdata, sd_size);
1762 reply_doserror(req, ERRDOS, ERRnomem);
1766 status = marshall_sec_desc(talloc_tos(), psd,
1767 &blob.data, &blob.length);
1769 if (!NT_STATUS_IS_OK(status)) {
1770 reply_nterror(req, status);
1774 SMB_ASSERT(sd_size == blob.length);
1775 memcpy(data, blob.data, sd_size);
1777 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1782 /****************************************************************************
1783 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1784 ****************************************************************************/
1786 static void call_nt_transact_set_security_desc(connection_struct *conn,
1787 struct smb_request *req,
1791 uint32 parameter_count,
1794 uint32 max_data_count)
1796 char *params= *ppparams;
1797 char *data = *ppdata;
1798 files_struct *fsp = NULL;
1799 uint32 security_info_sent = 0;
1802 if(parameter_count < 8) {
1803 reply_doserror(req, ERRDOS, ERRbadfunc);
1807 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1808 reply_doserror(req, ERRDOS, ERRbadfid);
1812 if(!lp_nt_acl_support(SNUM(conn))) {
1816 security_info_sent = IVAL(params,4);
1818 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1819 (unsigned int)security_info_sent ));
1821 if (data_count == 0) {
1822 reply_doserror(req, ERRDOS, ERRnoaccess);
1826 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1828 if (!NT_STATUS_IS_OK(status)) {
1829 reply_nterror(req, status);
1834 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1838 /****************************************************************************
1840 ****************************************************************************/
1842 static void call_nt_transact_ioctl(connection_struct *conn,
1843 struct smb_request *req,
1844 uint16 **ppsetup, uint32 setup_count,
1845 char **ppparams, uint32 parameter_count,
1846 char **ppdata, uint32 data_count,
1847 uint32 max_data_count)
1854 char *pdata = *ppdata;
1856 if (setup_count != 8) {
1857 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1858 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1862 function = IVAL(*ppsetup, 0);
1863 fidnum = SVAL(*ppsetup, 4);
1864 isFSctl = CVAL(*ppsetup, 6);
1865 compfilter = CVAL(*ppsetup, 7);
1867 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1868 function, fidnum, isFSctl, compfilter));
1870 fsp=file_fsp(req, fidnum);
1871 /* this check is done in each implemented function case for now
1872 because I don't want to break anything... --metze
1873 FSP_BELONGS_CONN(fsp,conn);*/
1875 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1878 case FSCTL_SET_SPARSE:
1879 /* pretend this succeeded - tho strictly we should
1880 mark the file sparse (if the local fs supports it)
1881 so we can know if we need to pre-allocate or not */
1883 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1884 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1887 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1889 unsigned char objid[16];
1891 /* This should return the object-id on this file.
1892 * I think I'll make this be the inode+dev. JRA.
1895 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1897 if (!fsp_belongs_conn(conn, req, fsp)) {
1902 pdata = nttrans_realloc(ppdata, data_count);
1903 if (pdata == NULL) {
1904 reply_nterror(req, NT_STATUS_NO_MEMORY);
1908 /* For backwards compatibility only store the dev/inode. */
1909 push_file_id_16(pdata, &fsp->file_id);
1910 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1911 push_file_id_16(pdata+32, &fsp->file_id);
1912 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1917 case FSCTL_GET_REPARSE_POINT:
1918 /* pretend this fail - my winXP does it like this
1922 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1923 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1926 case FSCTL_SET_REPARSE_POINT:
1927 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1931 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1932 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1935 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1938 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1939 * and return their volume names. If max_data_count is 16, then it is just
1940 * asking for the number of volumes and length of the combined names.
1942 * pdata is the data allocated by our caller, but that uses
1943 * total_data_count (which is 0 in our case) rather than max_data_count.
1944 * Allocate the correct amount and return the pointer to let
1945 * it be deallocated when we return.
1947 SHADOW_COPY_DATA *shadow_data = NULL;
1948 TALLOC_CTX *shadow_mem_ctx = NULL;
1949 bool labels = False;
1950 uint32 labels_data_count = 0;
1954 if (!fsp_belongs_conn(conn, req, fsp)) {
1958 if (max_data_count < 16) {
1959 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1961 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1965 if (max_data_count > 16) {
1969 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1970 if (shadow_mem_ctx == NULL) {
1971 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1972 reply_nterror(req, NT_STATUS_NO_MEMORY);
1976 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
1977 if (shadow_data == NULL) {
1978 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1979 talloc_destroy(shadow_mem_ctx);
1980 reply_nterror(req, NT_STATUS_NO_MEMORY);
1984 shadow_data->mem_ctx = shadow_mem_ctx;
1987 * Call the VFS routine to actually do the work.
1989 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1990 talloc_destroy(shadow_data->mem_ctx);
1991 if (errno == ENOSYS) {
1992 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1993 conn->connectpath));
1994 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1997 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1998 conn->connectpath));
1999 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
2004 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2009 data_count = 12+labels_data_count+4;
2012 if (max_data_count<data_count) {
2013 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2014 max_data_count,data_count));
2015 talloc_destroy(shadow_data->mem_ctx);
2016 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2020 pdata = nttrans_realloc(ppdata, data_count);
2021 if (pdata == NULL) {
2022 talloc_destroy(shadow_data->mem_ctx);
2023 reply_nterror(req, NT_STATUS_NO_MEMORY);
2029 /* num_volumes 4 bytes */
2030 SIVAL(pdata,0,shadow_data->num_volumes);
2033 /* num_labels 4 bytes */
2034 SIVAL(pdata,4,shadow_data->num_volumes);
2037 /* needed_data_count 4 bytes */
2038 SIVAL(pdata,8,labels_data_count);
2042 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2043 shadow_data->num_volumes,fsp->fsp_name));
2044 if (labels && shadow_data->labels) {
2045 for (i=0;i<shadow_data->num_volumes;i++) {
2046 srvstr_push(pdata, req->flags2,
2047 cur_pdata, shadow_data->labels[i],
2048 2*sizeof(SHADOW_COPY_LABEL),
2049 STR_UNICODE|STR_TERMINATE);
2050 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2051 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2055 talloc_destroy(shadow_data->mem_ctx);
2057 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2063 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2065 /* pretend this succeeded -
2067 * we have to send back a list with all files owned by this SID
2069 * but I have to check that --metze
2073 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2075 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2077 if (!fsp_belongs_conn(conn, req, fsp)) {
2081 /* unknown 4 bytes: this is not the length of the sid :-( */
2082 /*unknown = IVAL(pdata,0);*/
2084 sid_parse(pdata+4,sid_len,&sid);
2085 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2087 if (!sid_to_uid(&sid, &uid)) {
2088 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2089 sid_string_dbg(&sid),
2090 (unsigned long)sid_len));
2094 /* we can take a look at the find source :-)
2096 * find ./ -uid $uid -name '*' is what we need here
2099 * and send 4bytes len and then NULL terminated unicode strings
2102 * but I don't know how to deal with the paged results
2103 * (maybe we can hang the result anywhere in the fsp struct)
2105 * we don't send all files at once
2106 * and at the next we should *not* start from the beginning,
2107 * so we have to cache the result
2112 /* this works for now... */
2113 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2117 if (!logged_ioctl_message) {
2118 logged_ioctl_message = true; /* Only print this once... */
2119 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2124 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2128 #ifdef HAVE_SYS_QUOTAS
2129 /****************************************************************************
2130 Reply to get user quota
2131 ****************************************************************************/
2133 static void call_nt_transact_get_user_quota(connection_struct *conn,
2134 struct smb_request *req,
2138 uint32 parameter_count,
2141 uint32 max_data_count)
2143 NTSTATUS nt_status = NT_STATUS_OK;
2144 char *params = *ppparams;
2145 char *pdata = *ppdata;
2147 int data_len=0,param_len=0;
2150 files_struct *fsp = NULL;
2154 bool start_enum = True;
2155 SMB_NTQUOTA_STRUCT qt;
2156 SMB_NTQUOTA_LIST *tmp_list;
2157 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2162 if (conn->server_info->utok.uid != 0) {
2163 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2164 "[%s]\n", lp_servicename(SNUM(conn)),
2165 conn->server_info->unix_name));
2166 reply_doserror(req, ERRDOS, ERRnoaccess);
2171 * Ensure minimum number of parameters sent.
2174 if (parameter_count < 4) {
2175 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2176 reply_doserror(req, ERRDOS, ERRinvalidparam);
2180 /* maybe we can check the quota_fnum */
2181 fsp = file_fsp(req, SVAL(params,0));
2182 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2183 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2184 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2188 /* the NULL pointer checking for fsp->fake_file_handle->pd
2189 * is done by CHECK_NTQUOTA_HANDLE_OK()
2191 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2193 level = SVAL(params,2);
2195 /* unknown 12 bytes leading in params */
2198 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2199 /* seems that we should continue with the enum here --metze */
2201 if (qt_handle->quota_list!=NULL &&
2202 qt_handle->tmp_list==NULL) {
2205 free_ntquota_list(&(qt_handle->quota_list));
2207 /* Realloc the size of parameters and data we will return */
2209 params = nttrans_realloc(ppparams, param_len);
2210 if(params == NULL) {
2211 reply_doserror(req, ERRDOS, ERRnomem);
2216 SIVAL(params,0,data_len);
2223 case TRANSACT_GET_USER_QUOTA_LIST_START:
2225 if (qt_handle->quota_list==NULL &&
2226 qt_handle->tmp_list==NULL) {
2230 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2231 reply_doserror(req, ERRSRV, ERRerror);
2235 /* Realloc the size of parameters and data we will return */
2237 params = nttrans_realloc(ppparams, param_len);
2238 if(params == NULL) {
2239 reply_doserror(req, ERRDOS, ERRnomem);
2243 /* we should not trust the value in max_data_count*/
2244 max_data_count = MIN(max_data_count,2048);
2246 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2248 reply_doserror(req, ERRDOS, ERRnomem);
2254 /* set params Size of returned Quota Data 4 bytes*/
2255 /* but set it later when we know it */
2257 /* for each entry push the data */
2260 qt_handle->tmp_list = qt_handle->quota_list;
2263 tmp_list = qt_handle->tmp_list;
2265 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2266 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2268 sid_len = ndr_size_dom_sid(
2269 &tmp_list->quotas->sid, NULL, 0);
2270 entry_len = 40 + sid_len;
2272 /* nextoffset entry 4 bytes */
2273 SIVAL(entry,0,entry_len);
2275 /* then the len of the SID 4 bytes */
2276 SIVAL(entry,4,sid_len);
2278 /* unknown data 8 bytes uint64_t */
2279 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2281 /* the used disk space 8 bytes uint64_t */
2282 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2284 /* the soft quotas 8 bytes uint64_t */
2285 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2287 /* the hard quotas 8 bytes uint64_t */
2288 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2290 /* and now the SID */
2291 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2294 qt_handle->tmp_list = tmp_list;
2296 /* overwrite the offset of the last entry */
2297 SIVAL(entry-entry_len,0,0);
2299 data_len = 4+qt_len;
2300 /* overwrite the params quota_data_len */
2301 SIVAL(params,0,data_len);
2305 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2307 /* unknown 4 bytes IVAL(pdata,0) */
2309 if (data_count < 8) {
2310 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2311 reply_doserror(req, ERRDOS, ERRunknownlevel);
2315 sid_len = IVAL(pdata,4);
2316 /* Ensure this is less than 1mb. */
2317 if (sid_len > (1024*1024)) {
2318 reply_doserror(req, ERRDOS, ERRnomem);
2322 if (data_count < 8+sid_len) {
2323 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2324 reply_doserror(req, ERRDOS, ERRunknownlevel);
2328 data_len = 4+40+sid_len;
2330 if (max_data_count < data_len) {
2331 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2332 max_data_count, data_len));
2334 SIVAL(params,0,data_len);
2336 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2340 sid_parse(pdata+8,sid_len,&sid);
2342 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2345 * we have to return zero's in all fields
2346 * instead of returning an error here
2351 /* Realloc the size of parameters and data we will return */
2353 params = nttrans_realloc(ppparams, param_len);
2354 if(params == NULL) {
2355 reply_doserror(req, ERRDOS, ERRnomem);
2359 pdata = nttrans_realloc(ppdata, data_len);
2361 reply_doserror(req, ERRDOS, ERRnomem);
2367 /* set params Size of returned Quota Data 4 bytes*/
2368 SIVAL(params,0,data_len);
2370 /* nextoffset entry 4 bytes */
2373 /* then the len of the SID 4 bytes */
2374 SIVAL(entry,4,sid_len);
2376 /* unknown data 8 bytes uint64_t */
2377 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2379 /* the used disk space 8 bytes uint64_t */
2380 SBIG_UINT(entry,16,qt.usedspace);
2382 /* the soft quotas 8 bytes uint64_t */
2383 SBIG_UINT(entry,24,qt.softlim);
2385 /* the hard quotas 8 bytes uint64_t */
2386 SBIG_UINT(entry,32,qt.hardlim);
2388 /* and now the SID */
2389 sid_linearize(entry+40, sid_len, &sid);
2394 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2395 reply_doserror(req, ERRSRV, ERRerror);
2400 send_nt_replies(conn, req, nt_status, params, param_len,
2404 /****************************************************************************
2405 Reply to set user quota
2406 ****************************************************************************/
2408 static void call_nt_transact_set_user_quota(connection_struct *conn,
2409 struct smb_request *req,
2413 uint32 parameter_count,
2416 uint32 max_data_count)
2418 char *params = *ppparams;
2419 char *pdata = *ppdata;
2420 int data_len=0,param_len=0;
2421 SMB_NTQUOTA_STRUCT qt;
2424 files_struct *fsp = NULL;
2429 if (conn->server_info->utok.uid != 0) {
2430 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2431 "[%s]\n", lp_servicename(SNUM(conn)),
2432 conn->server_info->unix_name));
2433 reply_doserror(req, ERRDOS, ERRnoaccess);
2438 * Ensure minimum number of parameters sent.
2441 if (parameter_count < 2) {
2442 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2443 reply_doserror(req, ERRDOS, ERRinvalidparam);
2447 /* maybe we can check the quota_fnum */
2448 fsp = file_fsp(req, SVAL(params,0));
2449 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2450 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2451 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2455 if (data_count < 40) {
2456 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2457 reply_doserror(req, ERRDOS, ERRunknownlevel);
2461 /* offset to next quota record.
2462 * 4 bytes IVAL(pdata,0)
2467 sid_len = IVAL(pdata,4);
2469 if (data_count < 40+sid_len) {
2470 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2471 reply_doserror(req, ERRDOS, ERRunknownlevel);
2475 /* unknown 8 bytes in pdata
2476 * maybe its the change time in NTTIME
2479 /* the used space 8 bytes (uint64_t)*/
2480 qt.usedspace = (uint64_t)IVAL(pdata,16);
2481 #ifdef LARGE_SMB_OFF_T
2482 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2483 #else /* LARGE_SMB_OFF_T */
2484 if ((IVAL(pdata,20) != 0)&&
2485 ((qt.usedspace != 0xFFFFFFFF)||
2486 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2487 /* more than 32 bits? */
2488 reply_doserror(req, ERRDOS, ERRunknownlevel);
2491 #endif /* LARGE_SMB_OFF_T */
2493 /* the soft quotas 8 bytes (uint64_t)*/
2494 qt.softlim = (uint64_t)IVAL(pdata,24);
2495 #ifdef LARGE_SMB_OFF_T
2496 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2497 #else /* LARGE_SMB_OFF_T */
2498 if ((IVAL(pdata,28) != 0)&&
2499 ((qt.softlim != 0xFFFFFFFF)||
2500 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2501 /* more than 32 bits? */
2502 reply_doserror(req, ERRDOS, ERRunknownlevel);
2505 #endif /* LARGE_SMB_OFF_T */
2507 /* the hard quotas 8 bytes (uint64_t)*/
2508 qt.hardlim = (uint64_t)IVAL(pdata,32);
2509 #ifdef LARGE_SMB_OFF_T
2510 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2511 #else /* LARGE_SMB_OFF_T */
2512 if ((IVAL(pdata,36) != 0)&&
2513 ((qt.hardlim != 0xFFFFFFFF)||
2514 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2515 /* more than 32 bits? */
2516 reply_doserror(req, ERRDOS, ERRunknownlevel);
2519 #endif /* LARGE_SMB_OFF_T */
2521 sid_parse(pdata+40,sid_len,&sid);
2522 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2524 /* 44 unknown bytes left... */
2526 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2527 reply_doserror(req, ERRSRV, ERRerror);
2531 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2534 #endif /* HAVE_SYS_QUOTAS */
2536 static void handle_nttrans(connection_struct *conn,
2537 struct trans_state *state,
2538 struct smb_request *req)
2540 if (Protocol >= PROTOCOL_NT1) {
2541 req->flags2 |= 0x40; /* IS_LONG_NAME */
2542 SSVAL(req->inbuf,smb_flg2,req->flags2);
2546 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2548 /* Now we must call the relevant NT_TRANS function */
2549 switch(state->call) {
2550 case NT_TRANSACT_CREATE:
2552 START_PROFILE(NT_transact_create);
2553 call_nt_transact_create(
2555 &state->setup, state->setup_count,
2556 &state->param, state->total_param,
2557 &state->data, state->total_data,
2558 state->max_data_return);
2559 END_PROFILE(NT_transact_create);
2563 case NT_TRANSACT_IOCTL:
2565 START_PROFILE(NT_transact_ioctl);
2566 call_nt_transact_ioctl(
2568 &state->setup, state->setup_count,
2569 &state->param, state->total_param,
2570 &state->data, state->total_data,
2571 state->max_data_return);
2572 END_PROFILE(NT_transact_ioctl);
2576 case NT_TRANSACT_SET_SECURITY_DESC:
2578 START_PROFILE(NT_transact_set_security_desc);
2579 call_nt_transact_set_security_desc(
2581 &state->setup, state->setup_count,
2582 &state->param, state->total_param,
2583 &state->data, state->total_data,
2584 state->max_data_return);
2585 END_PROFILE(NT_transact_set_security_desc);
2589 case NT_TRANSACT_NOTIFY_CHANGE:
2591 START_PROFILE(NT_transact_notify_change);
2592 call_nt_transact_notify_change(
2594 &state->setup, state->setup_count,
2595 &state->param, state->total_param,
2596 &state->data, state->total_data,
2597 state->max_data_return,
2598 state->max_param_return);
2599 END_PROFILE(NT_transact_notify_change);
2603 case NT_TRANSACT_RENAME:
2605 START_PROFILE(NT_transact_rename);
2606 call_nt_transact_rename(
2608 &state->setup, state->setup_count,
2609 &state->param, state->total_param,
2610 &state->data, state->total_data,
2611 state->max_data_return);
2612 END_PROFILE(NT_transact_rename);
2616 case NT_TRANSACT_QUERY_SECURITY_DESC:
2618 START_PROFILE(NT_transact_query_security_desc);
2619 call_nt_transact_query_security_desc(
2621 &state->setup, state->setup_count,
2622 &state->param, state->total_param,
2623 &state->data, state->total_data,
2624 state->max_data_return);
2625 END_PROFILE(NT_transact_query_security_desc);
2629 #ifdef HAVE_SYS_QUOTAS
2630 case NT_TRANSACT_GET_USER_QUOTA:
2632 START_PROFILE(NT_transact_get_user_quota);
2633 call_nt_transact_get_user_quota(
2635 &state->setup, state->setup_count,
2636 &state->param, state->total_param,
2637 &state->data, state->total_data,
2638 state->max_data_return);
2639 END_PROFILE(NT_transact_get_user_quota);
2643 case NT_TRANSACT_SET_USER_QUOTA:
2645 START_PROFILE(NT_transact_set_user_quota);
2646 call_nt_transact_set_user_quota(
2648 &state->setup, state->setup_count,
2649 &state->param, state->total_param,
2650 &state->data, state->total_data,
2651 state->max_data_return);
2652 END_PROFILE(NT_transact_set_user_quota);
2655 #endif /* HAVE_SYS_QUOTAS */
2658 /* Error in request */
2659 DEBUG(0,("handle_nttrans: Unknown request %d in "
2660 "nttrans call\n", state->call));
2661 reply_doserror(req, ERRSRV, ERRerror);
2667 /****************************************************************************
2668 Reply to a SMBNTtrans.
2669 ****************************************************************************/
2671 void reply_nttrans(struct smb_request *req)
2673 connection_struct *conn = req->conn;
2678 uint16 function_code;
2680 struct trans_state *state;
2682 START_PROFILE(SMBnttrans);
2684 if (req->wct < 19) {
2685 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2686 END_PROFILE(SMBnttrans);
2690 pscnt = IVAL(req->vwv+9, 1);
2691 psoff = IVAL(req->vwv+11, 1);
2692 dscnt = IVAL(req->vwv+13, 1);
2693 dsoff = IVAL(req->vwv+15, 1);
2694 function_code = SVAL(req->vwv+18, 0);
2696 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2697 reply_doserror(req, ERRSRV, ERRaccess);
2698 END_PROFILE(SMBnttrans);
2702 result = allow_new_trans(conn->pending_trans, req->mid);
2703 if (!NT_STATUS_IS_OK(result)) {
2704 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2705 reply_nterror(req, result);
2706 END_PROFILE(SMBnttrans);
2710 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2711 reply_doserror(req, ERRSRV, ERRaccess);
2712 END_PROFILE(SMBnttrans);
2716 state->cmd = SMBnttrans;
2718 state->mid = req->mid;
2719 state->vuid = req->vuid;
2720 state->total_data = IVAL(req->vwv+3, 1);
2722 state->total_param = IVAL(req->vwv+1, 1);
2723 state->param = NULL;
2724 state->max_data_return = IVAL(req->vwv+7, 1);
2725 state->max_param_return = IVAL(req->vwv+5, 1);
2727 /* setup count is in *words* */
2728 state->setup_count = 2*CVAL(req->vwv+17, 1);
2729 state->setup = NULL;
2730 state->call = function_code;
2732 DEBUG(10, ("num_setup=%u, "
2733 "param_total=%u, this_param=%u, max_param=%u, "
2734 "data_total=%u, this_data=%u, max_data=%u, "
2735 "param_offset=%u, data_offset=%u\n",
2736 (unsigned)state->setup_count,
2737 (unsigned)state->total_param, (unsigned)pscnt,
2738 (unsigned)state->max_param_return,
2739 (unsigned)state->total_data, (unsigned)dscnt,
2740 (unsigned)state->max_data_return,
2741 (unsigned)psoff, (unsigned)dsoff));
2744 * All nttrans messages we handle have smb_wct == 19 +
2745 * state->setup_count. Ensure this is so as a sanity check.
2748 if(req->wct != 19 + (state->setup_count/2)) {
2749 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2750 req->wct, 19 + (state->setup_count/2)));
2754 /* Don't allow more than 128mb for each value. */
2755 if ((state->total_data > (1024*1024*128)) ||
2756 (state->total_param > (1024*1024*128))) {
2757 reply_doserror(req, ERRDOS, ERRnomem);
2758 END_PROFILE(SMBnttrans);
2762 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2765 if (state->total_data) {
2767 if (trans_oob(state->total_data, 0, dscnt)
2768 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2772 /* Can't use talloc here, the core routines do realloc on the
2773 * params and data. */
2774 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2775 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2776 "bytes !\n", (unsigned int)state->total_data));
2778 reply_doserror(req, ERRDOS, ERRnomem);
2779 END_PROFILE(SMBnttrans);
2783 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2786 if (state->total_param) {
2788 if (trans_oob(state->total_param, 0, pscnt)
2789 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2793 /* Can't use talloc here, the core routines do realloc on the
2794 * params and data. */
2795 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2796 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2797 "bytes !\n", (unsigned int)state->total_param));
2798 SAFE_FREE(state->data);
2800 reply_doserror(req, ERRDOS, ERRnomem);
2801 END_PROFILE(SMBnttrans);
2805 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2808 state->received_data = dscnt;
2809 state->received_param = pscnt;
2811 if(state->setup_count > 0) {
2812 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2813 state->setup_count));
2816 * No overflow possible here, state->setup_count is an
2817 * unsigned int, being filled by a single byte from
2818 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2819 * below is not necessary, it's here to clarify things. The
2820 * validity of req->vwv and req->wct has been checked in
2821 * init_smb_request already.
2823 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2827 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2828 if (state->setup == NULL) {
2829 DEBUG(0,("reply_nttrans : Out of memory\n"));
2830 SAFE_FREE(state->data);
2831 SAFE_FREE(state->param);
2833 reply_doserror(req, ERRDOS, ERRnomem);
2834 END_PROFILE(SMBnttrans);
2838 memcpy(state->setup, req->vwv+19, state->setup_count);
2839 dump_data(10, (uint8 *)state->setup, state->setup_count);
2842 if ((state->received_data == state->total_data) &&
2843 (state->received_param == state->total_param)) {
2844 handle_nttrans(conn, state, req);
2845 SAFE_FREE(state->param);
2846 SAFE_FREE(state->data);
2848 END_PROFILE(SMBnttrans);
2852 DLIST_ADD(conn->pending_trans, state);
2854 /* We need to send an interim response then receive the rest
2855 of the parameter/data bytes */
2856 reply_outbuf(req, 0, 0);
2857 show_msg((char *)req->outbuf);
2858 END_PROFILE(SMBnttrans);
2863 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2864 SAFE_FREE(state->data);
2865 SAFE_FREE(state->param);
2867 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2868 END_PROFILE(SMBnttrans);
2872 /****************************************************************************
2873 Reply to a SMBnttranss
2874 ****************************************************************************/
2876 void reply_nttranss(struct smb_request *req)
2878 connection_struct *conn = req->conn;
2879 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2880 struct trans_state *state;
2882 START_PROFILE(SMBnttranss);
2884 show_msg((char *)req->inbuf);
2886 if (req->wct < 18) {
2887 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2888 END_PROFILE(SMBnttranss);
2892 for (state = conn->pending_trans; state != NULL;
2893 state = state->next) {
2894 if (state->mid == req->mid) {
2899 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2900 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2901 END_PROFILE(SMBnttranss);
2905 /* Revise state->total_param and state->total_data in case they have
2906 changed downwards */
2907 if (IVAL(req->vwv+1, 1) < state->total_param) {
2908 state->total_param = IVAL(req->vwv+1, 1);
2910 if (IVAL(req->vwv+3, 1) < state->total_data) {
2911 state->total_data = IVAL(req->vwv+3, 1);
2914 pcnt = IVAL(req->vwv+5, 1);
2915 poff = IVAL(req->vwv+7, 1);
2916 pdisp = IVAL(req->vwv+9, 1);
2918 dcnt = IVAL(req->vwv+11, 1);
2919 doff = IVAL(req->vwv+13, 1);
2920 ddisp = IVAL(req->vwv+15, 1);
2922 state->received_param += pcnt;
2923 state->received_data += dcnt;
2925 if ((state->received_data > state->total_data) ||
2926 (state->received_param > state->total_param))
2930 if (trans_oob(state->total_param, pdisp, pcnt)
2931 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2934 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2938 if (trans_oob(state->total_data, ddisp, dcnt)
2939 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2942 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2945 if ((state->received_param < state->total_param) ||
2946 (state->received_data < state->total_data)) {
2947 END_PROFILE(SMBnttranss);
2951 handle_nttrans(conn, state, req);
2953 DLIST_REMOVE(conn->pending_trans, state);
2954 SAFE_FREE(state->data);
2955 SAFE_FREE(state->param);
2957 END_PROFILE(SMBnttranss);
2962 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2963 DLIST_REMOVE(conn->pending_trans, state);
2964 SAFE_FREE(state->data);
2965 SAFE_FREE(state->param);
2967 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2968 END_PROFILE(SMBnttranss);