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 2009/04/29 19:04:47 UTC

svn commit: r769829 - in /commons/sandbox/runtime/trunk/src: main/native/os/win32/group.c main/native/os/win32/user.c test/org/apache/commons/runtime/TestGroup.java

Author: mturk
Date: Wed Apr 29 17:04:46 2009
New Revision: 769829

URL: http://svn.apache.org/viewvc?rev=769829&view=rev
Log:
Add groupMembers for windows

Modified:
    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/test/org/apache/commons/runtime/TestGroup.java

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=769829&r1=769828&r2=769829&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 Wed Apr 29 17:04:46 2009
@@ -280,3 +280,74 @@
     return grps;
 
 }
+
+ACR_JNI_EXPORT_DECLARE(jobjectArray, Group, enum2)(ACR_JNISTDARGS,
+                                                   jobject gdd)
+{
+
+    DWORD resumehandle = 0, total;
+    PLOCALGROUP_MEMBERS_INFO_1 pb;
+    DWORD  res, dwRec, n, i = 0;
+    jsize j = 0, nusers = 0;
+    jobjectArray usrs = NULL;
+    PSID gid;
+    SID_NAME_USE gidt;
+    WCHAR gname[MAX_PATH];
+
+    UNREFERENCED_O;
+    gid = (PSID)ACR_DescriptorGetPtr(_E, gdd);
+    if (gid == NULL) {
+        return NULL;
+    }
+    gidt = ACR_GetAccountNameFromSid(gname, MAX_PATH, gid);
+    if (gidt == -1) {
+        return NULL;
+    }
+    do {
+        res = NetLocalGroupGetMembers(NULL, gname, 1, (LPBYTE *)&pb,
+                                      MAX_PREFERRED_LENGTH,
+                                      &dwRec, &total, (LPDWORD)&resumehandle );
+        if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+            for (n = 0; n < dwRec; n++) {
+                if (pb[i].lgrmi1_sidusage == SidTypeUser) {
+                    /* Only count in the User accounts */
+                    nusers++;
+                }
+            }
+            NetApiBufferFree(pb);
+        }
+    } while (res == ERROR_MORE_DATA);
+    if (nusers)
+        usrs = ACR_NewUserArray(_E, n);
+    if (!usrs)
+        return NULL;
+    resumehandle = 0;
+    do {
+        res = NetLocalGroupGetMembers(NULL, gname, 1, (LPBYTE *)&pb,
+                                      MAX_PREFERRED_LENGTH,
+                                      &dwRec, &total, (LPDWORD)&resumehandle );
+        if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+            for (n = 0; n < dwRec; n++) {
+                if (pb[n].lgrmi1_sidusage != SidTypeUser)
+                    continue;
+                if (j < nusers) {
+                    jobject uid = ACR_UserObjectCreate(_E, pb[n].lgrmi1_name);
+                    if ((*_E)->ExceptionCheck(_E) || gid == NULL) {
+                        NetApiBufferFree(pb);
+                        usrs = NULL;
+                        goto cleanup;
+                    }
+                    (*_E)->SetObjectArrayElement(_E, usrs, j, uid);
+                    (*_E)->DeleteLocalRef(_E, uid);
+                }
+                j++;
+            }
+            NetApiBufferFree(pb);
+        }
+    } while (res == ERROR_MORE_DATA);
+
+
+cleanup:
+    return usrs;
+
+}

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=769829&r1=769828&r2=769829&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 Wed Apr 29 17:04:46 2009
@@ -134,10 +134,6 @@
     DWORD acclen = (DWORD)blen;
     SID_NAME_USE sidtype;
 
-    if (IsWellKnownSid(psid, WinBuiltinAdministratorsSid)) {
-        wcscpy(buf, L"SYSTEM");
-        return SidTypeWellKnownGroup;
-    }
     if (!LookupAccountSidW(NULL, psid,
                            buf, &acclen,
                            domain, &domlen,

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestGroup.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestGroup.java?rev=769829&r1=769828&r2=769829&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestGroup.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestGroup.java Wed Apr 29 17:04:46 2009
@@ -103,7 +103,7 @@
         Group g;
 
         if (OS.TYPE.contains(OsType.WINDOWS))
-            g = Group.get("Users");
+            g = Group.get("Administrators");
         else
             g = Group.get("sys");
         assertNotNull("Group", g);