Try to remove the last vestiges of unknown_3...
[Samba/bb.git] / source / smbd / nttrans.c
blob92629faa9e2d13ebfef9522a5b98dba26bc6abd9
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;
358 * Convert GENERIC bits to specific bits.
361 se_map_generic(desired_access, &file_generic_mapping);
363 switch( *desired_access & (FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA) ) {
364 case FILE_READ_DATA:
365 smb_open_mode = DOS_OPEN_RDONLY;
366 break;
367 case FILE_WRITE_DATA:
368 case FILE_APPEND_DATA:
369 case FILE_WRITE_DATA|FILE_APPEND_DATA:
370 smb_open_mode = DOS_OPEN_WRONLY;
371 break;
372 case FILE_READ_DATA|FILE_WRITE_DATA:
373 case FILE_READ_DATA|FILE_WRITE_DATA|FILE_APPEND_DATA:
374 case FILE_READ_DATA|FILE_APPEND_DATA:
375 smb_open_mode = DOS_OPEN_RDWR;
376 break;
380 * NB. For DELETE_ACCESS we should really check the
381 * directory permissions, as that is what controls
382 * delete, and for WRITE_DAC_ACCESS we should really
383 * check the ownership, as that is what controls the
384 * chmod. Note that this is *NOT* a security hole (this
385 * note is for you, Andrew) as we are not *allowing*
386 * the access at this point, the actual unlink or
387 * chown or chmod call would do this. We are just helping
388 * clients out by telling them if they have a hope
389 * of any of this succeeding. POSIX acls may still
390 * deny the real call. JRA.
393 if (smb_open_mode == -1) {
395 if(*desired_access & (DELETE_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS|SYNCHRONIZE_ACCESS|
396 FILE_EXECUTE|FILE_READ_ATTRIBUTES|
397 FILE_READ_EA|FILE_WRITE_EA|SYSTEM_SECURITY_ACCESS|
398 FILE_WRITE_ATTRIBUTES|READ_CONTROL_ACCESS)) {
399 smb_open_mode = DOS_OPEN_RDONLY;
400 } else if(*desired_access == 0) {
403 * JRA - NT seems to sometimes send desired_access as zero. play it safe
404 * and map to a stat open.
407 smb_open_mode = DOS_OPEN_RDONLY;
409 } else {
410 DEBUG(0,("map_share_mode: Incorrect value 0x%lx for desired_access to file %s\n",
411 (unsigned long)*desired_access, fname));
412 return -1;
417 * Set the special bit that means allow share delete.
418 * This is held outside the normal share mode bits at 1<<15.
419 * JRA.
422 if(share_access & FILE_SHARE_DELETE) {
423 smb_open_mode |= ALLOW_SHARE_DELETE;
424 DEBUG(10,("map_share_mode: FILE_SHARE_DELETE requested. open_mode = 0x%x\n", smb_open_mode));
428 * We need to store the intent to open for Delete. This
429 * is what determines if a delete on close flag can be set.
430 * This is the wrong way (and place) to store this, but for 2.2 this
431 * is the only practical way. JRA.
434 if(*desired_access & DELETE_ACCESS) {
435 DEBUG(10,("map_share_mode: DELETE_ACCESS requested. open_mode = 0x%x\n", smb_open_mode));
438 if (create_options & FILE_DELETE_ON_CLOSE) {
439 /* Implicit delete access is *NOT* requested... */
440 smb_open_mode |= DELETE_ON_CLOSE_FLAG;
441 DEBUG(10,("map_share_mode: FILE_DELETE_ON_CLOSE requested. open_mode = 0x%x\n", smb_open_mode));
444 /* Add in the requested share mode. */
445 switch( share_access & (FILE_SHARE_READ|FILE_SHARE_WRITE)) {
446 case FILE_SHARE_READ:
447 smb_open_mode |= SET_DENY_MODE(DENY_WRITE);
448 break;
449 case FILE_SHARE_WRITE:
450 smb_open_mode |= SET_DENY_MODE(DENY_READ);
451 break;
452 case (FILE_SHARE_READ|FILE_SHARE_WRITE):
453 smb_open_mode |= SET_DENY_MODE(DENY_NONE);
454 break;
455 case FILE_SHARE_NONE:
456 smb_open_mode |= SET_DENY_MODE(DENY_ALL);
457 break;
461 * Handle an O_SYNC request.
464 if(file_attributes & FILE_FLAG_WRITE_THROUGH)
465 smb_open_mode |= FILE_SYNC_OPENMODE;
467 DEBUG(10,("map_share_mode: Mapped desired access 0x%lx, share access 0x%lx, file attributes 0x%lx \
468 to open_mode 0x%x\n", (unsigned long)*desired_access, (unsigned long)share_access,
469 (unsigned long)file_attributes, smb_open_mode ));
471 return smb_open_mode;
474 /****************************************************************************
475 Reply to an NT create and X call on a pipe.
476 ****************************************************************************/
478 static int nt_open_pipe(char *fname, connection_struct *conn,
479 char *inbuf, char *outbuf, int *ppnum)
481 smb_np_struct *p = NULL;
483 uint16 vuid = SVAL(inbuf, smb_uid);
484 int i;
486 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
488 /* See if it is one we want to handle. */
490 if (lp_disable_spoolss() && strequal(fname, "\\spoolss"))
491 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
493 for( i = 0; known_nt_pipes[i]; i++ )
494 if( strequal(fname,known_nt_pipes[i]))
495 break;
497 if ( known_nt_pipes[i] == NULL )
498 return(ERROR_BOTH(NT_STATUS_OBJECT_NAME_NOT_FOUND,ERRDOS,ERRbadpipe));
500 /* Strip \\ off the name. */
501 fname++;
503 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
505 p = open_rpc_pipe_p(fname, conn, vuid);
506 if (!p)
507 return(ERROR_DOS(ERRSRV,ERRnofids));
509 *ppnum = p->pnum;
511 return 0;
514 /****************************************************************************
515 Reply to an NT create and X call for pipes.
516 ****************************************************************************/
518 static int do_ntcreate_pipe_open(connection_struct *conn,
519 char *inbuf,char *outbuf,int length,int bufsize)
521 pstring fname;
522 int ret;
523 int pnum = -1;
524 char *p = NULL;
525 NTSTATUS status;
527 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE,&status);
528 if (!NT_STATUS_IS_OK(status))
529 return ERROR_NT(status);
531 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
532 return ret;
535 * Deal with pipe return.
538 set_message(outbuf,34,0,True);
540 p = outbuf + smb_vwv2;
541 p++;
542 SSVAL(p,0,pnum);
543 p += 2;
544 SIVAL(p,0,FILE_WAS_OPENED);
545 p += 4;
546 p += 32;
547 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
548 p += 20;
549 /* File type. */
550 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
551 /* Device state. */
552 SSVAL(p,2, 0x5FF); /* ? */
554 DEBUG(5,("do_ntcreate_pipe_open: open pipe = %s\n", fname));
556 return chain_reply(inbuf,outbuf,length,bufsize);
559 /****************************************************************************
560 Reply to an NT create and X call.
561 ****************************************************************************/
563 int reply_ntcreate_and_X(connection_struct *conn,
564 char *inbuf,char *outbuf,int length,int bufsize)
566 int result;
567 pstring fname;
568 enum FAKE_FILE_TYPE fake_file_type = FAKE_FILE_TYPE_NONE;
569 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
570 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
571 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
572 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
573 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
574 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
575 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
576 SMB_BIG_UINT allocation_size = 0;
577 int smb_ofun;
578 int smb_open_mode;
579 int smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
580 /* Breakout the oplock request bits so we can set the
581 reply bits separately. */
582 int oplock_request = 0;
583 mode_t unixmode;
584 int fmode=0,rmode=0;
585 SMB_OFF_T file_len = 0;
586 SMB_STRUCT_STAT sbuf;
587 int smb_action = 0;
588 BOOL bad_path = False;
589 files_struct *fsp=NULL;
590 char *p = NULL;
591 time_t c_time;
592 BOOL extended_oplock_granted = False;
593 NTSTATUS status;
595 START_PROFILE(SMBntcreateX);
597 DEBUG(10,("reply_ntcreateX: flags = 0x%x, desired_access = 0x%x \
598 file_attributes = 0x%x, share_access = 0x%x, create_disposition = 0x%x \
599 create_options = 0x%x root_dir_fid = 0x%x\n", flags, desired_access, file_attributes,
600 share_access, create_disposition,
601 create_options, root_dir_fid ));
603 /* If it's an IPC, use the pipe handler. */
605 if (IS_IPC(conn)) {
606 if (lp_nt_pipe_support()) {
607 END_PROFILE(SMBntcreateX);
608 return do_ntcreate_pipe_open(conn,inbuf,outbuf,length,bufsize);
609 } else {
610 END_PROFILE(SMBntcreateX);
611 return(ERROR_DOS(ERRDOS,ERRnoaccess));
615 if (create_options & FILE_OPEN_BY_FILE_ID) {
616 END_PROFILE(SMBntcreateX);
617 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
621 * We need to construct the open_and_X ofun value from the
622 * NT values, as that's what our code is structured to accept.
625 if((smb_ofun = map_create_disposition( create_disposition )) == -1) {
626 END_PROFILE(SMBntcreateX);
627 return(ERROR_DOS(ERRDOS,ERRnoaccess));
631 * Get the file name.
634 if(root_dir_fid != 0) {
636 * This filename is relative to a directory fid.
638 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
639 size_t dir_name_len;
641 if(!dir_fsp) {
642 END_PROFILE(SMBntcreateX);
643 return(ERROR_DOS(ERRDOS,ERRbadfid));
646 if(!dir_fsp->is_directory) {
648 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE,&status);
649 if (!NT_STATUS_IS_OK(status)) {
650 END_PROFILE(SMBntcreateX);
651 return ERROR_NT(status);
655 * Check to see if this is a mac fork of some kind.
658 if( strchr_m(fname, ':')) {
659 END_PROFILE(SMBntcreateX);
660 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
665 we need to handle the case when we get a
666 relative open relative to a file and the
667 pathname is blank - this is a reopen!
668 (hint from demyn plantenberg)
672 END_PROFILE(SMBntcreateX);
673 return(ERROR_DOS(ERRDOS,ERRbadfid));
677 * Copy in the base directory name.
680 pstrcpy( fname, dir_fsp->fsp_name );
681 dir_name_len = strlen(fname);
684 * Ensure it ends in a '\'.
687 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
688 pstrcat(fname, "\\");
689 dir_name_len++;
692 srvstr_get_path(inbuf, &fname[dir_name_len], smb_buf(inbuf), sizeof(fname)-dir_name_len, STR_TERMINATE,&status);
693 if (!NT_STATUS_IS_OK(status)) {
694 END_PROFILE(SMBntcreateX);
695 return ERROR_NT(status);
697 } else {
698 srvstr_get_path(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE,&status);
699 if (!NT_STATUS_IS_OK(status)) {
700 END_PROFILE(SMBntcreateX);
701 return ERROR_NT(status);
705 * Check to see if this is a mac fork of some kind.
708 if( strchr_m(fname, ':')) {
710 #ifdef HAVE_SYS_QUOTAS
711 if ((fake_file_type=is_fake_file(fname))!=FAKE_FILE_TYPE_NONE) {
713 * here we go! support for changing the disk quotas --metze
715 * we need to fake up to open this MAGIC QUOTA file
716 * and return a valid FID
718 * w2k close this file directly after openening
719 * xp also tries a QUERY_FILE_INFO on the file and then close it
721 } else {
722 #endif
723 END_PROFILE(SMBntcreateX);
724 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
725 #ifdef HAVE_SYS_QUOTAS
727 #endif
732 * Now contruct the smb_open_mode value from the filename,
733 * desired access and the share access.
735 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
737 if((smb_open_mode = map_share_mode(fname, create_options, &desired_access,
738 share_access,
739 file_attributes)) == -1) {
740 END_PROFILE(SMBntcreateX);
741 return ERROR_DOS(ERRDOS,ERRnoaccess);
744 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
745 if (oplock_request) {
746 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
750 * Ordinary file or directory.
754 * Check if POSIX semantics are wanted.
757 set_posix_case_semantics(file_attributes);
759 unix_convert(fname,conn,0,&bad_path,&sbuf);
761 unixmode = unix_mode(conn,smb_attr | aARCH, fname);
764 * If it's a request for a directory open, deal with it separately.
767 if(create_options & FILE_DIRECTORY_FILE) {
768 oplock_request = 0;
770 /* Can't open a temp directory. IFS kit test. */
771 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
772 END_PROFILE(SMBntcreateX);
773 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
776 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
778 restore_case_semantics(file_attributes);
780 if(!fsp) {
781 END_PROFILE(SMBntcreateX);
782 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
784 } else {
786 * Ordinary file case.
789 /* NB. We have a potential bug here. If we
790 * cause an oplock break to ourselves, then we
791 * could end up processing filename related
792 * SMB requests whilst we await the oplock
793 * break response. As we may have changed the
794 * filename case semantics to be POSIX-like,
795 * this could mean a filename request could
796 * fail when it should succeed. This is a rare
797 * condition, but eventually we must arrange
798 * to restore the correct case semantics
799 * before issuing an oplock break request to
800 * our client. JRA. */
802 if (fake_file_type==FAKE_FILE_TYPE_NONE) {
803 fsp = open_file_shared1(conn,fname,&sbuf,
804 desired_access,
805 smb_open_mode,
806 smb_ofun,unixmode, oplock_request,
807 &rmode,&smb_action);
808 } else {
809 /* to open a fake_file --metze */
810 fsp = open_fake_file_shared1(fake_file_type,conn,fname,&sbuf,
811 desired_access,
812 smb_open_mode,
813 smb_ofun,unixmode, oplock_request,
814 &rmode,&smb_action);
817 if (!fsp) {
818 /* We cheat here. There are two cases we
819 * care about. One is a directory rename,
820 * where the NT client will attempt to
821 * open the source directory for
822 * DELETE access. Note that when the
823 * NT client does this it does *not*
824 * set the directory bit in the
825 * request packet. This is translated
826 * into a read/write open
827 * request. POSIX states that any open
828 * for write request on a directory
829 * will generate an EISDIR error, so
830 * we can catch this here and open a
831 * pseudo handle that is flagged as a
832 * directory. The second is an open
833 * for a permissions read only, which
834 * we handle in the open_file_stat case. JRA.
837 if(errno == EISDIR) {
840 * Fail the open if it was explicitly a non-directory file.
843 if (create_options & FILE_NON_DIRECTORY_FILE) {
844 restore_case_semantics(file_attributes);
845 SSVAL(outbuf, smb_flg2,
846 SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
847 END_PROFILE(SMBntcreateX);
848 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
851 oplock_request = 0;
852 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
854 if(!fsp) {
855 restore_case_semantics(file_attributes);
856 END_PROFILE(SMBntcreateX);
857 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
859 } else {
861 restore_case_semantics(file_attributes);
862 END_PROFILE(SMBntcreateX);
863 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
868 restore_case_semantics(file_attributes);
870 file_len = sbuf.st_size;
871 fmode = dos_mode(conn,fname,&sbuf);
872 if(fmode == 0)
873 fmode = FILE_ATTRIBUTE_NORMAL;
874 if (!fsp->is_directory && (fmode & aDIR)) {
875 close_file(fsp,False);
876 END_PROFILE(SMBntcreateX);
877 return ERROR_DOS(ERRDOS,ERRnoaccess);
880 /* Save the requested allocation size. */
881 allocation_size = (SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize);
882 #ifdef LARGE_SMB_OFF_T
883 allocation_size |= (((SMB_BIG_UINT)IVAL(inbuf,smb_ntcreate_AllocationSize + 4)) << 32);
884 #endif
885 if (allocation_size && (allocation_size > (SMB_BIG_UINT)file_len)) {
886 fsp->initial_allocation_size = SMB_ROUNDUP(allocation_size,SMB_ROUNDUP_ALLOCATION_SIZE);
887 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
888 close_file(fsp,False);
889 END_PROFILE(SMBntcreateX);
890 return ERROR_NT(NT_STATUS_DISK_FULL);
892 } else {
893 fsp->initial_allocation_size = SMB_ROUNDUP(((SMB_BIG_UINT)file_len),SMB_ROUNDUP_ALLOCATION_SIZE);
897 * If the caller set the extended oplock request bit
898 * and we granted one (by whatever means) - set the
899 * correct bit for extended oplock reply.
902 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
903 extended_oplock_granted = True;
905 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
906 extended_oplock_granted = True;
908 #if 0
909 /* W2K sends back 42 words here ! If we do the same it breaks offline sync. Go figure... ? JRA. */
910 set_message(outbuf,42,0,True);
911 #else
912 set_message(outbuf,34,0,True);
913 #endif
915 p = outbuf + smb_vwv2;
918 * Currently as we don't support level II oplocks we just report
919 * exclusive & batch here.
922 if (extended_oplock_granted) {
923 if (flags & REQUEST_BATCH_OPLOCK) {
924 SCVAL(p,0, BATCH_OPLOCK_RETURN);
925 } else {
926 SCVAL(p,0, EXCLUSIVE_OPLOCK_RETURN);
928 } else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type)) {
929 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
930 } else {
931 SCVAL(p,0,NO_OPLOCK_RETURN);
934 p++;
935 SSVAL(p,0,fsp->fnum);
936 p += 2;
937 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
938 SIVAL(p,0,FILE_WAS_SUPERSEDED);
939 else
940 SIVAL(p,0,smb_action);
941 p += 4;
943 /* Create time. */
944 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
946 if (lp_dos_filetime_resolution(SNUM(conn))) {
947 c_time &= ~1;
948 sbuf.st_atime &= ~1;
949 sbuf.st_mtime &= ~1;
950 sbuf.st_mtime &= ~1;
953 put_long_date(p,c_time);
954 p += 8;
955 put_long_date(p,sbuf.st_atime); /* access time */
956 p += 8;
957 put_long_date(p,sbuf.st_mtime); /* write time */
958 p += 8;
959 put_long_date(p,sbuf.st_mtime); /* change time */
960 p += 8;
961 SIVAL(p,0,fmode); /* File Attributes. */
962 p += 4;
963 SOFF_T(p, 0, get_allocation_size(fsp,&sbuf));
964 p += 8;
965 SOFF_T(p,0,file_len);
966 p += 12;
967 SCVAL(p,0,fsp->is_directory ? 1 : 0);
969 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
971 result = chain_reply(inbuf,outbuf,length,bufsize);
972 END_PROFILE(SMBntcreateX);
973 return result;
976 /****************************************************************************
977 Reply to a NT_TRANSACT_CREATE call to open a pipe.
978 ****************************************************************************/
980 static int do_nt_transact_create_pipe( connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
981 char **ppsetup, uint32 setup_count,
982 char **ppparams, uint32 parameter_count,
983 char **ppdata, uint32 data_count)
985 pstring fname;
986 char *params = *ppparams;
987 int ret;
988 int pnum = -1;
989 char *p = NULL;
990 NTSTATUS status;
993 * Ensure minimum number of parameters sent.
996 if(parameter_count < 54) {
997 DEBUG(0,("do_nt_transact_create_pipe - insufficient parameters (%u)\n", (unsigned int)parameter_count));
998 return ERROR_DOS(ERRDOS,ERRnoaccess);
1001 srvstr_pull(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE);
1002 status = check_path_syntax(fname);
1003 if (!NT_STATUS_IS_OK(status)) {
1004 return ERROR_NT(status);
1007 if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
1008 return ret;
1010 /* Realloc the size of parameters and data we will return */
1011 params = nttrans_realloc(ppparams, 69);
1012 if(params == NULL)
1013 return ERROR_DOS(ERRDOS,ERRnomem);
1015 p = params;
1016 SCVAL(p,0,NO_OPLOCK_RETURN);
1018 p += 2;
1019 SSVAL(p,0,pnum);
1020 p += 2;
1021 SIVAL(p,0,FILE_WAS_OPENED);
1022 p += 8;
1024 p += 32;
1025 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
1026 p += 20;
1027 /* File type. */
1028 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
1029 /* Device state. */
1030 SSVAL(p,2, 0x5FF); /* ? */
1032 DEBUG(5,("do_nt_transact_create_pipe: open name = %s\n", fname));
1034 /* Send the required number of replies */
1035 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1037 return -1;
1040 /****************************************************************************
1041 Internal fn to set security descriptors.
1042 ****************************************************************************/
1044 static NTSTATUS set_sd(files_struct *fsp, char *data, uint32 sd_len, uint32 security_info_sent)
1046 prs_struct pd;
1047 SEC_DESC *psd = NULL;
1048 TALLOC_CTX *mem_ctx;
1049 BOOL ret;
1051 if (sd_len == 0) {
1052 return NT_STATUS_OK;
1056 * Init the parse struct we will unmarshall from.
1059 if ((mem_ctx = talloc_init("set_sd")) == NULL) {
1060 DEBUG(0,("set_sd: talloc_init failed.\n"));
1061 return NT_STATUS_NO_MEMORY;
1064 prs_init(&pd, 0, mem_ctx, UNMARSHALL);
1067 * Setup the prs_struct to point at the memory we just
1068 * allocated.
1071 prs_give_memory( &pd, data, sd_len, False);
1074 * Finally, unmarshall from the data buffer.
1077 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1078 DEBUG(0,("set_sd: Error in unmarshalling security descriptor.\n"));
1080 * Return access denied for want of a better error message..
1082 talloc_destroy(mem_ctx);
1083 return NT_STATUS_NO_MEMORY;
1086 if (psd->off_owner_sid==0)
1087 security_info_sent &= ~OWNER_SECURITY_INFORMATION;
1088 if (psd->off_grp_sid==0)
1089 security_info_sent &= ~GROUP_SECURITY_INFORMATION;
1090 if (psd->off_sacl==0)
1091 security_info_sent &= ~SACL_SECURITY_INFORMATION;
1092 if (psd->off_dacl==0)
1093 security_info_sent &= ~DACL_SECURITY_INFORMATION;
1095 ret = SMB_VFS_FSET_NT_ACL( fsp, fsp->fd, security_info_sent, psd);
1097 if (!ret) {
1098 talloc_destroy(mem_ctx);
1099 return NT_STATUS_ACCESS_DENIED;
1102 talloc_destroy(mem_ctx);
1104 return NT_STATUS_OK;
1107 /****************************************************************************
1108 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
1109 ****************************************************************************/
1111 static int call_nt_transact_create(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1112 char **ppsetup, uint32 setup_count,
1113 char **ppparams, uint32 parameter_count,
1114 char **ppdata, uint32 data_count)
1116 pstring fname;
1117 char *params = *ppparams;
1118 char *data = *ppdata;
1119 /* Breakout the oplock request bits so we can set the reply bits separately. */
1120 int oplock_request = 0;
1121 mode_t unixmode;
1122 int fmode=0,rmode=0;
1123 SMB_OFF_T file_len = 0;
1124 SMB_STRUCT_STAT sbuf;
1125 int smb_action = 0;
1126 BOOL bad_path = False;
1127 files_struct *fsp = NULL;
1128 char *p = NULL;
1129 BOOL extended_oplock_granted = False;
1130 uint32 flags;
1131 uint32 desired_access;
1132 uint32 file_attributes;
1133 uint32 share_access;
1134 uint32 create_disposition;
1135 uint32 create_options;
1136 uint32 sd_len;
1137 uint16 root_dir_fid;
1138 SMB_BIG_UINT allocation_size = 0;
1139 int smb_ofun;
1140 int smb_open_mode;
1141 int smb_attr;
1142 time_t c_time;
1143 NTSTATUS nt_status;
1145 DEBUG(5,("call_nt_transact_create\n"));
1148 * If it's an IPC, use the pipe handler.
1151 if (IS_IPC(conn)) {
1152 if (lp_nt_pipe_support())
1153 return do_nt_transact_create_pipe(conn, inbuf, outbuf, length,
1154 bufsize,
1155 ppsetup, setup_count,
1156 ppparams, parameter_count,
1157 ppdata, data_count);
1158 else
1159 return ERROR_DOS(ERRDOS,ERRnoaccess);
1163 * Ensure minimum number of parameters sent.
1166 if(parameter_count < 54) {
1167 DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)parameter_count));
1168 return ERROR_DOS(ERRDOS,ERRnoaccess);
1171 flags = IVAL(params,0);
1172 desired_access = IVAL(params,8);
1173 file_attributes = IVAL(params,20);
1174 share_access = IVAL(params,24);
1175 create_disposition = IVAL(params,28);
1176 create_options = IVAL(params,32);
1177 sd_len = IVAL(params,36);
1178 root_dir_fid = (uint16)IVAL(params,4);
1179 smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
1181 if (create_options & FILE_OPEN_BY_FILE_ID) {
1182 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1186 * We need to construct the open_and_X ofun value from the
1187 * NT values, as that's what our code is structured to accept.
1190 if((smb_ofun = map_create_disposition( create_disposition )) == -1)
1191 return ERROR_DOS(ERRDOS,ERRbadmem);
1194 * Get the file name.
1197 if(root_dir_fid != 0) {
1199 * This filename is relative to a directory fid.
1202 files_struct *dir_fsp = file_fsp(params,4);
1203 size_t dir_name_len;
1205 if(!dir_fsp)
1206 return ERROR_DOS(ERRDOS,ERRbadfid);
1208 if(!dir_fsp->is_directory) {
1210 srvstr_pull(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE);
1211 nt_status = check_path_syntax(fname);
1212 if (!NT_STATUS_IS_OK(nt_status)) {
1213 return ERROR_NT(nt_status);
1217 * Check to see if this is a mac fork of some kind.
1220 if( strchr_m(fname, ':'))
1221 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1223 return ERROR_DOS(ERRDOS,ERRbadfid);
1227 * Copy in the base directory name.
1230 pstrcpy( fname, dir_fsp->fsp_name );
1231 dir_name_len = strlen(fname);
1234 * Ensure it ends in a '\'.
1237 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
1238 pstrcat(fname, "\\");
1239 dir_name_len++;
1242 srvstr_pull(inbuf, &fname[dir_name_len], params+53, sizeof(fname)-dir_name_len,
1243 parameter_count-53, STR_TERMINATE);
1244 nt_status = check_path_syntax(fname);
1245 if (!NT_STATUS_IS_OK(nt_status)) {
1246 return ERROR_NT(nt_status);
1248 } else {
1249 srvstr_pull(inbuf, fname, params+53, sizeof(fname), parameter_count-53, STR_TERMINATE);
1250 nt_status = check_path_syntax(fname);
1251 if (!NT_STATUS_IS_OK(nt_status)) {
1252 return ERROR_NT(nt_status);
1256 * Check to see if this is a mac fork of some kind.
1259 if( strchr_m(fname, ':'))
1260 return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
1264 * Now contruct the smb_open_mode value from the desired access
1265 * and the share access.
1268 if((smb_open_mode = map_share_mode( fname, create_options, &desired_access,
1269 share_access, file_attributes)) == -1)
1270 return ERROR_DOS(ERRDOS,ERRnoaccess);
1272 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
1273 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
1276 * Check if POSIX semantics are wanted.
1279 set_posix_case_semantics(file_attributes);
1281 RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
1283 unix_convert(fname,conn,0,&bad_path,&sbuf);
1285 unixmode = unix_mode(conn,smb_attr | aARCH, fname);
1288 * If it's a request for a directory open, deal with it separately.
1291 if(create_options & FILE_DIRECTORY_FILE) {
1293 /* Can't open a temp directory. IFS kit test. */
1294 if (file_attributes & FILE_ATTRIBUTE_TEMPORARY) {
1295 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1298 oplock_request = 0;
1301 * We will get a create directory here if the Win32
1302 * app specified a security descriptor in the
1303 * CreateDirectory() call.
1306 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
1308 if(!fsp) {
1309 restore_case_semantics(file_attributes);
1310 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1313 } else {
1316 * Ordinary file case.
1319 fsp = open_file_shared1(conn,fname,&sbuf,desired_access,
1320 smb_open_mode,smb_ofun,unixmode,
1321 oplock_request,&rmode,&smb_action);
1323 if (!fsp) {
1325 if(errno == EISDIR) {
1328 * Fail the open if it was explicitly a non-directory file.
1331 if (create_options & FILE_NON_DIRECTORY_FILE) {
1332 restore_case_semantics(file_attributes);
1333 SSVAL(outbuf, smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
1334 return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
1337 oplock_request = 0;
1338 fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
1340 if(!fsp) {
1341 restore_case_semantics(file_attributes);
1342 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1344 } else {
1345 restore_case_semantics(file_attributes);
1346 return set_bad_path_error(errno, bad_path, outbuf, ERRDOS,ERRnoaccess);
1350 file_len = sbuf.st_size;
1351 fmode = dos_mode(conn,fname,&sbuf);
1352 if(fmode == 0)
1353 fmode = FILE_ATTRIBUTE_NORMAL;
1355 if (fmode & aDIR) {
1356 close_file(fsp,False);
1357 restore_case_semantics(file_attributes);
1358 return ERROR_DOS(ERRDOS,ERRnoaccess);
1362 * If the caller set the extended oplock request bit
1363 * and we granted one (by whatever means) - set the
1364 * correct bit for extended oplock reply.
1367 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
1368 extended_oplock_granted = True;
1370 if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
1371 extended_oplock_granted = True;
1375 * Now try and apply the desired SD.
1378 if (sd_len && !NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION))) {
1379 close_file(fsp,False);
1380 restore_case_semantics(file_attributes);
1381 return ERROR_NT(nt_status);
1384 restore_case_semantics(file_attributes);
1386 /* Save the requested allocation size. */
1387 allocation_size = (SMB_BIG_UINT)IVAL(params,12);
1388 #ifdef LARGE_SMB_OFF_T
1389 allocation_size |= (((SMB_BIG_UINT)IVAL(params,16)) << 32);
1390 #endif
1391 if (allocation_size && (allocation_size > file_len)) {
1392 fsp->initial_allocation_size = SMB_ROUNDUP(allocation_size,SMB_ROUNDUP_ALLOCATION_SIZE);
1393 if (vfs_allocate_file_space(fsp, fsp->initial_allocation_size) == -1) {
1394 close_file(fsp,False);
1395 return ERROR_NT(NT_STATUS_DISK_FULL);
1397 } else {
1398 fsp->initial_allocation_size = SMB_ROUNDUP(((SMB_BIG_UINT)file_len),SMB_ROUNDUP_ALLOCATION_SIZE);
1401 /* Realloc the size of parameters and data we will return */
1402 params = nttrans_realloc(ppparams, 69);
1403 if(params == NULL)
1404 return ERROR_DOS(ERRDOS,ERRnomem);
1406 p = params;
1407 if (extended_oplock_granted)
1408 SCVAL(p,0, BATCH_OPLOCK_RETURN);
1409 else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
1410 SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
1411 else
1412 SCVAL(p,0,NO_OPLOCK_RETURN);
1414 p += 2;
1415 SSVAL(p,0,fsp->fnum);
1416 p += 2;
1417 if ((create_disposition == FILE_SUPERSEDE) && (smb_action == FILE_WAS_OVERWRITTEN))
1418 SIVAL(p,0,FILE_WAS_SUPERSEDED);
1419 else
1420 SIVAL(p,0,smb_action);
1421 p += 8;
1423 /* Create time. */
1424 c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
1426 if (lp_dos_filetime_resolution(SNUM(conn))) {
1427 c_time &= ~1;
1428 sbuf.st_atime &= ~1;
1429 sbuf.st_mtime &= ~1;
1430 sbuf.st_mtime &= ~1;
1433 put_long_date(p,c_time);
1434 p += 8;
1435 put_long_date(p,sbuf.st_atime); /* access time */
1436 p += 8;
1437 put_long_date(p,sbuf.st_mtime); /* write time */
1438 p += 8;
1439 put_long_date(p,sbuf.st_mtime); /* change time */
1440 p += 8;
1441 SIVAL(p,0,fmode); /* File Attributes. */
1442 p += 4;
1443 SOFF_T(p, 0, get_allocation_size(fsp,&sbuf));
1444 p += 8;
1445 SOFF_T(p,0,file_len);
1447 DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
1449 /* Send the required number of replies */
1450 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
1452 return -1;
1455 /****************************************************************************
1456 Reply to a NT CANCEL request.
1457 ****************************************************************************/
1459 int reply_ntcancel(connection_struct *conn,
1460 char *inbuf,char *outbuf,int length,int bufsize)
1463 * Go through and cancel any pending change notifies.
1466 int mid = SVAL(inbuf,smb_mid);
1467 START_PROFILE(SMBntcancel);
1468 remove_pending_change_notify_requests_by_mid(mid);
1469 remove_pending_lock_requests_by_mid(mid);
1470 srv_cancel_sign_response(mid);
1472 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1474 END_PROFILE(SMBntcancel);
1475 return(-1);
1478 /****************************************************************************
1479 Reply to an unsolicited SMBNTtranss - just ignore it!
1480 ****************************************************************************/
1482 int reply_nttranss(connection_struct *conn,
1483 char *inbuf,char *outbuf,int length,int bufsize)
1485 START_PROFILE(SMBnttranss);
1486 DEBUG(4,("Ignoring nttranss of length %d\n",length));
1487 END_PROFILE(SMBnttranss);
1488 return(-1);
1491 /****************************************************************************
1492 Reply to a notify change - queue the request and
1493 don't allow a directory to be opened.
1494 ****************************************************************************/
1496 static int call_nt_transact_notify_change(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1497 char **ppsetup, uint32 setup_count,
1498 char **ppparams, uint32 parameter_count,
1499 char **ppdata, uint32 data_count)
1501 char *setup = *ppsetup;
1502 files_struct *fsp;
1503 uint32 flags;
1505 if(setup_count < 6)
1506 return ERROR_DOS(ERRDOS,ERRbadfunc);
1508 fsp = file_fsp(setup,4);
1509 flags = IVAL(setup, 0);
1511 DEBUG(3,("call_nt_transact_notify_change\n"));
1513 if(!fsp)
1514 return ERROR_DOS(ERRDOS,ERRbadfid);
1516 if((!fsp->is_directory) || (conn != fsp->conn))
1517 return ERROR_DOS(ERRDOS,ERRbadfid);
1519 if (!change_notify_set(inbuf, fsp, conn, flags))
1520 return(UNIXERROR(ERRDOS,ERRbadfid));
1522 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1523 name = %s\n", fsp->fsp_name ));
1525 return -1;
1528 /****************************************************************************
1529 Reply to an NT transact rename command.
1530 ****************************************************************************/
1532 static int call_nt_transact_rename(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1533 char **ppsetup, uint32 setup_count,
1534 char **ppparams, uint32 parameter_count,
1535 char **ppdata, uint32 data_count)
1537 char *params = *ppparams;
1538 pstring new_name;
1539 files_struct *fsp = NULL;
1540 BOOL replace_if_exists = False;
1541 NTSTATUS status;
1543 if(parameter_count < 4)
1544 return ERROR_DOS(ERRDOS,ERRbadfunc);
1546 fsp = file_fsp(params, 0);
1547 replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1548 CHECK_FSP(fsp, conn);
1549 srvstr_pull(inbuf, new_name, params+4, sizeof(new_name), -1, STR_TERMINATE);
1550 status = check_path_syntax(new_name);
1551 if (!NT_STATUS_IS_OK(status)) {
1552 return ERROR_NT(status);
1555 status = rename_internals(conn, fsp->fsp_name,
1556 new_name, replace_if_exists);
1557 if (!NT_STATUS_IS_OK(status))
1558 return ERROR_NT(status);
1561 * Rename was successful.
1563 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1565 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1566 fsp->fsp_name, new_name));
1569 * Win2k needs a changenotify request response before it will
1570 * update after a rename..
1573 process_pending_change_notify_queue((time_t)0);
1575 return -1;
1578 /******************************************************************************
1579 Fake up a completely empty SD.
1580 *******************************************************************************/
1582 static size_t get_null_nt_acl(TALLOC_CTX *mem_ctx, SEC_DESC **ppsd)
1584 extern DOM_SID global_sid_World;
1585 size_t sd_size;
1587 *ppsd = make_standard_sec_desc( mem_ctx, &global_sid_World, &global_sid_World, NULL, &sd_size);
1588 if(!*ppsd) {
1589 DEBUG(0,("get_null_nt_acl: Unable to malloc space for security descriptor.\n"));
1590 sd_size = 0;
1593 return sd_size;
1596 /****************************************************************************
1597 Reply to query a security descriptor.
1598 ****************************************************************************/
1600 static int call_nt_transact_query_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1601 char **ppsetup, uint32 setup_count,
1602 char **ppparams, uint32 parameter_count,
1603 char **ppdata, uint32 data_count)
1605 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
1606 char *params = *ppparams;
1607 char *data = *ppdata;
1608 prs_struct pd;
1609 SEC_DESC *psd = NULL;
1610 size_t sd_size;
1611 uint32 security_info_wanted;
1612 TALLOC_CTX *mem_ctx;
1613 files_struct *fsp = NULL;
1615 if(parameter_count < 8)
1616 return ERROR_DOS(ERRDOS,ERRbadfunc);
1618 fsp = file_fsp(params,0);
1619 if(!fsp)
1620 return ERROR_DOS(ERRDOS,ERRbadfid);
1622 security_info_wanted = IVAL(params,4);
1624 DEBUG(3,("call_nt_transact_query_security_desc: file = %s\n", fsp->fsp_name ));
1626 params = nttrans_realloc(ppparams, 4);
1627 if(params == NULL)
1628 return ERROR_DOS(ERRDOS,ERRnomem);
1630 if ((mem_ctx = talloc_init("call_nt_transact_query_security_desc")) == NULL) {
1631 DEBUG(0,("call_nt_transact_query_security_desc: talloc_init failed.\n"));
1632 return ERROR_DOS(ERRDOS,ERRnomem);
1636 * Get the permissions to return.
1639 if (!lp_nt_acl_support(SNUM(conn)))
1640 sd_size = get_null_nt_acl(mem_ctx, &psd);
1641 else
1642 sd_size = SMB_VFS_FGET_NT_ACL(fsp, fsp->fd, security_info_wanted, &psd);
1644 if (sd_size == 0) {
1645 talloc_destroy(mem_ctx);
1646 return(UNIXERROR(ERRDOS,ERRnoaccess));
1649 DEBUG(3,("call_nt_transact_query_security_desc: sd_size = %d.\n",(int)sd_size));
1651 SIVAL(params,0,(uint32)sd_size);
1653 if(max_data_count < sd_size) {
1655 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_BUFFER_TOO_SMALL,
1656 params, 4, *ppdata, 0);
1657 talloc_destroy(mem_ctx);
1658 return -1;
1662 * Allocate the data we will point this at.
1665 data = nttrans_realloc(ppdata, sd_size);
1666 if(data == NULL) {
1667 talloc_destroy(mem_ctx);
1668 return ERROR_DOS(ERRDOS,ERRnomem);
1672 * Init the parse struct we will marshall into.
1675 prs_init(&pd, 0, mem_ctx, MARSHALL);
1678 * Setup the prs_struct to point at the memory we just
1679 * allocated.
1682 prs_give_memory( &pd, data, (uint32)sd_size, False);
1685 * Finally, linearize into the outgoing buffer.
1688 if(!sec_io_desc( "sd data", &psd, &pd, 1)) {
1689 DEBUG(0,("call_nt_transact_query_security_desc: Error in marshalling \
1690 security descriptor.\n"));
1692 * Return access denied for want of a better error message..
1694 talloc_destroy(mem_ctx);
1695 return(UNIXERROR(ERRDOS,ERRnoaccess));
1699 * Now we can delete the security descriptor.
1702 talloc_destroy(mem_ctx);
1704 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 4, data, (int)sd_size);
1705 return -1;
1708 /****************************************************************************
1709 Reply to set a security descriptor. Map to UNIX perms or POSIX ACLs.
1710 ****************************************************************************/
1712 static int call_nt_transact_set_security_desc(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1713 char **ppsetup, uint32 setup_count,
1714 char **ppparams, uint32 parameter_count,
1715 char **ppdata, uint32 data_count)
1717 char *params= *ppparams;
1718 char *data = *ppdata;
1719 files_struct *fsp = NULL;
1720 uint32 security_info_sent = 0;
1721 NTSTATUS nt_status;
1723 if(parameter_count < 8)
1724 return ERROR_DOS(ERRDOS,ERRbadfunc);
1726 if((fsp = file_fsp(params,0)) == NULL)
1727 return ERROR_DOS(ERRDOS,ERRbadfid);
1729 if(!lp_nt_acl_support(SNUM(conn)))
1730 goto done;
1732 security_info_sent = IVAL(params,4);
1734 DEBUG(3,("call_nt_transact_set_security_desc: file = %s, sent 0x%x\n", fsp->fsp_name,
1735 (unsigned int)security_info_sent ));
1737 if (data_count == 0)
1738 return ERROR_DOS(ERRDOS, ERRnoaccess);
1740 if (!NT_STATUS_IS_OK(nt_status = set_sd( fsp, data, data_count, security_info_sent)))
1741 return ERROR_NT(nt_status);
1743 done:
1745 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1746 return -1;
1749 /****************************************************************************
1750 Reply to NT IOCTL
1751 ****************************************************************************/
1753 static int call_nt_transact_ioctl(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
1754 char **ppsetup, uint32 setup_count,
1755 char **ppparams, uint32 parameter_count,
1756 char **ppdata, uint32 data_count)
1758 uint32 function;
1759 uint16 fidnum;
1760 files_struct *fsp;
1761 uint8 isFSctl;
1762 uint8 compfilter;
1763 static BOOL logged_message;
1764 char *pdata = *ppdata;
1766 if (setup_count != 8) {
1767 DEBUG(3,("call_nt_transact_ioctl: invalid setup count %d\n", setup_count));
1768 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1771 function = IVAL(*ppsetup, 0);
1772 fidnum = SVAL(*ppsetup, 4);
1773 isFSctl = CVAL(*ppsetup, 6);
1774 compfilter = CVAL(*ppsetup, 7);
1776 DEBUG(10,("call_nt_transact_ioctl: function[0x%08X] FID[0x%04X] isFSctl[0x%02X] compfilter[0x%02X]\n",
1777 function, fidnum, isFSctl, compfilter));
1779 fsp=file_fsp(*ppsetup, 4);
1780 /* this check is done in each implemented function case for now
1781 because I don't want to break anything... --metze
1782 FSP_BELONGS_CONN(fsp,conn);*/
1784 switch (function) {
1785 case FSCTL_SET_SPARSE:
1786 /* pretend this succeeded - tho strictly we should
1787 mark the file sparse (if the local fs supports it)
1788 so we can know if we need to pre-allocate or not */
1790 DEBUG(10,("FSCTL_SET_SPARSE: called on FID[0x%04X](but not implemented)\n", fidnum));
1791 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1792 return -1;
1794 case FSCTL_0x000900C0:
1795 /* pretend this succeeded - don't know what this really is
1796 but works ok like this --metze
1799 DEBUG(10,("FSCTL_0x000900C0: called on FID[0x%04X](but not implemented)\n",fidnum));
1800 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1801 return -1;
1803 case FSCTL_GET_REPARSE_POINT:
1804 /* pretend this fail - my winXP does it like this
1805 * --metze
1808 DEBUG(10,("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1809 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
1810 return -1;
1812 case FSCTL_SET_REPARSE_POINT:
1813 /* pretend this fail - I'm assuming this because of the FSCTL_GET_REPARSE_POINT case.
1814 * --metze
1817 DEBUG(10,("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X](but not implemented)\n",fidnum));
1818 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_NOT_A_REPARSE_POINT, NULL, 0, NULL, 0);
1819 return -1;
1821 case FSCTL_GET_SHADOW_COPY_DATA: /* don't know if this name is right...*/
1824 * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
1825 * and return their volume names. If max_data_count is 16, then it is just
1826 * asking for the number of volumes and length of the combined names.
1828 * pdata is the data allocated by our caller, but that uses
1829 * total_data_count (which is 0 in our case) rather than max_data_count.
1830 * Allocate the correct amount and return the pointer to let
1831 * it be deallocated when we return.
1833 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
1834 SHADOW_COPY_DATA *shadow_data = NULL;
1835 TALLOC_CTX *shadow_mem_ctx = NULL;
1836 BOOL labels = False;
1837 uint32 labels_data_count = 0;
1838 uint32 i;
1839 char *cur_pdata;
1841 FSP_BELONGS_CONN(fsp,conn);
1843 if (max_data_count < 16) {
1844 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
1845 max_data_count));
1846 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);
1849 if (max_data_count > 16) {
1850 labels = True;
1853 shadow_mem_ctx = talloc_init("SHADOW_COPY_DATA");
1854 if (shadow_mem_ctx == NULL) {
1855 DEBUG(0,("talloc_init(SHADOW_COPY_DATA) failed!\n"));
1856 return ERROR_NT(NT_STATUS_NO_MEMORY);
1859 shadow_data = (SHADOW_COPY_DATA *)talloc_zero(shadow_mem_ctx,sizeof(SHADOW_COPY_DATA));
1860 if (shadow_data == NULL) {
1861 DEBUG(0,("talloc_zero() failed!\n"));
1862 return ERROR_NT(NT_STATUS_NO_MEMORY);
1865 shadow_data->mem_ctx = shadow_mem_ctx;
1868 * Call the VFS routine to actually do the work.
1870 if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
1871 talloc_destroy(shadow_data->mem_ctx);
1872 if (errno == ENOSYS) {
1873 DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n",
1874 conn->connectpath));
1875 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1876 } else {
1877 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n",
1878 conn->connectpath));
1879 return ERROR_NT(NT_STATUS_UNSUCCESSFUL);
1883 labels_data_count = (shadow_data->num_volumes*2*sizeof(SHADOW_COPY_LABEL))+2;
1885 if (!labels) {
1886 data_count = 16;
1887 } else {
1888 data_count = 12+labels_data_count+4;
1891 if (max_data_count<data_count) {
1892 DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
1893 max_data_count,data_count));
1894 talloc_destroy(shadow_data->mem_ctx);
1895 return ERROR_NT(NT_STATUS_BUFFER_TOO_SMALL);
1898 pdata = nttrans_realloc(ppdata, data_count);
1899 if (pdata == NULL) {
1900 talloc_destroy(shadow_data->mem_ctx);
1901 return ERROR_NT(NT_STATUS_NO_MEMORY);
1904 cur_pdata = pdata;
1906 /* num_volumes 4 bytes */
1907 SIVAL(pdata,0,shadow_data->num_volumes);
1909 if (labels) {
1910 /* num_labels 4 bytes */
1911 SIVAL(pdata,4,shadow_data->num_volumes);
1914 /* needed_data_count 4 bytes */
1915 SIVAL(pdata,8,labels_data_count);
1917 cur_pdata+=12;
1919 DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
1920 shadow_data->num_volumes,fsp->fsp_name));
1921 if (labels && shadow_data->labels) {
1922 for (i=0;i<shadow_data->num_volumes;i++) {
1923 srvstr_push(outbuf, cur_pdata, shadow_data->labels[i], 2*sizeof(SHADOW_COPY_LABEL), STR_UNICODE|STR_TERMINATE);
1924 cur_pdata+=2*sizeof(SHADOW_COPY_LABEL);
1925 DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
1929 talloc_destroy(shadow_data->mem_ctx);
1931 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, pdata, data_count);
1933 return -1;
1936 case FSCTL_FIND_FILES_BY_SID: /* I hope this name is right */
1938 /* pretend this succeeded -
1940 * we have to send back a list with all files owned by this SID
1942 * but I have to check that --metze
1944 DOM_SID sid;
1945 uid_t uid;
1946 size_t sid_len = MIN(data_count-4,SID_MAX_SIZE);
1948 DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n",fidnum));
1950 FSP_BELONGS_CONN(fsp,conn);
1952 /* unknown 4 bytes: this is not the length of the sid :-( */
1953 /*unknown = IVAL(pdata,0);*/
1955 sid_parse(pdata+4,sid_len,&sid);
1956 DEBUGADD(10,("for SID: %s\n",sid_string_static(&sid)));
1958 if (!NT_STATUS_IS_OK(sid_to_uid(&sid, &uid))) {
1959 DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
1960 sid_string_static(&sid),(unsigned long)sid_len));
1961 uid = (-1);
1964 /* we can take a look at the find source :-)
1966 * find ./ -uid $uid -name '*' is what we need here
1969 * and send 4bytes len and then NULL terminated unicode strings
1970 * for each file
1972 * but I don't know how to deal with the paged results
1973 * (maybe we can hang the result anywhere in the fsp struct)
1975 * we don't send all files at once
1976 * and at the next we should *not* start from the beginning,
1977 * so we have to cache the result
1979 * --metze
1982 /* this works for now... */
1983 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, NULL, 0, NULL, 0);
1984 return -1;
1986 default:
1987 if (!logged_message) {
1988 logged_message = True; /* Only print this once... */
1989 DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n",
1990 function));
1994 return ERROR_NT(NT_STATUS_NOT_SUPPORTED);
1998 #ifdef HAVE_SYS_QUOTAS
1999 /****************************************************************************
2000 Reply to get user quota
2001 ****************************************************************************/
2003 static int call_nt_transact_get_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2004 char **ppsetup, uint32 setup_count,
2005 char **ppparams, uint32 parameter_count,
2006 char **ppdata, uint32 data_count)
2008 NTSTATUS nt_status = NT_STATUS_OK;
2009 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2010 char *params = *ppparams;
2011 char *pdata = *ppdata;
2012 char *entry;
2013 int data_len=0,param_len=0;
2014 int qt_len=0;
2015 int entry_len = 0;
2016 files_struct *fsp = NULL;
2017 uint16 level = 0;
2018 size_t sid_len;
2019 DOM_SID sid;
2020 BOOL start_enum = True;
2021 SMB_NTQUOTA_STRUCT qt;
2022 SMB_NTQUOTA_LIST *tmp_list;
2023 SMB_NTQUOTA_HANDLE *qt_handle = NULL;
2024 extern struct current_user current_user;
2026 ZERO_STRUCT(qt);
2028 /* access check */
2029 if (current_user.uid != 0) {
2030 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2031 lp_servicename(SNUM(conn)),conn->user));
2032 return ERROR_DOS(ERRDOS,ERRnoaccess);
2036 * Ensure minimum number of parameters sent.
2039 if (parameter_count < 4) {
2040 DEBUG(0,("TRANSACT_GET_USER_QUOTA: requires %d >= 4 bytes parameters\n",parameter_count));
2041 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2044 /* maybe we can check the quota_fnum */
2045 fsp = file_fsp(params,0);
2046 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2047 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2048 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2051 /* the NULL pointer cheking for fsp->fake_file_handle->pd
2052 * is done by CHECK_NTQUOTA_HANDLE_OK()
2054 qt_handle = (SMB_NTQUOTA_HANDLE *)fsp->fake_file_handle->pd;
2056 level = SVAL(params,2);
2058 /* unknown 12 bytes leading in params */
2060 switch (level) {
2061 case TRANSACT_GET_USER_QUOTA_LIST_CONTINUE:
2062 /* seems that we should continue with the enum here --metze */
2064 if (qt_handle->quota_list!=NULL &&
2065 qt_handle->tmp_list==NULL) {
2067 /* free the list */
2068 free_ntquota_list(&(qt_handle->quota_list));
2070 /* Realloc the size of parameters and data we will return */
2071 param_len = 4;
2072 params = nttrans_realloc(ppparams, param_len);
2073 if(params == NULL)
2074 return ERROR_DOS(ERRDOS,ERRnomem);
2076 data_len = 0;
2077 SIVAL(params,0,data_len);
2079 break;
2082 start_enum = False;
2084 case TRANSACT_GET_USER_QUOTA_LIST_START:
2086 if (qt_handle->quota_list==NULL &&
2087 qt_handle->tmp_list==NULL) {
2088 start_enum = True;
2091 if (start_enum && vfs_get_user_ntquota_list(fsp,&(qt_handle->quota_list))!=0)
2092 return ERROR_DOS(ERRSRV,ERRerror);
2094 /* Realloc the size of parameters and data we will return */
2095 param_len = 4;
2096 params = nttrans_realloc(ppparams, param_len);
2097 if(params == NULL)
2098 return ERROR_DOS(ERRDOS,ERRnomem);
2100 /* we should not trust the value in max_data_count*/
2101 max_data_count = MIN(max_data_count,2048);
2103 pdata = nttrans_realloc(ppdata, max_data_count);/* should be max data count from client*/
2104 if(pdata == NULL)
2105 return ERROR_DOS(ERRDOS,ERRnomem);
2107 entry = pdata;
2110 /* set params Size of returned Quota Data 4 bytes*/
2111 /* but set it later when we know it */
2113 /* for each entry push the data */
2115 if (start_enum) {
2116 qt_handle->tmp_list = qt_handle->quota_list;
2119 tmp_list = qt_handle->tmp_list;
2121 for (;((tmp_list!=NULL)&&((qt_len +40+SID_MAX_SIZE)<max_data_count));
2122 tmp_list=tmp_list->next,entry+=entry_len,qt_len+=entry_len) {
2124 sid_len = sid_size(&tmp_list->quotas->sid);
2125 entry_len = 40 + sid_len;
2127 /* nextoffset entry 4 bytes */
2128 SIVAL(entry,0,entry_len);
2130 /* then the len of the SID 4 bytes */
2131 SIVAL(entry,4,sid_len);
2133 /* unknown data 8 bytes SMB_BIG_UINT */
2134 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-metze*/
2136 /* the used disk space 8 bytes SMB_BIG_UINT */
2137 SBIG_UINT(entry,16,tmp_list->quotas->usedspace);
2139 /* the soft quotas 8 bytes SMB_BIG_UINT */
2140 SBIG_UINT(entry,24,tmp_list->quotas->softlim);
2142 /* the hard quotas 8 bytes SMB_BIG_UINT */
2143 SBIG_UINT(entry,32,tmp_list->quotas->hardlim);
2145 /* and now the SID */
2146 sid_linearize(entry+40, sid_len, &tmp_list->quotas->sid);
2149 qt_handle->tmp_list = tmp_list;
2151 /* overwrite the offset of the last entry */
2152 SIVAL(entry-entry_len,0,0);
2154 data_len = 4+qt_len;
2155 /* overwrite the params quota_data_len */
2156 SIVAL(params,0,data_len);
2158 break;
2160 case TRANSACT_GET_USER_QUOTA_FOR_SID:
2162 /* unknown 4 bytes IVAL(pdata,0) */
2164 if (data_count < 8) {
2165 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %d bytes data\n",data_count,8));
2166 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2169 sid_len = IVAL(pdata,4);
2171 if (data_count < 8+sid_len) {
2172 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: requires %d >= %lu bytes data\n",data_count,(unsigned long)(8+sid_len)));
2173 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2176 data_len = 4+40+sid_len;
2178 if (max_data_count < data_len) {
2179 DEBUG(0,("TRANSACT_GET_USER_QUOTA_FOR_SID: max_data_count(%d) < data_len(%d)\n",
2180 max_data_count, data_len));
2181 param_len = 4;
2182 SIVAL(params,0,data_len);
2183 data_len = 0;
2184 nt_status = NT_STATUS_BUFFER_TOO_SMALL;
2185 break;
2188 sid_parse(pdata+8,sid_len,&sid);
2191 if (vfs_get_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2192 ZERO_STRUCT(qt);
2194 * we have to return zero's in all fields
2195 * instead of returning an error here
2196 * --metze
2200 /* Realloc the size of parameters and data we will return */
2201 param_len = 4;
2202 params = nttrans_realloc(ppparams, param_len);
2203 if(params == NULL)
2204 return ERROR_DOS(ERRDOS,ERRnomem);
2206 pdata = nttrans_realloc(ppdata, data_len);
2207 if(pdata == NULL)
2208 return ERROR_DOS(ERRDOS,ERRnomem);
2210 entry = pdata;
2212 /* set params Size of returned Quota Data 4 bytes*/
2213 SIVAL(params,0,data_len);
2215 /* nextoffset entry 4 bytes */
2216 SIVAL(entry,0,0);
2218 /* then the len of the SID 4 bytes */
2219 SIVAL(entry,4,sid_len);
2221 /* unknown data 8 bytes SMB_BIG_UINT */
2222 SBIG_UINT(entry,8,(SMB_BIG_UINT)0); /* this is not 0 in windows...-mezte*/
2224 /* the used disk space 8 bytes SMB_BIG_UINT */
2225 SBIG_UINT(entry,16,qt.usedspace);
2227 /* the soft quotas 8 bytes SMB_BIG_UINT */
2228 SBIG_UINT(entry,24,qt.softlim);
2230 /* the hard quotas 8 bytes SMB_BIG_UINT */
2231 SBIG_UINT(entry,32,qt.hardlim);
2233 /* and now the SID */
2234 sid_linearize(entry+40, sid_len, &sid);
2236 break;
2238 default:
2239 DEBUG(0,("do_nt_transact_get_user_quota: fnum %d unknown level 0x%04hX\n",fsp->fnum,level));
2240 return ERROR_DOS(ERRSRV,ERRerror);
2241 break;
2244 send_nt_replies(inbuf, outbuf, bufsize, nt_status, params, param_len, pdata, data_len);
2246 return -1;
2249 /****************************************************************************
2250 Reply to set user quota
2251 ****************************************************************************/
2253 static int call_nt_transact_set_user_quota(connection_struct *conn, char *inbuf, char *outbuf, int length, int bufsize,
2254 char **ppsetup, uint32 setup_count,
2255 char **ppparams, uint32 parameter_count,
2256 char **ppdata, uint32 data_count)
2258 char *params = *ppparams;
2259 char *pdata = *ppdata;
2260 int data_len=0,param_len=0;
2261 SMB_NTQUOTA_STRUCT qt;
2262 size_t sid_len;
2263 DOM_SID sid;
2264 files_struct *fsp = NULL;
2266 ZERO_STRUCT(qt);
2268 /* access check */
2269 if (conn->admin_user != True) {
2270 DEBUG(1,("set_user_quota: access_denied service [%s] user [%s]\n",
2271 lp_servicename(SNUM(conn)),conn->user));
2272 return ERROR_DOS(ERRDOS,ERRnoaccess);
2276 * Ensure minimum number of parameters sent.
2279 if (parameter_count < 2) {
2280 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= 2 bytes parameters\n",parameter_count));
2281 return ERROR_DOS(ERRDOS,ERRinvalidparam);
2284 /* maybe we can check the quota_fnum */
2285 fsp = file_fsp(params,0);
2286 if (!CHECK_NTQUOTA_HANDLE_OK(fsp,conn)) {
2287 DEBUG(3,("TRANSACT_GET_USER_QUOTA: no valid QUOTA HANDLE\n"));
2288 return ERROR_NT(NT_STATUS_INVALID_HANDLE);
2291 if (data_count < 40) {
2292 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %d bytes data\n",data_count,40));
2293 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2296 /* offset to next quota record.
2297 * 4 bytes IVAL(pdata,0)
2298 * unused here...
2301 /* sid len */
2302 sid_len = IVAL(pdata,4);
2304 if (data_count < 40+sid_len) {
2305 DEBUG(0,("TRANSACT_SET_USER_QUOTA: requires %d >= %lu bytes data\n",data_count,(unsigned long)40+sid_len));
2306 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2309 /* unknown 8 bytes in pdata
2310 * maybe its the change time in NTTIME
2313 /* the used space 8 bytes (SMB_BIG_UINT)*/
2314 qt.usedspace = (SMB_BIG_UINT)IVAL(pdata,16);
2315 #ifdef LARGE_SMB_OFF_T
2316 qt.usedspace |= (((SMB_BIG_UINT)IVAL(pdata,20)) << 32);
2317 #else /* LARGE_SMB_OFF_T */
2318 if ((IVAL(pdata,20) != 0)&&
2319 ((qt.usedspace != 0xFFFFFFFF)||
2320 (IVAL(pdata,20)!=0xFFFFFFFF))) {
2321 /* more than 32 bits? */
2322 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2324 #endif /* LARGE_SMB_OFF_T */
2326 /* the soft quotas 8 bytes (SMB_BIG_UINT)*/
2327 qt.softlim = (SMB_BIG_UINT)IVAL(pdata,24);
2328 #ifdef LARGE_SMB_OFF_T
2329 qt.softlim |= (((SMB_BIG_UINT)IVAL(pdata,28)) << 32);
2330 #else /* LARGE_SMB_OFF_T */
2331 if ((IVAL(pdata,28) != 0)&&
2332 ((qt.softlim != 0xFFFFFFFF)||
2333 (IVAL(pdata,28)!=0xFFFFFFFF))) {
2334 /* more than 32 bits? */
2335 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2337 #endif /* LARGE_SMB_OFF_T */
2339 /* the hard quotas 8 bytes (SMB_BIG_UINT)*/
2340 qt.hardlim = (SMB_BIG_UINT)IVAL(pdata,32);
2341 #ifdef LARGE_SMB_OFF_T
2342 qt.hardlim |= (((SMB_BIG_UINT)IVAL(pdata,36)) << 32);
2343 #else /* LARGE_SMB_OFF_T */
2344 if ((IVAL(pdata,36) != 0)&&
2345 ((qt.hardlim != 0xFFFFFFFF)||
2346 (IVAL(pdata,36)!=0xFFFFFFFF))) {
2347 /* more than 32 bits? */
2348 return ERROR_DOS(ERRDOS,ERRunknownlevel);
2350 #endif /* LARGE_SMB_OFF_T */
2352 sid_parse(pdata+40,sid_len,&sid);
2353 DEBUGADD(8,("SID: %s\n",sid_string_static(&sid)));
2355 /* 44 unknown bytes left... */
2357 if (vfs_set_ntquota(fsp, SMB_USER_QUOTA_TYPE, &sid, &qt)!=0) {
2358 return ERROR_DOS(ERRSRV,ERRerror);
2361 send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, param_len, pdata, data_len);
2363 return -1;
2365 #endif /* HAVE_SYS_QUOTAS */
2367 /****************************************************************************
2368 Reply to a SMBNTtrans.
2369 ****************************************************************************/
2371 int reply_nttrans(connection_struct *conn,
2372 char *inbuf,char *outbuf,int length,int bufsize)
2374 int outsize = 0;
2375 #if 0 /* Not used. */
2376 uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount);
2377 uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
2378 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
2379 #endif /* Not used. */
2380 uint32 total_parameter_count = IVAL(inbuf, smb_nt_TotalParameterCount);
2381 uint32 total_data_count = IVAL(inbuf, smb_nt_TotalDataCount);
2382 uint32 parameter_count = IVAL(inbuf,smb_nt_ParameterCount);
2383 uint32 parameter_offset = IVAL(inbuf,smb_nt_ParameterOffset);
2384 uint32 data_count = IVAL(inbuf,smb_nt_DataCount);
2385 uint32 data_offset = IVAL(inbuf,smb_nt_DataOffset);
2386 uint16 setup_count = 2*CVAL(inbuf,smb_nt_SetupCount); /* setup count is in *words* */
2387 uint16 function_code = SVAL( inbuf, smb_nt_Function);
2388 char *params = NULL, *data = NULL, *setup = NULL;
2389 uint32 num_params_sofar, num_data_sofar;
2390 START_PROFILE(SMBnttrans);
2392 if(global_oplock_break &&
2393 ((function_code == NT_TRANSACT_CREATE) ||
2394 (function_code == NT_TRANSACT_RENAME))) {
2396 * Queue this open message as we are the process of an oplock break.
2399 DEBUG(2,("reply_nttrans: queueing message code 0x%x \
2400 due to being in oplock break state.\n", (unsigned int)function_code ));
2402 push_oplock_pending_smb_message( inbuf, length);
2403 END_PROFILE(SMBnttrans);
2404 return -1;
2407 if (IS_IPC(conn) && (function_code != NT_TRANSACT_CREATE)) {
2408 END_PROFILE(SMBnttrans);
2409 return ERROR_DOS(ERRSRV,ERRaccess);
2412 outsize = set_message(outbuf,0,0,True);
2415 * All nttrans messages we handle have smb_wct == 19 + setup_count.
2416 * Ensure this is so as a sanity check.
2419 if(CVAL(inbuf, smb_wct) != 19 + (setup_count/2)) {
2420 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
2421 CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
2422 goto bad_param;
2425 /* Allocate the space for the setup, the maximum needed parameters and data */
2427 if(setup_count > 0)
2428 setup = (char *)malloc(setup_count);
2429 if (total_parameter_count > 0)
2430 params = (char *)malloc(total_parameter_count);
2431 if (total_data_count > 0)
2432 data = (char *)malloc(total_data_count);
2434 if ((total_parameter_count && !params) || (total_data_count && !data) ||
2435 (setup_count && !setup)) {
2436 SAFE_FREE(setup);
2437 SAFE_FREE(params);
2438 SAFE_FREE(data);
2439 DEBUG(0,("reply_nttrans : Out of memory\n"));
2440 END_PROFILE(SMBnttrans);
2441 return ERROR_DOS(ERRDOS,ERRnomem);
2444 /* Copy the param and data bytes sent with this request into the params buffer */
2445 num_params_sofar = parameter_count;
2446 num_data_sofar = data_count;
2448 if (parameter_count > total_parameter_count || data_count > total_data_count)
2449 goto bad_param;
2451 if(setup) {
2452 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
2453 if ((smb_nt_SetupStart + setup_count < smb_nt_SetupStart) ||
2454 (smb_nt_SetupStart + setup_count < setup_count))
2455 goto bad_param;
2456 if (smb_nt_SetupStart + setup_count > length)
2457 goto bad_param;
2459 memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
2460 dump_data(10, setup, setup_count);
2462 if(params) {
2463 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count));
2464 if ((parameter_offset + parameter_count < parameter_offset) ||
2465 (parameter_offset + parameter_count < parameter_count))
2466 goto bad_param;
2467 if ((smb_base(inbuf) + parameter_offset + parameter_count > inbuf + length)||
2468 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
2469 goto bad_param;
2471 memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
2472 dump_data(10, params, parameter_count);
2474 if(data) {
2475 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
2476 if ((data_offset + data_count < data_offset) || (data_offset + data_count < data_count))
2477 goto bad_param;
2478 if ((smb_base(inbuf) + data_offset + data_count > inbuf + length) ||
2479 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
2480 goto bad_param;
2482 memcpy( data, smb_base(inbuf) + data_offset, data_count);
2483 dump_data(10, data, data_count);
2486 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2488 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2489 /* We need to send an interim response then receive the rest
2490 of the parameter/data bytes */
2491 outsize = set_message(outbuf,0,0,True);
2492 srv_signing_trans_stop();
2493 if (!send_smb(smbd_server_fd(),outbuf))
2494 exit_server("reply_nttrans: send_smb failed.");
2496 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
2497 BOOL ret;
2498 uint32 parameter_displacement;
2499 uint32 data_displacement;
2501 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
2504 * The sequence number for the trans reply is always
2505 * based on the last secondary received.
2508 srv_signing_trans_start(SVAL(inbuf,smb_mid));
2510 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
2511 outsize = set_message(outbuf,0,0,True);
2512 if(ret) {
2513 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
2514 } else {
2515 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
2516 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
2518 goto bad_param;
2521 /* Revise total_params and total_data in case they have changed downwards */
2522 if (IVAL(inbuf, smb_nts_TotalParameterCount) < total_parameter_count)
2523 total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
2524 if (IVAL(inbuf, smb_nts_TotalDataCount) < total_data_count)
2525 total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
2527 parameter_count = IVAL(inbuf,smb_nts_ParameterCount);
2528 parameter_offset = IVAL(inbuf, smb_nts_ParameterOffset);
2529 parameter_displacement = IVAL(inbuf, smb_nts_ParameterDisplacement);
2530 num_params_sofar += parameter_count;
2532 data_count = IVAL(inbuf, smb_nts_DataCount);
2533 data_displacement = IVAL(inbuf, smb_nts_DataDisplacement);
2534 data_offset = IVAL(inbuf, smb_nts_DataOffset);
2535 num_data_sofar += data_count;
2537 if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count) {
2538 DEBUG(0,("reply_nttrans2: data overflow in secondary nttrans packet"));
2539 goto bad_param;
2542 if (parameter_count) {
2543 if (parameter_displacement + parameter_count >= total_parameter_count)
2544 goto bad_param;
2545 if ((parameter_displacement + parameter_count < parameter_displacement) ||
2546 (parameter_displacement + parameter_count < parameter_count))
2547 goto bad_param;
2548 if (parameter_displacement > total_parameter_count)
2549 goto bad_param;
2550 if ((smb_base(inbuf) + parameter_offset + parameter_count >= inbuf + bufsize) ||
2551 (smb_base(inbuf) + parameter_offset + parameter_count < smb_base(inbuf)))
2552 goto bad_param;
2553 if (parameter_displacement + params < params)
2554 goto bad_param;
2556 memcpy( &params[parameter_displacement], smb_base(inbuf) + parameter_offset, parameter_count);
2559 if (data_count) {
2560 if (data_displacement + data_count >= total_data_count)
2561 goto bad_param;
2562 if ((data_displacement + data_count < data_displacement) ||
2563 (data_displacement + data_count < data_count))
2564 goto bad_param;
2565 if (data_displacement > total_data_count)
2566 goto bad_param;
2567 if ((smb_base(inbuf) + data_offset + data_count >= inbuf + bufsize) ||
2568 (smb_base(inbuf) + data_offset + data_count < smb_base(inbuf)))
2569 goto bad_param;
2570 if (data_displacement + data < data)
2571 goto bad_param;
2573 memcpy( &data[data_displacement], smb_base(inbuf)+ data_offset, data_count);
2578 if (Protocol >= PROTOCOL_NT1)
2579 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_IS_LONG_NAME);
2581 /* Now we must call the relevant NT_TRANS function */
2582 switch(function_code) {
2583 case NT_TRANSACT_CREATE:
2584 START_PROFILE_NESTED(NT_transact_create);
2585 outsize = call_nt_transact_create(conn, inbuf, outbuf,
2586 length, bufsize,
2587 &setup, setup_count,
2588 &params, total_parameter_count,
2589 &data, total_data_count);
2590 END_PROFILE_NESTED(NT_transact_create);
2591 break;
2592 case NT_TRANSACT_IOCTL:
2593 START_PROFILE_NESTED(NT_transact_ioctl);
2594 outsize = call_nt_transact_ioctl(conn, inbuf, outbuf,
2595 length, bufsize,
2596 &setup, setup_count,
2597 &params, total_parameter_count,
2598 &data, total_data_count);
2599 END_PROFILE_NESTED(NT_transact_ioctl);
2600 break;
2601 case NT_TRANSACT_SET_SECURITY_DESC:
2602 START_PROFILE_NESTED(NT_transact_set_security_desc);
2603 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
2604 length, bufsize,
2605 &setup, setup_count,
2606 &params, total_parameter_count,
2607 &data, total_data_count);
2608 END_PROFILE_NESTED(NT_transact_set_security_desc);
2609 break;
2610 case NT_TRANSACT_NOTIFY_CHANGE:
2611 START_PROFILE_NESTED(NT_transact_notify_change);
2612 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
2613 length, bufsize,
2614 &setup, setup_count,
2615 &params, total_parameter_count,
2616 &data, total_data_count);
2617 END_PROFILE_NESTED(NT_transact_notify_change);
2618 break;
2619 case NT_TRANSACT_RENAME:
2620 START_PROFILE_NESTED(NT_transact_rename);
2621 outsize = call_nt_transact_rename(conn, inbuf, outbuf,
2622 length, bufsize,
2623 &setup, setup_count,
2624 &params, total_parameter_count,
2625 &data, total_data_count);
2626 END_PROFILE_NESTED(NT_transact_rename);
2627 break;
2629 case NT_TRANSACT_QUERY_SECURITY_DESC:
2630 START_PROFILE_NESTED(NT_transact_query_security_desc);
2631 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
2632 length, bufsize,
2633 &setup, setup_count,
2634 &params, total_parameter_count,
2635 &data, total_data_count);
2636 END_PROFILE_NESTED(NT_transact_query_security_desc);
2637 break;
2638 #ifdef HAVE_SYS_QUOTAS
2639 case NT_TRANSACT_GET_USER_QUOTA:
2640 START_PROFILE_NESTED(NT_transact_get_user_quota);
2641 outsize = call_nt_transact_get_user_quota(conn, inbuf, outbuf,
2642 length, bufsize,
2643 &setup, setup_count,
2644 &params, total_parameter_count,
2645 &data, total_data_count);
2646 END_PROFILE_NESTED(NT_transact_get_user_quota);
2647 break;
2648 case NT_TRANSACT_SET_USER_QUOTA:
2649 START_PROFILE_NESTED(NT_transact_set_user_quota);
2650 outsize = call_nt_transact_set_user_quota(conn, inbuf, outbuf,
2651 length, bufsize,
2652 &setup, setup_count,
2653 &params, total_parameter_count,
2654 &data, total_data_count);
2655 END_PROFILE_NESTED(NT_transact_set_user_quota);
2656 break;
2657 #endif /* HAVE_SYS_QUOTAS */
2658 default:
2659 /* Error in request */
2660 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
2661 SAFE_FREE(setup);
2662 SAFE_FREE(params);
2663 SAFE_FREE(data);
2664 END_PROFILE(SMBnttrans);
2665 srv_signing_trans_stop();
2666 return ERROR_DOS(ERRSRV,ERRerror);
2669 /* As we do not know how many data packets will need to be
2670 returned here the various call_nt_transact_xxxx calls
2671 must send their own. Thus a call_nt_transact_xxxx routine only
2672 returns a value other than -1 when it wants to send
2673 an error packet.
2676 srv_signing_trans_stop();
2678 SAFE_FREE(setup);
2679 SAFE_FREE(params);
2680 SAFE_FREE(data);
2681 END_PROFILE(SMBnttrans);
2682 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
2683 calls have already sent it. If outsize != -1 then it is
2684 returning an error packet. */
2686 bad_param:
2688 srv_signing_trans_stop();
2689 SAFE_FREE(params);
2690 SAFE_FREE(data);
2691 SAFE_FREE(setup);
2692 END_PROFILE(SMBnttrans);
2693 return ERROR_NT(NT_STATUS_INVALID_PARAMETER);