1GETPWENT(3)                Library Functions Manual                GETPWENT(3)
2
3
4

NAME

6       getpwent,  getpwuid,  getpwnam,  setpwent, endpwent - get password file
7       entry
8

SYNOPSIS

10       #include <pwd.h>
11
12       struct passwd *getpwent();
13
14       struct passwd *getpwuid(uid) int uid;
15
16       struct passwd *getpwnam(name) char *name;
17
18       int setpwent();
19
20       int endpwent();
21

DESCRIPTION

23       Getpwent, getpwuid and getpwnam each return a pointer to an object with
24       the  following  structure containing the broken-out fields of a line in
25       the password file.
26
27              /* Copyright (C) 1991,1992,1995-2001,2003,2004,2012
28                 Free Software Foundation, Inc.
29                 This file is part of the GNU C Library.
30
31                 The GNU C Library is free software; you can redistribute it and/or
32                 modify it under the terms of the GNU Lesser General Public
33                 License as published by the Free Software Foundation; either
34                 version 2.1 of the License, or (at your option) any later version.
35
36                 The GNU C Library is distributed in the hope that it will be useful,
37                 but WITHOUT ANY WARRANTY; without even the implied warranty of
38                 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
39                 Lesser General Public License for more details.
40
41                 You should have received a copy of the GNU Lesser General Public
42                 License along with the GNU C Library; if not, see
43                 <http://www.gnu.org/licenses/>.  */
44
45              /*
46               *   POSIX Standard: 9.2.2 User Database Access   <pwd.h>
47               */
48
49              #ifndef   _PWD_H
50              #define   _PWD_H    1
51
52              #include <features.h>
53
54              __BEGIN_DECLS
55
56              #include <bits/types.h>
57
58              #define __need_size_t
59              #include <stddef.h>
60
61              #if defined __USE_XOPEN || defined __USE_XOPEN2K
62              /* The Single Unix specification says that some more types are
63                 available here.  */
64              # ifndef __gid_t_defined
65              typedef __gid_t gid_t;
66              #  define __gid_t_defined
67              # endif
68
69              # ifndef __uid_t_defined
70              typedef __uid_t uid_t;
71              #  define __uid_t_defined
72              # endif
73              #endif
74
75              /* The passwd structure.  */
76              struct passwd
77              {
78                char *pw_name;         /* Username.  */
79                char *pw_passwd;       /* Password.  */
80                __uid_t pw_uid;        /* User ID.  */
81                __gid_t pw_gid;        /* Group ID.  */
82                char *pw_gecos;        /* Real name.  */
83                char *pw_dir;               /* Home directory.  */
84                char *pw_shell;        /* Shell program.  */
85              };
86
87
88              #if defined __USE_SVID || defined __USE_GNU
89              # define __need_FILE
90              # include <stdio.h>
91              #endif
92
93
94              #if defined __USE_SVID || defined __USE_MISC || defined __USE_XOPEN_EXTENDED
95              /* Rewind the password-file stream.
96
97                 This function is a possible cancellation point and therefore not
98                 marked with __THROW.  */
99              extern void setpwent (void);
100
101              /* Close the password-file stream.
102
103                 This function is a possible cancellation point and therefore not
104                 marked with __THROW.  */
105              extern void endpwent (void);
106
107              /* Read an entry from the password-file stream, opening it if necessary.
108
109                 This function is a possible cancellation point and therefore not
110                 marked with __THROW.  */
111              extern struct passwd *getpwent (void);
112              #endif
113
114              #ifdef    __USE_SVID
115              /* Read an entry from STREAM.
116
117                 This function is not part of POSIX and therefore no official
118                 cancellation point.  But due to similarity with an POSIX interface
119                 or due to the implementation it is a cancellation point and
120                 therefore not marked with __THROW.  */
121              extern struct passwd *fgetpwent (FILE *__stream);
122
123              /* Write the given entry onto the given stream.
124
125                 This function is not part of POSIX and therefore no official
126                 cancellation point.  But due to similarity with an POSIX interface
127                 or due to the implementation it is a cancellation point and
128                 therefore not marked with __THROW.  */
129              extern int putpwent (const struct passwd *__restrict __p,
130                             FILE *__restrict __f);
131              #endif
132
133              /* Search for an entry with a matching user ID.
134
135                 This function is a possible cancellation point and therefore not
136                 marked with __THROW.  */
137              extern struct passwd *getpwuid (__uid_t __uid);
138
139              /* Search for an entry with a matching username.
140
141                 This function is a possible cancellation point and therefore not
142                 marked with __THROW.  */
143              extern struct passwd *getpwnam (const char *__name);
144
145              #if defined __USE_POSIX || defined __USE_MISC
146
147              # ifdef __USE_MISC
148              /* Reasonable value for the buffer sized used in the reentrant
149                 functions below.  But better use `sysconf'.  */
150              #  define NSS_BUFLEN_PASSWD   1024
151              # endif
152
153              /* Reentrant versions of some of the functions above.
154
155                 PLEASE NOTE: the `getpwent_r' function is not (yet) standardized.
156                 The interface may change in later versions of this library.  But
157                 the interface is designed following the principals used for the
158                 other reentrant functions so the chances are good this is what the
159                 POSIX people would choose.  */
160
161              # if defined __USE_SVID || defined __USE_MISC
162              /* This function is not part of POSIX and therefore no official
163                 cancellation point.  But due to similarity with an POSIX interface
164                 or due to the implementation it is a cancellation point and
165                 therefore not marked with __THROW.  */
166              extern int getpwent_r (struct passwd *__restrict __resultbuf,
167                               char *__restrict __buffer, size_t __buflen,
168                               struct passwd **__restrict __result);
169              # endif
170
171              extern int getpwuid_r (__uid_t __uid,
172                               struct passwd *__restrict __resultbuf,
173                               char *__restrict __buffer, size_t __buflen,
174                               struct passwd **__restrict __result);
175
176              extern int getpwnam_r (const char *__restrict __name,
177                               struct passwd *__restrict __resultbuf,
178                               char *__restrict __buffer, size_t __buflen,
179                               struct passwd **__restrict __result);
180
181
182              # ifdef   __USE_SVID
183              /* Read an entry from STREAM.  This function is not standardized and
184                 probably never will.
185
186                 This function is not part of POSIX and therefore no official
187                 cancellation point.  But due to similarity with an POSIX interface
188                 or due to the implementation it is a cancellation point and
189                 therefore not marked with __THROW.  */
190              extern int fgetpwent_r (FILE *__restrict __stream,
191                             struct passwd *__restrict __resultbuf,
192                             char *__restrict __buffer, size_t __buflen,
193                             struct passwd **__restrict __result);
194              # endif
195
196              #endif    /* POSIX or reentrant */
197
198              #ifdef __USE_GNU
199              /* Re-construct the password-file line for the given uid
200                 in the given buffer.  This knows the format that the caller
201                 will expect, but this need not be the format of the password file.
202
203                 This function is not part of POSIX and therefore no official
204                 cancellation point.  But due to similarity with an POSIX interface
205                 or due to the implementation it is a cancellation point and
206                 therefore not marked with __THROW.  */
207              extern int getpw (__uid_t __uid, char *__buffer);
208              #endif
209
210              __END_DECLS
211
212              #endif /* pwd.h  */
213
214       The fields pw_quota and pw_comment are unused; the others have meanings
215       described in passwd(5).
216
217       Getpwent  reads the next line (opening the file if necessary); setpwent
218       rewinds the file; endpwent closes it.
219
220       Getpwuid and getpwnam search from the beginning until a matching uid or
221       name is found (or until EOF is encountered).
222

FILES

224       /etc/passwd
225

SEE ALSO

227       getlogin(3), getgrent(3), passwd(5)
228

DIAGNOSTICS

230       Null pointer (0) returned on EOF or error.
231

BUGS

233       All  information  is contained in a static area so it must be copied if
234       it is to be saved.
235
236
237
238                                                                   GETPWENT(3)
Impressum