MentOS  0.8.0
The Mentoring Operating System
Functions | Variables
grp.c File Reference

Functions

static void __parse_line (group_t *grp, char *buf)
 It parses the line (as string) and saves its content inside the group_t structure. More...
 
static int __search_entry (int fd, char *buf, size_t buflen, const char *name, gid_t gid)
 Searches an entry in /etc/group. More...
 
group_tgetgrgid (gid_t gid)
 Provides access to the group database entry for uid. More...
 
group_tgetgrnam (const char *name)
 Provides access to the group database entry for name. More...
 
int getgrgid_r (gid_t gid, group_t *group, char *buf, size_t buflen, group_t **result)
 Provides the same information as getgrgid but it stores the results inside group, and the string information are store store inside buf. More...
 
int getgrnam_r (const char *name, group_t *group, char *buf, size_t buflen, group_t **result)
 Provides the same information as getgrnam but it stores the results inside group, and the string information are store store inside buf. More...
 
group_tgetgrent (void)
 Returns a pointer to a structure containing the broken-out fields of an entry in the group database. More...
 
void endgrent (void)
 Rewinds the group database to allow repeated searches.
 
void setgrent (void)
 May be called to close the group database when processing is complete.
 

Variables

static int __fd = -1
 Holds the file descriptor while we are working with /etc/group.
 

Detailed Description

Function Documentation

◆ __parse_line()

static void __parse_line ( group_t grp,
char *  buf 
)
inlinestatic

It parses the line (as string) and saves its content inside the group_t structure.

Parameters
grpthe struct where we store the information.
bufthe line from which we extract the information.

◆ __search_entry()

static int __search_entry ( int  fd,
char *  buf,
size_t  buflen,
const char *  name,
gid_t  gid 
)
inlinestatic

Searches an entry in /etc/group.

Parameters
fdthe file descriptor pointing to /etc/group.
bufthe buffer we are going to use to search the entry.
buflenthe length of the buffer.
namethe name we are looking for.
gidthe group id we must match.
Returns
1 on success, 0 on failure.

◆ getgrent()

group_t* getgrent ( void  )

Returns a pointer to a structure containing the broken-out fields of an entry in the group database.

Returns
pointer to the group entry.

When first called returns a pointer to a group structure containing the first entry in the group database. Thereafter, it returns a pointer to a group structure containing the next group structure in the group database, so successive calls may be used to search the entire database.

◆ getgrgid()

group_t* getgrgid ( gid_t  gid)

Provides access to the group database entry for uid.

Parameters
gidThe gid to search inside the database.
Returns
A pointer to the structure containing the database entry.

◆ getgrgid_r()

int getgrgid_r ( gid_t  gid,
group_t group,
char *  buf,
size_t  buflen,
group_t **  result 
)

Provides the same information as getgrgid but it stores the results inside group, and the string information are store store inside buf.

Parameters
gidThe uid to search inside the database.
groupThe structure containing pointers to the entry fields.
bufThe buffer where the strings should be stored.
buflenThe lenght of the buffer.
resultA pointer to the result or NULL is stored here.
Returns
If the entry was found returns zero and set *result to group, if the entry was not found returns zero and set *result to NULL, on failure returns a number and sets and set *result to NULL.

◆ getgrnam()

group_t* getgrnam ( const char *  name)

Provides access to the group database entry for name.

Parameters
nameThe name to search inside the database.
Returns
A pointer to the structure containing the database entry.

◆ getgrnam_r()

int getgrnam_r ( const char *  name,
group_t group,
char *  buf,
size_t  buflen,
group_t **  result 
)

Provides the same information as getgrnam but it stores the results inside group, and the string information are store store inside buf.

Parameters
nameThe name to search inside the database.
groupThe structure containing pointers to the entry fields.
bufThe buffer where the strings should be stored.
buflenThe lenght of the buffer.
resultA pointer to the result or NULL is stored here.
Returns
If the entry was found returns zero and set *result to group, if the entry was not found returns zero and set *result to NULL, on failure returns a number and sets and set *result to NULL.