Determine the group access list for a user
#include <unistd.h> int getgrouplist( const char *name, gid_t basegid, gid_t *groups, int *ngroups );
The Neutrino implementation of getgrouplist() ignores the basegid argument; see the “Caveats,” below. |
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
This function is in libc.a, but not in libc.so (in order to save space). |
The getgrouplist() function reads the group file and determines the group access list for the user specified in name.
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <limits.h> int main() { int ngroups, i; gid_t groups[NGROUPS_MAX]; ngroups = NGROUPS_MAX; if ( getgrouplist( getlogin(), getegid(), groups, &ngroups) == -1) { printf ("Groups array is too small: %d\n", ngroups); } printf ("%s belongs to these groups: %d", getlogin(), getegid()); for (i=0; i < ngroups; i++) { printf (", %d", groups[i]); } printf ("\n"); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |