rework get{gr,pw,fs}ent to all be about the same;
[unix-history] / usr / src / lib / libc / gen / getpwent.3
CommitLineData
62ab31a2
KB
1.\" Copyright (c) 1988 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)getpwent.3 6.4 (Berkeley) %G%
4e6e003a 6.\"
3fb9eae6 7.TH GETPWENT 3 ""
4e6e003a
KM
8.AT 3
9.SH NAME
3fb9eae6 10getpwent, getpwuid, getpwnam, setpwent, endpwent, setpwfile \- get password file entry
4e6e003a
KM
11.SH SYNOPSIS
12.nf
13.B #include <pwd.h>
14.PP
4e6e003a 15.B struct passwd *getpwuid(uid)
62ab31a2 16.B uid_t uid;
4e6e003a
KM
17.PP
18.B struct passwd *getpwnam(name)
19.B char *name;
20.PP
1e00f4a7
KM
21.B struct passwd *getpwent()
22.PP
62ab31a2 23.B void setpwent()
4e6e003a 24.PP
62ab31a2 25.B void endpwent()
3fb9eae6
KM
26.PP
27.B setpwfile(name)
28.B char *name;
4e6e003a
KM
29.fi
30.SH DESCRIPTION
31.I Getpwent,
32.I getpwuid
33and
34.I getpwnam
62ab31a2
KB
35each return a pointer to an object with the following structure,
36containing the broken-out fields of a line in the password file,
37as described in
38.IR < pwd.h > .
4e6e003a
KM
39.RS
40.PP
41.nf
62ab31a2
KB
42struct passwd {
43 char *pw_name;
44 char *pw_passwd;
45 uid_t pw_uid;
46 gid_t pw_gid;
47 int pw_quota;
48 char *pw_comment;
49 char *pw_gecos;
50 char *pw_dir;
51 char *pw_shell;
52};
4e6e003a
KM
53.ft R
54.ad
55.fi
56.RE
57.PP
58The fields
59.I pw_quota
60and
61.I pw_comment
62are unused; the others have meanings described in
63.IR passwd (5).
64.PP
62ab31a2
KB
65.I Setpwfile
66changes the default password file to
67.IR name ,
68thus allowing usage of alternate password files. If \fIndbm\fP databases
69are available for any password files, they are used, otherwise the file
70itself is linearly searched.
71.PP
1e00f4a7 72.I Setpwent
62ab31a2
KB
73opens the database or file (closing any previously opened database or file)
74or rewinds it if it is already open.
75.PP
76.I Endpwent
77closes any open databases or files.
78.PP
1e00f4a7
KM
79.I Getpwuid
80and
81.I getpwnam
62ab31a2 82search the entire database or file (opening it if necessary) for a matching
1e00f4a7
KM
83.I uid
84or
85.IR name .
1e00f4a7
KM
86.PP
87For programs wishing to read the entire database,
88.I getpwent
62ab31a2 89reads the next entry (opening the database or file if necessary).
4e6e003a
KM
90.SH FILES
91/etc/passwd
92.SH "SEE ALSO"
93getlogin(3), getgrent(3), passwd(5)
94.SH DIAGNOSTICS
c5892565
KM
95The routines
96.IR getpwent ,
97.IR getpwuid ,
98and
99.IR getpwnam ,
100return a null pointer (0) on EOF or error.
62ab31a2
KB
101.I Setpwent
102returns 0 on failure, 1 on success.
103.I Endpwent
104and
105.I setpwfile
106have no return value.
4e6e003a 107.SH BUGS
62ab31a2
KB
108All information is contained in a static area so it must be
109copied if it is to be saved.