]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/getgrnam.3
ffix
[thirdparty/man-pages.git] / man3 / getgrnam.3
1 .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" References consulted:
24 .\" Linux libc source code
25 .\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
26 .\" 386BSD man pages
27 .\"
28 .\" Modified 1993-07-24 by Rik Faith (faith@cs.unc.edu)
29 .\" Modified 2003-11-15 by aeb
30 .\"
31 .TH GETGRNAM 3 2003-11-15 "" "Linux Programmer's Manual"
32 .SH NAME
33 getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
34 .SH SYNOPSIS
35 .nf
36 .B #include <sys/types.h>
37 .B #include <grp.h>
38 .sp
39 .BI "struct group *getgrnam(const char *" name );
40 .sp
41 .BI "struct group *getgrgid(gid_t " gid );
42 .sp
43 .BI "int getgrnam_r(const char *" name ", struct group *" gbuf ,
44 .br
45 .BI " char *" buf ", size_t " buflen ", struct group **" gbufp );
46 .sp
47 .BI "int getgrgid_r(gid_t " gid ", struct group *" gbuf ,
48 .br
49 .BI " char *" buf ", size_t " buflen ", struct group **" gbufp );
50 .fi
51 .SH DESCRIPTION
52 The
53 .BR getgrnam ()
54 function returns a pointer to a structure containing
55 the broken-out fields of the record in the group database
56 (e.g., the local group file
57 .IR /etc/group ,
58 NIS, and LDAP)
59 that matches the group name
60 .IR name .
61 .PP
62 The
63 .BR getgrgid ()
64 function returns a pointer to a structure containing
65 the broken-out fields of the record in the group database
66 that matches the group ID
67 .IR gid .
68 .PP
69 The
70 .BR getgrnam_r ()
71 and
72 .BR getgrgid_r ()
73 functions obtain the same information, but store the retrieved
74 .I group
75 structure
76 in the space pointed to by
77 .IR gbuf .
78 This
79 .I group
80 structure contains pointers to strings, and these strings
81 are stored in the buffer
82 .I buf
83 of size
84 .IR buflen .
85 A pointer to the result (in case of success) or NULL (in case no entry
86 was found or an error occurred) is stored in
87 .RI * gbufp .
88 .PP
89 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
90 .sp
91 .RS +0.25i
92 .nf
93 struct group {
94 char *gr_name; /* group name */
95 char *gr_passwd; /* group password */
96 gid_t gr_gid; /* group ID */
97 char **gr_mem; /* group members */
98 };
99 .fi
100 .RE
101 .PP
102 The maximum needed size for
103 .I buf
104 can be found using
105 .BR sysconf (3)
106 with the
107 .B _SC_GETGR_R_SIZE_MAX
108 parameter.
109 .SH "RETURN VALUE"
110 The
111 .BR getgrnam ()
112 and
113 .BR getgrgid ()
114 functions return a pointer to a
115 .I group
116 structure, or NULL if the matching entry
117 is not found or an error occurs.
118 If an error occurs,
119 .I errno
120 is set appropriately.
121 If one wants to check
122 .I errno
123 after the call, it should be set to zero before the call.
124 .LP
125 The return value may point to static area, and may be overwritten
126 by subsequent calls to
127 .BR getgrent (3),
128 .BR getgrgid (),
129 or
130 .BR getgrnam ().
131 .LP
132 The
133 .BR getgrnam_r ()
134 and
135 .BR getgrgid_r ()
136 functions return
137 zero on success.
138 In case of error, an error number is returned.
139 .SH ERRORS
140 .TP
141 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
142 The given
143 .I name
144 or
145 .I gid
146 was not found.
147 .TP
148 .B EINTR
149 A signal was caught.
150 .TP
151 .B EIO
152 I/O error.
153 .TP
154 .B EMFILE
155 The maximum number
156 .RB ( OPEN_MAX )
157 of files was open already in the calling process.
158 .TP
159 .B ENFILE
160 The maximum number of files was open already in the system.
161 .TP
162 .B ENOMEM
163 .\" not in POSIX
164 Insufficient memory to allocate group structure.
165 .\" to allocate the group structure, or to allocate buffers
166 .TP
167 .B ERANGE
168 Insufficient buffer space supplied.
169 .SH FILES
170 .TP
171 .I /etc/group
172 local group database file
173 .SH "CONFORMING TO"
174 SVr4, 4.3BSD, POSIX.1-2001
175 .SH NOTES
176 The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
177 It does not call "not found" an error, hence does not specify what value
178 .I errno
179 might have in this situation.
180 But that makes it impossible to recognize
181 errors.
182 One might argue that according to POSIX
183 .I errno
184 should be left unchanged if an entry is not found.
185 Experiments on various
186 Unix-like systems shows that lots of different values occur in this
187 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.
188 .\" more precisely:
189 .\" AIX 5.1 - gives ESRCH
190 .\" OSF1 4.0g - gives EWOULDBLOCK
191 .\" libc, glibc, Irix 6.5 - give ENOENT
192 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
193 .\" SunOS 5.8 - gives EBADF
194 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
195 .SH "SEE ALSO"
196 .BR endgrent (3),
197 .BR fgetgrent (3),
198 .BR getgrent (3),
199 .BR getpwnam (3),
200 .BR setgrent (3),
201 .BR group (5)