Fixed the bug with descending into mangled directories.
authorJeremy Allison <jra@samba.org>
Tue, 18 Dec 2001 01:26:54 +0000 (01:26 +0000)
committerJeremy Allison <jra@samba.org>
Tue, 18 Dec 2001 01:26:54 +0000 (01:26 +0000)
The problem is that name_map_mangle can *change* the length of a patchname.
Ensure that all the character pointer messing about can cope with changing
sizes of components. This code is too ugly to live.....
This also needs *lots* of testing.
Jeremy.

source/smbd/filename.c

index d1c512c25117f0efeb3f7fac0fc388c549896bc6..f098950c441412481b9bfd3bb3d032b6cc3065ac 100644 (file)
@@ -283,7 +283,7 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
       } else {
         pstring rest;
 
-               /* Stat failed - ensure we don't use it. */
+        /* Stat failed - ensure we don't use it. */
         ZERO_STRUCT(st);
         *rest = 0;
 
@@ -320,7 +320,7 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
              
           /* 
            * Just the last part of the name doesn't exist.
-              * We may need to strupper() or strlower() it in case
+           * We may need to strupper() or strlower() it in case
            * this conversion is being used for file creation 
            * purposes. If the filename is of mixed case then 
            * don't normalise it.
@@ -343,11 +343,14 @@ BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component,
         }
 
       /* 
-       * Restore the rest of the string.
+       * Restore the rest of the string. If the string was mangled the size
+       * may have changed.
        */
       if (end) {
-        pstrcpy(start+strlen(start)+1,rest);
         end = start + strlen(start);
+        pstrcat(start,"/");
+        pstrcat(start,rest);
+        *end = '\0';
       }
     } /* end else */
 
@@ -489,7 +492,7 @@ static BOOL scan_directory(char *path, char *name,connection_struct *conn,BOOL d
       if (!name_map_mangle(name2,False,True,SNUM(conn)))
         continue;
 
-      if ((mangled && mangled_equal(name,name2)) || fname_equal(name, name2)) {
+      if ((mangled && mangled_equal(name,name2)) || fname_equal(name, dname)) {
         /* we've found the file, change it's name and return */
         if (docache)
           DirCacheAdd(path,name,dname,SNUM(conn));