You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/19 00:07:59 UTC

svn commit: r1094791 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/platform/windows/ native/shared/

Author: mturk
Date: Mon Apr 18 22:07:58 2011
New Revision: 1094791

URL: http://svn.apache.org/viewvc?rev=1094791&view=rev
Log:
More Win32 security API

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java?rev=1094791&r1=1094790&r2=1094791&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Security.java Mon Apr 18 22:07:58 2011
@@ -21,6 +21,7 @@ import org.apache.commons.runtime.Alread
 import org.apache.commons.runtime.NoSuchObjectException;
 import org.apache.commons.runtime.ClosedDescriptorException;
 import org.apache.commons.runtime.SystemException;
+import org.apache.commons.runtime.util.Utils;
 
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -62,4 +63,50 @@ final class Security
     public static native long       GetCurrentProcessToken()
         throws SystemException;
 
+
+    public static long getStdSecurityDescriptor(int objectType, int mode)
+        throws SystemException
+    {
+        int uacc = GetAccessMask(objectType, PROT_SCOPE_USER,  mode);
+        int gacc = GetAccessMask(objectType, PROT_SCOPE_GROUP, mode);
+        int wacc = GetAccessMask(objectType, PROT_SCOPE_WORLD, mode);
+
+        StringBuffer sdd = new StringBuffer("D:(D;OICI;GA;;;BG)(D;OICI;GA;;;AN)");
+        StringBuffer saa = new StringBuffer("(A;OICI;0x");
+        saa.append(Utils.hex(uacc));
+        sdd.append(saa);
+        sdd.append(";;;BA)");
+        sdd.append(saa);
+        sdd.append(";;;CO)");
+        sdd.append(saa);
+        sdd.append(";;;LS)");
+        sdd.append(saa);
+        sdd.append(";;;SY)");
+        sdd.append(saa);
+        sdd.append(";;;SU)");
+        if (gacc != 0) {
+            sdd.append("(A;OICI;0x");
+            sdd.append(Utils.hex(gacc));
+            sdd.append(";;;CG)");
+        }
+        if (wacc != 0) {
+            sdd.append("(A;OICI;0x");
+            sdd.append(Utils.hex(wacc));
+            sdd.append(";;;AU)");
+        }
+        String desc = sdd.toString();
+        Long sd = sdcache.get(desc);
+        if (sd == null) {
+            long sh = ConvertStringSecurityDescriptorToSecurityDescriptor(desc, SDDL_REVISION_1);
+            if (sh == 0L) {
+                // Throw SystemException
+                throw new SystemException(Status.describe(Status.errno()));
+            }
+            sd = new Long(sh);
+            sdcache.put(desc, sd);
+        }
+        return sd.longValue();
+    }
+
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java?rev=1094791&r1=1094790&r2=1094791&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/Win32.java Mon Apr 18 22:07:58 2011
@@ -79,7 +79,7 @@ final class Win32
     /* semaphore access rights  */
     public static final int         SEMAPHORE_ALL_ACCESS    = 0x001F0003;
     public static final int         SEMAPHORE_MODIFY_STATE  = 0x00000002;
-    
+
     /* Memory allocation flags  */
     public static final int         MEM_COMMIT              = 0x00001000;
     public static final int         MEM_RESERVE             = 0x00002000;
@@ -109,5 +109,5 @@ final class Win32
     public static native long       VirtualAlloc(long base, long size, int type, int protect);
     public static native int        VirtualProtect(long addr, long size, int protect);
     public static native int        VirtualFree(long addr, long size, int type);
-     
+
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java?rev=1094791&r1=1094790&r2=1094791&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/windows/WindowsSemaphore.java Mon Apr 18 22:07:58 2011
@@ -39,7 +39,6 @@ final class WindowsSemaphore extends Sem
 
     // OS semaphore handle
     private long    sd;
-    private long    sa;
 
     private static native long create0(String name, int value, long sd)
         throws IllegalAccessException,
@@ -61,7 +60,10 @@ final class WindowsSemaphore extends Sem
         if (name == null)
             throw new NullPointerException();
         this.name = "Global\\" + name.replace('\\', '_');
-        sa = Win32.GetNullDacl();
+        long sa = Security.getStdSecurityDescriptor(Security.SEMAPHORE,
+                                                    Win32.FPROT_URWX |
+                                                    Win32.FPROT_GRWX |
+                                                    Win32.FPROT_WRW);
         sd = create0(this.name, value, sa);
         owner = true;
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=1094791&r1=1094790&r2=1094791&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Mon Apr 18 22:07:58 2011
@@ -768,7 +768,7 @@ AcrThrowByStatus(JNI_STDENV, int err, co
     AcrThrow(env, cls, msg);
 }
 
-ACR_JNI_EXPORT(void, io_Status, init0)(JNI_STDARGS, jintArray ra)
+ACR_JNI_EXPORT(void, Status, init0)(JNI_STDARGS, jintArray ra)
 {
     jint i[92];