commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r769771 - /commons/sandbox/runtime/trunk/src/main/native/os/win32/user.c
Date Wed, 29 Apr 2009 12:21:58 GMT
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;
+
+}



Mime
View raw message