David Carr avatar David Carr committed fdef430

windows-provider: add support for user full name enumeration

Comments (0)

Files changed (2)

windows-provider/src/main/java/us/carrclan/david/authc4j/windows/provider/USER_INFO_10.java

+package us.carrclan.david.authc4j.windows.provider;
+
+import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
+import com.sun.jna.WString;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * The USER_INFO_10 structure contains information about a user account, including the account name, comments associated
+ * with the account, and the user's full name.
+ */
+public class USER_INFO_10 extends Structure {
+    public USER_INFO_10() {
+        super();
+    }
+
+    public USER_INFO_10(Pointer memory) {
+        super(memory);
+        read();
+    }
+
+    /**
+     * Pointer to a Unicode string that specifies the name of the user account.  Calls to the NetUserSetInfo function
+     * ignore this member.
+     */
+    public WString usri10_name;
+    /**
+     * Pointer to a Unicode string that contains a comment associated with the user account. The string can be a null
+     * string, or can have any number of characters before the terminating null character.
+     */
+    public WString usri10_comment;
+    /**
+     * Pointer to a Unicode string that contains a user comment. This string can be a null string, or it can have any
+     * number of characters before the terminating null character.
+     */
+    public WString usri10_usr_comment;
+    /**
+     * Pointer to a Unicode string that contains the full name of the user. This string can be a null string, or it can
+     * have any number of characters before the terminating null character.
+     */
+    public WString usri10_full_name;
+
+    protected List getFieldOrder() {
+        return Arrays.asList(new String[]{"usri10_name", "usri10_comment", "usri10_usr_comment", "usri10_full_name"});
+    }
+}

windows-provider/src/main/java/us/carrclan/david/authc4j/windows/provider/WindowsUserInformationSource.java

         IntByReference totalEntries = new IntByReference();
         try {
             int rc = Netapi32.INSTANCE.NetUserEnum(
-                    serverName, 1, LMAccess.FILTER_NORMAL_ACCOUNT, bufptr,
+                    serverName, 10, LMAccess.FILTER_NORMAL_ACCOUNT, bufptr,
                     LMCons.MAX_PREFERRED_LENGTH, entriesRead,
                     totalEntries, null);
             if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
                 throw new Win32Exception(rc);
             }
-            LMAccess.USER_INFO_1 user = new LMAccess.USER_INFO_1(bufptr.getValue());
-            LMAccess.USER_INFO_1[] users = (LMAccess.USER_INFO_1[]) user.toArray(entriesRead.getValue());
-            for (LMAccess.USER_INFO_1 lu : users) {
-                // TODO: support full name
-                recipient.receiveUserInfo(lu.usri1_name.toString(), null);
+            USER_INFO_10 user = new USER_INFO_10(bufptr.getValue());
+            USER_INFO_10[] users = (USER_INFO_10[]) user.toArray(entriesRead.getValue());
+            for (USER_INFO_10 lu : users) {
+                recipient.receiveUserInfo(lu.usri10_name.toString(), lu.usri10_full_name.toString());
             }
         } finally {
             if (bufptr.getValue() != Pointer.NULL) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.