aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen/getpwent.c
Commit message (Collapse)AuthorAgeFilesLines
* libc: Purge unneeded cdefs.hWarner Losh2023-11-011-1/+0
| | | | | | | | | These sys/cdefs.h are not needed. Purge them. They are mostly left-over from the $FreeBSD$ removal. A few in libc are still required for macros that cdefs.h defines. Keep those. Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D42385
* Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSDWarner Losh2023-05-121-1/+1
| | | | | | | | | The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch up to that fact and revert to their recommended match of BSD-2-Clause. Discussed with: pfg MFC After: 3 days Sponsored by: Netflix
* libc/gen/getpwent.c: plug warnings about write-only variablesKonstantin Belousov2021-11-291-6/+6
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* libc: Fix the WITH_HESIOD buildMark Johnston2021-04-051-1/+1
| | | | | Reported by: Daniel Braniss <danny@cs.huji.ac.il> MFC after: 1 week
* libc/nss: Restore iterator state when doing passwd/group lookupsMark Johnston2021-01-211-7/+11
| | | | | | | | | | | | | | | | | | | | The getpwent(3) and getgrent(3) implementations maintain some internal iterator state. Interleaved calls to functions which do passwd/group lookups using a key, such as getpwnam(3), would in some cases clobber this state, causing a subsequent getpwent() or getgrent() call to restart iteration from the beginning of the database or to terminate early. This is particularly troublesome in programming environments where execution of green threads is interleaved within a single OS thread. Take care to restore any iterator state following a keyed lookup. The "files" provider for the passwd database was already handling this correctly, but "compat" was not, and both providers had this problem when accessing the group database. PR: 252094 Submitted by: Viktor Dukhovni <ietf-dane@dukhovni.org> MFC after: 1 month
* fix integer underflow in getgrnam_r and getpwnam_rAlan Somers2020-09-191-2/+9
| | | | | | | | | | | | | | | | | | | Sometimes nscd(8) will return a 1-byte buffer for a nonexistent entry. This triggered an integer underflow in grp_unmarshal_func, causing getgrnam_r to return ERANGE instead of 0. Fix the user's buffer size check, and add a correct check for a too-small nscd buffer. PR: 248932 Event: September 2020 Bugathon Reviewed by: markj MFC after: 2 weeks Sponsored by: Axcient Differential Revision: https://reviews.freebsd.org/D26204 Notes: svn path=/head/; revision=365910
* Fix -Wvoid-pointer-to-enum-cast warnings.Brooks Davis2020-04-151-8/+8
| | | | | | | | | | | | | | | | | This pattern is used in callbacks with void * data arguments and seems both relatively uncommon and relatively harmless. Silence the warning by casting through uintptr_t. This warning is on by default in Clang 11. Reviewed by: arichardson Obtained from: CheriBSD (partial) MFC after: 1 week Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D24425 Notes: svn path=/head/; revision=359978
* Make pw_scan(3) more compatible with getpwent(3) et. al. when processingIan Lepore2018-07-261-23/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | data from /etc/passwd rather than /etc/master.passwd. The libc getpwent(3) and related functions automatically read master.passwd when run by root, or passwd when run by a non-root user. When run by non- root, getpwent() copes with the missing data by setting the corresponding fields in the passwd struct to known values (zeroes for numbers, or a pointer to an empty string for literals). When libutil's pw_scan(3) was used to parse a line without the root-accessible data, it was leaving garbage in the corresponding fields. These changes rename the static pw_init() function used by getpwent() and friends to __pw_initpwd(), and move it into pw_scan.c so that common init code can be shared between libc and libutil. pw_scan(3) now calls __pw_initpwd() before __pw_scan(), just like the getpwent() family does, so that reading an arbitrary passwd file in either format and parsing it with pw_scan(3) returns the same results as getpwent(3) would. This also adds a new pw_initpwd(3) function to libutil, so that code which creates passwd structs from scratch in some manner that doesn't involve pw_scan() can initialize the struct to the values expected by lots of existing code, which doesn't expect to encounter NULL pointers or garbage values in some fields. Notes: svn path=/head/; revision=336746
* libc: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-251-0/+2
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326193
* libc: make some more use of the nitems() macro.Pedro F. Giffuni2016-04-161-1/+1
| | | | | | | | | | | We have an nitems() macro in the <sys/param.h> header that is convenient to re-use as it makes things easier to read. Given that it is available already without adding additional headers and other parts of libc already use it, extend a bit more its use. Notes: svn path=/head/; revision=298120
* Fix compiling with gcc [4.2.1] after r287797 when MK_HESOID == no andEnji Cooper2015-10-251-6/+4
| | | | | | | | | | | | | | | | | | | | | | | MK_NIS == no by converting `i` back to an int, and instead cast the loop comparison to `int` The loop comparison is iterating the len(ns_dtab)-1, because the last element is the sentinel tuple { NULL, NULL, NULL, }, so when both HESOID and NIS are off, len(ns_dtab)-1 == 1 - 1 == 0, and the loop is skipped because the expression is tautologically false While here, convert `(sizeof(x) / sizeof(x[0]))` to `nitems(x)` Tested with: clang 3.7.0, gcc 4.2.1, and gcc 4.9.4 [*] with MK_NIS={no,yes} and by running bash -lc 'id -u && id -g && id' * gcc 4.9.4 needs another patch in order for the compile to succeed with -Werror with lib/libc/gen/getgrent.c Reported by: jhibbits Notes: svn path=/head/; revision=289925
* Use unsigned variables in a few places.Craig Rodrigues2015-09-141-2/+3
| | | | | | | Eliminates gcc 4.9 warnings. Notes: svn path=/head/; revision=287797
* compat_passwd(): yet another uninitialized access to stayopen.Pedro F. Giffuni2015-03-061-1/+1
| | | | | | | CID: 1018731 Notes: svn path=/head/; revision=279712
* Fix small memleaks in nis_passwd() and nis_group().Pedro F. Giffuni2015-02-201-1/+3
| | | | | | | | | | | | | These only occur upon error. Code Review: https://reviews.freebsd.org/D1849 Reviewed by: delphij CID: 1016715 CID: 1016717 Notes: svn path=/head/; revision=279035
* More tidy-ups on uninitialized scalar variablePedro F. Giffuni2015-02-151-1/+1
| | | | | | | | | | | | | As a followup to r278363, there is one more case where stayopen can be accessed uninitialized, but even after swapping arguments, access is possible in some other cases so prevent it completely by initializing stayopen. CID: 1018729 CID: 1018732 Notes: svn path=/head/; revision=278804
* Protect uninitialized scalar variable from being accessedPedro F. Giffuni2015-02-071-1/+1
| | | | | | | | | | | | | In a couple of cases a variable "stayopen" can be checked unitialized. This is of no danger as the complementary condition is false but prevent the access by switching the checks. CID: 1018729 CID: 1018732 Notes: svn path=/head/; revision=278363
* - Extend the nsswitch to support Services, Protocols and RpcHajimu UMEMOTO2006-04-281-0/+277
| | | | | | | | | | | databases. - Make nsswitch support caching. Submitted by: Michael Bushkov <bushman__at__rsu.ru> Sponsored by: Google Summer of Code 2005 Notes: svn path=/head/; revision=158115
* POSIX prohibits any library function from setting errno to 0.Tim Kientzle2004-05-171-1/+1
| | | | | | | | | | | Correct my previous commit and add a comment to the manpage indicating that the user must set errno to 0 if they wish to distinguish "no such user" from "error". Pointed out by: Jacques Vidrine (nectar@) Notes: svn path=/head/; revision=129349
* If getpwent/getpwuid/getpwnam return NULL, they must also set errno.Tim Kientzle2004-05-171-0/+3
| | | | Notes: svn path=/head/; revision=129319
* Fix a bug that could result in getpw*() incorrectly returning NULL when NISJonathan Chen2004-04-211-0/+1
| | | | | | | | | | adjunct maps are used. One symtom of this bug is sshd saying: login_get_lastlog: Cannot find account for uid X when logging in. The problem here is caused by an incorrect reuse of the rv variable when previous values are needed later. Notes: svn path=/head/; revision=128537
* Make NULL a (void*)0 whereever possible, and fix the warnings(-Werror)Mark Murray2004-03-051-1/+1
| | | | | | | | | | | | | | | | | | that this provokes. "Wherever possible" means "In the kernel OR NOT C++" (implying C). There are places where (void *) pointers are not valid, such as for function pointers, but in the special case of (void *)0, agreement settles on it being OK. Most of the fixes were NULL where an integer zero was needed; many of the fixes were NULL where ascii <nul> ('\0') was needed, and a few were just "other". Tested on: i386 sparc64 Notes: svn path=/head/; revision=126643
* Kill whitespace at end of lines.Jacques Vidrine2004-01-121-9/+9
| | | | Notes: svn path=/head/; revision=124432
* Fix a bug that could result in a null pointer dereference inJacques Vidrine2004-01-121-1/+1
| | | | | | | | | | | | | | getpwent(3) or getpwuid(3) when using NIS adjunct maps. The bug was present in the internal `nis_passwd' function. The lookup in the adjunct map used the name passed into `nis_passwd', however no name was of course supplied by getpwent or getpwuid. Correctly use the name from the `struct pwd' that was found instead. PR: bin/59962 Submitted by: Gabriel Gomez <ggomez@fing.edu.uy> Notes: svn path=/head/; revision=124431
* Revert to using yp_order() to probe for master.paswd.by* maps andBill Paul2003-07-181-7/+14
| | | | | | | | | | | | | | | | | | don't probe the server at all for passwd.by* maps. This fixes interoperability with the Services For UNIX NIS server (which is really a front end to Captive^WActiveDirectory). This server incorrectly returns success for all YPPROC_MASTER requests, even for maps that don't exist, which makes it impossible to (ab)use it to probe for the existence of the master.passwd.by* maps. This is a little kludgey, but basically restores the original behavior of getpwent.c as it is in -stable, and works around both the lack of YPPROC_ORDER on NIS+ servers as well as the broken YPPROC_MASTER on Services For UNIX servers. Notes: svn path=/head/; revision=117750
* fix NIS+ YP compat modeJohn W. De Boskey2003-06-271-3/+4
| | | | | | | | PR: bin/52792 Submitted by: TOMITA Yoshinori <yoshint@flab.fujitsu.co.jp> Notes: svn path=/head/; revision=116901
* Back out the `hiding' of strlcpy and strlcat. Several peopleJacques Vidrine2003-05-011-5/+5
| | | | | | | vocally objected to this safety belt. Notes: svn path=/head/; revision=114443
* `Hide' strlcpy and strlcat (using the namespace.h / __weak_referenceJacques Vidrine2003-04-291-5/+5
| | | | | | | | | | technique) so that we don't wind up calling into an application's version if the application defines them. Inspired by: qpopper's interfering and buggy version of strlcpy Notes: svn path=/head/; revision=114256
* When using `compat' mode, be sure to re-dispatch setpwent, endpwent,Jacques Vidrine2003-04-251-0/+29
| | | | | | | | | | | | | setgrent, and endgrent also. (The previous NSS implementation used to simply twiddle the internal data of the various modules directly.) A symptom (group list set incorrectly in sshd) was Reported by: Glenn Johnson <gjohnson@srrc.ars.usda.gov> Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=114021
* In compat mode, we `redispatch' the lookup. It is probably a goodJacques Vidrine2003-04-241-0/+1
| | | | | | | | | | | idea to re-initialize `struct passwd', because e.g. pw_class might get set by one module, but not by another. Add another call to the internal pwd_init function to accomplish this. Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113992
* Don't try to access the NIS `master' maps unless we have superuserJacques Vidrine2003-04-211-7/+9
| | | | | | | | | | | privileges. To do so may cause the NIS server to log spurious and annoying `access denied' messages. Reported by: Philip Paeps <philip@paeps.cx> Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113794
* Follow-up to revision 1.74: Using the result buffer to store our emptyJacques Vidrine2003-04-181-22/+16
| | | | | | | | | | string was an incredibly dumb idea (of course it will be changed by an NSS module on success!). Use a static empty string instead. Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113694
* Follow-up to revision 1.73: set _PWF_FILES when `compat' source is usedJacques Vidrine2003-04-181-4/+13
| | | | | | | | | | but user is found in local file. Reported by: Shizuka Kudo <shizukakudo_99@yahoo.com> Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113691
* Don't use `memset' to initialize a struct passwd. A moduleJacques Vidrine2003-04-181-6/+31
| | | | | | | | | | | | | | | | | | | may not fill in all fields, and in the case of string fields, this could cause trouble for applications. (The only likely example is `pw_class', because this field is not used by all modules in all cases.) Move initialization of struct passwd from module-specific code to the dispatch code. The problem of a NULL pw_class was Noticed by: Philip Paeps <philip@paeps.cx> and the c^Htrusty ssh(1) command. Déjà vu by: getpwent.c revision 1.56 Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113672
* Correctly set _PWF_FILES in pw_fields when appropriate.Jacques Vidrine2003-04-181-2/+6
| | | | | | | | | | (_PWF_NIS and _PWF_HESIOD were already being set.) Reported by: Shizuka Kudo <shizukakudo_99@yahoo.com> Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113670
* Revert the definitions of _PW_KEY* to their previous values. There isJacques Vidrine2003-04-181-2/+2
| | | | | | | | | | | | | at least one consumer outside of libc and pwd_mkdb. Adjust the versioning in libc and pwd_mkdb accordingly. named was the application affected, and that fact was first Reported by: Zherdev Anatoly <tolyar@mx.ru> Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113666
* The default if nsswitch.conf(5) is not present is supposed to be theJacques Vidrine2003-04-181-1/+1
| | | | | | | | | | hated `compat' source, not `files'. Reported by: Philip Paeps <philip@paeps.cx> Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113643
* = Implement thread-safe versions of the getpwent(3) and getgrent(3)Jacques Vidrine2003-04-171-971/+1446
| | | | | | | | | | | | | | | | | | | | | | | | | family of functions using the new nsdispatch(3) core. Remove arbitrary size limits when using the thread-safe versions. = Re-implement the traditional getpwent(3)/getgrent(3) functions on top of the thread-safe versions. = Update the on-disk format of the hashed version of the passwd(5) databases to allow for versioned entries. The legacy version is `3'. (Don't ask.) = Add support for version `4' entries in the passwd(5) database. Entries in this format are identical to version 3 entries except that all integers are stored as 32-bit integers in network byte order (big endian). = pwd_mkdb is updated to generate both version 3 and version 4 entries. Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=113596
* Eliminate 19 warnings in libc (at level WARNS=2) of theJacques Vidrine2003-02-271-0/+1
| | | | | | | `implicit declaration of function' variety. Notes: svn path=/head/; revision=111618
* Eliminate 61 warnings emitted at WARNS=2 (leaving 53 to go).Jacques Vidrine2003-02-161-4/+1
| | | | | | | | | | Only warnings that could be fixed without changing the generated object code and without restructuring the source code have been handled. Reviewed by: /sbin/md5 Notes: svn path=/head/; revision=111010
* Fix bug that causes passwd and friends to fail when the user has a '+' inDag-Erling Smørgrav2002-05-071-0/+3
| | | | | | | | | their passwd file for NIS because _PWF_SOURCE is not set. Submitted by: amigus (perforce change 10969) Notes: svn path=/head/; revision=96186
* Missed a spot in previous commit.Dag-Erling Smørgrav2002-04-151-1/+3
| | | | | | | Sponsored by: DARPA, NAI Labs Notes: svn path=/head/; revision=94700
* (ab)use unused bits in the pw_fields member of struct passwd to recordDag-Erling Smørgrav2002-04-141-2/+12
| | | | | | | | | the source of the data contained in the structure. Sponsored by: DARPA, NAI Labs Notes: svn path=/head/; revision=94688
* * Remove __P and convert to ANSI prototypes.David E. O'Brien2002-02-011-23/+19
| | | | | | | | * Remove 'register'. (some functions had 7+ register functions...) * Fix SCM ID's. Notes: svn path=/head/; revision=90045
* Fixed world breakage due to missing include of <sys/cdefs.h> in previousBruce Evans2002-01-311-0/+4
| | | | | | | | | | | | | | | commit. Fixed related style bugs: basename.c: misplaced '#if 0' dirname.c: misplaced '#if 0' getgrent.c: missing '#if 0', and tab lossage in vendor id (the previous commit fixed the complete corruption of the vendor id but lost a tab) getpwent.c: missing '#if 0' Notes: svn path=/head/; revision=90016
* Fix FreeBSD IDs.David E. O'Brien2002-01-301-3/+2
| | | | Notes: svn path=/head/; revision=89999
* Explicitly use int32_t for on-disk records for pw_change and pw_expire,Peter Wemm2001-10-271-2/+5
| | | | | | | | | since that is what we use now and this insulates us from any time_t tweaks here. We can define a record format that uses 64 bit times if/when we need to. Notes: svn path=/head/; revision=85572
* If the username we are trying to look up in the db files won't fit intoDavid Malone2001-06-181-1/+3
| | | | | | | | | | | the buffer then act like it doesn't exist. The buffer is always big enough for any valid username. PR: 27860 Reviewed by: nectar Notes: svn path=/head/; revision=78418
* Remove _THREAD_SAFE and make libc thread-safe by default byDaniel Eischen2001-01-241-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. <db.h> is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of <errno.h> from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch Notes: svn path=/head/; revision=71579
* Fix bug introduced in previous commit: users obtained via compat modeJacques Vidrine2000-11-131-3/+8
| | | | | | | | | had uid, gid set to 0 if not otherwise specified! Submitted by: eivind Notes: svn path=/head/; revision=68691