xref: /illumos-gate/usr/src/head/grp.h (revision f2c438c5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
23b4203d75SMarcel Telka /*	  All Rights Reserved	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
27ba3594baSGarrett D'Amore  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
28ba3594baSGarrett D'Amore  *
297c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
307c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
31*f2c438c5SJason King  *
32*f2c438c5SJason King  * Copyright 2020 Joyent, Inc.
337c478bd9Sstevel@tonic-gate  */
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #ifndef _GRP_H
367c478bd9Sstevel@tonic-gate #define	_GRP_H
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include <sys/types.h>
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
437c478bd9Sstevel@tonic-gate #include <stdio.h>
447c478bd9Sstevel@tonic-gate #endif
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
477c478bd9Sstevel@tonic-gate extern "C" {
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate struct	group {	/* see getgrent(3C) */
517c478bd9Sstevel@tonic-gate 	char	*gr_name;
527c478bd9Sstevel@tonic-gate 	char	*gr_passwd;
537c478bd9Sstevel@tonic-gate 	gid_t	gr_gid;
547c478bd9Sstevel@tonic-gate 	char	**gr_mem;
557c478bd9Sstevel@tonic-gate };
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate extern struct group *getgrgid(gid_t);		/* MT-unsafe */
587c478bd9Sstevel@tonic-gate extern struct group *getgrnam(const char *);	/* MT-unsafe */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)
617c478bd9Sstevel@tonic-gate extern struct group *getgrent_r(struct group *, char *, int);
627c478bd9Sstevel@tonic-gate extern struct group *fgetgrent_r(FILE *, struct group *, char *, int);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate extern struct group *fgetgrent(FILE *);		/* MT-unsafe */
667c478bd9Sstevel@tonic-gate extern int initgroups(const char *, gid_t);
67*f2c438c5SJason King extern int getgrouplist(const char *, gid_t, gid_t *, int *);
687c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) */
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #if defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2)
717c478bd9Sstevel@tonic-gate extern void endgrent(void);
727c478bd9Sstevel@tonic-gate extern void setgrent(void);
737c478bd9Sstevel@tonic-gate extern struct group *getgrent(void);		/* MT-unsafe */
747c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)... */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate /*
777c478bd9Sstevel@tonic-gate  * getgrgid_r() & getgrnam_r() prototypes are defined here.
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate /*
817c478bd9Sstevel@tonic-gate  * Previous releases of Solaris, starting at 2.3, provided definitions of
827c478bd9Sstevel@tonic-gate  * various functions as specified in POSIX.1c, Draft 6.  For some of these
837c478bd9Sstevel@tonic-gate  * functions, the final POSIX 1003.1c standard had a different number of
847c478bd9Sstevel@tonic-gate  * arguments and return values.
857c478bd9Sstevel@tonic-gate  *
867c478bd9Sstevel@tonic-gate  * The following segment of this header provides support for the standard
877c478bd9Sstevel@tonic-gate  * interfaces while supporting applications written under earlier
887c478bd9Sstevel@tonic-gate  * releases.  The application defines appropriate values of the feature
897c478bd9Sstevel@tonic-gate  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
907c478bd9Sstevel@tonic-gate  * whether it was written to expect the Draft 6 or standard versions of
917c478bd9Sstevel@tonic-gate  * these interfaces, before including this header.  This header then
927c478bd9Sstevel@tonic-gate  * provides a mapping from the source version of the interface to an
937c478bd9Sstevel@tonic-gate  * appropriate binary interface.  Such mappings permit an application
947c478bd9Sstevel@tonic-gate  * to be built from libraries and objects which have mixed expectations
957c478bd9Sstevel@tonic-gate  * of the definitions of these functions.
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  * For applications using the Draft 6 definitions, the binary symbol is the
987c478bd9Sstevel@tonic-gate  * same as the source symbol, and no explicit mapping is needed.  For the
997c478bd9Sstevel@tonic-gate  * standard interface, the function func() is mapped to the binary symbol
1007c478bd9Sstevel@tonic-gate  * _posix_func().  The preferred mechanism for the remapping is a compiler
1017c478bd9Sstevel@tonic-gate  * #pragma.  If the compiler does not provide such a #pragma, the header file
1027c478bd9Sstevel@tonic-gate  * defines a static function func() which calls the _posix_func() version;
1037c478bd9Sstevel@tonic-gate  * this has to be done instead of #define since POSIX specifies that an
1047c478bd9Sstevel@tonic-gate  * application can #undef the symbol and still be bound to the correct
1057c478bd9Sstevel@tonic-gate  * implementation.  Unfortunately, the statics confuse lint so we fallback to
1067c478bd9Sstevel@tonic-gate  * #define in that case.
1077c478bd9Sstevel@tonic-gate  *
1087c478bd9Sstevel@tonic-gate  * NOTE: Support for the Draft 6 definitions is provided for compatibility
1097c478bd9Sstevel@tonic-gate  * only.  New applications/libraries should use the standard definitions.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate #if	defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX) || \
1137c478bd9Sstevel@tonic-gate 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
1187c478bd9Sstevel@tonic-gate #pragma redefine_extname getgrgid_r __posix_getgrgid_r
1197c478bd9Sstevel@tonic-gate #pragma redefine_extname getgrnam_r __posix_getgrnam_r
120591ef764SKeith M Wesolowski extern int getgrgid_r(gid_t, struct group *, char *,
121591ef764SKeith M Wesolowski     size_t, struct group **);
122591ef764SKeith M Wesolowski extern int getgrnam_r(const char *, struct group *, char *,
123591ef764SKeith M Wesolowski     size_t, struct group **);
1247c478bd9Sstevel@tonic-gate #else  /* __PRAGMA_REDEFINE_EXTNAME */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate extern int __posix_getgrgid_r(gid_t, struct group *, char *, size_t,
1277c478bd9Sstevel@tonic-gate     struct group **);
1287c478bd9Sstevel@tonic-gate extern int __posix_getgrnam_r(const char *, struct group *, char *, size_t,
1297c478bd9Sstevel@tonic-gate     struct group **);
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate static int
getgrgid_r(gid_t __gid,struct group * __grp,char * __buf,size_t __len,struct group ** __res)132591ef764SKeith M Wesolowski getgrgid_r(gid_t __gid, struct group *__grp, char *__buf, size_t __len,
1337c478bd9Sstevel@tonic-gate     struct group **__res)
1347c478bd9Sstevel@tonic-gate {
1357c478bd9Sstevel@tonic-gate 	return (__posix_getgrgid_r(__gid, __grp, __buf, __len, __res));
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate static int
getgrnam_r(const char * __cb,struct group * __grp,char * __buf,size_t __len,struct group ** __res)138591ef764SKeith M Wesolowski getgrnam_r(const char *__cb, struct group *__grp, char *__buf, size_t __len,
1397c478bd9Sstevel@tonic-gate     struct group **__res)
1407c478bd9Sstevel@tonic-gate {
1417c478bd9Sstevel@tonic-gate 	return (__posix_getgrnam_r(__cb, __grp, __buf, __len, __res));
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate #endif /* __PRAGMA_REDEFINE_EXTNAME */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate extern struct group *getgrgid_r(gid_t, struct group *, char *, int);
1497c478bd9Sstevel@tonic-gate extern struct group *getgrnam_r(const char *, struct group *, char *, int);
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #endif /* defined(__EXTENSIONS__) || !defined(__XOPEN_OR_POSIX)... */
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate #endif
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate #endif	/* _GRP_H */
160