Accesses the basic group information in the user database.
Standard C Library (libc.a)
#include <sys/types.h> #include <grp.h>
struct group *getgrent ( );
struct group *getgrgid (GID)
gid_t GID;
struct group *getgrnam (Name)
const char * Name;
void setgrent ( );
void endgrent ( );
The setgrent subroutine opens the user database if it is not already open. Then, this subroutine sets the cursor to point to the first group entry in the database.
The getgrent, getgrnam, and getgrgid subroutines return information about the requested group. The getgrent subroutine returns the next group in the sequential search. The getgrnam subroutine returns the first group in the database whose name matches that of the Name parameter. The getgrgid subroutine returns the first group in the database whose group ID matches the GID parameter. The endgrent subroutine closes the user database.
The group structure is defined in the grp.h file and has the following fields:
gr_name | Contains the name of the group. |
gr_passwd | Contains the password of the group.
Note
This field is
no longer used. |
gr_gid | Contains the ID of the group. |
gr_mem | Contains the members of the group. |
If the Network Information Service (NIS) is enabled on the system, these subroutines attempt to retrieve the group information from the NIS authentication server.
GID | Specifies the group ID. |
Name | Specifies the group name. |
Group | Specifies the basic group information to enter into the user database. |
If successful, the getgrent, getgrnam, and getgrgid subroutines return a pointer to a valid group structure. Otherwise, a null pointer is returned.
These subroutines fail if one or more of the following are returned:
To check an application for error situations, set the errno global variable to a value of 0 before calling the getgrgid subroutine. If the errno global variable is set on return, an error occurred.
/etc/group | Contains basic group attributes. |
List of Security and Auditing Subroutines, Subroutines Overview in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.