blob: 45b21043c330ad0908d693fcaae17532547a7b42 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Copyright (C) 1991,1992,1995-2001,2003,2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19/*
20 * POSIX Standard: 9.2.1 Group Database Access <grp.h>
21 */
22
23#ifndef _GRP_H
24#define _GRP_H 1
25
26#include <features.h>
27
28__BEGIN_DECLS
29
30#include <bits/types.h>
31
32#define __need_size_t
33#include <stddef.h>
34
35
36/* For the Single Unix specification we must define this type here. */
37#if (defined __USE_XOPEN || defined __USE_XOPEN2K) && !defined __gid_t_defined
38typedef __gid_t gid_t;
39# define __gid_t_defined
40#endif
41
42/* The group structure. */
43struct group
44 {
45 char *gr_name; /* Group name. */
46 char *gr_passwd; /* Password. */
47 __gid_t gr_gid; /* Group ID. */
48 char **gr_mem; /* Member list. */
49 };
50
51
52#if defined __USE_SVID || defined __USE_GNU
53# define __need_FILE
54# include <stdio.h>
55#endif
56
57
58#if defined __USE_SVID || defined __USE_BSD || defined __USE_XOPEN_EXTENDED
59/* Rewind the group-file stream.
60
61 This function is a possible cancellation point and therefore not
62 marked with __THROW. */
63extern void setgrent (void);
64
65/* Close the group-file stream.
66
67 This function is a possible cancellation point and therefore not
68 marked with __THROW. */
69extern void endgrent (void);
70
71/* Read an entry from the group-file stream, opening it if necessary.
72
73 This function is a possible cancellation point and therefore not
74 marked with __THROW. */
75extern struct group *getgrent (void);
76#endif
77
78#ifdef __USE_SVID
79/* Read a group entry from STREAM.
80
81 This function is not part of POSIX and therefore no official
82 cancellation point. But due to similarity with an POSIX interface
83 or due to the implementation it is a cancellation point and
84 therefore not marked with __THROW. */
85extern struct group *fgetgrent (FILE *__stream);
86#endif
87
88#ifdef __USE_GNU
89/* Write the given entry onto the given stream.
90
91 This function is not part of POSIX and therefore no official
92 cancellation point. But due to similarity with an POSIX interface
93 or due to the implementation it is a cancellation point and
94 therefore not marked with __THROW. */
95extern int putgrent (__const struct group *__restrict __p,
96 FILE *__restrict __f);
97#endif
98
99/* Search for an entry with a matching group ID.
100
101 This function is a possible cancellation point and therefore not
102 marked with __THROW. */
103extern struct group *getgrgid (__gid_t __gid);
104
105/* Search for an entry with a matching group name.
106
107 This function is a possible cancellation point and therefore not
108 marked with __THROW. */
109extern struct group *getgrnam (__const char *__name);
110
111#if defined __USE_POSIX || defined __USE_MISC
112
113# ifdef __USE_MISC
114/* Reasonable value for the buffer sized used in the reentrant
115 functions below. But better use `sysconf'. */
116# define NSS_BUFLEN_GROUP 1024
117# endif
118
119/* Reentrant versions of some of the functions above.
120
121 PLEASE NOTE: the `getgrent_r' function is not (yet) standardized.
122 The interface may change in later versions of this library. But
123 the interface is designed following the principals used for the
124 other reentrant functions so the chances are good this is what the
125 POSIX people would choose.
126
127 This function is not part of POSIX and therefore no official
128 cancellation point. But due to similarity with an POSIX interface
129 or due to the implementation it is a cancellation point and
130 therefore not marked with __THROW. */
131
132# ifdef __USE_GNU
133extern int getgrent_r (struct group *__restrict __resultbuf,
134 char *__restrict __buffer, size_t __buflen,
135 struct group **__restrict __result);
136libc_hidden_proto(getgrent_r)
137# endif
138
139/* Search for an entry with a matching group ID.
140
141 This function is a possible cancellation point and therefore not
142 marked with __THROW. */
143extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,
144 char *__restrict __buffer, size_t __buflen,
145 struct group **__restrict __result);
146libc_hidden_proto(getgrgid_r)
147
148/* Search for an entry with a matching group name.
149
150 This function is a possible cancellation point and therefore not
151 marked with __THROW. */
152extern int getgrnam_r (__const char *__restrict __name,
153 struct group *__restrict __resultbuf,
154 char *__restrict __buffer, size_t __buflen,
155 struct group **__restrict __result);
156libc_hidden_proto(getgrnam_r)
157
158# ifdef __USE_SVID
159/* Read a group entry from STREAM. This function is not standardized
160 an probably never will.
161
162 This function is not part of POSIX and therefore no official
163 cancellation point. But due to similarity with an POSIX interface
164 or due to the implementation it is a cancellation point and
165 therefore not marked with __THROW. */
166extern int fgetgrent_r (FILE *__restrict __stream,
167 struct group *__restrict __resultbuf,
168 char *__restrict __buffer, size_t __buflen,
169 struct group **__restrict __result);
170libc_hidden_proto(fgetgrent_r)
171# endif
172
173#endif /* POSIX or reentrant */
174
175
176#if defined __USE_BSD || defined __USE_GNU
177
178# define __need_size_t
179# include <stddef.h>
180
181/* Store at most *NGROUPS members of the group set for USER into
182 *GROUPS. Also include GROUP. The actual number of groups found is
183 returned in *NGROUPS. Return -1 if the if *NGROUPS is too small.
184 In all cases the actual number of groups is stored in *NGROUPS.
185
186 This function is not part of POSIX and therefore no official
187 cancellation point. But due to similarity with an POSIX interface
188 or due to the implementation it is a cancellation point and
189 therefore not marked with __THROW. */
190extern int getgrouplist (__const char *__user, __gid_t __group,
191 __gid_t *__groups, int *__ngroups);
192
193#endif
194
195#if defined __USE_BSD
196
197/* Set the group set for the current user to GROUPS (N of them). */
198extern int setgroups (size_t __n, __const __gid_t *__groups) __THROW;
199libc_hidden_proto(setgroups)
200
201/* Initialize the group set for the current user
202 by reading the group database and using all groups
203 of which USER is a member. Also include GROUP.
204
205 This function is not part of POSIX and therefore no official
206 cancellation point. But due to similarity with an POSIX interface
207 or due to the implementation it is a cancellation point and
208 therefore not marked with __THROW. */
209extern int initgroups (__const char *__user, __gid_t __group);
210
211#endif /* Use BSD. */
212
213__END_DECLS
214
215#endif /* grp.h */