Fixed the AFP_Resource:$DATA filename creation bug.
authorJeremy Allison <jra@samba.org>
Wed, 17 Apr 2002 21:53:35 +0000 (21:53 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 17 Apr 2002 21:53:35 +0000 (21:53 +0000)
Jeremy.

source/smbd/nttrans.c

index 89b199f67dbd42d9c71e4d49ca607d9324fa0102..c05be55e39ebcc91d2dcd3d0651812a5e0fe7ac4 100644 (file)
@@ -686,13 +686,14 @@ int reply_ntcreate_and_X(connection_struct *conn,
                }
 
                if(!dir_fsp->is_directory) {
+
+                       get_filename(&fname[0], inbuf, smb_buf(inbuf)-inbuf, 
+                               smb_buflen(inbuf),fname_len);
+
                        /* 
                         * Check to see if this is a mac fork of some kind.
                         */
 
-                       get_filename(&fname[0], inbuf, smb_buf(inbuf)-inbuf, 
-                       smb_buflen(inbuf),fname_len);
-
                        if( strchr(fname, ':')) {
                                END_PROFILE(SMBntcreateX);
                                return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
@@ -734,6 +735,15 @@ int reply_ntcreate_and_X(connection_struct *conn,
       
                get_filename(fname, inbuf, smb_buf(inbuf)-inbuf, 
                        smb_buflen(inbuf),fname_len);
+
+               /* 
+                * Check to see if this is a mac fork of some kind.
+                */
+
+               if( strchr(fname, ':')) {
+                       END_PROFILE(SMBntcreateX);
+                       return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND);
+               }
        }
        
        /*
@@ -1105,317 +1115,321 @@ static int call_nt_transact_create(connection_struct *conn,
                                        int bufsize, char **ppsetup, char **ppparams, 
                                        char **ppdata)
 {
-  pstring fname;
-  char *params = *ppparams;
-  char *data = *ppdata;
-  int total_parameter_count = (int)IVAL(inbuf, smb_nt_TotalParameterCount);
-  /* Breakout the oplock request bits so we can set the
-     reply bits separately. */
-  int oplock_request = 0;
-  mode_t unixmode;
-  int fmode=0,rmode=0;
-  SMB_OFF_T file_len = 0;
-  SMB_STRUCT_STAT sbuf;
-  int smb_action = 0;
-  BOOL bad_path = False;
-  files_struct *fsp = NULL;
-  char *p = NULL;
-  uint32 flags;
-  uint32 desired_access;
-  uint32 file_attributes;
-  uint32 share_access;
-  uint32 create_disposition;
-  uint32 create_options;
-  uint32 fname_len;
-  uint32 sd_len;
-  uint16 root_dir_fid;
-  int smb_ofun;
-  int smb_open_mode;
-  int smb_attr;
-  int error_class;
-  uint32 error_code;
-  time_t c_time;
-
-  DEBUG(5,("call_nt_transact_create\n"));
+       pstring fname;
+       char *params = *ppparams;
+       char *data = *ppdata;
+       int total_parameter_count = (int)IVAL(inbuf, smb_nt_TotalParameterCount);
+       /* Breakout the oplock request bits so we can set the reply bits separately. */
+       int oplock_request = 0;
+       mode_t unixmode;
+       int fmode=0,rmode=0;
+       SMB_OFF_T file_len = 0;
+       SMB_STRUCT_STAT sbuf;
+       int smb_action = 0;
+       BOOL bad_path = False;
+       files_struct *fsp = NULL;
+       char *p = NULL;
+       uint32 flags;
+       uint32 desired_access;
+       uint32 file_attributes;
+       uint32 share_access;
+       uint32 create_disposition;
+       uint32 create_options;
+       uint32 fname_len;
+       uint32 sd_len;
+       uint16 root_dir_fid;
+       int smb_ofun;
+       int smb_open_mode;
+       int smb_attr;
+       int error_class;
+       uint32 error_code;
+       time_t c_time;
 
-  /*
-   * If it's an IPC, use the pipe handler.
-   */
+       DEBUG(5,("call_nt_transact_create\n"));
 
-  if (IS_IPC(conn)) {
+       /*
+        * If it's an IPC, use the pipe handler.
+        */
+
+       if (IS_IPC(conn)) {
                if (lp_nt_pipe_support())
                        return do_nt_transact_create_pipe(conn, inbuf, outbuf, length, 
                                        bufsize, ppsetup, ppparams, ppdata);
                else
                        return ERROR_DOS(ERRDOS,ERRbadaccess);
-  }
+       }
 
-  /*
-   * Ensure minimum number of parameters sent.
-   */
+       /*
+        * Ensure minimum number of parameters sent.
+        */
 
-  if(total_parameter_count < 54) {
-    DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)total_parameter_count));
-    return ERROR_DOS(ERRDOS,ERRbadaccess);
-  }
+       if(total_parameter_count < 54) {
+               DEBUG(0,("call_nt_transact_create - insufficient parameters (%u)\n", (unsigned int)total_parameter_count));
+               return ERROR_DOS(ERRDOS,ERRbadaccess);
+       }
 
-  flags = IVAL(params,0);
-  desired_access = IVAL(params,8);
-  file_attributes = IVAL(params,20);
-  share_access = IVAL(params,24);
-  create_disposition = IVAL(params,28);
-  create_options = IVAL(params,32);
-  sd_len = IVAL(params,36);
-  fname_len = MIN(((uint32)IVAL(params,44)),((uint32)sizeof(fname)-1));
-  root_dir_fid = (uint16)IVAL(params,4);
-  smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
+       flags = IVAL(params,0);
+       desired_access = IVAL(params,8);
+       file_attributes = IVAL(params,20);
+       share_access = IVAL(params,24);
+       create_disposition = IVAL(params,28);
+       create_options = IVAL(params,32);
+       sd_len = IVAL(params,36);
+       fname_len = MIN(((uint32)IVAL(params,44)),((uint32)sizeof(fname)-1));
+       root_dir_fid = (uint16)IVAL(params,4);
+       smb_attr = (file_attributes & SAMBA_ATTRIBUTES_MASK);
 
-  /* 
-   * We need to construct the open_and_X ofun value from the
-   * NT values, as that's what our code is structured to accept.
-   */    
+       /* 
+        * We need to construct the open_and_X ofun value from the
+        * NT values, as that's what our code is structured to accept.
+        */    
 
-  if((smb_ofun = map_create_disposition( create_disposition )) == -1)
-    return ERROR_DOS(ERRDOS,ERRbadmem);
+       if((smb_ofun = map_create_disposition( create_disposition )) == -1)
+               return ERROR_DOS(ERRDOS,ERRbadmem);
 
-  /*
-   * Get the file name.
-   */
+       /*
+        * Get the file name.
+        */
 
-  if(root_dir_fid != 0) {
-    /*
-     * This filename is relative to a directory fid.
-     */
+       if(root_dir_fid != 0) {
+               /*
+                * This filename is relative to a directory fid.
+                */
 
-    files_struct *dir_fsp = file_fsp(params,4);
-    size_t dir_name_len;
+               files_struct *dir_fsp = file_fsp(params,4);
+               size_t dir_name_len;
 
-    if(!dir_fsp)
-        return ERROR_DOS(ERRDOS,ERRbadfid);
+               if(!dir_fsp)
+                       return ERROR_DOS(ERRDOS,ERRbadfid);
 
-    if(!dir_fsp->is_directory) {
-      /*
-       * Check to see if this is a mac fork of some kind.
-       */
+               if(!dir_fsp->is_directory) {
+                       get_filename_transact(&fname[0], params, 53,
+                                       total_parameter_count - 53 - fname_len, fname_len);
 
-      get_filename_transact(&fname[0], params, 53,
-                            total_parameter_count - 53 - fname_len, fname_len);
+                       /*
+                        * Check to see if this is a mac fork of some kind.
+                        */
 
-      if( strchr(fname, ':')) {
-        return(ERROR_BOTH(NT_STATUS_OBJECT_PATH_NOT_FOUND,ERRDOS,ERRbadpath));
-      }
+                       if( strchr(fname, ':'))
+                               return(ERROR_BOTH(NT_STATUS_OBJECT_PATH_NOT_FOUND,ERRDOS,ERRbadpath));
 
-      return(ERROR_DOS(ERRDOS,ERRbadfid));
-    }
+                       return(ERROR_DOS(ERRDOS,ERRbadfid));
+               }
 
-    /*
-     * Copy in the base directory name.
-     */
+               /*
+                * Copy in the base directory name.
+                */
 
-    pstrcpy( fname, dir_fsp->fsp_name );
-    dir_name_len = strlen(fname);
+               pstrcpy( fname, dir_fsp->fsp_name );
+               dir_name_len = strlen(fname);
 
-    /*
-     * Ensure it ends in a '\'.
-     */
+               /*
+                * Ensure it ends in a '\'.
+                */
 
-    if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
-      pstrcat(fname, "\\");
-      dir_name_len++;
-    }
+               if((fname[dir_name_len-1] != '\\') && (fname[dir_name_len-1] != '/')) {
+                       pstrcat(fname, "\\");
+                       dir_name_len++;
+               }
 
-    /*
-     * This next calculation can refuse a correct filename if we're dealing
-     * with the Win2k unicode bug, but that would be rare. JRA.
-     */
+               /*
+                * This next calculation can refuse a correct filename if we're dealing
+                * with the Win2k unicode bug, but that would be rare. JRA.
+                */
 
-    if(fname_len + dir_name_len >= sizeof(pstring))
-      return(ERROR_DOS(ERRSRV,ERRfilespecs));
+               if(fname_len + dir_name_len >= sizeof(pstring))
+                       return(ERROR_DOS(ERRSRV,ERRfilespecs));
 
-    get_filename_transact(&fname[dir_name_len], params, 53,
-                 total_parameter_count - 53 - fname_len, fname_len);
+               get_filename_transact(&fname[dir_name_len], params, 53,
+                               total_parameter_count - 53 - fname_len, fname_len);
 
-  } else {
-    get_filename_transact(&fname[0], params, 53,
-                 total_parameter_count - 53 - fname_len, fname_len);
-  }
+       } else {
+               get_filename_transact(&fname[0], params, 53,
+                               total_parameter_count - 53 - fname_len, fname_len);
 
-  /*
-   * Now contruct the smb_open_mode value from the desired access
-   * and the share access.
-   */
+               /*
+                * Check to see if this is a mac fork of some kind.
+                */
 
-  if((smb_open_mode = map_share_mode( fname, create_options, &desired_access,
-                                      share_access, file_attributes)) == -1)
-    return ERROR_DOS(ERRDOS,ERRbadaccess);
+               if( strchr(fname, ':'))
+                       return(ERROR_BOTH(NT_STATUS_OBJECT_PATH_NOT_FOUND,ERRDOS,ERRbadpath));
+       }
 
-  oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
-  oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
+       /*
+        * Now contruct the smb_open_mode value from the desired access
+        * and the share access.
+        */
 
-  /*
-   * Check if POSIX semantics are wanted.
-   */
+       if((smb_open_mode = map_share_mode( fname, create_options, &desired_access,
+                                       share_access, file_attributes)) == -1)
+               return ERROR_DOS(ERRDOS,ERRbadaccess);
 
-  set_posix_case_semantics(file_attributes);
+       oplock_request = (flags & REQUEST_OPLOCK) ? EXCLUSIVE_OPLOCK : 0;
+       oplock_request |= (flags & REQUEST_BATCH_OPLOCK) ? BATCH_OPLOCK : 0;
+
+       /*
+        * Check if POSIX semantics are wanted.
+        */
+
+       set_posix_case_semantics(file_attributes);
     
-  RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
+       RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
-  unix_convert(fname,conn,0,&bad_path,&sbuf);
+       unix_convert(fname,conn,0,&bad_path,&sbuf);
     
-  unixmode = unix_mode(conn,smb_attr | aARCH, fname);
+       unixmode = unix_mode(conn,smb_attr | aARCH, fname);
    
-  /*
-   * If it's a request for a directory open, deal with it separately.
-   */
+       /*
+        * If it's a request for a directory open, deal with it separately.
+        */
 
-  if(create_options & FILE_DIRECTORY_FILE) {
+       if(create_options & FILE_DIRECTORY_FILE) {
 
-    oplock_request = 0;
+               oplock_request = 0;
 
-    /*
-     * We will get a create directory here if the Win32
-     * app specified a security descriptor in the 
-     * CreateDirectory() call.
-     */
+               /*
+                * We will get a create directory here if the Win32
+                * app specified a security descriptor in the 
+                * CreateDirectory() call.
+                */
 
-    fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
+               fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
 
-    if(!fsp) {
-      restore_case_semantics(file_attributes);
-      set_bad_path_error(errno, bad_path);
-      return(UNIXERROR(ERRDOS,ERRnoaccess));
-    }
+               if(!fsp) {
+                       restore_case_semantics(file_attributes);
+                       set_bad_path_error(errno, bad_path);
+                       return(UNIXERROR(ERRDOS,ERRnoaccess));
+               }
 
-  } else {
+       } else {
 
-    /*
-     * Ordinary file case.
-     */
+               /*
+                * Ordinary file case.
+                */
 
-    fsp = open_file_shared1(conn,fname,&sbuf,desired_access,smb_open_mode,smb_ofun,unixmode,
-                     oplock_request,&rmode,&smb_action);
+               fsp = open_file_shared1(conn,fname,&sbuf,desired_access,smb_open_mode,smb_ofun,unixmode,
+                               oplock_request,&rmode,&smb_action);
 
-    if (!fsp) { 
+               if (!fsp) { 
 
-               if(errno == EISDIR) {
+                       if(errno == EISDIR) {
 
-                       /*
-                        * Fail the open if it was explicitly a non-directory file.
-                        */
+                               /*
+                                * Fail the open if it was explicitly a non-directory file.
+                                */
 
-                       if (create_options & FILE_NON_DIRECTORY_FILE) {
-                               restore_case_semantics(file_attributes);
-                               SSVAL(outbuf, smb_flg2, 
-                                     SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
-                               return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
-                       }
+                               if (create_options & FILE_NON_DIRECTORY_FILE) {
+                                       restore_case_semantics(file_attributes);
+                                       SSVAL(outbuf, smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
+                                       return ERROR_NT(NT_STATUS_FILE_IS_A_DIRECTORY);
+                               }
        
-                       oplock_request = 0;
-                       fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
-                               
-                       if(!fsp) {
+                               oplock_request = 0;
+                               fsp = open_directory(conn, fname, &sbuf, desired_access, smb_open_mode, smb_ofun, unixmode, &smb_action);
+
+                               if(!fsp) {
+                                       restore_case_semantics(file_attributes);
+                                       set_bad_path_error(errno, bad_path);
+                                       return(UNIXERROR(ERRDOS,ERRnoaccess));
+                               }
+                       } else {
+
                                restore_case_semantics(file_attributes);
                                set_bad_path_error(errno, bad_path);
+
                                return(UNIXERROR(ERRDOS,ERRnoaccess));
                        }
-               } else {
-
-                       restore_case_semantics(file_attributes);
-                       set_bad_path_error(errno, bad_path);
-
-                       return(UNIXERROR(ERRDOS,ERRnoaccess));
-               }
-      } 
+               } 
   
-      file_len = sbuf.st_size;
-      fmode = dos_mode(conn,fname,&sbuf);
-      if(fmode == 0)
-        fmode = FILE_ATTRIBUTE_NORMAL;
+               file_len = sbuf.st_size;
+               fmode = dos_mode(conn,fname,&sbuf);
+               if(fmode == 0)
+                       fmode = FILE_ATTRIBUTE_NORMAL;
 
-      if (fmode & aDIR) {
-        close_file(fsp,False);
-        restore_case_semantics(file_attributes);
-        return ERROR_DOS(ERRDOS,ERRnoaccess);
-      } 
+               if (fmode & aDIR) {
+                       close_file(fsp,False);
+                       restore_case_semantics(file_attributes);
+                       return ERROR_DOS(ERRDOS,ERRnoaccess);
+               
 
-      /* 
-       * If the caller set the extended oplock request bit
-       * and we granted one (by whatever means) - set the
-       * correct bit for extended oplock reply.
-       */
+               /* 
+                * If the caller set the extended oplock request bit
+                * and we granted one (by whatever means) - set the
+                * correct bit for extended oplock reply.
+                */
     
-      if (oplock_request && lp_fake_oplocks(SNUM(conn)))
-        smb_action |= EXTENDED_OPLOCK_GRANTED;
+               if (oplock_request && lp_fake_oplocks(SNUM(conn)))
+                       smb_action |= EXTENDED_OPLOCK_GRANTED;
   
-      if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
-        smb_action |= EXTENDED_OPLOCK_GRANTED;
-  }
+               if(oplock_request && EXCLUSIVE_OPLOCK_TYPE(fsp->oplock_type))
+                       smb_action |= EXTENDED_OPLOCK_GRANTED;
+       }
 
-  /*
-   * Now try and apply the desired SD.
-   */
+       /*
+        * Now try and apply the desired SD.
+        */
 
-  if (!set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION, &error_class, &error_code)) {
-    close_file(fsp,False);
-    restore_case_semantics(file_attributes);
-    return ERROR_DOS(error_class, error_code);
-  }
+       if (!set_sd( fsp, data, sd_len, ALL_SECURITY_INFORMATION, &error_class, &error_code)) {
+               close_file(fsp,False);
+               restore_case_semantics(file_attributes);
+               return ERROR_DOS(error_class, error_code);
+       }
 
-  restore_case_semantics(file_attributes);
+       restore_case_semantics(file_attributes);
 
-  /* Realloc the size of parameters and data we will return */
-  params = Realloc(*ppparams, 69);
-  if(params == NULL)
-    return ERROR_DOS(ERRDOS,ERRnomem);
+       /* Realloc the size of parameters and data we will return */
+       params = Realloc(*ppparams, 69);
+       if(params == NULL)
+               return ERROR_DOS(ERRDOS,ERRnomem);
 
-  *ppparams = params;
+       *ppparams = params;
 
-  memset((char *)params,'\0',69);
+       memset((char *)params,'\0',69);
 
-  p = params;
-  if (smb_action & EXTENDED_OPLOCK_GRANTED)    
-       SCVAL(p,0, BATCH_OPLOCK_RETURN);
-  else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
-    SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
-  else
-       SCVAL(p,0,NO_OPLOCK_RETURN);
+       p = params;
+       if (smb_action & EXTENDED_OPLOCK_GRANTED)       
+               SCVAL(p,0, BATCH_OPLOCK_RETURN);
+       else if (LEVEL_II_OPLOCK_TYPE(fsp->oplock_type))
+               SCVAL(p,0, LEVEL_II_OPLOCK_RETURN);
+       else
+               SCVAL(p,0,NO_OPLOCK_RETURN);
        
-  p += 2;
-  SSVAL(p,0,fsp->fnum);
-  p += 2;
-  SIVAL(p,0,smb_action);
-  p += 8;
-
-  /* Create time. */
-  c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
-
-  if (lp_dos_filetime_resolution(SNUM(conn))) {
-    c_time &= ~1;
-    sbuf.st_atime &= ~1;
-    sbuf.st_mtime &= ~1;
-    sbuf.st_mtime &= ~1;
-  }
+       p += 2;
+       SSVAL(p,0,fsp->fnum);
+       p += 2;
+       SIVAL(p,0,smb_action);
+       p += 8;
 
-  put_long_date(p,c_time);
-  p += 8;
-  put_long_date(p,sbuf.st_atime); /* access time */
-  p += 8;
-  put_long_date(p,sbuf.st_mtime); /* write time */
-  p += 8;
-  put_long_date(p,sbuf.st_mtime); /* change time */
-  p += 8;
-  SIVAL(p,0,fmode); /* File Attributes. */
-  p += 4;
-  SOFF_T(p, 0, SMB_ROUNDUP_ALLOCATION(file_len));
-  p += 8;
-  SOFF_T(p,0,file_len);
-
-  DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
-
-  /* Send the required number of replies */
-  send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
+       /* Create time. */
+       c_time = get_create_time(&sbuf,lp_fake_dir_create_times(SNUM(conn)));
 
-  return -1;
+       if (lp_dos_filetime_resolution(SNUM(conn))) {
+               c_time &= ~1;
+               sbuf.st_atime &= ~1;
+               sbuf.st_mtime &= ~1;
+               sbuf.st_mtime &= ~1;
+       }
+
+       put_long_date(p,c_time);
+       p += 8;
+       put_long_date(p,sbuf.st_atime); /* access time */
+       p += 8;
+       put_long_date(p,sbuf.st_mtime); /* write time */
+       p += 8;
+       put_long_date(p,sbuf.st_mtime); /* change time */
+       p += 8;
+       SIVAL(p,0,fmode); /* File Attributes. */
+       p += 4;
+       SOFF_T(p, 0, SMB_ROUNDUP_ALLOCATION(file_len));
+       p += 8;
+       SOFF_T(p,0,file_len);
+
+       DEBUG(5,("call_nt_transact_create: open name = %s\n", fname));
+
+       /* Send the required number of replies */
+       send_nt_replies(inbuf, outbuf, bufsize, NT_STATUS_OK, params, 69, *ppdata, 0);
+
+       return -1;
 }
 
 /****************************************************************************
@@ -1710,13 +1724,13 @@ static int call_nt_transact_ioctl(connection_struct *conn,
                                   int bufsize, 
                                   char **ppsetup, char **ppparams, char **ppdata)
 {
-  static BOOL logged_message = False;
+       static BOOL logged_message = False;
 
-  if(!logged_message) {
-    DEBUG(2,("call_nt_transact_ioctl: Currently not implemented.\n"));
-    logged_message = True; /* Only print this once... */
-  }
-  return ERROR_DOS(ERRSRV,ERRnosupport);
+       if(!logged_message) {
+               DEBUG(2,("call_nt_transact_ioctl: Currently not implemented.\n"));
+               logged_message = True; /* Only print this once... */
+       }
+       return ERROR_DOS(ERRSRV,ERRnosupport);
 }
    
 /****************************************************************************