1 /* Copyright (C) 1991-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
19 * POSIX Standard: 9.2.1 Group Database Access <grp.h>
29 #include <bits/types.h>
35 /* For the Single Unix specification we must define this type here. */
36 #if (defined __USE_XOPEN || defined __USE_XOPEN2K) && !defined __gid_t_defined
37 typedef __gid_t gid_t
;
38 # define __gid_t_defined
41 /* The group structure. */
44 char *gr_name
; /* Group name. */
45 char *gr_passwd
; /* Password. */
46 __gid_t gr_gid
; /* Group ID. */
47 char **gr_mem
; /* Member list. */
52 # include <bits/types/FILE.h>
56 #if defined __USE_MISC || defined __USE_XOPEN_EXTENDED
57 /* Rewind the group-file stream.
59 This function is a possible cancellation point and therefore not
60 marked with __THROW. */
61 extern void setgrent (void);
63 /* Close the group-file stream.
65 This function is a possible cancellation point and therefore not
66 marked with __THROW. */
67 extern void endgrent (void);
69 /* Read an entry from the group-file stream, opening it if necessary.
71 This function is a possible cancellation point and therefore not
72 marked with __THROW. */
73 extern struct group
*getgrent (void);
77 /* Read a group entry from STREAM.
79 This function is not part of POSIX and therefore no official
80 cancellation point. But due to similarity with an POSIX interface
81 or due to the implementation it is a cancellation point and
82 therefore not marked with __THROW. */
83 extern struct group
*fgetgrent (FILE *__stream
);
87 /* Write the given entry onto the given stream.
89 This function is not part of POSIX and therefore no official
90 cancellation point. But due to similarity with an POSIX interface
91 or due to the implementation it is a cancellation point and
92 therefore not marked with __THROW. */
93 extern int putgrent (const struct group
*__restrict __p
,
94 FILE *__restrict __f
);
97 /* Search for an entry with a matching group ID.
99 This function is a possible cancellation point and therefore not
100 marked with __THROW. */
101 extern struct group
*getgrgid (__gid_t __gid
);
103 /* Search for an entry with a matching group name.
105 This function is a possible cancellation point and therefore not
106 marked with __THROW. */
107 extern struct group
*getgrnam (const char *__name
);
112 /* Reasonable value for the buffer sized used in the reentrant
113 functions below. But better use `sysconf'. */
114 # define NSS_BUFLEN_GROUP 1024
117 /* Reentrant versions of some of the functions above.
119 PLEASE NOTE: the `getgrent_r' function is not (yet) standardized.
120 The interface may change in later versions of this library. But
121 the interface is designed following the principals used for the
122 other reentrant functions so the chances are good this is what the
123 POSIX people would choose.
125 This function is not part of POSIX and therefore no official
126 cancellation point. But due to similarity with an POSIX interface
127 or due to the implementation it is a cancellation point and
128 therefore not marked with __THROW. */
131 extern int getgrent_r (struct group
*__restrict __resultbuf
,
132 char *__restrict __buffer
, size_t __buflen
,
133 struct group
**__restrict __result
)
134 __attr_access ((__write_only__
, 2, 3));
137 /* Search for an entry with a matching group ID.
139 This function is a possible cancellation point and therefore not
140 marked with __THROW. */
141 extern int getgrgid_r (__gid_t __gid
, struct group
*__restrict __resultbuf
,
142 char *__restrict __buffer
, size_t __buflen
,
143 struct group
**__restrict __result
)
144 __attr_access ((__write_only__
, 3, 4));
146 /* Search for an entry with a matching group name.
148 This function is a possible cancellation point and therefore not
149 marked with __THROW. */
150 extern int getgrnam_r (const char *__restrict __name
,
151 struct group
*__restrict __resultbuf
,
152 char *__restrict __buffer
, size_t __buflen
,
153 struct group
**__restrict __result
)
154 __attr_access ((__write_only__
, 3, 4));
157 /* Read a group entry from STREAM. This function is not standardized
158 an probably never will.
160 This function is not part of POSIX and therefore no official
161 cancellation point. But due to similarity with an POSIX interface
162 or due to the implementation it is a cancellation point and
163 therefore not marked with __THROW. */
164 extern int fgetgrent_r (FILE *__restrict __stream
,
165 struct group
*__restrict __resultbuf
,
166 char *__restrict __buffer
, size_t __buflen
,
167 struct group
**__restrict __result
)
168 __attr_access ((__write_only__
, 3, 4));
171 #endif /* POSIX or reentrant */
176 # define __need_size_t
179 /* Set the group set for the current user to GROUPS (N of them). */
180 extern int setgroups (size_t __n
, const __gid_t
*__groups
) __THROW
;
182 /* Store at most *NGROUPS members of the group set for USER into
183 *GROUPS. Also include GROUP. The actual number of groups found is
184 returned in *NGROUPS. Return -1 if the if *NGROUPS is too small.
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. */
190 extern int getgrouplist (const char *__user
, __gid_t __group
,
191 __gid_t
*__groups
, int *__ngroups
);
193 /* Initialize the group set for the current user
194 by reading the group database and using all groups
195 of which USER is a member. Also include GROUP.
197 This function is not part of POSIX and therefore no official
198 cancellation point. But due to similarity with an POSIX interface
199 or due to the implementation it is a cancellation point and
200 therefore not marked with __THROW. */
201 extern int initgroups (const char *__user
, __gid_t __group
);
203 #endif /* Use misc. */