first pass at updating head branch to be to be the same as the SAMBA_2_0 branch
[tprouty/samba.git] / source3 / smbd / filename.c
index 685725f0961198c793f32adf05d8b1f425f8a280..64f63805f3250dc32b74897f45aaed351599d59b 100644 (file)
@@ -96,7 +96,12 @@ static int global_stat_cache_hits;
 
 void print_stat_cache_statistics(void)
 {
-  double eff = (100.0* (double)global_stat_cache_hits)/(double)global_stat_cache_lookups;
+  double eff;
+
+  if(global_stat_cache_lookups == 0)
+    return;
+
+  eff = (100.0* (double)global_stat_cache_hits)/(double)global_stat_cache_lookups;
 
   DEBUG(0,("stat cache stats: lookups = %d, hits = %d, misses = %d, \
 stat cache was %f%% effective.\n", global_stat_cache_lookups,
@@ -332,10 +337,9 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
                   BOOL *bad_path, SMB_STRUCT_STAT *pst)
 {
   SMB_STRUCT_STAT st;
-  char *start, *end, *orig_start;
+  char *start, *end;
   pstring dirpath;
   pstring orig_path;
-  int saved_errno;
   BOOL component_was_mangled = False;
   BOOL name_has_wildcard = False;
 #if 0
@@ -343,6 +347,8 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
   extern char magic_char;
 #endif
 
+  DEBUG(5, ("unix_convert called on file \"%s\"\n", name));
+
   *dirpath = 0;
   *bad_path = False;
   if(pst) {
@@ -366,19 +372,17 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
 
   trim_string(name,"/","/");
 
-  /* I've disabled this till we fix printing (probably a getatr problem) (tridge) */
-#if TRIM_NULL_NAMES
   /*
    * If we trimmed down to a single '\0' character
    * then we should use the "." directory to avoid
-   * searching the cache.
+   * searching the cache, but not if we are in a
+   * printing share.
    */
 
-  if(!*name) {
+  if (!*name && (!conn -> printer)) {
     name[0] = '.';
     name[1] = '\0';
   }
-#endif
 
   /*
    * Ensure saved_last_component is valid even if file exists.
@@ -411,11 +415,20 @@ 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 *)smbd_mktemp(name2));          
     }      
     return(True);
   }
 
+  /*
+   * If we trimmed down to a single '\0' character
+   * then we will be using the "." directory.
+   * As we know this is valid we can return true here.
+   */
+
+  if(!*name)
+    return(True);
+
   start = name;
   while (strncmp(start,"./",2) == 0)
     start += 2;
@@ -440,8 +453,6 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
     return(True);
   }
 
-  saved_errno = errno;
-
   DEBUG(5,("unix_convert begin: name = %s, dirpath = %s, start = %s\n",
         name, dirpath, start));
 
@@ -451,7 +462,7 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
    */
 
   if (case_sensitive && !is_mangled(name) && 
-      !lp_strip_dot() && !use_mangled_map && (saved_errno != ENOENT))
+      !lp_strip_dot() && !use_mangled_map)
     return(False);
 
   if(strchr(start,'?') || strchr(start,'*'))
@@ -482,7 +493,7 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
    * as is first, then trying to scan the directory for matching names.
    */
 
-  for (orig_start = start; start ; start = (end?end+1:(char *)NULL)) {
+  for (; start ; start = (end?end+1:(char *)NULL)) {
       /* 
        * Pinpoint the end of this section of the filename.
        */
@@ -716,7 +727,8 @@ static BOOL scan_directory(char *path, char *name,connection_struct *conn,BOOL d
        continue;
 
       pstrcpy(name2,dname);
-      if (!name_map_mangle(name2,False,SNUM(conn))) continue;
+      if (!name_map_mangle(name2,False,True,SNUM(conn)))
+        continue;
 
       if ((mangled && mangled_equal(name,name2))
          || fname_equal(name, name2))