1GETGRNAM(3) Linux Programmer's Manual GETGRNAM(3)
2
3
4
6 getgrnam, getgrnam_r, getgrgid, getgrgid_r - get group file entry
7
9 #include <sys/types.h>
10 #include <grp.h>
11
12 struct group *getgrnam(const char *name);
13
14 struct group *getgrgid(gid_t gid);
15
16 int getgrnam_r(const char *name, struct group *gbuf,
17 char *buf, size_t buflen, struct group **gbufp);
18
19 int getgrgid_r(gid_t gid, struct group *gbuf,
20 char *buf, size_t buflen, struct group **gbufp);
21
23 The getgrnam() function returns a pointer to a structure containing the
24 broken-out fields of the record in the group database (e.g., the local
25 group file /etc/group, NIS, and LDAP) that matches the group name name.
26
27 The getgrgid() function returns a pointer to a structure containing the
28 broken-out fields of the record in the group database that matches the
29 group ID gid.
30
31 The getgrnam_r() and getgrgid_r() functions obtain the same informa‐
32 tion, but store the retrieved group structure in the space pointed to
33 by gbuf. This group structure contains pointers to strings, and these
34 strings are stored in the buffer buf of size buflen. A pointer to the
35 result (in case of success) or NULL (in case no entry was found or an
36 error occurred) is stored in *gbufp.
37
38 The group structure is defined in <grp.h> as follows:
39
40 struct group {
41 char *gr_name; /* group name */
42 char *gr_passwd; /* group password */
43 gid_t gr_gid; /* group ID */
44 char **gr_mem; /* group members */
45 };
46
47 The maximum needed size for buf can be found using sysconf(3) with the
48 _SC_GETGR_R_SIZE_MAX parameter.
49
51 The getgrnam() and getgrgid() functions return a pointer to a group
52 structure, or NULL if the matching entry is not found or an error
53 occurs. If an error occurs, errno is set appropriately. If one wants
54 to check errno after the call, it should be set to zero before the
55 call.
56
57 The return value may point to static area, and may be overwritten by
58 subsequent calls to getgrent(), getgrgid(), or getgrnam().
59
60 The getgrnam_r() and getgrgid_r() functions return zero on success. In
61 case of error, an error number is returned.
62
64 0 or ENOENT or ESRCH or EBADF or EPERM or ...
65 The given name or gid was not found.
66
67 EINTR A signal was caught.
68
69 EIO I/O error.
70
71 EMFILE The maximum number (OPEN_MAX) of files was open already in the
72 calling process.
73
74 ENFILE The maximum number of files was open already in the system.
75
76 ENOMEM Insufficient memory to allocate group structure.
77
78 ERANGE Insufficient buffer space supplied.
79
81 /etc/group
82 local group database file
83
85 SVr4, 4.3BSD, POSIX.1-2001
86
88 The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
89 It does not call "not found" an error, hence does not specify what
90 value errno might have in this situation. But that makes it impossible
91 to recognize errors. One might argue that according to POSIX errno
92 should be left unchanged if an entry is not found. Experiments on vari‐
93 ous Unix-like systems shows that lots of different values occur in this
94 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably
95 others.
96
98 endgrent(3), fgetgrent(3), getgrent(3), getpwnam(3), setgrent(3),
99 group(5)
100
101
102
103 2003-11-15 GETGRNAM(3)