Page MenuHomeFreeBSD

lposix: Use reentrant passwd and group lookup functions
ClosedPublic

Authored by markj on Sep 5 2024, 10:42 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 9:19 PM
Unknown Object (File)
Fri, Oct 10, 9:19 PM
Unknown Object (File)
Fri, Oct 10, 9:19 PM
Unknown Object (File)
Fri, Oct 10, 3:38 PM
Unknown Object (File)
Wed, Oct 8, 8:28 PM
Unknown Object (File)
Sep 5 2025, 11:19 AM
Unknown Object (File)
Aug 30 2025, 1:59 AM
Unknown Object (File)
Aug 14 2025, 10:11 PM
Subscribers
None

Details

Summary

Avoid nasty surprises for code which calls posix.unistd.chmod() in a
loop while iterating over passwd or group entries.

Fix some style nits while here.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj requested review of this revision.Sep 5 2024, 10:42 PM
markj created this revision.
This revision is now accepted and ready to land.Sep 6 2024, 11:51 AM

The change is fine. Had a question about the code, but if itakes more than a sec to answer, then 'it was like that when I got here' is fine :)

libexec/flua/modules/lposix.c
112

So what happens if you pass in none or nil for this argument? You just get the -1 default?

libexec/flua/modules/lposix.c
112

Yes, so chown("/foo/bar", "markj") doesn't change the group ownership.

If you want to avoid modifying the user ownership, you have to write chown("/foo/bar", -1, "imp") instead, though it's not immediately clear to me that that will work as implemented.

When dealing with lua integers, I tend to write something like:

lua_Integer i = lua_tointeger(L, 2);
if (i < 0 || i > UID_MAX)
    /* raise an error */
uid_t uid = (uid_t)i;
...

so that we don't silently truncate arguments.