OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / release / man3 / getgrouplist.3
1 .\" Copyright (C) 2008, Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" A few pieces remain from an earlier version written in
25 .\" 2002 by Walter Harms (walter.harms@informatik.uni-oldenburg.de)
26 .\"
27 .\" Japanese Version Copyright (c) 2004 Yuichi SATO
28 .\"         all rights reserved.
29 .\" Translated 2004-08-07, Yuichi SATO <ysato444@yahoo.co.jp>
30 .\" Updated 2008-08-11, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
31 .\"
32 .TH GETGROUPLIST 3 2009-07-03 "GNU" "Linux Programmer's Manual"
33 .SH Ì¾Á°
34 getgrouplist \- ¥æ¡¼¥¶¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤ò¼èÆÀ¤¹¤ë
35 .SH ½ñ¼°
36 .B #include <grp.h>
37 .sp
38 .BI "int getgrouplist(const char *" user ", gid_t " group ,
39 .br
40 .BI "                 gid_t *" groups ", int *" ngroups );
41 .sp
42 .in -4n
43 glibc ¸þ¤±¤Îµ¡Ç½¸¡ºº¥Þ¥¯¥í¤ÎÍ×·ï
44 .RB ( feature_test_macros (7)
45 »²¾È):
46 .in
47 .sp
48 .BR getgrouplist ():
49 _BSD_SOURCE
50 .SH ÀâÌÀ
51 .BR getgrouplist ()
52 ´Ø¿ô¤Ï¡¢¥°¥ë¡¼¥×¥Ç¡¼¥¿¥Ù¡¼¥¹
53 .RB ( group (5)
54 »²¾È) ¤òÄ´¤Ù¤Æ¡¢
55 .I user
56 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤ò¼èÆÀ¤¹¤ë¡£
57 ¸«¤Ä¤«¤Ã¤¿¥°¥ë¡¼¥×¤Î¤¦¤ÁºÇÂç
58 .I *ngroups
59 ¸Ä¤Î¥°¥ë¡¼¥×¤¬¡¢ÇÛÎó
60 .I groups
61 ¤Ë³ÊǼ¤µ¤ì¤ÆÊÖ¤µ¤ì¤ë¡£
62
63 °ú¤­¿ô
64 .I group
65 ¤¬¥°¥ë¡¼¥×¥Ç¡¼¥¿¥Ù¡¼¥¹¤Ë
66 .I user
67 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤¬¤Ê¤«¤Ã¤¿¾ì¹ç¡¢
68 .BR getgrouplist ()
69 ¤¬ÊÖ¤¹¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤Ë°ú¤­¿ô
70 .I group
71 ¤âÄɲ䵤ì¤ë¡£
72 Ä̾ï¤Ï¡¢¤³¤Î°ú¤­¿ô¤Ë¤Ï¥æ¡¼¥¶
73 .I user
74 ¤Î¥Ñ¥¹¥ï¡¼¥É¥ì¥³¡¼¥É¤Ë½ñ¤«¤ì¤Æ¤¤¤ë¥°¥ë¡¼¥× ID ¤ò»ØÄꤹ¤ë¡£
75
76 °ú¤­¿ô
77 .I ngroups
78 ¤Ï¡¢ÃÍÅϤ·¤È·ë²Ì¤ÎξÊý¤Ë»ÈÍѤµ¤ì¤ë°ú¤­¿ô (value-result argument) ¤Ç¤¢¤ê¡¢
79 ¥ê¥¿¡¼¥ó»þ¤Ë¤Ï¡¢¾ï¤Ë
80 .I group
81 ¤â´Þ¤á¤¿
82 .I user
83 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¿ô¤¬³ÊǼ¤µ¤ì¤ë¡£
84 ¤³¤ÎÃͤÏ
85 .I groups
86 ¤Ë³ÊǼ¤µ¤ì¤¿¥°¥ë¡¼¥×¿ô¤è¤êÂ礭¤¯¤Ê¤ë²ÄǽÀ­¤¬¤¢¤ë¡£
87 .SH ÊÖ¤êÃÍ
88 .I user
89 ¤¬½ê°¤·¤Æ¤¤¤ë¥°¥ë¡¼¥×¿ô¤¬
90 .I *ngroups
91 °Ê²¼¤Î¾ì¹ç¡¢
92 .I *ngroups
93 ¤ÎÃͤ¬ÊÖ¤µ¤ì¤ë¡£
94
95 »ØÄꤵ¤ì¤¿¥æ¡¼¥¶¤¬
96 .I *ngroups
97 ¤è¤ê¿¤¯¤Î¥°¥ë¡¼¥×¤Ë½ê°¤·¤Æ¤¤¤ë¾ì¹ç¡¢
98 .BR getgrouplist ()
99 ¤Ï \-1 ¤òÊÖ¤¹¡£
100 ¤³¤Î¾ì¹ç¡¢
101 .I *ngroups
102 ¤ÇÊÖ¤µ¤ì¤ëÃͤò»È¤Ã¤Æ¡¢¥Ð¥Ã¥Õ¥¡¤Î¥µ¥¤¥º¤òÊѹ¹¤·¤Æ¤«¤é¡¢
103 .BR getgrouplist ()
104 ¤ò¤â¤¦°ìÅٸƤӽФ¹¤³¤È¤¬¤Ç¤­¤ë¡£
105 .SH ¥Ð¡¼¥¸¥ç¥ó
106 ¤³¤Î´Ø¿ô¤Ï glibc 2.2.4 ¤«¤é¸ºß¤¹¤ë¡£
107 .SH ½àµò
108 ¤³¤Î´Ø¿ô¤ÏÈóɸ½à¤Ç¤¢¤ë¡£¤Û¤È¤ó¤É¤Î BSD ¤Ë¸ºß¤¹¤ë¡£
109 .SH ¥Ð¥°
110 ¥Ð¡¼¥¸¥ç¥ó 2.3.3 ¤è¤êÁ°¤Î glibc ¤Ç¤Ï¡¢
111 ¤³¤Î´Ø¿ô¤Î¼ÂÁõ¤Ë¤Ï¥Ð¥Ã¥Õ¥¡¥ª¡¼¥Ð¡¼¥Õ¥í¡¼¤Î¥Ð¥°¤¬¤¢¤ê¡¢
112 .I user
113 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¿ô¤¬
114 .I *ngroups
115 ¤è¤ê¿¤¤¾ì¹ç¤Ç¤¢¤Ã¤Æ¤â¡¢
116 .I user
117 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤ÎÁ´¥ê¥¹¥È¤òÇÛÎó
118 .I groups
119 ¤Ë³ÊǼ¤·¤Æ¤·¤Þ¤¦¡£
120 .SH Îã
121 .PP
122 °Ê²¼¤Î¥×¥í¥°¥é¥à¤Ï¡¢°ì¤ÄÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ç»ØÄꤵ¤ì¤¿Ì¾Á°¤Î¥æ¡¼¥¶
123 ¤¬½ê°¤¹¤ë¥°¥ë¡¼¥×¤Î¥ê¥¹¥È¤òɽ¼¨¤¹¤ë¡£
124 ÆóÈÖÌܤΥ³¥Þ¥ó¥É¥é¥¤¥ó°ú¤­¿ô¤Ë¤Ï¡¢
125 .BR getgrouplist ()
126 ¤ËÅϤ¹
127 .I ngroups
128 ¤ÎÃͤò»ØÄꤹ¤ë¡£
129 °Ê²¼¤Î¥·¥§¥ë¤Î¥»¥Ã¥·¥ç¥ó¤Ï¤³¤Î¥×¥í¥°¥é¥à¤Î»ÈÍÑÎã¤ò¼¨¤·¤¿¤â¤Î¤Ç¤¢¤ë¡£
130 .in +4n
131 .nf
132
133 .RB "$" " ./a.out cecilia 0"
134 getgrouplist() returned -1; ngroups = 3
135 .RB "$" " ./a.out cecilia 3"
136 ngroups = 3
137 16 (dialout)
138 33 (video)
139 100 (users)
140 .fi
141 .in
142 .SS ¥×¥í¥°¥é¥à¤Î¥½¡¼¥¹
143 \&
144 .nf
145 #include <stdio.h>
146 #include <stdlib.h>
147 #include <grp.h>
148 #include <pwd.h>
149
150 int
151 main(int argc, char *argv[])
152 {
153     int j, ngroups;
154     gid_t *groups;
155     struct passwd *pw;
156     struct group *gr;
157
158     if (argc != 3) {
159         fprintf(stderr, "Usage: %s <user> <ngroups>\\n", argv[0]);
160         exit(EXIT_FAILURE);
161     }
162
163     ngroups = atoi(argv[2]);
164
165     groups = malloc(ngroups * sizeof (gid_t));
166     if (groups == NULL) {
167         perror("malloc");
168         exit(EXIT_FAILURE);
169     }
170
171     /* Fetch passwd structure (contains first group ID for user) */
172
173     pw = getpwnam(argv[1]);
174     if (pw == NULL) {
175         perror("getpwnam");
176         exit(EXIT_SUCCESS);
177     }
178
179     /* Retrieve group list */
180
181     if (getgrouplist(argv[1], pw\->pw_gid, groups, &ngroups) == \-1) {
182         fprintf(stderr, "getgrouplist() returned \-1; ngroups = %d\\n",
183                 ngroups);
184         exit(EXIT_FAILURE);
185     }
186
187     /* Display list of retrieved groups, along with group names */
188
189     fprintf(stderr, "ngroups = %d\\n", ngroups);
190     for (j = 0; j < ngroups; j++) {
191         printf("%d", groups[j]);
192         gr = getgrgid(groups[j]);
193         if (gr != NULL)
194             printf(" (%s)", gr\->gr_name);
195         printf("\\n");
196     }
197
198     exit(EXIT_SUCCESS);
199 }
200 .fi
201 .SH ´ØÏ¢¹àÌÜ
202 .BR getgroups (2),
203 .BR setgroups (2),
204 .BR getgrent (3),
205 .BR group (5),
206 .BR passwd (5)