db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject svn commit: r384282 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/store/raw/data/ testing/org/apache/derbyTesting/functionTests/tests/lang/ testing/org/apache/derbyTesting/functionTests/tests/store/ testing/org/apache/derbyTesting/functi...
Date Wed, 08 Mar 2006 17:51:18 GMT
Author: mikem
Date: Wed Mar  8 09:51:15 2006
New Revision: 384282

URL: http://svn.apache.org/viewcvs?rev=384282&view=rev
Log:
DERBY-616, committing on behalf of Suresh Thalamati

- Added a missing privileged blocks for I/O call in StreamFileContainer.java ,
this class is used by the sort during index creation ..etc.

-- Enabled some of the tests which were not running under security manager
earlier because of this bug to run by default with security manager.

-- removed the additional permissions from the derby test policy file
that were added earlier to avoid this bug for some test cases.


Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/authorize_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/compressTable_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/syscat_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/wisconsin_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/access_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/testsqldecimal_app.properties
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/store/raw/data/StreamFileContainer.java
Wed Mar  8 09:51:15 2006
@@ -57,6 +57,7 @@
 import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream;
 import org.apache.derby.iapi.services.io.LimitInputStream;
 import org.apache.derby.iapi.services.property.PropertyUtil;
+import org.apache.derby.iapi.util.ReuseFactory;
 
 import java.util.Properties;
 import java.io.InputStream;
@@ -66,6 +67,10 @@
 import java.io.EOFException;
 import java.io.InvalidClassException;
 import java.io.Externalizable;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
+import java.io.FileNotFoundException;
 
 /**
 
@@ -84,7 +89,7 @@
 **/
 
 
-public class StreamFileContainer implements TypedFormat
+public class StreamFileContainer implements TypedFormat, PrivilegedExceptionAction
 {
 
     /**************************************************************************
@@ -138,6 +143,17 @@
 	private byte[]                          zeroBytes;	// in case encryption
                                                         // stream needs pad.
 
+
+    /* privileged actions */
+    private static final int STORAGE_FILE_EXISTS_ACTION = 1;
+    private static final int STORAGE_FILE_DELETE_ACTION = 2;
+    private static final int STORAGE_FILE_MKDIRS_ACTION = 3;
+    private static final int STORAGE_FILE_GET_OUTPUT_STREAM_ACTION = 4;
+    private static final int STORAGE_FILE_GET_INPUT_STREAM_ACTION = 5;
+    private int actionCode;
+    private StorageFile actionStorageFile;
+
+
     /**************************************************************************
      * Constructors for This class:
      **************************************************************************
@@ -179,7 +195,7 @@
         {
 			file = getFileName(identity, true, false);
 
-            if (file.exists()) 
+            if (privExists(file)) 
             {
 				// note I'm left in the no-identity state as fillInIdentity()
                 // hasn't been called.
@@ -226,14 +242,14 @@
     {
 
 		file = getFileName(this.identity, false, true);
-        if (!file.exists())
+        if (!privExists(file))
 			return null;
 
 		try 
         {
 			if (!forUpdate) 
             {
-				fileIn = file.getInputStream();
+				fileIn = privGetInputStream(file);
 
 				if (dataFactory.databaseEncrypted()) 
                 {
@@ -459,7 +475,7 @@
 
 		try 
         {
-			fileOut = file.getOutputStream();
+			fileOut = privGetOutputStream(file);
 
 			FormatableBitSet validColumns = rowSource.getValidColumns();
 
@@ -966,9 +982,9 @@
     {
 		close();
 
-        if (file.exists())
+        if (privExists(file))
         {
-            return file.delete();
+            return privDelete(file);
         }
         else
         {
@@ -1005,7 +1021,7 @@
 
 			StorageFile container = dataFactory.getContainerPath( identity, false);
 
-			if (!container.exists()) 
+			if (!privExists(container)) 
             {
 
 				if (!forCreate)
@@ -1013,14 +1029,14 @@
 
 				StorageFile directory = container.getParentDir();
 
-				if (!directory.exists()) 
+				if (!privExists(directory)) 
                 {
 					// make sure only 1 thread can create a segment at one time
 					synchronized(dataFactory) 
                     {
-						if (!directory.exists()) 
+						if (!privExists(directory)) 
                         {
-							if (!directory.mkdirs()) 
+							if (!privMkdirs(directory)) 
                             {
 								if (errorOK)
 									return null;
@@ -1036,4 +1052,132 @@
 			return container;
 		}
 	}
+
+
+
+    
+    private synchronized boolean privExists(StorageFile file)
+    {
+        actionCode = STORAGE_FILE_EXISTS_ACTION;
+        actionStorageFile = file;
+
+        try
+        {
+            Object ret = AccessController.doPrivileged( this);
+            return ((Boolean) ret).booleanValue();
+        }catch( PrivilegedActionException pae) 
+        { 
+            // method executed under this priveleged block 
+            // does not throw an exception
+            return false;
+        } 
+        finally
+        {
+            actionStorageFile = null;
+        }
+    }
+
+    private synchronized boolean privMkdirs(StorageFile file)
+    {
+        actionCode = STORAGE_FILE_MKDIRS_ACTION;
+        actionStorageFile = file;
+
+        try
+        {
+            Object ret = AccessController.doPrivileged( this);
+            return ((Boolean) ret).booleanValue();
+        }catch( PrivilegedActionException pae) 
+        {
+            // method executed under this priveleged block 
+            // does not throw an exception
+            return false;
+        } 
+        finally
+        {
+            actionStorageFile = null;
+        }
+    }
+
+    
+    private synchronized boolean privDelete(StorageFile file)
+    {
+        actionCode = STORAGE_FILE_DELETE_ACTION;
+        actionStorageFile = file;
+
+        try
+        {
+            Object ret = AccessController.doPrivileged( this);
+            return ((Boolean) ret).booleanValue();
+        }catch( PrivilegedActionException pae) 
+        { 
+            // method executed under this priveleged block 
+            // does not throw an exception
+            return false;
+        } 
+        finally
+        {
+            actionStorageFile = null;
+        }
+    }
+
+    private synchronized OutputStream privGetOutputStream(StorageFile file)
+        throws FileNotFoundException
+    {
+        actionCode = STORAGE_FILE_GET_OUTPUT_STREAM_ACTION;
+        actionStorageFile = file;
+
+        try
+        {
+            return (OutputStream) AccessController.doPrivileged( this);
+        }catch( PrivilegedActionException pae) 
+        { 
+            throw (FileNotFoundException)pae.getException();
+        } 
+        finally
+        {
+            actionStorageFile = null;
+        }
+    }
+
+
+    private synchronized InputStream privGetInputStream(StorageFile file)
+        throws FileNotFoundException
+    {
+        actionCode = STORAGE_FILE_GET_INPUT_STREAM_ACTION;
+        actionStorageFile = file;
+
+        try
+        {
+            return (InputStream) AccessController.doPrivileged( this);
+        }catch( PrivilegedActionException pae) 
+        { 
+            throw (FileNotFoundException)pae.getException();
+        } 
+        finally
+        {
+            actionStorageFile = null;
+        }
+    }
+
+
+    // PrivilegedAction method
+    public Object run() throws FileNotFoundException
+    {
+        switch(actionCode)
+        {
+        case STORAGE_FILE_EXISTS_ACTION:
+            return ReuseFactory.getBoolean(actionStorageFile.exists());
+        case STORAGE_FILE_DELETE_ACTION:
+            return ReuseFactory.getBoolean(actionStorageFile.delete());
+        case STORAGE_FILE_MKDIRS_ACTION:
+            return ReuseFactory.getBoolean(actionStorageFile.mkdirs());
+        case STORAGE_FILE_GET_OUTPUT_STREAM_ACTION:
+            return actionStorageFile.getOutputStream();
+        case STORAGE_FILE_GET_INPUT_STREAM_ACTION:
+            return actionStorageFile.getInputStream();
+        }
+
+        return null;
+    }
+
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/authorize_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/authorize_app.properties?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/authorize_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/authorize_app.properties
Wed Mar  8 09:51:15 2006
@@ -7,5 +7,5 @@
 #Exclude for J2ME/Foundation for now - test uses server-side JDBC
 runwithfoundation=false
 
-# BUG - DERBY-616
+# Test fails with security manager due to bug DEBRY-537
 noSecurityManager=true

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/compressTable_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/compressTable_app.properties?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/compressTable_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/compressTable_app.properties
Wed Mar  8 09:51:15 2006
@@ -1,5 +1,2 @@
 usedefaults=true
 
-# BUG - DERBY-616
-noSecurityManager=true
-

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/syscat_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/syscat_app.properties?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/syscat_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/syscat_app.properties
Wed Mar  8 09:51:15 2006
@@ -1,8 +1,5 @@
 #usedefaults=true
 
-# BUG - DERBY-616
-noSecurityManager=true
-
 ij.database=jdbc:derby:syscatdb;create=true
 ij.protocol=jdbc:derby:
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/wisconsin_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/wisconsin_app.properties?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/wisconsin_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/wisconsin_app.properties
Wed Mar  8 09:51:15 2006
@@ -15,7 +15,4 @@
 
 usedefaults=true
 
-# BUG - DERBY-616
-noSecurityManager=true
-
 supportfiles=tests/lang/wisc_setup.sql

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/access_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/access_app.properties?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/access_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/access_app.properties
Wed Mar  8 09:51:15 2006
@@ -1,6 +1,3 @@
 
 usedefaults=true
 
-#exclude with SecurityManager DERBY-616
-noSecurityManager=true
-

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30_app.properties?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/holdCursorExternalSortJDBC30_app.properties
Wed Mar  8 09:51:15 2006
@@ -5,6 +5,3 @@
 
 usedefaults=true
 
-#exclude with SecurityManager DERBY-616
-noSecurityManager=true
-

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/testsqldecimal_app.properties
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/testsqldecimal_app.properties?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/testsqldecimal_app.properties
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/store/testsqldecimal_app.properties
Wed Mar  8 09:51:15 2006
@@ -1,7 +1,5 @@
 
 usedefaults=true
 
-#exclude with SecurityManager - DERBY-616
-noSecurityManager=true
 
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy?rev=384282&r1=384281&r2=384282&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/util/derby_tests.policy
Wed Mar  8 09:51:15 2006
@@ -82,11 +82,6 @@
   // BUG DERBY-622 derbynet/sysinfo.java
   permission java.io.FilePermission "${derbyTesting.codedir}${/}*", "read";
   
-  // BUG DERBY-616 lang/wisconsin.sql & jdbcapi/maxfieldsize.java
-  permission java.io.FilePermission "${derby.system.home}${/}wombat${/}tmp${/}-", "read,
write, delete";
-  // BUG DERBY-616/DERBY-943 lang/syscat.sql with ibm142. 
-  permission java.io.FilePermission "${derby.system.home}${/}syscatdb${/}tmp${/}-", "read,
write, delete";
-  
   // BUG DERBY-623 - sane=true
   permission java.util.PropertyPermission "derby.monitor.verbose", "read";
   permission java.util.PropertyPermission "derby.debug.*", "read";



Mime
View raw message