2 Unix SMB/Netbios implementation.
4 SMB NT transaction handling
5 Copyright (C) Jeremy Allison 1994-1998
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.
25 extern int DEBUGLEVEL;
28 extern int smb_read_error;
29 extern int global_oplock_break;
30 extern int chain_size;
31 extern BOOL case_sensitive;
32 extern BOOL case_preserve;
33 extern BOOL short_case_preserve;
35 static void remove_pending_change_notify_requests_by_mid(int mid);
37 static char *known_nt_pipes[] = {
53 /****************************************************************************
54 Send the required number of replies back.
55 We assume all fields other than the data fields are
56 set correctly for the type of call.
57 HACK ! Always assumes smb_setup field is zero.
58 ****************************************************************************/
60 static int send_nt_replies(char *outbuf, int bufsize, char *params,
61 int paramsize, char *pdata, int datasize)
64 int data_to_send = datasize;
65 int params_to_send = paramsize;
69 int params_sent_thistime, data_sent_thistime, total_sent_thistime;
70 int alignment_offset = 3;
71 int data_alignment_offset = 0;
74 * Initially set the wcnt area to be 18 - this is true for all
78 set_message(outbuf,18,0,True);
81 * If there genuinely are no parameters or data to send just send
85 if(params_to_send == 0 && data_to_send == 0) {
86 send_smb(Client,outbuf);
91 * When sending params and data ensure that both are nicely aligned.
92 * Only do this alignment when there is also data to send - else
93 * can cause NT redirector problems.
96 if (((params_to_send % 4) != 0) && (data_to_send != 0))
97 data_alignment_offset = 4 - (params_to_send % 4);
100 * Space is bufsize minus Netbios over TCP header minus SMB header.
101 * The alignment_offset is to align the param bytes on a four byte
102 * boundary (2 bytes for data len, one byte pad).
103 * NT needs this to work correctly.
106 useable_space = bufsize - ((smb_buf(outbuf)+
107 alignment_offset+data_alignment_offset) -
111 * useable_space can never be more than max_send minus the
115 useable_space = MIN(useable_space,
116 max_send - (alignment_offset+data_alignment_offset));
119 while (params_to_send || data_to_send) {
122 * Calculate whether we will totally or partially fill this packet.
125 total_sent_thistime = params_to_send + data_to_send +
126 alignment_offset + data_alignment_offset;
129 * We can never send more than useable_space.
132 total_sent_thistime = MIN(total_sent_thistime, useable_space);
134 set_message(outbuf, 18, total_sent_thistime, True);
137 * Set total params and data to be sent.
140 SIVAL(outbuf,smb_ntr_TotalParameterCount,paramsize);
141 SIVAL(outbuf,smb_ntr_TotalDataCount,datasize);
144 * Calculate how many parameters and data we can fit into
145 * this packet. Parameters get precedence.
148 params_sent_thistime = MIN(params_to_send,useable_space);
149 data_sent_thistime = useable_space - params_sent_thistime;
150 data_sent_thistime = MIN(data_sent_thistime,data_to_send);
152 SIVAL(outbuf,smb_ntr_ParameterCount,params_sent_thistime);
154 if(params_sent_thistime == 0) {
155 SIVAL(outbuf,smb_ntr_ParameterOffset,0);
156 SIVAL(outbuf,smb_ntr_ParameterDisplacement,0);
159 * smb_ntr_ParameterOffset is the offset from the start of the SMB header to the
160 * parameter bytes, however the first 4 bytes of outbuf are
161 * the Netbios over TCP header. Thus use smb_base() to subtract
162 * them from the calculation.
165 SIVAL(outbuf,smb_ntr_ParameterOffset,
166 ((smb_buf(outbuf)+alignment_offset) - smb_base(outbuf)));
168 * Absolute displacement of param bytes sent in this packet.
171 SIVAL(outbuf,smb_ntr_ParameterDisplacement,pp - params);
175 * Deal with the data portion.
178 SIVAL(outbuf,smb_ntr_DataCount, data_sent_thistime);
180 if(data_sent_thistime == 0) {
181 SIVAL(outbuf,smb_ntr_DataOffset,0);
182 SIVAL(outbuf,smb_ntr_DataDisplacement, 0);
185 * The offset of the data bytes is the offset of the
186 * parameter bytes plus the number of parameters being sent this time.
189 SIVAL(outbuf,smb_ntr_DataOffset,((smb_buf(outbuf)+alignment_offset) -
190 smb_base(outbuf)) + params_sent_thistime + data_alignment_offset);
191 SIVAL(outbuf,smb_ntr_DataDisplacement, pd - pdata);
195 * Copy the param bytes into the packet.
198 if(params_sent_thistime)
199 memcpy((smb_buf(outbuf)+alignment_offset),pp,params_sent_thistime);
202 * Copy in the data bytes
205 if(data_sent_thistime)
206 memcpy(smb_buf(outbuf)+alignment_offset+params_sent_thistime+
207 data_alignment_offset,pd,data_sent_thistime);
209 DEBUG(9,("nt_rep: params_sent_thistime = %d, data_sent_thistime = %d, useable_space = %d\n",
210 params_sent_thistime, data_sent_thistime, useable_space));
211 DEBUG(9,("nt_rep: params_to_send = %d, data_to_send = %d, paramsize = %d, datasize = %d\n",
212 params_to_send, data_to_send, paramsize, datasize));
214 /* Send the packet */
215 send_smb(Client,outbuf);
217 pp += params_sent_thistime;
218 pd += data_sent_thistime;
220 params_to_send -= params_sent_thistime;
221 data_to_send -= data_sent_thistime;
227 if(params_to_send < 0 || data_to_send < 0) {
228 DEBUG(0,("send_nt_replies failed sanity check pts = %d, dts = %d\n!!!",
229 params_to_send, data_to_send));
237 /****************************************************************************
238 (Hopefully) temporary call to fix bugs in NT5.0beta2. This OS sends unicode
239 strings in NT calls AND DOESN'T SET THE UNICODE BIT !!!!!!!
240 ****************************************************************************/
242 static void my_wcstombs(char *dst, uint16 *src, size_t len)
246 for(i = 0; i < len; i++)
247 dst[i] = (char)SVAL(src,i*2);
250 static void get_filename( char *fname, char *inbuf, int data_offset, int data_len, int fname_len)
252 if(data_len - fname_len > 1) {
254 * NT 5.0 Beta 2 has kindly sent us a UNICODE string
255 * without bothering to set the unicode bit. How kind.
257 * Firstly - ensure that the data offset is aligned
258 * on a 2 byte boundary - add one if not.
260 fname_len = fname_len/2;
263 my_wcstombs( fname, (uint16 *)(inbuf+data_offset), fname_len);
265 StrnCpy(fname,inbuf+data_offset,fname_len);
267 fname[fname_len] = '\0';
270 /****************************************************************************
272 ****************************************************************************/
274 static BOOL saved_case_sensitive;
275 static BOOL saved_case_preserve;
276 static BOOL saved_short_case_preserve;
278 /****************************************************************************
280 ****************************************************************************/
282 static void set_posix_case_semantics(uint32 file_attributes)
284 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS))
287 saved_case_sensitive = case_sensitive;
288 saved_case_preserve = case_preserve;
289 saved_short_case_preserve = short_case_preserve;
292 case_sensitive = True;
293 case_preserve = True;
294 short_case_preserve = True;
297 /****************************************************************************
298 Restore case semantics.
299 ****************************************************************************/
301 static void restore_case_semantics(uint32 file_attributes)
303 if(!(file_attributes & FILE_FLAG_POSIX_SEMANTICS))
306 case_sensitive = saved_case_sensitive;
307 case_preserve = saved_case_preserve;
308 short_case_preserve = saved_short_case_preserve;
311 /****************************************************************************
312 Utility function to map create disposition.
313 ****************************************************************************/
315 static int map_create_disposition( uint32 create_disposition)
319 switch( create_disposition ) {
321 /* create if not exist, fail if exist */
322 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_FAIL);
325 case FILE_OVERWRITE_IF:
326 /* create if not exist, trunc if exist */
327 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
330 /* fail if not exist, open if exists */
331 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN);
334 /* create if not exist, open if exists */
335 ret = (FILE_CREATE_IF_NOT_EXIST|FILE_EXISTS_OPEN);
338 /* fail if not exist, truncate if exists */
339 ret = (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_TRUNCATE);
342 DEBUG(0,("map_create_disposition: Incorrect value for create_disposition = %d\n",
343 create_disposition ));
347 DEBUG(10,("map_create_disposition: Mapped create_disposition %lx to %x\n",
348 (unsigned long)create_disposition, ret ));
353 /****************************************************************************
354 Utility function to map share modes.
355 ****************************************************************************/
357 static int map_share_mode( char *fname, uint32 desired_access, uint32 share_access, uint32 file_attributes)
359 int smb_open_mode = -1;
361 switch( desired_access & (FILE_READ_DATA|FILE_WRITE_DATA) ) {
363 smb_open_mode = DOS_OPEN_RDONLY;
365 case FILE_WRITE_DATA:
366 smb_open_mode = DOS_OPEN_WRONLY;
368 case FILE_READ_DATA|FILE_WRITE_DATA:
369 smb_open_mode = DOS_OPEN_RDWR;
374 * NB. For DELETE_ACCESS we should really check the
375 * directory permissions, as that is what controls
376 * delete, and for WRITE_DAC_ACCESS we should really
377 * check the ownership, as that is what controls the
378 * chmod. Note that this is *NOT* a security hole (this
379 * note is for you, Andrew) as we are not *allowing*
380 * the access at this point, the actual unlink or
381 * chown or chmod call would do this. We are just helping
382 * clients out by telling them if they have a hope
383 * of any of this succeeding. POSIX acls may still
384 * deny the real call. JRA.
387 if (smb_open_mode == -1) {
388 if(desired_access & (DELETE_ACCESS|WRITE_DAC_ACCESS|WRITE_OWNER_ACCESS|
389 FILE_EXECUTE|FILE_READ_ATTRIBUTES|
390 FILE_WRITE_ATTRIBUTES|READ_CONTROL_ACCESS))
391 smb_open_mode = DOS_OPEN_RDONLY;
393 DEBUG(0,("map_share_mode: Incorrect value %lx for desired_access to file %s\n",
394 (unsigned long)desired_access, fname));
400 * Set the special bit that means allow share delete.
401 * This is held outside the normal share mode bits at 1<<15.
405 if(share_access & FILE_SHARE_DELETE)
406 smb_open_mode |= ALLOW_SHARE_DELETE;
408 /* Add in the requested share mode. */
409 switch( share_access & (FILE_SHARE_READ|FILE_SHARE_WRITE)) {
410 case FILE_SHARE_READ:
411 smb_open_mode |= SET_DENY_MODE(DENY_WRITE);
413 case FILE_SHARE_WRITE:
414 smb_open_mode |= SET_DENY_MODE(DENY_READ);
416 case (FILE_SHARE_READ|FILE_SHARE_WRITE):
417 smb_open_mode |= SET_DENY_MODE(DENY_NONE);
419 case FILE_SHARE_NONE:
420 smb_open_mode |= SET_DENY_MODE(DENY_ALL);
425 * Handle an O_SYNC request.
428 if(file_attributes & FILE_FLAG_WRITE_THROUGH)
429 smb_open_mode |= FILE_SYNC_OPENMODE;
431 DEBUG(10,("map_share_mode: Mapped desired access %lx, share access %lx, file attributes %lx \
432 to open_mode %x\n", (unsigned long)desired_access, (unsigned long)share_access,
433 (unsigned long)file_attributes, smb_open_mode ));
435 return smb_open_mode;
439 * This is a *disgusting* hack.
440 * This is *so* bad that even I'm embarrassed (and I
441 * have no shame). Here's the deal :
442 * Until we get the correct SPOOLSS code into smbd
443 * then when we're running with NT SMB support then
444 * NT makes this call with a level of zero, and then
445 * immediately follows it with an open request to
446 * the \\SRVSVC pipe. If we allow that open to
447 * succeed then NT barfs when it cannot open the
448 * \\SPOOLSS pipe immediately after and continually
449 * whines saying "Printer name is invalid" forever
450 * after. If we cause *JUST THIS NEXT OPEN* of \\SRVSVC
451 * to fail, then NT downgrades to using the downlevel code
452 * and everything works as well as before. I hate
453 * myself for adding this code.... JRA.
455 * The HACK_FAIL_TIME define allows only a 2
456 * second window for this to occur, just in
460 static BOOL fail_next_srvsvc = False;
461 static time_t fail_time;
462 #define HACK_FAIL_TIME 2 /* In seconds. */
464 void fail_next_srvsvc_open(void)
466 fail_next_srvsvc = True;
467 fail_time = time(NULL);
468 DEBUG(10,("fail_next_srvsvc_open: setting up timeout close of \\srvsvc pipe for print fix.\n"));
471 /****************************************************************************
472 Reply to an NT create and X call on a pipe.
473 ****************************************************************************/
474 static int nt_open_pipe(char *fname, connection_struct *conn,
475 char *inbuf, char *outbuf, int *ppnum)
477 pipes_struct *p = NULL;
479 uint16 vuid = SVAL(inbuf, smb_uid);
482 DEBUG(4,("nt_open_pipe: Opening pipe %s.\n", fname));
484 /* See if it is one we want to handle. */
485 for( i = 0; known_nt_pipes[i]; i++ )
486 if( strequal(fname,known_nt_pipes[i]))
490 * HACK alert.... see above - JRA.
493 if(fail_next_srvsvc && (time(NULL) > fail_time + HACK_FAIL_TIME)) {
494 fail_next_srvsvc = False;
495 fail_time = (time_t)0;
496 DEBUG(10,("nt_open_pipe: End of timeout close of \\srvsvc pipe for print fix.\n"));
499 if(fail_next_srvsvc && strequal(fname, "\\srvsvc")) {
500 fail_next_srvsvc = False;
501 DEBUG(10,("nt_open_pipe: Deliberately failing open of \\srvsvc pipe for print fix.\n"));
502 return(ERROR(ERRSRV,ERRaccess));
506 * End hack alert.... see above - JRA.
509 if ( known_nt_pipes[i] == NULL )
510 return(ERROR(ERRSRV,ERRaccess));
512 /* Strip \\ off the name. */
515 DEBUG(3,("nt_open_pipe: Known pipe %s opening.\n", fname));
517 p = open_rpc_pipe_p(fname, conn, vuid);
519 return(ERROR(ERRSRV,ERRnofids));
526 /****************************************************************************
527 Reply to an NT create and X call.
528 ****************************************************************************/
530 int reply_ntcreate_and_X(connection_struct *conn,
531 char *inbuf,char *outbuf,int length,int bufsize)
534 uint32 flags = IVAL(inbuf,smb_ntcreate_Flags);
535 uint32 desired_access = IVAL(inbuf,smb_ntcreate_DesiredAccess);
536 uint32 file_attributes = IVAL(inbuf,smb_ntcreate_FileAttributes);
537 uint32 share_access = IVAL(inbuf,smb_ntcreate_ShareAccess);
538 uint32 create_disposition = IVAL(inbuf,smb_ntcreate_CreateDisposition);
539 uint32 create_options = IVAL(inbuf,smb_ntcreate_CreateOptions);
540 uint32 fname_len = MIN(((uint32)SVAL(inbuf,smb_ntcreate_NameLength)),
541 ((uint32)sizeof(fname)-1));
542 uint16 root_dir_fid = (uint16)IVAL(inbuf,smb_ntcreate_RootDirectoryFid);
545 int smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
546 /* Breakout the oplock request bits so we can set the
547 reply bits separately. */
548 int oplock_request = 0;
552 SMB_OFF_T file_len = 0;
553 SMB_STRUCT_STAT sbuf;
555 BOOL bad_path = False;
556 files_struct *fsp=NULL;
560 * We need to construct the open_and_X ofun value from the
561 * NT values, as that's what our code is structured to accept.
564 if((smb_ofun = map_create_disposition( create_disposition )) == -1)
565 return(ERROR(ERRDOS,ERRbadaccess));
571 if(root_dir_fid != 0) {
573 * This filename is relative to a directory fid.
575 files_struct *dir_fsp = file_fsp(inbuf,smb_ntcreate_RootDirectoryFid);
578 if(!dir_fsp || !dir_fsp->is_directory)
579 return(ERROR(ERRDOS,ERRbadfid));
582 * Copy in the base directory name.
585 pstrcpy( fname, dir_fsp->fsp_name );
586 dir_name_len = strlen(fname);
589 * Ensure it ends in a '\'.
592 if(fname[dir_name_len-1] != '\\' && fname[dir_name_len-1] != '/') {
593 pstrcat(fname, "\\");
597 if(fname_len + dir_name_len >= sizeof(pstring))
598 return(ERROR(ERRSRV,ERRfilespecs));
600 get_filename(&fname[dir_name_len], inbuf, smb_buf(inbuf)-inbuf,
601 smb_buflen(inbuf),fname_len);
603 StrnCpy(&fname[dir_name_len], smb_buf(inbuf),fname_len);
604 fname[dir_name_len+fname_len] = '\0';
609 get_filename(fname, inbuf, smb_buf(inbuf)-inbuf,
610 smb_buflen(inbuf),fname_len);
613 StrnCpy(fname,smb_buf(inbuf),fname_len);
614 fname[fname_len] = '\0';
618 /* If it's an IPC, use the pipe handler. */
620 if (IS_IPC(conn) && lp_nt_pipe_support() && lp_security() != SEC_SHARE)
622 int ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum);
627 * Deal with pipe return.
630 set_message(outbuf,34,0,True);
632 p = outbuf + smb_vwv2;
636 SIVAL(p,0,FILE_WAS_OPENED);
639 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
642 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
644 SSVAL(p,2, 0x5FF); /* ? */
646 DEBUG(5,("reply_ntcreate_and_X: open pipe = %s\n", fname));
648 return chain_reply(inbuf,outbuf,length,bufsize);
652 * Now contruct the smb_open_mode value from the filename,
653 * desired access and the share access.
656 if((smb_open_mode = map_share_mode(fname, desired_access,
658 file_attributes)) == -1) {
659 return(ERROR(ERRDOS,ERRbadaccess));
663 * Ordinary file or directory.
667 * Check if POSIX semantics are wanted.
670 set_posix_case_semantics(file_attributes);
672 unix_convert(fname,conn,0,&bad_path,NULL);
676 restore_case_semantics(file_attributes);
677 return(ERROR(ERRSRV,ERRnofids));
680 if (!check_name(fname,conn)) {
681 if((errno == ENOENT) && bad_path) {
682 unix_ERR_class = ERRDOS;
683 unix_ERR_code = ERRbadpath;
687 restore_case_semantics(file_attributes);
689 return(UNIXERROR(ERRDOS,ERRnoaccess));
692 unixmode = unix_mode(conn,smb_attr | aARCH);
694 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
695 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
698 * If it's a request for a directory open, deal with it separately.
701 if(create_options & FILE_DIRECTORY_FILE) {
704 open_directory(fsp, conn, fname, smb_ofun, unixmode,
707 restore_case_semantics(file_attributes);
711 return(UNIXERROR(ERRDOS,ERRnoaccess));
715 * Ordinary file case.
718 /* NB. We have a potential bug here. If we
719 * cause an oplock break to ourselves, then we
720 * could end up processing filename related
721 * SMB requests whilst we await the oplock
722 * break response. As we may have changed the
723 * filename case semantics to be POSIX-like,
724 * this could mean a filename request could
725 * fail when it should succeed. This is a rare
726 * condition, but eventually we must arrange
727 * to restore the correct case semantics
728 * before issuing an oplock break request to
729 * our client. JRA. */
731 open_file_shared(fsp,conn,fname,smb_open_mode,
733 oplock_request,&rmode,&smb_action);
736 /* We cheat here. The only case we
737 * care about is a directory rename,
738 * where the NT client will attempt to
739 * open the source directory for
740 * DELETE access. Note that when the
741 * NT client does this it does *not*
742 * set the directory bit in the
743 * request packet. This is translated
744 * into a read/write open
745 * request. POSIX states that any open
746 * for write request on a directory
747 * will generate an EISDIR error, so
748 * we can catch this here and open a
749 * pseudo handle that is flagged as a
752 if(errno == EISDIR) {
755 open_directory(fsp, conn, fname,
761 restore_case_semantics(file_attributes);
762 return(UNIXERROR(ERRDOS,ERRnoaccess));
765 if((errno == ENOENT) && bad_path) {
766 unix_ERR_class = ERRDOS;
767 unix_ERR_code = ERRbadpath;
772 restore_case_semantics(file_attributes);
774 return(UNIXERROR(ERRDOS,ERRnoaccess));
779 if(fsp->is_directory) {
780 if(fsp->conn->vfs_ops.stat(dos_to_unix(fsp->fsp_name, False),
782 close_directory(fsp);
783 restore_case_semantics(file_attributes);
784 return(ERROR(ERRDOS,ERRnoaccess));
787 if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf)
789 close_file(fsp,False);
790 restore_case_semantics(file_attributes);
791 return(ERROR(ERRDOS,ERRnoaccess));
795 restore_case_semantics(file_attributes);
797 file_len = sbuf.st_size;
798 fmode = dos_mode(conn,fname,&sbuf);
800 fmode = FILE_ATTRIBUTE_NORMAL;
801 if (!fsp->is_directory && (fmode & aDIR)) {
802 close_file(fsp,False);
803 return(ERROR(ERRDOS,ERRnoaccess));
807 * If the caller set the extended oplock request bit
808 * and we granted one (by whatever means) - set the
809 * correct bit for extended oplock reply.
812 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
813 smb_action |= EXTENDED_OPLOCK_GRANTED;
815 if(oplock_request && fsp->granted_oplock)
816 smb_action |= EXTENDED_OPLOCK_GRANTED;
818 set_message(outbuf,34,0,True);
820 p = outbuf + smb_vwv2;
823 * Currently as we don't support level II oplocks we just report
824 * exclusive & batch here.
827 SCVAL(p,0, (smb_action & EXTENDED_OPLOCK_GRANTED ? 1 : 0));
829 SSVAL(p,0,fsp->fnum);
831 SIVAL(p,0,smb_action);
835 put_long_date(p,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn))));
837 put_long_date(p,sbuf.st_atime); /* access time */
839 put_long_date(p,sbuf.st_mtime); /* write time */
841 put_long_date(p,sbuf.st_mtime); /* change time */
843 SIVAL(p,0,fmode); /* File Attributes. */
845 SOFF_T(p, 0, file_len);
847 SOFF_T(p,0,file_len);
849 SCVAL(p,0,fsp->is_directory ? 1 : 0);
851 DEBUG(5,("reply_ntcreate_and_X: fnum = %d, open name = %s\n", fsp->fnum, fsp->fsp_name));
853 return chain_reply(inbuf,outbuf,length,bufsize);
856 /****************************************************************************
857 Reply to a NT_TRANSACT_CREATE call (needs to process SD's).
858 ****************************************************************************/
859 static int call_nt_transact_create(connection_struct *conn,
860 char *inbuf, char *outbuf, int length,
862 char **ppsetup, char **ppparams,
866 char *params = *ppparams;
867 uint32 flags = IVAL(params,0);
868 uint32 desired_access = IVAL(params,8);
869 uint32 file_attributes = IVAL(params,20);
870 uint32 share_access = IVAL(params,24);
871 uint32 create_disposition = IVAL(params,28);
872 uint32 create_options = IVAL(params,32);
873 uint32 fname_len = MIN(((uint32)IVAL(params,44)),
874 ((uint32)sizeof(fname)-1));
875 uint16 root_dir_fid = (uint16)IVAL(params,4);
878 int smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
879 /* Breakout the oplock request bits so we can set the
880 reply bits separately. */
881 int oplock_request = 0;
885 SMB_OFF_T file_len = 0;
886 SMB_STRUCT_STAT sbuf;
888 BOOL bad_path = False;
889 files_struct *fsp = NULL;
893 * We need to construct the open_and_X ofun value from the
894 * NT values, as that's what our code is structured to accept.
897 if((smb_ofun = map_create_disposition( create_disposition )) == -1)
898 return(ERROR(ERRDOS,ERRbadaccess));
904 if(root_dir_fid != 0) {
906 * This filename is relative to a directory fid.
909 files_struct *dir_fsp = file_fsp(params,4);
912 if(!dir_fsp || !dir_fsp->is_directory)
913 return(ERROR(ERRDOS,ERRbadfid));
916 * Copy in the base directory name.
919 pstrcpy( fname, dir_fsp->fsp_name );
920 dir_name_len = strlen(fname);
923 * Ensure it ends in a '\'.
926 if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
927 pstrcat(fname, "\\");
931 if(fname_len + dir_name_len >= sizeof(pstring))
932 return(ERROR(ERRSRV,ERRfilespecs));
934 StrnCpy(&fname[dir_name_len], params+53, fname_len);
935 fname[dir_name_len+fname_len] = '\0';
938 StrnCpy(fname,params+53,fname_len);
939 fname[fname_len] = '\0';
942 /* If it's an IPC, use the pipe handler. */
944 int ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum);
947 smb_action = FILE_WAS_OPENED;
950 * Check if POSIX semantics are wanted.
953 set_posix_case_semantics(file_attributes);
955 unix_convert(fname,conn,0,&bad_path,NULL);
959 restore_case_semantics(file_attributes);
960 return(ERROR(ERRSRV,ERRnofids));
963 if (!check_name(fname,conn)) {
964 if((errno == ENOENT) && bad_path) {
965 unix_ERR_class = ERRDOS;
966 unix_ERR_code = ERRbadpath;
970 restore_case_semantics(file_attributes);
972 return(UNIXERROR(ERRDOS,ERRnoaccess));
975 unixmode = unix_mode(conn,smb_attr | aARCH);
977 oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
978 oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
981 * Now contruct the smb_open_mode value from the desired access
982 * and the share access.
985 if((smb_open_mode = map_share_mode( fname, desired_access, share_access, file_attributes)) == -1)
986 return(ERROR(ERRDOS,ERRbadaccess));
989 * If it's a request for a directory open, deal with it separately.
992 if(create_options & FILE_DIRECTORY_FILE) {
997 * We will get a create directory here if the Win32
998 * app specified a security descriptor in the
999 * CreateDirectory() call.
1002 open_directory(fsp, conn, fname, smb_ofun, unixmode, &smb_action);
1006 return(UNIXERROR(ERRDOS,ERRnoaccess));
1011 * Ordinary file case.
1014 open_file_shared(fsp,conn,fname,smb_open_mode,smb_ofun,
1015 unixmode,oplock_request,&rmode,&smb_action);
1018 if((errno == ENOENT) && bad_path) {
1019 unix_ERR_class = ERRDOS;
1020 unix_ERR_code = ERRbadpath;
1024 restore_case_semantics(file_attributes);
1026 return(UNIXERROR(ERRDOS,ERRnoaccess));
1029 if (fsp->conn->vfs_ops.fstat(fsp->fd_ptr->fd,&sbuf) != 0) {
1030 close_file(fsp,False);
1032 restore_case_semantics(file_attributes);
1034 return(ERROR(ERRDOS,ERRnoaccess));
1037 file_len = sbuf.st_size;
1038 fmode = dos_mode(conn,fname,&sbuf);
1040 fmode = FILE_ATTRIBUTE_NORMAL;
1043 close_file(fsp,False);
1044 restore_case_semantics(file_attributes);
1045 return(ERROR(ERRDOS,ERRnoaccess));
1049 * If the caller set the extended oplock request bit
1050 * and we granted one (by whatever means) - set the
1051 * correct bit for extended oplock reply.
1054 if (oplock_request && lp_fake_oplocks(SNUM(conn)))
1055 smb_action |= EXTENDED_OPLOCK_GRANTED;
1057 if(oplock_request && fsp->granted_oplock)
1058 smb_action |= EXTENDED_OPLOCK_GRANTED;
1062 restore_case_semantics(file_attributes);
1064 /* Realloc the size of parameters and data we will return */
1065 params = *ppparams = Realloc(*ppparams, 69);
1067 return(ERROR(ERRDOS,ERRnomem));
1070 SCVAL(p,0, (smb_action & EXTENDED_OPLOCK_GRANTED ? 1 : 0));
1075 SSVAL(p,0,fsp->fnum);
1078 SIVAL(p,0,smb_action);
1083 * Deal with pipe return.
1086 SIVAL(p,0,FILE_ATTRIBUTE_NORMAL); /* File Attributes. */
1089 SSVAL(p,0,FILE_TYPE_MESSAGE_MODE_PIPE);
1091 SSVAL(p,2, 0x5FF); /* ? */
1094 * Deal with file return.
1097 put_long_date(p,get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn))));
1099 put_long_date(p,sbuf.st_atime); /* access time */
1101 put_long_date(p,sbuf.st_mtime); /* write time */
1103 put_long_date(p,sbuf.st_mtime); /* change time */
1105 SIVAL(p,0,fmode); /* File Attributes. */
1107 SOFF_T(p,0,file_len);
1109 SOFF_T(p,0,file_len);
1112 /* Send the required number of replies */
1113 send_nt_replies(outbuf, bufsize, params, 69, *ppdata, 0);
1118 /****************************************************************************
1119 Reply to a NT CANCEL request.
1120 ****************************************************************************/
1121 int reply_ntcancel(connection_struct *conn,
1122 char *inbuf,char *outbuf,int length,int bufsize)
1125 * Go through and cancel any pending change notifies.
1128 int mid = SVAL(inbuf,smb_mid);
1129 remove_pending_change_notify_requests_by_mid(mid);
1130 remove_pending_lock_requests_by_mid(mid);
1132 DEBUG(3,("reply_ntcancel: cancel called on mid = %d.\n", mid));
1137 /****************************************************************************
1138 Reply to an unsolicited SMBNTtranss - just ignore it!
1139 ****************************************************************************/
1140 int reply_nttranss(connection_struct *conn,
1141 char *inbuf,char *outbuf,int length,int bufsize)
1143 DEBUG(4,("Ignoring nttranss of length %d\n",length));
1147 /****************************************************************************
1148 Reply to an NT transact rename command.
1149 ****************************************************************************/
1150 static int call_nt_transact_rename(connection_struct *conn,
1151 char *inbuf, char *outbuf, int length,
1153 char **ppsetup, char **ppparams, char **ppdata)
1155 char *params = *ppparams;
1157 files_struct *fsp = file_fsp(params, 0);
1158 BOOL replace_if_exists = (SVAL(params,2) & RENAME_REPLACE_IF_EXISTS) ? True : False;
1159 uint32 fname_len = MIN((((uint32)IVAL(inbuf,smb_nt_TotalParameterCount)-4)),
1160 ((uint32)sizeof(new_name)-1));
1163 CHECK_FSP(fsp, conn);
1164 StrnCpy(new_name,params+4,fname_len);
1165 new_name[fname_len] = '\0';
1167 outsize = rename_internals(conn, inbuf, outbuf, fsp->fsp_name,
1168 new_name, replace_if_exists);
1171 * Rename was successful.
1173 send_nt_replies(outbuf, bufsize, NULL, 0, NULL, 0);
1175 DEBUG(3,("nt transact rename from = %s, to = %s succeeded.\n",
1176 fsp->fsp_name, new_name));
1184 /****************************************************************************
1185 This is the structure to queue to implement NT change
1186 notify. It consists of smb_size bytes stored from the
1187 transact command (to keep the mid, tid etc around).
1188 Plus the fid to examine and the time to check next.
1189 *****************************************************************************/
1192 ubi_slNode msg_next;
1194 connection_struct *conn;
1195 time_t next_check_time;
1196 time_t modify_time; /* Info from the directory we're monitoring. */
1197 time_t status_time; /* Info from the directory we're monitoring. */
1198 char request_buf[smb_size];
1199 } change_notify_buf;
1201 static ubi_slList change_notify_queue = { NULL, (ubi_slNodePtr)&change_notify_queue, 0};
1203 /****************************************************************************
1204 Setup the common parts of the return packet and send it.
1205 *****************************************************************************/
1207 static void change_notify_reply_packet(char *inbuf, int error_class, uint32 error_code)
1210 char outbuf[smb_size+38];
1212 memset(outbuf, '\0', sizeof(outbuf));
1213 construct_reply_common(inbuf, outbuf);
1216 * If we're returning a 'too much in the directory changed' we need to
1217 * set this is an NT error status flags. If we don't then the (probably
1218 * untested) code in the NT redirector has a bug in that it doesn't re-issue
1219 * the change notify.... Ah - I *love* it when I get so deeply into this I
1220 * can even determine how MS failed to test stuff and why.... :-). JRA.
1223 if(error_class == 0) /* NT Error. */
1224 SSVAL(outbuf,smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
1226 ERROR(error_class,error_code);
1229 * Seems NT needs a transact command with an error code
1230 * in it. This is a longer packet than a simple error.
1232 set_message(outbuf,18,0,False);
1234 send_smb(Client,outbuf);
1237 /****************************************************************************
1238 Delete entries by fnum from the change notify pending queue.
1239 *****************************************************************************/
1240 void remove_pending_change_notify_requests_by_fid(files_struct *fsp)
1242 change_notify_buf *cnbp = (change_notify_buf *)ubi_slFirst( &change_notify_queue );
1243 change_notify_buf *prev = NULL;
1245 while(cnbp != NULL) {
1246 if(cnbp->fsp->fnum == fsp->fnum) {
1247 free((char *)ubi_slRemNext( &change_notify_queue, prev));
1248 cnbp = (change_notify_buf *)(prev ? ubi_slNext(prev) : ubi_slFirst(&change_notify_queue));
1253 cnbp = (change_notify_buf *)ubi_slNext(cnbp);
1257 /****************************************************************************
1258 Delete entries by mid from the change notify pending queue. Always send reply.
1259 *****************************************************************************/
1261 static void remove_pending_change_notify_requests_by_mid(int mid)
1263 change_notify_buf *cnbp = (change_notify_buf *)ubi_slFirst( &change_notify_queue );
1264 change_notify_buf *prev = NULL;
1266 while(cnbp != NULL) {
1267 if(SVAL(cnbp->request_buf,smb_mid) == mid) {
1268 change_notify_reply_packet(cnbp->request_buf,0,NT_STATUS_CANCELLED);
1269 free((char *)ubi_slRemNext( &change_notify_queue, prev));
1270 cnbp = (change_notify_buf *)(prev ? ubi_slNext(prev) : ubi_slFirst(&change_notify_queue));
1275 cnbp = (change_notify_buf *)ubi_slNext(cnbp);
1279 /****************************************************************************
1280 Process the change notify queue. Note that this is only called as root.
1281 *****************************************************************************/
1283 void process_pending_change_notify_queue(time_t t)
1285 change_notify_buf *cnbp = (change_notify_buf *)ubi_slFirst( &change_notify_queue );
1286 change_notify_buf *prev = NULL;
1291 if(cnbp->next_check_time >= t)
1295 * It's time to check. Go through the queue and see if
1296 * the timestamps changed.
1299 while((cnbp != NULL) && (cnbp->next_check_time <= t)) {
1301 files_struct *fsp = cnbp->fsp;
1302 connection_struct *conn = cnbp->conn;
1303 uint16 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID :
1304 SVAL(cnbp->request_buf,smb_uid);
1307 * Ensure we don't have any old chain_fsp values
1308 * sitting around....
1313 if(!become_user(conn,vuid)) {
1314 DEBUG(0,("process_pending_change_notify_queue: Unable to become user vuid=%d.\n",
1317 * Remove the entry and return an error to the client.
1319 change_notify_reply_packet(cnbp->request_buf,ERRSRV,ERRaccess);
1320 free((char *)ubi_slRemNext( &change_notify_queue, prev));
1321 cnbp = (change_notify_buf *)(prev ? ubi_slNext(prev) : ubi_slFirst(&change_notify_queue));
1325 if(!become_service(conn,True)) {
1326 DEBUG(0,("process_pending_change_notify_queue: Unable to become service Error was %s.\n", strerror(errno) ));
1328 * Remove the entry and return an error to the client.
1330 change_notify_reply_packet(cnbp->request_buf,ERRSRV,ERRaccess);
1331 free((char *)ubi_slRemNext( &change_notify_queue, prev));
1332 cnbp = (change_notify_buf *)(prev ? ubi_slNext(prev) : ubi_slFirst(&change_notify_queue));
1337 if(fsp->conn->vfs_ops.stat(dos_to_unix(fsp->fsp_name, False), &st) < 0) {
1338 DEBUG(0,("process_pending_change_notify_queue: Unable to stat directory %s. \
1339 Error was %s.\n", fsp->fsp_name, strerror(errno) ));
1341 * Remove the entry and return an error to the client.
1343 change_notify_reply_packet(cnbp->request_buf,ERRSRV,ERRaccess);
1344 free((char *)ubi_slRemNext( &change_notify_queue, prev));
1345 cnbp = (change_notify_buf *)(prev ? ubi_slNext(prev) : ubi_slFirst(&change_notify_queue));
1350 if(cnbp->modify_time != st.st_mtime ||
1351 cnbp->status_time != st.st_ctime) {
1353 * Remove the entry and return a change notify to the client.
1355 DEBUG(5,("process_pending_change_notify_queue: directory name = %s changed\n",
1357 change_notify_reply_packet(cnbp->request_buf,0,NT_STATUS_NOTIFY_ENUM_DIR);
1358 free((char *)ubi_slRemNext( &change_notify_queue, prev));
1359 cnbp = (change_notify_buf *)(prev ? ubi_slNext(prev) : ubi_slFirst(&change_notify_queue));
1367 * Move to the next in the list.
1370 cnbp = (change_notify_buf *)ubi_slNext(cnbp);
1374 /****************************************************************************
1375 Reply to a notify change - queue the request and
1376 don't allow a directory to be opened.
1377 ****************************************************************************/
1378 static int call_nt_transact_notify_change(connection_struct *conn,
1379 char *inbuf, char *outbuf, int length,
1382 char **ppparams, char **ppdata)
1384 char *setup = *ppsetup;
1386 change_notify_buf *cnbp;
1389 fsp = file_fsp(setup,4);
1391 DEBUG(3,("call_nt_transact_notify_change\n"));
1394 return(ERROR(ERRDOS,ERRbadfid));
1396 if((!fsp->open) || (!fsp->is_directory) || (conn != fsp->conn))
1397 return(ERROR(ERRDOS,ERRbadfid));
1400 * Now queue an entry on the notify change stack. We timestamp
1401 * the entry we are adding so that we know when to scan next.
1402 * We only need to save smb_size bytes from this incoming packet
1403 * as we will always by returning a 'read the directory yourself'
1407 if((cnbp = (change_notify_buf *)malloc(sizeof(change_notify_buf))) == NULL) {
1408 DEBUG(0,("call_nt_transact_notify_change: Malloc fail (2) !\n" ));
1413 * Store the current timestamp on the directory we are monitoring.
1416 if(fsp->conn->vfs_ops.stat(dos_to_unix(fsp->fsp_name, False), &st) < 0) {
1417 DEBUG(0,("call_nt_transact_notify_change: Unable to stat name = %s. \
1418 Error was %s\n", fsp->fsp_name, strerror(errno) ));
1420 return(UNIXERROR(ERRDOS,ERRbadfid));
1423 memcpy(cnbp->request_buf, inbuf, smb_size);
1426 cnbp->modify_time = st.st_mtime;
1427 cnbp->status_time = st.st_ctime;
1429 cnbp->next_check_time = time(NULL) + lp_change_notify_timeout();
1432 * Adding to the tail enables us to check only
1433 * the head when scanning for change, as this entry
1434 * is forced to have the first timeout expiration.
1437 ubi_slAddTail(&change_notify_queue, cnbp);
1439 DEBUG(3,("call_nt_transact_notify_change: notify change called on directory \
1440 name = %s\n", fsp->fsp_name ));
1445 /****************************************************************************
1446 Reply to query a security descriptor - currently this is not implemented (it
1447 is planned to be though).
1448 ****************************************************************************/
1449 static int call_nt_transact_query_security_desc(connection_struct *conn,
1450 char *inbuf, char *outbuf,
1453 char **ppsetup, char **ppparams, char **ppdata)
1455 static BOOL logged_message = False;
1457 if(!logged_message) {
1458 DEBUG(0,("call_nt_transact_query_security_desc: Currently not implemented.\n"));
1459 logged_message = True; /* Only print this once... */
1462 return(ERROR(ERRSRV,ERRnosupport));
1465 /****************************************************************************
1466 Reply to set a security descriptor - currently this is not implemented (it
1467 is planned to be though).
1468 ****************************************************************************/
1469 static int call_nt_transact_set_security_desc(connection_struct *conn,
1470 char *inbuf, char *outbuf,
1474 char **ppparams, char **ppdata)
1476 static BOOL logged_message = False;
1478 if(!logged_message) {
1479 DEBUG(0,("call_nt_transact_set_security_desc: Currently not implemented.\n"));
1480 logged_message = True; /* Only print this once... */
1482 return(ERROR(ERRSRV,ERRnosupport));
1485 /****************************************************************************
1486 Reply to IOCTL - not implemented - no plans.
1487 ****************************************************************************/
1488 static int call_nt_transact_ioctl(connection_struct *conn,
1489 char *inbuf, char *outbuf, int length,
1491 char **ppsetup, char **ppparams, char **ppdata)
1493 static BOOL logged_message = False;
1495 if(!logged_message) {
1496 DEBUG(0,("call_nt_transact_ioctl: Currently not implemented.\n"));
1497 logged_message = True; /* Only print this once... */
1499 return(ERROR(ERRSRV,ERRnosupport));
1502 /****************************************************************************
1503 Reply to a SMBNTtrans.
1504 ****************************************************************************/
1505 int reply_nttrans(connection_struct *conn,
1506 char *inbuf,char *outbuf,int length,int bufsize)
1509 #if 0 /* Not used. */
1510 uint16 max_setup_count = CVAL(inbuf, smb_nt_MaxSetupCount);
1511 uint32 max_parameter_count = IVAL(inbuf, smb_nt_MaxParameterCount);
1512 uint32 max_data_count = IVAL(inbuf,smb_nt_MaxDataCount);
1513 #endif /* Not used. */
1514 uint32 total_parameter_count = IVAL(inbuf, smb_nt_TotalParameterCount);
1515 uint32 total_data_count = IVAL(inbuf, smb_nt_TotalDataCount);
1516 uint32 parameter_count = IVAL(inbuf,smb_nt_ParameterCount);
1517 uint32 parameter_offset = IVAL(inbuf,smb_nt_ParameterOffset);
1518 uint32 data_count = IVAL(inbuf,smb_nt_DataCount);
1519 uint32 data_offset = IVAL(inbuf,smb_nt_DataOffset);
1520 uint16 setup_count = 2*CVAL(inbuf,smb_nt_SetupCount); /* setup count is in *words* */
1521 uint16 function_code = SVAL( inbuf, smb_nt_Function);
1522 char *params = NULL, *data = NULL, *setup = NULL;
1523 uint32 num_params_sofar, num_data_sofar;
1525 if(global_oplock_break && (function_code == NT_TRANSACT_CREATE)) {
1527 * Queue this open message as we are the process of an oplock break.
1530 DEBUG(2,("reply_nttrans: queueing message NT_TRANSACT_CREATE \
1531 due to being in oplock break state.\n" ));
1533 push_oplock_pending_smb_message( inbuf, length);
1537 outsize = set_message(outbuf,0,0,True);
1540 * All nttrans messages we handle have smb_wct == 19 + setup_count.
1541 * Ensure this is so as a sanity check.
1544 if(CVAL(inbuf, smb_wct) != 19 + (setup_count/2)) {
1545 DEBUG(2,("Invalid smb_wct %d in nttrans call (should be %d)\n",
1546 CVAL(inbuf, smb_wct), 19 + (setup_count/2)));
1547 return(ERROR(ERRSRV,ERRerror));
1550 /* Allocate the space for the setup, the maximum needed parameters and data */
1553 setup = (char *)malloc(setup_count);
1554 if (total_parameter_count > 0)
1555 params = (char *)malloc(total_parameter_count);
1556 if (total_data_count > 0)
1557 data = (char *)malloc(total_data_count);
1559 if ((total_parameter_count && !params) || (total_data_count && !data) ||
1560 (setup_count && !setup)) {
1561 DEBUG(0,("reply_nttrans : Out of memory\n"));
1562 return(ERROR(ERRDOS,ERRnomem));
1565 /* Copy the param and data bytes sent with this request into
1566 the params buffer */
1567 num_params_sofar = parameter_count;
1568 num_data_sofar = data_count;
1570 if (parameter_count > total_parameter_count || data_count > total_data_count)
1571 exit_server("reply_nttrans: invalid sizes in packet.\n");
1574 memcpy( setup, &inbuf[smb_nt_SetupStart], setup_count);
1575 DEBUG(10,("reply_nttrans: setup_count = %d\n", setup_count));
1576 dump_data(10, setup, setup_count);
1579 memcpy( params, smb_base(inbuf) + parameter_offset, parameter_count);
1580 DEBUG(10,("reply_nttrans: parameter_count = %d\n", parameter_count));
1581 dump_data(10, params, parameter_count);
1584 memcpy( data, smb_base(inbuf) + data_offset, data_count);
1585 DEBUG(10,("reply_nttrans: data_count = %d\n",data_count));
1586 dump_data(10, data, data_count);
1589 if(num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
1590 /* We need to send an interim response then receive the rest
1591 of the parameter/data bytes */
1592 outsize = set_message(outbuf,0,0,True);
1593 send_smb(Client,outbuf);
1595 while( num_data_sofar < total_data_count || num_params_sofar < total_parameter_count) {
1598 ret = receive_next_smb(inbuf,bufsize,SMB_SECONDARY_WAIT);
1600 if((ret && (CVAL(inbuf, smb_com) != SMBnttranss)) || !ret) {
1601 outsize = set_message(outbuf,0,0,True);
1603 DEBUG(0,("reply_nttrans: Invalid secondary nttrans packet\n"));
1605 DEBUG(0,("reply_nttrans: %s in getting secondary nttrans response.\n",
1606 (smb_read_error == READ_ERROR) ? "error" : "timeout" ));
1614 return(ERROR(ERRSRV,ERRerror));
1617 /* Revise total_params and total_data in case they have changed downwards */
1618 total_parameter_count = IVAL(inbuf, smb_nts_TotalParameterCount);
1619 total_data_count = IVAL(inbuf, smb_nts_TotalDataCount);
1620 num_params_sofar += (parameter_count = IVAL(inbuf,smb_nts_ParameterCount));
1621 num_data_sofar += ( data_count = IVAL(inbuf, smb_nts_DataCount));
1622 if (num_params_sofar > total_parameter_count || num_data_sofar > total_data_count)
1623 exit_server("reply_nttrans2: data overflow in secondary nttrans packet\n");
1625 memcpy( ¶ms[ IVAL(inbuf, smb_nts_ParameterDisplacement)],
1626 smb_base(inbuf) + IVAL(inbuf, smb_nts_ParameterOffset), parameter_count);
1627 memcpy( &data[IVAL(inbuf, smb_nts_DataDisplacement)],
1628 smb_base(inbuf)+ IVAL(inbuf, smb_nts_DataOffset), data_count);
1632 if (Protocol >= PROTOCOL_NT1) {
1633 uint16 flg2 = SVAL(outbuf,smb_flg2);
1634 SSVAL(outbuf,smb_flg2,flg2 | 0x40); /* IS_LONG_NAME */
1637 /* Now we must call the relevant NT_TRANS function */
1638 switch(function_code) {
1639 case NT_TRANSACT_CREATE:
1640 outsize = call_nt_transact_create(conn, inbuf, outbuf, length, bufsize,
1641 &setup, ¶ms, &data);
1643 case NT_TRANSACT_IOCTL:
1644 outsize = call_nt_transact_ioctl(conn,
1645 inbuf, outbuf, length, bufsize,
1646 &setup, ¶ms, &data);
1648 case NT_TRANSACT_SET_SECURITY_DESC:
1649 outsize = call_nt_transact_set_security_desc(conn, inbuf, outbuf,
1651 &setup, ¶ms, &data);
1653 case NT_TRANSACT_NOTIFY_CHANGE:
1654 outsize = call_nt_transact_notify_change(conn, inbuf, outbuf,
1656 &setup, ¶ms, &data);
1658 case NT_TRANSACT_RENAME:
1659 outsize = call_nt_transact_rename(conn, inbuf, outbuf, length,
1661 &setup, ¶ms, &data);
1664 case NT_TRANSACT_QUERY_SECURITY_DESC:
1665 outsize = call_nt_transact_query_security_desc(conn, inbuf, outbuf,
1667 &setup, ¶ms, &data);
1670 /* Error in request */
1671 DEBUG(0,("reply_nttrans: Unknown request %d in nttrans call\n", function_code));
1678 return (ERROR(ERRSRV,ERRerror));
1681 /* As we do not know how many data packets will need to be
1682 returned here the various call_nt_transact_xxxx calls
1683 must send their own. Thus a call_nt_transact_xxxx routine only
1684 returns a value other than -1 when it wants to send
1694 return outsize; /* If a correct response was needed the call_nt_transact_xxxx
1695 calls have already sent it. If outsize != -1 then it is
1696 returning an error packet. */