missed one on BUG 1195; make sure to set the private * to NULL
[Samba/gebeck_regimport.git] / source3 / smbd / nttrans.c
blob21b6db8b4691df241f484779a15c7811b614d49b
1 /*
2 Unix SMB/CIFS implementation.
3 SMB NT transaction handling
4 Copyright (C) Jeremy Allison 1994-1998
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
24 extern int Protocol;
25 extern int smb_read_error;
26 extern int global_oplock_break;
27 extern BOOL case_sensitive;
28 extern BOOL case_preserve;
29 extern BOOL short_case_preserve;
30 extern struct current_user current_user;
32 static const char *known_nt_pipes[] = {
33 "\\LANMAN",
34 "\\srvsvc",
35 "\\samr",
36 "\\wkssvc",
37 "\\NETLOGON",
38 "\\ntlsa",
39 "\\ntsvcs",
40 "\\lsass",
41 "\\lsarpc",
42 "\\winreg",
43 "\\spoolss",
44 "\\netdfs",
45 "\\rpcecho",
46 NULL
49 /* Map generic permissions to file object specific permissions */
51 struct generic_mapping file_generic_mapping = {
52 FILE_GENERIC_READ,
53 FILE_GENERIC_WRITE,
54 FILE_GENERIC_EXECUTE,
55 FILE_GENERIC_ALL
58 static char *nttrans_realloc(char **ptr, size_t size)
60 char *tptr = NULL;
61 if (ptr==NULL)
62 smb_panic("nttrans_realloc() called with NULL ptr\n");
64 tptr = Realloc_zero(*ptr, size);
65 if(tptr == NULL) {
66 *ptr = NULL;
67 return NULL;
70 *ptr = tptr;
72 return tptr;
76 /****************************************************************************
77 Send the required number of replies back.
78 We assume all fields other than the data fields are
79 set correctly for the type of call.
80 HACK ! Always assumes smb_setup field is zero.
81 ****************************************************************************/
83 static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, NTSTATUS nt_error, char *params,
84 int paramsize, char *pdata, int datasize)
86 extern int max_send;
87 int data_to_send = datasize;
88 int params_to_send = paramsize;
89 int useable_space;
90 char *pp = params;
91 char *pd = pdata;
92 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
93 int alignment_offset = 3;
94 int data_alignment_offset = 0;
97 * Initially set the wcnt area to be 18 - this is true for all
98 * transNT replies.
101 set_message(outbuf,18,0,True);
103 if (NT_STATUS_V(nt_error))
104 ERROR_NT(nt_error);
107 * If there genuinely are no parameters or data to send just send
108 * the empty packet.
111 if(params_to_send == 0 && data_to_send == 0) {
112 if (!send_smb(smbd_server_fd(),outbuf))
113 exit_server("send_nt_replies: send_smb failed.");
114 return 0;
118 * When sending params and data ensure that both are nicely aligned.
119 * Only do this alignment when there is also data to send - else
120 * can cause NT redirector problems.
123 if (((params_to_send % 4) != 0) && (data_to_send != 0))
124 data_alignment_offset = 4 - (params_to_send % 4);
127 * Space is bufsize minus Netbios over TCP header minus SMB header.
128 * The alignment_offset is to align the param bytes on a four byte
129 * boundary (2 bytes for data len, one byte pad).
130 * NT needs this to work correctly.
133 useable_space = bufsize - ((smb_buf(outbuf)+
134 alignment_offset+data_alignment_offset) -
135 outbuf);
138 * useable_space can never be more than max_send minus the
139 * alignment offset.
142 useable_space = MIN(useable_space,
143 max_send - (alignment_offset+data_alignment_offset));
146 while (params_to_send || data_to_send) {
149 * Calculate whether we will totally or partially fill this packet.
152 total_sent_thistime = params_to_send + data_to_send +
153 alignment_offset + data_alignment_offset;
156 * We can never send more than useable_space.
159 total_sent_thistime = MIN(total_sent_thistime, useable_space);
161 set_message(outbuf, 18, total_sent_thistime, True);
164 * Set total params and data to be sent.
167 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
168 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
171 * Calculate how many parameters and data we can fit into
172 * this packet. Parameters get precedence.
175 params_sent_thistime = MIN(params_to_send,useable_space);
176 data_sent_thistime = useable_space - params_sent_thistime;
177 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
179 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
181 if(params_sent_thistime == 0) {
182 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
183 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
184 } else {
186 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
187 * parameter bytes, however the first 4 bytes of outbuf are
188 * the Netbios over TCP header. Thus use smb_base() to subtract
189 * them from the calculation.
192 SIVAL(outbuf,smb_ntr_ParameterOffset,
193 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
195 * Absolute displacement of param bytes sent in this packet.
198 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
202 * Deal with the data portion.
205 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
207 if(data_sent_thistime == 0) {
208 SIVAL(outbuf,smb_ntr_DataOffset,0);
209 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
210 } else {
212 * The offset of the data bytes is the offset of the
213 * parameter bytes plus the number of parameters being sent this time.
216 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
217 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
218 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
222 * Copy the param bytes into the packet.
225 if(params_sent_thistime)
226 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
229 * Copy in the data bytes
232 if(data_sent_thistime)
233 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
234 data_alignment_offset,pd,data_sent_thistime);
236 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
237 params_sent_thistime, data_sent_thistime, useable_space));
238 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
239 params_to_send, data_to_send, paramsize, datasize));
241 /* Send the packet */
242 if (!send_smb(smbd_server_fd(),outbuf))
243 exit_server("send_nt_replies: send_smb failed.");
245 pp += params_sent_thistime;
246 pd += data_sent_thistime;
248 params_to_send -= params_sent_thistime;
249 data_to_send -= data_sent_thistime;
252 * Sanity check
255 if(params_to_send < 0 || data_to_send < 0) {
256 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
257 params_to_send, data_to_send));
258 return -1;
262 return 0;
265 /****************************************************************************
266 Save case statics.
267 ****************************************************************************/
269 static BOOL saved_case_sensitive;
270 static BOOL saved_case_preserve;
271 static BOOL saved_short_case_preserve;
273 /****************************************************************************
274 Save case semantics.
275 ****************************************************************************/
277 static void set_posix_case_semantics(uint32 file_attributes)
279 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS))
280 return;
282 saved_case_sensitive = case_sensitive;
283 saved_case_preserve = case_preserve;
284 saved_short_case_preserve = short_case_preserve;
286 /* Set to POSIX. */
287 case_sensitive = True;
288 case_preserve = True;
289 short_case_preserve = True;
292 /****************************************************************************
293 Restore case semantics.
294 ****************************************************************************/
296 static void restore_case_semantics(uint32 file_attributes)
298 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS))
299 return;
301 case_sensitive = saved_case_sensitive;
302 case_preserve = saved_case_preserve;
303 short_case_preserve = saved_short_case_preserve;
306 /****************************************************************************
307 Utility function to map create disposition.
308 ****************************************************************************/
310 static int map_create_disposition( uint32 create_disposition)
312 int ret;
314 switch( create_disposition ) {
315 case FILE_CREATE:
316 /* create if not exist, fail if exist */
317 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_FAIL);
318 break;
319 case FILE_SUPERSEDE:
320 case FILE_OVERWRITE_IF:
321 /* create if not exist, trunc if exist */
322 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
323 break;
324 case FILE_OPEN:
325 /* fail if not exist, open if exists */
326 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN);
327 break;
328 case FILE_OPEN_IF:
329 /* create if not exist, open if exists */
330 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_OPEN);
331 break;
332 case FILE_OVERWRITE:
333 /* fail if not exist, truncate if exists */
334 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
335 break;
336 default:
337 DEBUG(0,("map_create_disposition: Incorrect value for create_disposition = %d\n",
338 create_disposition ));
339 return -1;
342 DEBUG(10,("map_create_disposition: Mapped create_disposition 0x%lx to 0x%x\n",
343 (unsigned long)create_disposition, ret ));
345 return ret;
348 /****************************************************************************
349 Utility function to map share modes.
350 ****************************************************************************/
352 static int map_share_mode( char *fname, uint32 create_options,
353 uint32 *desired_access, uint32 share_access, uint32 file_attributes)
355 int smb_open_mode = -1;
356 uint32 original_desired_access = *desired_access;
359 * Convert GENERIC bits to specific bits.
362 se_map_generic(desired_access, &file_generic_mapping);
364 switch( *desired_access & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA) ) {
365 case FILE_READ_DATA:
366 smb_open_mode = DOS_OPEN_RDONLY;
367 break;
368 case FILE_WRITE_DATA:
369 case FILE_APPEND_DATA:
370 case FILE_WRITE_DATA|FILE_APPEND_DATA:
371 smb_open_mode = DOS_OPEN_WRONLY;
372 break;
373 case FILE_READ_DATA|FILE_WRITE_DATA:
374 case FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA:
375 case FILE_READ_DATA|FILE_APPEND_DATA:
376 smb_open_mode = DOS_OPEN_RDWR;
377 break;
381 * NB. For DELETE_ACCESS we should really check the
382 * directory permissions, as that is what controls
383 * delete, and for WRITE_DAC_ACCESS we should really
384 * check the ownership, as that is what controls the
385 * chmod. Note that this is *NOT* a security hole (this
386 * note is for you, Andrew) as we are not *allowing*
387 * the access at this point, the actual unlink or
388 * chown or chmod call would do this. We are just helping
389 * clients out by telling them if they have a hope
390 * of any of this succeeding. POSIX acls may still
391 * deny the real call. JRA.
394 if (smb_open_mode == -1) {
396 if(*desired_access & (DELETE_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS|SYNCHRONIZE_ACCESS|
397 FILE_EXECUTE|FILE_READ_ATTRIBUTES|
398 FILE_READ_EA|FILE_WRITE_EA|SYSTEM_SECURITY_ACCESS|
399 FILE_WRITE_ATTRIBUTES|READ_CONTROL_ACCESS)) {
400 smb_open_mode = DOS_OPEN_RDONLY;
401 } else if(*desired_access == 0) {
404 * JRA - NT seems to sometimes send desired_access as zero. play it safe
405 * and map to a stat open.
408 smb_open_mode = DOS_OPEN_RDONLY;
410 } else {
411 DEBUG(0,("map_share_mode: Incorrect value 0x%lx for desired_access to file %s\n",
412 (unsigned long)*desired_access, fname));
413 return -1;
418 * Set the special bit that means allow share delete.
419 * This is held outside the normal share mode bits at 1<<15.
420 * JRA.
423 if(share_access & FILE_SHARE_DELETE) {
424 smb_open_mode |= ALLOW_SHARE_DELETE;
425 DEBUG(10,("map_share_mode: FILE_SHARE_DELETE requested. open_mode = 0x%x\n", smb_open_mode));
428 if(*desired_access & DELETE_ACCESS) {
429 DEBUG(10,("map_share_mode: DELETE_ACCESS requested. open_mode = 0x%x\n", smb_open_mode));
433 * We need to store the intent to open for Delete. This
434 * is what determines if a delete on close flag can be set.
435 * This is the wrong way (and place) to store this, but for 2.2 this
436 * is the only practical way. JRA.
439 if (create_options & FILE_DELETE_ON_CLOSE) {
441 * W2K3 bug compatibility mode... To set delete on close
442 * the redirector must have *specifically* set DELETE_ACCESS
443 * in the desired_access field. Just asking for GENERIC_ALL won't do. JRA.
446 if (!(original_desired_access & DELETE_ACCESS)) {
447 DEBUG(5,("map_share_mode: FILE_DELETE_ON_CLOSE requested without \
448 DELETE_ACCESS for file %s. (desired_access = 0x%lx)\n",
449 fname, (unsigned long)*desired_access));
450 return -1;
452 /* Implicit delete access is *NOT* requested... */
453 smb_open_mode |= DELETE_ON_CLOSE_FLAG;
454 DEBUG(10,("map_share_mode: FILE_DELETE_ON_CLOSE requested. open_mode = 0x%x\n", smb_open_mode));
457 /* Add in the requested share mode. */
458 switch( share_access & (FILE_SHARE_READ|FILE_SHARE_WRITE)) {
459 case FILE_SHARE_READ:
460 smb_open_mode |= SET_DENY_MODE(DENY_WRITE);
461 break;
462 case FILE_SHARE_WRITE:
463 smb_open_mode |= SET_DENY_MODE(DENY_READ);
464 break;
465 case (FILE_SHARE_READ|FILE_SHARE_WRITE):
466 smb_open_mode |= SET_DENY_MODE(DENY_NONE);
467 break;
468 case FILE_SHARE_NONE:
469 smb_open_mode |= SET_DENY_MODE(DENY_ALL);
470 break;
474 * Handle an O_SYNC request.
477 if(file_attributes & FILE_FLAG_WRITE_THROUGH)
478 smb_open_mode |= FILE_SYNC_OPENMODE;
480 DEBUG(10,("map_share_mode: Mapped desired access 0x%lx, share access 0x%lx, file attributes 0x%lx \
481 to open_mode 0x%x\n", (unsigned long)*desired_access, (unsigned long)share_access,
482 (unsigned long)file_attributes, smb_open_mode ));
484 return smb_open_mode;
487 /****************************************************************************
488 Reply to an NT create and X call on a pipe.
489 ****************************************************************************/
491 static int nt_open_pipe(char *fname, connection_struct *conn,
492 char *inbuf, char *outbuf, int *ppnum)
494 smb_np_struct *p = NULL;
496 uint16 vuid = SVAL(inbuf, smb_uid);
497 int i;
499 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
501 /* See if it is one we want to handle. */
503 if (lp_disable_spoolss() && strequal(fname, "\\spoolss"))
504 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
506 for( i = 0; known_nt_pipes[i]; i++ )
507 if( strequal(fname,known_nt_pipes[i]))
508 break;
510 if ( known_nt_pipes[i] == NULL )
511 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
513 /* Strip \\ off the name. */
514 fname++;
516 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
518 p = open_rpc_pipe_p(fname, conn, vuid);
519 if (!p)
520 return(ERROR_DOS(ERRSRV,ERRnofids));
522 *ppnum = p->pnum;
524 return 0;
527 /****************************************************************************
528 Reply to an NT create and X call for pipes.
529 ****************************************************************************/
531 static int do_ntcreate_pipe_open(connection_struct *conn,
532 char *inbuf,char *outbuf,int length,int bufsize)
534 pstring fname;
535 int ret;
536 int pnum = -1;
537 char *p = NULL;
539 srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
541 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
542 return ret;
545 * Deal with pipe return.
548 set_message(outbuf,34,0,True);
550 p = outbuf + smb_vwv2;
551 p++;
552 SSVAL(p,0,pnum);
553 p += 2;
554 SIVAL(p,0,FILE_WAS_OPENED);
555 p += 4;
556 p += 32;
557 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
558 p += 20;
559 /* File type. */
560 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
561 /* Device state. */
562 SSVAL(p,2, 0x5FF); /* ? */
564 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
566 return chain_reply(inbuf,outbuf,length,bufsize);
569 /****************************************************************************
570 Reply to an NT create and X call.
571 ****************************************************************************/
573 int reply_ntcreate_and_X(connection_struct *conn,
574 char *inbuf,char *outbuf,int length,int bufsize)
576 int result;
577 pstring fname;
578 enum FAKE_FILE_TYPE fake_file_type = FAKE_FILE_TYPE_NONE;
579 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
580 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
581 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
582 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
583 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
584 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
585 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
586 SMB_BIG_UINT allocation_size = 0;
587 int smb_ofun;
588 int smb_open_mode;
589 int smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
590 /* Breakout the oplock request bits so we can set the
591 reply bits separately. */
592 int oplock_request = 0;
593 mode_t unixmode;
594 int fmode=0,rmode=0;
595 SMB_OFF_T file_len = 0;
596 SMB_STRUCT_STAT sbuf;
597 int smb_action = 0;
598 BOOL bad_path = False;
599 files_struct *fsp=NULL;
600 char *p = NULL;
601 time_t c_time;
602 BOOL extended_oplock_granted = False;
603 NTSTATUS status;
605 START_PROFILE(SMBntcreateX);
607 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
608 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
609 create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attributes,
610 share_access, create_disposition,
611 create_options, root_dir_fid ));
613 /* If it's an IPC, use the pipe handler. */
615 if (IS_IPC(conn)) {
616 if (lp_nt_pipe_support()) {
617 END_PROFILE(SMBntcreateX);
618 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
619 } else {
620 END_PROFILE(SMBntcreateX);
621 return(ERROR_DOS(ERRDOS,ERRnoaccess));
625 if (create_options & FILE_OPEN_BY_FILE_ID) {
626 END_PROFILE(SMBntcreateX);
627 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
631 * We need to construct the open_and_X ofun value from the
632 * NT values, as that's what our code is structured to accept.
635 if((smb_ofun = map_create_disposition( create_disposition )) == -1) {
636 END_PROFILE(SMBntcreateX);
637 return(ERROR_DOS(ERRDOS,ERRnoaccess));
641 * Get the file name.
644 if(root_dir_fid != 0) {
646 * This filename is relative to a directory fid.
648 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
649 size_t dir_name_len;
651 if(!dir_fsp) {
652 END_PROFILE(SMBntcreateX);
653 return(ERROR_DOS(ERRDOS,ERRbadfid));
656 if(!dir_fsp->is_directory) {
658 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
659 if (!NT_STATUS_IS_OK(status)) {
660 END_PROFILE(SMBntcreateX);
661 return ERROR_NT(status);
665 * Check to see if this is a mac fork of some kind.
668 if( strchr_m(fname, ':')) {
669 END_PROFILE(SMBntcreateX);
670 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
674 we need to handle the case when we get a
675 relative open relative to a file and the
676 pathname is blank - this is a reopen!
677 (hint from demyn plantenberg)
680 END_PROFILE(SMBntcreateX);
681 return(ERROR_DOS(ERRDOS,ERRbadfid));
685 * Copy in the base directory name.
688 pstrcpy( fname, dir_fsp->fsp_name );
689 dir_name_len = strlen(fname);
692 * Ensure it ends in a '\'.
695 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
696 pstrcat(fname, "\\");
697 dir_name_len++;
700 srvstr_get_path(inbuf, &fname[dir_name_len], smb_buf(inbuf), sizeof(fname)-dir_name_len, 0, STR_TERMINATE, &status);
701 if (!NT_STATUS_IS_OK(status)) {
702 END_PROFILE(SMBntcreateX);
703 return ERROR_NT(status);
705 } else {
706 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), 0, STR_TERMINATE, &status);
707 if (!NT_STATUS_IS_OK(status)) {
708 END_PROFILE(SMBntcreateX);
709 return ERROR_NT(status);
713 * Check to see if this is a mac fork of some kind.
716 if( strchr_m(fname, ':')) {
718 #ifdef HAVE_SYS_QUOTAS
719 if ((fake_file_type=is_fake_file(fname))!=FAKE_FILE_TYPE_NONE) {
721 * here we go! support for changing the disk quotas --metze
723 * we need to fake up to open this MAGIC QUOTA file
724 * and return a valid FID
726 * w2k close this file directly after openening
727 * xp also tries a QUERY_FILE_INFO on the file and then close it
729 } else {
730 #endif
731 END_PROFILE(SMBntcreateX);
732 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
733 #ifdef HAVE_SYS_QUOTAS
735 #endif
740 * Now contruct the smb_open_mode value from the filename,
741 * desired access and the share access.
743 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
745 if((smb_open_mode = map_share_mode(fname, create_options, &desired_access,
746 share_access,
747 file_attributes)) == -1) {
748 END_PROFILE(SMBntcreateX);
749 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
752 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
753 if (oplock_request) {
754 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
758 * Ordinary file or directory.
762 * Check if POSIX semantics are wanted.
765 set_posix_case_semantics(file_attributes);
767 unix_convert(fname,conn,0,&bad_path,&sbuf);
769 unixmode = unix_mode(conn,smb_attr | aARCH, fname);
772 * If it's a request for a directory open, deal with it separately.
775 if(create_options & FILE_DIRECTORY_FILE) {
776 oplock_request = 0;
778 /* Can't open a temp directory. IFS kit test. */
779 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
780 END_PROFILE(SMBntcreateX);
781 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
784 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
786 restore_case_semantics(file_attributes);
788 if(!fsp) {
789 END_PROFILE(SMBntcreateX);
790 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
792 } else {
794 * Ordinary file case.
797 /* NB. We have a potential bug here. If we
798 * cause an oplock break to ourselves, then we
799 * could end up processing filename related
800 * SMB requests whilst we await the oplock
801 * break response. As we may have changed the
802 * filename case semantics to be POSIX-like,
803 * this could mean a filename request could
804 * fail when it should succeed. This is a rare
805 * condition, but eventually we must arrange
806 * to restore the correct case semantics
807 * before issuing an oplock break request to
808 * our client. JRA. */
810 if (fake_file_type==FAKE_FILE_TYPE_NONE) {
811 fsp = open_file_shared1(conn,fname,&sbuf,
812 desired_access,
813 smb_open_mode,
814 smb_ofun,unixmode, oplock_request,
815 &rmode,&smb_action);
816 } else {
817 /* to open a fake_file --metze */
818 fsp = open_fake_file_shared1(fake_file_type,conn,fname,&sbuf,
819 desired_access,
820 smb_open_mode,
821 smb_ofun,unixmode, oplock_request,
822 &rmode,&smb_action);
825 if (!fsp) {
826 /* We cheat here. There are two cases we
827 * care about. One is a directory rename,
828 * where the NT client will attempt to
829 * open the source directory for
830 * DELETE access. Note that when the
831 * NT client does this it does *not*
832 * set the directory bit in the
833 * request packet. This is translated
834 * into a read/write open
835 * request. POSIX states that any open
836 * for write request on a directory
837 * will generate an EISDIR error, so
838 * we can catch this here and open a
839 * pseudo handle that is flagged as a
840 * directory. The second is an open
841 * for a permissions read only, which
842 * we handle in the open_file_stat case. JRA.
845 if(errno == EISDIR) {
848 * Fail the open if it was explicitly a non-directory file.
851 if (create_options & FILE_NON_DIRECTORY_FILE) {
852 restore_case_semantics(file_attributes);
853 SSVAL(outbuf, smb_flg2,
854 SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
855 END_PROFILE(SMBntcreateX);
856 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
859 oplock_request = 0;
860 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
862 if(!fsp) {
863 restore_case_semantics(file_attributes);
864 END_PROFILE(SMBntcreateX);
865 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
867 } else {
869 restore_case_semantics(file_attributes);
870 END_PROFILE(SMBntcreateX);
871 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
876 restore_case_semantics(file_attributes);
878 file_len = sbuf.st_size;
879 fmode = dos_mode(conn,fname,&sbuf);
880 if(fmode == 0)
881 fmode = FILE_ATTRIBUTE_NORMAL;
882 if (!fsp->is_directory && (fmode & aDIR)) {
883 close_file(fsp,False);
884 END_PROFILE(SMBntcreateX);
885 return ERROR_DOS(ERRDOS,ERRnoaccess);
888 /* Save the requested allocation size. */
889 allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
890 #ifdef LARGE_SMB_OFF_T
891 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
892 #endif
893 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
894 fsp->initial_allocation_size = SMB_ROUNDUP(allocation_size,SMB_ROUNDUP_ALLOCATION_SIZE);
895 if (fsp->is_directory) {
896 close_file(fsp,False);
897 END_PROFILE(SMBntcreateX);
898 /* Can't set allocation size on a directory. */
899 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
901 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
902 close_file(fsp,False);
903 END_PROFILE(SMBntcreateX);
904 return ERROR_NT(NT_STATUS_DISK_FULL);
906 } else {
907 fsp->initial_allocation_size = SMB_ROUNDUP(((SMB_BIG_UINT)file_len),SMB_ROUNDUP_ALLOCATION_SIZE);
911 * If the caller set the extended oplock request bit
912 * and we granted one (by whatever means) - set the
913 * correct bit for extended oplock reply.
916 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
917 extended_oplock_granted = True;
919 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
920 extended_oplock_granted = True;
922 #if 0
923 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
924 set_message(outbuf,42,0,True);
925 #else
926 set_message(outbuf,34,0,True);
927 #endif
929 p = outbuf + smb_vwv2;
932 * Currently as we don't support level II oplocks we just report
933 * exclusive & batch here.
936 if (extended_oplock_granted) {
937 if (flags & REQUEST_BATCH_OPLOCK) {
938 SCVAL(p,0, BATCH_OPLOCK_RETURN);
939 } else {
940 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
942 } else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
943 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
944 } else {
945 SCVAL(p,0,NO_OPLOCK_RETURN);
948 p++;
949 SSVAL(p,0,fsp->fnum);
950 p += 2;
951 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
952 SIVAL(p,0,FILE_WAS_SUPERSEDED);
953 else
954 SIVAL(p,0,smb_action);
955 p += 4;
957 /* Create time. */
958 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
960 if (lp_dos_filetime_resolution(SNUM(conn))) {
961 c_time &= ~1;
962 sbuf.st_atime &= ~1;
963 sbuf.st_mtime &= ~1;
964 sbuf.st_mtime &= ~1;
967 put_long_date(p,c_time);
968 p += 8;
969 put_long_date(p,sbuf.st_atime); /* access time */
970 p += 8;
971 put_long_date(p,sbuf.st_mtime); /* write time */
972 p += 8;
973 put_long_date(p,sbuf.st_mtime); /* change time */
974 p += 8;
975 SIVAL(p,0,fmode); /* File Attributes. */
976 p += 4;
977 SOFF_T(p, 0, get_allocation_size(fsp,&sbuf));
978 p += 8;
979 SOFF_T(p,0,file_len);
980 p += 8;
981 if (flags & EXTENDED_RESPONSE_REQUIRED)
982 SSVAL(p,2,0x7);
983 p += 4;
984 SCVAL(p,0,fsp->is_directory ? 1 : 0);
986 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
988 result = chain_reply(inbuf,outbuf,length,bufsize);
989 END_PROFILE(SMBntcreateX);
990 return result;
993 /****************************************************************************
994 Reply to a NT_TRANSACT_CREATE call to open a pipe.
995 ****************************************************************************/
997 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
998 char **ppsetup, uint32 setup_count,
999 char **ppparams, uint32 parameter_count,
1000 char **ppdata, uint32 data_count)
1002 pstring fname;
1003 char *params = *ppparams;
1004 int ret;
1005 int pnum = -1;
1006 char *p = NULL;
1007 NTSTATUS status;
1010 * Ensure minimum number of parameters sent.
1013 if(parameter_count < 54) {
1014 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1015 return ERROR_DOS(ERRDOS,ERRnoaccess);
1018 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1019 if (!NT_STATUS_IS_OK(status)) {
1020 return ERROR_NT(status);
1023 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
1024 return ret;
1026 /* Realloc the size of parameters and data we will return */
1027 params = nttrans_realloc(ppparams, 69);
1028 if(params == NULL)
1029 return ERROR_DOS(ERRDOS,ERRnomem);
1031 p = params;
1032 SCVAL(p,0,NO_OPLOCK_RETURN);
1034 p += 2;
1035 SSVAL(p,0,pnum);
1036 p += 2;
1037 SIVAL(p,0,FILE_WAS_OPENED);
1038 p += 8;
1040 p += 32;
1041 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
1042 p += 20;
1043 /* File type. */
1044 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
1045 /* Device state. */
1046 SSVAL(p,2, 0x5FF); /* ? */
1048 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
1050 /* Send the required number of replies */
1051 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1053 return -1;
1056 /****************************************************************************
1057 Internal fn to set security descriptors.
1058 ****************************************************************************/
1060 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
1062 prs_struct pd;
1063 SEC_DESC *psd = NULL;
1064 TALLOC_CTX *mem_ctx;
1065 BOOL ret;
1067 if (sd_len == 0) {
1068 return NT_STATUS_OK;
1072 * Init the parse struct we will unmarshall from.
1075 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
1076 DEBUG(0,("set_sd: talloc_init failed.\n"));
1077 return NT_STATUS_NO_MEMORY;
1080 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1083 * Setup the prs_struct to point at the memory we just
1084 * allocated.
1087 prs_give_memory( &pd, data, sd_len, False);
1090 * Finally, unmarshall from the data buffer.
1093 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1094 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1096 * Return access denied for want of a better error message..
1098 talloc_destroy(mem_ctx);
1099 return NT_STATUS_NO_MEMORY;
1102 if (psd->off_owner_sid==0)
1103 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1104 if (psd->off_grp_sid==0)
1105 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1106 if (psd->off_sacl==0)
1107 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1108 if (psd->off_dacl==0)
1109 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1111 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fd, security_info_sent, psd);
1113 if (!ret) {
1114 talloc_destroy(mem_ctx);
1115 return NT_STATUS_ACCESS_DENIED;
1118 talloc_destroy(mem_ctx);
1120 return NT_STATUS_OK;
1123 /****************************************************************************
1124 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1125 ****************************************************************************/
1127 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1128 char **ppsetup, uint32 setup_count,
1129 char **ppparams, uint32 parameter_count,
1130 char **ppdata, uint32 data_count)
1132 pstring fname;
1133 char *params = *ppparams;
1134 char *data = *ppdata;
1135 /* Breakout the oplock request bits so we can set the reply bits separately. */
1136 int oplock_request = 0;
1137 mode_t unixmode;
1138 int fmode=0,rmode=0;
1139 SMB_OFF_T file_len = 0;
1140 SMB_STRUCT_STAT sbuf;
1141 int smb_action = 0;
1142 BOOL bad_path = False;
1143 files_struct *fsp = NULL;
1144 char *p = NULL;
1145 BOOL extended_oplock_granted = False;
1146 uint32 flags;
1147 uint32 desired_access;
1148 uint32 file_attributes;
1149 uint32 share_access;
1150 uint32 create_disposition;
1151 uint32 create_options;
1152 uint32 sd_len;
1153 uint16 root_dir_fid;
1154 SMB_BIG_UINT allocation_size = 0;
1155 int smb_ofun;
1156 int smb_open_mode;
1157 int smb_attr;
1158 time_t c_time;
1159 NTSTATUS status;
1161 DEBUG(5,("call_nt_transact_create\n"));
1164 * If it's an IPC, use the pipe handler.
1167 if (IS_IPC(conn)) {
1168 if (lp_nt_pipe_support())
1169 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1170 bufsize,
1171 ppsetup, setup_count,
1172 ppparams, parameter_count,
1173 ppdata, data_count);
1174 else
1175 return ERROR_DOS(ERRDOS,ERRnoaccess);
1179 * Ensure minimum number of parameters sent.
1182 if(parameter_count < 54) {
1183 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1184 return ERROR_DOS(ERRDOS,ERRnoaccess);
1187 flags = IVAL(params,0);
1188 desired_access = IVAL(params,8);
1189 file_attributes = IVAL(params,20);
1190 share_access = IVAL(params,24);
1191 create_disposition = IVAL(params,28);
1192 create_options = IVAL(params,32);
1193 sd_len = IVAL(params,36);
1194 root_dir_fid = (uint16)IVAL(params,4);
1195 smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
1197 if (create_options & FILE_OPEN_BY_FILE_ID) {
1198 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1202 * We need to construct the open_and_X ofun value from the
1203 * NT values, as that's what our code is structured to accept.
1206 if((smb_ofun = map_create_disposition( create_disposition )) == -1)
1207 return ERROR_DOS(ERRDOS,ERRbadmem);
1210 * Get the file name.
1213 if(root_dir_fid != 0) {
1215 * This filename is relative to a directory fid.
1218 files_struct *dir_fsp = file_fsp(params,4);
1219 size_t dir_name_len;
1221 if(!dir_fsp)
1222 return ERROR_DOS(ERRDOS,ERRbadfid);
1224 if(!dir_fsp->is_directory) {
1225 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1226 if (!NT_STATUS_IS_OK(status)) {
1227 return ERROR_NT(status);
1231 * Check to see if this is a mac fork of some kind.
1234 if( strchr_m(fname, ':'))
1235 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1237 return ERROR_DOS(ERRDOS,ERRbadfid);
1241 * Copy in the base directory name.
1244 pstrcpy( fname, dir_fsp->fsp_name );
1245 dir_name_len = strlen(fname);
1248 * Ensure it ends in a '\'.
1251 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1252 pstrcat(fname, "\\");
1253 dir_name_len++;
1257 pstring tmpname;
1258 srvstr_get_path(inbuf, tmpname, params+53, sizeof(tmpname), parameter_count-53, STR_TERMINATE, &status);
1259 if (!NT_STATUS_IS_OK(status)) {
1260 return ERROR_NT(status);
1262 pstrcat(fname, tmpname);
1264 } else {
1265 srvstr_get_path(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE, &status);
1266 if (!NT_STATUS_IS_OK(status)) {
1267 return ERROR_NT(status);
1271 * Check to see if this is a mac fork of some kind.
1274 if( strchr_m(fname, ':'))
1275 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1279 * Now contruct the smb_open_mode value from the desired access
1280 * and the share access.
1283 if((smb_open_mode = map_share_mode( fname, create_options, &desired_access,
1284 share_access, file_attributes)) == -1)
1285 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1287 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1288 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1291 * Check if POSIX semantics are wanted.
1294 set_posix_case_semantics(file_attributes);
1296 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1298 unix_convert(fname,conn,0,&bad_path,&sbuf);
1300 unixmode = unix_mode(conn,smb_attr | aARCH, fname);
1303 * If it's a request for a directory open, deal with it separately.
1306 if(create_options & FILE_DIRECTORY_FILE) {
1308 /* Can't open a temp directory. IFS kit test. */
1309 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1310 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1313 oplock_request = 0;
1316 * We will get a create directory here if the Win32
1317 * app specified a security descriptor in the
1318 * CreateDirectory() call.
1321 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
1323 if(!fsp) {
1324 restore_case_semantics(file_attributes);
1325 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1328 } else {
1331 * Ordinary file case.
1334 fsp = open_file_shared1(conn,fname,&sbuf,desired_access,
1335 smb_open_mode,smb_ofun,unixmode,
1336 oplock_request,&rmode,&smb_action);
1338 if (!fsp) {
1340 if(errno == EISDIR) {
1343 * Fail the open if it was explicitly a non-directory file.
1346 if (create_options & FILE_NON_DIRECTORY_FILE) {
1347 restore_case_semantics(file_attributes);
1348 SSVAL(outbuf, smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
1349 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1352 oplock_request = 0;
1353 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
1355 if(!fsp) {
1356 restore_case_semantics(file_attributes);
1357 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1359 } else {
1360 restore_case_semantics(file_attributes);
1361 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1365 file_len = sbuf.st_size;
1366 fmode = dos_mode(conn,fname,&sbuf);
1367 if(fmode == 0)
1368 fmode = FILE_ATTRIBUTE_NORMAL;
1370 if (fmode & aDIR) {
1371 close_file(fsp,False);
1372 restore_case_semantics(file_attributes);
1373 return ERROR_DOS(ERRDOS,ERRnoaccess);
1377 * If the caller set the extended oplock request bit
1378 * and we granted one (by whatever means) - set the
1379 * correct bit for extended oplock reply.
1382 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
1383 extended_oplock_granted = True;
1385 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
1386 extended_oplock_granted = True;
1390 * Now try and apply the desired SD.
1393 if (sd_len && !NT_STATUS_IS_OK(status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION))) {
1394 close_file(fsp,False);
1395 restore_case_semantics(file_attributes);
1396 return ERROR_NT(status);
1399 restore_case_semantics(file_attributes);
1401 /* Save the requested allocation size. */
1402 allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1403 #ifdef LARGE_SMB_OFF_T
1404 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1405 #endif
1406 if (allocation_size && (allocation_size > file_len)) {
1407 fsp->initial_allocation_size = SMB_ROUNDUP(allocation_size,SMB_ROUNDUP_ALLOCATION_SIZE);
1408 if (fsp->is_directory) {
1409 close_file(fsp,False);
1410 END_PROFILE(SMBntcreateX);
1411 /* Can't set allocation size on a directory. */
1412 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1414 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1415 close_file(fsp,False);
1416 return ERROR_NT(NT_STATUS_DISK_FULL);
1418 } else {
1419 fsp->initial_allocation_size = SMB_ROUNDUP(((SMB_BIG_UINT)file_len),SMB_ROUNDUP_ALLOCATION_SIZE);
1422 /* Realloc the size of parameters and data we will return */
1423 params = nttrans_realloc(ppparams, 69);
1424 if(params == NULL)
1425 return ERROR_DOS(ERRDOS,ERRnomem);
1427 p = params;
1428 if (extended_oplock_granted)
1429 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1430 else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
1431 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1432 else
1433 SCVAL(p,0,NO_OPLOCK_RETURN);
1435 p += 2;
1436 SSVAL(p,0,fsp->fnum);
1437 p += 2;
1438 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
1439 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1440 else
1441 SIVAL(p,0,smb_action);
1442 p += 8;
1444 /* Create time. */
1445 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1447 if (lp_dos_filetime_resolution(SNUM(conn))) {
1448 c_time &= ~1;
1449 sbuf.st_atime &= ~1;
1450 sbuf.st_mtime &= ~1;
1451 sbuf.st_mtime &= ~1;
1454 put_long_date(p,c_time);
1455 p += 8;
1456 put_long_date(p,sbuf.st_atime); /* access time */
1457 p += 8;
1458 put_long_date(p,sbuf.st_mtime); /* write time */
1459 p += 8;
1460 put_long_date(p,sbuf.st_mtime); /* change time */
1461 p += 8;
1462 SIVAL(p,0,fmode); /* File Attributes. */
1463 p += 4;
1464 SOFF_T(p, 0, get_allocation_size(fsp,&sbuf));
1465 p += 8;
1466 SOFF_T(p,0,file_len);
1467 p += 8;
1468 if (flags & EXTENDED_RESPONSE_REQUIRED)
1469 SSVAL(p,2,0x7);
1470 p += 4;
1471 SCVAL(p,0,fsp->is_directory ? 1 : 0);
1473 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1475 /* Send the required number of replies */
1476 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1478 return -1;
1481 /****************************************************************************
1482 Reply to a NT CANCEL request.
1483 ****************************************************************************/
1485 int reply_ntcancel(connection_struct *conn,
1486 char *inbuf,char *outbuf,int length,int bufsize)
1489 * Go through and cancel any pending change notifies.
1492 int mid = SVAL(inbuf,smb_mid);
1493 START_PROFILE(SMBntcancel);
1494 remove_pending_change_notify_requests_by_mid(mid);
1495 remove_pending_lock_requests_by_mid(mid);
1496 srv_cancel_sign_response(mid);
1498 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1500 END_PROFILE(SMBntcancel);
1501 return(-1);
1504 /****************************************************************************
1505 Reply to a NT rename request.
1506 ****************************************************************************/
1508 int reply_ntrename(connection_struct *conn,
1509 char *inbuf,char *outbuf,int length,int bufsize)
1511 int outsize = 0;
1512 pstring name;
1513 pstring newname;
1514 char *p;
1515 NTSTATUS status;
1516 uint16 attrs = SVAL(inbuf,smb_vwv0);
1517 uint16 rename_type = SVAL(inbuf,smb_vwv1);
1519 START_PROFILE(SMBntrename);
1521 if ((rename_type != RENAME_FLAG_RENAME) && (rename_type != RENAME_FLAG_HARD_LINK)) {
1522 END_PROFILE(SMBntrename);
1523 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1526 p = smb_buf(inbuf) + 1;
1527 p += srvstr_get_path(inbuf, name, p, sizeof(name), 0, STR_TERMINATE, &status);
1528 if (!NT_STATUS_IS_OK(status)) {
1529 END_PROFILE(SMBntrename);
1530 return ERROR_NT(status);
1533 if( strchr_m(name, ':')) {
1534 /* Can't rename a stream. */
1535 END_PROFILE(SMBntrename);
1536 return ERROR_NT(NT_STATUS_ACCESS_DENIED);
1539 p++;
1540 p += srvstr_get_path(inbuf, newname, p, sizeof(newname), 0, STR_TERMINATE, &status);
1541 if (!NT_STATUS_IS_OK(status)) {
1542 END_PROFILE(SMBntrename);
1543 return ERROR_NT(status);
1546 RESOLVE_DFSPATH(name, conn, inbuf, outbuf);
1547 RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
1549 DEBUG(3,("reply_ntrename : %s -> %s\n",name,newname));
1551 if (rename_type == RENAME_FLAG_RENAME) {
1552 status = rename_internals(conn, name, newname, attrs, False);
1553 } else {
1554 status = hardlink_internals(conn, name, newname);
1557 if (!NT_STATUS_IS_OK(status)) {
1558 END_PROFILE(SMBntrename);
1559 return ERROR_NT(status);
1563 * Win2k needs a changenotify request response before it will
1564 * update after a rename..
1566 process_pending_change_notify_queue((time_t)0);
1567 outsize = set_message(outbuf,0,0,True);
1569 END_PROFILE(SMBntrename);
1570 return(outsize);
1573 /****************************************************************************
1574 Reply to an unsolicited SMBNTtranss - just ignore it!
1575 ****************************************************************************/
1577 int reply_nttranss(connection_struct *conn,
1578 char *inbuf,char *outbuf,int length,int bufsize)
1580 START_PROFILE(SMBnttranss);
1581 DEBUG(4,("Ignoring nttranss of length %d\n",length));
1582 END_PROFILE(SMBnttranss);
1583 return(-1);
1586 /****************************************************************************
1587 Reply to a notify change - queue the request and
1588 don't allow a directory to be opened.
1589 ****************************************************************************/
1591 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1592 char **ppsetup, uint32 setup_count,
1593 char **ppparams, uint32 parameter_count,
1594 char **ppdata, uint32 data_count)
1596 char *setup = *ppsetup;
1597 files_struct *fsp;
1598 uint32 flags;
1600 if(setup_count < 6)
1601 return ERROR_DOS(ERRDOS,ERRbadfunc);
1603 fsp = file_fsp(setup,4);
1604 flags = IVAL(setup, 0);
1606 DEBUG(3,("call_nt_transact_notify_change\n"));
1608 if(!fsp)
1609 return ERROR_DOS(ERRDOS,ERRbadfid);
1611 if((!fsp->is_directory) || (conn != fsp->conn))
1612 return ERROR_DOS(ERRDOS,ERRbadfid);
1614 if (!change_notify_set(inbuf, fsp, conn, flags))
1615 return(UNIXERROR(ERRDOS,ERRbadfid));
1617 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1618 name = %s\n", fsp->fsp_name ));
1620 return -1;
1623 /****************************************************************************
1624 Reply to an NT transact rename command.
1625 ****************************************************************************/
1627 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1628 char **ppsetup, uint32 setup_count,
1629 char **ppparams, uint32 parameter_count,
1630 char **ppdata, uint32 data_count)
1632 char *params = *ppparams;
1633 pstring new_name;
1634 files_struct *fsp = NULL;
1635 BOOL replace_if_exists = False;
1636 NTSTATUS status;
1638 if(parameter_count < 4)
1639 return ERROR_DOS(ERRDOS,ERRbadfunc);
1641 fsp = file_fsp(params, 0);
1642 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1643 CHECK_FSP(fsp, conn);
1644 srvstr_get_path(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE, &status);
1645 if (!NT_STATUS_IS_OK(status)) {
1646 return ERROR_NT(status);
1649 status = rename_internals(conn, fsp->fsp_name,
1650 new_name, 0, replace_if_exists);
1651 if (!NT_STATUS_IS_OK(status))
1652 return ERROR_NT(status);
1655 * Rename was successful.
1657 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1659 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1660 fsp->fsp_name, new_name));
1663 * Win2k needs a changenotify request response before it will
1664 * update after a rename..
1667 process_pending_change_notify_queue((time_t)0);
1669 return -1;
1672 /******************************************************************************
1673 Fake up a completely empty SD.
1674 *******************************************************************************/
1676 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1678 extern DOM_SID global_sid_World;
1679 size_t sd_size;
1681 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1682 if(!*ppsd) {
1683 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1684 sd_size = 0;
1687 return sd_size;
1690 /****************************************************************************
1691 Reply to query a security descriptor.
1692 ****************************************************************************/
1694 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1695 char **ppsetup, uint32 setup_count,
1696 char **ppparams, uint32 parameter_count,
1697 char **ppdata, uint32 data_count)
1699 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
1700 char *params = *ppparams;
1701 char *data = *ppdata;
1702 prs_struct pd;
1703 SEC_DESC *psd = NULL;
1704 size_t sd_size;
1705 uint32 security_info_wanted;
1706 TALLOC_CTX *mem_ctx;
1707 files_struct *fsp = NULL;
1709 if(parameter_count < 8)
1710 return ERROR_DOS(ERRDOS,ERRbadfunc);
1712 fsp = file_fsp(params,0);
1713 if(!fsp)
1714 return ERROR_DOS(ERRDOS,ERRbadfid);
1716 security_info_wanted = IVAL(params,4);
1718 DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp->fsp_name ));
1720 params = nttrans_realloc(ppparams, 4);
1721 if(params == NULL)
1722 return ERROR_DOS(ERRDOS,ERRnomem);
1724 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1725 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1726 return ERROR_DOS(ERRDOS,ERRnomem);
1730 * Get the permissions to return.
1733 if (!lp_nt_acl_support(SNUM(conn)))
1734 sd_size = get_null_nt_acl(mem_ctx, &psd);
1735 else
1736 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fd, security_info_wanted, &psd);
1738 if (sd_size == 0) {
1739 talloc_destroy(mem_ctx);
1740 return(UNIXERROR(ERRDOS,ERRnoaccess));
1743 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size));
1745 SIVAL(params,0,(uint32)sd_size);
1747 if(max_data_count < sd_size) {
1749 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
1750 params, 4, *ppdata, 0);
1751 talloc_destroy(mem_ctx);
1752 return -1;
1756 * Allocate the data we will point this at.
1759 data = nttrans_realloc(ppdata, sd_size);
1760 if(data == NULL) {
1761 talloc_destroy(mem_ctx);
1762 return ERROR_DOS(ERRDOS,ERRnomem);
1766 * Init the parse struct we will marshall into.
1769 prs_init(&pd, 0, mem_ctx, MARSHALL);
1772 * Setup the prs_struct to point at the memory we just
1773 * allocated.
1776 prs_give_memory( &pd, data, (uint32)sd_size, False);
1779 * Finally, linearize into the outgoing buffer.
1782 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1783 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
1784 security descriptor.\n"));
1786 * Return access denied for want of a better error message..
1788 talloc_destroy(mem_ctx);
1789 return(UNIXERROR(ERRDOS,ERRnoaccess));
1793 * Now we can delete the security descriptor.
1796 talloc_destroy(mem_ctx);
1798 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 4, data, (int)sd_size);
1799 return -1;
1802 /****************************************************************************
1803 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1804 ****************************************************************************/
1806 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1807 char **ppsetup, uint32 setup_count,
1808 char **ppparams, uint32 parameter_count,
1809 char **ppdata, uint32 data_count)
1811 char *params= *ppparams;
1812 char *data = *ppdata;
1813 files_struct *fsp = NULL;
1814 uint32 security_info_sent = 0;
1815 NTSTATUS nt_status;
1817 if(parameter_count < 8)
1818 return ERROR_DOS(ERRDOS,ERRbadfunc);
1820 if((fsp = file_fsp(params,0)) == NULL)
1821 return ERROR_DOS(ERRDOS,ERRbadfid);
1823 if(!lp_nt_acl_support(SNUM(conn)))
1824 goto done;
1826 security_info_sent = IVAL(params,4);
1828 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1829 (unsigned int)security_info_sent ));
1831 if (data_count == 0)
1832 return ERROR_DOS(ERRDOS, ERRnoaccess);
1834 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent)))
1835 return ERROR_NT(nt_status);
1837 done:
1839 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1840 return -1;
1843 /****************************************************************************
1844 Reply to NT IOCTL
1845 ****************************************************************************/
1847 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1848 char **ppsetup, uint32 setup_count,
1849 char **ppparams, uint32 parameter_count,
1850 char **ppdata, uint32 data_count)
1852 uint32 function;
1853 uint16 fidnum;
1854 files_struct *fsp;
1855 uint8 isFSctl;
1856 uint8 compfilter;
1857 static BOOL logged_message;
1858 char *pdata = *ppdata;
1860 if (setup_count != 8) {
1861 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1862 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1865 function = IVAL(*ppsetup, 0);
1866 fidnum = SVAL(*ppsetup, 4);
1867 isFSctl = CVAL(*ppsetup, 6);
1868 compfilter = CVAL(*ppsetup, 7);
1870 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1871 function, fidnum, isFSctl, compfilter));
1873 fsp=file_fsp(*ppsetup, 4);
1874 /* this check is done in each implemented function case for now
1875 because I don't want to break anything... --metze
1876 FSP_BELONGS_CONN(fsp,conn);*/
1878 switch (function) {
1879 case FSCTL_SET_SPARSE:
1880 /* pretend this succeeded - tho strictly we should
1881 mark the file sparse (if the local fs supports it)
1882 so we can know if we need to pre-allocate or not */
1884 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1885 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1886 return -1;
1888 case FSCTL_0x000900C0:
1889 /* pretend this succeeded - don't know what this really is
1890 but works ok like this --metze
1893 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
1894 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1895 return -1;
1897 case FSCTL_GET_REPARSE_POINT:
1898 /* pretend this fail - my winXP does it like this
1899 * --metze
1902 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1903 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
1904 return -1;
1906 case FSCTL_SET_REPARSE_POINT:
1907 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1908 * --metze
1911 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1912 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
1913 return -1;
1915 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1918 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1919 * and return their volume names. If max_data_count is 16, then it is just
1920 * asking for the number of volumes and length of the combined names.
1922 * pdata is the data allocated by our caller, but that uses
1923 * total_data_count (which is 0 in our case) rather than max_data_count.
1924 * Allocate the correct amount and return the pointer to let
1925 * it be deallocated when we return.
1927 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
1928 SHADOW_COPY_DATA *shadow_data = NULL;
1929 TALLOC_CTX *shadow_mem_ctx = NULL;
1930 BOOL labels = False;
1931 uint32 labels_data_count = 0;
1932 uint32 i;
1933 char *cur_pdata;
1935 FSP_BELONGS_CONN(fsp,conn);
1937 if (max_data_count < 16) {
1938 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1939 max_data_count));
1940 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1943 if (max_data_count > 16) {
1944 labels = True;
1947 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1948 if (shadow_mem_ctx == NULL) {
1949 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1950 return ERROR_NT(NT_STATUS_NO_MEMORY);
1953 shadow_data = (SHADOW_COPY_DATA *)talloc_zero(shadow_mem_ctx,sizeof(SHADOW_COPY_DATA));
1954 if (shadow_data == NULL) {
1955 DEBUG(0,("talloc_zero() failed!\n"));
1956 return ERROR_NT(NT_STATUS_NO_MEMORY);
1959 shadow_data->mem_ctx = shadow_mem_ctx;
1962 * Call the VFS routine to actually do the work.
1964 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1965 talloc_destroy(shadow_data->mem_ctx);
1966 if (errno == ENOSYS) {
1967 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1968 conn->connectpath));
1969 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1970 } else {
1971 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1972 conn->connectpath));
1973 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
1977 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
1979 if (!labels) {
1980 data_count = 16;
1981 } else {
1982 data_count = 12+labels_data_count+4;
1985 if (max_data_count<data_count) {
1986 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1987 max_data_count,data_count));
1988 talloc_destroy(shadow_data->mem_ctx);
1989 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
1992 pdata = nttrans_realloc(ppdata, data_count);
1993 if (pdata == NULL) {
1994 talloc_destroy(shadow_data->mem_ctx);
1995 return ERROR_NT(NT_STATUS_NO_MEMORY);
1998 cur_pdata = pdata;
2000 /* num_volumes 4 bytes */
2001 SIVAL(pdata,0,shadow_data->num_volumes);
2003 if (labels) {
2004 /* num_labels 4 bytes */
2005 SIVAL(pdata,4,shadow_data->num_volumes);
2008 /* needed_data_count 4 bytes */
2009 SIVAL(pdata,8,labels_data_count);
2011 cur_pdata+=12;
2013 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
2014 shadow_data->num_volumes,fsp->fsp_name));
2015 if (labels && shadow_data->labels) {
2016 for (i=0;i<shadow_data->num_volumes;i++) {
2017 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
2018 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
2019 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
2023 talloc_destroy(shadow_data->mem_ctx);
2025 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
2027 return -1;
2030 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
2032 /* pretend this succeeded -
2034 * we have to send back a list with all files owned by this SID
2036 * but I have to check that --metze
2038 DOM_SID sid;
2039 uid_t uid;
2040 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
2042 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
2044 FSP_BELONGS_CONN(fsp,conn);
2046 /* unknown 4 bytes: this is not the length of the sid :-( */
2047 /*unknown = IVAL(pdata,0);*/
2049 sid_parse(pdata+4,sid_len,&sid);
2050 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
2052 if (!NT_STATUS_IS_OK(sid_to_uid(&sid, &uid))) {
2053 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
2054 sid_string_static(&sid),(unsigned long)sid_len));
2055 uid = (-1);
2058 /* we can take a look at the find source :-)
2060 * find ./ -uid $uid -name '*' is what we need here
2063 * and send 4bytes len and then NULL terminated unicode strings
2064 * for each file
2066 * but I don't know how to deal with the paged results
2067 * (maybe we can hang the result anywhere in the fsp struct)
2069 * we don't send all files at once
2070 * and at the next we should *not* start from the beginning,
2071 * so we have to cache the result
2073 * --metze
2076 /* this works for now... */
2077 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
2078 return -1;
2080 default:
2081 if (!logged_message) {
2082 logged_message = True; /* Only print this once... */
2083 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
2084 function));
2088 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
2092 #ifdef HAVE_SYS_QUOTAS
2093 /****************************************************************************
2094 Reply to get user quota
2095 ****************************************************************************/
2097 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2098 char **ppsetup, uint32 setup_count,
2099 char **ppparams, uint32 parameter_count,
2100 char **ppdata, uint32 data_count)
2102 NTSTATUS nt_status = NT_STATUS_OK;
2103 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2104 char *params = *ppparams;
2105 char *pdata = *ppdata;
2106 char *entry;
2107 int data_len=0,param_len=0;
2108 int qt_len=0;
2109 int entry_len = 0;
2110 files_struct *fsp = NULL;
2111 uint16 level = 0;
2112 size_t sid_len;
2113 DOM_SID sid;
2114 BOOL start_enum = True;
2115 SMB_NTQUOTA_STRUCT qt;
2116 SMB_NTQUOTA_LIST *tmp_list;
2117 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2118 extern struct current_user current_user;
2120 ZERO_STRUCT(qt);
2122 /* access check */
2123 if (current_user.uid != 0) {
2124 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2125 lp_servicename(SNUM(conn)),conn->user));
2126 return ERROR_DOS(ERRDOS,ERRnoaccess);
2130 * Ensure minimum number of parameters sent.
2133 if (parameter_count < 4) {
2134 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2135 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2138 /* maybe we can check the quota_fnum */
2139 fsp = file_fsp(params,0);
2140 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2141 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2142 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2145 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2146 * is done by CHECK_NTQUOTA_HANDLE_OK()
2148 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2150 level = SVAL(params,2);
2152 /* unknown 12 bytes leading in params */
2154 switch (level) {
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) {
2161 /* free the list */
2162 free_ntquota_list(&(qt_handle->quota_list));
2164 /* Realloc the size of parameters and data we will return */
2165 param_len = 4;
2166 params = nttrans_realloc(ppparams, param_len);
2167 if(params == NULL)
2168 return ERROR_DOS(ERRDOS,ERRnomem);
2170 data_len = 0;
2171 SIVAL(params,0,data_len);
2173 break;
2176 start_enum = False;
2178 case TRANSACT_GET_USER_QUOTA_LIST_START:
2180 if (qt_handle->quota_list==NULL &&
2181 qt_handle->tmp_list==NULL) {
2182 start_enum = True;
2185 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2186 return ERROR_DOS(ERRSRV,ERRerror);
2188 /* Realloc the size of parameters and data we will return */
2189 param_len = 4;
2190 params = nttrans_realloc(ppparams, param_len);
2191 if(params == NULL)
2192 return ERROR_DOS(ERRDOS,ERRnomem);
2194 /* we should not trust the value in max_data_count*/
2195 max_data_count = MIN(max_data_count,2048);
2197 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2198 if(pdata == NULL)
2199 return ERROR_DOS(ERRDOS,ERRnomem);
2201 entry = pdata;
2204 /* set params Size of returned Quota Data 4 bytes*/
2205 /* but set it later when we know it */
2207 /* for each entry push the data */
2209 if (start_enum) {
2210 qt_handle->tmp_list = qt_handle->quota_list;
2213 tmp_list = qt_handle->tmp_list;
2215 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2216 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2218 sid_len = sid_size(&tmp_list->quotas->sid);
2219 entry_len = 40 + sid_len;
2221 /* nextoffset entry 4 bytes */
2222 SIVAL(entry,0,entry_len);
2224 /* then the len of the SID 4 bytes */
2225 SIVAL(entry,4,sid_len);
2227 /* unknown data 8 bytes SMB_BIG_UINT */
2228 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2230 /* the used disk space 8 bytes SMB_BIG_UINT */
2231 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2233 /* the soft quotas 8 bytes SMB_BIG_UINT */
2234 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2236 /* the hard quotas 8 bytes SMB_BIG_UINT */
2237 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2239 /* and now the SID */
2240 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2243 qt_handle->tmp_list = tmp_list;
2245 /* overwrite the offset of the last entry */
2246 SIVAL(entry-entry_len,0,0);
2248 data_len = 4+qt_len;
2249 /* overwrite the params quota_data_len */
2250 SIVAL(params,0,data_len);
2252 break;
2254 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2256 /* unknown 4 bytes IVAL(pdata,0) */
2258 if (data_count < 8) {
2259 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2260 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2263 sid_len = IVAL(pdata,4);
2265 if (data_count < 8+sid_len) {
2266 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2267 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2270 data_len = 4+40+sid_len;
2272 if (max_data_count < data_len) {
2273 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2274 max_data_count, data_len));
2275 param_len = 4;
2276 SIVAL(params,0,data_len);
2277 data_len = 0;
2278 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2279 break;
2282 sid_parse(pdata+8,sid_len,&sid);
2285 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2286 ZERO_STRUCT(qt);
2288 * we have to return zero's in all fields
2289 * instead of returning an error here
2290 * --metze
2294 /* Realloc the size of parameters and data we will return */
2295 param_len = 4;
2296 params = nttrans_realloc(ppparams, param_len);
2297 if(params == NULL)
2298 return ERROR_DOS(ERRDOS,ERRnomem);
2300 pdata = nttrans_realloc(ppdata, data_len);
2301 if(pdata == NULL)
2302 return ERROR_DOS(ERRDOS,ERRnomem);
2304 entry = pdata;
2306 /* set params Size of returned Quota Data 4 bytes*/
2307 SIVAL(params,0,data_len);
2309 /* nextoffset entry 4 bytes */
2310 SIVAL(entry,0,0);
2312 /* then the len of the SID 4 bytes */
2313 SIVAL(entry,4,sid_len);
2315 /* unknown data 8 bytes SMB_BIG_UINT */
2316 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2318 /* the used disk space 8 bytes SMB_BIG_UINT */
2319 SBIG_UINT(entry,16,qt.usedspace);
2321 /* the soft quotas 8 bytes SMB_BIG_UINT */
2322 SBIG_UINT(entry,24,qt.softlim);
2324 /* the hard quotas 8 bytes SMB_BIG_UINT */
2325 SBIG_UINT(entry,32,qt.hardlim);
2327 /* and now the SID */
2328 sid_linearize(entry+40, sid_len, &sid);
2330 break;
2332 default:
2333 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2334 return ERROR_DOS(ERRSRV,ERRerror);
2335 break;
2338 send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
2340 return -1;
2343 /****************************************************************************
2344 Reply to set user quota
2345 ****************************************************************************/
2347 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2348 char **ppsetup, uint32 setup_count,
2349 char **ppparams, uint32 parameter_count,
2350 char **ppdata, uint32 data_count)
2352 char *params = *ppparams;
2353 char *pdata = *ppdata;
2354 int data_len=0,param_len=0;
2355 SMB_NTQUOTA_STRUCT qt;
2356 size_t sid_len;
2357 DOM_SID sid;
2358 files_struct *fsp = NULL;
2360 ZERO_STRUCT(qt);
2362 /* access check */
2363 if (conn->admin_user != True) {
2364 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2365 lp_servicename(SNUM(conn)),conn->user));
2366 return ERROR_DOS(ERRDOS,ERRnoaccess);
2370 * Ensure minimum number of parameters sent.
2373 if (parameter_count < 2) {
2374 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2375 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2378 /* maybe we can check the quota_fnum */
2379 fsp = file_fsp(params,0);
2380 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2381 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2382 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2385 if (data_count < 40) {
2386 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2387 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2390 /* offset to next quota record.
2391 * 4 bytes IVAL(pdata,0)
2392 * unused here...
2395 /* sid len */
2396 sid_len = IVAL(pdata,4);
2398 if (data_count < 40+sid_len) {
2399 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2400 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2403 /* unknown 8 bytes in pdata
2404 * maybe its the change time in NTTIME
2407 /* the used space 8 bytes (SMB_BIG_UINT)*/
2408 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2409 #ifdef LARGE_SMB_OFF_T
2410 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2411 #else /* LARGE_SMB_OFF_T */
2412 if ((IVAL(pdata,20) != 0)&&
2413 ((qt.usedspace != 0xFFFFFFFF)||
2414 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2415 /* more than 32 bits? */
2416 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2418 #endif /* LARGE_SMB_OFF_T */
2420 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2421 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2422 #ifdef LARGE_SMB_OFF_T
2423 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2424 #else /* LARGE_SMB_OFF_T */
2425 if ((IVAL(pdata,28) != 0)&&
2426 ((qt.softlim != 0xFFFFFFFF)||
2427 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2428 /* more than 32 bits? */
2429 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2431 #endif /* LARGE_SMB_OFF_T */
2433 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2434 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2435 #ifdef LARGE_SMB_OFF_T
2436 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2437 #else /* LARGE_SMB_OFF_T */
2438 if ((IVAL(pdata,36) != 0)&&
2439 ((qt.hardlim != 0xFFFFFFFF)||
2440 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2441 /* more than 32 bits? */
2442 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2444 #endif /* LARGE_SMB_OFF_T */
2446 sid_parse(pdata+40,sid_len,&sid);
2447 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2449 /* 44 unknown bytes left... */
2451 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2452 return ERROR_DOS(ERRSRV,ERRerror);
2455 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
2457 return -1;
2459 #endif /* HAVE_SYS_QUOTAS */
2461 /****************************************************************************
2462 Reply to a SMBNTtrans.
2463 ****************************************************************************/
2465 int reply_nttrans(connection_struct *conn,
2466 char *inbuf,char *outbuf,int length,int bufsize)
2468 int outsize = 0;
2469 #if 0 /* Not used. */
2470 uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount);
2471 uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
2472 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2473 #endif /* Not used. */
2474 uint32 total_parameter_count = IVAL(inbuf, smb_nt_TotalParameterCount);
2475 uint32 total_data_count = IVAL(inbuf, smb_nt_TotalDataCount);
2476 uint32 parameter_count = IVAL(inbuf,smb_nt_ParameterCount);
2477 uint32 parameter_offset = IVAL(inbuf,smb_nt_ParameterOffset);
2478 uint32 data_count = IVAL(inbuf,smb_nt_DataCount);
2479 uint32 data_offset = IVAL(inbuf,smb_nt_DataOffset);
2480 uint16 setup_count = 2*CVAL(inbuf,smb_nt_SetupCount); /* setup count is in *words* */
2481 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2482 char *params = NULL, *data = NULL, *setup = NULL;
2483 uint32 num_params_sofar, num_data_sofar;
2484 START_PROFILE(SMBnttrans);
2486 if(global_oplock_break &&
2487 ((function_code == NT_TRANSACT_CREATE) ||
2488 (function_code == NT_TRANSACT_RENAME))) {
2490 * Queue this open message as we are the process of an oplock break.
2493 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2494 due to being in oplock break state.\n", (unsigned int)function_code ));
2496 push_oplock_pending_smb_message( inbuf, length);
2497 END_PROFILE(SMBnttrans);
2498 return -1;
2501 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2502 END_PROFILE(SMBnttrans);
2503 return ERROR_DOS(ERRSRV,ERRaccess);
2506 outsize = set_message(outbuf,0,0,True);
2509 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2510 * Ensure this is so as a sanity check.
2513 if(CVAL(inbuf, smb_wct) != 19 + (setup_count/2)) {
2514 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2515 CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
2516 goto bad_param;
2519 /* Allocate the space for the setup, the maximum needed parameters and data */
2521 if(setup_count > 0)
2522 setup = (char *)malloc(setup_count);
2523 if (total_parameter_count > 0)
2524 params = (char *)malloc(total_parameter_count);
2525 if (total_data_count > 0)
2526 data = (char *)malloc(total_data_count);
2528 if ((total_parameter_count && !params) || (total_data_count && !data) ||
2529 (setup_count && !setup)) {
2530 SAFE_FREE(setup);
2531 SAFE_FREE(params);
2532 SAFE_FREE(data);
2533 DEBUG(0,("reply_nttrans : Out of memory\n"));
2534 END_PROFILE(SMBnttrans);
2535 return ERROR_DOS(ERRDOS,ERRnomem);
2538 /* Copy the param and data bytes sent with this request into the params buffer */
2539 num_params_sofar = parameter_count;
2540 num_data_sofar = data_count;
2542 if (parameter_count > total_parameter_count || data_count > total_data_count)
2543 goto bad_param;
2545 if(setup) {
2546 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
2547 if ((smb_nt_SetupStart + setup_count < smb_nt_SetupStart) ||
2548 (smb_nt_SetupStart + setup_count < setup_count))
2549 goto bad_param;
2550 if (smb_nt_SetupStart + setup_count > length)
2551 goto bad_param;
2553 memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
2554 dump_data(10, setup, setup_count);
2556 if(params) {
2557 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count));
2558 if ((parameter_offset + parameter_count < parameter_offset) ||
2559 (parameter_offset + parameter_count < parameter_count))
2560 goto bad_param;
2561 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length)||
2562 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
2563 goto bad_param;
2565 memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
2566 dump_data(10, params, parameter_count);
2568 if(data) {
2569 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
2570 if ((data_offset + data_count < data_offset) || (data_offset + data_count < data_count))
2571 goto bad_param;
2572 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2573 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
2574 goto bad_param;
2576 memcpy( data, smb_base(inbuf) + data_offset, data_count);
2577 dump_data(10, data, data_count);
2580 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2582 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2583 /* We need to send an interim response then receive the rest
2584 of the parameter/data bytes */
2585 outsize = set_message(outbuf,0,0,True);
2586 srv_signing_trans_stop();
2587 if (!send_smb(smbd_server_fd(),outbuf))
2588 exit_server("reply_nttrans: send_smb failed.");
2590 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2591 BOOL ret;
2592 uint32 parameter_displacement;
2593 uint32 data_displacement;
2595 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
2598 * The sequence number for the trans reply is always
2599 * based on the last secondary received.
2602 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2604 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
2605 outsize = set_message(outbuf,0,0,True);
2606 if(ret) {
2607 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2608 } else {
2609 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2610 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
2612 goto bad_param;
2615 /* Revise total_params and total_data in case they have changed downwards */
2616 if (IVAL(inbuf, smb_nts_TotalParameterCount) < total_parameter_count)
2617 total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
2618 if (IVAL(inbuf, smb_nts_TotalDataCount) < total_data_count)
2619 total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
2621 parameter_count = IVAL(inbuf,smb_nts_ParameterCount);
2622 parameter_offset = IVAL(inbuf, smb_nts_ParameterOffset);
2623 parameter_displacement = IVAL(inbuf, smb_nts_ParameterDisplacement);
2624 num_params_sofar += parameter_count;
2626 data_count = IVAL(inbuf, smb_nts_DataCount);
2627 data_displacement = IVAL(inbuf, smb_nts_DataDisplacement);
2628 data_offset = IVAL(inbuf, smb_nts_DataOffset);
2629 num_data_sofar += data_count;
2631 if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count) {
2632 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2633 goto bad_param;
2636 if (parameter_count) {
2637 if (parameter_displacement + parameter_count >= total_parameter_count)
2638 goto bad_param;
2639 if ((parameter_displacement + parameter_count < parameter_displacement) ||
2640 (parameter_displacement + parameter_count < parameter_count))
2641 goto bad_param;
2642 if (parameter_displacement > total_parameter_count)
2643 goto bad_param;
2644 if ((smb_base(inbuf) + parameter_offset + parameter_count >= inbuf + bufsize) ||
2645 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
2646 goto bad_param;
2647 if (parameter_displacement + params < params)
2648 goto bad_param;
2650 memcpy( &params[parameter_displacement], smb_base(inbuf) + parameter_offset, parameter_count);
2653 if (data_count) {
2654 if (data_displacement + data_count >= total_data_count)
2655 goto bad_param;
2656 if ((data_displacement + data_count < data_displacement) ||
2657 (data_displacement + data_count < data_count))
2658 goto bad_param;
2659 if (data_displacement > total_data_count)
2660 goto bad_param;
2661 if ((smb_base(inbuf) + data_offset + data_count >= inbuf + bufsize) ||
2662 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
2663 goto bad_param;
2664 if (data_displacement + data < data)
2665 goto bad_param;
2667 memcpy( &data[data_displacement], smb_base(inbuf)+ data_offset, data_count);
2672 if (Protocol >= PROTOCOL_NT1)
2673 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_IS_LONG_NAME);
2675 /* Now we must call the relevant NT_TRANS function */
2676 switch(function_code) {
2677 case NT_TRANSACT_CREATE:
2678 START_PROFILE_NESTED(NT_transact_create);
2679 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2680 length, bufsize,
2681 &setup, setup_count,
2682 &params, total_parameter_count,
2683 &data, total_data_count);
2684 END_PROFILE_NESTED(NT_transact_create);
2685 break;
2686 case NT_TRANSACT_IOCTL:
2687 START_PROFILE_NESTED(NT_transact_ioctl);
2688 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2689 length, bufsize,
2690 &setup, setup_count,
2691 &params, total_parameter_count,
2692 &data, total_data_count);
2693 END_PROFILE_NESTED(NT_transact_ioctl);
2694 break;
2695 case NT_TRANSACT_SET_SECURITY_DESC:
2696 START_PROFILE_NESTED(NT_transact_set_security_desc);
2697 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2698 length, bufsize,
2699 &setup, setup_count,
2700 &params, total_parameter_count,
2701 &data, total_data_count);
2702 END_PROFILE_NESTED(NT_transact_set_security_desc);
2703 break;
2704 case NT_TRANSACT_NOTIFY_CHANGE:
2705 START_PROFILE_NESTED(NT_transact_notify_change);
2706 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
2707 length, bufsize,
2708 &setup, setup_count,
2709 &params, total_parameter_count,
2710 &data, total_data_count);
2711 END_PROFILE_NESTED(NT_transact_notify_change);
2712 break;
2713 case NT_TRANSACT_RENAME:
2714 START_PROFILE_NESTED(NT_transact_rename);
2715 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2716 length, bufsize,
2717 &setup, setup_count,
2718 &params, total_parameter_count,
2719 &data, total_data_count);
2720 END_PROFILE_NESTED(NT_transact_rename);
2721 break;
2723 case NT_TRANSACT_QUERY_SECURITY_DESC:
2724 START_PROFILE_NESTED(NT_transact_query_security_desc);
2725 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
2726 length, bufsize,
2727 &setup, setup_count,
2728 &params, total_parameter_count,
2729 &data, total_data_count);
2730 END_PROFILE_NESTED(NT_transact_query_security_desc);
2731 break;
2732 #ifdef HAVE_SYS_QUOTAS
2733 case NT_TRANSACT_GET_USER_QUOTA:
2734 START_PROFILE_NESTED(NT_transact_get_user_quota);
2735 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
2736 length, bufsize,
2737 &setup, setup_count,
2738 &params, total_parameter_count,
2739 &data, total_data_count);
2740 END_PROFILE_NESTED(NT_transact_get_user_quota);
2741 break;
2742 case NT_TRANSACT_SET_USER_QUOTA:
2743 START_PROFILE_NESTED(NT_transact_set_user_quota);
2744 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
2745 length, bufsize,
2746 &setup, setup_count,
2747 &params, total_parameter_count,
2748 &data, total_data_count);
2749 END_PROFILE_NESTED(NT_transact_set_user_quota);
2750 break;
2751 #endif /* HAVE_SYS_QUOTAS */
2752 default:
2753 /* Error in request */
2754 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
2755 SAFE_FREE(setup);
2756 SAFE_FREE(params);
2757 SAFE_FREE(data);
2758 END_PROFILE(SMBnttrans);
2759 srv_signing_trans_stop();
2760 return ERROR_DOS(ERRSRV,ERRerror);
2763 /* As we do not know how many data packets will need to be
2764 returned here the various call_nt_transact_xxxx calls
2765 must send their own. Thus a call_nt_transact_xxxx routine only
2766 returns a value other than -1 when it wants to send
2767 an error packet.
2770 srv_signing_trans_stop();
2772 SAFE_FREE(setup);
2773 SAFE_FREE(params);
2774 SAFE_FREE(data);
2775 END_PROFILE(SMBnttrans);
2776 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
2777 calls have already sent it. If outsize != -1 then it is
2778 returning an error packet. */
2780 bad_param:
2782 srv_signing_trans_stop();
2783 SAFE_FREE(params);
2784 SAFE_FREE(data);
2785 SAFE_FREE(setup);
2786 END_PROFILE(SMBnttrans);
2787 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);