xref: /illumos-gate/usr/src/head/pwd.h (revision b4203d75)
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	*/
23*b4203d75SMarcel Telka /*	  All Rights Reserved	*/
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.
317c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate #ifndef _PWD_H
347c478bd9Sstevel@tonic-gate #define	_PWD_H
367c478bd9Sstevel@tonic-gate #include <sys/feature_tests.h>
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
417c478bd9Sstevel@tonic-gate #include <stdio.h>
427c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
457c478bd9Sstevel@tonic-gate extern "C" {
467c478bd9Sstevel@tonic-gate #endif
487c478bd9Sstevel@tonic-gate struct passwd {
497c478bd9Sstevel@tonic-gate 	char	*pw_name;
507c478bd9Sstevel@tonic-gate 	char	*pw_passwd;
517c478bd9Sstevel@tonic-gate 	uid_t	pw_uid;
527c478bd9Sstevel@tonic-gate 	gid_t	pw_gid;
537c478bd9Sstevel@tonic-gate 	char	*pw_age;
547c478bd9Sstevel@tonic-gate 	char	*pw_comment;
557c478bd9Sstevel@tonic-gate 	char	*pw_gecos;
567c478bd9Sstevel@tonic-gate 	char	*pw_dir;
577c478bd9Sstevel@tonic-gate 	char	*pw_shell;
587c478bd9Sstevel@tonic-gate };
607c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
617c478bd9Sstevel@tonic-gate struct comment {
627c478bd9Sstevel@tonic-gate 	char	*c_dept;
637c478bd9Sstevel@tonic-gate 	char	*c_name;
647c478bd9Sstevel@tonic-gate 	char	*c_acct;
657c478bd9Sstevel@tonic-gate 	char	*c_bin;
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
697c478bd9Sstevel@tonic-gate extern struct passwd *getpwuid(uid_t);		/* MT-unsafe */
707c478bd9Sstevel@tonic-gate extern struct passwd *getpwnam(const char *);	/* MT-unsafe */
727c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
737c478bd9Sstevel@tonic-gate extern struct passwd *getpwent_r(struct passwd *, char *, int);
747c478bd9Sstevel@tonic-gate extern struct passwd *fgetpwent_r(FILE *, struct passwd *, char *, int);
757c478bd9Sstevel@tonic-gate extern struct passwd *fgetpwent(FILE *);	/* MT-unsafe */
767c478bd9Sstevel@tonic-gate extern int putpwent(const struct passwd *, FILE *);
777c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
797c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
807c478bd9Sstevel@tonic-gate 	defined(__EXTENSIONS__)
817c478bd9Sstevel@tonic-gate extern void endpwent(void);
827c478bd9Sstevel@tonic-gate extern struct passwd *getpwent(void);		/* MT-unsafe */
837c478bd9Sstevel@tonic-gate extern void setpwent(void);
847c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * getpwuid_r() & getpwnam_r() prototypes are defined here.
887c478bd9Sstevel@tonic-gate  */
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * Previous releases of Solaris, starting at 2.3, provided definitions of
927c478bd9Sstevel@tonic-gate  * various functions as specified in POSIX.1c, Draft 6.  For some of these
937c478bd9Sstevel@tonic-gate  * functions, the final POSIX 1003.1c standard had a different number of
947c478bd9Sstevel@tonic-gate  * arguments and return values.
957c478bd9Sstevel@tonic-gate  *
967c478bd9Sstevel@tonic-gate  * The following segment of this header provides support for the standard
977c478bd9Sstevel@tonic-gate  * interfaces while supporting applications written under earlier
987c478bd9Sstevel@tonic-gate  * releases.  The application defines appropriate values of the feature
997c478bd9Sstevel@tonic-gate  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
1007c478bd9Sstevel@tonic-gate  * whether it was written to expect the Draft 6 or standard versions of
1017c478bd9Sstevel@tonic-gate  * these interfaces, before including this header.  This header then
1027c478bd9Sstevel@tonic-gate  * provides a mapping from the source version of the interface to an
1037c478bd9Sstevel@tonic-gate  * appropriate binary interface.  Such mappings permit an application
1047c478bd9Sstevel@tonic-gate  * to be built from libraries and objects which have mixed expectations
1057c478bd9Sstevel@tonic-gate  * of the definitions of these functions.
1067c478bd9Sstevel@tonic-gate  *
1077c478bd9Sstevel@tonic-gate  * For applications using the Draft 6 definitions, the binary symbol is the
1087c478bd9Sstevel@tonic-gate  * same as the source symbol, and no explicit mapping is needed.  For the
1097c478bd9Sstevel@tonic-gate  * standard interface, the function func() is mapped to the binary symbol
1107c478bd9Sstevel@tonic-gate  * _posix_func().  The preferred mechanism for the remapping is a compiler
1117c478bd9Sstevel@tonic-gate  * #pragma.  If the compiler does not provide such a #pragma, the header file
1127c478bd9Sstevel@tonic-gate  * defines a static function func() which calls the _posix_func() version;
1137c478bd9Sstevel@tonic-gate  * this has to be done instead of #define since POSIX specifies that an
1147c478bd9Sstevel@tonic-gate  * application can #undef the symbol and still be bound to the correct
1157c478bd9Sstevel@tonic-gate  * implementation.  Unfortunately, the statics confuse lint so we fallback to
1167c478bd9Sstevel@tonic-gate  * #define in that case.
1177c478bd9Sstevel@tonic-gate  *
1187c478bd9Sstevel@tonic-gate  * NOTE: Support for the Draft 6 definitions is provided for compatibility
1197c478bd9Sstevel@tonic-gate  * only.  New applications/libraries should use the standard definitions.
1207c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
1237c478bd9Sstevel@tonic-gate 	defined(_POSIX_PTHREAD_SEMANTICS) || defined(__EXTENSIONS__)
1257c478bd9Sstevel@tonic-gate #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
1277c478bd9Sstevel@tonic-gate #ifdef __PRAGMA_REDEFINE_EXTNAME
1287c478bd9Sstevel@tonic-gate #pragma redefine_extname getpwuid_r __posix_getpwuid_r
1297c478bd9Sstevel@tonic-gate #pragma redefine_extname getpwnam_r __posix_getpwnam_r
130750b79c7SKeith M Wesolowski extern int getpwuid_r(uid_t, struct passwd *, char *,
131750b79c7SKeith M Wesolowski     size_t, struct passwd **);
1327c478bd9Sstevel@tonic-gate extern int getpwnam_r(const char *, struct passwd *, char *,
133750b79c7SKeith M Wesolowski     size_t, struct passwd **);
1347c478bd9Sstevel@tonic-gate #else  /* __PRAGMA_REDEFINE_EXTNAME */
1367c478bd9Sstevel@tonic-gate extern int __posix_getpwuid_r(uid_t, struct passwd *, char *, size_t,
1377c478bd9Sstevel@tonic-gate     struct passwd **);
1387c478bd9Sstevel@tonic-gate extern int __posix_getpwnam_r(const char *, struct passwd *, char *,
1397c478bd9Sstevel@tonic-gate     size_t, struct passwd **);
1417c478bd9Sstevel@tonic-gate #ifdef __lint
1437c478bd9Sstevel@tonic-gate #define	getpwuid_r __posix_getpwuid_r
1447c478bd9Sstevel@tonic-gate #define	getpwnam_r __posix_getpwnam_r
1467c478bd9Sstevel@tonic-gate #else	/* !__lint */
1487c478bd9Sstevel@tonic-gate static int
getpwuid_r(uid_t __uid,struct passwd * __pwd,char * __buf,size_t __len,struct passwd ** __res)149750b79c7SKeith M Wesolowski getpwuid_r(uid_t __uid, struct passwd *__pwd, char *__buf, size_t __len,
1507c478bd9Sstevel@tonic-gate     struct passwd **__res)
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate 	return (__posix_getpwuid_r(__uid, __pwd, __buf, __len, __res));
1537c478bd9Sstevel@tonic-gate }
1547c478bd9Sstevel@tonic-gate static int
getpwnam_r(const char * __cb,struct passwd * __pwd,char * __buf,size_t __len,struct passwd ** __res)155750b79c7SKeith M Wesolowski getpwnam_r(const char *__cb, struct passwd *__pwd, char *__buf, size_t __len,
1567c478bd9Sstevel@tonic-gate     struct passwd **__res)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate 	return (__posix_getpwnam_r(__cb, __pwd, __buf, __len, __res));
1597c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate #endif /* !__lint */
1627c478bd9Sstevel@tonic-gate #endif /* __PRAGMA_REDEFINE_EXTNAME */
1647c478bd9Sstevel@tonic-gate #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
1667c478bd9Sstevel@tonic-gate extern struct passwd *getpwuid_r(uid_t, struct passwd *, char *, int);
1677c478bd9Sstevel@tonic-gate extern struct passwd *getpwnam_r(const char *, struct passwd *, char *, int);
1697c478bd9Sstevel@tonic-gate #endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
1717c478bd9Sstevel@tonic-gate #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L)... */
1737c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1747c478bd9Sstevel@tonic-gate }
1757c478bd9Sstevel@tonic-gate #endif
1777c478bd9Sstevel@tonic-gate #endif /* _PWD_H */