commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r770962 - in /commons/sandbox/runtime/trunk/src/main/native/os/win32: group.c user.c
Date Sat, 02 May 2009 15:15:22 GMT
Author: mturk
Date: Sat May  2 15:15:19 2009
New Revision: 770962

URL: http://svn.apache.org/viewvc?rev=770962&view=rev
Log:
Strengthen the error detection code

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/group.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/user.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=770962&r1=770961&r2=770962&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:15:19 2009
@@ -126,6 +126,12 @@
 
         return NULL;
     }
+    if (sidtype != SidTypeGroup && sidtype != SidTypeAlias &&
+        sidtype != SidTypeWellKnownGroup) {
+        /* Not a group SID */
+        free(sid);
+        return NULL;
+    }
 
     gid = ACR_DescriptorCreate(_E, 0, -1, sid, sid_descriptor_handler);
     if (!gid) {
@@ -140,7 +146,8 @@
     (*_E)->DeleteLocalRef(_E, gid);
 
     rc = NetLocalGroupGetInfo(NULL, name, 1, (LPBYTE *)&pb);
-    if (rc == NERR_GroupNotFound)
+    if (rc == NERR_GroupNotFound || rc == ERROR_NO_SUCH_ALIAS ||
+        rc == ERROR_NO_SUCH_GROUP)
         rc = NetGroupGetInfo(NULL, name, 1, (LPBYTE *)&pb);
     if (rc == ERROR_SUCCESS) {
         SET_IFIELD_W(0000, grp, pb->lgrpi1_name);
@@ -185,7 +192,12 @@
         free(sid);
         return NULL;
     }
-
+    if (sidtype != SidTypeGroup && sidtype != SidTypeAlias &&
+        sidtype != SidTypeWellKnownGroup) {
+        /* Not a group SID */
+        free(sid);
+        return NULL;
+    }
     gid = ACR_DescriptorCreate(_E, 0, -1, sid, sid_descriptor_handler);
     if (!gid) {
         free(sid);
@@ -197,15 +209,16 @@
         return NULL;
     }
     rc = NetLocalGroupGetInfo(NULL, name, 1, (LPBYTE *)&pb);
-    if (rc == NERR_GroupNotFound || rc == ERROR_NO_SUCH_ALIAS)
+    if (rc == NERR_GroupNotFound || rc == ERROR_NO_SUCH_ALIAS ||
+        rc == ERROR_NO_SUCH_GROUP)
         rc = NetGroupGetInfo(NULL, name, 1, (LPBYTE *)&pb);
     if (rc == ERROR_SUCCESS) {
         SET_IFIELD_W(0000, grp, pb->lgrpi1_name);
         SET_IFIELD_C(0001, grp, pb->lgrpi1_comment);
         NetApiBufferFree(pb);
     }
-    else if ((rc == NERR_GroupNotFound  || rc == ERROR_NO_SUCH_ALIAS) &&
-             sidtype == SidTypeGroup) {
+    else if (rc == NERR_GroupNotFound  || rc == ERROR_NO_SUCH_ALIAS ||
+             rc == ERROR_NO_SUCH_GROUP) {
         SET_IFIELD_W(0000, grp, name);
     }
     else {

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=770962&r1=770961&r2=770962&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:15:19 2009
@@ -141,6 +141,11 @@
         /* TODO: Throw exception */
         return NULL;
     }
+    if (sidtype != SidTypeUser && sidtype != SidTypeAlias) {
+        /* Not a user SID */
+        free(sid);
+        return NULL;
+    }
 
     uid = ACR_DescriptorCreate(_E, 0, -1, sid, sid_descriptor_handler);
     if (!uid) {
@@ -167,12 +172,19 @@
         }
         NetApiBufferFree(pb);
     }
-    else {
+    else if (rc == NERR_UserNotFound  || rc == ERROR_NO_SUCH_ALIAS ||
+             rc == ERROR_NO_SUCH_USER) {
         SET_IFIELD_W(0000, usr, name);
         SET_IFIELD_W(0001, usr, name);
         ACR_GetUserHomePath(home, MAX_PATH, sid);
         SET_IFIELD_C(0003, usr, home);
     }
+    else {
+        ACR_DescriptorCleanup(_E, uid);
+        ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,
+                           ACR_FROM_OS_ERROR(rc));
+        return NULL;
+    }
     if (ConvertSidToStringSidW(sid, &ssid)) {
 
         SET_IFIELD_W(0005, usr, ssid);
@@ -208,6 +220,11 @@
         free(sid);
         return NULL;
     }
+    if (sidtype != SidTypeUser && sidtype != SidTypeAlias) {
+        /* Not a group SID */
+        free(sid);
+        return NULL;
+    }
 
     uid = ACR_DescriptorCreate(_E, 0, -1, sid, sid_descriptor_handler);
     if (!uid) {
@@ -233,6 +250,13 @@
         }
         NetApiBufferFree(pb);
     }
+    else if (rc == NERR_UserNotFound  || rc == ERROR_NO_SUCH_ALIAS ||
+             rc == ERROR_NO_SUCH_USER) {
+        SET_IFIELD_W(0000, usr, name);
+        SET_IFIELD_W(0001, usr, name);
+        ACR_GetUserHomePath(home, MAX_PATH, sid);
+        SET_IFIELD_C(0003, usr, home);
+    }
     else {
         ACR_DescriptorCleanup(_E, uid);
         ACR_ThrowException(_E, THROW_NMARK, ACR_EX_EIO,



Mime
View raw message