1 .\" Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" A few pieces remain from an earlier version written in
25 .\" 2002 by Walter Harms (walter.harms@informatik.uni-oldenburg.de)
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
32 .TH GETGROUPLIST 3 2009-07-03 "GNU" "Linux Programmer's Manual"
35 .\"O getgrouplist \- get list of groups to which a user belongs
36 getgrouplist \- ¥æ¡¼¥¶¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤ò¼èÆÀ¤¹¤ë
41 .BI "int getgrouplist(const char *" user ", gid_t " group ,
43 .BI " gid_t *" groups ", int *" ngroups );
46 .\"O Feature Test Macro Requirements for glibc (see
47 .\"O .BR feature_test_macros (7)):
48 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
49 .RB ( feature_test_macros (7)
58 .\"O .BR getgrouplist ()
59 .\"O function scans the group database (see
61 .\"O to obtain the list of groups that
66 .\"O of these groups are returned in the array
69 ´Ø¿ô¤Ï¡¢¥°¥ë¡¼¥×¥Ç¡¼¥¿¥Ù¡¼¥¹
73 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤ò¼èÆÀ¤¹¤ë¡£
74 ¸«¤Ä¤«¤Ã¤¿¥°¥ë¡¼¥×¤Î¤¦¤ÁºÇÂç
78 ¤Ë³ÊǼ¤µ¤ì¤ÆÊÖ¤µ¤ì¤ë¡£
80 .\"O If it was not among the groups defined for
82 .\"O in the group database, then
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
91 ¤¬¥°¥ë¡¼¥×¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë
93 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤¬¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
95 ¤¬ÊÖ¤¹¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤Ë°ú¤¿ô
98 Ä̾ï¤Ï¡¢¤³¤Î°ú¤¿ô¤Ë¤Ï¥æ¡¼¥¶
100 ¤Î¥Ñ¥¹¥ï¡¼¥É¥ì¥³¡¼¥É¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¥°¥ë¡¼¥× ID ¤ò»ØÄꤹ¤ë¡£
104 .\"O argument is a value-result argument:
105 .\"O on return it always contains the number of groups found for
109 .\"O this value may be greater than the number of groups stored in
113 ¤Ï¡¢ÃÍÅϤ·¤È·ë²Ì¤ÎξÊý¤Ë»ÈÍѤµ¤ì¤ë°ú¤¿ô (value-result argument) ¤Ç¤¢¤ê¡¢
118 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¿ô¤¬³ÊǼ¤µ¤ì¤ë¡£
121 ¤Ë³ÊǼ¤µ¤ì¤¿¥°¥ë¡¼¥×¿ô¤è¤êÂ礤¯¤Ê¤ë²ÄǽÀ¤¬¤¢¤ë¡£
122 .\"O .SH "RETURN VALUE"
124 .\"O If the number of groups of which
126 .\"O is a member is less than or equal to
132 ¤¬½ê°¤·¤Æ¤¤¤ë¥°¥ë¡¼¥×¿ô¤¬
138 .\"O If the user is a member of more than
141 .\"O .BR getgrouplist ()
145 ¤è¤ê¿¤¯¤Î¥°¥ë¡¼¥×¤Ë½ê°¤·¤Æ¤¤¤ë¾ì¹ç¡¢
148 .\"O In this case the value returned in
150 .\"O can be used to resize the buffer passed to a further call
151 .\"O .BR getgrouplist ().
154 ¤ÇÊÖ¤µ¤ì¤ëÃͤò»È¤Ã¤Æ¡¢¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤òÊѹ¹¤·¤Æ¤«¤é¡¢
156 ¤ò¤â¤¦°ìÅٸƤӽФ¹¤³¤È¤¬¤Ç¤¤ë¡£
159 .\"O This function is present since glibc 2.2.4.
160 ¤³¤Î´Ø¿ô¤Ï glibc 2.2.4 ¤«¤é¸ºß¤¹¤ë¡£
161 .\"O .SH "CONFORMING TO"
163 .\"O This function is nonstandard; it appears on most BSDs.
164 ¤³¤Î´Ø¿ô¤ÏÈóɸ½à¤Ç¤¢¤ë¡£¤Û¤È¤ó¤É¤Î BSD ¤Ë¸ºß¤¹¤ë¡£
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
173 .\"O even when the number of groups exceeds
175 ¥Ð¡¼¥¸¥ç¥ó 2.3.3 ¤è¤êÁ°¤Î glibc ¤Ç¤Ï¡¢
176 ¤³¤Î´Ø¿ô¤Î¼ÂÁõ¤Ë¤Ï¥Ð¥Ã¥Õ¥¡¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Î¥Ð¥°¤¬¤¢¤ê¡¢
178 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¿ô¤¬
180 ¤è¤ê¿¤¤¾ì¹ç¤Ç¤¢¤Ã¤Æ¤â¡¢
182 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤ÎÁ´¥ê¥¹¥È¤òÇÛÎó
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
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 ÆóÈÖÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤¿ô¤Ë¤Ï¡¢
202 °Ê²¼¤Î¥·¥§¥ë¤Î¥»¥Ã¥·¥ç¥ó¤Ï¤³¤Î¥×¥í¥°¥é¥à¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
206 .RB "$" " ./a.out cecilia 0"
207 getgrouplist() returned \-1; ngroups = 3
208 .RB "$" " ./a.out cecilia 3"
215 .\"O .SS Program source
216 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
225 main(int argc, char *argv[])
233 fprintf(stderr, "Usage: %s <user> <ngroups>\\n", argv[0]);
237 ngroups = atoi(argv[2]);
239 groups = malloc(ngroups * sizeof (gid_t));
240 if (groups == NULL) {
245 /* Fetch passwd structure (contains first group ID for user) */
247 pw = getpwnam(argv[1]);
253 /* Retrieve group list */
255 if (getgrouplist(argv[1], pw\->pw_gid, groups, &ngroups) == \-1) {
256 fprintf(stderr, "getgrouplist() returned \-1; ngroups = %d\\n",
261 /* Display list of retrieved groups, along with group names */
263 fprintf(stderr, "ngroups = %d\\n", ngroups);
264 for (j = 0; j < ngroups; j++) {
265 printf("%d", groups[j]);
266 gr = getgrgid(groups[j]);
268 printf(" (%s)", gr\->gr_name);