xref: /illumos-gate/usr/src/head/grp.h (revision bdecfb1e5c840f07ab6122d9c8168b1a438db7dd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved	*/
24 
25 
26 /*
27  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
28  *
29  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
30  * Use is subject to license terms.
31  */
32 
33 #ifndef _GRP_H
34 #define	_GRP_H
35 
36 #include <sys/feature_tests.h>
37 
38 #include <sys/types.h>
39 
40 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
41 #include <stdio.h>
42 #endif
43 
44 #ifdef	__cplusplus
45 extern "C" {
46 #endif
47 
48 struct	group {	/* see getgrent(3C) */
49 	char	*gr_name;
50 	char	*gr_passwd;
51 	gid_t	gr_gid;
52 	char	**gr_mem;
53 };
54 
55 extern struct group *getgrgid(gid_t);		/* MT-unsafe */
56 extern struct group *getgrnam(const char *);	/* MT-unsafe */
57 
58 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
59 extern struct group *getgrent_r(struct group *, char *, int);
60 extern struct group *fgetgrent_r(FILE *, struct group *, char *, int);
61 
62 
63 extern struct group *fgetgrent(FILE *);		/* MT-unsafe */
64 extern int initgroups(const char *, gid_t);
65 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
66 
67 #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)
68 extern void endgrent(void);
69 extern void setgrent(void);
70 extern struct group *getgrent(void);		/* MT-unsafe */
71 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)... */
72 
73 /*
74  * getgrgid_r() & getgrnam_r() prototypes are defined here.
75  */
76 
77 /*
78  * Previous releases of Solaris, starting at 2.3, provided definitions of
79  * various functions as specified in POSIX.1c, Draft 6.  For some of these
80  * functions, the final POSIX 1003.1c standard had a different number of
81  * arguments and return values.
82  *
83  * The following segment of this header provides support for the standard
84  * interfaces while supporting applications written under earlier
85  * releases.  The application defines appropriate values of the feature
86  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
87  * whether it was written to expect the Draft 6 or standard versions of
88  * these interfaces, before including this header.  This header then
89  * provides a mapping from the source version of the interface to an
90  * appropriate binary interface.  Such mappings permit an application
91  * to be built from libraries and objects which have mixed expectations
92  * of the definitions of these functions.
93  *
94  * For applications using the Draft 6 definitions, the binary symbol is the
95  * same as the source symbol, and no explicit mapping is needed.  For the
96  * standard interface, the function func() is mapped to the binary symbol
97  * _posix_func().  The preferred mechanism for the remapping is a compiler
98  * #pragma.  If the compiler does not provide such a #pragma, the header file
99  * defines a static function func() which calls the _posix_func() version;
100  * this has to be done instead of #define since POSIX specifies that an
101  * application can #undef the symbol and still be bound to the correct
102  * implementation.  Unfortunately, the statics confuse lint so we fallback to
103  * #define in that case.
104  *
105  * NOTE: Support for the Draft 6 definitions is provided for compatibility
106  * only.  New applications/libraries should use the standard definitions.
107  */
108 
109 #if	defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \
110 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
111 
112 #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
113 
114 #ifdef __PRAGMA_REDEFINE_EXTNAME
115 #pragma redefine_extname getgrgid_r __posix_getgrgid_r
116 #pragma redefine_extname getgrnam_r __posix_getgrnam_r
117 extern int getgrgid_r(gid_t, struct group *, char *,
118     size_t, struct group **);
119 extern int getgrnam_r(const char *, struct group *, char *,
120     size_t, struct group **);
121 #else  /* __PRAGMA_REDEFINE_EXTNAME */
122 
123 extern int __posix_getgrgid_r(gid_t, struct group *, char *, size_t,
124     struct group **);
125 extern int __posix_getgrnam_r(const char *, struct group *, char *, size_t,
126     struct group **);
127 
128 #ifdef __lint
129 
130 #define	getgrgid_r __posix_getgrgid_r
131 #define	getgrnam_r __posix_getgrnam_r
132 
133 #else	/* !__lint */
134 
135 static int
136 getgrgid_r(gid_t __gid, struct group *__grp, char *__buf, size_t __len,
137     struct group **__res)
138 {
139 	return (__posix_getgrgid_r(__gid, __grp, __buf, __len, __res));
140 }
141 static int
142 getgrnam_r(const char *__cb, struct group *__grp, char *__buf, size_t __len,
143     struct group **__res)
144 {
145 	return (__posix_getgrnam_r(__cb, __grp, __buf, __len, __res));
146 }
147 
148 #endif /* !__lint */
149 #endif /* __PRAGMA_REDEFINE_EXTNAME */
150 
151 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
152 
153 extern struct group *getgrgid_r(gid_t, struct group *, char *, int);
154 extern struct group *getgrnam_r(const char *, struct group *, char *, int);
155 
156 #endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
157 
158 #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)... */
159 
160 #ifdef	__cplusplus
161 }
162 #endif
163 
164 #endif	/* _GRP_H */
165