Home | History | Annotate | Download | only in gen
History log of /src/lib/libc/gen/getpwent.c
RevisionDateAuthorComments
 1.84  20-Jan-2024  christos Catch up with all the lint warnings since exit on warning was disabled.
Disable 'missing header declaration' and 'nested extern' warnings for now.
 1.83  19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.82  14-Jan-2017  christos don't include machine/param.h <sys/param.h> already does WTF?
 1.81  08-Sep-2012  dholland branches: 1.81.14;
Revert previous temporary measure and fix the assertion properly instead.
 1.80  07-Sep-2012  dholland Disable bogus _DIAGASSERT.
 1.79  29-Mar-2012  christos PR/46279: Dr. W. Stukenbrock: Off-by-one in buffer length check and make sure
that the password fits in the supplied buffer.
 1.78  29-Mar-2012  christos PR?40728: W. Stukenbrock: Fix various issues with NIS-netgroups in users
and groups.
 1.77  23-Mar-2010  drochner branches: 1.77.6; 1.77.8;
remove some stray __weak_aliases, where the target functions were
__RENAMEd due to the time_t/dev_t type changes, which caused bogus
references to compat functions
now a libc built with BUILDCOLD is usable
 1.76  11-Jan-2009  christos merge christos-time_t
 1.75  28-Apr-2008  martin branches: 1.75.8;
Remove clause 3 and 4 from TNF licenses
 1.74  03-Feb-2007  christos branches: 1.74.10;
make this compile with DIAGNOSTIC
 1.73  15-Oct-2006  christos fix incomplete initializers
 1.72  29-Jun-2006  ginsbach Fix YP lookup latency reported by Stephen M. Jones on tech-net. This is a
performance regression between 2.0 and 3.0. The passwd compat method was
incorrectly querying the NIS server with yp_first()/yp_next() rather than
using yp_match() with the correct key.
 1.71  19-Mar-2006  christos Coverity CID 708: Remove dead code.
 1.70  05-Jun-2005  lukem Cosmetic tweak previous; IMHO we don't need the XXX comment in this
case, since I prefer to NULL initialize variables in this situation.
 1.69  04-Jun-2005  he Add an initialization to appease -Wuninitialized. Apparently the
sparc64 compiler gets this wrong.
 1.68  19-Apr-2005  lukem getpw{ent,nam,uid}_r():
Return 0 "entry not found" and errno for other failures.
("entry not found" still sets *result to NULL).

Various backends:
don't set the retval to errno (or modify errno) for NS_NOTFOUND.

Per discussion with Klaus Klein.
 1.67  02-Apr-2005  christos PR/29849, PR/29850: Add getpwent_r and getgrent_r
 1.66  28-Feb-2005  lukem branches: 1.66.2;
Restore getpwent() behaviour prior to rev 1.57; skip dodgy NIS & DNS entries
rather than failing with NS_UNAVAIL when encountering them.
Fixes PR 29272 by Antoine Reilles.
 1.65  10-Nov-2004  lukem Use the common __nsdefaultFOO rather than private defaultFOO duplicates.
 1.64  10-Nov-2004  lukem Use _GETPW_R_SIZE_MAX from <limits.h> rather than defining a private version.
 1.63  01-Nov-2004  lukem default to "compat" not "files"
 1.62  29-Oct-2004  lukem #include "reentrant.h" instead of <threadlib.h>
 1.61  24-Oct-2004  lukem Protect access to all public functions via a mutex as some of the backends are
not reentrant (such as compat, because it uses the non reentrant getnetgrent(3)
to implement `+@netgrp' & `-@netgrp').
 1.60  11-Oct-2004  lukem Fix MKYP=no MKHESIOD=no build.
Rename an internal function to a more appropriate name.
 1.59  07-Oct-2004  lukem Ensure that _nis_start(&state) has been called before using PASSWD_BYNAME()
or PASSWD_BYUID(), otherwise state.maptype won't be correct and the wrong
map may be selected (e.g., "passwd.by*" instead of "master.passwd.by*").

Set _PASSWORD_NOWARN in flags to __pw_scan(), so libc won't display parse
errors to stderr. (This was the behaviour before my recent rototill.)

Fixes PR 27168 from Markus W Kilbinger.
 1.58  05-Oct-2004  lukem Use PASSWD_BYxxx(state) macros instead of "passwd.byxxx" to refer to
the NIS "passwd.by*" maps.
Fixes problem with "passwd_compat: nis" noted by Matthias Scheler.
 1.57  05-Oct-2004  lukem 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.
 1.56  26-Nov-2003  lukem Fix compile problem if -UYP -DHESIOD.
Noted on current-users by Srinivasa Kanduru.
 1.55  13-Oct-2003  agc Move Jason Downs's code from a 4-clause to a 3-clause licence by
removing the advertising clause. Diffs provided in PR 22410 by Joel
Baker, confirmed to the board by Jason Downs.

With additional thanks to Jason Thorpe.
 1.54  07-Aug-2003  agc Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.53  17-Nov-2002  itojun use strlcpy where it is more appropriate.
 1.52  11-Nov-2002  thorpej Fix signed/unsigned comparison warnings.
 1.51  26-May-2002  wiz __STDC__ is always defined on NetBSD.
 1.50  16-Apr-2002  groo botched strncpy -> strlcpy
from xs@kittenz.org
 1.49  12-Feb-2002  mycroft Just return an error if we try to look up a user name that's too long, rather
than trying to truncate. The previous truncation code actually set key.size
too large and caused a (non-exploitable) core dump inside DB.
 1.48  03-Oct-2000  enami branches: 1.48.2;
Reset allocated buffer size to 0 on allocation failure.
 1.47  02-Oct-2000  simonb Fix potential buffer overflow processing long password database entries.
Inspired by similar OpenBSD change.
 1.46  22-Jan-2000  mycroft branches: 1.46.4;
Delint.
Remove trailing ; from uses of __weak_alias(). The macro inserts this if
needed.
 1.45  16-Sep-1999  lukem * use _DIAGASSERT() to check pointer arguments against NULL and file
descriptors against -1 (as appropriate).
* add actual checks which to detect stuff that would trigger_DIAGASSERT(),
and attempt to return a sane error condition.
* knf some code
* remove some `register' decls.

the first two items result in the addition of code similar to the
following in various functions:

_DIAGASSERT(path != NULL)
#ifdef _DIAGNOSTIC
if (path == NULL) {
errno = EFAULT;
return (-1);
}
#endif
 1.44  27-Apr-1999  ross Unconditionalize `rval' declaration referenced in usr.bin/chpass/ via .PATH
 1.43  26-Apr-1999  lukem change dns_getpw() to skip dodgy entries when doing getpwent(), rather
than returning NS_UNAVAIL. this means that a -ve uid entry in hesiod
doesn't stop getpwent() in its tracks. it also brings it in line with
how nis_getpw() works as well in this situation.
problem tracked down (with much pain & suffereing) by simonb.

XXX: we currently have no support for -ve uids, and this is painful in
XXX: hetrogenous environment... (this -ve check is enforced in __pwscan())
 1.42  25-Apr-1999  lukem change getpwent() backends so that a flag (per source) is set once the
source has been exhausted. this allows getpwent() across multiple
sources (e.g, ``passwd: files nis'') to work correctly. the flags are
reset in setpassent()/endpwent().

this fixes a bug noted in [lib/7449] by thorpej, and tracked down to
getpwent() as being the culprit by simonb.
 1.41  18-Apr-1999  lukem specifically include stdarg/varargs.h
 1.40  26-Jan-1999  lukem branches: 1.40.2;
always compile in support for `compat' backends (even if !YP & !HESIOD),
and make it the responsibility of the backends to fallback to `files'
if !YP & !HESIOD. fixes chsh problem noted by billc@netbsd.org.
 1.39  25-Jan-1999  lukem convert from hes_*() -> hesiod_*()
 1.38  21-Jan-1999  mycroft Use the right map for Hesiod lookups by uid.
 1.37  20-Jan-1999  christos - remove unneeded casts
- remove unreachable code
- delint
 1.36  19-Jan-1999  lukem * `passwd' defaults to `compat', and `passwd_compat' defaults to `nis'
* constify ns_dtab defs
 1.35  19-Jan-1999  lukem * maximum limit of names is MAXLOGNAME not UT_NAMESIZE. fixes [bin/6847] from
scott ellis.
* convert to new nsdispatch(3)
 1.34  18-Jan-1999  lukem * fix _compat_getpw so that it returns _local_getpw(...) if there
isn't a `+' token in the files database.
(this bug probably crept in when a merge to current occurred)
* ensure that the _bad_getpw callbacks in __getpwcompat have an
argument for error reporting.
 1.33  16-Jan-1999  lukem fix some uid casts
 1.32  16-Jan-1999  lukem pull nsswitch up to main branch
 1.31  13-Nov-1998  christos avoid assignment of a read only location that lint does not pick, but gcc does.
 1.30  12-Nov-1998  christos delint
 1.29  26-Aug-1998  perry fix bcopy->memcpy with memcpy->memmove -- not strictly needed, but...
 1.28  10-Aug-1998  perry bzero->memset, bcopy->memcpy, bcmp->memcmp
 1.27  27-Jun-1998  thorpej Fix a serious symbol collision problem introduced when pw_scan() was added
to libc. Note, pw_scan() is NO LONGER exported from libc (it never should
have been, and we're just going to pretend like it never was).
 1.26  08-Jun-1998  lukem * move pw_scan() from libutil to libc
* add support for YP "master.passwd.by*" (master.passwd in YP, including
pw_passwd) and "passwd.adjunct.by*" (SunOS `secure' maps (?)), based
on code in FreeBSD and partially from OpenBSD.
this is only used if euid == 0.
with this, the YP "passwd.by*" maps can have `*' in the pw_passwd field.
* use pw_scan() to parse YP "passwd.by*" and "master.passwd.by*" entries

XXX: i didn't test the "passwd.adjunct" support...
 1.25  10-Feb-1998  mrg allow root to use pwd.db.
 1.24  02-Feb-1998  perry merge/update to lite-2
 1.23  21-Jul-1997  jtc If port provides __weak_alias(), provide an Standard C and POSIX pure
identifier namespace by renaming non standard functions and variables
such that they have a leading underscore. The library will use those
names internally. Weak aliases are used to provide the original names
to the API.

This is only the first part of this change. It is most of the functions
which are implemented in C for all NetBSD ports. Subsequent changes are
to add the same support to the remaining C files, to assembly files, and
to the automagically generated assembly source used for system calls.
When all of the above is done, ports with weak alias support should add
a definition for __weak_alias to <sys/cdefs.h>.
 1.22  13-Jul-1997  christos Fix gcc warnings (unused variables, missing prototypes, etc.)
Fix RCSID's
 1.21  22-May-1997  lukem branches: 1.21.2;
a valid uid/gid *ends* in \0 (i.e, barf if (*ep != '\0'), not if (*ep == '\0'))
 1.20  22-May-1997  lukem * parse gid with strtoul() instead of atoi(), and sanity check a) the parsed
value was just a number, b) it doesn't exceed GID_MAX
* convert gid to a string with %u not %d
* use [gu]id_t instead of int
 1.19  22-May-1997  lukem * parse uid with strtoul() instead of atoi(), and sanity check a) the parsed
value was just a number, b) it doesn't exceed UID_MAX
* convert uid to a string with %u not %d
 1.18  21-May-1997  lukem fix potential memory leaks: before calling yp_next(), reset key to NULL. if
an error occurred, and key != NULL, free(key).
 1.17  20-May-1997  lukem * fix [lib/3580], by ensuring that the outdata arg to the yp_xxx()
calls is initialised to the null pointer so that the error condition
doesn't fail by trying to free() memory that wasn't malloc()ed
* cleanup a bit; remove use of register, KNFify
 1.16  23-Jan-1997  mrg - convert unsafe strcpy(), strcat() and sprintf() to the `n' versions.
- some KNF.
 1.15  20-Dec-1996  sommerfe Longer login name support: use MAXLOGNAME, not UT_NAMESIZE
 1.14  28-Jul-1995  phil branches: 1.14.4; 1.14.8;
Improvements to YP support from Jason Downs.
 1.13  17-May-1995  mycroft Modify getpwent() to use __ypparse().
 1.12  27-Feb-1995  cgd update from Lite, with local changes. fix Ids, etc.
 1.11  09-Mar-1994  deraadt branches: 1.11.4;
__initdb() should only warn about spwd.db errors once, fix from
Cornelis van der Laan <nils@merlin.ims.uni-stuttgart.de>
 1.10  10-Dec-1993  deraadt speed up getpwnam/getpwuid for standard cases
 1.9  25-Oct-1993  jtc Update source and manual pages to match X/Open 1170 specification.
Updated setpassent() to understand YP (a bug), and changed setpwent()
to simply be a call to setpassent(0) (to remove duplicated code).
 1.8  25-Oct-1993  jtc X/Open 1170 defines the return type of setpwent() to be void -- a trival
change since our setpwent() allways succeeded.
 1.7  26-Aug-1993  jtc Declare rcsid strings so they are stored in text segment.
 1.6  30-Jul-1993  mycroft Add even more RCS frobs.
 1.5  24-Jul-1993  deraadt fixed a yp-related bug found by Paul Kranenburg <pk@cs.few.eur.nl>:
endpwent was free'ing passwd line.
 1.4  04-May-1993  deraadt I was horrified to find these had not been commited with the YP changes.
 1.3  21-Apr-1993  proven Opps, dbopen doesn't have an underscore. Fixed.
 1.2  21-Apr-1993  proven Fixed these twon files to use db_open instead of hash_open.
 1.1  21-Mar-1993  cgd branches: 1.1.1;
Initial revision
 1.1.1.3  02-Feb-1998  perry import lite-2
 1.1.1.2  25-Feb-1995  cgd from lite, with minor name rearrangement to fit.
 1.1.1.1  21-Mar-1993  cgd initial import of 386bsd-0.1 sources
 1.11.4.1  02-May-1995  jtc #include "namespace.h"
 1.14.8.1  06-Nov-1996  lukem initial nsswitch implementation
 1.14.4.2  19-Sep-1996  jtc snapshot namespace cleanup: gen
 1.14.4.1  16-Sep-1996  jtc snapshot namespace cleanup
 1.21.2.6  14-Jan-1999  lukem use new ns_dtab structure
 1.21.2.5  22-Nov-1998  lukem missed an #if
 1.21.2.4  02-Nov-1998  lukem sync with current
 1.21.2.3  02-Jun-1997  lukem * set _pw_none = 1 && return NS_SUCCESS in _*_getpwent() at EOF, so that
getpwent() won't merge sources.
 1.21.2.2  26-May-1997  lukem only initialise ns_dtab if it hasn't been done yet
 1.21.2.1  24-May-1997  lukem convert to using nsdispatch()
 1.40.2.2  27-Apr-1999  perry pullup 1.43->1.44 (ross)
 1.40.2.1  27-Apr-1999  perry pullup 1.41->1.43 (lukem)
 1.46.4.4  17-Apr-2002  he Pull up revision 1.50 (requested by groo):
Replace an instance of erroneous usage of strncpy() with strlcpy().
 1.46.4.3  17-Apr-2002  he Pull up revision 1.49 (requested by he):
Return an error if we try to look up a user name that is too long,
rather than trying to truncate. Fixes non-exploitable core dump
problem inside DB.
 1.46.4.2  11-Oct-2000  enami Pull up rev. 1.48 (approved by jhawk):
Reset allocated buffer size to 0 on allocation failure.
 1.46.4.1  02-Oct-2000  simonb Pull up rev 1.47 (approved by thorpej):
Fix potential buffer overflow processing long password database entries.
Inspired by similar OpenBSD change.
 1.48.2.6  10-Dec-2002  thorpej Sync with HEAD.
 1.48.2.5  11-Nov-2002  nathanw Catch up to -current
 1.48.2.4  21-Jun-2002  nathanw Catch up to -current.
 1.48.2.3  25-Apr-2002  nathanw Catch up to -current.
 1.48.2.2  22-Mar-2002  nathanw Catch up to -current.
 1.48.2.1  08-Mar-2002  nathanw Catch up to -current.
 1.66.2.3  13-Jul-2006  ghen Pull up following revision(s) (requested by ginsbach in ticket #1399):
lib/libc/gen/getpwent.c: revision 1.72
Fix YP lookup latency reported by Stephen M. Jones on tech-net. This is a
performance regression between 2.0 and 3.0. The passwd compat method was
incorrectly querying the NIS server with yp_first()/yp_next() rather than
using yp_match() with the correct key.
 1.66.2.2  11-Jul-2005  tron Pull up revision 1.68 (requested by lukem in ticket #540):
getpw{ent,nam,uid}_r():
Return 0 "entry not found" and errno for other failures.
("entry not found" still sets *result to NULL).
Various backends:
don't set the retval to errno (or modify errno) for NS_NOTFOUND.
Per discussion with Klaus Klein.
 1.66.2.1  11-Jul-2005  tron Pull up revision 1.67 (requested by lukem in ticket #540):
PR/29849, PR/29850: Add getpwent_r and getgrent_r
 1.74.10.1  18-May-2008  yamt sync with head.
 1.75.8.3  28-Dec-2008  christos don't hard-code 8.
 1.75.8.2  23-Nov-2008  christos - add a VERSION tag in the db files to handle new and old version passwd
entries.
XXX: Need to add the tag in mkpasswd.
 1.75.8.1  28-Apr-2008  christos file getpwent.c was added on branch christos-time_t on 2008-11-23 21:44:07 +0000
 1.77.8.1  07-Nov-2013  snj Pull up following revision(s) (requested by christos in ticket #979):
lib/libc/gen/getpwent.c: revision 1.79
PR/46279: Dr. W. Stukenbrock: Off-by-one in buffer length check and make sure
that the password fits in the supplied buffer.
 1.77.6.2  30-Oct-2012  yamt sync with head
 1.77.6.1  17-Apr-2012  yamt sync with head
 1.81.14.1  20-Mar-2017  pgoyette Sync with HEAD

RSS XML Feed