6.4. Group FileThe UNIX System's group file, called the group database by POSIX.1, contains the fields shown in Figure 6.4. These fields are contained in a group structure that is defined in <grp.h>.
The field gr_mem is an array of pointers to the user names that belong to this group. This array is terminated by a null pointer. We can look up either a group name or a numerical group ID with the following two functions, which are defined by POSIX.1.
As with the password file functions, both of these functions normally return pointers to a static variable, which is overwritten on each call. If we want to search the entire group file, we need some additional functions. The following three functions are like their counterparts for the password file.
The setgrent function opens the group file, if it's not already open, and rewinds it. The getgrent function reads the next entry from the group file, opening the file first, if it's not already open. The endgrent function closes the group file. |