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 2004 Sun Microsystems, Inc.  All rights reserved.
  28  * Use is subject to license terms.
  29  */
  30 
  31 #ifndef _PWD_H
  32 #define _PWD_H
  33 
  34 #pragma ident   "%Z%%M% %I%     %E% SMI"        /* SVr4.0 1.3.1.9 */
  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 #if defined(__STDC__)
  70 
  71 extern struct passwd *getpwuid(uid_t);          /* MT-unsafe */
  72 extern struct passwd *getpwnam(const char *);   /* MT-unsafe */
  73 
  74 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
  75 extern struct passwd *getpwent_r(struct passwd *, char *, int);
  76 extern struct passwd *fgetpwent_r(FILE *, struct passwd *, char *, int);
  77 extern struct passwd *fgetpwent(FILE *);        /* MT-unsafe */
  78 extern int putpwent(const struct passwd *, FILE *);
  79 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
  80 
  81 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
  82         defined(__EXTENSIONS__)
  83 extern void endpwent(void);
  84 extern struct passwd *getpwent(void);           /* MT-unsafe */
  85 extern void setpwent(void);
  86 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
  87 
  88 #else  /* (__STDC__) */
  89 
  90 extern struct passwd *getpwuid();               /* MT-unsafe */
  91 extern struct passwd *getpwnam();               /* MT-unsafe */
  92 
  93 #if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
  94 extern struct passwd *getpwent_r();
  95 extern struct passwd *fgetpwent_r();
  96 
  97 extern struct passwd *fgetpwent();              /* MT-unsafe */
  98 extern int putpwent();
  99 #endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
 100 
 101 #if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || \
 102         defined(__EXTENSIONS__)
 103 extern void endpwent();
 104 extern struct passwd *getpwent();               /* MT-unsafe */
 105 extern void setpwent();
 106 #endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
 107 
 108 #endif /* (__STDC__) */
 109 
 110 /*
 111  * getpwuid_r() & getpwnam_r() prototypes are defined here.
 112  */
 113 
 114 /*
 115  * Previous releases of Solaris, starting at 2.3, provided definitions of
 116  * various functions as specified in POSIX.1c, Draft 6.  For some of these
 117  * functions, the final POSIX 1003.1c standard had a different number of
 118  * arguments and return values.
 119  *
 120  * The following segment of this header provides support for the standard
 121  * interfaces while supporting applications written under earlier
 122  * releases.  The application defines appropriate values of the feature
 123  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
 124  * whether it was written to expect the Draft 6 or standard versions of
 125  * these interfaces, before including this header.  This header then
 126  * provides a mapping from the source version of the interface to an
 127  * appropriate binary interface.  Such mappings permit an application
 128  * to be built from libraries and objects which have mixed expectations
 129  * of the definitions of these functions.
 130  *
 131  * For applications using the Draft 6 definitions, the binary symbol is the
 132  * same as the source symbol, and no explicit mapping is needed.  For the
 133  * standard interface, the function func() is mapped to the binary symbol
 134  * _posix_func().  The preferred mechanism for the remapping is a compiler
 135  * #pragma.  If the compiler does not provide such a #pragma, the header file
 136  * defines a static function func() which calls the _posix_func() version;
 137  * this has to be done instead of #define since POSIX specifies that an
 138  * application can #undef the symbol and still be bound to the correct
 139  * implementation.  Unfortunately, the statics confuse lint so we fallback to
 140  * #define in that case.
 141  *
 142  * NOTE: Support for the Draft 6 definitions is provided for compatibility
 143  * only.  New applications/libraries should use the standard definitions.
 144  */
 145 
 146 #if !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L) || \
 147         defined(_POSIX_PTHREAD_SEMANTICS) || defined(__EXTENSIONS__)
 148 
 149 #if defined(__STDC__)
 150 
 151 #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
 152 
 153 #ifdef __PRAGMA_REDEFINE_EXTNAME
 154 #pragma redefine_extname getpwuid_r __posix_getpwuid_r
 155 #pragma redefine_extname getpwnam_r __posix_getpwnam_r
 156 extern int getpwuid_r(uid_t, struct passwd *, char *, int, struct passwd **);
 157 extern int getpwnam_r(const char *, struct passwd *, char *,
 158                                                         int, struct passwd **);
 159 #else  /* __PRAGMA_REDEFINE_EXTNAME */
 160 
 161 extern int __posix_getpwuid_r(uid_t, struct passwd *, char *, size_t,
 162     struct passwd **);
 163 extern int __posix_getpwnam_r(const char *, struct passwd *, char *,
 164     size_t, struct passwd **);
 165 
 166 #ifdef __lint
 167 
 168 #define getpwuid_r __posix_getpwuid_r
 169 #define getpwnam_r __posix_getpwnam_r
 170 
 171 #else   /* !__lint */
 172 
 173 static int
 174 getpwuid_r(uid_t __uid, struct passwd *__pwd, char *__buf, int __len,
 175     struct passwd **__res)
 176 {
 177         return (__posix_getpwuid_r(__uid, __pwd, __buf, __len, __res));
 178 }
 179 static int
 180 getpwnam_r(const char *__cb, struct passwd *__pwd, char *__buf, int __len,
 181     struct passwd **__res)
 182 {
 183         return (__posix_getpwnam_r(__cb, __pwd, __buf, __len, __res));
 184 }
 185 
 186 #endif /* !__lint */
 187 #endif /* __PRAGMA_REDEFINE_EXTNAME */
 188 
 189 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 190 
 191 extern struct passwd *getpwuid_r(uid_t, struct passwd *, char *, int);
 192 extern struct passwd *getpwnam_r(const char *, struct passwd *, char *, int);
 193 
 194 #endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 195 
 196 #else  /* __STDC__ */
 197 
 198 #if (_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
 199 
 200 #ifdef __PRAGMA_REDEFINE_EXTNAME
 201 #pragma redefine_extname getpwuid_r __posix_getpwuid_r
 202 #pragma redefine_extname getpwnam_r __posix_getpwnam_r
 203 extern int getpwuid_r();
 204 extern int getpwnam_r();
 205 #else  /* __PRAGMA_REDEFINE_EXTNAME */
 206 
 207 extern int __posix_getpwuid_r();
 208 extern int __posix_getpwnam_r();
 209 
 210 #ifdef  __lint
 211 
 212 #define getpwuid_r __posix_getpwuid_r
 213 #define getpwnam_r __posix_getpwnam_r
 214 
 215 #else   /* !__lint */
 216 
 217 static int
 218 getpwuid_r(__uid, __pwd, __buf, __len, __res)
 219         uid_t __uid;
 220         struct passwd *__pwd;
 221         char *__buf;
 222         int __len;
 223         struct passwd **__res;
 224 {
 225         return (__posix_getpwuid_r(__uid, __pwd, __buf, __len, __res));
 226 }
 227 static int
 228 getpwnam_r(__cb, __pwd, __buf, __len, __res)
 229         char *__cb;
 230         struct passwd *__pwd;
 231         char *__buf;
 232         int __len;
 233         struct passwd **__res;
 234 {
 235         return (__posix_getpwnam_r(__cb, __pwd, __buf, __len, __res));
 236 }
 237 
 238 #endif /* !__lint */
 239 #endif /* __PRAGMA_REDEFINE_EXTNAME */
 240 
 241 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 242 
 243 extern struct passwd *getpwuid_r();
 244 extern struct passwd *getpwnam_r();
 245 
 246 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
 247 
 248 #endif /* __STDC__ */
 249 
 250 #endif /* !defined(__XOPEN_OR_POSIX) || (_POSIX_C_SOURCE - 0 >= 199506L)... */
 251 
 252 #ifdef  __cplusplus
 253 }
 254 #endif
 255 
 256 #endif /* _PWD_H */