You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2006/02/11 01:32:18 UTC

svn commit: r376897 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/monitor/ModuleFactory.java iapi/services/monitor/Monitor.java impl/services/monitor/BaseMonitor.java impl/store/raw/data/BaseDataFileFactory.java

Author: djd
Date: Fri Feb 10 16:32:16 2006
New Revision: 376897

URL: http://svn.apache.org/viewcvs?rev=376897&view=rev
Log:
DERBY-927 (partial) Remove the (unused) code path that incorrectly seemed to allow
service providers (implementations for a service, e.g. a database) and
storage factory implementations to be set from the Properties object passed
into a connection. This would be a security hole as it would allow remote
users to possibly change the implementation used to access the database,
thus changing the security environment. The code could not be exercised
as the embedded driver correctly stripped out derby.* properties from
the JDBC attributes passed in with a connection request.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/ModuleFactory.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/Monitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/ModuleFactory.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/ModuleFactory.java?rev=376897&r1=376896&r2=376897&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/ModuleFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/ModuleFactory.java Fri Feb 10 16:32:16 2006
@@ -103,7 +103,7 @@
      *
      * @exception StandardException
      */
-    public PersistentService getServiceProvider( Properties startParams, String subSubProtocol) throws StandardException;
+    public PersistentService getServiceProvider(String subSubProtocol) throws StandardException;
     
 	public Properties getApplicationProperties();
 
@@ -175,6 +175,14 @@
 		Start a persistent service.
 		<BR>
 		<B>Do not call directly - use Monitor.startPersistentService()</B>
+		
+		<P> The poperty set passed in is for boot options for the modules
+		required to start the service. It does not support defining different
+		or new modules implementations.
+		
+		@param serviceName Name of the service to be started
+		@param properties Property set made available to all modules booted
+		for this service, through their ModuleControl.boot method.
 
 		@return true if the service type is handled by the monitor, false if it isn't
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/Monitor.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/Monitor.java?rev=376897&r1=376896&r2=376897&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/Monitor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/monitor/Monitor.java Fri Feb 10 16:32:16 2006
@@ -516,6 +516,14 @@
 
 		If true is returned then findService should be used to see if the service
 		exists or not.
+		
+		<P> The poperty set passed in is for boot options for the modules
+		required to start the service. It does not support defining different
+		or new modules implementations.
+		
+		@param serviceName Name of the service to be started
+		@param properties Property set made available to all modules booted
+		for this service, through their ModuleControl.boot method.
 
 		@return true if the service type is handled by the monitor, false if it isn't
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=376897&r1=376896&r2=376897&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java Fri Feb 10 16:32:16 2006
@@ -961,7 +961,7 @@
 				try {
 					if (protocolOrType.equals(Monitor.SERVICE_TYPE_DIRECTORY)) {
 						if (bootAll)	// only if automatic booting is required
-							startPersistentService(name, properties, true);
+							findProviderAndStartService(name, properties, true);
 					} else {
 						bootService((PersistentService) null,
 							protocolOrType, name, (Properties)null, false);
@@ -984,20 +984,13 @@
 		@see ModuleFactory#startPersistentService
 		@see Monitor#startPersistentService
 	*/
-	public boolean startPersistentService(String name, Properties properties)
+	public final boolean startPersistentService(String name, Properties properties)
 		throws StandardException {
 
-		return startPersistentService(name, properties, false);
+		return findProviderAndStartService(name, properties, false);
 
 	}
 
-	protected boolean startPersistentService(String name, 
-				 Properties properties, boolean bootTime)
-		throws StandardException {
-
-		return findProviderAndStartService(name, properties, bootTime);
-	}
-
 	/**
 		Create a persistent service.
 
@@ -1012,24 +1005,24 @@
 		throws StandardException {
 
 
-		PersistentService provider = findProviderForCreate(properties, name);
+		PersistentService provider = findProviderForCreate(name);
 		if (provider == null) {
 			throw StandardException.newException(SQLState.PROTOCOL_UNKNOWN, name);
 		}
 
 		return bootService(provider, factoryInterface, name, properties, true);
 	}
-    /* Removes a PersistentService
+    /**
+     *  Removes a PersistentService.
+     *  Could be used for drop database.
        @param name : Service name to be removed.
        
-       Note : Currently needed by dropPublisher. But this can be used to
-              remove any PersistentService.
-	*/
+    */
     public void removePersistentService(String name)
          throws StandardException 
     {
         PersistentService provider=null;
-		provider = findProviderForCreate(null, name);
+		provider = findProviderForCreate(name);
         String serviceName = provider.getCanonicalServiceName(name);
         boolean removed = provider.removeServiceRoot(serviceName);
         if (removed == false)
@@ -1503,7 +1496,7 @@
 	/**
 		Find a provider and start  a service.
 	*/
-	protected boolean findProviderAndStartService(String name, 
+	private boolean findProviderAndStartService(String name, 
 						  Properties properties, boolean bootTime)
 		throws StandardException {
 
@@ -1515,7 +1508,7 @@
 		// see if the name already includes a service type
 		int colon = name.indexOf(':');
 		if (colon != -1) {
-			actualProvider = findProviderFromName(properties, name, colon);
+			actualProvider = findProviderFromName(name, colon);
 
 			// if null is returned here then its a sub-sub protocol/provider
 			// that we don't understand. Attempt to load it as an untyped name.
@@ -1593,25 +1586,17 @@
 		return true;
 	}
 
-	protected PersistentService findProvider() throws StandardException
-	{
-		// This is a hack. This is called when we want to re-write 
-		// services.properties, and need the provider for the database
-		// directory.
-		return findProviderForCreate(null, "");
-	}
-
-	protected PersistentService findProviderForCreate(Properties startParams, String name) throws StandardException {
+	protected PersistentService findProviderForCreate(String name) throws StandardException {
 		// RESOLVE - hard code creating databases in directories for now.
-		return (PersistentService) findProviderFromName( startParams, name, name.indexOf(':'));
+		return (PersistentService) findProviderFromName(name, name.indexOf(':'));
 	}
 
 	/**
 		Find the service provider from a name that includes a service type,
-		ie. is of the form 'type:name'. If type is less than 3 chanacters
+		ie. is of the form 'type:name'. If type is less than 3 characters
 		then it is assumed to be of type directory, i.e. a windows driver letter.
 	*/
-	private PersistentService findProviderFromName(Properties startParams, String name, int colon) throws StandardException
+	private PersistentService findProviderFromName(String name, int colon) throws StandardException
     {
 		// empty type, treat as a unknown protocol
 		if (colon == 0)
@@ -1624,10 +1609,10 @@
 		} else {
 			serviceType = name.substring(0, colon);
 		}
-		return getServiceProvider( startParams, serviceType);
+		return getServiceProvider(serviceType);
 	}
 
-    public PersistentService getServiceProvider( Properties startParams, String subSubProtocol) throws StandardException
+    public PersistentService getServiceProvider(String subSubProtocol) throws StandardException
     {
         if( subSubProtocol == null)
             return null;
@@ -1637,13 +1622,18 @@
             if( ps != null)
                 return ps;
         }
-        return getPersistentService( startParams, subSubProtocol);
+        return getPersistentService(subSubProtocol);
     } // end of getServiceProvider
 
-    private PersistentService getPersistentService( Properties properties, String subSubProtocol)
+ 
+    /**
+     * Return a PersistentService implementation to handle the subSubProtocol.
+     * @return Valid PersistentService or null if the protocol is not handled.
+      */
+    private PersistentService getPersistentService(String subSubProtocol)
         throws StandardException
     {
-        String className = getStorageFactoryClassName( properties, subSubProtocol);
+        String className = getStorageFactoryClassName(subSubProtocol);
         return getPersistentService( className, subSubProtocol);
     }
 
@@ -1665,14 +1655,16 @@
         return new StorageFactoryService( subSubProtocol, storageFactoryClass);
     } // end of getPersistentService
 
-    private String getStorageFactoryClassName( Properties properties, String subSubProtocol)
+    /**
+     * Find the StorageFactory class name that handles the subSub protocol.
+     * Looks in the system property set and the set defined during boot.
+ 
+      * @return Valid class name, or null if no StorageFactory handles the protocol.
+     */
+    private String getStorageFactoryClassName(String subSubProtocol)
     {
         String propertyName = Property.SUB_SUB_PROTOCOL_PREFIX + subSubProtocol;
-        String className = null;
-        if( properties != null)
-            className = properties.getProperty( propertyName);
-        if( className == null)
-            className = PropertyUtil.getSystemProperty( propertyName);
+        String className = PropertyUtil.getSystemProperty( propertyName);
         if( className != null)
             return className;
         return (String) storageFactories.get( subSubProtocol);
@@ -2169,7 +2161,7 @@
                 try
                 {
                     storageFactoryPersistentService
-                      = getPersistentService( getStorageFactoryClassName( null, PersistentService.DIRECTORY),
+                      = getPersistentService( getStorageFactoryClassName(PersistentService.DIRECTORY),
                                               PersistentService.DIRECTORY);
                 }
                 catch( StandardException se){ storageFactoryPersistentService = null; }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java?rev=376897&r1=376896&r2=376897&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/BaseDataFileFactory.java Fri Feb 10 16:32:16 2006
@@ -250,7 +250,7 @@
 		if (serviceType == null)
 			return false;
 
-		if (!handleServiceType(startParams, serviceType))
+		if (!handleServiceType(serviceType))
 			return false;
 
 		if (startParams.getProperty(PersistentService.ROOT) == null)
@@ -1770,13 +1770,12 @@
 		Does this factory support this service type.
 	*/
 	private boolean handleServiceType(
-    Properties  startParams, 
     String      type) 
     {
         try
         {
             PersistentService ps = 
-                Monitor.getMonitor().getServiceProvider( startParams, type);
+                Monitor.getMonitor().getServiceProvider(type);
             return ps != null && ps.hasStorageFactory();
         }
         catch (StandardException se)