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 _PWD_H 34 #define _PWD_H 35 36 #include <sys/feature_tests.h> 37 38 #include <sys/types.h> 39 40 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 41 #include <stdio.h> 42 #endif 43 44 #ifdef __cplusplus 45 extern "C" { 46 #endif 47 48 struct passwd { 49 char *pw_name; 50 char *pw_passwd; 51 uid_t pw_uid; 52 gid_t pw_gid; 53 char *pw_age; 54 char *pw_comment; 55 char *pw_gecos; 56 char *pw_dir; 57 char *pw_shell; 58 }; 59 60 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 61 struct comment { 62 char *c_dept; 63 char *c_name; 64 char *c_acct; 65 char *c_bin; 66 }; 67 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 68 69 extern struct passwd *getpwuid(uid_t); /* MT-unsafe */ 70 extern struct passwd *getpwnam(const char *); /* MT-unsafe */ 71 72 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) 73 extern struct passwd *getpwent_r(struct passwd *, char *, int); 74 extern struct passwd *fgetpwent_r(FILE *, struct passwd *, char *, int); 75 extern struct passwd *fgetpwent(FILE *); /* MT-unsafe */ 76 extern int putpwent(const struct passwd *, FILE *); 77 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */ 78 79 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \ 80 defined(__EXTENSIONS__) 81 extern void endpwent(void); 82 extern struct passwd *getpwent(void); /* MT-unsafe */ 83 extern void setpwent(void); 84 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */ 85 86 /* 87 * getpwuid_r() & getpwnam_r() prototypes are defined here. 88 */ 89 90 /* 91 * Previous releases of Solaris, starting at 2.3, provided definitions of 92 * various functions as specified in POSIX.1c, Draft 6. For some of these 93 * functions, the final POSIX 1003.1c standard had a different number of 94 * arguments and return values. 95 * 96 * The following segment of this header provides support for the standard 97 * interfaces while supporting applications written under earlier 98 * releases. The application defines appropriate values of the feature 99 * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate 100 * whether it was written to expect the Draft 6 or standard versions of 101 * these interfaces, before including this header. This header then 102 * provides a mapping from the source version of the interface to an 103 * appropriate binary interface. Such mappings permit an application 104 * to be built from libraries and objects which have mixed expectations 105 * of the definitions of these functions. 106 * 107 * For applications using the Draft 6 definitions, the binary symbol is the 108 * same as the source symbol, and no explicit mapping is needed. For the 109 * standard interface, the function func() is mapped to the binary symbol 110 * _posix_func(). The preferred mechanism for the remapping is a compiler 111 * #pragma. If the compiler does not provide such a #pragma, the header file 112 * defines a static function func() which calls the _posix_func() version; 113 * this has to be done instead of #define since POSIX specifies that an 114 * application can #undef the symbol and still be bound to the correct 115 * implementation. Unfortunately, the statics confuse lint so we fallback to 116 * #define in that case. 117 * 118 * NOTE: Support for the Draft 6 definitions is provided for compatibility 119 * only. New applications/libraries should use the standard definitions. 120 */ 121 122 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \ 123 defined(_POSIX_PTHREAD_SEMANTICS) || defined(__EXTENSIONS__) 124 125 #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS) 126 127 #ifdef __PRAGMA_REDEFINE_EXTNAME 128 #pragma redefine_extname getpwuid_r __posix_getpwuid_r 129 #pragma redefine_extname getpwnam_r __posix_getpwnam_r 130 extern int getpwuid_r(uid_t, struct passwd *, char *, int, struct passwd **); 131 extern int getpwnam_r(const char *, struct passwd *, char *, 132 int, struct passwd **); 133 #else /* __PRAGMA_REDEFINE_EXTNAME */ 134 135 extern int __posix_getpwuid_r(uid_t, struct passwd *, char *, size_t, 136 struct passwd **); 137 extern int __posix_getpwnam_r(const char *, struct passwd *, char *, 138 size_t, struct passwd **); 139 140 #ifdef __lint 141 142 #define getpwuid_r __posix_getpwuid_r 143 #define getpwnam_r __posix_getpwnam_r 144 145 #else /* !__lint */ 146 147 static int 148 getpwuid_r(uid_t __uid, struct passwd *__pwd, char *__buf, int __len, 149 struct passwd **__res) 150 { 151 return (__posix_getpwuid_r(__uid, __pwd, __buf, __len, __res)); 152 } 153 static int 154 getpwnam_r(const char *__cb, struct passwd *__pwd, char *__buf, int __len, 155 struct passwd **__res) 156 { 157 return (__posix_getpwnam_r(__cb, __pwd, __buf, __len, __res)); 158 } 159 160 #endif /* !__lint */ 161 #endif /* __PRAGMA_REDEFINE_EXTNAME */ 162 163 #else /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ 164 165 extern struct passwd *getpwuid_r(uid_t, struct passwd *, char *, int); 166 extern struct passwd *getpwnam_r(const char *, struct passwd *, char *, int); 167 168 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */ 169 170 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L)... */ 171 172 #ifdef __cplusplus 173 } 174 #endif 175 176 #endif /* _PWD_H */