1 /* Copyright (C) 1991,1992,1995-2001,2003,2004,2012
2 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 * POSIX Standard: 9.2.2 User Database Access <pwd.h>
31 #include <bits/types.h>
36 #if defined __USE_XOPEN || defined __USE_XOPEN2K
37 /* The Single Unix specification says that some more types are
39 # ifndef __gid_t_defined
40 typedef __gid_t gid_t
;
41 # define __gid_t_defined
44 # ifndef __uid_t_defined
45 typedef __uid_t uid_t
;
46 # define __uid_t_defined
50 /* The passwd structure. */
53 char *pw_name
; /* Username. */
54 char *pw_passwd
; /* Password. */
55 __uid_t pw_uid
; /* User ID. */
56 __gid_t pw_gid
; /* Group ID. */
57 char *pw_gecos
; /* Real name. */
58 char *pw_dir
; /* Home directory. */
59 char *pw_shell
; /* Shell program. */
63 #if defined __USE_SVID || defined __USE_GNU
69 #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN_EXTENDED
70 /* Rewind the password-file stream.
72 This function is a possible cancellation point and therefore not
73 marked with __THROW. */
74 extern void setpwent (void);
76 /* Close the password-file stream.
78 This function is a possible cancellation point and therefore not
79 marked with __THROW. */
80 extern void endpwent (void);
82 /* Read an entry from the password-file stream, opening it if necessary.
84 This function is a possible cancellation point and therefore not
85 marked with __THROW. */
86 extern struct passwd
*getpwent (void);
90 /* Read an entry from STREAM.
92 This function is not part of POSIX and therefore no official
93 cancellation point. But due to similarity with an POSIX interface
94 or due to the implementation it is a cancellation point and
95 therefore not marked with __THROW. */
96 extern struct passwd
*fgetpwent (FILE *__stream
);
98 /* Write the given entry onto the given stream.
100 This function is not part of POSIX and therefore no official
101 cancellation point. But due to similarity with an POSIX interface
102 or due to the implementation it is a cancellation point and
103 therefore not marked with __THROW. */
104 extern int putpwent (const struct passwd
*__restrict __p
,
105 FILE *__restrict __f
);
108 /* Search for an entry with a matching user ID.
110 This function is a possible cancellation point and therefore not
111 marked with __THROW. */
112 extern struct passwd
*getpwuid (__uid_t __uid
);
114 /* Search for an entry with a matching username.
116 This function is a possible cancellation point and therefore not
117 marked with __THROW. */
118 extern struct passwd
*getpwnam (const char *__name
);
120 #if defined __USE_POSIX || defined __USE_MISC
123 /* Reasonable value for the buffer sized used in the reentrant
124 functions below. But better use `sysconf'. */
125 # define NSS_BUFLEN_PASSWD 1024
128 /* Reentrant versions of some of the functions above.
130 PLEASE NOTE: the `getpwent_r' function is not (yet) standardized.
131 The interface may change in later versions of this library. But
132 the interface is designed following the principals used for the
133 other reentrant functions so the chances are good this is what the
134 POSIX people would choose. */
136 # if defined __USE_SVID || defined __USE_MISC
137 /* This function is not part of POSIX and therefore no official
138 cancellation point. But due to similarity with an POSIX interface
139 or due to the implementation it is a cancellation point and
140 therefore not marked with __THROW. */
141 extern int getpwent_r (struct passwd
*__restrict __resultbuf
,
142 char *__restrict __buffer
, size_t __buflen
,
143 struct passwd
**__restrict __result
);
146 extern int getpwuid_r (__uid_t __uid
,
147 struct passwd
*__restrict __resultbuf
,
148 char *__restrict __buffer
, size_t __buflen
,
149 struct passwd
**__restrict __result
);
151 extern int getpwnam_r (const char *__restrict __name
,
152 struct passwd
*__restrict __resultbuf
,
153 char *__restrict __buffer
, size_t __buflen
,
154 struct passwd
**__restrict __result
);
158 /* Read an entry from STREAM. This function is not standardized and
161 This function is not part of POSIX and therefore no official
162 cancellation point. But due to similarity with an POSIX interface
163 or due to the implementation it is a cancellation point and
164 therefore not marked with __THROW. */
165 extern int fgetpwent_r (FILE *__restrict __stream
,
166 struct passwd
*__restrict __resultbuf
,
167 char *__restrict __buffer
, size_t __buflen
,
168 struct passwd
**__restrict __result
);
171 #endif /* POSIX or reentrant */
174 /* Re-construct the password-file line for the given uid
175 in the given buffer. This knows the format that the caller
176 will expect, but this need not be the format of the password file.
178 This function is not part of POSIX and therefore no official
179 cancellation point. But due to similarity with an POSIX interface
180 or due to the implementation it is a cancellation point and
181 therefore not marked with __THROW. */
182 extern int getpw (__uid_t __uid
, char *__buffer
);