OSDN Git Service

6ec9f39b46be6483a650ffe531db15779a4437e8
[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)