17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bdstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bdstevel@tonic-gate * (the "License").  You may not use this file except in compliance
77c478bdstevel@tonic-gate * with the License.
87c478bdstevel@tonic-gate *
97c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bdstevel@tonic-gate * See the License for the specific language governing permissions
127c478bdstevel@tonic-gate * and limitations under the License.
137c478bdstevel@tonic-gate *
147c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * CDDL HEADER END
217c478bdstevel@tonic-gate */
227c478bdstevel@tonic-gate/*	Copyright (c) 1988 AT&T	*/
23b4203d7Marcel Telka/*	  All Rights Reserved	*/
247c478bdstevel@tonic-gate
257c478bdstevel@tonic-gate
267c478bdstevel@tonic-gate/*
27ba3594bGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org>
28ba3594bGarrett D'Amore *
297c478bdstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
307c478bdstevel@tonic-gate * Use is subject to license terms.
317c478bdstevel@tonic-gate */
327c478bdstevel@tonic-gate
337c478bdstevel@tonic-gate#ifndef _PWD_H
347c478bdstevel@tonic-gate#define	_PWD_H
357c478bdstevel@tonic-gate
367c478bdstevel@tonic-gate#include <sys/feature_tests.h>
377c478bdstevel@tonic-gate
387c478bdstevel@tonic-gate#include <sys/types.h>
397c478bdstevel@tonic-gate
407c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
417c478bdstevel@tonic-gate#include <stdio.h>
427c478bdstevel@tonic-gate#endif
437c478bdstevel@tonic-gate
447c478bdstevel@tonic-gate#ifdef	__cplusplus
457c478bdstevel@tonic-gateextern "C" {
467c478bdstevel@tonic-gate#endif
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gatestruct passwd {
497c478bdstevel@tonic-gate	char	*pw_name;
507c478bdstevel@tonic-gate	char	*pw_passwd;
517c478bdstevel@tonic-gate	uid_t	pw_uid;
527c478bdstevel@tonic-gate	gid_t	pw_gid;
537c478bdstevel@tonic-gate	char	*pw_age;
547c478bdstevel@tonic-gate	char	*pw_comment;
557c478bdstevel@tonic-gate	char	*pw_gecos;
567c478bdstevel@tonic-gate	char	*pw_dir;
577c478bdstevel@tonic-gate	char	*pw_shell;
587c478bdstevel@tonic-gate};
597c478bdstevel@tonic-gate
607c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
617c478bdstevel@tonic-gatestruct comment {
627c478bdstevel@tonic-gate	char	*c_dept;
637c478bdstevel@tonic-gate	char	*c_name;
647c478bdstevel@tonic-gate	char	*c_acct;
657c478bdstevel@tonic-gate	char	*c_bin;
667c478bdstevel@tonic-gate};
677c478bdstevel@tonic-gate#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
687c478bdstevel@tonic-gate
697c478bdstevel@tonic-gateextern struct passwd *getpwuid(uid_t);		/* MT-unsafe */
707c478bdstevel@tonic-gateextern struct passwd *getpwnam(const char *);	/* MT-unsafe */
717c478bdstevel@tonic-gate
727c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
737c478bdstevel@tonic-gateextern struct passwd *getpwent_r(struct passwd *, char *, int);
747c478bdstevel@tonic-gateextern struct passwd *fgetpwent_r(FILE *, struct passwd *, char *, int);
757c478bdstevel@tonic-gateextern struct passwd *fgetpwent(FILE *);	/* MT-unsafe */
767c478bdstevel@tonic-gateextern int putpwent(const struct passwd *, FILE *);
777c478bdstevel@tonic-gate#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
787c478bdstevel@tonic-gate
797c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
807c478bdstevel@tonic-gate	defined(__EXTENSIONS__)
817c478bdstevel@tonic-gateextern void endpwent(void);
827c478bdstevel@tonic-gateextern struct passwd *getpwent(void);		/* MT-unsafe */
837c478bdstevel@tonic-gateextern void setpwent(void);
847c478bdstevel@tonic-gate#endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
857c478bdstevel@tonic-gate
867c478bdstevel@tonic-gate/*
877c478bdstevel@tonic-gate * getpwuid_r() & getpwnam_r() prototypes are defined here.
887c478bdstevel@tonic-gate */
897c478bdstevel@tonic-gate
907c478bdstevel@tonic-gate/*
917c478bdstevel@tonic-gate * Previous releases of Solaris, starting at 2.3, provided definitions of
927c478bdstevel@tonic-gate * various functions as specified in POSIX.1c, Draft 6.  For some of these
937c478bdstevel@tonic-gate * functions, the final POSIX 1003.1c standard had a different number of
947c478bdstevel@tonic-gate * arguments and return values.
957c478bdstevel@tonic-gate *
967c478bdstevel@tonic-gate * The following segment of this header provides support for the standard
977c478bdstevel@tonic-gate * interfaces while supporting applications written under earlier
987c478bdstevel@tonic-gate * releases.  The application defines appropriate values of the feature
997c478bdstevel@tonic-gate * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
1007c478bdstevel@tonic-gate * whether it was written to expect the Draft 6 or standard versions of
1017c478bdstevel@tonic-gate * these interfaces, before including this header.  This header then
1027c478bdstevel@tonic-gate * provides a mapping from the source version of the interface to an
1037c478bdstevel@tonic-gate * appropriate binary interface.  Such mappings permit an application
1047c478bdstevel@tonic-gate * to be built from libraries and objects which have mixed expectations
1057c478bdstevel@tonic-gate * of the definitions of these functions.
1067c478bdstevel@tonic-gate *
1077c478bdstevel@tonic-gate * For applications using the Draft 6 definitions, the binary symbol is the
1087c478bdstevel@tonic-gate * same as the source symbol, and no explicit mapping is needed.  For the
1097c478bdstevel@tonic-gate * standard interface, the function func() is mapped to the binary symbol
1107c478bdstevel@tonic-gate * _posix_func().  The preferred mechanism for the remapping is a compiler
1117c478bdstevel@tonic-gate * #pragma.  If the compiler does not provide such a #pragma, the header file
1127c478bdstevel@tonic-gate * defines a static function func() which calls the _posix_func() version;
1137c478bdstevel@tonic-gate * this has to be done instead of #define since POSIX specifies that an
1147c478bdstevel@tonic-gate * application can #undef the symbol and still be bound to the correct
1157c478bdstevel@tonic-gate * implementation.  Unfortunately, the statics confuse lint so we fallback to
1167c478bdstevel@tonic-gate * #define in that case.
1177c478bdstevel@tonic-gate *
1187c478bdstevel@tonic-gate * NOTE: Support for the Draft 6 definitions is provided for compatibility
1197c478bdstevel@tonic-gate * only.  New applications/libraries should use the standard definitions.
1207c478bdstevel@tonic-gate */
1217c478bdstevel@tonic-gate
1227c478bdstevel@tonic-gate#if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
1237c478bdstevel@tonic-gate	defined(_POSIX_PTHREAD_SEMANTICS) || defined(__EXTENSIONS__)
1247c478bdstevel@tonic-gate
1257c478bdstevel@tonic-gate#if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
1267c478bdstevel@tonic-gate
1277c478bdstevel@tonic-gate#ifdef __PRAGMA_REDEFINE_EXTNAME
1287c478bdstevel@tonic-gate#pragma redefine_extname getpwuid_r __posix_getpwuid_r
1297c478bdstevel@tonic-gate#pragma redefine_extname getpwnam_r __posix_getpwnam_r
130750b79cKeith M Wesolowskiextern int getpwuid_r(uid_t, struct passwd *, char *,
131750b79cKeith M Wesolowski    size_t, struct passwd **);
1327c478bdstevel@tonic-gateextern int getpwnam_r(const char *, struct passwd *, char *,
133750b79cKeith M Wesolowski    size_t, struct passwd **);
1347c478bdstevel@tonic-gate#else  /* __PRAGMA_REDEFINE_EXTNAME */
1357c478bdstevel@tonic-gate
1367c478bdstevel@tonic-gateextern int __posix_getpwuid_r(uid_t, struct passwd *, char *, size_t,
1377c478bdstevel@tonic-gate    struct passwd **);
1387c478bdstevel@tonic-gateextern int __posix_getpwnam_r(const char *, struct passwd *, char *,
1397c478bdstevel@tonic-gate    size_t, struct passwd **);
1407c478bdstevel@tonic-gate
1417c478bdstevel@tonic-gate#ifdef __lint
1427c478bdstevel@tonic-gate
1437c478bdstevel@tonic-gate#define	getpwuid_r __posix_getpwuid_r
1447c478bdstevel@tonic-gate#define	getpwnam_r __posix_getpwnam_r
1457c478bdstevel@tonic-gate
1467c478bdstevel@tonic-gate#else	/* !__lint */
1477c478bdstevel@tonic-gate
1487c478bdstevel@tonic-gatestatic int
149750b79cKeith M Wesolowskigetpwuid_r(uid_t __uid, struct passwd *__pwd, char *__buf, size_t __len,
1507c478bdstevel@tonic-gate    struct passwd **__res)
1517c478bdstevel@tonic-gate{
1527c478bdstevel@tonic-gate	return (__posix_getpwuid_r(__uid, __pwd, __buf, __len, __res));
1537c478bdstevel@tonic-gate}
1547c478bdstevel@tonic-gatestatic int
155750b79cKeith M Wesolowskigetpwnam_r(const char *__cb, struct passwd *__pwd, char *__buf, size_t __len,
1567c478bdstevel@tonic-gate    struct passwd **__res)
1577c478bdstevel@tonic-gate{
1587c478bdstevel@tonic-gate	return (__posix_getpwnam_r(__cb, __pwd, __buf, __len, __res));
1597c478bdstevel@tonic-gate}
1607c478bdstevel@tonic-gate
1617c478bdstevel@tonic-gate#endif /* !__lint */
1627c478bdstevel@tonic-gate#endif /* __PRAGMA_REDEFINE_EXTNAME */
1637c478bdstevel@tonic-gate
1647c478bdstevel@tonic-gate#else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
1657c478bdstevel@tonic-gate
1667c478bdstevel@tonic-gateextern struct passwd *getpwuid_r(uid_t, struct passwd *, char *, int);
1677c478bdstevel@tonic-gateextern struct passwd *getpwnam_r(const char *, struct passwd *, char *, int);
1687c478bdstevel@tonic-gate
1697c478bdstevel@tonic-gate#endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
1707c478bdstevel@tonic-gate
1717c478bdstevel@tonic-gate#endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L)... */
1727c478bdstevel@tonic-gate
1737c478bdstevel@tonic-gate#ifdef	__cplusplus
1747c478bdstevel@tonic-gate}
1757c478bdstevel@tonic-gate#endif
1767c478bdstevel@tonic-gate
1777c478bdstevel@tonic-gate#endif /* _PWD_H */
178