104 lines
3.0 KiB
C
104 lines
3.0 KiB
C
#ifndef VLIBC_GRP_H
|
|
#define VLIBC_GRP_H
|
|
|
|
/*
|
|
* vlibc — <grp.h>.
|
|
*
|
|
* The group database (todo 37). struct group mirrors /etc/group, whose
|
|
* records are name:passwd:gid:member,member,... — the member list is a
|
|
* comma-separated tail, empty when the group has no members. Everything
|
|
* here is POSIX.1-2008 base (Level 1).
|
|
*
|
|
* The non-reentrant forms getgrnam/getgrgid/getgrent return a pointer to a
|
|
* static structure whose contents — including the strings and the member
|
|
* array it points at — are overwritten by the next call to any of the
|
|
* three. getgrnam/getgrgid open and scan the whole file per call; getgrent
|
|
* walks a cursor that setgrent rewinds and endgrent closes.
|
|
*
|
|
* The _r forms behave like their <pwd.h> counterparts: the entry is written
|
|
* into caller storage (the gr_mem pointer array and the member name strings
|
|
* both live inside the supplied buffer) and the return value is 0 on
|
|
* success, ERANGE when the buffer is too small, or 0 with *result NULL when
|
|
* no entry matches. errno is never touched: the error number IS the return
|
|
* value.
|
|
*/
|
|
|
|
#include <vlibc/features.h>
|
|
|
|
#include <stddef.h>
|
|
#include <sys/types.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* One group database entry (/etc/group record). */
|
|
struct group
|
|
{
|
|
char *gr_name; /* group name */
|
|
char *gr_passwd; /* encrypted password; usually empty */
|
|
gid_t gr_gid; /* numeric group id */
|
|
char **gr_mem; /* NULL-terminated member-name array */
|
|
};
|
|
|
|
/*
|
|
* Look up the first entry whose name matches; NULL when absent. The result
|
|
* points into shared static storage valid only until the next grp call.
|
|
*/
|
|
struct group *
|
|
getgrnam(const char *name);
|
|
|
|
/*
|
|
* Look up the first entry whose gid matches; NULL when absent. Result
|
|
* storage is shared with getgrnam/getgrent as described above.
|
|
*/
|
|
struct group *
|
|
getgrgid(gid_t gid);
|
|
|
|
/*
|
|
* Return the next entry from the group stream, opening it on the first
|
|
* call; NULL at end of file. The stream cursor advances per call.
|
|
*/
|
|
struct group *
|
|
getgrent(void);
|
|
|
|
/* Rewind the group stream to its first entry. */
|
|
void
|
|
setgrent(void);
|
|
|
|
/* Close the group stream; a later getgrent reopens from the start. */
|
|
void
|
|
endgrent(void);
|
|
|
|
int
|
|
getgrnam_r(const char *name, struct group *gr, char *buf, size_t bufsize, struct group **result);
|
|
|
|
int
|
|
getgrgid_r(gid_t gid, struct group *gr, char *buf, size_t bufsize, struct group **result);
|
|
|
|
int
|
|
getgrent_r(struct group *gr, char *buf, size_t bufsize, struct group **result);
|
|
|
|
#if VLIBC_LEVEL_GE(2)
|
|
/* Level 2 (muslmimic): XSI. */
|
|
|
|
#include <stdio.h> /* FILE */
|
|
|
|
/*
|
|
* Return the next entry read from the given open stream, or NULL at end of
|
|
* file or on a malformed/unopenable record; the entry is parsed as an
|
|
* /etc/group record. Result storage is shared with getgrnam/getgrgid/
|
|
* getgrent as described above, so the stream must not be closed until the
|
|
* caller has copied the result. XSI.
|
|
*/
|
|
struct group *
|
|
fgetgrent(FILE *stream);
|
|
|
|
#endif /* VLIBC_LEVEL_GE(2) */
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* VLIBC_GRP_H */
|