.\" Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk .\" .\" .\" A few pieces remain from an earlier version written in .\" 2002 by Walter Harms (walter.harms@informatik.uni-oldenburg.de) .\" .\" %%%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 .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2004 Yuichi SATO .\" all rights reserved. .\" Translated 2004-08-07, Yuichi SATO .\" Updated 2008-08-11, Akihiro MOTOKI , LDP v3.05 .\" .TH GETGROUPLIST 3 2014\-08\-19 GNU "Linux Programmer's Manual" .SH 名前 getgrouplist \- ユーザーが所属するグループのリストを取得する .SH 書式 \fB#include \fP .sp \fBint getgrouplist(const char *\fP\fIuser\fP\fB, gid_t \fP\fIgroup\fP\fB,\fP .br \fB gid_t *\fP\fIgroups\fP\fB, int *\fP\fIngroups\fP\fB);\fP .sp .in -4n glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照): .in .sp \fBgetgrouplist\fP(): _BSD_SOURCE .SH 説明 \fBgetgrouplist\fP() 関数は、グループデータベース (\fBgroup\fP(5) 参照) を調べて、 \fIuser\fP が所属するグループのリストを取得する。 見つかったグループのうち最大 \fI*ngroups\fP 個のグループが、配列 \fIgroups\fP に格納されて返される。 引き数 \fIgroup\fP がグループデータベースに \fIuser\fP が所属するグループがなかった場合、 \fBgetgrouplist\fP() が返すグループのリストに引き数 \fIgroup\fP も追加される。 通常は、この引き数にはユーザー \fIuser\fP のパスワードレコードに書かれているグループ ID を指定する。 引き数 \fIngroups\fP は、値渡しと結果の両方に使用される引き数 (value\-result argument) であり、 リターン時には、常に \fIgroup\fP も含めた \fIuser\fP が所属するグループ数が格納される。 この値は \fIgroups\fP に格納されたグループ数より大きくなる可能性がある。 .SH 返り値 \fIuser\fP が所属しているグループ数が \fI*ngroups\fP 以下の場合、 \fI*ngroups\fP の値が返される。 指定されたユーザーが \fI*ngroups\fP より多くのグループに所属している場合、 \fBgetgrouplist\fP() は \-1 を返す。 この場合、 \fI*ngroups\fP で返される値を使って、バッファーのサイズを変更してから、 \fBgetgrouplist\fP() をもう一度呼び出すことができる。 .SH バージョン この関数は glibc 2.2.4 から存在する。 .SH 準拠 この関数は非標準である。ほとんどの BSD に存在する。 .SH バグ バージョン 2.3.3 より前の glibc では、 この関数の実装にはバッファーオーバーフローのバグがあり、 \fIuser\fP が所属するグループ数が \fI*ngroups\fP より多い場合であっても、 \fIuser\fP が所属するグループの全リストを配列 \fIgroups\fP に格納してしまう。 .SH 例 .PP 以下のプログラムは、一つ目のコマンドライン引き数で指定された名前のユーザー が所属するグループのリストを表示する。 二番目のコマンドライン引き数には、 \fBgetgrouplist\fP() に渡す \fIngroups\fP の値を指定する。 以下のシェルのセッションはこのプログラムの使用例を示したものである。 .in +4n .nf $\fB ./a.out cecilia 0\fP getgrouplist() returned \-1; ngroups = 3 $\fB ./a.out cecilia 3\fP ngroups = 3 16 (dialout) 33 (video) 100 (users) .fi .in .SS プログラムのソース \& .nf #include #include #include #include int main(int argc, char *argv[]) { int j, ngroups; gid_t *groups; struct passwd *pw; struct group *gr; if (argc != 3) { fprintf(stderr, "Usage: %s \en", argv[0]); exit(EXIT_FAILURE); } ngroups = atoi(argv[2]); groups = malloc(ngroups * sizeof (gid_t)); if (groups == NULL) { perror("malloc"); exit(EXIT_FAILURE); } /* Fetch passwd structure (contains first group ID for user) */ pw = getpwnam(argv[1]); if (pw == NULL) { perror("getpwnam"); exit(EXIT_SUCCESS); } /* Retrieve group list */ if (getgrouplist(argv[1], pw\->pw_gid, groups, &ngroups) == \-1) { fprintf(stderr, "getgrouplist() returned \-1; ngroups = %d\en", ngroups); exit(EXIT_FAILURE); } /* Display list of retrieved groups, along with group names */ fprintf(stderr, "ngroups = %d\en", ngroups); for (j = 0; j < ngroups; j++) { printf("%d", groups[j]); gr = getgrgid(groups[j]); if (gr != NULL) printf(" (%s)", gr\->gr_name); printf("\en"); } exit(EXIT_SUCCESS); } .fi .SH 関連項目 \fBgetgroups\fP(2), \fBsetgroups\fP(2), \fBgetgrent\fP(3), \fBgroup_member\fP(3), \fBgroup\fP(5), \fBpasswd\fP(5) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。