OSDN Git Service

(split) LDP: Update original to LDP v3.38.
[linuxjm/LDP_man-pages.git] / original / 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 2010-10-21 "" "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 *" grp ,
44 .br
45 .BI "          char *" buf ", size_t " buflen ", struct group **" result );
46 .sp
47 .BI "int getgrgid_r(gid_t " gid ", struct group *" grp ,
48 .br
49 .BI "          char *" buf ", size_t " buflen ", struct group **" result );
50 .fi
51 .sp
52 .in -4n
53 Feature Test Macro Requirements for glibc (see
54 .BR feature_test_macros (7)):
55 .ad l
56 .in
57 .sp
58 .BR getgrnam_r (),
59 .BR getgrgid_r ():
60 .RS 4
61 _POSIX_C_SOURCE\ >=\ 1 || _XOPEN_SOURCE || _BSD_SOURCE ||
62 _SVID_SOURCE || _POSIX_SOURCE
63 .RE
64 .ad b
65 .SH DESCRIPTION
66 The
67 .BR getgrnam ()
68 function returns a pointer to a structure containing
69 the broken-out fields of the record in the group database
70 (e.g., the local group file
71 .IR /etc/group ,
72 NIS, and LDAP)
73 that matches the group name
74 .IR name .
75 .PP
76 The
77 .BR getgrgid ()
78 function returns a pointer to a structure containing
79 the broken-out fields of the record in the group database
80 that matches the group ID
81 .IR gid .
82 .PP
83 The \fIgroup\fP structure is defined in \fI<grp.h>\fP as follows:
84 .sp
85 .in +4n
86 .nf
87 struct group {
88     char   *gr_name;       /* group name */
89     char   *gr_passwd;     /* group password */
90     gid_t   gr_gid;        /* group ID */
91     char  **gr_mem;        /* group members */
92 };
93 .fi
94 .in
95 .PP
96 For more information about the fields of this structure, see
97 .BR group (5).
98 .PP
99 The
100 .BR getgrnam_r ()
101 and
102 .BR getgrgid_r ()
103 functions obtain the same information as
104 .BR getgrnam ()
105 and
106 .BR getgrgid (),
107 but store the retrieved
108 .I group
109 structure
110 in the space pointed to by
111 .IR grp .
112 The string fields pointed to by the members of the
113 .I group
114 structure are stored in the buffer
115 .I buf
116 of size
117 .IR buflen .
118 A pointer to the result (in case of success) or NULL (in case no entry
119 was found or an error occurred) is stored in
120 .IR *result .
121 .PP
122 The maximum needed size for
123 .I buf
124 can be found using
125 .BR sysconf (3)
126 with the argument
127 .BR _SC_GETGR_R_SIZE_MAX .
128 .SH "RETURN VALUE"
129 The
130 .BR getgrnam ()
131 and
132 .BR getgrgid ()
133 functions return a pointer to a
134 .I group
135 structure, or NULL if the matching entry
136 is not found or an error occurs.
137 If an error occurs,
138 .I errno
139 is set appropriately.
140 If one wants to check
141 .I errno
142 after the call, it should be set to zero before the call.
143 .LP
144 The return value may point to a static area, and may be overwritten
145 by subsequent calls to
146 .BR getgrent (3),
147 .BR getgrgid (),
148 or
149 .BR getgrnam ().
150 (Do not pass the returned pointer to
151 .BR free (3).)
152 .LP
153 On success,
154 .BR getgrnam_r ()
155 and
156 .BR getgrgid_r ()
157 return zero, and set
158 .IR *result
159 to
160 .IR grp .
161 If no matching group record was found,
162 these functions return 0 and store NULL in
163 .IR *result .
164 In case of error, an error number is returned, and NULL is stored in
165 .IR *result .
166 .SH ERRORS
167 .TP
168 .BR 0 " or " ENOENT " or " ESRCH " or " EBADF " or " EPERM " or ... "
169 The given
170 .I name
171 or
172 .I gid
173 was not found.
174 .TP
175 .B EINTR
176 A signal was caught.
177 .TP
178 .B EIO
179 I/O error.
180 .TP
181 .B EMFILE
182 The maximum number
183 .RB ( OPEN_MAX )
184 of files was open already in the calling process.
185 .TP
186 .B ENFILE
187 The maximum number of files was open already in the system.
188 .TP
189 .B ENOMEM
190 .\" not in POSIX
191 Insufficient memory to allocate
192 .I group
193 structure.
194 .\" to allocate the group structure, or to allocate buffers
195 .TP
196 .B ERANGE
197 Insufficient buffer space supplied.
198 .SH FILES
199 .TP
200 .I /etc/group
201 local group database file
202 .SH "CONFORMING TO"
203 SVr4, 4.3BSD, POSIX.1-2001.
204 .SH NOTES
205 The formulation given above under "RETURN VALUE" is from POSIX.1-2001.
206 It does not call "not found" an error, hence does not specify what value
207 .I errno
208 might have in this situation.
209 But that makes it impossible to recognize
210 errors.
211 One might argue that according to POSIX
212 .I errno
213 should be left unchanged if an entry is not found.
214 Experiments on various
215 UNIX-like systems shows that lots of different values occur in this
216 situation: 0, ENOENT, EBADF, ESRCH, EWOULDBLOCK, EPERM and probably others.
217 .\" more precisely:
218 .\" AIX 5.1 - gives ESRCH
219 .\" OSF1 4.0g - gives EWOULDBLOCK
220 .\" libc, glibc up to version 2.6, Irix 6.5 - give ENOENT
221 .\" glibc since version 2.7 - give 0
222 .\" FreeBSD 4.8, OpenBSD 3.2, NetBSD 1.6 - give EPERM
223 .\" SunOS 5.8 - gives EBADF
224 .\" Tru64 5.1b, HP-UX-11i, SunOS 5.7 - give 0
225 .SH "SEE ALSO"
226 .BR endgrent (3),
227 .BR fgetgrent (3),
228 .BR getgrent (3),
229 .BR getpwnam (3),
230 .BR setgrent (3),
231 .BR group (5)