RFR: 8277489: Rewrite JAAS UnixLoginModule with FFM

Weijun Wang weijun at openjdk.org
Mon Dec 22 14:27:03 UTC 2025


On Mon, 22 Dec 2025 07:19:21 GMT, Shawn M Emery <duke at openjdk.org> wrote:

>> Rewrite the native calls with FFM.
>
> src/jdk.security.auth/share/classes/com/sun/security/auth/module/UnixSystem.java line 78:
> 
>> 76:             }
>> 77: 
>> 78:             var resbuf = passwd.allocate(scope);
> 
> Wouldn't this be 1024 as well?

This is the `MemorySegment allocate(SegmentAllocator allocator)` method in the generated `passwd.java`. If I understand correctly, the 2nd argument to `getpwuid_r` should be the pointer to a single `passwd` struct and the 3rd is to a big enough memory to hold contents of extra pointers inside `passwd`.

> src/jdk.security.auth/share/classes/com/sun/security/auth/module/UnixSystem.java line 81:
> 
>> 79:             var pwd = scope.allocate(C_POINTER);
>> 80:             var pwd_buf = scope.allocate(1024);
>> 81:             int out = getpwuid_r(getuid(), resbuf, pwd_buf, pwd_buf.byteSize(), pwd);
> 
> nit: resbuf is usually name pwd, which is used to reference the passwd attributes in pwd_buf.

I was using the old names in the C code. They could be confusing. I'll fix them.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/28931#discussion_r2640048037
PR Review Comment: https://git.openjdk.org/jdk/pull/28931#discussion_r2640050297


More information about the security-dev mailing list