2005-05-25 14:05:22 +04:00
|
|
|
.\" $NetBSD: getpwent.3,v 1.35 2005/05/25 10:05:22 wiz Exp $
|
1995-02-27 07:12:15 +03:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1988, 1991, 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
2003-08-07 20:42:00 +04:00
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
1993-03-21 12:45:37 +03:00
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
1995-02-27 07:12:15 +03:00
|
|
|
.\" @(#)getpwent.3 8.2 (Berkeley) 12/11/93
|
1993-03-21 12:45:37 +03:00
|
|
|
.\"
|
2005-05-25 14:05:22 +04:00
|
|
|
.Dd May 24, 2005
|
1993-03-21 12:45:37 +03:00
|
|
|
.Dt GETPWENT 3
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm getpwent ,
|
2005-04-04 18:19:55 +04:00
|
|
|
.Nm getpwent_r ,
|
1993-03-21 12:45:37 +03:00
|
|
|
.Nm getpwnam ,
|
2004-10-05 08:45:54 +04:00
|
|
|
.Nm getpwnam_r ,
|
1993-03-21 12:45:37 +03:00
|
|
|
.Nm getpwuid ,
|
2004-10-05 08:45:54 +04:00
|
|
|
.Nm getpwuid_r ,
|
1993-03-21 12:45:37 +03:00
|
|
|
.Nm setpassent ,
|
|
|
|
.Nm setpwent ,
|
|
|
|
.Nm endpwent
|
|
|
|
.Nd password database operations
|
1998-02-05 21:45:17 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libc
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In pwd.h
|
1993-03-21 12:45:37 +03:00
|
|
|
.Ft struct passwd *
|
|
|
|
.Fn getpwent void
|
2005-04-04 18:19:55 +04:00
|
|
|
.Ft int
|
|
|
|
.Fo getpwent_r
|
|
|
|
.Fa "struct passwd *pw"
|
|
|
|
.Fa "char *buffer"
|
|
|
|
.Fa "size_t buflen"
|
|
|
|
.Fa "struct passwd **result"
|
|
|
|
.Fc
|
1993-03-21 12:45:37 +03:00
|
|
|
.Ft struct passwd *
|
2004-10-05 08:45:54 +04:00
|
|
|
.Fn getpwnam "const char *name"
|
2004-10-05 17:52:09 +04:00
|
|
|
.Ft int
|
2004-10-05 08:45:54 +04:00
|
|
|
.Fo getpwnam_r
|
|
|
|
.Fa "const char *name"
|
|
|
|
.Fa "struct passwd *pw"
|
|
|
|
.Fa "char *buffer"
|
|
|
|
.Fa "size_t buflen"
|
|
|
|
.Fa "struct passwd **result"
|
|
|
|
.Fc
|
1993-03-21 12:45:37 +03:00
|
|
|
.Ft struct passwd *
|
2001-09-16 06:30:23 +04:00
|
|
|
.Fn getpwuid "uid_t uid"
|
2004-10-05 17:52:09 +04:00
|
|
|
.Ft int
|
2004-10-05 08:45:54 +04:00
|
|
|
.Fo getpwuid_r
|
|
|
|
.Fa "uid_t uid"
|
|
|
|
.Fa "struct passwd *pw"
|
|
|
|
.Fa "char *buffer"
|
|
|
|
.Fa "size_t buflen"
|
|
|
|
.Fa "struct passwd **result"
|
|
|
|
.Fc
|
1993-03-21 12:45:37 +03:00
|
|
|
.Ft int
|
2004-10-05 17:52:09 +04:00
|
|
|
.Fn setpassent "int stayopen"
|
1993-10-26 01:21:36 +03:00
|
|
|
.Ft void
|
1993-03-21 12:45:37 +03:00
|
|
|
.Fn setpwent void
|
|
|
|
.Ft void
|
|
|
|
.Fn endpwent void
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
These functions
|
2004-10-05 08:45:54 +04:00
|
|
|
operate on the password database
|
1993-03-21 12:45:37 +03:00
|
|
|
which is described
|
|
|
|
in
|
|
|
|
.Xr passwd 5 .
|
|
|
|
Each entry in the database is defined by the structure
|
|
|
|
.Ar passwd
|
|
|
|
found in the include
|
|
|
|
file
|
|
|
|
.Aq Pa pwd.h :
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
struct passwd {
|
|
|
|
char *pw_name; /* user name */
|
|
|
|
char *pw_passwd; /* encrypted password */
|
|
|
|
uid_t pw_uid; /* user uid */
|
|
|
|
gid_t pw_gid; /* user gid */
|
|
|
|
time_t pw_change; /* password change time */
|
2004-10-05 08:45:54 +04:00
|
|
|
char *pw_class; /* user login class */
|
|
|
|
char *pw_gecos; /* general information */
|
1993-03-21 12:45:37 +03:00
|
|
|
char *pw_dir; /* home directory */
|
|
|
|
char *pw_shell; /* default shell */
|
|
|
|
time_t pw_expire; /* account expiration */
|
|
|
|
};
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
The functions
|
|
|
|
.Fn getpwnam
|
|
|
|
and
|
|
|
|
.Fn getpwuid
|
2005-04-04 18:19:55 +04:00
|
|
|
search the password database for the given user name pointed to by
|
|
|
|
.Ar name
|
|
|
|
or user id pointed to by
|
|
|
|
.Ar uid
|
1993-03-21 12:45:37 +03:00
|
|
|
respectively, always returning the first one encountered.
|
2004-10-05 08:45:54 +04:00
|
|
|
Identical user names or user ids may result in undefined behavior.
|
|
|
|
.Pp
|
2005-04-04 18:19:55 +04:00
|
|
|
The
|
|
|
|
.Fn getpwent
|
|
|
|
function
|
|
|
|
sequentially reads the password database and is intended for programs
|
|
|
|
that wish to process the complete list of users.
|
|
|
|
.Pp
|
2004-10-05 08:45:54 +04:00
|
|
|
The functions
|
2005-04-04 18:19:55 +04:00
|
|
|
.Fn getpwnam_r ,
|
|
|
|
.Fn getpwuid_r ,
|
2004-10-05 08:45:54 +04:00
|
|
|
and
|
2005-04-04 18:19:55 +04:00
|
|
|
.Fn getpwent_r
|
|
|
|
act like their non re-entrant counterparts, updating the contents of
|
2004-10-05 08:45:54 +04:00
|
|
|
.Ar pw
|
|
|
|
and storing a pointer to that in
|
|
|
|
.Ar result ,
|
2005-04-19 08:26:16 +04:00
|
|
|
and returning
|
|
|
|
.Dv 0 .
|
2004-10-05 08:45:54 +04:00
|
|
|
Storage used by
|
|
|
|
.Ar pw
|
|
|
|
is allocated from
|
|
|
|
.Ar buffer ,
|
|
|
|
which is
|
|
|
|
.Ar buflen
|
|
|
|
bytes in size.
|
2005-04-19 08:26:16 +04:00
|
|
|
If the requested entry cannot be found,
|
|
|
|
.Ar result
|
|
|
|
will point to
|
|
|
|
.Dv NULL
|
|
|
|
and
|
|
|
|
.Dv 0
|
|
|
|
will be returned.
|
2004-10-05 08:45:54 +04:00
|
|
|
If an error occurs,
|
2005-04-19 08:26:16 +04:00
|
|
|
a non-zero error number will be returned and
|
2004-10-05 08:45:54 +04:00
|
|
|
.Ar result
|
2005-04-19 08:26:16 +04:00
|
|
|
will point to
|
|
|
|
.Dv NULL .
|
2005-04-04 18:19:55 +04:00
|
|
|
Calling
|
|
|
|
.Fn getpwent_r
|
2005-04-04 22:24:21 +04:00
|
|
|
from multiple threads will result in each thread reading a disjoint portion
|
2005-04-04 18:19:55 +04:00
|
|
|
of the password database.
|
1993-03-21 12:45:37 +03:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn setpassent
|
|
|
|
function
|
|
|
|
accomplishes two purposes.
|
|
|
|
First, it causes
|
|
|
|
.Fn getpwent
|
2005-04-04 22:26:19 +04:00
|
|
|
to
|
|
|
|
.Dq rewind
|
|
|
|
to the beginning of the database.
|
1993-03-21 12:45:37 +03:00
|
|
|
Additionally, if
|
|
|
|
.Fa stayopen
|
|
|
|
is non-zero, file descriptors are left open, significantly speeding
|
1999-04-25 17:45:02 +04:00
|
|
|
up subsequent accesses for all of the functions.
|
1993-03-21 12:45:37 +03:00
|
|
|
(This latter functionality is unnecessary for
|
|
|
|
.Fn getpwent
|
|
|
|
as it doesn't close its file descriptors by default.)
|
|
|
|
.Pp
|
|
|
|
It is dangerous for long-running programs to keep the file descriptors
|
1995-02-27 07:12:15 +03:00
|
|
|
open as the database will become out of date if it is updated while the
|
1993-03-21 12:45:37 +03:00
|
|
|
program is running.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn setpwent
|
|
|
|
function
|
1993-10-26 02:36:51 +03:00
|
|
|
is equivalent to
|
1993-03-21 12:45:37 +03:00
|
|
|
.Fn setpassent
|
|
|
|
with an argument of zero.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn endpwent
|
|
|
|
function
|
|
|
|
closes any open files.
|
|
|
|
.Pp
|
2005-04-04 22:26:19 +04:00
|
|
|
These functions have been written to
|
|
|
|
.Dq shadow
|
|
|
|
the password file, e.g. allow only certain programs to have access
|
|
|
|
to the encrypted password.
|
1993-03-21 12:45:37 +03:00
|
|
|
If the process which calls them has an effective uid of 0, the encrypted
|
1994-01-11 02:32:20 +03:00
|
|
|
password will be returned, otherwise, the password field of the returned
|
1993-03-21 12:45:37 +03:00
|
|
|
structure will point to the string
|
|
|
|
.Ql * .
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
The functions
|
|
|
|
.Fn getpwent ,
|
|
|
|
.Fn getpwnam ,
|
|
|
|
and
|
|
|
|
.Fn getpwuid ,
|
|
|
|
return a valid pointer to a passwd structure on success
|
2005-04-19 08:26:16 +04:00
|
|
|
and a
|
2005-04-19 08:32:58 +04:00
|
|
|
.Dv NULL
|
2005-04-19 08:26:16 +04:00
|
|
|
pointer if the entry was not found or an error occurs.
|
1993-10-26 02:36:51 +03:00
|
|
|
The
|
1993-03-21 12:45:37 +03:00
|
|
|
.Fn setpassent
|
1993-10-26 02:36:51 +03:00
|
|
|
function returns 0 on failure and 1 on success.
|
1993-03-21 12:45:37 +03:00
|
|
|
The
|
|
|
|
.Fn endpwent
|
2001-09-16 06:30:23 +04:00
|
|
|
and
|
1993-10-26 02:36:51 +03:00
|
|
|
.Fn setpwent
|
|
|
|
functions
|
|
|
|
have no return value.
|
2005-03-31 08:17:05 +04:00
|
|
|
The functions
|
|
|
|
.Fn getpwnam_r ,
|
2005-04-04 18:19:55 +04:00
|
|
|
.Fn getpwuid_r ,
|
2005-03-31 08:17:05 +04:00
|
|
|
and
|
2005-04-04 18:19:55 +04:00
|
|
|
.Fn getpwent_r
|
2005-03-31 08:17:05 +04:00
|
|
|
return
|
|
|
|
.Dv 0
|
2005-04-19 14:00:50 +04:00
|
|
|
on success or entry not found, and non-zero on failure.
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh FILES
|
|
|
|
.Bl -tag -width /etc/master.passwd -compact
|
1995-01-03 18:57:32 +03:00
|
|
|
.It Pa /etc/pwd.db
|
1993-03-21 12:45:37 +03:00
|
|
|
The insecure password database file
|
1995-01-03 18:57:32 +03:00
|
|
|
.It Pa /etc/spwd.db
|
1993-03-21 12:45:37 +03:00
|
|
|
The secure password database file
|
|
|
|
.It Pa /etc/master.passwd
|
|
|
|
The current password file
|
|
|
|
.It Pa /etc/passwd
|
|
|
|
A Version 7 format password file
|
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
1997-07-14 06:07:10 +04:00
|
|
|
.Xr getlogin 2 ,
|
1993-03-21 12:45:37 +03:00
|
|
|
.Xr getgrent 3 ,
|
1999-01-16 10:59:39 +03:00
|
|
|
.Xr nsswitch.conf 5 ,
|
1993-03-21 12:45:37 +03:00
|
|
|
.Xr passwd 5 ,
|
2000-07-11 16:12:53 +04:00
|
|
|
.Xr passwd.conf 5 ,
|
1993-03-21 12:45:37 +03:00
|
|
|
.Xr pwd_mkdb 8 ,
|
|
|
|
.Xr vipw 8
|
1997-07-15 03:19:39 +04:00
|
|
|
.Sh STANDARDS
|
|
|
|
The
|
2005-05-24 22:01:36 +04:00
|
|
|
.Fn getpwnam
|
|
|
|
and
|
|
|
|
.Fn getpwuid ,
|
|
|
|
functions conform to
|
|
|
|
.St -p1003.1-90 .
|
|
|
|
The
|
|
|
|
.Fn getpwnam_r
|
|
|
|
and
|
|
|
|
.Fn getpwuid_r
|
|
|
|
functions conform to
|
|
|
|
.St -p1003.1c-95 .
|
|
|
|
The
|
2004-10-05 08:45:54 +04:00
|
|
|
.Fn endpwent ,
|
|
|
|
.Fn getpwent ,
|
1997-07-15 03:19:39 +04:00
|
|
|
and
|
2004-10-05 08:45:54 +04:00
|
|
|
.Fn setpwent
|
1997-07-15 03:19:39 +04:00
|
|
|
functions conform to
|
2005-05-24 22:01:36 +04:00
|
|
|
.St -xpg4.2
|
|
|
|
and
|
|
|
|
.St -p1003.1-2004
|
|
|
|
(XSI extension).
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm getpwent ,
|
|
|
|
.Nm getpwnam ,
|
|
|
|
.Nm getpwuid ,
|
2001-09-16 06:57:03 +04:00
|
|
|
.Nm setpwent ,
|
1993-03-21 12:45:37 +03:00
|
|
|
and
|
|
|
|
.Nm endpwent
|
|
|
|
functions appeared in
|
|
|
|
.At v7 .
|
|
|
|
The
|
|
|
|
.Nm setpassent
|
|
|
|
function appeared in
|
|
|
|
.Bx 4.3 Reno .
|
2004-10-05 08:45:54 +04:00
|
|
|
The functions
|
|
|
|
.Fn getpwnam_r
|
|
|
|
and
|
|
|
|
.Fn getpwuid_r
|
|
|
|
appeared in
|
|
|
|
.Nx 3.0 .
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh BUGS
|
|
|
|
The functions
|
|
|
|
.Fn getpwent ,
|
|
|
|
.Fn getpwnam ,
|
|
|
|
and
|
|
|
|
.Fn getpwuid ,
|
|
|
|
leave their results in an internal static object and return
|
2002-10-01 20:48:34 +04:00
|
|
|
a pointer to that object.
|
|
|
|
Subsequent calls to any of these functions will modify the same object.
|
1993-03-21 12:45:37 +03:00
|
|
|
.Pp
|
1999-04-25 17:45:02 +04:00
|
|
|
The functions
|
1993-03-21 12:45:37 +03:00
|
|
|
.Fn getpwent ,
|
|
|
|
.Fn endpwent ,
|
|
|
|
.Fn setpassent ,
|
|
|
|
and
|
|
|
|
.Fn setpwent
|
|
|
|
are fairly useless in a networked environment and should be
|
|
|
|
avoided, if possible.
|
1999-04-25 17:45:02 +04:00
|
|
|
.Fn getpwent
|
|
|
|
makes no attempt to suppress duplicate information if multiple
|
|
|
|
sources are specified in
|
2005-04-04 22:26:19 +04:00
|
|
|
.Xr nsswitch.conf 5 .
|
1993-03-21 12:45:37 +03:00
|
|
|
.Sh COMPATIBILITY
|
|
|
|
The historic function
|
1998-04-29 00:11:33 +04:00
|
|
|
.Fn setpwfile
|
1997-03-08 16:36:38 +03:00
|
|
|
which allowed the specification of alternative password databases,
|
1993-03-21 12:45:37 +03:00
|
|
|
has been deprecated and is no longer available.
|