.\" Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk .\" .\" .\" 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. .\" .\" A few pieces remain from an earlier version written in .\" 2002 by Walter Harms (walter.harms@informatik.uni-oldenburg.de) .\" .\" 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 2009-07-03 "GNU" "Linux Programmer's Manual" .\"O .SH NAME .SH 名前 .\"O getgrouplist \- get list of groups to which a user belongs getgrouplist \- ユーザが所属するグループのリストを取得する .\"O .SH SYNOPSIS .SH 書式 .B #include .sp .BI "int getgrouplist(const char *" user ", gid_t " group , .br .BI " gid_t *" groups ", int *" ngroups ); .sp .in -4n .\"O Feature Test Macro Requirements for glibc (see .\"O .BR feature_test_macros (7)): glibc 向けの機能検査マクロの要件 .RB ( feature_test_macros (7) 参照): .in .sp .BR getgrouplist (): _BSD_SOURCE .\"O .SH DESCRIPTION .SH 説明 .\"O The .\"O .BR getgrouplist () .\"O function scans the group database (see .\"O .BR group (5)) .\"O to obtain the list of groups that .\"O .I user .\"O belongs to. .\"O Up to .\"O .I *ngroups .\"O of these groups are returned in the array .\"O .IR groups . .BR getgrouplist () 関数は、グループデータベース .RB ( group (5) 参照) を調べて、 .I user が所属するグループのリストを取得する。 見つかったグループのうち最大 .I *ngroups 個のグループが、配列 .I groups に格納されて返される。 .\"O If it was not among the groups defined for .\"O .I user .\"O in the group database, then .\"O .I group .\"O is included in the list of groups returned by .\"O .BR getgrouplist (); .\"O typically this argument is specified as the group ID from .\"O the password record for .\"O .IR user . 引き数 .I group がグループデータベースに .I user が所属するグループがなかった場合、 .BR getgrouplist () が返すグループのリストに引き数 .I group も追加される。 通常は、この引き数にはユーザ .I user のパスワードレコードに書かれているグループ ID を指定する。 .\"O The .\"O .I ngroups .\"O argument is a value-result argument: .\"O on return it always contains the number of groups found for .\"O .IR user , .\"O including .\"O .IR group ; .\"O this value may be greater than the number of groups stored in .\"O .IR groups . 引き数 .I ngroups は、値渡しと結果の両方に使用される引き数 (value-result argument) であり、 リターン時には、常に .I group も含めた .I user が所属するグループ数が格納される。 この値は .I groups に格納されたグループ数より大きくなる可能性がある。 .\"O .SH "RETURN VALUE" .SH 返り値 .\"O If the number of groups of which .\"O .I user .\"O is a member is less than or equal to .\"O .IR *ngroups , .\"O then the value .\"O .I *ngroups .\"O is returned. .I user が所属しているグループ数が .I *ngroups 以下の場合、 .I *ngroups の値が返される。 .\"O If the user is a member of more than .\"O .I *ngroups .\"O groups, then .\"O .BR getgrouplist () .\"O returns \-1. 指定されたユーザが .I *ngroups より多くのグループに所属している場合、 .BR getgrouplist () は \-1 を返す。 .\"O In this case the value returned in .\"O .IR *ngroups .\"O can be used to resize the buffer passed to a further call .\"O .BR getgrouplist (). この場合、 .I *ngroups で返される値を使って、バッファのサイズを変更してから、 .BR getgrouplist () をもう一度呼び出すことができる。 .\"O .SH "VERSIONS" .SH バージョン .\"O This function is present since glibc 2.2.4. この関数は glibc 2.2.4 から存在する。 .\"O .SH "CONFORMING TO" .SH 準拠 .\"O This function is nonstandard; it appears on most BSDs. この関数は非標準である。ほとんどの BSD に存在する。 .\"O .SH BUGS .SH バグ .\"O In glibc versions before 2.3.3, .\"O the implementation of this function contains a buffer-overrun bug: .\"O it returns the complete list of groups for .\"O .IR user .\"O in the array .\"O .IR groups , .\"O even when the number of groups exceeds .\"O .IR *ngroups . バージョン 2.3.3 より前の glibc では、 この関数の実装にはバッファオーバーフローのバグがあり、 .I user が所属するグループ数が .I *ngroups より多い場合であっても、 .I user が所属するグループの全リストを配列 .I groups に格納してしまう。 .\"O .SH EXAMPLE .SH 例 .PP .\"O The program below displays the group list for the user named in its .\"O first command-line argument. .\"O The second command-line argument specifies the .\"O .I ngroups .\"O value to be supplied to .\"O .BR getgrouplist (). .\"O The following shell session shows examples of the use of this program: 以下のプログラムは、一つ目のコマンドライン引き数で指定された名前のユーザ が所属するグループのリストを表示する。 二番目のコマンドライン引き数には、 .BR getgrouplist () に渡す .I ngroups の値を指定する。 以下のシェルのセッションはこのプログラムの使用例を示したものである。 .in +4n .nf .RB "$" " ./a.out cecilia 0" getgrouplist() returned -1; ngroups = 3 .RB "$" " ./a.out cecilia 3" ngroups = 3 16 (dialout) 33 (video) 100 (users) .fi .in .\"O .SS Program source .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 \\n", 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\\n", ngroups); exit(EXIT_FAILURE); } /* Display list of retrieved groups, along with group names */ fprintf(stderr, "ngroups = %d\\n", ngroups); for (j = 0; j < ngroups; j++) { printf("%d", groups[j]); gr = getgrgid(groups[j]); if (gr != NULL) printf(" (%s)", gr\->gr_name); printf("\\n"); } exit(EXIT_SUCCESS); } .fi .\"O .SH "SEE ALSO" .SH 関連項目 .BR getgroups (2), .BR setgroups (2), .BR getgrent (3), .BR group (5), .BR passwd (5)