OSDN Git Service

(split) Apply minor changes from v3.32 to v3.35 in the upstream.
[linuxjm/LDP_man-pages.git] / draft / man3 / getgrouplist.3
1 .\" Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" A few pieces remain from an earlier version written in
25 .\" 2002 by Walter Harms (walter.harms@informatik.uni-oldenburg.de)
26 .\"
27 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
28 .\"         all rights reserved.
29 .\" Translated 2004-08-07, Yuichi SATO <ysato444@yahoo.co.jp>
30 .\" Updated 2008-08-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
31 .\"
32 .TH GETGROUPLIST 3 2009-07-03 "GNU" "Linux Programmer's Manual"
33 .\"O .SH NAME
34 .SH Ì¾Á°
35 .\"O getgrouplist \- get list of groups to which a user belongs
36 getgrouplist \- ¥æ¡¼¥¶¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤ò¼èÆÀ¤¹¤ë
37 .\"O .SH SYNOPSIS
38 .SH ½ñ¼°
39 .B #include <grp.h>
40 .sp
41 .BI "int getgrouplist(const char *" user ", gid_t " group ,
42 .br
43 .BI "                 gid_t *" groups ", int *" ngroups );
44 .sp
45 .in -4n
46 .\"O Feature Test Macro Requirements for glibc (see
47 .\"O .BR feature_test_macros (7)):
48 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
49 .RB ( feature_test_macros (7)
50 »²¾È):
51 .in
52 .sp
53 .BR getgrouplist ():
54 _BSD_SOURCE
55 .\"O .SH DESCRIPTION
56 .SH ÀâÌÀ
57 .\"O The
58 .\"O .BR getgrouplist ()
59 .\"O function scans the group database (see
60 .\"O .BR group (5))
61 .\"O to obtain the list of groups that
62 .\"O .I user
63 .\"O belongs to.
64 .\"O Up to
65 .\"O .I *ngroups
66 .\"O of these groups are returned in the array
67 .\"O .IR groups .
68 .BR getgrouplist ()
69 ´Ø¿ô¤Ï¡¢¥°¥ë¡¼¥×¥Ç¡¼¥¿¥Ù¡¼¥¹
70 .RB ( group (5)
71 »²¾È) ¤òÄ´¤Ù¤Æ¡¢
72 .I user
73 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤ò¼èÆÀ¤¹¤ë¡£
74 ¸«¤Ä¤«¤Ã¤¿¥°¥ë¡¼¥×¤Î¤¦¤ÁºÇÂç
75 .I *ngroups
76 ¸Ä¤Î¥°¥ë¡¼¥×¤¬¡¢ÇÛÎó
77 .I groups
78 ¤Ë³ÊǼ¤µ¤ì¤ÆÊÖ¤µ¤ì¤ë¡£
79
80 .\"O If it was not among the groups defined for
81 .\"O .I user
82 .\"O in the group database, then
83 .\"O .I group
84 .\"O is included in the list of groups returned by
85 .\"O .BR getgrouplist ();
86 .\"O typically this argument is specified as the group ID from
87 .\"O the password record for
88 .\"O .IR user .
89 °ú¤­¿ô
90 .I group
91 ¤¬¥°¥ë¡¼¥×¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë
92 .I user
93 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤¬¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
94 .BR getgrouplist ()
95 ¤¬ÊÖ¤¹¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤Ë°ú¤­¿ô
96 .I group
97 ¤âÄɲ䵤ì¤ë¡£
98 Ä̾ï¤Ï¡¢¤³¤Î°ú¤­¿ô¤Ë¤Ï¥æ¡¼¥¶
99 .I user
100 ¤Î¥Ñ¥¹¥ï¡¼¥É¥ì¥³¡¼¥É¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¥°¥ë¡¼¥× ID ¤ò»ØÄꤹ¤ë¡£
101
102 .\"O The
103 .\"O .I ngroups
104 .\"O argument is a value-result argument:
105 .\"O on return it always contains the number of groups found for
106 .\"O .IR user ,
107 .\"O including
108 .\"O .IR group ;
109 .\"O this value may be greater than the number of groups stored in
110 .\"O .IR groups .
111 °ú¤­¿ô
112 .I ngroups
113 ¤Ï¡¢ÃÍÅϤ·¤È·ë²Ì¤ÎξÊý¤Ë»ÈÍѤµ¤ì¤ë°ú¤­¿ô (value-result argument) ¤Ç¤¢¤ê¡¢
114 ¥ê¥¿¡¼¥ó»þ¤Ë¤Ï¡¢¾ï¤Ë
115 .I group
116 ¤â´Þ¤á¤¿
117 .I user
118 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¿ô¤¬³ÊǼ¤µ¤ì¤ë¡£
119 ¤³¤ÎÃͤÏ
120 .I groups
121 ¤Ë³ÊǼ¤µ¤ì¤¿¥°¥ë¡¼¥×¿ô¤è¤êÂ礭¤¯¤Ê¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
122 .\"O .SH "RETURN VALUE"
123 .SH ÊÖ¤êÃÍ
124 .\"O If the number of groups of which
125 .\"O .I user
126 .\"O is a member is less than or equal to
127 .\"O .IR *ngroups ,
128 .\"O then the value
129 .\"O .I *ngroups
130 .\"O is returned.
131 .I user
132 ¤¬½ê°¤·¤Æ¤¤¤ë¥°¥ë¡¼¥×¿ô¤¬
133 .I *ngroups
134 °Ê²¼¤Î¾ì¹ç¡¢
135 .I *ngroups
136 ¤ÎÃͤ¬ÊÖ¤µ¤ì¤ë¡£
137
138 .\"O If the user is a member of more than
139 .\"O .I *ngroups
140 .\"O groups, then
141 .\"O .BR getgrouplist ()
142 .\"O returns \-1.
143 »ØÄꤵ¤ì¤¿¥æ¡¼¥¶¤¬
144 .I *ngroups
145 ¤è¤ê¿¤¯¤Î¥°¥ë¡¼¥×¤Ë½ê°¤·¤Æ¤¤¤ë¾ì¹ç¡¢
146 .BR getgrouplist ()
147 ¤Ï \-1 ¤òÊÖ¤¹¡£
148 .\"O In this case the value returned in
149 .\"O .IR *ngroups
150 .\"O can be used to resize the buffer passed to a further call
151 .\"O .BR getgrouplist ().
152 ¤³¤Î¾ì¹ç¡¢
153 .I *ngroups
154 ¤ÇÊÖ¤µ¤ì¤ëÃͤò»È¤Ã¤Æ¡¢¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤òÊѹ¹¤·¤Æ¤«¤é¡¢
155 .BR getgrouplist ()
156 ¤ò¤â¤¦°ìÅٸƤӽФ¹¤³¤È¤¬¤Ç¤­¤ë¡£
157 .\"O .SH "VERSIONS"
158 .SH ¥Ð¡¼¥¸¥ç¥ó
159 .\"O This function is present since glibc 2.2.4.
160 ¤³¤Î´Ø¿ô¤Ï glibc 2.2.4 ¤«¤é¸ºß¤¹¤ë¡£
161 .\"O .SH "CONFORMING TO"
162 .SH ½àµò
163 .\"O This function is nonstandard; it appears on most BSDs.
164 ¤³¤Î´Ø¿ô¤ÏÈóɸ½à¤Ç¤¢¤ë¡£¤Û¤È¤ó¤É¤Î BSD ¤Ë¸ºß¤¹¤ë¡£
165 .\"O .SH BUGS
166 .SH ¥Ð¥°
167 .\"O In glibc versions before 2.3.3,
168 .\"O the implementation of this function contains a buffer-overrun bug:
169 .\"O it returns the complete list of groups for
170 .\"O .IR user
171 .\"O in the array
172 .\"O .IR groups ,
173 .\"O even when the number of groups exceeds
174 .\"O .IR *ngroups .
175 ¥Ð¡¼¥¸¥ç¥ó 2.3.3 ¤è¤êÁ°¤Î glibc ¤Ç¤Ï¡¢
176 ¤³¤Î´Ø¿ô¤Î¼ÂÁõ¤Ë¤Ï¥Ð¥Ã¥Õ¥¡¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Î¥Ð¥°¤¬¤¢¤ê¡¢
177 .I user
178 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¿ô¤¬
179 .I *ngroups
180 ¤è¤ê¿¤¤¾ì¹ç¤Ç¤¢¤Ã¤Æ¤â¡¢
181 .I user
182 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤ÎÁ´¥ê¥¹¥È¤òÇÛÎó
183 .I groups
184 ¤Ë³ÊǼ¤·¤Æ¤·¤Þ¤¦¡£
185 .\"O .SH EXAMPLE
186 .SH Îã
187 .PP
188 .\"O The program below displays the group list for the user named in its
189 .\"O first command-line argument.
190 .\"O The second command-line argument specifies the
191 .\"O .I ngroups
192 .\"O value to be supplied to
193 .\"O .BR getgrouplist ().
194 .\"O The following shell session shows examples of the use of this program:
195 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢°ì¤ÄÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥æ¡¼¥¶
196 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤òɽ¼¨¤¹¤ë¡£
197 ÆóÈÖÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ë¤Ï¡¢
198 .BR getgrouplist ()
199 ¤ËÅϤ¹
200 .I ngroups
201 ¤ÎÃͤò»ØÄꤹ¤ë¡£
202 °Ê²¼¤Î¥·¥§¥ë¤Î¥»¥Ã¥·¥ç¥ó¤Ï¤³¤Î¥×¥í¥°¥é¥à¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
203 .in +4n
204 .nf
205
206 .RB "$" " ./a.out cecilia 0"
207 getgrouplist() returned \-1; ngroups = 3
208 .RB "$" " ./a.out cecilia 3"
209 ngroups = 3
210 16 (dialout)
211 33 (video)
212 100 (users)
213 .fi
214 .in
215 .\"O .SS Program source
216 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
217 \&
218 .nf
219 #include <stdio.h>
220 #include <stdlib.h>
221 #include <grp.h>
222 #include <pwd.h>
223
224 int
225 main(int argc, char *argv[])
226 {
227     int j, ngroups;
228     gid_t *groups;
229     struct passwd *pw;
230     struct group *gr;
231
232     if (argc != 3) {
233         fprintf(stderr, "Usage: %s <user> <ngroups>\\n", argv[0]);
234         exit(EXIT_FAILURE);
235     }
236
237     ngroups = atoi(argv[2]);
238
239     groups = malloc(ngroups * sizeof (gid_t));
240     if (groups == NULL) {
241         perror("malloc");
242         exit(EXIT_FAILURE);
243     }
244
245     /* Fetch passwd structure (contains first group ID for user) */
246
247     pw = getpwnam(argv[1]);
248     if (pw == NULL) {
249         perror("getpwnam");
250         exit(EXIT_SUCCESS);
251     }
252
253     /* Retrieve group list */
254
255     if (getgrouplist(argv[1], pw\->pw_gid, groups, &ngroups) == \-1) {
256         fprintf(stderr, "getgrouplist() returned \-1; ngroups = %d\\n",
257                 ngroups);
258         exit(EXIT_FAILURE);
259     }
260
261     /* Display list of retrieved groups, along with group names */
262
263     fprintf(stderr, "ngroups = %d\\n", ngroups);
264     for (j = 0; j < ngroups; j++) {
265         printf("%d", groups[j]);
266         gr = getgrgid(groups[j]);
267         if (gr != NULL)
268             printf(" (%s)", gr\->gr_name);
269         printf("\\n");
270     }
271
272     exit(EXIT_SUCCESS);
273 }
274 .fi
275 .\"O .SH "SEE ALSO"
276 .SH ´ØÏ¢¹àÌÜ
277 .BR getgroups (2),
278 .BR setgroups (2),
279 .BR getgrent (3),
280 .BR group (5),
281 .BR passwd (5)