commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r770966 - in /commons/sandbox/runtime/trunk/src/main/native: include/arch/windows/acr_arch_private.h os/win32/group.c os/win32/user.c os/win32/wusec.c
Date Sat, 02 May 2009 15:43:19 GMT
Author: mturk
Date: Sat May  2 15:43:18 2009
New Revision: 770966

URL: http://svn.apache.org/viewvc?rev=770966&view=rev
Log:
Abstract common code in a util function

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c

Modified: commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h?rev=770966&r1=770965&r2=770966&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/arch/windows/acr_arch_private.h
Sat May  2 15:43:18 2009
@@ -67,6 +67,7 @@
 SID_NAME_USE ACR_GetAccountSidType(PSID psid);
 LPVOID       ACR_GetTokenInformation(JNIEnv *_E, HANDLE h, TOKEN_INFORMATION_CLASS ic);
 void         ACR_GetUserHomePath(LPWSTR buf, DWORD blen, PSID sid);
+HANDLE       ACR_GetCurrentAccessToken(JNIEnv *_E);
 
 /**
  * Heap allocation from main.c

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c?rev=770966&r1=770965&r2=770966&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c Sat May  2 15:43:18 2009
@@ -258,27 +258,8 @@
     PTOKEN_PRIMARY_GROUP grp = NULL;
 
     UNREFERENCED_O;
-    if (!OpenThreadToken(GetCurrentThread(),
-                         TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                         TRUE, &token)) {
-        if ((rc = GetLastError()) == ERROR_NO_TOKEN) {
-            if (!OpenProcessToken(GetCurrentProcess(),
-                                  TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                                  &token)) {
-                rc = GetLastError();
-            }
-            else
-                rc = 0;
-        }
-        if (rc != ERROR_SUCCESS) {
-            if  (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            else
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
-                                   ACR_FROM_OS_ERROR(rc));
-            return NULL;
-        }
-    }
+    if ((token = ACR_GetCurrentAccessToken(_E)) == NULL)
+        return NULL;
     grp = ACR_GetTokenInformation(_E, token, TokenPrimaryGroup);
     if (grp) {
         gid = ACR_GroupObjectCreateFromId(_E, grp->PrimaryGroup);
@@ -299,27 +280,8 @@
     PTOKEN_OWNER  own = NULL;
 
     UNREFERENCED_O;
-    if (!OpenThreadToken(GetCurrentThread(),
-                         TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                         TRUE, &token)) {
-        if ((rc = GetLastError()) == ERROR_NO_TOKEN) {
-            if (!OpenProcessToken(GetCurrentProcess(),
-                                  TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                                  &token)) {
-                rc = GetLastError();
-            }
-            else
-                rc = 0;
-        }
-        if (rc != ERROR_SUCCESS) {
-            if  (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            else
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
-                                   ACR_FROM_OS_ERROR(rc));
-            return NULL;
-        }
-    }
+    if ((token = ACR_GetCurrentAccessToken(_E)) == NULL)
+        return NULL;
     own = ACR_GetTokenInformation(_E, token, TokenOwner);
     if (own) {
         sidtype = ACR_GetAccountSidType(own->Owner);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c?rev=770966&r1=770965&r2=770966&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c Sat May  2 15:43:18 2009
@@ -294,27 +294,8 @@
     PTOKEN_USER usr = NULL;
 
     UNREFERENCED_O;
-    if (!OpenThreadToken(GetCurrentThread(),
-                         TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                         TRUE, &token)) {
-        if ((rc = GetLastError()) == ERROR_NO_TOKEN) {
-            if (!OpenProcessToken(GetCurrentProcess(),
-                                  TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                                  &token)) {
-                rc = GetLastError();
-            }
-            else
-                rc = 0;
-        }
-        if (rc != ERROR_SUCCESS) {
-            if  (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            else
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
-                                   ACR_FROM_OS_ERROR(rc));
-            return NULL;
-        }
-    }
+    if ((token = ACR_GetCurrentAccessToken(_E)) == NULL)
+        return NULL;
     usr = ACR_GetTokenInformation(_E, token, TokenUser);
     if (usr) {
         uid = ACR_UserObjectCreateFromId(_E, usr->User.Sid);
@@ -333,27 +314,8 @@
     PTOKEN_OWNER usr = NULL;
 
     UNREFERENCED_O;
-    if (!OpenThreadToken(GetCurrentThread(),
-                         TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                         TRUE, &token)) {
-        if ((rc = GetLastError()) == ERROR_NO_TOKEN) {
-            if (!OpenProcessToken(GetCurrentProcess(),
-                                  TOKEN_QUERY | TOKEN_QUERY_SOURCE,
-                                  &token)) {
-                rc = GetLastError();
-            }
-            else
-                rc = 0;
-        }
-        if (rc != ERROR_SUCCESS) {
-            if  (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-            else
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
-                                   ACR_FROM_OS_ERROR(rc));
-            return NULL;
-        }
-    }
+    if ((token = ACR_GetCurrentAccessToken(_E)) == NULL)
+        return NULL;
     usr = ACR_GetTokenInformation(_E, token, TokenOwner);
     if (usr) {
         SID_NAME_USE sidtype = ACR_GetAccountSidType(usr->Owner);

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c?rev=770966&r1=770965&r2=770966&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/wusec.c Sat May  2 15:43:18 2009
@@ -151,3 +151,32 @@
     }
 }
 
+HANDLE ACR_GetCurrentAccessToken(JNIEnv *_E)
+{
+    HANDLE token = NULL;
+    DWORD  rc;
+    if (!OpenThreadToken(GetCurrentThread(),
+                         TOKEN_QUERY | TOKEN_QUERY_SOURCE,
+                         TRUE, &token)) {
+        if ((rc = GetLastError()) == ERROR_NO_TOKEN) {
+            if (!OpenProcessToken(GetCurrentProcess(),
+                                  TOKEN_QUERY | TOKEN_QUERY_SOURCE,
+                                  &token)) {
+                rc = GetLastError();
+            }
+            else
+                rc = 0;
+        }
+        if (rc != ERROR_SUCCESS) {
+            if (_E) {
+                if  (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
+                    ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
+                else
+                    ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+                                       ACR_FROM_OS_ERROR(rc));
+            }
+            return NULL;
+        }
+    }
+    return token;
+}



Mime
View raw message