xiaoxiang781216 opened a new pull request, #19183:
URL: https://github.com/apache/nuttx/pull/19183

   ## Summary
   
   Add `getgrouplist()` to the C library. It scans the group database for
   a user's supplementary groups and always reports the primary group
   (passed by the caller) first.
   
   - With CONFIG_LIBC_GROUP_FILE, the group file is scanned and every group
     whose member list contains the user is appended, skipping the primary
     group to avoid duplicates.
   - Without CONFIG_LIBC_GROUP_FILE, only the primary group is returned,
     since no membership information is available.
   - *ngroups is updated with the number of groups found; when the caller
     buffer is too small the function returns -1 with *ngroups set to the
     required count, following glibc.
   
   The group file is read through lib_get_tempbuffer()/lib_put_tempbuffer()
   to avoid a heap allocation on every lookup.
   
   ## Impact
   
   New GNU/BSD API declared in <grp.h>. No change to existing behavior or
   build for code that does not call getgrouplist(). Helps porting
   third-party software that expects getgrouplist() to be available.
   
   ## Testing
   
   Built the sim:nsh configuration on Linux (x86_64, GCC) with
   CONFIG_LIBC_GROUP_FILE both enabled and disabled, and exercised
   getgrouplist() against a crafted /etc/group with a user in multiple
   groups (correct count and gid list; -1 with required count on a
   too-small buffer). checkpatch.sh passes on the changed files.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to