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