.\" Copyright 1993 Rickard E. Faith (faith@cs.unc.edu) .\" and Copyright (C) 2008, 2010, 2015, Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" Modified Thu Oct 31 12:04:29 1996 by Eric S. Raymond .\" Modified, 27 May 2004, Michael Kerrisk .\" Added notes on capability requirements .\" 2008-05-03, mtk, expanded and rewrote parts of DESCRIPTION and RETURN .\" VALUE, made style of page more consistent with man-pages style. .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya .\" all rights reserved. .\" Translated 1997-02-22, HANATAKA Shinya .\" Updated 2001-02-10, Yuichi SATO .\" Updated & Modified 2004-12-30, Yuichi SATO .\" Updated 2008-08-04, Akihiro MOTOKI , LDP v3.05 .\" Updated 2012-04-30, Akihiro MOTOKI .\" .TH GETGROUPS 2 2019\-03\-06 Linux "Linux Programmer's Manual" .SH 名前 getgroups, setgroups \- 補助グループ ID のリストを取得/設定する .SH 書式 \fB#include \fP .br \fB#include \fP .PP \fBint getgroups(int \fP\fIsize\fP\fB, gid_t \fP\fIlist\fP\fB[]);\fP \fB#include \fP .PP \fBint setgroups(size_t \fP\fIsize\fP\fB, const gid_t *\fP\fIlist\fP\fB);\fP .PP .RS -4 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .RE .PP \fBsetgroups\fP(): Since glibc 2.19: _DEFAULT_SOURCE Glibc 2.19 and earlier: _BSD_SOURCE .SH 説明 \fBgetgroups\fP() は呼び出し元プロセスの補助グループ (supplementary group) ID を \fIlist\fP に返す。 \fIsize\fP 引数には、 \fIlist\fP により参照されるバッファーに格納できる要素の最大数を設定すべきである。 呼び出し元プロセスが \fIsize\fP 個より多くの補助グループのメンバの場合には、エラーとなる。 .PP この関数を呼び出したプロセスの実効グループ ID が、 返されるリストに含まれるかどうかは規定されていない (したがって、アプリケーションは \fBgetegid\fP(2) を呼び出し、その結果の値を追加・削除すべきである)。 .PP \fIsize\fP が 0 ならば、 \fIlist\fP は修正されないが、そのプロセスの補助グループ ID の合計数が返される。 これを使うことで、それ以降の \fBgetgroups\fP() の呼び出しで必要となる動的割り当てバッファー \fIlist\fP のサイズを、呼び出し元が決定することができる。 .PP \fBsetgroups\fP() sets the supplementary group IDs for the calling process. Appropriate privileges are required (see the description of the \fBEPERM\fP error, below). The \fIsize\fP argument specifies the number of supplementary group IDs in the buffer pointed to by \fIlist\fP. A process can drop all of its supplementary groups with the call: .PP .in +4n .EX setgroups(0, NULL); .EE .in .SH 返り値 \fBgetgroups\fP() は、成功すると補助グループ ID の数を返す。 エラーの場合 \-1 を返し、 \fIerrno\fP を適切に設定する。 .PP \fBsetgroups\fP() は、成功すると 0 を返す。 エラーの場合 \-1 を返し、 \fIerrno\fP を適切に設定する。 .SH エラー .TP \fBEFAULT\fP \fIlist\fP が不正なアドレスである。 .PP \fBgetgroups\fP() は、上記に加えて以下のエラーで失敗する可能性がある。 .TP \fBEINVAL\fP \fIsize\fP が補助グループ ID の数より小さいが 0 でない。 .PP \fBsetgroups\fP() は、上記に加えて以下のエラーで失敗する可能性がある。 .TP \fBEINVAL\fP \fIsize\fP が \fBNGROUPS_MAX\fP より大きい (\fBNGROUPS_MAX\fP は Linux 2.6.4 より前では 32、Linux 2.6.4 以降では 65536)。 .TP \fBENOMEM\fP メモリー不足。 .TP \fBEPERM\fP The calling process has insufficient privilege (the caller does not have the \fBCAP_SETGID\fP capability in the user namespace in which it resides). .TP \fBEPERM\fP (Linux 3.19 以降) The use of \fBsetgroups\fP() is denied in this user namespace. See the description of \fI/proc/[pid]/setgroups\fP in \fBuser_namespaces\fP(7). .SH 準拠 \fBgetgroups\fP(): SVr4, 4.3BSD, POSIX.1\-2001, POSIX.1\-2008. .PP \fBsetgroups\fP(): SVr4, 4.3BSD. Since \fBsetgroups\fP() requires privilege, it is not covered by POSIX.1. .SH 注意 プロセスは、実効グループ ID に加え、最大 \fBNGROUPS_MAX\fP までの補助グループ ID を持つことができる。 定数 \fBNGROUPS_MAX\fP は \fI\fP で定義されている。 補助グループ ID の集合は親プロセスから継承され、 \fBexecve\fP(2) の前後で保持される。 .PP 補助グループ ID の最大数は、実行時に \fBsysconf\fP(3) を使って以下のようにして調べることができる: .PP .in +4n .EX long ngroups_max; ngroups_max = sysconf(_SC_NGROUPS_MAX); .EE .in .PP \fBgetgroups\fP() の返り値の最大値は、この値より大きくなることはない。 Linux 2.6.4 以降では、補助グループ ID の最大数も Linux 固有の読み込み専用のファイル \fI/proc/sys/kernel/ngroups_max\fP 経由で公開されている。 .PP .\" 元々の Linux の \fBgetgroups\fP() システムコールは 16 ビットのグループ ID だけ に対応していた。その後、Linux 2.4 で、32 ビットの ID に対応した \fBgetgroups\fP() が追加された。glibc の \fBgetgroups\fP のラッパー関数はカーネル バージョンによるこの違いを吸収している。 .SS "C ライブラリとカーネルの違い" At the kernel level, user IDs and group IDs are a per\-thread attribute. However, POSIX requires that all threads in a process share the same credentials. The NPTL threading implementation handles the POSIX requirements by providing wrapper functions for the various system calls that change process UIDs and GIDs. These wrapper functions (including the one for \fBsetgroups\fP()) employ a signal\-based technique to ensure that when one thread changes credentials, all of the other threads in the process also change their credentials. For details, see \fBnptl\fP(7). .SH 関連項目 \fBgetgid\fP(2), \fBsetgid\fP(2), \fBgetgrouplist\fP(3), \fBgroup_member\fP(3), \fBinitgroups\fP(3), \fBcapabilities\fP(7), \fBcredentials\fP(7) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は \%https://www.kernel.org/doc/man\-pages/ に書かれている。