getgroupsのヘルプ・マニュアル
日本語 英語
getgroups --help
man getgroups
GETGROUPS(2) Linux Programmer’s Manual GETGROUPS(2)
名前
getgroups, setgroups - 補助グループ ID のリストを取得/設定する
書式
#include
#include
int getgroups(int size, gid_t list[]);
#include
int setgroups(size_t size, const gid_t *list);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
setgroups(): _BSD_SOURCE
説明
getgroups() は呼び出し元プロセスの補助グループ (supplementary group) ID
を list に返す。 size 引き数には、 list により参照されるバッファに格 納
で きる要素の最大数を設定すべきである。呼び出し元プロセスが size 個より
多くの補助グループのメンバの場合には、エラーとなる。この関数を呼び出 し
た プロセスの実効グループ ID が、返されるリストに含まれるかどうかは規定
されていない (したがって、アプリケーションは getegid(2) を呼び出し、 そ
の結果の値を追加・削除すべきである)。
size が 0 ならば、 list は修正されないが、そのプロセスの補助グループ ID
の合計数が返される。これを使うことで、それ以降の getgroups() の呼び出し
で 必要となる動的割り当てバッファ list のサイズを、呼び出し元が決定する
ことができる。
setgroups() は、呼び出し元プロセスの補助グループ ID を設定する。適切 な
特権 (Linux では CAP_SETGID ケーパビリティ (capability)) が必要である。
size 引き数には、 list により参照されるバッファに格納された補助グループ
ID の数を指定する。
返り値
getgroups() は、成功すると補助グループ ID の数を返す。エラーの場合 -1
を返し、 errno を適切に設定する。
setgroups() は、成功すると 0 を返す。エラーの場合 -1 を返し、 errno を
適切に設定する。
エラー
EFAULT list が不正なアドレスである。
getgroups() は、上記に加えて以下のエラーで失敗する可能性がある。
EINVAL size が補助グループ ID の数より小さいが 0 でない。
setgroups() は、上記に加えて以下のエラーで失敗する可能性がある。
EINVAL size が NGROUPS_MAX より大きい (NGROUPS_MAX は Linux 2.6.4 より
前では 32、Linux 2.6.4 以降では 65536)。
ENOMEM メモリ不足。
EPERM 呼び出し元プロセスが十分な特権を持っていない。
準拠
SVr4, 4.3BSD. getgroups() 関数は POSIX.1-2001 に準拠してい る 。 set-
groups() は特権を必要とするため、POSIX.1-2001 に従っていない。
注意
プロセスは、実効グループ ID に加え、最大 NGROUPS_MAX までの補助グループ
ID を持つことができる。補助グループ ID の集合は親プロセスから継承され、
execve(2) の前後で保持される。
補 助グループ ID の最大数は sysconf(3) を使って以下のようにして調べるこ
とができる:
long ngroups_max;
ngroups_max = sysconf(_SC_NGROUPS_MAX);
getgroups() の返り値の最大値は、この値より 1 大きい値より大きくなること
はない。
関連項目
getgid(2), setgid(2), getgrouplist(3), initgroups(3), capabilities(7),
credentials(7)
Linux 2008-06-03 GETGROUPS(2)
GETGROUPS(2) Linux Programmer’s Manual GETGROUPS(2)
NAME
getgroups, setgroups - get/set list of supplementary group IDs
SYNOPSIS
#include
#include
int getgroups(int size, gid_t list[]);
#include
int setgroups(size_t size, const gid_t *list);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
setgroups(): _BSD_SOURCE
DESCRIPTION
getgroups() returns the supplementary group IDs of the calling process
in list. The argument size should be set to the maximum number of
items that can be stored in the buffer pointed to by list. If the
calling process is a member of more than size supplementary groups,
then an error results. It is unspecified whether the effective group
ID of the calling process is included in the returned list. (Thus, an
application should also call getegid(2) and add or remove the resulting
value.)
If size is zero, list is not modified, but the total number of supple-
mentary group IDs for the process is returned. This allows the caller
to determine the size of a dynamically allocated list to be used in a
further call to getgroups().
setgroups() sets the supplementary group IDs for the calling process.
Appropriate privileges (Linux: the CAP_SETGID capability) are required.
The size argument specifies the number of supplementary group IDs in
the buffer pointed to by list.
RETURN VALUE
On success, getgroups() returns the number of supplementary group IDs.
On error, -1 is returned, and errno is set appropriately.
On success, setgroups() returns 0. On error, -1 is returned, and errno
is set appropriately.
ERRORS
EFAULT list has an invalid address.
getgroups() can additionally fail with the following error:
EINVAL size is less than the number of supplementary group IDs, but is
not zero.
setgroups() can additionally fail with the following errors:
EINVAL size is greater than NGROUPS_MAX (32 before Linux 2.6.4; 65536
since Linux 2.6.4).
ENOMEM Out of memory.
EPERM The calling process has insufficient privilege.
CONFORMING TO
SVr4, 4.3BSD. The getgroups() function is in POSIX.1-2001. Since set-
groups() requires privilege, it is not covered by POSIX.1-2001.
NOTES
A process can have up to NGROUPS_MAX supplementary group IDs in addi-
tion to the effective group ID. The set of supplementary group IDs is
inherited from the parent process, and preserved across an execve(2).
The maximum number of supplementary group IDs can be found using
sysconf(3):
long ngroups_max;
ngroups_max = sysconf(_SC_NGROUPS_MAX);
The maximum return value of getgroups() cannot be larger than one more
than this value.
SEE ALSO
getgid(2), setgid(2), getgrouplist(3), initgroups(3), capabilities(7),
credentials(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-06-03 GETGROUPS(2)