costin      01/07/15 17:19:46

  Modified:    src/share/org/apache/tomcat/modules/mappers
                        SimpleMapper1.java
  Log:
  Allow case insensitive matching.
  
  This is another big security addition - we already had huge problems with that.
  Note that this fix is done at the lowest level - the mapper - instead of
  requiring each individual servlet/module to do many checks.
  
  It is of course easy to turn this off or on.
  
  Revision  Changes    Path
  1.6       +42 -11    
jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java
  
  Index: SimpleMapper1.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/mappers/SimpleMapper1.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SimpleMapper1.java        2001/07/02 19:37:54     1.5
  +++ SimpleMapper1.java        2001/07/16 00:19:46     1.6
  @@ -62,10 +62,9 @@
   import org.apache.tomcat.core.*;
   import org.apache.tomcat.util.buf.MessageBytes;
   import org.apache.tomcat.util.io.FileUtil;
  -//import org.apache.tomcat.util.PrefixMapper;
   import org.apache.tomcat.util.collections.*;
   import java.util.*;
  -
  +import java.io.*;
   /**
    *  This class will set up the data structures used by a simple patern matching
    *  alghoritm and use it to extract the path components from the request URI.
  @@ -100,8 +99,11 @@
       // Property for the PrefixMapper - cache the mapping results
       boolean mapCacheEnabled=false;
       
  +    
       public SimpleMapper1() {
        map=new PrefixMapper();
  +     ignoreCase= (File.separatorChar  == '\\');
  +     map.setIgnoreCase( ignoreCase );
       }
   
       /* -------------------- Support functions -------------------- */
  @@ -113,6 +115,17 @@
        map.setMapCache( v );
       }
   
  +    // -------------------- Ingore case --------------------
  +    boolean ignoreCase=false;
  +
  +    /** Use case insensitive match, for windows and
  +     similar platforms
  +    */
  +    public void setIgnoreCase( boolean b ) {
  +     ignoreCase=b;
  +     map.setIgnoreCase( b );
  +    }
  +
       /* -------------------- Initialization -------------------- */
       
       /** Set the context manager. To keep it simple we don't support
  @@ -209,7 +222,10 @@
                defC.setNote( ctExtMapNote, eM );
            }
            // add it to the Container local maps
  -         eM.put( path.substring( 1 ), ct );
  +         if( ignoreCase )
  +             eM.put( path.substring( 1 ).toLowerCase() , ct );
  +         else
  +             eM.put( path.substring( 1 ), ct );
            if(debug>0)
                log( "SM: extension map " + ctxP + "/" +
                     path + " " + ct + " " );
  @@ -359,6 +375,7 @@
        if( extM==null ) return null;
   
        // Find the container associated with that extension
  +     if( ignoreCase ) extension=extension.toLowerCase();
        Container container= (Container)extM.get(extension);
   
        if (container == null)
  @@ -460,7 +477,7 @@
       // mappers ( extending this one for example ) using 1.2 collections
       // TreeMap mapCache;
       boolean mapCacheEnabled=false;
  -
  +    boolean ignoreCase=false;
       
       public PrefixMapper() {
        prefixMappedServlets=new SimpleHashtable();
  @@ -472,6 +489,10 @@
        mapCacheEnabled=v;
       }
   
  +    public void setIgnoreCase( boolean b ) {
  +     ignoreCase=b;
  +    }
  +    
       /** Remove all mappings matching path
        */
       public void removeAllMappings( String host, Context ctx ) {
  @@ -523,17 +544,24 @@
       /**
        */
       public void addMapping( String host, String path, Object target ) {
  -     if( host == null )
  -         prefixMappedServlets.put( path, target);
  -     else {
  +     if( host == null ) {
  +         if( ignoreCase )
  +             prefixMappedServlets.put( path.toLowerCase(), target);
  +         else
  +             prefixMappedServlets.put( path, target);
  +     } else {
            host=host.toLowerCase();
            PrefixMapper vmap=(PrefixMapper)vhostMaps.get( host );
            if( vmap == null ) {
                vmap=new PrefixMapper();
  -             vhostMaps.put( host, vmap );
  +             vmap.setIgnoreCase( ignoreCase );
  +                 vhostMaps.put( host, vmap );
                vmap.setMapCache( mapCacheEnabled );
            }
  -         vmap.addMapping( path, target );
  +         if( ignoreCase ) 
  +             vmap.addMapping( path.toLowerCase(), target );
  +         else
  +             vmap.addMapping( path, target );
        }
       }
   
  @@ -549,7 +577,10 @@
                vmap=new PrefixMapper();
                vhostMaps.put( host, vmap );
            }
  -         vmap.addExactMapping( path, target );
  +         if( ignoreCase ) 
  +             vmap.addExactMapping( path.toLowerCase(), target );
  +         else
  +             vmap.addExactMapping( path, target );
        }
       }
       
  @@ -577,7 +608,7 @@
        
        if( myMap==null ) myMap = this; // default server
   
  -     
  +     if( ignoreCase ) path=path.toLowerCase();
        container=myMap.exactMappedServlets.get( path );
        if( container != null ) return container; // and we're done!
   
  
  
  

Reply via email to