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 14:21:58 UTC

svn commit: r769771 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c

Author: mturk
Date: Wed Apr 29 12:21:56 2009
New Revision: 769771

URL: http://svn.apache.org/viewvc?rev=769771&view=rev
Log:
Add windows 'who'

Modified:
    commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c

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=769771&r1=769770&r2=769771&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 12:21:56 2009
@@ -334,3 +334,59 @@
     return usrs;
 
 }
+
+ACR_JNI_EXPORT_DECLARE(jobjectArray, User, enum1)(ACR_JNISTDARGS)
+{
+
+    DWORD resumehandle = 0, total;
+    PWKSTA_USER_INFO_0 pb;
+    DWORD  res, dwRec, n, i = 0;
+    jsize j = 0, nusers = 0;
+    jobjectArray usrs = NULL;
+
+    UNREFERENCED_O;
+    do {
+        res = NetWkstaUserEnum(NULL, 0, (LPBYTE *)&pb, MAX_PREFERRED_LENGTH,
+                               &dwRec, &total, (LPDWORD)&resumehandle );
+        if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+            for (n = 0; n < dwRec; n++) {
+                if (!wcschr(pb[n].wkui0_username, L'$')) {
+                    /* XXX: What are those users with $ in the name? */
+                    nusers++;
+                }
+            }
+            NetApiBufferFree(pb);
+        }
+    } while (res == ERROR_MORE_DATA);
+    if (nusers)
+        usrs = (*_E)->NewObjectArray(_E, nusers, _clazzn.i, NULL);
+    if (!usrs)
+        return NULL;
+    resumehandle = 0;
+    do {
+        res = NetWkstaUserEnum(NULL, 0, (LPBYTE *)&pb, MAX_PREFERRED_LENGTH,
+                               &dwRec, &total, (LPDWORD)&resumehandle );
+        if ((res == ERROR_SUCCESS) || (res == ERROR_MORE_DATA)) {
+            for (n = 0; n < dwRec; n++) {
+                if (wcschr(pb[n].wkui0_username, L'$'))
+                    continue;
+                if (j < nusers) {
+                    jobject uid = ACR_UserObjectCreate(_E, pb[n].wkui0_username);
+                    if ((*_E)->ExceptionCheck(_E) || uid == 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;
+
+}