Overhaul the use of nsdispatch(3) by public APIs so that the back-end

methods use va_list in a manner that is directly related to the public API.
This makes it much easier to write dynamic nsswitch backends for getpwent(3).
Per my proposal on tech-userlevel.

Implement getpwgid_r() and getpwnam_r() APIs per the POSIX 1003.1, 2004 Ed.
These aren't fully reentrant or threadsafe yet, because the compat stuff
currently uses non-reentrant data sources (getnetgrent(3), getpwent(3)),
and there is probably some locking to be improved in the backends.
This will be fixed in the near future.
We also need to add _SC_GETPW_R_SIZE_MAX to sysconf(3).

Fix the compat `+' prototype override so getpwnam(3) and getpwuid(3) DTRT.

Improve the description of pw_class and pw_gecos.
This commit is contained in:
lukem 2004-10-05 04:45:54 +00:00
parent 557877d024
commit 45a7a69275
4 changed files with 2112 additions and 1000 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: pwd.h,v 1.33 2004/06/20 22:20:14 jmc Exp $ */
/* $NetBSD: pwd.h,v 1.34 2004/10/05 04:45:54 lukem Exp $ */
/*-
* Copyright (c) 1989, 1993
@ -110,8 +110,8 @@ struct passwd {
uid_t pw_uid; /* user uid */
gid_t pw_gid; /* user gid */
time_t pw_change; /* password change time */
__aconst char *pw_class; /* user access class */
__aconst char *pw_gecos; /* Honeywell login info */
__aconst char *pw_class; /* user login class */
__aconst char *pw_gecos; /* general information */
__aconst char *pw_dir; /* home directory */
__aconst char *pw_shell; /* default shell */
time_t pw_expire; /* account expiration */
@ -124,6 +124,10 @@ struct passwd *getpwnam __P((const char *));
struct passwd *getpwent __P((void));
void setpwent __P((void));
void endpwent __P((void));
int getpwnam_r __P((const char *, struct passwd *, char *, size_t,
struct passwd **));
int getpwuid_r __P((uid_t, struct passwd *, char *, size_t,
struct passwd **));
#endif
#if defined(_NETBSD_SOURCE)
char *bcrypt_gensalt(u_int8_t);

View File

@ -1,4 +1,4 @@
.\" $NetBSD: getpwent.3,v 1.23 2003/08/07 16:42:50 agc Exp $
.\" $NetBSD: getpwent.3,v 1.24 2004/10/05 04:45:54 lukem Exp $
.\"
.\" Copyright (c) 1988, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,13 +29,15 @@
.\"
.\" @(#)getpwent.3 8.2 (Berkeley) 12/11/93
.\"
.Dd April 25, 1999
.Dd October 5, 2004
.Dt GETPWENT 3
.Os
.Sh NAME
.Nm getpwent ,
.Nm getpwnam ,
.Nm getpwnam_r ,
.Nm getpwuid ,
.Nm getpwuid_r ,
.Nm setpassent ,
.Nm setpwent ,
.Nm endpwent
@ -47,9 +49,23 @@
.Ft struct passwd *
.Fn getpwent void
.Ft struct passwd *
.Fn getpwnam "const char *login"
.Fn getpwnam "const char *name"
.Fo getpwnam_r
.Fa "const char *name"
.Fa "struct passwd *pw"
.Fa "char *buffer"
.Fa "size_t buflen"
.Fa "struct passwd **result"
.Fc
.Ft struct passwd *
.Fn getpwuid "uid_t uid"
.Fo getpwuid_r
.Fa "uid_t uid"
.Fa "struct passwd *pw"
.Fa "char *buffer"
.Fa "size_t buflen"
.Fa "struct passwd **result"
.Fc
.Ft int
.Fn setpassent "int stayopen"
.Ft void
@ -58,7 +74,7 @@
.Fn endpwent void
.Sh DESCRIPTION
These functions
operate on the password database file
operate on the password database
which is described
in
.Xr passwd 5 .
@ -74,8 +90,8 @@ struct passwd {
uid_t pw_uid; /* user uid */
gid_t pw_gid; /* user gid */
time_t pw_change; /* password change time */
char *pw_class; /* user access class */
char *pw_gecos; /* Honeywell login info */
char *pw_class; /* user login class */
char *pw_gecos; /* general information */
char *pw_dir; /* home directory */
char *pw_shell; /* default shell */
time_t pw_expire; /* account expiration */
@ -86,8 +102,35 @@ The functions
.Fn getpwnam
and
.Fn getpwuid
search the password database for the given login name or user uid,
search the password database for the given user name or user id,
respectively, always returning the first one encountered.
Identical user names or user ids may result in undefined behavior.
.Pp
The functions
.Fn getpwnam_r
and
.Fn getpwuid_r
search the password database for the given user name pointed to by
.Ar name
or the user id pointed to by
.Ar uid ,
respectively, updating the contents of
.Ar pw
and storing a pointer to that in
.Ar result ,
and returning 0.
Storage used by
.Ar pw
is allocated from
.Ar buffer ,
which is
.Ar buflen
bytes in size.
If an error occurs,
an error number will be returned and
.Ar result
will point to null.
Identical user names or user ids may result in undefined behavior.
.Pp
The
.Fn getpwent
@ -170,9 +213,14 @@ A Version 7 format password file
.Xr vipw 8
.Sh STANDARDS
The
.Fn getpwnam
.Fn endpwent ,
.Fn getpwent ,
.Fn getpwnam ,
.Fn getpwnam_r ,
.Fn getpwuid ,
.Fn getpwuid_r ,
and
.Fn getpwuid
.Fn setpwent
functions conform to
.St -p1003.1-90 .
.Sh HISTORY
@ -189,6 +237,12 @@ The
.Nm setpassent
function appeared in
.Bx 4.3 Reno .
The functions
.Fn getpwnam_r
and
.Fn getpwuid_r
appeared in
.Nx 3.0 .
.Sh BUGS
The functions
.Fn getpwent ,

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: namespace.h,v 1.94 2004/10/04 04:16:26 lukem Exp $ */
/* $NetBSD: namespace.h,v 1.95 2004/10/05 04:45:54 lukem Exp $ */
/*-
* Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@ -255,7 +255,9 @@
#define getprotoent_r _getprotoent_r
#define getpwent _getpwent
#define getpwnam _getpwnam
#define getpwnam_r _getpwnam_r
#define getpwuid _getpwuid
#define getpwuid_r _getpwuid_r
#define getrpcbyname _getrpcbyname
#define getrpcbyname_r _getrpcbyname_r
#define getrpcbynumber _getrpcbynumber