Use VFS I/O for stat_cache_lookup()
[samba.git] / source3 / smbd / filename.c
index d311d56b99f685560eee5f083c0e2cff34a4efb0..fb2f57339b4b68724bb42cc5f99e3718342767e7 100644 (file)
@@ -229,7 +229,9 @@ static void stat_cache_add( char *full_orig_name, char *orig_translated_path)
  Return True if we translated (and did a scuccessful stat on) the entire name.
 *****************************************************************************/
 
-static BOOL stat_cache_lookup( char *name, char *dirpath, char **start, SMB_STRUCT_STAT *pst)
+static BOOL stat_cache_lookup(struct connection_struct *conn, char *name, 
+                             char *dirpath, char **start, 
+                             SMB_STRUCT_STAT *pst)
 {
   stat_cache_entry *scp;
   stat_cache_entry *longest_hit = NULL;
@@ -282,7 +284,7 @@ static BOOL stat_cache_lookup( char *name, char *dirpath, char **start, SMB_STRU
    * and then promote it to the top.
    */
 
-  if(dos_stat( longest_hit->translated_name, pst) != 0) {
+  if(conn->vfs_ops.stat(longest_hit->translated_name, pst) != 0) {
     /*
      * Discard this entry.
      */
@@ -368,6 +370,18 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
 
   trim_string(name,"/","/");
 
+  /*
+   * If we trimmed down to a single '\0' character
+   * then we should use the "." directory to avoid
+   * searching the cache, but not if we are in a
+   * printing share.
+   */
+
+  if (!*name && (!conn -> printer)) {
+    name[0] = '.';
+    name[1] = '\0';
+  }
+
   /*
    * Ensure saved_last_component is valid even if file exists.
    */
@@ -399,7 +413,7 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
 
       for (s=name2 ; *s ; s++)
         if (!issafe(*s)) *s = '_';
-          pstrcpy(name,(char *)mktemp(name2));   
+      pstrcpy(name,(char *)mktemp(name2));       
     }      
     return(True);
   }
@@ -419,7 +433,7 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
 
   pstrcpy(orig_path, name);
 
-  if(stat_cache_lookup( name, dirpath, &start, &st)) {
+  if(stat_cache_lookup(conn, name, dirpath, &start, &st)) {
     if(pst)
       *pst = st;
     return True;
@@ -429,7 +443,7 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
    * stat the name - if it exists then we are all done!
    */
 
-  if (dos_stat(name,&st) == 0) {
+  if (conn->vfs_ops.stat(name,&st) == 0) {
     stat_cache_add(orig_path, name);
     DEBUG(5,("conversion finished %s -> %s\n",orig_path, name));
     if(pst)
@@ -497,7 +511,8 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
       /* 
        * Check if the name exists up to this point.
        */
-      if (dos_stat(name, &st) == 0) {
+
+      if (conn->vfs_ops.stat(name, &st) == 0) {
         /*
          * It exists. it must either be a directory or this must be
          * the last part of the path for it to be OK.
@@ -649,7 +664,7 @@ BOOL check_name(char *name,connection_struct *conn)
   if (!lp_symlinks(SNUM(conn)))
     {
       SMB_STRUCT_STAT statbuf;
-      if ( (dos_lstat(name,&statbuf) != -1) &&
+      if ( (conn->vfs_ops.lstat(dos_to_unix(name,False),&statbuf) != -1) &&
           (S_ISLNK(statbuf.st_mode)) )
         {
           DEBUG(3,("check_name: denied: file path name %s is a symlink\n",name));