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 if (NT_STATUS_V(nt_error)) {
72 error_packet_set((char *)req->outbuf,
76 show_msg((char *)req->outbuf);
77 if (!srv_send_smb(smbd_server_fd(),
80 IS_CONN_ENCRYPTED(conn),
82 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
84 TALLOC_FREE(req->outbuf);
89 * When sending params and data ensure that both are nicely aligned.
90 * Only do this alignment when there is also data to send - else
91 * can cause NT redirector problems.
94 if (((params_to_send % 4) != 0) && (data_to_send != 0)) {
95 data_alignment_offset = 4 - (params_to_send % 4);
99 * Space is bufsize minus Netbios over TCP header minus SMB header.
100 * The alignment_offset is to align the param bytes on a four byte
101 * boundary (2 bytes for data len, one byte pad).
102 * NT needs this to work correctly.
105 useable_space = max_send - (smb_size
108 + data_alignment_offset);
110 if (useable_space < 0) {
111 char *msg = talloc_asprintf(
113 "send_nt_replies failed sanity useable_space = %d!!!",
115 DEBUG(0, ("%s\n", msg));
116 exit_server_cleanly(msg);
119 while (params_to_send || data_to_send) {
122 * Calculate whether we will totally or partially fill this packet.
125 total_sent_thistime = params_to_send + data_to_send;
128 * We can never send more than useable_space.
131 total_sent_thistime = MIN(total_sent_thistime, useable_space);
133 reply_outbuf(req, 18,
134 total_sent_thistime + alignment_offset
135 + data_alignment_offset);
138 * We might have had SMBnttranss in req->inbuf, fix that.
140 SCVAL(req->outbuf, smb_com, SMBnttrans);
143 * Set total params and data to be sent.
146 SIVAL(req->outbuf,smb_ntr_TotalParameterCount,paramsize);
147 SIVAL(req->outbuf,smb_ntr_TotalDataCount,datasize);
150 * Calculate how many parameters and data we can fit into
151 * this packet. Parameters get precedence.
154 params_sent_thistime = MIN(params_to_send,useable_space);
155 data_sent_thistime = useable_space - params_sent_thistime;
156 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
158 SIVAL(req->outbuf, smb_ntr_ParameterCount,
159 params_sent_thistime);
161 if(params_sent_thistime == 0) {
162 SIVAL(req->outbuf,smb_ntr_ParameterOffset,0);
163 SIVAL(req->outbuf,smb_ntr_ParameterDisplacement,0);
166 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
167 * parameter bytes, however the first 4 bytes of outbuf are
168 * the Netbios over TCP header. Thus use smb_base() to subtract
169 * them from the calculation.
172 SIVAL(req->outbuf,smb_ntr_ParameterOffset,
173 ((smb_buf(req->outbuf)+alignment_offset)
174 - smb_base(req->outbuf)));
176 * Absolute displacement of param bytes sent in this packet.
179 SIVAL(req->outbuf, smb_ntr_ParameterDisplacement,
184 * Deal with the data portion.
187 SIVAL(req->outbuf, smb_ntr_DataCount, data_sent_thistime);
189 if(data_sent_thistime == 0) {
190 SIVAL(req->outbuf,smb_ntr_DataOffset,0);
191 SIVAL(req->outbuf,smb_ntr_DataDisplacement, 0);
194 * The offset of the data bytes is the offset of the
195 * parameter bytes plus the number of parameters being sent this time.
198 SIVAL(req->outbuf, smb_ntr_DataOffset,
199 ((smb_buf(req->outbuf)+alignment_offset) -
200 smb_base(req->outbuf))
201 + params_sent_thistime + data_alignment_offset);
202 SIVAL(req->outbuf,smb_ntr_DataDisplacement, pd - pdata);
206 * Copy the param bytes into the packet.
209 if(params_sent_thistime) {
210 if (alignment_offset != 0) {
211 memset(smb_buf(req->outbuf), 0,
214 memcpy((smb_buf(req->outbuf)+alignment_offset), pp,
215 params_sent_thistime);
219 * Copy in the data bytes
222 if(data_sent_thistime) {
223 if (data_alignment_offset != 0) {
224 memset((smb_buf(req->outbuf)+alignment_offset+
225 params_sent_thistime), 0,
226 data_alignment_offset);
228 memcpy(smb_buf(req->outbuf)+alignment_offset
229 +params_sent_thistime+data_alignment_offset,
230 pd,data_sent_thistime);
233 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
234 params_sent_thistime, data_sent_thistime, useable_space));
235 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
236 params_to_send, data_to_send, paramsize, datasize));
238 if (NT_STATUS_V(nt_error)) {
239 error_packet_set((char *)req->outbuf,
244 /* Send the packet */
245 show_msg((char *)req->outbuf);
246 if (!srv_send_smb(smbd_server_fd(),
249 IS_CONN_ENCRYPTED(conn),
251 exit_server_cleanly("send_nt_replies: srv_send_smb failed.");
254 TALLOC_FREE(req->outbuf);
256 pp += params_sent_thistime;
257 pd += data_sent_thistime;
259 params_to_send -= params_sent_thistime;
260 data_to_send -= data_sent_thistime;
266 if(params_to_send < 0 || data_to_send < 0) {
267 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
268 params_to_send, data_to_send));
269 exit_server_cleanly("send_nt_replies: internal error");
274 /****************************************************************************
275 Is it an NTFS stream name ?
276 An NTFS file name is <path>.<extention>:<stream name>:<stream type>
277 $DATA can be used as both a stream name and a stream type. A missing stream
278 name or type implies $DATA.
280 Both Windows stream names and POSIX files can contain the ':' character.
281 This function first checks for the existence of a colon in the last component
282 of the given name. If the name contains a colon we differentiate between a
283 stream and POSIX file by checking if the latter exists through a POSIX stat.
285 Function assumes we've already chdir() to the "root" directory of fname.
286 ****************************************************************************/
288 bool is_ntfs_stream_name(const char *fname)
290 const char *lastcomp;
291 SMB_STRUCT_STAT sbuf;
293 /* If all pathnames are treated as POSIX we ignore streams. */
294 if (lp_posix_pathnames()) {
298 /* Find the last component of the name. */
299 if ((lastcomp = strrchr_m(fname, '/')) != NULL)
304 /* If there is no colon in the last component, it's not a stream. */
305 if (strchr_m(lastcomp, ':') == NULL)
309 * If file already exists on disk, it's not a stream. The stat must
310 * bypass the vfs layer so streams modules don't intefere.
312 if (sys_stat(fname, &sbuf) == 0) {
313 DEBUG(5, ("is_ntfs_stream_name: file %s contains a ':' but is "
314 "not a stream\n", fname));
321 /****************************************************************************
322 Simple check to determine if the filename is a stream.
323 ***************************************************************************/
324 bool is_ntfs_stream_smb_fname(const struct smb_filename *smb_fname)
326 if (lp_posix_pathnames()) {
330 return smb_fname->stream_name;
333 /****************************************************************************
334 Returns true if the filename's stream == "::$DATA"
335 ***************************************************************************/
336 bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname)
338 if (!is_ntfs_stream_smb_fname(smb_fname)) {
342 return StrCaseCmp(smb_fname->stream_name, "::$DATA") == 0;
345 /****************************************************************************
346 Reply to an NT create and X call on a pipe
347 ****************************************************************************/
349 static void nt_open_pipe(char *fname, connection_struct *conn,
350 struct smb_request *req, int *ppnum)
355 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
357 /* Strip \\ off the name. */
360 status = open_np_file(req, fname, &fsp);
361 if (!NT_STATUS_IS_OK(status)) {
362 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
363 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
367 reply_nterror(req, status);
375 /****************************************************************************
376 Reply to an NT create and X call for pipes.
377 ****************************************************************************/
379 static void do_ntcreate_pipe_open(connection_struct *conn,
380 struct smb_request *req)
385 uint32 flags = IVAL(req->vwv+3, 1);
386 TALLOC_CTX *ctx = talloc_tos();
388 srvstr_pull_req_talloc(ctx, req, &fname, req->buf, STR_TERMINATE);
391 reply_botherror(req, NT_STATUS_OBJECT_NAME_NOT_FOUND,
395 nt_open_pipe(fname, conn, req, &pnum);
403 * Deal with pipe return.
406 if (flags & EXTENDED_RESPONSE_REQUIRED) {
407 /* This is very strange. We
408 * return 50 words, but only set
409 * the wcnt to 42 ? It's definately
410 * what happens on the wire....
412 reply_outbuf(req, 50, 0);
413 SCVAL(req->outbuf,smb_wct,42);
415 reply_outbuf(req, 34, 0);
418 p = (char *)req->outbuf + smb_vwv2;
422 SIVAL(p,0,FILE_WAS_OPENED);
425 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
428 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
430 SSVAL(p,2, 0x5FF); /* ? */
433 if (flags & EXTENDED_RESPONSE_REQUIRED) {
435 SIVAL(p,0,FILE_GENERIC_ALL);
437 * For pipes W2K3 seems to return
439 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
441 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
444 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
449 /****************************************************************************
450 Reply to an NT create and X call.
451 ****************************************************************************/
453 void reply_ntcreate_and_X(struct smb_request *req)
455 connection_struct *conn = req->conn;
456 struct smb_filename *smb_fname = NULL;
460 uint32 file_attributes;
462 uint32 create_disposition;
463 uint32 create_options;
465 uint64_t allocation_size;
466 /* Breakout the oplock request bits so we can set the
467 reply bits separately. */
469 SMB_OFF_T file_len = 0;
471 files_struct *fsp = NULL;
473 struct timespec c_timespec;
474 struct timespec a_timespec;
475 struct timespec m_timespec;
476 struct timespec write_time_ts;
479 uint8_t oplock_granted = NO_OPLOCK_RETURN;
480 TALLOC_CTX *ctx = talloc_tos();
482 START_PROFILE(SMBntcreateX);
485 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
489 flags = IVAL(req->vwv+3, 1);
490 access_mask = IVAL(req->vwv+7, 1);
491 file_attributes = IVAL(req->vwv+13, 1);
492 share_access = IVAL(req->vwv+15, 1);
493 create_disposition = IVAL(req->vwv+17, 1);
494 create_options = IVAL(req->vwv+19, 1);
495 root_dir_fid = (uint16)IVAL(req->vwv+5, 1);
497 allocation_size = (uint64_t)IVAL(req->vwv+9, 1);
498 #ifdef LARGE_SMB_OFF_T
499 allocation_size |= (((uint64_t)IVAL(req->vwv+11, 1)) << 32);
502 srvstr_get_path_req(ctx, req, &fname, (const char *)req->buf,
503 STR_TERMINATE, &status);
505 if (!NT_STATUS_IS_OK(status)) {
506 reply_nterror(req, status);
510 DEBUG(10,("reply_ntcreate_and_X: flags = 0x%x, access_mask = 0x%x "
511 "file_attributes = 0x%x, share_access = 0x%x, "
512 "create_disposition = 0x%x create_options = 0x%x "
513 "root_dir_fid = 0x%x, fname = %s\n",
515 (unsigned int)access_mask,
516 (unsigned int)file_attributes,
517 (unsigned int)share_access,
518 (unsigned int)create_disposition,
519 (unsigned int)create_options,
520 (unsigned int)root_dir_fid,
524 * we need to remove ignored bits when they come directly from the client
525 * because we reuse some of them for internal stuff
527 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
530 * If it's an IPC, use the pipe handler.
534 if (lp_nt_pipe_support()) {
535 do_ntcreate_pipe_open(conn, req);
538 reply_doserror(req, ERRDOS, ERRnoaccess);
542 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
543 if (oplock_request) {
544 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
548 status = filename_convert(ctx,
550 req->flags2 & FLAGS2_DFS_PATHNAMES,
555 if (!NT_STATUS_IS_OK(status)) {
556 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
558 NT_STATUS_PATH_NOT_COVERED,
562 reply_nterror(req, status);
566 status = SMB_VFS_CREATE_FILE(
569 root_dir_fid, /* root_dir_fid */
570 smb_fname, /* fname */
571 access_mask, /* access_mask */
572 share_access, /* share_access */
573 create_disposition, /* create_disposition*/
574 create_options, /* create_options */
575 file_attributes, /* file_attributes */
576 oplock_request, /* oplock_request */
577 allocation_size, /* allocation_size */
583 if (!NT_STATUS_IS_OK(status)) {
584 if (open_was_deferred(req->mid)) {
585 /* We have re-scheduled this call, no error. */
588 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_COLLISION)) {
589 reply_botherror(req, status, ERRDOS, ERRfilexists);
592 reply_nterror(req, status);
598 * If the caller set the extended oplock request bit
599 * and we granted one (by whatever means) - set the
600 * correct bit for extended oplock reply.
603 if (oplock_request &&
604 (lp_fake_oplocks(SNUM(conn))
605 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
608 * Exclusive oplock granted
611 if (flags & REQUEST_BATCH_OPLOCK) {
612 oplock_granted = BATCH_OPLOCK_RETURN;
614 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
616 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
617 oplock_granted = LEVEL_II_OPLOCK_RETURN;
619 oplock_granted = NO_OPLOCK_RETURN;
622 file_len = smb_fname->st.st_ex_size;
623 fattr = dos_mode(conn, smb_fname);
625 fattr = FILE_ATTRIBUTE_NORMAL;
628 if (flags & EXTENDED_RESPONSE_REQUIRED) {
629 /* This is very strange. We
630 * return 50 words, but only set
631 * the wcnt to 42 ? It's definately
632 * what happens on the wire....
634 reply_outbuf(req, 50, 0);
635 SCVAL(req->outbuf,smb_wct,42);
637 reply_outbuf(req, 34, 0);
640 p = (char *)req->outbuf + smb_vwv2;
642 SCVAL(p, 0, oplock_granted);
645 SSVAL(p,0,fsp->fnum);
647 if ((create_disposition == FILE_SUPERSEDE)
648 && (info == FILE_WAS_OVERWRITTEN)) {
649 SIVAL(p,0,FILE_WAS_SUPERSEDED);
655 /* Deal with other possible opens having a modified
657 ZERO_STRUCT(write_time_ts);
658 get_file_infos(fsp->file_id, NULL, &write_time_ts);
659 if (!null_timespec(write_time_ts)) {
660 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
664 c_timespec = smb_fname->st.st_ex_btime;
665 a_timespec = smb_fname->st.st_ex_atime;
666 m_timespec = smb_fname->st.st_ex_mtime;
668 if (lp_dos_filetime_resolution(SNUM(conn))) {
669 dos_filetime_timespec(&c_timespec);
670 dos_filetime_timespec(&a_timespec);
671 dos_filetime_timespec(&m_timespec);
674 put_long_date_timespec(p, c_timespec); /* create time. */
676 put_long_date_timespec(p, a_timespec); /* access time */
678 put_long_date_timespec(p, m_timespec); /* write time */
680 put_long_date_timespec(p, m_timespec); /* change time */
682 SIVAL(p,0,fattr); /* File Attributes. */
684 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn,fsp,&smb_fname->st));
686 SOFF_T(p,0,file_len);
688 if (flags & EXTENDED_RESPONSE_REQUIRED) {
692 SCVAL(p,0,fsp->is_directory ? 1 : 0);
694 if (flags & EXTENDED_RESPONSE_REQUIRED) {
697 if (fsp->is_directory ||
698 can_write_to_file(conn, smb_fname)) {
699 perms = FILE_GENERIC_ALL;
701 perms = FILE_GENERIC_READ|FILE_EXECUTE;
706 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n",
707 fsp->fnum, smb_fname_str_dbg(smb_fname)));
711 TALLOC_FREE(smb_fname);
712 END_PROFILE(SMBntcreateX);
716 /****************************************************************************
717 Reply to a NT_TRANSACT_CREATE call to open a pipe.
718 ****************************************************************************/
720 static void do_nt_transact_create_pipe(connection_struct *conn,
721 struct smb_request *req,
722 uint16 **ppsetup, uint32 setup_count,
723 char **ppparams, uint32 parameter_count,
724 char **ppdata, uint32 data_count)
727 char *params = *ppparams;
733 TALLOC_CTX *ctx = talloc_tos();
736 * Ensure minimum number of parameters sent.
739 if(parameter_count < 54) {
740 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
741 reply_doserror(req, ERRDOS, ERRnoaccess);
745 flags = IVAL(params,0);
747 srvstr_get_path(ctx, params, req->flags2, &fname, params+53,
748 parameter_count-53, STR_TERMINATE,
750 if (!NT_STATUS_IS_OK(status)) {
751 reply_nterror(req, status);
755 nt_open_pipe(fname, conn, req, &pnum);
762 /* Realloc the size of parameters and data we will return */
763 if (flags & EXTENDED_RESPONSE_REQUIRED) {
764 /* Extended response is 32 more byyes. */
769 params = nttrans_realloc(ppparams, param_len);
771 reply_doserror(req, ERRDOS, ERRnomem);
776 SCVAL(p,0,NO_OPLOCK_RETURN);
781 SIVAL(p,0,FILE_WAS_OPENED);
785 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
788 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
790 SSVAL(p,2, 0x5FF); /* ? */
793 if (flags & EXTENDED_RESPONSE_REQUIRED) {
795 SIVAL(p,0,FILE_GENERIC_ALL);
797 * For pipes W2K3 seems to return
799 * This is ((FILE_GENERIC_READ|FILE_GENERIC_WRITE) & ~FILE_APPEND_DATA)
801 SIVAL(p,4,(FILE_GENERIC_READ|FILE_GENERIC_WRITE)&~FILE_APPEND_DATA);
804 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
806 /* Send the required number of replies */
807 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
812 /****************************************************************************
813 Internal fn to set security descriptors.
814 ****************************************************************************/
816 static NTSTATUS set_sd(files_struct *fsp, uint8 *data, uint32 sd_len,
817 uint32 security_info_sent)
819 SEC_DESC *psd = NULL;
822 if (sd_len == 0 || !lp_nt_acl_support(SNUM(fsp->conn))) {
826 status = unmarshall_sec_desc(talloc_tos(), data, sd_len, &psd);
828 if (!NT_STATUS_IS_OK(status)) {
832 if (psd->owner_sid == NULL) {
833 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
835 if (psd->group_sid == NULL) {
836 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
839 /* Convert all the generic bits. */
840 security_acl_map_generic(psd->dacl, &file_generic_mapping);
841 security_acl_map_generic(psd->sacl, &file_generic_mapping);
843 if (DEBUGLEVEL >= 10) {
844 DEBUG(10,("set_sd for file %s\n", fsp->fsp_name ));
845 NDR_PRINT_DEBUG(security_descriptor, psd);
848 status = SMB_VFS_FSET_NT_ACL(fsp, security_info_sent, psd);
855 /****************************************************************************
856 Read a list of EA names and data from an incoming data buffer. Create an ea_list with them.
857 ****************************************************************************/
859 static struct ea_list *read_nttrans_ea_list(TALLOC_CTX *ctx, const char *pdata, size_t data_size)
861 struct ea_list *ea_list_head = NULL;
868 while (offset + 4 <= data_size) {
869 size_t next_offset = IVAL(pdata,offset);
870 struct ea_list *eal = read_ea_list_entry(ctx, pdata + offset + 4, data_size - offset - 4, NULL);
876 DLIST_ADD_END(ea_list_head, eal, struct ea_list *);
877 if (next_offset == 0) {
880 offset += next_offset;
886 /****************************************************************************
887 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
888 ****************************************************************************/
890 static void call_nt_transact_create(connection_struct *conn,
891 struct smb_request *req,
892 uint16 **ppsetup, uint32 setup_count,
893 char **ppparams, uint32 parameter_count,
894 char **ppdata, uint32 data_count,
895 uint32 max_data_count)
897 struct smb_filename *smb_fname = NULL;
899 char *params = *ppparams;
900 char *data = *ppdata;
901 /* Breakout the oplock request bits so we can set the reply bits separately. */
903 SMB_OFF_T file_len = 0;
905 files_struct *fsp = NULL;
909 uint32 file_attributes;
911 uint32 create_disposition;
912 uint32 create_options;
914 struct security_descriptor *sd = NULL;
917 struct timespec c_timespec;
918 struct timespec a_timespec;
919 struct timespec m_timespec;
920 struct timespec write_time_ts;
921 struct ea_list *ea_list = NULL;
924 uint64_t allocation_size;
926 uint8_t oplock_granted;
927 TALLOC_CTX *ctx = talloc_tos();
929 DEBUG(5,("call_nt_transact_create\n"));
932 * If it's an IPC, use the pipe handler.
936 if (lp_nt_pipe_support()) {
937 do_nt_transact_create_pipe(
939 ppsetup, setup_count,
940 ppparams, parameter_count,
944 reply_doserror(req, ERRDOS, ERRnoaccess);
949 * Ensure minimum number of parameters sent.
952 if(parameter_count < 54) {
953 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
954 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
958 flags = IVAL(params,0);
959 access_mask = IVAL(params,8);
960 file_attributes = IVAL(params,20);
961 share_access = IVAL(params,24);
962 create_disposition = IVAL(params,28);
963 create_options = IVAL(params,32);
964 sd_len = IVAL(params,36);
965 ea_len = IVAL(params,40);
966 root_dir_fid = (uint16)IVAL(params,4);
967 allocation_size = (uint64_t)IVAL(params,12);
968 #ifdef LARGE_SMB_OFF_T
969 allocation_size |= (((uint64_t)IVAL(params,16)) << 32);
973 * we need to remove ignored bits when they come directly from the client
974 * because we reuse some of them for internal stuff
976 create_options &= ~NTCREATEX_OPTIONS_MUST_IGNORE_MASK;
978 /* Ensure the data_len is correct for the sd and ea values given. */
979 if ((ea_len + sd_len > data_count)
980 || (ea_len > data_count) || (sd_len > data_count)
981 || (ea_len + sd_len < ea_len) || (ea_len + sd_len < sd_len)) {
982 DEBUG(10, ("call_nt_transact_create - ea_len = %u, sd_len = "
983 "%u, data_count = %u\n", (unsigned int)ea_len,
984 (unsigned int)sd_len, (unsigned int)data_count));
985 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
990 DEBUG(10, ("call_nt_transact_create - sd_len = %d\n",
993 status = unmarshall_sec_desc(ctx, (uint8_t *)data, sd_len,
995 if (!NT_STATUS_IS_OK(status)) {
996 DEBUG(10, ("call_nt_transact_create: "
997 "unmarshall_sec_desc failed: %s\n",
999 reply_nterror(req, status);
1005 if (!lp_ea_support(SNUM(conn))) {
1006 DEBUG(10, ("call_nt_transact_create - ea_len = %u but "
1007 "EA's not supported.\n",
1008 (unsigned int)ea_len));
1009 reply_nterror(req, NT_STATUS_EAS_NOT_SUPPORTED);
1014 DEBUG(10,("call_nt_transact_create - ea_len = %u - "
1015 "too small (should be more than 10)\n",
1016 (unsigned int)ea_len ));
1017 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1021 /* We have already checked that ea_len <= data_count here. */
1022 ea_list = read_nttrans_ea_list(talloc_tos(), data + sd_len,
1024 if (ea_list == NULL) {
1025 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1030 srvstr_get_path(ctx, params, req->flags2, &fname,
1031 params+53, parameter_count-53,
1032 STR_TERMINATE, &status);
1033 if (!NT_STATUS_IS_OK(status)) {
1034 reply_nterror(req, status);
1038 status = filename_convert(ctx,
1040 req->flags2 & FLAGS2_DFS_PATHNAMES,
1045 if (!NT_STATUS_IS_OK(status)) {
1046 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1047 reply_botherror(req,
1048 NT_STATUS_PATH_NOT_COVERED,
1049 ERRSRV, ERRbadpath);
1052 reply_nterror(req, status);
1056 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1057 if (oplock_request) {
1058 oplock_request |= (flags & REQUEST_BATCH_OPLOCK)
1062 status = SMB_VFS_CREATE_FILE(
1065 root_dir_fid, /* root_dir_fid */
1066 smb_fname, /* fname */
1067 access_mask, /* access_mask */
1068 share_access, /* share_access */
1069 create_disposition, /* create_disposition*/
1070 create_options, /* create_options */
1071 file_attributes, /* file_attributes */
1072 oplock_request, /* oplock_request */
1073 allocation_size, /* allocation_size */
1075 ea_list, /* ea_list */
1079 if(!NT_STATUS_IS_OK(status)) {
1080 if (open_was_deferred(req->mid)) {
1081 /* We have re-scheduled this call, no error. */
1084 reply_openerror(req, status);
1089 * If the caller set the extended oplock request bit
1090 * and we granted one (by whatever means) - set the
1091 * correct bit for extended oplock reply.
1094 if (oplock_request &&
1095 (lp_fake_oplocks(SNUM(conn))
1096 || EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))) {
1099 * Exclusive oplock granted
1102 if (flags & REQUEST_BATCH_OPLOCK) {
1103 oplock_granted = BATCH_OPLOCK_RETURN;
1105 oplock_granted = EXCLUSIVE_OPLOCK_RETURN;
1107 } else if (fsp->oplock_type == LEVEL_II_OPLOCK) {
1108 oplock_granted = LEVEL_II_OPLOCK_RETURN;
1110 oplock_granted = NO_OPLOCK_RETURN;
1113 file_len = smb_fname->st.st_ex_size;
1114 fattr = dos_mode(conn, smb_fname);
1116 fattr = FILE_ATTRIBUTE_NORMAL;
1119 /* Realloc the size of parameters and data we will return */
1120 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1121 /* Extended response is 32 more byyes. */
1126 params = nttrans_realloc(ppparams, param_len);
1127 if(params == NULL) {
1128 reply_doserror(req, ERRDOS, ERRnomem);
1133 SCVAL(p, 0, oplock_granted);
1136 SSVAL(p,0,fsp->fnum);
1138 if ((create_disposition == FILE_SUPERSEDE)
1139 && (info == FILE_WAS_OVERWRITTEN)) {
1140 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1146 /* Deal with other possible opens having a modified
1148 ZERO_STRUCT(write_time_ts);
1149 get_file_infos(fsp->file_id, NULL, &write_time_ts);
1150 if (!null_timespec(write_time_ts)) {
1151 update_stat_ex_mtime(&smb_fname->st, write_time_ts);
1155 c_timespec = smb_fname->st.st_ex_btime;
1156 a_timespec = smb_fname->st.st_ex_atime;
1157 m_timespec = smb_fname->st.st_ex_mtime;
1159 if (lp_dos_filetime_resolution(SNUM(conn))) {
1160 dos_filetime_timespec(&c_timespec);
1161 dos_filetime_timespec(&a_timespec);
1162 dos_filetime_timespec(&m_timespec);
1165 put_long_date_timespec(p, c_timespec); /* create time. */
1167 put_long_date_timespec(p, a_timespec); /* access time */
1169 put_long_date_timespec(p, m_timespec); /* write time */
1171 put_long_date_timespec(p, m_timespec); /* change time */
1173 SIVAL(p,0,fattr); /* File Attributes. */
1175 SOFF_T(p, 0, SMB_VFS_GET_ALLOC_SIZE(conn, fsp, &smb_fname->st));
1177 SOFF_T(p,0,file_len);
1179 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1183 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1185 if (flags & EXTENDED_RESPONSE_REQUIRED) {
1188 if (fsp->is_directory ||
1189 can_write_to_file(conn, smb_fname)) {
1190 perms = FILE_GENERIC_ALL;
1192 perms = FILE_GENERIC_READ|FILE_EXECUTE;
1197 DEBUG(5,("call_nt_transact_create: open name = %s\n",
1198 smb_fname_str_dbg(smb_fname)));
1200 /* Send the required number of replies */
1201 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len, *ppdata, 0);
1203 TALLOC_FREE(smb_fname);
1207 /****************************************************************************
1208 Reply to a NT CANCEL request.
1209 conn POINTER CAN BE NULL HERE !
1210 ****************************************************************************/
1212 void reply_ntcancel(struct smb_request *req)
1215 * Go through and cancel any pending change notifies.
1218 START_PROFILE(SMBntcancel);
1219 srv_cancel_sign_response(smbd_server_conn);
1220 remove_pending_change_notify_requests_by_mid(req->mid);
1221 remove_pending_lock_requests_by_mid(req->mid);
1223 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", req->mid));
1225 END_PROFILE(SMBntcancel);
1229 /****************************************************************************
1231 ****************************************************************************/
1233 static NTSTATUS copy_internals(TALLOC_CTX *ctx,
1234 connection_struct *conn,
1235 struct smb_request *req,
1236 struct smb_filename *smb_fname_src,
1237 struct smb_filename *smb_fname_dst,
1240 files_struct *fsp1,*fsp2;
1244 NTSTATUS status = NT_STATUS_OK;
1247 if (!CAN_WRITE(conn)) {
1248 status = NT_STATUS_MEDIA_WRITE_PROTECTED;
1252 /* Source must already exist. */
1253 if (!VALID_STAT(smb_fname_src->st)) {
1254 status = NT_STATUS_OBJECT_NAME_NOT_FOUND;
1258 /* Ensure attributes match. */
1259 fattr = dos_mode(conn, smb_fname_src);
1260 if ((fattr & ~attrs) & (aHIDDEN | aSYSTEM)) {
1261 status = NT_STATUS_NO_SUCH_FILE;
1265 /* Disallow if dst file already exists. */
1266 if (VALID_STAT(smb_fname_dst->st)) {
1267 status = NT_STATUS_OBJECT_NAME_COLLISION;
1271 /* No links from a directory. */
1272 if (S_ISDIR(smb_fname_src->st.st_ex_mode)) {
1273 status = NT_STATUS_FILE_IS_A_DIRECTORY;
1277 DEBUG(10,("copy_internals: doing file copy %s to %s\n",
1278 smb_fname_str_dbg(smb_fname_src),
1279 smb_fname_str_dbg(smb_fname_dst)));
1281 status = SMB_VFS_CREATE_FILE(
1284 0, /* root_dir_fid */
1285 smb_fname_src, /* fname */
1286 FILE_READ_DATA, /* access_mask */
1287 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1289 FILE_OPEN, /* create_disposition*/
1290 0, /* create_options */
1291 FILE_ATTRIBUTE_NORMAL, /* file_attributes */
1292 NO_OPLOCK, /* oplock_request */
1293 0, /* allocation_size */
1299 if (!NT_STATUS_IS_OK(status)) {
1303 status = SMB_VFS_CREATE_FILE(
1306 0, /* root_dir_fid */
1307 smb_fname_dst, /* fname */
1308 FILE_WRITE_DATA, /* access_mask */
1309 (FILE_SHARE_READ | FILE_SHARE_WRITE | /* share_access */
1311 FILE_CREATE, /* create_disposition*/
1312 0, /* create_options */
1313 fattr, /* file_attributes */
1314 NO_OPLOCK, /* oplock_request */
1315 0, /* allocation_size */
1321 if (!NT_STATUS_IS_OK(status)) {
1322 close_file(NULL, fsp1, ERROR_CLOSE);
1326 if (smb_fname_src->st.st_ex_size) {
1327 ret = vfs_transfer_file(fsp1, fsp2, smb_fname_src->st.st_ex_size);
1331 * As we are opening fsp1 read-only we only expect
1332 * an error on close on fsp2 if we are out of space.
1333 * Thus we don't look at the error return from the
1336 close_file(NULL, fsp1, NORMAL_CLOSE);
1338 /* Ensure the modtime is set correctly on the destination file. */
1339 set_close_write_time(fsp2, smb_fname_src->st.st_ex_mtime);
1341 status = close_file(NULL, fsp2, NORMAL_CLOSE);
1343 /* Grrr. We have to do this as open_file_ntcreate adds aARCH when it
1344 creates the file. This isn't the correct thing to do in the copy
1346 if (!parent_dirname(talloc_tos(), smb_fname_dst->base_name, &parent,
1348 status = NT_STATUS_NO_MEMORY;
1351 file_set_dosmode(conn, smb_fname_dst, fattr, parent, false);
1352 TALLOC_FREE(parent);
1354 if (ret < (SMB_OFF_T)smb_fname_src->st.st_ex_size) {
1355 status = NT_STATUS_DISK_FULL;
1359 if (!NT_STATUS_IS_OK(status)) {
1360 DEBUG(3,("copy_internals: Error %s copy file %s to %s\n",
1361 nt_errstr(status), smb_fname_str_dbg(smb_fname_src),
1362 smb_fname_str_dbg(smb_fname_dst)));
1368 /****************************************************************************
1369 Reply to a NT rename request.
1370 ****************************************************************************/
1372 void reply_ntrename(struct smb_request *req)
1374 connection_struct *conn = req->conn;
1375 struct smb_filename *smb_fname_old = NULL;
1376 struct smb_filename *smb_fname_new = NULL;
1377 char *oldname = NULL;
1378 char *newname = NULL;
1381 bool src_has_wcard = False;
1382 bool dest_has_wcard = False;
1385 TALLOC_CTX *ctx = talloc_tos();
1387 START_PROFILE(SMBntrename);
1390 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1391 END_PROFILE(SMBntrename);
1395 attrs = SVAL(req->vwv+0, 0);
1396 rename_type = SVAL(req->vwv+1, 0);
1398 p = (const char *)req->buf + 1;
1399 p += srvstr_get_path_req_wcard(ctx, req, &oldname, p, STR_TERMINATE,
1400 &status, &src_has_wcard);
1401 if (!NT_STATUS_IS_OK(status)) {
1402 reply_nterror(req, status);
1403 END_PROFILE(SMBntrename);
1407 if (ms_has_wild(oldname)) {
1408 reply_nterror(req, NT_STATUS_OBJECT_PATH_SYNTAX_BAD);
1409 END_PROFILE(SMBntrename);
1414 p += srvstr_get_path_req_wcard(ctx, req, &newname, p, STR_TERMINATE,
1415 &status, &dest_has_wcard);
1416 if (!NT_STATUS_IS_OK(status)) {
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 status = filename_convert(ctx, conn,
1440 req->flags2 & FLAGS2_DFS_PATHNAMES,
1444 if (!NT_STATUS_IS_OK(status)) {
1445 if (NT_STATUS_EQUAL(status,NT_STATUS_PATH_NOT_COVERED)) {
1446 reply_botherror(req, NT_STATUS_PATH_NOT_COVERED,
1447 ERRSRV, ERRbadpath);
1448 END_PROFILE(SMBntrename);
1451 reply_nterror(req, status);
1452 END_PROFILE(SMBntrename);
1456 /* The new name must begin with a ':' if the old name is a stream. */
1457 if (is_ntfs_stream_name(oldname) && (newname[0] != ':')) {
1458 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1459 END_PROFILE(SMBntrename);
1463 DEBUG(3,("reply_ntrename : %s -> %s\n",oldname,newname));
1465 switch(rename_type) {
1466 case RENAME_FLAG_RENAME:
1467 status = rename_internals(ctx, conn, req, oldname,
1468 newname, attrs, False, src_has_wcard,
1469 dest_has_wcard, DELETE_ACCESS);
1471 case RENAME_FLAG_HARD_LINK:
1472 if (src_has_wcard || dest_has_wcard) {
1474 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1476 status = hardlink_internals(ctx,
1482 case RENAME_FLAG_COPY:
1483 if (src_has_wcard || dest_has_wcard) {
1485 status = NT_STATUS_OBJECT_PATH_SYNTAX_BAD;
1487 status = copy_internals(ctx, conn, req,
1493 case RENAME_FLAG_MOVE_CLUSTER_INFORMATION:
1494 status = NT_STATUS_INVALID_PARAMETER;
1497 status = NT_STATUS_ACCESS_DENIED; /* Default error. */
1501 if (!NT_STATUS_IS_OK(status)) {
1502 if (open_was_deferred(req->mid)) {
1503 /* We have re-scheduled this call. */
1504 END_PROFILE(SMBntrename);
1508 reply_nterror(req, status);
1509 END_PROFILE(SMBntrename);
1513 reply_outbuf(req, 0, 0);
1515 END_PROFILE(SMBntrename);
1519 /****************************************************************************
1520 Reply to a notify change - queue the request and
1521 don't allow a directory to be opened.
1522 ****************************************************************************/
1524 static void smbd_smb1_notify_reply(struct smb_request *req,
1525 NTSTATUS error_code,
1526 uint8_t *buf, size_t len)
1528 send_nt_replies(req->conn, req, error_code, (char *)buf, len, NULL, 0);
1531 static void call_nt_transact_notify_change(connection_struct *conn,
1532 struct smb_request *req,
1536 uint32 parameter_count,
1537 char **ppdata, uint32 data_count,
1538 uint32 max_data_count,
1539 uint32 max_param_count)
1541 uint16 *setup = *ppsetup;
1547 if(setup_count < 6) {
1548 reply_doserror(req, ERRDOS, ERRbadfunc);
1552 fsp = file_fsp(req, SVAL(setup,4));
1553 filter = IVAL(setup, 0);
1554 recursive = (SVAL(setup, 6) != 0) ? True : False;
1556 DEBUG(3,("call_nt_transact_notify_change\n"));
1559 reply_doserror(req, ERRDOS, ERRbadfid);
1564 char *filter_string;
1566 if (!(filter_string = notify_filter_string(NULL, filter))) {
1567 reply_nterror(req,NT_STATUS_NO_MEMORY);
1571 DEBUG(3,("call_nt_transact_notify_change: notify change "
1572 "called on %s, filter = %s, recursive = %d\n",
1573 fsp->fsp_name, filter_string, recursive));
1575 TALLOC_FREE(filter_string);
1578 if((!fsp->is_directory) || (conn != fsp->conn)) {
1579 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1583 if (fsp->notify == NULL) {
1585 status = change_notify_create(fsp, filter, recursive);
1587 if (!NT_STATUS_IS_OK(status)) {
1588 DEBUG(10, ("change_notify_create returned %s\n",
1589 nt_errstr(status)));
1590 reply_nterror(req, status);
1595 if (fsp->notify->num_changes != 0) {
1598 * We've got changes pending, respond immediately
1602 * TODO: write a torture test to check the filtering behaviour
1606 change_notify_reply(fsp->conn, req,
1610 smbd_smb1_notify_reply);
1613 * change_notify_reply() above has independently sent its
1620 * No changes pending, queue the request
1623 status = change_notify_add_request(req,
1627 smbd_smb1_notify_reply);
1628 if (!NT_STATUS_IS_OK(status)) {
1629 reply_nterror(req, status);
1634 /****************************************************************************
1635 Reply to an NT transact rename command.
1636 ****************************************************************************/
1638 static void call_nt_transact_rename(connection_struct *conn,
1639 struct smb_request *req,
1640 uint16 **ppsetup, uint32 setup_count,
1641 char **ppparams, uint32 parameter_count,
1642 char **ppdata, uint32 data_count,
1643 uint32 max_data_count)
1645 char *params = *ppparams;
1646 char *new_name = NULL;
1647 files_struct *fsp = NULL;
1648 bool dest_has_wcard = False;
1650 TALLOC_CTX *ctx = talloc_tos();
1652 if(parameter_count < 5) {
1653 reply_doserror(req, ERRDOS, ERRbadfunc);
1657 fsp = file_fsp(req, SVAL(params, 0));
1658 if (!check_fsp(conn, req, fsp)) {
1661 srvstr_get_path_wcard(ctx, params, req->flags2, &new_name, params+4,
1662 parameter_count - 4,
1663 STR_TERMINATE, &status, &dest_has_wcard);
1664 if (!NT_STATUS_IS_OK(status)) {
1665 reply_nterror(req, status);
1670 * W2K3 ignores this request as the RAW-RENAME test
1671 * demonstrates, so we do.
1673 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1675 DEBUG(3,("nt transact rename from = %s, to = %s ignored!\n",
1676 fsp->fsp_name, new_name));
1681 /******************************************************************************
1682 Fake up a completely empty SD.
1683 *******************************************************************************/
1685 static NTSTATUS get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1689 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1691 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1692 return NT_STATUS_NO_MEMORY;
1695 return NT_STATUS_OK;
1698 /****************************************************************************
1699 Reply to query a security descriptor.
1700 ****************************************************************************/
1702 static void call_nt_transact_query_security_desc(connection_struct *conn,
1703 struct smb_request *req,
1707 uint32 parameter_count,
1710 uint32 max_data_count)
1712 char *params = *ppparams;
1713 char *data = *ppdata;
1714 SEC_DESC *psd = NULL;
1716 uint32 security_info_wanted;
1717 files_struct *fsp = NULL;
1721 if(parameter_count < 8) {
1722 reply_doserror(req, ERRDOS, ERRbadfunc);
1726 fsp = file_fsp(req, SVAL(params,0));
1728 reply_doserror(req, ERRDOS, ERRbadfid);
1732 security_info_wanted = IVAL(params,4);
1734 DEBUG(3,("call_nt_transact_query_security_desc: file = %s, info_wanted = 0x%x\n", fsp->fsp_name,
1735 (unsigned int)security_info_wanted ));
1737 params = nttrans_realloc(ppparams, 4);
1738 if(params == NULL) {
1739 reply_doserror(req, ERRDOS, ERRnomem);
1744 * Get the permissions to return.
1747 if (!lp_nt_acl_support(SNUM(conn))) {
1748 status = get_null_nt_acl(talloc_tos(), &psd);
1750 status = SMB_VFS_FGET_NT_ACL(
1751 fsp, security_info_wanted, &psd);
1753 if (!NT_STATUS_IS_OK(status)) {
1754 reply_nterror(req, status);
1758 /* If the SACL/DACL is NULL, but was requested, we mark that it is
1759 * present in the reply to match Windows behavior */
1760 if (psd->sacl == NULL &&
1761 security_info_wanted & SACL_SECURITY_INFORMATION)
1762 psd->type |= SEC_DESC_SACL_PRESENT;
1763 if (psd->dacl == NULL &&
1764 security_info_wanted & DACL_SECURITY_INFORMATION)
1765 psd->type |= SEC_DESC_DACL_PRESENT;
1767 sd_size = ndr_size_security_descriptor(psd, NULL, 0);
1769 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %lu.\n",(unsigned long)sd_size));
1771 if (DEBUGLEVEL >= 10) {
1772 DEBUG(10,("call_nt_transact_query_security_desc for file %s\n", fsp->fsp_name));
1773 NDR_PRINT_DEBUG(security_descriptor, psd);
1776 SIVAL(params,0,(uint32)sd_size);
1778 if (max_data_count < sd_size) {
1779 send_nt_replies(conn, req, NT_STATUS_BUFFER_TOO_SMALL,
1780 params, 4, *ppdata, 0);
1785 * Allocate the data we will point this at.
1788 data = nttrans_realloc(ppdata, sd_size);
1790 reply_doserror(req, ERRDOS, ERRnomem);
1794 status = marshall_sec_desc(talloc_tos(), psd,
1795 &blob.data, &blob.length);
1797 if (!NT_STATUS_IS_OK(status)) {
1798 reply_nterror(req, status);
1802 SMB_ASSERT(sd_size == blob.length);
1803 memcpy(data, blob.data, sd_size);
1805 send_nt_replies(conn, req, NT_STATUS_OK, params, 4, data, (int)sd_size);
1810 /****************************************************************************
1811 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1812 ****************************************************************************/
1814 static void call_nt_transact_set_security_desc(connection_struct *conn,
1815 struct smb_request *req,
1819 uint32 parameter_count,
1822 uint32 max_data_count)
1824 char *params= *ppparams;
1825 char *data = *ppdata;
1826 files_struct *fsp = NULL;
1827 uint32 security_info_sent = 0;
1830 if(parameter_count < 8) {
1831 reply_doserror(req, ERRDOS, ERRbadfunc);
1835 if((fsp = file_fsp(req, SVAL(params,0))) == NULL) {
1836 reply_doserror(req, ERRDOS, ERRbadfid);
1840 if(!lp_nt_acl_support(SNUM(conn))) {
1844 security_info_sent = IVAL(params,4);
1846 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1847 (unsigned int)security_info_sent ));
1849 if (data_count == 0) {
1850 reply_doserror(req, ERRDOS, ERRnoaccess);
1854 status = set_sd(fsp, (uint8 *)data, data_count, security_info_sent);
1856 if (!NT_STATUS_IS_OK(status)) {
1857 reply_nterror(req, status);
1862 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1866 /****************************************************************************
1868 ****************************************************************************/
1870 static void call_nt_transact_ioctl(connection_struct *conn,
1871 struct smb_request *req,
1872 uint16 **ppsetup, uint32 setup_count,
1873 char **ppparams, uint32 parameter_count,
1874 char **ppdata, uint32 data_count,
1875 uint32 max_data_count)
1882 char *pdata = *ppdata;
1884 if (setup_count != 8) {
1885 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1886 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
1890 function = IVAL(*ppsetup, 0);
1891 fidnum = SVAL(*ppsetup, 4);
1892 isFSctl = CVAL(*ppsetup, 6);
1893 compfilter = CVAL(*ppsetup, 7);
1895 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1896 function, fidnum, isFSctl, compfilter));
1898 fsp=file_fsp(req, fidnum);
1899 /* this check is done in each implemented function case for now
1900 because I don't want to break anything... --metze
1901 FSP_BELONGS_CONN(fsp,conn);*/
1903 SMB_PERFCOUNT_SET_IOCTL(&req->pcd, function);
1906 case FSCTL_SET_SPARSE:
1907 /* pretend this succeeded - tho strictly we should
1908 mark the file sparse (if the local fs supports it)
1909 so we can know if we need to pre-allocate or not */
1911 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1912 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
1915 case FSCTL_CREATE_OR_GET_OBJECT_ID:
1917 unsigned char objid[16];
1919 /* This should return the object-id on this file.
1920 * I think I'll make this be the inode+dev. JRA.
1923 DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fidnum));
1925 if (!fsp_belongs_conn(conn, req, fsp)) {
1930 pdata = nttrans_realloc(ppdata, data_count);
1931 if (pdata == NULL) {
1932 reply_nterror(req, NT_STATUS_NO_MEMORY);
1936 /* For backwards compatibility only store the dev/inode. */
1937 push_file_id_16(pdata, &fsp->file_id);
1938 memcpy(pdata+16,create_volume_objectid(conn,objid),16);
1939 push_file_id_16(pdata+32, &fsp->file_id);
1940 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
1945 case FSCTL_GET_REPARSE_POINT:
1946 /* pretend this fail - my winXP does it like this
1950 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1951 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1954 case FSCTL_SET_REPARSE_POINT:
1955 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1959 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1960 reply_nterror(req, NT_STATUS_NOT_A_REPARSE_POINT);
1963 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1966 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1967 * and return their volume names. If max_data_count is 16, then it is just
1968 * asking for the number of volumes and length of the combined names.
1970 * pdata is the data allocated by our caller, but that uses
1971 * total_data_count (which is 0 in our case) rather than max_data_count.
1972 * Allocate the correct amount and return the pointer to let
1973 * it be deallocated when we return.
1975 SHADOW_COPY_DATA *shadow_data = NULL;
1976 TALLOC_CTX *shadow_mem_ctx = NULL;
1977 bool labels = False;
1978 uint32 labels_data_count = 0;
1982 if (!fsp_belongs_conn(conn, req, fsp)) {
1986 if (max_data_count < 16) {
1987 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1989 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
1993 if (max_data_count > 16) {
1997 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1998 if (shadow_mem_ctx == NULL) {
1999 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
2000 reply_nterror(req, NT_STATUS_NO_MEMORY);
2004 shadow_data = TALLOC_ZERO_P(shadow_mem_ctx,SHADOW_COPY_DATA);
2005 if (shadow_data == NULL) {
2006 DEBUG(0,("TALLOC_ZERO() failed!\n"));
2007 talloc_destroy(shadow_mem_ctx);
2008 reply_nterror(req, NT_STATUS_NO_MEMORY);
2012 shadow_data->mem_ctx = shadow_mem_ctx;
2015 * Call the VFS routine to actually do the work.
2017 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
2018 talloc_destroy(shadow_data->mem_ctx);
2019 if (errno == ENOSYS) {
2020 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
2021 conn->connectpath));
2022 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2025 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
2026 conn->connectpath));
2027 reply_nterror(req, NT_STATUS_UNSUCCESSFUL);
2032 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
2037 data_count = 12+labels_data_count+4;
2040 if (max_data_count<data_count) {
2041 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
2042 max_data_count,data_count));
2043 talloc_destroy(shadow_data->mem_ctx);
2044 reply_nterror(req, NT_STATUS_BUFFER_TOO_SMALL);
2048 pdata = nttrans_realloc(ppdata, data_count);
2049 if (pdata == NULL) {
2050 talloc_destroy(shadow_data->mem_ctx);
2051 reply_nterror(req, NT_STATUS_NO_MEMORY);
2057 /* num_volumes 4 bytes */
2058 SIVAL(pdata,0,shadow_data->num_volumes);
2061 /* num_labels 4 bytes */
2062 SIVAL(pdata,4,shadow_data->num_volumes);
2065 /* needed_data_count 4 bytes */
2066 SIVAL(pdata,8,labels_data_count);
2070 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2071 shadow_data->num_volumes,fsp->fsp_name));
2072 if (labels && shadow_data->labels) {
2073 for (i=0;i<shadow_data->num_volumes;i++) {
2074 srvstr_push(pdata, req->flags2,
2075 cur_pdata, shadow_data->labels[i],
2076 2*sizeof(SHADOW_COPY_LABEL),
2077 STR_UNICODE|STR_TERMINATE);
2078 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2079 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2083 talloc_destroy(shadow_data->mem_ctx);
2085 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0,
2091 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2093 /* pretend this succeeded -
2095 * we have to send back a list with all files owned by this SID
2097 * but I have to check that --metze
2101 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2103 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2105 if (!fsp_belongs_conn(conn, req, fsp)) {
2109 /* unknown 4 bytes: this is not the length of the sid :-( */
2110 /*unknown = IVAL(pdata,0);*/
2112 sid_parse(pdata+4,sid_len,&sid);
2113 DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
2115 if (!sid_to_uid(&sid, &uid)) {
2116 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2117 sid_string_dbg(&sid),
2118 (unsigned long)sid_len));
2122 /* we can take a look at the find source :-)
2124 * find ./ -uid $uid -name '*' is what we need here
2127 * and send 4bytes len and then NULL terminated unicode strings
2130 * but I don't know how to deal with the paged results
2131 * (maybe we can hang the result anywhere in the fsp struct)
2133 * we don't send all files at once
2134 * and at the next we should *not* start from the beginning,
2135 * so we have to cache the result
2140 /* this works for now... */
2141 send_nt_replies(conn, req, NT_STATUS_OK, NULL, 0, NULL, 0);
2145 if (!logged_ioctl_message) {
2146 logged_ioctl_message = true; /* Only print this once... */
2147 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2152 reply_nterror(req, NT_STATUS_NOT_SUPPORTED);
2156 #ifdef HAVE_SYS_QUOTAS
2157 /****************************************************************************
2158 Reply to get user quota
2159 ****************************************************************************/
2161 static void call_nt_transact_get_user_quota(connection_struct *conn,
2162 struct smb_request *req,
2166 uint32 parameter_count,
2169 uint32 max_data_count)
2171 NTSTATUS nt_status = NT_STATUS_OK;
2172 char *params = *ppparams;
2173 char *pdata = *ppdata;
2175 int data_len=0,param_len=0;
2178 files_struct *fsp = NULL;
2182 bool start_enum = True;
2183 SMB_NTQUOTA_STRUCT qt;
2184 SMB_NTQUOTA_LIST *tmp_list;
2185 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2190 if (conn->server_info->utok.uid != 0) {
2191 DEBUG(1,("get_user_quota: access_denied service [%s] user "
2192 "[%s]\n", lp_servicename(SNUM(conn)),
2193 conn->server_info->unix_name));
2194 reply_doserror(req, ERRDOS, ERRnoaccess);
2199 * Ensure minimum number of parameters sent.
2202 if (parameter_count < 4) {
2203 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2204 reply_doserror(req, ERRDOS, ERRinvalidparam);
2208 /* maybe we can check the quota_fnum */
2209 fsp = file_fsp(req, SVAL(params,0));
2210 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2211 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2212 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2216 /* the NULL pointer checking for fsp->fake_file_handle->pd
2217 * is done by CHECK_NTQUOTA_HANDLE_OK()
2219 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->private_data;
2221 level = SVAL(params,2);
2223 /* unknown 12 bytes leading in params */
2226 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2227 /* seems that we should continue with the enum here --metze */
2229 if (qt_handle->quota_list!=NULL &&
2230 qt_handle->tmp_list==NULL) {
2233 free_ntquota_list(&(qt_handle->quota_list));
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);
2244 SIVAL(params,0,data_len);
2251 case TRANSACT_GET_USER_QUOTA_LIST_START:
2253 if (qt_handle->quota_list==NULL &&
2254 qt_handle->tmp_list==NULL) {
2258 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0) {
2259 reply_doserror(req, ERRSRV, ERRerror);
2263 /* Realloc the size of parameters and data we will return */
2265 params = nttrans_realloc(ppparams, param_len);
2266 if(params == NULL) {
2267 reply_doserror(req, ERRDOS, ERRnomem);
2271 /* we should not trust the value in max_data_count*/
2272 max_data_count = MIN(max_data_count,2048);
2274 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2276 reply_doserror(req, ERRDOS, ERRnomem);
2282 /* set params Size of returned Quota Data 4 bytes*/
2283 /* but set it later when we know it */
2285 /* for each entry push the data */
2288 qt_handle->tmp_list = qt_handle->quota_list;
2291 tmp_list = qt_handle->tmp_list;
2293 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2294 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2296 sid_len = ndr_size_dom_sid(
2297 &tmp_list->quotas->sid, NULL, 0);
2298 entry_len = 40 + sid_len;
2300 /* nextoffset entry 4 bytes */
2301 SIVAL(entry,0,entry_len);
2303 /* then the len of the SID 4 bytes */
2304 SIVAL(entry,4,sid_len);
2306 /* unknown data 8 bytes uint64_t */
2307 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-metze*/
2309 /* the used disk space 8 bytes uint64_t */
2310 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2312 /* the soft quotas 8 bytes uint64_t */
2313 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2315 /* the hard quotas 8 bytes uint64_t */
2316 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2318 /* and now the SID */
2319 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2322 qt_handle->tmp_list = tmp_list;
2324 /* overwrite the offset of the last entry */
2325 SIVAL(entry-entry_len,0,0);
2327 data_len = 4+qt_len;
2328 /* overwrite the params quota_data_len */
2329 SIVAL(params,0,data_len);
2333 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2335 /* unknown 4 bytes IVAL(pdata,0) */
2337 if (data_count < 8) {
2338 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2339 reply_doserror(req, ERRDOS, ERRunknownlevel);
2343 sid_len = IVAL(pdata,4);
2344 /* Ensure this is less than 1mb. */
2345 if (sid_len > (1024*1024)) {
2346 reply_doserror(req, ERRDOS, ERRnomem);
2350 if (data_count < 8+sid_len) {
2351 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2352 reply_doserror(req, ERRDOS, ERRunknownlevel);
2356 data_len = 4+40+sid_len;
2358 if (max_data_count < data_len) {
2359 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2360 max_data_count, data_len));
2362 SIVAL(params,0,data_len);
2364 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2368 sid_parse(pdata+8,sid_len,&sid);
2370 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2373 * we have to return zero's in all fields
2374 * instead of returning an error here
2379 /* Realloc the size of parameters and data we will return */
2381 params = nttrans_realloc(ppparams, param_len);
2382 if(params == NULL) {
2383 reply_doserror(req, ERRDOS, ERRnomem);
2387 pdata = nttrans_realloc(ppdata, data_len);
2389 reply_doserror(req, ERRDOS, ERRnomem);
2395 /* set params Size of returned Quota Data 4 bytes*/
2396 SIVAL(params,0,data_len);
2398 /* nextoffset entry 4 bytes */
2401 /* then the len of the SID 4 bytes */
2402 SIVAL(entry,4,sid_len);
2404 /* unknown data 8 bytes uint64_t */
2405 SBIG_UINT(entry,8,(uint64_t)0); /* this is not 0 in windows...-mezte*/
2407 /* the used disk space 8 bytes uint64_t */
2408 SBIG_UINT(entry,16,qt.usedspace);
2410 /* the soft quotas 8 bytes uint64_t */
2411 SBIG_UINT(entry,24,qt.softlim);
2413 /* the hard quotas 8 bytes uint64_t */
2414 SBIG_UINT(entry,32,qt.hardlim);
2416 /* and now the SID */
2417 sid_linearize(entry+40, sid_len, &sid);
2422 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2423 reply_doserror(req, ERRSRV, ERRerror);
2428 send_nt_replies(conn, req, nt_status, params, param_len,
2432 /****************************************************************************
2433 Reply to set user quota
2434 ****************************************************************************/
2436 static void call_nt_transact_set_user_quota(connection_struct *conn,
2437 struct smb_request *req,
2441 uint32 parameter_count,
2444 uint32 max_data_count)
2446 char *params = *ppparams;
2447 char *pdata = *ppdata;
2448 int data_len=0,param_len=0;
2449 SMB_NTQUOTA_STRUCT qt;
2452 files_struct *fsp = NULL;
2457 if (conn->server_info->utok.uid != 0) {
2458 DEBUG(1,("set_user_quota: access_denied service [%s] user "
2459 "[%s]\n", lp_servicename(SNUM(conn)),
2460 conn->server_info->unix_name));
2461 reply_doserror(req, ERRDOS, ERRnoaccess);
2466 * Ensure minimum number of parameters sent.
2469 if (parameter_count < 2) {
2470 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2471 reply_doserror(req, ERRDOS, ERRinvalidparam);
2475 /* maybe we can check the quota_fnum */
2476 fsp = file_fsp(req, SVAL(params,0));
2477 if (!check_fsp_ntquota_handle(conn, req, fsp)) {
2478 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2479 reply_nterror(req, NT_STATUS_INVALID_HANDLE);
2483 if (data_count < 40) {
2484 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2485 reply_doserror(req, ERRDOS, ERRunknownlevel);
2489 /* offset to next quota record.
2490 * 4 bytes IVAL(pdata,0)
2495 sid_len = IVAL(pdata,4);
2497 if (data_count < 40+sid_len) {
2498 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2499 reply_doserror(req, ERRDOS, ERRunknownlevel);
2503 /* unknown 8 bytes in pdata
2504 * maybe its the change time in NTTIME
2507 /* the used space 8 bytes (uint64_t)*/
2508 qt.usedspace = (uint64_t)IVAL(pdata,16);
2509 #ifdef LARGE_SMB_OFF_T
2510 qt.usedspace |= (((uint64_t)IVAL(pdata,20)) << 32);
2511 #else /* LARGE_SMB_OFF_T */
2512 if ((IVAL(pdata,20) != 0)&&
2513 ((qt.usedspace != 0xFFFFFFFF)||
2514 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2515 /* more than 32 bits? */
2516 reply_doserror(req, ERRDOS, ERRunknownlevel);
2519 #endif /* LARGE_SMB_OFF_T */
2521 /* the soft quotas 8 bytes (uint64_t)*/
2522 qt.softlim = (uint64_t)IVAL(pdata,24);
2523 #ifdef LARGE_SMB_OFF_T
2524 qt.softlim |= (((uint64_t)IVAL(pdata,28)) << 32);
2525 #else /* LARGE_SMB_OFF_T */
2526 if ((IVAL(pdata,28) != 0)&&
2527 ((qt.softlim != 0xFFFFFFFF)||
2528 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2529 /* more than 32 bits? */
2530 reply_doserror(req, ERRDOS, ERRunknownlevel);
2533 #endif /* LARGE_SMB_OFF_T */
2535 /* the hard quotas 8 bytes (uint64_t)*/
2536 qt.hardlim = (uint64_t)IVAL(pdata,32);
2537 #ifdef LARGE_SMB_OFF_T
2538 qt.hardlim |= (((uint64_t)IVAL(pdata,36)) << 32);
2539 #else /* LARGE_SMB_OFF_T */
2540 if ((IVAL(pdata,36) != 0)&&
2541 ((qt.hardlim != 0xFFFFFFFF)||
2542 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2543 /* more than 32 bits? */
2544 reply_doserror(req, ERRDOS, ERRunknownlevel);
2547 #endif /* LARGE_SMB_OFF_T */
2549 sid_parse(pdata+40,sid_len,&sid);
2550 DEBUGADD(8,("SID: %s\n", sid_string_dbg(&sid)));
2552 /* 44 unknown bytes left... */
2554 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2555 reply_doserror(req, ERRSRV, ERRerror);
2559 send_nt_replies(conn, req, NT_STATUS_OK, params, param_len,
2562 #endif /* HAVE_SYS_QUOTAS */
2564 static void handle_nttrans(connection_struct *conn,
2565 struct trans_state *state,
2566 struct smb_request *req)
2568 if (Protocol >= PROTOCOL_NT1) {
2569 req->flags2 |= 0x40; /* IS_LONG_NAME */
2570 SSVAL(req->inbuf,smb_flg2,req->flags2);
2574 SMB_PERFCOUNT_SET_SUBOP(&req->pcd, state->call);
2576 /* Now we must call the relevant NT_TRANS function */
2577 switch(state->call) {
2578 case NT_TRANSACT_CREATE:
2580 START_PROFILE(NT_transact_create);
2581 call_nt_transact_create(
2583 &state->setup, state->setup_count,
2584 &state->param, state->total_param,
2585 &state->data, state->total_data,
2586 state->max_data_return);
2587 END_PROFILE(NT_transact_create);
2591 case NT_TRANSACT_IOCTL:
2593 START_PROFILE(NT_transact_ioctl);
2594 call_nt_transact_ioctl(
2596 &state->setup, state->setup_count,
2597 &state->param, state->total_param,
2598 &state->data, state->total_data,
2599 state->max_data_return);
2600 END_PROFILE(NT_transact_ioctl);
2604 case NT_TRANSACT_SET_SECURITY_DESC:
2606 START_PROFILE(NT_transact_set_security_desc);
2607 call_nt_transact_set_security_desc(
2609 &state->setup, state->setup_count,
2610 &state->param, state->total_param,
2611 &state->data, state->total_data,
2612 state->max_data_return);
2613 END_PROFILE(NT_transact_set_security_desc);
2617 case NT_TRANSACT_NOTIFY_CHANGE:
2619 START_PROFILE(NT_transact_notify_change);
2620 call_nt_transact_notify_change(
2622 &state->setup, state->setup_count,
2623 &state->param, state->total_param,
2624 &state->data, state->total_data,
2625 state->max_data_return,
2626 state->max_param_return);
2627 END_PROFILE(NT_transact_notify_change);
2631 case NT_TRANSACT_RENAME:
2633 START_PROFILE(NT_transact_rename);
2634 call_nt_transact_rename(
2636 &state->setup, state->setup_count,
2637 &state->param, state->total_param,
2638 &state->data, state->total_data,
2639 state->max_data_return);
2640 END_PROFILE(NT_transact_rename);
2644 case NT_TRANSACT_QUERY_SECURITY_DESC:
2646 START_PROFILE(NT_transact_query_security_desc);
2647 call_nt_transact_query_security_desc(
2649 &state->setup, state->setup_count,
2650 &state->param, state->total_param,
2651 &state->data, state->total_data,
2652 state->max_data_return);
2653 END_PROFILE(NT_transact_query_security_desc);
2657 #ifdef HAVE_SYS_QUOTAS
2658 case NT_TRANSACT_GET_USER_QUOTA:
2660 START_PROFILE(NT_transact_get_user_quota);
2661 call_nt_transact_get_user_quota(
2663 &state->setup, state->setup_count,
2664 &state->param, state->total_param,
2665 &state->data, state->total_data,
2666 state->max_data_return);
2667 END_PROFILE(NT_transact_get_user_quota);
2671 case NT_TRANSACT_SET_USER_QUOTA:
2673 START_PROFILE(NT_transact_set_user_quota);
2674 call_nt_transact_set_user_quota(
2676 &state->setup, state->setup_count,
2677 &state->param, state->total_param,
2678 &state->data, state->total_data,
2679 state->max_data_return);
2680 END_PROFILE(NT_transact_set_user_quota);
2683 #endif /* HAVE_SYS_QUOTAS */
2686 /* Error in request */
2687 DEBUG(0,("handle_nttrans: Unknown request %d in "
2688 "nttrans call\n", state->call));
2689 reply_doserror(req, ERRSRV, ERRerror);
2695 /****************************************************************************
2696 Reply to a SMBNTtrans.
2697 ****************************************************************************/
2699 void reply_nttrans(struct smb_request *req)
2701 connection_struct *conn = req->conn;
2706 uint16 function_code;
2708 struct trans_state *state;
2710 START_PROFILE(SMBnttrans);
2712 if (req->wct < 19) {
2713 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2714 END_PROFILE(SMBnttrans);
2718 pscnt = IVAL(req->vwv+9, 1);
2719 psoff = IVAL(req->vwv+11, 1);
2720 dscnt = IVAL(req->vwv+13, 1);
2721 dsoff = IVAL(req->vwv+15, 1);
2722 function_code = SVAL(req->vwv+18, 0);
2724 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2725 reply_doserror(req, ERRSRV, ERRaccess);
2726 END_PROFILE(SMBnttrans);
2730 result = allow_new_trans(conn->pending_trans, req->mid);
2731 if (!NT_STATUS_IS_OK(result)) {
2732 DEBUG(2, ("Got invalid nttrans request: %s\n", nt_errstr(result)));
2733 reply_nterror(req, result);
2734 END_PROFILE(SMBnttrans);
2738 if ((state = TALLOC_P(conn, struct trans_state)) == NULL) {
2739 reply_doserror(req, ERRSRV, ERRaccess);
2740 END_PROFILE(SMBnttrans);
2744 state->cmd = SMBnttrans;
2746 state->mid = req->mid;
2747 state->vuid = req->vuid;
2748 state->total_data = IVAL(req->vwv+3, 1);
2750 state->total_param = IVAL(req->vwv+1, 1);
2751 state->param = NULL;
2752 state->max_data_return = IVAL(req->vwv+7, 1);
2753 state->max_param_return = IVAL(req->vwv+5, 1);
2755 /* setup count is in *words* */
2756 state->setup_count = 2*CVAL(req->vwv+17, 1);
2757 state->setup = NULL;
2758 state->call = function_code;
2760 DEBUG(10, ("num_setup=%u, "
2761 "param_total=%u, this_param=%u, max_param=%u, "
2762 "data_total=%u, this_data=%u, max_data=%u, "
2763 "param_offset=%u, data_offset=%u\n",
2764 (unsigned)state->setup_count,
2765 (unsigned)state->total_param, (unsigned)pscnt,
2766 (unsigned)state->max_param_return,
2767 (unsigned)state->total_data, (unsigned)dscnt,
2768 (unsigned)state->max_data_return,
2769 (unsigned)psoff, (unsigned)dsoff));
2772 * All nttrans messages we handle have smb_wct == 19 +
2773 * state->setup_count. Ensure this is so as a sanity check.
2776 if(req->wct != 19 + (state->setup_count/2)) {
2777 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2778 req->wct, 19 + (state->setup_count/2)));
2782 /* Don't allow more than 128mb for each value. */
2783 if ((state->total_data > (1024*1024*128)) ||
2784 (state->total_param > (1024*1024*128))) {
2785 reply_doserror(req, ERRDOS, ERRnomem);
2786 END_PROFILE(SMBnttrans);
2790 if ((dscnt > state->total_data) || (pscnt > state->total_param))
2793 if (state->total_data) {
2795 if (trans_oob(state->total_data, 0, dscnt)
2796 || trans_oob(smb_len(req->inbuf), dsoff, dscnt)) {
2800 /* Can't use talloc here, the core routines do realloc on the
2801 * params and data. */
2802 if ((state->data = (char *)SMB_MALLOC(state->total_data)) == NULL) {
2803 DEBUG(0,("reply_nttrans: data malloc fail for %u "
2804 "bytes !\n", (unsigned int)state->total_data));
2806 reply_doserror(req, ERRDOS, ERRnomem);
2807 END_PROFILE(SMBnttrans);
2811 memcpy(state->data,smb_base(req->inbuf)+dsoff,dscnt);
2814 if (state->total_param) {
2816 if (trans_oob(state->total_param, 0, pscnt)
2817 || trans_oob(smb_len(req->inbuf), psoff, pscnt)) {
2821 /* Can't use talloc here, the core routines do realloc on the
2822 * params and data. */
2823 if ((state->param = (char *)SMB_MALLOC(state->total_param)) == NULL) {
2824 DEBUG(0,("reply_nttrans: param malloc fail for %u "
2825 "bytes !\n", (unsigned int)state->total_param));
2826 SAFE_FREE(state->data);
2828 reply_doserror(req, ERRDOS, ERRnomem);
2829 END_PROFILE(SMBnttrans);
2833 memcpy(state->param,smb_base(req->inbuf)+psoff,pscnt);
2836 state->received_data = dscnt;
2837 state->received_param = pscnt;
2839 if(state->setup_count > 0) {
2840 DEBUG(10,("reply_nttrans: state->setup_count = %d\n",
2841 state->setup_count));
2844 * No overflow possible here, state->setup_count is an
2845 * unsigned int, being filled by a single byte from
2846 * CVAL(req->vwv+13, 0) above. The cast in the comparison
2847 * below is not necessary, it's here to clarify things. The
2848 * validity of req->vwv and req->wct has been checked in
2849 * init_smb_request already.
2851 if ((state->setup_count/2) + 19 > (unsigned int)req->wct) {
2855 state->setup = (uint16 *)TALLOC(state, state->setup_count);
2856 if (state->setup == NULL) {
2857 DEBUG(0,("reply_nttrans : Out of memory\n"));
2858 SAFE_FREE(state->data);
2859 SAFE_FREE(state->param);
2861 reply_doserror(req, ERRDOS, ERRnomem);
2862 END_PROFILE(SMBnttrans);
2866 memcpy(state->setup, req->vwv+19, state->setup_count);
2867 dump_data(10, (uint8 *)state->setup, state->setup_count);
2870 if ((state->received_data == state->total_data) &&
2871 (state->received_param == state->total_param)) {
2872 handle_nttrans(conn, state, req);
2873 SAFE_FREE(state->param);
2874 SAFE_FREE(state->data);
2876 END_PROFILE(SMBnttrans);
2880 DLIST_ADD(conn->pending_trans, state);
2882 /* We need to send an interim response then receive the rest
2883 of the parameter/data bytes */
2884 reply_outbuf(req, 0, 0);
2885 show_msg((char *)req->outbuf);
2886 END_PROFILE(SMBnttrans);
2891 DEBUG(0,("reply_nttrans: invalid trans parameters\n"));
2892 SAFE_FREE(state->data);
2893 SAFE_FREE(state->param);
2895 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2896 END_PROFILE(SMBnttrans);
2900 /****************************************************************************
2901 Reply to a SMBnttranss
2902 ****************************************************************************/
2904 void reply_nttranss(struct smb_request *req)
2906 connection_struct *conn = req->conn;
2907 uint32_t pcnt,poff,dcnt,doff,pdisp,ddisp;
2908 struct trans_state *state;
2910 START_PROFILE(SMBnttranss);
2912 show_msg((char *)req->inbuf);
2914 if (req->wct < 18) {
2915 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2916 END_PROFILE(SMBnttranss);
2920 for (state = conn->pending_trans; state != NULL;
2921 state = state->next) {
2922 if (state->mid == req->mid) {
2927 if ((state == NULL) || (state->cmd != SMBnttrans)) {
2928 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2929 END_PROFILE(SMBnttranss);
2933 /* Revise state->total_param and state->total_data in case they have
2934 changed downwards */
2935 if (IVAL(req->vwv+1, 1) < state->total_param) {
2936 state->total_param = IVAL(req->vwv+1, 1);
2938 if (IVAL(req->vwv+3, 1) < state->total_data) {
2939 state->total_data = IVAL(req->vwv+3, 1);
2942 pcnt = IVAL(req->vwv+5, 1);
2943 poff = IVAL(req->vwv+7, 1);
2944 pdisp = IVAL(req->vwv+9, 1);
2946 dcnt = IVAL(req->vwv+11, 1);
2947 doff = IVAL(req->vwv+13, 1);
2948 ddisp = IVAL(req->vwv+15, 1);
2950 state->received_param += pcnt;
2951 state->received_data += dcnt;
2953 if ((state->received_data > state->total_data) ||
2954 (state->received_param > state->total_param))
2958 if (trans_oob(state->total_param, pdisp, pcnt)
2959 || trans_oob(smb_len(req->inbuf), poff, pcnt)) {
2962 memcpy(state->param+pdisp, smb_base(req->inbuf)+poff,pcnt);
2966 if (trans_oob(state->total_data, ddisp, dcnt)
2967 || trans_oob(smb_len(req->inbuf), doff, dcnt)) {
2970 memcpy(state->data+ddisp, smb_base(req->inbuf)+doff,dcnt);
2973 if ((state->received_param < state->total_param) ||
2974 (state->received_data < state->total_data)) {
2975 END_PROFILE(SMBnttranss);
2979 handle_nttrans(conn, state, req);
2981 DLIST_REMOVE(conn->pending_trans, state);
2982 SAFE_FREE(state->data);
2983 SAFE_FREE(state->param);
2985 END_PROFILE(SMBnttranss);
2990 DEBUG(0,("reply_nttranss: invalid trans parameters\n"));
2991 DLIST_REMOVE(conn->pending_trans, state);
2992 SAFE_FREE(state->data);
2993 SAFE_FREE(state->param);
2995 reply_nterror(req, NT_STATUS_INVALID_PARAMETER);
2996 END_PROFILE(SMBnttranss);