commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r812087 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_error.h os/unix/group.c os/unix/user.c os/win32/group.c os/win32/user.c os/win32/wusec.c
Date Mon, 07 Sep 2009 11:26:58 GMT
Author: mturk
Date: Mon Sep  7 11:26:57 2009
New Revision: 812087

URL: http://svn.apache.org/viewvc?rev=812087&view=rev
Log:
Throw OS exception instead IO exception for users and groups

Modified:
    commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c
    commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c
    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/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=812087&r1=812086&r2=812087&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Mon Sep  7 11:26:57
2009
@@ -134,6 +134,25 @@
         ACR_SET_OS_ERROR(_se);                                              \
     } else _E = _E
 
+#define ACR_THROW_OS_IF_ERR(S)                                              \
+    if ((S) && IS_VALID_HANDLE(_E)) {                                       \
+        if (ACR_STATUS_IS_EACCES((S)))                                      \
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, (S));     \
+        else                                                                \
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, (S));         \
+        ACR_SET_OS_ERROR((S));                                              \
+    } else _E = _E
+
+#define ACR_THROW_OS_ERRNO()                                                \
+    if (IS_VALID_HANDLE(_E)) {                                              \
+        int _se = ACR_GET_OS_ERROR();                                       \
+        if (ACR_STATUS_IS_EACCES(_se))                                      \
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, _se);     \
+        else                                                                \
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, _se);         \
+        ACR_SET_OS_ERROR(_se);                                              \
+    } else _E = _E
+
 /*
  * Convenience function to help throw any class
  * @param env JNI Environment

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c?rev=812087&r1=812086&r2=812087&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/group.c Mon Sep  7 11:26:57 2009
@@ -106,7 +106,7 @@
     if (rc) {
         rc = ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_ENOENT(rc)) {
-            ACR_THROW_IO_IF_ERR(rc);
+            ACR_THROW_OS_IF_ERR(rc);
         }
         return NULL;
     }
@@ -148,7 +148,7 @@
     if (rc) {
         rc = ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_ENOENT(rc)) {
-            ACR_THROW_IO_IF_ERR(rc);
+            ACR_THROW_OS_IF_ERR(rc);
         }
         return NULL;
     }
@@ -254,7 +254,7 @@
     if (rc) {
         rc = ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_ENOENT(rc)) {
-            ACR_THROW_IO_IF_ERR(rc);
+            ACR_THROW_OS_IF_ERR(rc);
         }
         return NULL;
     }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c?rev=812087&r1=812086&r2=812087&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/user.c Mon Sep  7 11:26:57 2009
@@ -121,7 +121,7 @@
     if (rc) {
         rc = ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_ENOENT(rc)) {
-            ACR_THROW_IO_IF_ERR(rc);
+            ACR_THROW_OS_IF_ERR(rc);
         }
         return NULL;
     }
@@ -168,7 +168,7 @@
     if (rc) {
         rc = ACR_GET_OS_ERROR();
         if (ACR_STATUS_IS_ENOENT(rc)) {
-            ACR_THROW_IO_IF_ERR(rc);
+            ACR_THROW_OS_IF_ERR(rc);
         }
         return NULL;
     }
@@ -265,7 +265,7 @@
         errno = 0;
         ut = getutxent();
         if (ut == NULL && n == 0) {
-            ACR_THROW_IO_ERRNO();
+            ACR_THROW_OS_ERRNO();
             return NULL;
         }
         if (ut == NULL)

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=812087&r1=812086&r2=812087&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 Mon Sep  7 11:26:57 2009
@@ -109,7 +109,6 @@
 {
     jobject grp;
     jobject gid;
-    int err;
     DWORD rc;
     SID_NAME_USE sidtype;
     PSID  sid;
@@ -118,12 +117,9 @@
 
     sid =  ACR_GetSidFromAccountName(name, &sidtype);
     if (!sid) {
-        err = ACR_GET_OS_ERROR();
-        if  (ACR_STATUS_IS_EACCES(err))
-            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-        else if (ACR_TO_OS_ERROR(err) != ERROR_NONE_MAPPED)
-            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, err);
-
+        if ((rc = GetLastError()) != ERROR_NONE_MAPPED) {
+            ACR_THROW_OS_IF_ERR((ACR_TO_OS_ERROR(rc));
+        }
         return NULL;
     }
     if (sidtype != SidTypeGroup && sidtype != SidTypeAlias &&
@@ -183,13 +179,13 @@
     if (!(sid = ACR_Malloc(_E, THROW_FMARK, len)))
         return NULL;
     if (!CopySid(len, sid, id)) {
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, ACR_GET_OS_ERROR());
+        ACR_THROW_OS_ERRNO();
         free(sid);
         return NULL;
     }
     sidtype = ACR_GetAccountNameFromSid(name, MAX_PATH, sid);
     if (sidtype == -1) {
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, ACR_GET_OS_ERROR());
+        ACR_THROW_OS_ERRNO();
         free(sid);
         return NULL;
     }

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=812087&r1=812086&r2=812087&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 Mon Sep  7 11:26:57 2009
@@ -122,7 +122,6 @@
 {
     jobject usr;
     jobject uid;
-    int err;
     DWORD rc;
     SID_NAME_USE sidtype;
     PSID  sid;
@@ -132,12 +131,9 @@
 
     sid =  ACR_GetSidFromAccountName(name, &sidtype);
     if (!sid) {
-        err = ACR_GET_OS_ERROR();
-        if  (ACR_STATUS_IS_EACCES(err))
-            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
-        else if (ACR_TO_OS_ERROR(err) != ERROR_NONE_MAPPED)
-            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, err);
-
+        if ((rc = GetLastError()) != ERROR_NONE_MAPPED) {
+            ACR_THROW_OS_IF_ERR((ACR_TO_OS_ERROR(rc));
+        }
         /* TODO: Throw exception */
         return NULL;
     }
@@ -182,8 +178,7 @@
     }
     else {
         ACR_DescriptorCleanup(_E, uid);
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR,
-                           ACR_FROM_OS_ERROR(rc));
+        ACR_THROW_OS_IF_ERR(ACR_FROM_OS_ERROR(rc));
         return NULL;
     }
     if (ConvertSidToStringSidW(sid, &ssid)) {
@@ -211,13 +206,13 @@
     if (!(sid = ACR_Malloc(_E, THROW_FMARK, len)))
         return NULL;
     if (!CopySid(len, sid, id)) {
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, ACR_GET_OS_ERROR());
+        ACR_THROW_OS_ERRNO();
         free(sid);
         return NULL;
     }
     sidtype = ACR_GetAccountNameFromSid(name, MAX_PATH, sid);
     if (sidtype == -1) {
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, ACR_GET_OS_ERROR());
+        ACR_THROW_OS_ERRNO();
         free(sid);
         return NULL;
     }
@@ -261,8 +256,7 @@
     }
     else {
         ACR_DescriptorCleanup(_E, uid);
-        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR,
-                           ACR_FROM_OS_ERROR(rc));
+        ACR_THROW_OS_IF_ERR(ACR_FROM_OS_ERROR(rc));
         return NULL;
     }
     if (ConvertSidToStringSidW(sid, &ssid)) {

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=812087&r1=812086&r2=812087&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 Mon Sep  7 11:26:57 2009
@@ -98,11 +98,12 @@
     GetTokenInformation(h, ic, NULL, sz, &sz);
     if ((rc = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) {
         if(_E) {
-            if (ACR_STATUS_IS_EACCES(ACR_FROM_OS_ERROR(rc)))
+            rc = ACR_FROM_OS_ERROR(rc);
+            if (ACR_STATUS_IS_EACCES(rc))
                 ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ESECURITY, 0);
             else if (rc != NERR_UserNotFound && rc != NERR_GroupNotFound)
-                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR,
-                                   ACR_FROM_OS_ERROR(rc));
+                ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, rc);
+            ACR_SET_OS_ERROR(rc);
         }
         return NULL;
     }
@@ -110,11 +111,12 @@
         return NULL;
     }
     if (!GetTokenInformation(h, ic, rv, sz, &sz)) {
+        rc = ACR_GET_OS_ERROR();
         if(_E) {
-            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR,
-                               ACR_GET_OS_ERROR());
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_OSERR, rc);
         }
         free(rv);
+        ACR_SET_OS_ERROR(rc);
         rv = NULL;
     }
     return rv;



Mime
View raw message