summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/getpwent.c
Commit message (Collapse)AuthorAgeFilesLines
* General -Wall warning cleanup, part I.jkh1996-07-121-3/+7
| | | | Submitted-By: Kent Vander Velden <graphix@iastate.edu>
* Grrrr... yet another variation on Murphy's Law: the best way to findwpaul1996-05-071-1/+0
| | | | | | | | | | | bugs in your code is to put it in the -stable branch. (Corollary: the day you discover the bug is the day the Internet decides to route your telnet session to the repository box via Zimbabwe.) Remove one bogus free(result) (from _havemaster()) that slipped by me. Flagged by: phkmalloc Pointed out to me by: Stefan Esser
* Very minor tweak:wpaul1996-04-291-1/+1
| | | | | | | | | | | | In __initdb(), a failure to open the local password database is supposed to result in a warning message being syslog()ed. This warning is only supposed to be generated as long as the 'warned' flag hasn't been yet; once the warning is generated, the flag should be set so that the message is only syslog()ed once. However, while the state of the flag is checked properly, the flag's state is never changed, so you always get multiple warnings instead of just one. Pointed out by: Peter Wemm
* NIS cleanups and fixes, the next generation.wpaul1996-04-161-259/+259
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | getnetgrent.c: - Catch one bogon that snuck by: in _listmatch(), check for '\0' rather than '\n'; strings returned from yp_match() are terminated with a nul, not a newline. getpwent.c: - Rip out all of the +inclusion/-exclusion stuff from before and replace it with something a little less grotty. The main problem with the old mechanism was that it wasted many cycles processing NIS entries even after it already knew they were to be exlcuded (or not included, depending on your pointof view). The highlights of these changes include: o Uses an in-memory hash database table to keep track of all the -@netgroup, -user, and -@group exclusions. o Tries harder to duplicate the behavior normally obtained when using NIS inclusions/exclusions on a flat /etc/passwd file (meaning things come out in much the same order). o Uses seperate methods for handling getpwent() and getpwnam()/getpwuid() operations instead of trying to do everything with one general function, which didn't work as well as I thought it would. o Uses both getnetgrent() and innetgr() to try to save time where possible. o Use only one special token in the local password database (_PW_KEYYPBYNUM) instead of seperate tokens to mark + and - entries (and stop using the counter tokens too). If this new token doesn't exist, the code will make due with the standard _PW_KEYBYNUM token in order to support older databases that won't have the new token in them. All this is an attempt to make this stuff work better in environments with large NIS passwd databases.
* Getpwent() and getservent() can wind up calling free() withmpp1996-01-291-1/+0
| | | | | an invalid pointer if a call to yp_first() fails. Closes PR # 964, and possibly # 952.
* Minor cleanup, mostly unused vars and missing #includes.phk1995-10-221-1/+1
|
* Another tweak/speedup pass:wpaul1995-10-111-62/+80
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Fix buffer overflow problem once and for all: do away with the buffer copies to 'user' prior to calling _scancaches() and just pass a pointer to the buffer returned by yp_match()/yp_first()/yp_next()/whatever. (We turn the first ':' to a NUL first so strcmp() works, then change it back later. Submitted by Bill Fenner <fenner@parc.xerox.com> and tweaked slightly by me. - Give _pw_breakout_yp() the 'more elegant solution' I promised way back when. Eliminate several copies to static buffers and replace them with just one copy. (The buffer returned by the NIS functions is at most YPMAXRECORD bytes long, so we should only need one static buffer of the same length (plus 2 for paranoia's sake).) - Also in _pw_breakout_yp(): always set pw.pw_passwd to the username obtained via NIS regardless of what pw_fields says: usernames cannot be overridden so we have no choice but to use the name returned by NIS. - _Again_ in _pw_breakout_yp(): before doing anything else, check that the first character of the NIS-returned buffer is not a '+' or '-'. If it is, drop the entry. (#define EXTRA_PARANOIA 1 :) - Probe for the master.passwd.* maps once during __initdb() instead of doing it each time _getyppass() or _nextyppass() is called. - Don't copy the NIS data buffers to static memory in _getyppass() and _nextyppass(): this is done in _pw_breakout_yp() now. - Test against phkmalloc and phkmalloc/2 (TNG!) to make sure we're free()ing the yp buffers sanely. - Put _havemaster(), _getyppass() and nextyppass() prototypes under #ifdef YP. (Somehow they ended up on the wrong side of the #endif.) - Remove unused variable ___yp_only.
* getgrent.c: adjust _nextypgroup() slightly so that it continues processingwpaul1995-09-051-3/+6
| | | | | | | | | | | | | the group map after encountering a badly formatted entry. getpwent.c: same as above for _nextyppass(), and also turn a couple of sprintf()s into snprintf()s to avoid potential buffer overruns. (The other day I nearly went mad because of a username in my NIS database that's actually 9 characters long instead of 8. Stuffing a 9-character username into an 8-character buffer can do some strange things.) (This reminds me: I hope somebody's planning to fix the buffer overrun security hole in syslog(3) before 2.1 ships.)
* getpwent.c: turn the code that checks the override caches into awpaul1995-09-021-70/+65
| | | | | | | | | | | | | seperate function to avoid duplication. Also fix getpwent() a small bit to properly handle the case where the magic NIS '+' entry appears before the end of the password file. getgrent.c: be a little more SunOS-ish. Make it look like the NIS group map is 'inserted' at the the point(s) where the magic NIS '+' entry/entries appear. getgrent: fix a file descriptor leak: remember to close the netgroup file after we determine that we're using NIS-only innetgr() lookups.
* Do the same sanity checking in _pw_breakout_yp() that we do inwpaul1995-06-261-16/+19
| | | | | | | _gr_breakout_yp(): if we encounter a NULL pointer generated as the result of a badly formatted NIS passwd entry (e.g. missing fields), we punt and return an error code, thereby silently skipping the bad entry.
* Make _havemaster() use yp_first() (again) instead of yp_order() towpaul1995-06-171-2/+6
| | | | | ward off possible NIS+ evil. (I might be overly paranoid with this, but it doesn't hurt, so...)
* Merge RELENG_2_0_5 into HEADrgrimes1995-06-111-0/+9
|
* Remove trailing whitespace.rgrimes1995-05-301-4/+4
|
* in _freecaches(): strdup() allocates us memory -- remember to free it.wpaul1995-04-221-10/+18
|
* Head off potential core dump in _havemaster() (we don't need to free anywpaul1995-04-151-4/+1
| | | | memory here: the underlying YP routines handle this one for us).
* Better conformance to SunOS behavior: if we can't match a user to onewpaul1995-04-141-2/+8
| | | | | | | | of the plus or minus lists at all, reject him. This lets you create a +@netgroup list of users that you want to admit and reject everybody else. If you end your +@netgroup list with the wildcard line (+:::::::::) then you'll have a +@netgroup list that remaps the specified people but leaves people not in any netgroup unaffected.
* getpwent.c: fix problem with emacs dumping core when NIS is enabled. Alsowpaul1995-04-041-16/+20
| | | | | | | | add #includes for YP headers when compiling with -DYP to avoid some implicit declarations. getgrent.c & getnetgrent.c: add some #includes to avoid implicit declarations of YP functions.
* Use yp_order() instead of yp_first() in _havemaster() to check for thewpaul1995-03-271-7/+7
| | | | | presence of the master.passwd.byname map, and remember to free the returned order value before exiting.
* Add calls to endgrent() and endnetgrent() to the end of _createcaches().wpaul1995-03-251-0/+2
|
* Yikes! Fix stupid mistake I made in last commit that made getpwent() ignorewpaul1995-03-241-9/+12
| | | | | local password entries when YP was enabled. (How the heck did that get by me!?)
* As per Justin T. Gibbs's request, agument the +@netgroup/-@netgroupwpaul1995-03-241-36/+72
| | | | | | | | | | | | | remapping mechanism in the following manner: if given an entry +@foo and there is no netgroup named 'foo,' try searching for a regular user group called 'foo' and build the cache using the members of group 'foo' instead. If both a netgroup 'foo' and a user group 'foo' exist, the 'foo' netgroup takes precedence, since we're primarily interested in netgroup matching anyway. This allows access control schemes based on ordinary user groups (which are also available via NIS) rather than netgroups, since netgroups on some systems are limited in really brain-damaged ways.
* Very important sanity checks: today I clobbered all four NIS servers onwpaul1995-03-231-6/+8
| | | | | | | | | | | | | my network because setnetgrent() was trying to do a lookup on group "". It seems that an attempt to do a yp_match() (and possible yp_next()) on a null or empty key causes Sun's ypserv in SunOS 4.1.3 to exit suddenly (and without warning). Our ypserv behaves badly in this situation too, thoush it doesn't appear to crash. In any event, getpwent, getnetgrent and yp_match() and yp_next() are now extra careful not to accidentally pass on null or empty arguments. Also made a small change to getpwent.c to allow +::::::::: wildcarding, which I had disabled previously.
* Lots of fixes/improvements in the +user substitution handling:wpaul1995-03-231-52/+39
| | | | | - Have the +@netgroup/-@netgroup caches handle the +user/-user cases too. - Clean up getpwent() to take advantage of the improved +user/-user handling.
* Small cleanups:wpaul1995-03-231-39/+44
| | | | | | - Prepend a '_' to a couple of things - Make sure YP is enabled in _createcaches() - Remove a couple of unused/uneeded variables from _createcaches()
* Phew! Done at last: getpwent now understands +@netgroup/-@netgroup directiveswpaul1995-03-231-9/+212
| | | | | in addition to the existing NIS substitutions. I may tweak this a bit in the future, but the important stuff is all here.
* Collapsed _masterpw_breakout_yp() and _pw_breakout_yp() into awpaul1995-02-051-72/+20
| | | | single function.
* Fixed a rather serious bug that presents itself when FreeBSD is configuredwpaul1995-02-031-2/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | as an NIS client. The pw_breakout_yp routines that are used to populate the _pw_passwd structire only do anything if the bits in the pw_fields member _pw_passwd are cleared. Unfortunately, we can get into a state where pw_fields has garbage in it right before the YP lookup functions are called, which causes the breakout functions to screw up in a big way. Here's how to duplicate the problem: - Configure FreeBSD as an NIS client - Log in as a user who's password database records reside only in the NIS passwd maps. - Type ps -aux Result: your processes appear to be owned by 'root' or 'deamon.' /bin/ls can exhibit the same problem. The reason this happens: - When ps(1) needs to match a username to a UID, it calls getpwuid(). - root is in the local password file, so getpwuid() calls __hashpw() and __hashpw() populates the _pw_passwd struct, including the pw_fields member. This happens before NIS lookups take place because, by coincidence, ps(1) tends to display processes owned by root before it happens upon a proccess owned by you. - When your UID comes up, __hashpw() fails to find your entry in the local password database, so it bails out, BUT THE BITS IN THE pw_fields STRUCTURE OF _pw_passwd ARE NEVER CLEARED AND STILL CONTAIN INFORMATION FROM THE PREVIOUS CALL TO __hash_pw()!! - If we have NIS enabled, the NIS lookup functions are called. - The pw_breakout_yp routines see that the pw_fields bits are set and decline to place the data retrieved from the NIS passwd maps into the _pw_passwd structure. - getpwuid() returns the results of the last __hashpw() lookup instead of the valid NIS data. - Hijinxs ensue when user_from_uid() caches this bogus information and starts handing out the wrong usernames. AAAARRRRRRRRRGGGGGGHHHHHHHHHH!!! *Please* don't tell me I'm the only person to have noticed this. Fixed by having __hashpw() check the state of pw_fields just before bailing out on a failed lookup and clearing away any leftover garbage. What a fun way to spend an afternoon.
* Fix for that last fix... pass the hat. :)wpaul1995-02-011-2/+1
|
* Small fix to _getyppass(): sometimes we can construct the wrong mapnamewpaul1995-02-011-1/+2
| | | | when looking for master.passwd.whatever.
* Some changes for YP password map handling:wpaul1995-01-311-6/+114
| | | | | | | | | | | | | | | | | | | | | - FreeBSD's NIS server can supply a master.passwd map, which has more fields in it than a standard passwd map, so we need a _master_pw_breakout() fuction. - When doing passwd map lookups, look for master.passwd.* by attempting a _yp_first() on master.passwd.byname. If it exists, we're being served by a FreeBSD NIS server and we should use this map. - If we aren't the superuser, retrieve only the standard passwd maps. If we're being served by a FreeBSD system, then the passwd map has no passwords in it, and it won't serve us the master.passwd map unless we're superuser anyway. There's a small speed hit for the superuser inherent in the check for the master.passwd map, but this lets us dynamically decide what to do rather than rely on a non-standard config file somewhere. Since all of this is bypassed for normal users, they shouldn't notice the difference.
* Fix unbalanced #endif introduced by yesterday's change.wollman1995-01-191-1/+1
|
* Prevent sites from shooting themselves in the foot while enabling/disablingwollman1995-01-171-1/+1
| | | | | | | YP by disallowing `+' entries as logins in all cases. (This handles the case of a `+' entry in the password file but YP not running, which should never happen but is easy enough to check for so we'll apply some prophylaxis.)
* Second half of YP security hole fix. Needs updated passwordwollman1994-09-201-5/+12
| | | | database in order to operate.
* Re-implement YP password file support from scratch. This implementationwollman1994-09-201-3/+215
| | | | correctly handles +user entries and + entries with local overrides.
* BSD 4.4 Lite Lib Sourcesrgrimes1994-05-271-0/+201
OpenPOWER on IntegriCloud