OSDN Git Service

(split) Convert release and draft pages to UTF-8.
[linuxjm/LDP_man-pages.git] / release / man2 / getgroups.2
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu)
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" Modified Thu Oct 31 12:04:29 1996 by Eric S. Raymond <esr@thyrsus.com>
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\"     Added notes on capability requirements
28 .\" 2008-05-03, mtk, expanded and rewrote parts of DESCRIPTION and RETURN
29 .\"     VALUE, made style of page more consistent with man-pages style.
30 .\"
31 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
32 .\"         all rights reserved.
33 .\" Translated 1997-02-22, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
34 .\" Updated 2001-02-10, Yuichi SATO <sato@complex.eng.hokudai.ac.jp>
35 .\" Updated & Modified 2004-12-30, Yuichi SATO <ysato444@yahoo.co.jp>
36 .\" Updated 2008-08-04, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
37 .\"
38 .\"WORD:        group                   グループ
39 .\"WORD:        access                  アクセス
40 .\"WORD:        process                 プロセス
41 .\"WORD:        super user              スーパー・ユーザー
42 .\"WORD:        supplementary group     補助グループ
43 .\"
44 .TH GETGROUPS 2 2008-06-03 "Linux" "Linux Programmer's Manual"
45 .SH 名前
46 getgroups, setgroups \- 補助グループ ID のリストを取得/設定する
47 .SH 書式
48 .B #include <sys/types.h>
49 .br
50 .B #include <unistd.h>
51 .sp
52 .BI "int getgroups(int " size ", gid_t " list []);
53 .sp
54 .B #include <grp.h>
55 .sp
56 .BI "int setgroups(size_t " size ", const gid_t *" list );
57 .sp
58 .in -4n
59 glibc 向けの機能検査マクロの要件
60 .RB ( feature_test_macros (7)
61 参照):
62 .in
63 .sp
64 .BR setgroups ():
65 _BSD_SOURCE
66 .SH 説明
67 .PP
68 .BR getgroups ()
69 は呼び出し元プロセスの補助グループ (supplementary group) ID を
70 .I list
71 に返す。
72 .I size
73 引き数には、
74 .I list
75 により参照されるバッファに格納できる要素の最大数を設定すべきである。
76 呼び出し元プロセスが
77 .I size
78 個より多くの補助グループのメンバの場合には、エラーとなる。
79 この関数を呼び出したプロセスの実効グループ ID が、
80 返されるリストに含まれるかどうかは規定されていない
81 (したがって、アプリケーションは
82 .BR getegid (2)
83 を呼び出し、その結果の値を追加・削除すべきである)。
84
85 .I size
86 が 0 ならば、
87 .I list
88 は修正されないが、そのプロセスの補助グループ ID の合計数が返される。
89 これを使うことで、それ以降の
90 .BR getgroups ()
91 の呼び出しで必要となる動的割り当てバッファ
92 .I list
93 のサイズを、呼び出し元が決定することができる。
94 .PP
95 .BR setgroups ()
96 は、呼び出し元プロセスの補助グループ ID を設定する。
97 適切な特権 (Linux では
98 .B CAP_SETGID
99 ケーパビリティ (capability)) が必要である。
100 .I size
101 引き数には、
102 .I list
103 により参照されるバッファに格納された補助グループ ID の数を指定する。
104 .SH 返り値
105 .BR getgroups ()
106 は、成功すると補助グループ ID の数を返す。
107 エラーの場合 \-1 を返し、
108 .I errno
109 を適切に設定する。
110
111 .BR setgroups ()
112 は、成功すると 0 を返す。
113 エラーの場合 \-1 を返し、
114 .I errno
115 を適切に設定する。
116 .SH エラー
117 .TP
118 .B EFAULT
119 .I list
120 が不正なアドレスである。
121 .PP
122 .BR getgroups ()
123 は、上記に加えて以下のエラーで失敗する可能性がある。
124 .TP
125 .B EINVAL
126 .I size
127 が補助グループ ID の数より小さいが 0 でない。
128 .PP
129 .BR setgroups ()
130 は、上記に加えて以下のエラーで失敗する可能性がある。
131 .TP
132 .B EINVAL
133 .I size
134
135 .B NGROUPS_MAX
136 より大きい
137 .RB ( NGROUPS_MAX
138 は Linux 2.6.4 より前では 32、Linux 2.6.4 以降では 65536)。
139 .TP
140 .B ENOMEM
141 メモリ不足。
142 .TP
143 .B EPERM
144 呼び出し元プロセスが十分な特権を持っていない。
145 .SH 準拠
146 SVr4, 4.3BSD.
147 .BR getgroups ()
148 関数は POSIX.1-2001 に準拠している。
149 .BR setgroups ()
150 は特権を必要とするため、POSIX.1-2001 に従っていない。
151 .SH 注意
152 プロセスは、実効グループ ID に加え、最大
153 .B NGROUPS_MAX
154 までの補助グループ ID を持つことができる。
155 補助グループ ID の集合は親プロセスから継承され、
156 .BR execve (2)
157 の前後で保持される。
158
159 補助グループ ID の最大数は
160 .BR sysconf (3)
161 を使って以下のようにして調べることができる:
162 .nf
163
164     long ngroups_max;
165     ngroups_max = sysconf(_SC_NGROUPS_MAX);
166
167 .fi
168 .BR getgroups ()
169 の返り値の最大値は、この値より 1 大きい値より大きくなることはない。
170 .SH 関連項目
171 .BR getgid (2),
172 .BR setgid (2),
173 .BR getgrouplist (3),
174 .BR initgroups (3),
175 .BR capabilities (7),
176 .BR credentials (7)