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;
63 * If there genuinely are no parameters or data to send just send
67 if(params_to_send == 0 && data_to_send == 0) {
68 reply_outbuf(req, 18, 0);
69 show_msg((char *)req->outbuf);
74 * When sending params and data ensure that both are nicely aligned.
75 * Only do this alignment when there is also data to send - else
76 * can cause NT redirector problems.
79 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
80 data_alignment_offset = 4 - (params_to_send % 4);
84 * Space is bufsize minus Netbios over TCP header minus SMB header.
85 * The alignment_offset is to align the param bytes on a four byte
86 * boundary (2 bytes for data len, one byte pad).
87 * NT needs this to work correctly.
90 useable_space = max_send - (smb_size
93 + data_alignment_offset);
95 if (useable_space < 0) {
96 char *msg = talloc_asprintf(
98 "send_nt_replies failed sanity useable_space = %d!!!",
100 DEBUG(0, ("%s\n", msg));
101 exit_server_cleanly(msg);
104 while (params_to_send || data_to_send) {
107 * Calculate whether we will totally or partially fill this packet.
110 total_sent_thistime = params_to_send + data_to_send;
113 * We can never send more than useable_space.
116 total_sent_thistime = MIN(total_sent_thistime, useable_space);
118 reply_outbuf(req, 18,
119 total_sent_thistime + alignment_offset
120 + data_alignment_offset);
123 * We might have had SMBnttranss in req->inbuf, fix that.
125 SCVAL(req->outbuf, smb_com, SMBnttrans);
128 * Set total params and data to be sent.
131 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
132 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
135 * Calculate how many parameters and data we can fit into
136 * this packet. Parameters get precedence.
139 params_sent_thistime = MIN(params_to_send,useable_space);
140 data_sent_thistime = useable_space - params_sent_thistime;
141 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
143 SIVAL(req->outbuf, smb_ntr_ParameterCount,
144 params_sent_thistime);
146 if(params_sent_thistime == 0) {
147 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
148 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
151 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
152 * parameter bytes, however the first 4 bytes of outbuf are
153 * the Netbios over TCP header. Thus use smb_base() to subtract
154 * them from the calculation.
157 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
158 ((smb_buf(req->outbuf)+alignment_offset)
159 - smb_base(req->outbuf)));
161 * Absolute displacement of param bytes sent in this packet.
164 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
169 * Deal with the data portion.
172 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
174 if(data_sent_thistime == 0) {
175 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
176 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
179 * The offset of the data bytes is the offset of the
180 * parameter bytes plus the number of parameters being sent this time.
183 SIVAL(req->outbuf, smb_ntr_DataOffset,
184 ((smb_buf(req->outbuf)+alignment_offset) -
185 smb_base(req->outbuf))
186 + params_sent_thistime + data_alignment_offset);
187 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
191 * Copy the param bytes into the packet.
194 if(params_sent_thistime) {
195 if (alignment_offset != 0) {
196 memset(smb_buf(req->outbuf), 0,
199 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
200 params_sent_thistime);
204 * Copy in the data bytes
207 if(data_sent_thistime) {
208 if (data_alignment_offset != 0) {
209 memset((smb_buf(req->outbuf)+alignment_offset+
210 params_sent_thistime), 0,
211 data_alignment_offset);
213 memcpy(smb_buf(req->outbuf)+alignment_offset
214 +params_sent_thistime+data_alignment_offset,
215 pd,data_sent_thistime);
218 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
219 params_sent_thistime, data_sent_thistime, useable_space));
220 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
221 params_to_send, data_to_send, paramsize, datasize));
223 if (NT_STATUS_V(nt_error)) {
224 error_packet_set((char *)req->outbuf,
229 /* Send the packet */
230 show_msg((char *)req->outbuf);
231 if (!srv_send_smb(smbd_server_fd(),
234 IS_CONN_ENCRYPTED(conn),
236 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
239 TALLOC_FREE(req->outbuf);
241 pp += params_sent_thistime;
242 pd += data_sent_thistime;
244 params_to_send -= params_sent_thistime;
245 data_to_send -= data_sent_thistime;
251 if(params_to_send < 0 || data_to_send < 0) {
252 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
253 params_to_send, data_to_send));
254 exit_server_cleanly("send_nt_replies: internal error");
259 /****************************************************************************
260 Is it an NTFS stream name ?
261 An NTFS file name is <path>.<extention>:<stream name>:<stream type>
262 $DATA can be used as both a stream name and a stream type. A missing stream
263 name or type implies $DATA.
265 Both Windows stream names and POSIX files can contain the ':' character.
266 This function first checks for the existence of a colon in the last component
267 of the given name. If the name contains a colon we differentiate between a
268 stream and POSIX file by checking if the latter exists through a POSIX stat.
270 Function assumes we've already chdir() to the "root" directory of fname.
271 ****************************************************************************/
273 bool is_ntfs_stream_name(const char *fname)
275 const char *lastcomp;
276 SMB_STRUCT_STAT sbuf;
278 /* If all pathnames are treated as POSIX we ignore streams. */
279 if (lp_posix_pathnames()) {
283 /* Find the last component of the name. */
284 if ((lastcomp = strrchr_m(fname, '/')) != NULL)
289 /* If there is no colon in the last component, it's not a stream. */
290 if (strchr_m(lastcomp, ':') == NULL)
294 * If file already exists on disk, it's not a stream. The stat must
295 * bypass the vfs layer so streams modules don't intefere.
297 if (sys_stat(fname, &sbuf) == 0) {
298 DEBUG(5, ("is_ntfs_stream_name: file %s contains a ':' but is "
299 "not a stream\n", fname));
306 /****************************************************************************
307 Reply to an NT create and X call on a pipe
308 ****************************************************************************/
310 static void nt_open_pipe(char *fname, connection_struct *conn,
311 struct smb_request *req, int *ppnum)
316 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
318 /* Strip \\ off the name. */
321 status = open_np_file(req, fname, &fsp);
322 if (!NT_STATUS_IS_OK(status)) {
323 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
324 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
328 reply_nterror(req, status);
336 /****************************************************************************
337 Reply to an NT create and X call for pipes.
338 ****************************************************************************/
340 static void do_ntcreate_pipe_open(connection_struct *conn,
341 struct smb_request *req)
346 uint32 flags = IVAL(req->vwv+3, 1);
347 TALLOC_CTX *ctx = talloc_tos();
349 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
352 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
356 nt_open_pipe(fname, conn, req, &pnum);
364 * Deal with pipe return.
367 if (flags & EXTENDED_RESPONSE_REQUIRED) {
368 /* This is very strange. We
369 * return 50 words, but only set
370 * the wcnt to 42 ? It's definately
371 * what happens on the wire....
373 reply_outbuf(req, 50, 0);
374 SCVAL(req->outbuf,smb_wct,42);
376 reply_outbuf(req, 34, 0);
379 p = (char *)req->outbuf + smb_vwv2;
383 SIVAL(p,0,FILE_WAS_OPENED);
386 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
389 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
391 SSVAL(p,2, 0x5FF); /* ? */
394 if (flags & EXTENDED_RESPONSE_REQUIRED) {
396 SIVAL(p,0,FILE_GENERIC_ALL);
398 * For pipes W2K3 seems to return
400 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
402 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
405 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
410 /****************************************************************************
411 Reply to an NT create and X call.
412 ****************************************************************************/
414 void reply_ntcreate_and_X(struct smb_request *req)
416 connection_struct *conn = req->conn;
420 uint32 file_attributes;
422 uint32 create_disposition;
423 uint32 create_options;
425 uint64_t allocation_size;
426 /* Breakout the oplock request bits so we can set the
427 reply bits separately. */
429 SMB_OFF_T file_len = 0;
430 SMB_STRUCT_STAT sbuf;
432 files_struct *fsp = NULL;
434 struct timespec c_timespec;
435 struct timespec a_timespec;
436 struct timespec m_timespec;
439 uint8_t oplock_granted = NO_OPLOCK_RETURN;
440 TALLOC_CTX *ctx = talloc_tos();
442 START_PROFILE(SMBntcreateX);
444 SET_STAT_INVALID(sbuf);
447 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
451 flags = IVAL(req->vwv+3, 1);
452 access_mask = IVAL(req->vwv+7, 1);
453 file_attributes = IVAL(req->vwv+13, 1);
454 share_access = IVAL(req->vwv+15, 1);
455 create_disposition = IVAL(req->vwv+17, 1);
456 create_options = IVAL(req->vwv+19, 1);
457 root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
459 allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
460 #ifdef LARGE_SMB_OFF_T
461 allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
464 srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
465 STR_TERMINATE, &status);
467 if (!NT_STATUS_IS_OK(status)) {
468 reply_nterror(req, status);
469 END_PROFILE(SMBntcreateX);
473 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
474 "file_attributes = 0x%x, share_access = 0x%x, "
475 "create_disposition = 0x%x create_options = 0x%x "
476 "root_dir_fid = 0x%x, fname = %s\n",
478 (unsigned int)access_mask,
479 (unsigned int)file_attributes,
480 (unsigned int)share_access,
481 (unsigned int)create_disposition,
482 (unsigned int)create_options,
483 (unsigned int)root_dir_fid,
487 * we need to remove ignored bits when they come directly from the client
488 * because we reuse some of them for internal stuff
490 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
493 * If it's an IPC, use the pipe handler.
497 if (lp_nt_pipe_support()) {
498 do_ntcreate_pipe_open(conn, req);
499 END_PROFILE(SMBntcreateX);
502 reply_doserror(req, ERRDOS, ERRnoaccess);
503 END_PROFILE(SMBntcreateX);
507 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
508 if (oplock_request) {
509 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
513 status = SMB_VFS_CREATE_FILE(
516 root_dir_fid, /* root_dir_fid */
518 CFF_DOS_PATH, /* create_file_flags */
519 access_mask, /* access_mask */
520 share_access, /* share_access */
521 create_disposition, /* create_disposition*/
522 create_options, /* create_options */
523 file_attributes, /* file_attributes */
524 oplock_request, /* oplock_request */
525 allocation_size, /* allocation_size */
532 if (!NT_STATUS_IS_OK(status)) {
533 if (open_was_deferred(req->mid)) {
534 /* We have re-scheduled this call, no error. */
535 END_PROFILE(SMBntcreateX);
538 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
539 reply_botherror(req, status, ERRDOS, ERRfilexists);
542 reply_nterror(req, status);
544 END_PROFILE(SMBntcreateX);
549 * If the caller set the extended oplock request bit
550 * and we granted one (by whatever means) - set the
551 * correct bit for extended oplock reply.
554 if (oplock_request &&
555 (lp_fake_oplocks(SNUM(conn))
556 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
559 * Exclusive oplock granted
562 if (flags & REQUEST_BATCH_OPLOCK) {
563 oplock_granted = BATCH_OPLOCK_RETURN;
565 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
567 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
568 oplock_granted = LEVEL_II_OPLOCK_RETURN;
570 oplock_granted = NO_OPLOCK_RETURN;
573 file_len = sbuf.st_size;
574 fattr = dos_mode(conn,fsp->fsp_name,&sbuf);
576 fattr = FILE_ATTRIBUTE_NORMAL;
579 if (flags & EXTENDED_RESPONSE_REQUIRED) {
580 /* This is very strange. We
581 * return 50 words, but only set
582 * the wcnt to 42 ? It's definately
583 * what happens on the wire....
585 reply_outbuf(req, 50, 0);
586 SCVAL(req->outbuf,smb_wct,42);
588 reply_outbuf(req, 34, 0);
591 p = (char *)req->outbuf + smb_vwv2;
593 SCVAL(p, 0, oplock_granted);
596 SSVAL(p,0,fsp->fnum);
598 if ((create_disposition == FILE_SUPERSEDE)
599 && (info == FILE_WAS_OVERWRITTEN)) {
600 SIVAL(p,0,FILE_WAS_SUPERSEDED);
607 c_timespec = get_create_timespec(
608 &sbuf,lp_fake_dir_create_times(SNUM(conn)));
609 a_timespec = get_atimespec(&sbuf);
610 m_timespec = get_mtimespec(&sbuf);
612 if (lp_dos_filetime_resolution(SNUM(conn))) {
613 dos_filetime_timespec(&c_timespec);
614 dos_filetime_timespec(&a_timespec);
615 dos_filetime_timespec(&m_timespec);
618 put_long_date_timespec(p, c_timespec); /* create time. */
620 put_long_date_timespec(p, a_timespec); /* access time */
622 put_long_date_timespec(p, m_timespec); /* write time */
624 put_long_date_timespec(p, m_timespec); /* change time */
626 SIVAL(p,0,fattr); /* File Attributes. */
628 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf));
630 SOFF_T(p,0,file_len);
632 if (flags & EXTENDED_RESPONSE_REQUIRED) {
636 SCVAL(p,0,fsp->is_directory ? 1 : 0);
638 if (flags & EXTENDED_RESPONSE_REQUIRED) {
641 if (fsp->is_directory
642 || can_write_to_file(conn, fsp->fsp_name, &sbuf)) {
643 perms = FILE_GENERIC_ALL;
645 perms = FILE_GENERIC_READ|FILE_EXECUTE;
650 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
651 fsp->fnum, fsp->fsp_name));
654 END_PROFILE(SMBntcreateX);
658 /****************************************************************************
659 Reply to a NT_TRANSACT_CREATE call to open a pipe.
660 ****************************************************************************/
662 static void do_nt_transact_create_pipe(connection_struct *conn,
663 struct smb_request *req,
664 uint16 **ppsetup, uint32 setup_count,
665 char **ppparams, uint32 parameter_count,
666 char **ppdata, uint32 data_count)
669 char *params = *ppparams;
675 TALLOC_CTX *ctx = talloc_tos();
678 * Ensure minimum number of parameters sent.
681 if(parameter_count < 54) {
682 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
683 reply_doserror(req, ERRDOS, ERRnoaccess);
687 flags = IVAL(params,0);
689 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
690 parameter_count-53, STR_TERMINATE,
692 if (!NT_STATUS_IS_OK(status)) {
693 reply_nterror(req, status);
697 nt_open_pipe(fname, conn, req, &pnum);
704 /* Realloc the size of parameters and data we will return */
705 if (flags & EXTENDED_RESPONSE_REQUIRED) {
706 /* Extended response is 32 more byyes. */
711 params = nttrans_realloc(ppparams, param_len);
713 reply_doserror(req, ERRDOS, ERRnomem);
718 SCVAL(p,0,NO_OPLOCK_RETURN);
723 SIVAL(p,0,FILE_WAS_OPENED);
727 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
730 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
732 SSVAL(p,2, 0x5FF); /* ? */
735 if (flags & EXTENDED_RESPONSE_REQUIRED) {
737 SIVAL(p,0,FILE_GENERIC_ALL);
739 * For pipes W2K3 seems to return
741 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
743 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
746 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
748 /* Send the required number of replies */
749 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
754 /****************************************************************************
755 Internal fn to set security descriptors.
756 ****************************************************************************/
758 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
759 uint32 security_info_sent)
761 SEC_DESC *psd = NULL;
764 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
768 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
770 if (!NT_STATUS_IS_OK(status)) {
774 if (psd->owner_sid == NULL) {
775 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
777 if (psd->group_sid == NULL) {
778 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
781 /* Convert all the generic bits. */
782 security_acl_map_generic(psd->dacl, &file_generic_mapping);
783 security_acl_map_generic(psd->sacl, &file_generic_mapping);
785 if (DEBUGLEVEL >= 10) {
786 DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
787 NDR_PRINT_DEBUG(security_descriptor, psd);
790 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
797 /****************************************************************************
798 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
799 ****************************************************************************/
801 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
803 struct ea_list *ea_list_head = NULL;
810 while (offset + 4 <= data_size) {
811 size_t next_offset = IVAL(pdata,offset);
812 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
818 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
819 if (next_offset == 0) {
822 offset += next_offset;
828 /****************************************************************************
829 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
830 ****************************************************************************/
832 static void call_nt_transact_create(connection_struct *conn,
833 struct smb_request *req,
834 uint16 **ppsetup, uint32 setup_count,
835 char **ppparams, uint32 parameter_count,
836 char **ppdata, uint32 data_count,
837 uint32 max_data_count)
840 char *params = *ppparams;
841 char *data = *ppdata;
842 /* Breakout the oplock request bits so we can set the reply bits separately. */
844 SMB_OFF_T file_len = 0;
845 SMB_STRUCT_STAT sbuf;
847 files_struct *fsp = NULL;
851 uint32 file_attributes;
853 uint32 create_disposition;
854 uint32 create_options;
856 struct security_descriptor *sd = NULL;
859 struct timespec c_timespec;
860 struct timespec a_timespec;
861 struct timespec m_timespec;
862 struct ea_list *ea_list = NULL;
865 uint64_t allocation_size;
867 uint8_t oplock_granted;
868 TALLOC_CTX *ctx = talloc_tos();
870 SET_STAT_INVALID(sbuf);
872 DEBUG(5,("call_nt_transact_create\n"));
875 * If it's an IPC, use the pipe handler.
879 if (lp_nt_pipe_support()) {
880 do_nt_transact_create_pipe(
882 ppsetup, setup_count,
883 ppparams, parameter_count,
887 reply_doserror(req, ERRDOS, ERRnoaccess);
892 * Ensure minimum number of parameters sent.
895 if(parameter_count < 54) {
896 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
897 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
901 flags = IVAL(params,0);
902 access_mask = IVAL(params,8);
903 file_attributes = IVAL(params,20);
904 share_access = IVAL(params,24);
905 create_disposition = IVAL(params,28);
906 create_options = IVAL(params,32);
907 sd_len = IVAL(params,36);
908 ea_len = IVAL(params,40);
909 root_dir_fid = (uint16)IVAL(params,4);
910 allocation_size = (uint64_t)IVAL(params,12);
911 #ifdef LARGE_SMB_OFF_T
912 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
916 * we need to remove ignored bits when they come directly from the client
917 * because we reuse some of them for internal stuff
919 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
921 /* Ensure the data_len is correct for the sd and ea values given. */
922 if ((ea_len + sd_len > data_count)
923 || (ea_len > data_count) || (sd_len > data_count)
924 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
925 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
926 "%u, data_count = %u\n", (unsigned int)ea_len,
927 (unsigned int)sd_len, (unsigned int)data_count));
928 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
933 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
936 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
938 if (!NT_STATUS_IS_OK(status)) {
939 DEBUG(10, ("call_nt_transact_create: "
940 "unmarshall_sec_desc failed: %s\n",
942 reply_nterror(req, status);
948 if (!lp_ea_support(SNUM(conn))) {
949 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
950 "EA's not supported.\n",
951 (unsigned int)ea_len));
952 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
957 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
958 "too small (should be more than 10)\n",
959 (unsigned int)ea_len ));
960 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
964 /* We have already checked that ea_len <= data_count here. */
965 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
967 if (ea_list == NULL) {
968 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
973 srvstr_get_path(ctx, params, req->flags2, &fname,
974 params+53, parameter_count-53,
975 STR_TERMINATE, &status);
976 if (!NT_STATUS_IS_OK(status)) {
977 reply_nterror(req, status);
981 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
982 if (oplock_request) {
983 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
987 status = SMB_VFS_CREATE_FILE(
990 root_dir_fid, /* root_dir_fid */
992 CFF_DOS_PATH, /* create_file_flags */
993 access_mask, /* access_mask */
994 share_access, /* share_access */
995 create_disposition, /* create_disposition*/
996 create_options, /* create_options */
997 file_attributes, /* file_attributes */
998 oplock_request, /* oplock_request */
999 allocation_size, /* allocation_size */
1001 ea_list, /* ea_list */
1006 if(!NT_STATUS_IS_OK(status)) {
1007 if (open_was_deferred(req->mid)) {
1008 /* We have re-scheduled this call, no error. */
1011 reply_openerror(req, status);
1016 * If the caller set the extended oplock request bit
1017 * and we granted one (by whatever means) - set the
1018 * correct bit for extended oplock reply.
1021 if (oplock_request &&
1022 (lp_fake_oplocks(SNUM(conn))
1023 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1026 * Exclusive oplock granted
1029 if (flags & REQUEST_BATCH_OPLOCK) {
1030 oplock_granted = BATCH_OPLOCK_RETURN;
1032 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1034 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1035 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1037 oplock_granted = NO_OPLOCK_RETURN;
1040 file_len = sbuf.st_size;
1041 fattr = dos_mode(conn,fsp->fsp_name,&sbuf);
1043 fattr = FILE_ATTRIBUTE_NORMAL;
1046 /* Realloc the size of parameters and data we will return */
1047 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1048 /* Extended response is 32 more byyes. */
1053 params = nttrans_realloc(ppparams, param_len);
1054 if(params == NULL) {
1055 reply_doserror(req, ERRDOS, ERRnomem);
1060 SCVAL(p, 0, oplock_granted);
1063 SSVAL(p,0,fsp->fnum);
1065 if ((create_disposition == FILE_SUPERSEDE)
1066 && (info == FILE_WAS_OVERWRITTEN)) {
1067 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1074 c_timespec = get_create_timespec(
1075 &sbuf,lp_fake_dir_create_times(SNUM(conn)));
1076 a_timespec = get_atimespec(&sbuf);
1077 m_timespec = get_mtimespec(&sbuf);
1079 if (lp_dos_filetime_resolution(SNUM(conn))) {
1080 dos_filetime_timespec(&c_timespec);
1081 dos_filetime_timespec(&a_timespec);
1082 dos_filetime_timespec(&m_timespec);
1085 put_long_date_timespec(p, c_timespec); /* create time. */
1087 put_long_date_timespec(p, a_timespec); /* access time */
1089 put_long_date_timespec(p, m_timespec); /* write time */
1091 put_long_date_timespec(p, m_timespec); /* change time */
1093 SIVAL(p,0,fattr); /* File Attributes. */
1095 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&sbuf));
1097 SOFF_T(p,0,file_len);
1099 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1103 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1105 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1108 if (fsp->is_directory
1109 || can_write_to_file(conn, fsp->fsp_name, &sbuf)) {
1110 perms = FILE_GENERIC_ALL;
1112 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1117 DEBUG(5,("call_nt_transact_create: open name = %s\n", fsp->fsp_name));
1119 /* Send the required number of replies */
1120 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1125 /****************************************************************************
1126 Reply to a NT CANCEL request.
1127 conn POINTER CAN BE NULL HERE !
1128 ****************************************************************************/
1130 void reply_ntcancel(struct smb_request *req)
1133 * Go through and cancel any pending change notifies.
1136 START_PROFILE(SMBntcancel);
1137 srv_cancel_sign_response(smbd_server_conn);
1138 remove_pending_change_notify_requests_by_mid(req->mid);
1139 remove_pending_lock_requests_by_mid(req->mid);
1141 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1143 END_PROFILE(SMBntcancel);
1147 /****************************************************************************
1149 ****************************************************************************/
1151 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1152 connection_struct *conn,
1153 struct smb_request *req,
1154 const char *oldname_in,
1155 const char *newname_in,
1158 SMB_STRUCT_STAT sbuf1, sbuf2;
1159 char *oldname = NULL;
1160 char *newname = NULL;
1161 char *last_component_oldname = NULL;
1162 char *last_component_newname = NULL;
1163 files_struct *fsp1,*fsp2;
1167 NTSTATUS status = NT_STATUS_OK;
1173 if (!CAN_WRITE(conn)) {
1174 return NT_STATUS_MEDIA_WRITE_PROTECTED;
1177 status = unix_convert(ctx, conn, oldname_in, False, &oldname,
1178 &last_component_oldname, &sbuf1);
1179 if (!NT_STATUS_IS_OK(status)) {
1183 status = check_name(conn, oldname);
1184 if (!NT_STATUS_IS_OK(status)) {
1188 /* Source must already exist. */
1189 if (!VALID_STAT(sbuf1)) {
1190 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1192 /* Ensure attributes match. */
1193 fattr = dos_mode(conn,oldname,&sbuf1);
1194 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1195 return NT_STATUS_NO_SUCH_FILE;
1198 status = unix_convert(ctx, conn, newname_in, False, &newname,
1199 &last_component_newname, &sbuf2);
1200 if (!NT_STATUS_IS_OK(status)) {
1204 status = check_name(conn, newname);
1205 if (!NT_STATUS_IS_OK(status)) {
1209 /* Disallow if newname already exists. */
1210 if (VALID_STAT(sbuf2)) {
1211 return NT_STATUS_OBJECT_NAME_COLLISION;
1214 /* No links from a directory. */
1215 if (S_ISDIR(sbuf1.st_mode)) {
1216 return NT_STATUS_FILE_IS_A_DIRECTORY;
1219 /* Ensure this is within the share. */
1220 status = check_reduced_name(conn, oldname);
1221 if (!NT_STATUS_IS_OK(status)) {
1225 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1228 status = SMB_VFS_CREATE_FILE(
1231 0, /* root_dir_fid */
1232 oldname, /* fname */
1233 0, /* create_file_flags */
1234 FILE_READ_DATA, /* access_mask */
1235 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1237 FILE_OPEN, /* create_disposition*/
1238 0, /* create_options */
1239 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1240 NO_OPLOCK, /* oplock_request */
1241 0, /* allocation_size */
1246 &sbuf1); /* psbuf */
1248 if (!NT_STATUS_IS_OK(status)) {
1252 status = SMB_VFS_CREATE_FILE(
1255 0, /* root_dir_fid */
1256 newname, /* fname */
1257 0, /* create_file_flags */
1258 FILE_WRITE_DATA, /* access_mask */
1259 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1261 FILE_CREATE, /* create_disposition*/
1262 0, /* create_options */
1263 fattr, /* file_attributes */
1264 NO_OPLOCK, /* oplock_request */
1265 0, /* allocation_size */
1270 &sbuf2); /* psbuf */
1272 if (!NT_STATUS_IS_OK(status)) {
1273 close_file(NULL, fsp1, ERROR_CLOSE);
1277 if (sbuf1.st_size) {
1278 ret = vfs_transfer_file(fsp1, fsp2, sbuf1.st_size);
1282 * As we are opening fsp1 read-only we only expect
1283 * an error on close on fsp2 if we are out of space.
1284 * Thus we don't look at the error return from the
1287 close_file(NULL, fsp1, NORMAL_CLOSE);
1289 /* Ensure the modtime is set correctly on the destination file. */
1290 set_close_write_time(fsp2, get_mtimespec(&sbuf1));
1292 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1294 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1295 creates the file. This isn't the correct thing to do in the copy
1297 if (!parent_dirname(talloc_tos(), newname, &parent, NULL)) {
1298 return NT_STATUS_NO_MEMORY;
1300 file_set_dosmode(conn, newname, fattr, &sbuf2, parent, false);
1301 TALLOC_FREE(parent);
1303 if (ret < (SMB_OFF_T)sbuf1.st_size) {
1304 return NT_STATUS_DISK_FULL;
1307 if (!NT_STATUS_IS_OK(status)) {
1308 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1309 nt_errstr(status), oldname, newname));
1314 /****************************************************************************
1315 Reply to a NT rename request.
1316 ****************************************************************************/
1318 void reply_ntrename(struct smb_request *req)
1320 connection_struct *conn = req->conn;
1321 char *oldname = NULL;
1322 char *newname = NULL;
1325 bool src_has_wcard = False;
1326 bool dest_has_wcard = False;
1329 TALLOC_CTX *ctx = talloc_tos();
1331 START_PROFILE(SMBntrename);
1334 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1335 END_PROFILE(SMBntrename);
1339 attrs = SVAL(req->vwv+0, 0);
1340 rename_type = SVAL(req->vwv+1, 0);
1342 p = (const char *)req->buf + 1;
1343 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1344 &status, &src_has_wcard);
1345 if (!NT_STATUS_IS_OK(status)) {
1346 reply_nterror(req, status);
1347 END_PROFILE(SMBntrename);
1351 if (ms_has_wild(oldname)) {
1352 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1353 END_PROFILE(SMBntrename);
1358 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1359 &status, &dest_has_wcard);
1360 if (!NT_STATUS_IS_OK(status)) {
1361 reply_nterror(req, status);
1362 END_PROFILE(SMBntrename);
1366 status = resolve_dfspath(ctx, conn,
1367 req->flags2 & FLAGS2_DFS_PATHNAMES,
1370 if (!NT_STATUS_IS_OK(status)) {
1371 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1372 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1373 ERRSRV, ERRbadpath);
1374 END_PROFILE(SMBntrename);
1377 reply_nterror(req, status);
1378 END_PROFILE(SMBntrename);
1382 status = resolve_dfspath(ctx, conn,
1383 req->flags2 & FLAGS2_DFS_PATHNAMES,
1386 if (!NT_STATUS_IS_OK(status)) {
1387 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1388 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1389 ERRSRV, ERRbadpath);
1390 END_PROFILE(SMBntrename);
1393 reply_nterror(req, status);
1394 END_PROFILE(SMBntrename);
1398 /* The new name must begin with a ':' if the old name is a stream. */
1399 if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
1400 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1401 END_PROFILE(SMBntrename);
1405 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1407 switch(rename_type) {
1408 case RENAME_FLAG_RENAME:
1409 status = rename_internals(ctx, conn, req, oldname,
1410 newname, attrs, False, src_has_wcard,
1411 dest_has_wcard, DELETE_ACCESS);
1413 case RENAME_FLAG_HARD_LINK:
1414 if (src_has_wcard || dest_has_wcard) {
1416 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1418 status = hardlink_internals(ctx,
1424 case RENAME_FLAG_COPY:
1425 if (src_has_wcard || dest_has_wcard) {
1427 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1429 status = copy_internals(ctx, conn, req, oldname,
1433 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1434 status = NT_STATUS_INVALID_PARAMETER;
1437 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1441 if (!NT_STATUS_IS_OK(status)) {
1442 if (open_was_deferred(req->mid)) {
1443 /* We have re-scheduled this call. */
1444 END_PROFILE(SMBntrename);
1448 reply_nterror(req, status);
1449 END_PROFILE(SMBntrename);
1453 reply_outbuf(req, 0, 0);
1455 END_PROFILE(SMBntrename);
1459 /****************************************************************************
1460 Reply to a notify change - queue the request and
1461 don't allow a directory to be opened.
1462 ****************************************************************************/
1464 static void call_nt_transact_notify_change(connection_struct *conn,
1465 struct smb_request *req,
1469 uint32 parameter_count,
1470 char **ppdata, uint32 data_count,
1471 uint32 max_data_count,
1472 uint32 max_param_count)
1474 uint16 *setup = *ppsetup;
1480 if(setup_count < 6) {
1481 reply_doserror(req, ERRDOS, ERRbadfunc);
1485 fsp = file_fsp(req, SVAL(setup,4));
1486 filter = IVAL(setup, 0);
1487 recursive = (SVAL(setup, 6) != 0) ? True : False;
1489 DEBUG(3,("call_nt_transact_notify_change\n"));
1492 reply_doserror(req, ERRDOS, ERRbadfid);
1497 char *filter_string;
1499 if (!(filter_string = notify_filter_string(NULL, filter))) {
1500 reply_nterror(req,NT_STATUS_NO_MEMORY);
1504 DEBUG(3,("call_nt_transact_notify_change: notify change "
1505 "called on %s, filter = %s, recursive = %d\n",
1506 fsp->fsp_name, filter_string, recursive));
1508 TALLOC_FREE(filter_string);
1511 if((!fsp->is_directory) || (conn != fsp->conn)) {
1512 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1516 if (fsp->notify == NULL) {
1518 status = change_notify_create(fsp, filter, recursive);
1520 if (!NT_STATUS_IS_OK(status)) {
1521 DEBUG(10, ("change_notify_create returned %s\n",
1522 nt_errstr(status)));
1523 reply_nterror(req, status);
1528 if (fsp->notify->num_changes != 0) {
1531 * We've got changes pending, respond immediately
1535 * TODO: write a torture test to check the filtering behaviour
1539 change_notify_reply(fsp->conn, req, max_param_count,
1543 * change_notify_reply() above has independently sent its
1550 * No changes pending, queue the request
1553 status = change_notify_add_request(req,
1557 if (!NT_STATUS_IS_OK(status)) {
1558 reply_nterror(req, status);
1563 /****************************************************************************
1564 Reply to an NT transact rename command.
1565 ****************************************************************************/
1567 static void call_nt_transact_rename(connection_struct *conn,
1568 struct smb_request *req,
1569 uint16 **ppsetup, uint32 setup_count,
1570 char **ppparams, uint32 parameter_count,
1571 char **ppdata, uint32 data_count,
1572 uint32 max_data_count)
1574 char *params = *ppparams;
1575 char *new_name = NULL;
1576 files_struct *fsp = NULL;
1577 bool dest_has_wcard = False;
1579 TALLOC_CTX *ctx = talloc_tos();
1581 if(parameter_count < 5) {
1582 reply_doserror(req, ERRDOS, ERRbadfunc);
1586 fsp = file_fsp(req, SVAL(params, 0));
1587 if (!check_fsp(conn, req, fsp)) {
1590 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1591 parameter_count - 4,
1592 STR_TERMINATE, &status, &dest_has_wcard);
1593 if (!NT_STATUS_IS_OK(status)) {
1594 reply_nterror(req, status);
1599 * W2K3 ignores this request as the RAW-RENAME test
1600 * demonstrates, so we do.
1602 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1604 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1605 fsp->fsp_name, new_name));
1610 /******************************************************************************
1611 Fake up a completely empty SD.
1612 *******************************************************************************/
1614 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1618 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1620 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1621 return NT_STATUS_NO_MEMORY;
1624 return NT_STATUS_OK;
1627 /****************************************************************************
1628 Reply to query a security descriptor.
1629 ****************************************************************************/
1631 static void call_nt_transact_query_security_desc(connection_struct *conn,
1632 struct smb_request *req,
1636 uint32 parameter_count,
1639 uint32 max_data_count)
1641 char *params = *ppparams;
1642 char *data = *ppdata;
1643 SEC_DESC *psd = NULL;
1645 uint32 security_info_wanted;
1646 files_struct *fsp = NULL;
1650 if(parameter_count < 8) {
1651 reply_doserror(req, ERRDOS, ERRbadfunc);
1655 fsp = file_fsp(req, SVAL(params,0));
1657 reply_doserror(req, ERRDOS, ERRbadfid);
1661 security_info_wanted = IVAL(params,4);
1663 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1664 (unsigned int)security_info_wanted ));
1666 params = nttrans_realloc(ppparams, 4);
1667 if(params == NULL) {
1668 reply_doserror(req, ERRDOS, ERRnomem);
1673 * Get the permissions to return.
1676 if (!lp_nt_acl_support(SNUM(conn))) {
1677 status = get_null_nt_acl(talloc_tos(), &psd);
1679 status = SMB_VFS_FGET_NT_ACL(
1680 fsp, security_info_wanted, &psd);
1682 if (!NT_STATUS_IS_OK(status)) {
1683 reply_nterror(req, status);
1687 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1688 * present in the reply to match Windows behavior */
1689 if (psd->sacl == NULL &&
1690 security_info_wanted & SACL_SECURITY_INFORMATION)
1691 psd->type |= SEC_DESC_SACL_PRESENT;
1692 if (psd->dacl == NULL &&
1693 security_info_wanted & DACL_SECURITY_INFORMATION)
1694 psd->type |= SEC_DESC_DACL_PRESENT;
1696 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1698 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1700 if (DEBUGLEVEL >= 10) {
1701 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name));
1702 NDR_PRINT_DEBUG(security_descriptor, psd);
1705 SIVAL(params,0,(uint32)sd_size);
1707 if (max_data_count < sd_size) {
1708 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1709 params, 4, *ppdata, 0);
1714 * Allocate the data we will point this at.
1717 data = nttrans_realloc(ppdata, sd_size);
1719 reply_doserror(req, ERRDOS, ERRnomem);
1723 status = marshall_sec_desc(talloc_tos(), psd,
1724 &blob.data, &blob.length);
1726 if (!NT_STATUS_IS_OK(status)) {
1727 reply_nterror(req, status);
1731 SMB_ASSERT(sd_size == blob.length);
1732 memcpy(data, blob.data, sd_size);
1734 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1739 /****************************************************************************
1740 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1741 ****************************************************************************/
1743 static void call_nt_transact_set_security_desc(connection_struct *conn,
1744 struct smb_request *req,
1748 uint32 parameter_count,
1751 uint32 max_data_count)
1753 char *params= *ppparams;
1754 char *data = *ppdata;
1755 files_struct *fsp = NULL;
1756 uint32 security_info_sent = 0;
1759 if(parameter_count < 8) {
1760 reply_doserror(req, ERRDOS, ERRbadfunc);
1764 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1765 reply_doserror(req, ERRDOS, ERRbadfid);
1769 if(!lp_nt_acl_support(SNUM(conn))) {
1773 security_info_sent = IVAL(params,4);
1775 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1776 (unsigned int)security_info_sent ));
1778 if (data_count == 0) {
1779 reply_doserror(req, ERRDOS, ERRnoaccess);
1783 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1785 if (!NT_STATUS_IS_OK(status)) {
1786 reply_nterror(req, status);
1791 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1795 /****************************************************************************
1797 ****************************************************************************/
1799 static void call_nt_transact_ioctl(connection_struct *conn,
1800 struct smb_request *req,
1801 uint16 **ppsetup, uint32 setup_count,
1802 char **ppparams, uint32 parameter_count,
1803 char **ppdata, uint32 data_count,
1804 uint32 max_data_count)
1811 char *pdata = *ppdata;
1813 if (setup_count != 8) {
1814 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1815 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1819 function = IVAL(*ppsetup, 0);
1820 fidnum = SVAL(*ppsetup, 4);
1821 isFSctl = CVAL(*ppsetup, 6);
1822 compfilter = CVAL(*ppsetup, 7);
1824 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1825 function, fidnum, isFSctl, compfilter));
1827 fsp=file_fsp(req, fidnum);
1828 /* this check is done in each implemented function case for now
1829 because I don't want to break anything... --metze
1830 FSP_BELONGS_CONN(fsp,conn);*/
1832 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1835 case FSCTL_SET_SPARSE:
1836 /* pretend this succeeded - tho strictly we should
1837 mark the file sparse (if the local fs supports it)
1838 so we can know if we need to pre-allocate or not */
1840 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1841 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1844 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1846 unsigned char objid[16];
1848 /* This should return the object-id on this file.
1849 * I think I'll make this be the inode+dev. JRA.
1852 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1854 if (!fsp_belongs_conn(conn, req, fsp)) {
1859 pdata = nttrans_realloc(ppdata, data_count);
1860 if (pdata == NULL) {
1861 reply_nterror(req, NT_STATUS_NO_MEMORY);
1865 /* For backwards compatibility only store the dev/inode. */
1866 push_file_id_16(pdata, &fsp->file_id);
1867 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1868 push_file_id_16(pdata+32, &fsp->file_id);
1869 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1874 case FSCTL_GET_REPARSE_POINT:
1875 /* pretend this fail - my winXP does it like this
1879 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1880 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1883 case FSCTL_SET_REPARSE_POINT:
1884 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1888 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1889 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1892 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1895 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1896 * and return their volume names. If max_data_count is 16, then it is just
1897 * asking for the number of volumes and length of the combined names.
1899 * pdata is the data allocated by our caller, but that uses
1900 * total_data_count (which is 0 in our case) rather than max_data_count.
1901 * Allocate the correct amount and return the pointer to let
1902 * it be deallocated when we return.
1904 SHADOW_COPY_DATA *shadow_data = NULL;
1905 TALLOC_CTX *shadow_mem_ctx = NULL;
1906 bool labels = False;
1907 uint32 labels_data_count = 0;
1911 if (!fsp_belongs_conn(conn, req, fsp)) {
1915 if (max_data_count < 16) {
1916 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1918 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1922 if (max_data_count > 16) {
1926 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1927 if (shadow_mem_ctx == NULL) {
1928 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1929 reply_nterror(req, NT_STATUS_NO_MEMORY);
1933 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
1934 if (shadow_data == NULL) {
1935 DEBUG(0,("TALLOC_ZERO() failed!\n"));
1936 talloc_destroy(shadow_mem_ctx);
1937 reply_nterror(req, NT_STATUS_NO_MEMORY);
1941 shadow_data->mem_ctx = shadow_mem_ctx;
1944 * Call the VFS routine to actually do the work.
1946 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1947 talloc_destroy(shadow_data->mem_ctx);
1948 if (errno == ENOSYS) {
1949 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1950 conn->connectpath));
1951 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1954 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1955 conn->connectpath));
1956 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
1961 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
1966 data_count = 12+labels_data_count+4;
1969 if (max_data_count<data_count) {
1970 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1971 max_data_count,data_count));
1972 talloc_destroy(shadow_data->mem_ctx);
1973 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
1977 pdata = nttrans_realloc(ppdata, data_count);
1978 if (pdata == NULL) {
1979 talloc_destroy(shadow_data->mem_ctx);
1980 reply_nterror(req, NT_STATUS_NO_MEMORY);
1986 /* num_volumes 4 bytes */
1987 SIVAL(pdata,0,shadow_data->num_volumes);
1990 /* num_labels 4 bytes */
1991 SIVAL(pdata,4,shadow_data->num_volumes);
1994 /* needed_data_count 4 bytes */
1995 SIVAL(pdata,8,labels_data_count);
1999 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2000 shadow_data->num_volumes,fsp->fsp_name));
2001 if (labels && shadow_data->labels) {
2002 for (i=0;i<shadow_data->num_volumes;i++) {
2003 srvstr_push(pdata, req->flags2,
2004 cur_pdata, shadow_data->labels[i],
2005 2*sizeof(SHADOW_COPY_LABEL),
2006 STR_UNICODE|STR_TERMINATE);
2007 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2008 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2012 talloc_destroy(shadow_data->mem_ctx);
2014 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2020 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2022 /* pretend this succeeded -
2024 * we have to send back a list with all files owned by this SID
2026 * but I have to check that --metze
2030 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2032 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2034 if (!fsp_belongs_conn(conn, req, fsp)) {
2038 /* unknown 4 bytes: this is not the length of the sid :-( */
2039 /*unknown = IVAL(pdata,0);*/
2041 sid_parse(pdata+4,sid_len,&sid);
2042 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2044 if (!sid_to_uid(&sid, &uid)) {
2045 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2046 sid_string_dbg(&sid),
2047 (unsigned long)sid_len));
2051 /* we can take a look at the find source :-)
2053 * find ./ -uid $uid -name '*' is what we need here
2056 * and send 4bytes len and then NULL terminated unicode strings
2059 * but I don't know how to deal with the paged results
2060 * (maybe we can hang the result anywhere in the fsp struct)
2062 * we don't send all files at once
2063 * and at the next we should *not* start from the beginning,
2064 * so we have to cache the result
2069 /* this works for now... */
2070 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2074 if (!logged_ioctl_message) {
2075 logged_ioctl_message = true; /* Only print this once... */
2076 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2081 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2085 #ifdef HAVE_SYS_QUOTAS
2086 /****************************************************************************
2087 Reply to get user quota
2088 ****************************************************************************/
2090 static void call_nt_transact_get_user_quota(connection_struct *conn,
2091 struct smb_request *req,
2095 uint32 parameter_count,
2098 uint32 max_data_count)
2100 NTSTATUS nt_status = NT_STATUS_OK;
2101 char *params = *ppparams;
2102 char *pdata = *ppdata;
2104 int data_len=0,param_len=0;
2107 files_struct *fsp = NULL;
2111 bool start_enum = True;
2112 SMB_NTQUOTA_STRUCT qt;
2113 SMB_NTQUOTA_LIST *tmp_list;
2114 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2119 if (conn->server_info->utok.uid != 0) {
2120 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2121 "[%s]\n", lp_servicename(SNUM(conn)),
2122 conn->server_info->unix_name));
2123 reply_doserror(req, ERRDOS, ERRnoaccess);
2128 * Ensure minimum number of parameters sent.
2131 if (parameter_count < 4) {
2132 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2133 reply_doserror(req, ERRDOS, ERRinvalidparam);
2137 /* maybe we can check the quota_fnum */
2138 fsp = file_fsp(req, SVAL(params,0));
2139 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2140 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2141 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2145 /* the NULL pointer checking for fsp->fake_file_handle->pd
2146 * is done by CHECK_NTQUOTA_HANDLE_OK()
2148 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2150 level = SVAL(params,2);
2152 /* unknown 12 bytes leading in params */
2155 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2156 /* seems that we should continue with the enum here --metze */
2158 if (qt_handle->quota_list!=NULL &&
2159 qt_handle->tmp_list==NULL) {
2162 free_ntquota_list(&(qt_handle->quota_list));
2164 /* Realloc the size of parameters and data we will return */
2166 params = nttrans_realloc(ppparams, param_len);
2167 if(params == NULL) {
2168 reply_doserror(req, ERRDOS, ERRnomem);
2173 SIVAL(params,0,data_len);
2180 case TRANSACT_GET_USER_QUOTA_LIST_START:
2182 if (qt_handle->quota_list==NULL &&
2183 qt_handle->tmp_list==NULL) {
2187 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2188 reply_doserror(req, ERRSRV, ERRerror);
2192 /* Realloc the size of parameters and data we will return */
2194 params = nttrans_realloc(ppparams, param_len);
2195 if(params == NULL) {
2196 reply_doserror(req, ERRDOS, ERRnomem);
2200 /* we should not trust the value in max_data_count*/
2201 max_data_count = MIN(max_data_count,2048);
2203 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2205 reply_doserror(req, ERRDOS, ERRnomem);
2211 /* set params Size of returned Quota Data 4 bytes*/
2212 /* but set it later when we know it */
2214 /* for each entry push the data */
2217 qt_handle->tmp_list = qt_handle->quota_list;
2220 tmp_list = qt_handle->tmp_list;
2222 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2223 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2225 sid_len = ndr_size_dom_sid(
2226 &tmp_list->quotas->sid, NULL, 0);
2227 entry_len = 40 + sid_len;
2229 /* nextoffset entry 4 bytes */
2230 SIVAL(entry,0,entry_len);
2232 /* then the len of the SID 4 bytes */
2233 SIVAL(entry,4,sid_len);
2235 /* unknown data 8 bytes uint64_t */
2236 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2238 /* the used disk space 8 bytes uint64_t */
2239 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2241 /* the soft quotas 8 bytes uint64_t */
2242 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2244 /* the hard quotas 8 bytes uint64_t */
2245 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2247 /* and now the SID */
2248 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2251 qt_handle->tmp_list = tmp_list;
2253 /* overwrite the offset of the last entry */
2254 SIVAL(entry-entry_len,0,0);
2256 data_len = 4+qt_len;
2257 /* overwrite the params quota_data_len */
2258 SIVAL(params,0,data_len);
2262 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2264 /* unknown 4 bytes IVAL(pdata,0) */
2266 if (data_count < 8) {
2267 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2268 reply_doserror(req, ERRDOS, ERRunknownlevel);
2272 sid_len = IVAL(pdata,4);
2273 /* Ensure this is less than 1mb. */
2274 if (sid_len > (1024*1024)) {
2275 reply_doserror(req, ERRDOS, ERRnomem);
2279 if (data_count < 8+sid_len) {
2280 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2281 reply_doserror(req, ERRDOS, ERRunknownlevel);
2285 data_len = 4+40+sid_len;
2287 if (max_data_count < data_len) {
2288 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2289 max_data_count, data_len));
2291 SIVAL(params,0,data_len);
2293 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2297 sid_parse(pdata+8,sid_len,&sid);
2299 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2302 * we have to return zero's in all fields
2303 * instead of returning an error here
2308 /* Realloc the size of parameters and data we will return */
2310 params = nttrans_realloc(ppparams, param_len);
2311 if(params == NULL) {
2312 reply_doserror(req, ERRDOS, ERRnomem);
2316 pdata = nttrans_realloc(ppdata, data_len);
2318 reply_doserror(req, ERRDOS, ERRnomem);
2324 /* set params Size of returned Quota Data 4 bytes*/
2325 SIVAL(params,0,data_len);
2327 /* nextoffset entry 4 bytes */
2330 /* then the len of the SID 4 bytes */
2331 SIVAL(entry,4,sid_len);
2333 /* unknown data 8 bytes uint64_t */
2334 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2336 /* the used disk space 8 bytes uint64_t */
2337 SBIG_UINT(entry,16,qt.usedspace);
2339 /* the soft quotas 8 bytes uint64_t */
2340 SBIG_UINT(entry,24,qt.softlim);
2342 /* the hard quotas 8 bytes uint64_t */
2343 SBIG_UINT(entry,32,qt.hardlim);
2345 /* and now the SID */
2346 sid_linearize(entry+40, sid_len, &sid);
2351 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2352 reply_doserror(req, ERRSRV, ERRerror);
2357 send_nt_replies(conn, req, nt_status, params, param_len,
2361 /****************************************************************************
2362 Reply to set user quota
2363 ****************************************************************************/
2365 static void call_nt_transact_set_user_quota(connection_struct *conn,
2366 struct smb_request *req,
2370 uint32 parameter_count,
2373 uint32 max_data_count)
2375 char *params = *ppparams;
2376 char *pdata = *ppdata;
2377 int data_len=0,param_len=0;
2378 SMB_NTQUOTA_STRUCT qt;
2381 files_struct *fsp = NULL;
2386 if (conn->server_info->utok.uid != 0) {
2387 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2388 "[%s]\n", lp_servicename(SNUM(conn)),
2389 conn->server_info->unix_name));
2390 reply_doserror(req, ERRDOS, ERRnoaccess);
2395 * Ensure minimum number of parameters sent.
2398 if (parameter_count < 2) {
2399 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2400 reply_doserror(req, ERRDOS, ERRinvalidparam);
2404 /* maybe we can check the quota_fnum */
2405 fsp = file_fsp(req, SVAL(params,0));
2406 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2407 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2408 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2412 if (data_count < 40) {
2413 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2414 reply_doserror(req, ERRDOS, ERRunknownlevel);
2418 /* offset to next quota record.
2419 * 4 bytes IVAL(pdata,0)
2424 sid_len = IVAL(pdata,4);
2426 if (data_count < 40+sid_len) {
2427 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2428 reply_doserror(req, ERRDOS, ERRunknownlevel);
2432 /* unknown 8 bytes in pdata
2433 * maybe its the change time in NTTIME
2436 /* the used space 8 bytes (uint64_t)*/
2437 qt.usedspace = (uint64_t)IVAL(pdata,16);
2438 #ifdef LARGE_SMB_OFF_T
2439 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2440 #else /* LARGE_SMB_OFF_T */
2441 if ((IVAL(pdata,20) != 0)&&
2442 ((qt.usedspace != 0xFFFFFFFF)||
2443 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2444 /* more than 32 bits? */
2445 reply_doserror(req, ERRDOS, ERRunknownlevel);
2448 #endif /* LARGE_SMB_OFF_T */
2450 /* the soft quotas 8 bytes (uint64_t)*/
2451 qt.softlim = (uint64_t)IVAL(pdata,24);
2452 #ifdef LARGE_SMB_OFF_T
2453 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2454 #else /* LARGE_SMB_OFF_T */
2455 if ((IVAL(pdata,28) != 0)&&
2456 ((qt.softlim != 0xFFFFFFFF)||
2457 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2458 /* more than 32 bits? */
2459 reply_doserror(req, ERRDOS, ERRunknownlevel);
2462 #endif /* LARGE_SMB_OFF_T */
2464 /* the hard quotas 8 bytes (uint64_t)*/
2465 qt.hardlim = (uint64_t)IVAL(pdata,32);
2466 #ifdef LARGE_SMB_OFF_T
2467 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2468 #else /* LARGE_SMB_OFF_T */
2469 if ((IVAL(pdata,36) != 0)&&
2470 ((qt.hardlim != 0xFFFFFFFF)||
2471 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2472 /* more than 32 bits? */
2473 reply_doserror(req, ERRDOS, ERRunknownlevel);
2476 #endif /* LARGE_SMB_OFF_T */
2478 sid_parse(pdata+40,sid_len,&sid);
2479 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2481 /* 44 unknown bytes left... */
2483 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2484 reply_doserror(req, ERRSRV, ERRerror);
2488 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2491 #endif /* HAVE_SYS_QUOTAS */
2493 static void handle_nttrans(connection_struct *conn,
2494 struct trans_state *state,
2495 struct smb_request *req)
2497 if (Protocol >= PROTOCOL_NT1) {
2498 req->flags2 |= 0x40; /* IS_LONG_NAME */
2499 SSVAL(req->inbuf,smb_flg2,req->flags2);
2503 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2505 /* Now we must call the relevant NT_TRANS function */
2506 switch(state->call) {
2507 case NT_TRANSACT_CREATE:
2509 START_PROFILE(NT_transact_create);
2510 call_nt_transact_create(
2512 &state->setup, state->setup_count,
2513 &state->param, state->total_param,
2514 &state->data, state->total_data,
2515 state->max_data_return);
2516 END_PROFILE(NT_transact_create);
2520 case NT_TRANSACT_IOCTL:
2522 START_PROFILE(NT_transact_ioctl);
2523 call_nt_transact_ioctl(
2525 &state->setup, state->setup_count,
2526 &state->param, state->total_param,
2527 &state->data, state->total_data,
2528 state->max_data_return);
2529 END_PROFILE(NT_transact_ioctl);
2533 case NT_TRANSACT_SET_SECURITY_DESC:
2535 START_PROFILE(NT_transact_set_security_desc);
2536 call_nt_transact_set_security_desc(
2538 &state->setup, state->setup_count,
2539 &state->param, state->total_param,
2540 &state->data, state->total_data,
2541 state->max_data_return);
2542 END_PROFILE(NT_transact_set_security_desc);
2546 case NT_TRANSACT_NOTIFY_CHANGE:
2548 START_PROFILE(NT_transact_notify_change);
2549 call_nt_transact_notify_change(
2551 &state->setup, state->setup_count,
2552 &state->param, state->total_param,
2553 &state->data, state->total_data,
2554 state->max_data_return,
2555 state->max_param_return);
2556 END_PROFILE(NT_transact_notify_change);
2560 case NT_TRANSACT_RENAME:
2562 START_PROFILE(NT_transact_rename);
2563 call_nt_transact_rename(
2565 &state->setup, state->setup_count,
2566 &state->param, state->total_param,
2567 &state->data, state->total_data,
2568 state->max_data_return);
2569 END_PROFILE(NT_transact_rename);
2573 case NT_TRANSACT_QUERY_SECURITY_DESC:
2575 START_PROFILE(NT_transact_query_security_desc);
2576 call_nt_transact_query_security_desc(
2578 &state->setup, state->setup_count,
2579 &state->param, state->total_param,
2580 &state->data, state->total_data,
2581 state->max_data_return);
2582 END_PROFILE(NT_transact_query_security_desc);
2586 #ifdef HAVE_SYS_QUOTAS
2587 case NT_TRANSACT_GET_USER_QUOTA:
2589 START_PROFILE(NT_transact_get_user_quota);
2590 call_nt_transact_get_user_quota(
2592 &state->setup, state->setup_count,
2593 &state->param, state->total_param,
2594 &state->data, state->total_data,
2595 state->max_data_return);
2596 END_PROFILE(NT_transact_get_user_quota);
2600 case NT_TRANSACT_SET_USER_QUOTA:
2602 START_PROFILE(NT_transact_set_user_quota);
2603 call_nt_transact_set_user_quota(
2605 &state->setup, state->setup_count,
2606 &state->param, state->total_param,
2607 &state->data, state->total_data,
2608 state->max_data_return);
2609 END_PROFILE(NT_transact_set_user_quota);
2612 #endif /* HAVE_SYS_QUOTAS */
2615 /* Error in request */
2616 DEBUG(0,("handle_nttrans: Unknown request %d in "
2617 "nttrans call\n", state->call));
2618 reply_doserror(req, ERRSRV, ERRerror);
2624 /****************************************************************************
2625 Reply to a SMBNTtrans.
2626 ****************************************************************************/
2628 void reply_nttrans(struct smb_request *req)
2630 connection_struct *conn = req->conn;
2635 uint16 function_code;
2637 struct trans_state *state;
2639 START_PROFILE(SMBnttrans);
2641 if (req->wct < 19) {
2642 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2643 END_PROFILE(SMBnttrans);
2647 pscnt = IVAL(req->vwv+9, 1);
2648 psoff = IVAL(req->vwv+11, 1);
2649 dscnt = IVAL(req->vwv+13, 1);
2650 dsoff = IVAL(req->vwv+15, 1);
2651 function_code = SVAL(req->vwv+18, 0);
2653 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2654 reply_doserror(req, ERRSRV, ERRaccess);
2655 END_PROFILE(SMBnttrans);
2659 result = allow_new_trans(conn->pending_trans, req->mid);
2660 if (!NT_STATUS_IS_OK(result)) {
2661 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2662 reply_nterror(req, result);
2663 END_PROFILE(SMBnttrans);
2667 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2668 reply_doserror(req, ERRSRV, ERRaccess);
2669 END_PROFILE(SMBnttrans);
2673 state->cmd = SMBnttrans;
2675 state->mid = req->mid;
2676 state->vuid = req->vuid;
2677 state->total_data = IVAL(req->vwv+3, 1);
2679 state->total_param = IVAL(req->vwv+1, 1);
2680 state->param = NULL;
2681 state->max_data_return = IVAL(req->vwv+7, 1);
2682 state->max_param_return = IVAL(req->vwv+5, 1);
2684 /* setup count is in *words* */
2685 state->setup_count = 2*CVAL(req->vwv+17, 1);
2686 state->setup = NULL;
2687 state->call = function_code;
2689 DEBUG(10, ("num_setup=%u, "
2690 "param_total=%u, this_param=%u, max_param=%u, "
2691 "data_total=%u, this_data=%u, max_data=%u, "
2692 "param_offset=%u, data_offset=%u\n",
2693 (unsigned)state->setup_count,
2694 (unsigned)state->total_param, (unsigned)pscnt,
2695 (unsigned)state->max_param_return,
2696 (unsigned)state->total_data, (unsigned)dscnt,
2697 (unsigned)state->max_data_return,
2698 (unsigned)psoff, (unsigned)dsoff));
2701 * All nttrans messages we handle have smb_wct == 19 +
2702 * state->setup_count. Ensure this is so as a sanity check.
2705 if(req->wct != 19 + (state->setup_count/2)) {
2706 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2707 req->wct, 19 + (state->setup_count/2)));
2711 /* Don't allow more than 128mb for each value. */
2712 if ((state->total_data > (1024*1024*128)) ||
2713 (state->total_param > (1024*1024*128))) {
2714 reply_doserror(req, ERRDOS, ERRnomem);
2715 END_PROFILE(SMBnttrans);
2719 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2722 if (state->total_data) {
2724 if (trans_oob(state->total_data, 0, dscnt)
2725 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2729 /* Can't use talloc here, the core routines do realloc on the
2730 * params and data. */
2731 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2732 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2733 "bytes !\n", (unsigned int)state->total_data));
2735 reply_doserror(req, ERRDOS, ERRnomem);
2736 END_PROFILE(SMBnttrans);
2740 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2743 if (state->total_param) {
2745 if (trans_oob(state->total_param, 0, pscnt)
2746 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2750 /* Can't use talloc here, the core routines do realloc on the
2751 * params and data. */
2752 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2753 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2754 "bytes !\n", (unsigned int)state->total_param));
2755 SAFE_FREE(state->data);
2757 reply_doserror(req, ERRDOS, ERRnomem);
2758 END_PROFILE(SMBnttrans);
2762 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2765 state->received_data = dscnt;
2766 state->received_param = pscnt;
2768 if(state->setup_count > 0) {
2769 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2770 state->setup_count));
2773 * No overflow possible here, state->setup_count is an
2774 * unsigned int, being filled by a single byte from
2775 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2776 * below is not necessary, it's here to clarify things. The
2777 * validity of req->vwv and req->wct has been checked in
2778 * init_smb_request already.
2780 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2784 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2785 if (state->setup == NULL) {
2786 DEBUG(0,("reply_nttrans : Out of memory\n"));
2787 SAFE_FREE(state->data);
2788 SAFE_FREE(state->param);
2790 reply_doserror(req, ERRDOS, ERRnomem);
2791 END_PROFILE(SMBnttrans);
2795 memcpy(state->setup, req->vwv+19, state->setup_count);
2796 dump_data(10, (uint8 *)state->setup, state->setup_count);
2799 if ((state->received_data == state->total_data) &&
2800 (state->received_param == state->total_param)) {
2801 handle_nttrans(conn, state, req);
2802 SAFE_FREE(state->param);
2803 SAFE_FREE(state->data);
2805 END_PROFILE(SMBnttrans);
2809 DLIST_ADD(conn->pending_trans, state);
2811 /* We need to send an interim response then receive the rest
2812 of the parameter/data bytes */
2813 reply_outbuf(req, 0, 0);
2814 show_msg((char *)req->outbuf);
2815 END_PROFILE(SMBnttrans);
2820 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2821 SAFE_FREE(state->data);
2822 SAFE_FREE(state->param);
2824 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2825 END_PROFILE(SMBnttrans);
2829 /****************************************************************************
2830 Reply to a SMBnttranss
2831 ****************************************************************************/
2833 void reply_nttranss(struct smb_request *req)
2835 connection_struct *conn = req->conn;
2836 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2837 struct trans_state *state;
2839 START_PROFILE(SMBnttranss);
2841 show_msg((char *)req->inbuf);
2843 if (req->wct < 18) {
2844 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2845 END_PROFILE(SMBnttranss);
2849 for (state = conn->pending_trans; state != NULL;
2850 state = state->next) {
2851 if (state->mid == req->mid) {
2856 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2857 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2858 END_PROFILE(SMBnttranss);
2862 /* Revise state->total_param and state->total_data in case they have
2863 changed downwards */
2864 if (IVAL(req->vwv+1, 1) < state->total_param) {
2865 state->total_param = IVAL(req->vwv+1, 1);
2867 if (IVAL(req->vwv+3, 1) < state->total_data) {
2868 state->total_data = IVAL(req->vwv+3, 1);
2871 pcnt = IVAL(req->vwv+5, 1);
2872 poff = IVAL(req->vwv+7, 1);
2873 pdisp = IVAL(req->vwv+9, 1);
2875 dcnt = IVAL(req->vwv+11, 1);
2876 doff = IVAL(req->vwv+13, 1);
2877 ddisp = IVAL(req->vwv+15, 1);
2879 state->received_param += pcnt;
2880 state->received_data += dcnt;
2882 if ((state->received_data > state->total_data) ||
2883 (state->received_param > state->total_param))
2887 if (trans_oob(state->total_param, pdisp, pcnt)
2888 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2891 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2895 if (trans_oob(state->total_data, ddisp, dcnt)
2896 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2899 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2902 if ((state->received_param < state->total_param) ||
2903 (state->received_data < state->total_data)) {
2904 END_PROFILE(SMBnttranss);
2908 handle_nttrans(conn, state, req);
2910 DLIST_REMOVE(conn->pending_trans, state);
2911 SAFE_FREE(state->data);
2912 SAFE_FREE(state->param);
2914 END_PROFILE(SMBnttranss);
2919 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2920 DLIST_REMOVE(conn->pending_trans, state);
2921 SAFE_FREE(state->data);
2922 SAFE_FREE(state->param);
2924 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2925 END_PROFILE(SMBnttranss);