aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen/getpwent.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Restore old semantics (broken in rev 1.47's buffer overflow fix).Eivind Eklund1998-12-171-1/+3
| | | | Notes: svn path=/head/; revision=41898
* Prevent buffer overflow in getpwnam()Mike Smith1998-10-291-2/+2
| | | | | | | | PR: bin/8176 Submitted by: Archie Cobbs <archie@whistle.com> Notes: svn path=/head/; revision=40742
* Replace memory leaking instances of realloc with non-leaking reallocf.Warner Losh1998-09-161-1/+1
| | | | | | | | | | | | | | In some cases replace if (a == null) a = malloc(x); else a = realloc(a, x); with simple reallocf(a, x). Per ANSI-C, this is guaranteed to be the same thing. I've been running these on my system here w/o ill effects for some time. However, the CTM-express is at part 6 of 34 for the CAM changes, so I've not been able to do a build world with the CAM in the tree with these changes. Shouldn't impact anything, but... Notes: svn path=/head/; revision=39327
* Don't initialize NIS until it is really necessary. Now, in case of networkDmitrij Tejblum1998-09-151-55/+71
| | | | | | | | | or NIS server problems, local user can login without a pause. Also, -Wsomething cleanup. Notes: svn path=/head/; revision=39283
* XOpen says the void setpwent(void) is correct. Also call setpassent(0)Steve Price1998-02-011-7/+2
| | | | | | | | | instead of duplicating code, albeit trivial (inspired by NetBSD). PR: 5524 Notes: svn path=/head/; revision=32962
* Many places in the code NULL is used in integer context, wherePoul-Henning Kamp1997-09-181-2/+2
| | | | | | | | | | | | plain 0 should be used. This happens to work because we #define NULL to 0, but is stylistically wrong and can cause problems for people trying to port bits of code to other environments. PR: 2752 Submitted by: Arne Henrik Juul <arnej@imf.unit.no> Notes: svn path=/head/; revision=29574
* Fix yet a minor stylistic nit from Bruce.Wolfram Schneider1997-09-151-4/+4
| | | | | | | (`cvs diff -ib' print one new char ;-). Notes: svn path=/head/; revision=29479
* Potential bufferflow in getpwent(), getpwnam() and getpwuid()Wolfram Schneider1997-09-141-2/+7
| | | | | | | | PR: bin/4134 Submitted by: nick@foobar.org Notes: svn path=/head/; revision=29396
* Remove minor warning (for -Wall -Wshadow); clarifies code.David Nugent1997-03-261-3/+3
| | | | Notes: svn path=/head/; revision=24288
* Merge from Lite2:Peter Wemm1997-03-111-14/+13
| | | | | | | | filesystem include updates, duplicate group suppression, cleanups, filesystem whiteout support (unionfs), bidir popen(). Notes: svn path=/head/; revision=23668
* Fix brain-o in SunOS passwd.adjunct stuff: !strstr(s, "##") is a) badBill Paul1997-03-101-1/+1
| | | | | | | | | style and b) the wrong logic. Should be strstr(s, "##") != NULL. (Note that the passwd.adjunct stuff has not been merged into 2.2 so this bug is not in that branch.) Notes: svn path=/head/; revision=23608
* Small yet significant tweaks/cleanups:Bill Paul1996-12-271-5/+7
| | | | | | | | | | | | | | | | | | | | | - getpwent: o adjunctbuf should be NUL terminated after copying o _pw_breakout_yp() needs to know the length of the buffer returned from YP so it can properly NUL terminate its local buffer. - getgrent: o YP buffers should be YPMAXRECORD + 2 bytes long and NUL terminated. (Previously they were hardcoded to 1024 bytes.) - getnetgrent: o YP data should be copied with snprintf(), not sprintf() These are 2.2 candidates. I will wait a few days to make sure these don't break anything and then, if there are no objections, move them to the 2.2 branch. Notes: svn path=/head/; revision=20957
* Add support for detecting and hopefully using the passwd.adjunct.bynameBill Paul1996-12-031-13/+65
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | NIS map which is present on SunOS NIS servers with the SunOS C2 security hack^Woption installed. I'm convinced that the C2 security option restricts access to the passwd.adjunct.byname map in the same way that I restrict access to the master.passwd.{byname,buid} maps (checking for reserved ports), which means that we should be able to handle passwd.adjunct.byname map correctly. If _havemaster() doesn't find a master.passwd.byname map, it will now test for a passwd.adjunct.byname map before defaulting back to the standard non-shadowed passwd.{byname,byuid} maps. If _pw_breakout_yp() sees that the adjunct map was found and the password from the standard maps starts with ##, it will try to grab the correct password field from the adjunct map. As with the master.passwd maps, this only happens if the caller is root, so the shadowing feature is preserved; non-root users just get back ##username as the encrypted password. Note that all we do is grab the second field from the passwd.adjunct.byname entry, which is designated to be the real encrypted password. There are other auditing fields in the entry but they aren't of much use to us. Also switched back to using yp_order() to probe for the maps (instead of yp_first()). The original problem with yp_order() was that it barfed with NIS+ servers in YP compat mode since they don't support the YPPROC_ORDER procedure. This condition is handled a bit more gracefully in yplib now: we can detect the error and just punt on the probing. Notes: svn path=/head/; revision=20119
* General -Wall warning cleanup, part I.Jordan K. Hubbard1996-07-121-3/+7
| | | | | | | Submitted-By: Kent Vander Velden <graphix@iastate.edu> Notes: svn path=/head/; revision=17141
* Grrrr... yet another variation on Murphy's Law: the best way to findBill Paul1996-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 Notes: svn path=/head/; revision=15668
* Very minor tweak:Bill Paul1996-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 Notes: svn path=/head/; revision=15446
* NIS cleanups and fixes, the next generation.Bill Paul1996-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. Notes: svn path=/head/; revision=15267
* Getpwent() and getservent() can wind up calling free() withMike Pritchard1996-01-291-1/+0
| | | | | | | | an invalid pointer if a call to yp_first() fails. Closes PR # 964, and possibly # 952. Notes: svn path=/head/; revision=13717
* Minor cleanup, mostly unused vars and missing #includes.Poul-Henning Kamp1995-10-221-1/+1
| | | | Notes: svn path=/head/; revision=11659
* Another tweak/speedup pass:Bill Paul1995-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. Notes: svn path=/head/; revision=11436
* getgrent.c: adjust _nextypgroup() slightly so that it continues processingBill Paul1995-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.) Notes: svn path=/head/; revision=10565
* getpwent.c: turn the code that checks the override caches into aBill Paul1995-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. Notes: svn path=/head/; revision=10521
* Do the same sanity checking in _pw_breakout_yp() that we do inBill Paul1995-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. Notes: svn path=/head/; revision=9332
* Make _havemaster() use yp_first() (again) instead of yp_order() toBill Paul1995-06-171-2/+6
| | | | | | | | ward off possible NIS+ evil. (I might be overly paranoid with this, but it doesn't hurt, so...) Notes: svn path=/head/; revision=9250
* Merge RELENG_2_0_5 into HEADRodney W. Grimes1995-06-111-0/+9
| | | | Notes: svn path=/head/; revision=9202
* Remove trailing whitespace.Rodney W. Grimes1995-05-301-4/+4
| | | | Notes: svn path=/head/; revision=8870
* in _freecaches(): strdup() allocates us memory -- remember to free it.Bill Paul1995-04-221-10/+18
| | | | Notes: svn path=/head/; revision=8002
* Head off potential core dump in _havemaster() (we don't need to free anyBill Paul1995-04-151-4/+1
| | | | | | | memory here: the underlying YP routines handle this one for us). Notes: svn path=/head/; revision=7834
* Better conformance to SunOS behavior: if we can't match a user to oneBill Paul1995-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. Notes: svn path=/head/; revision=7815
* getpwent.c: fix problem with emacs dumping core when NIS is enabled. AlsoBill Paul1995-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. Notes: svn path=/head/; revision=7615
* Use yp_order() instead of yp_first() in _havemaster() to check for theBill Paul1995-03-271-7/+7
| | | | | | | | presence of the master.passwd.byname map, and remember to free the returned order value before exiting. Notes: svn path=/head/; revision=7422
* Add calls to endgrent() and endnetgrent() to the end of _createcaches().Bill Paul1995-03-251-0/+2
| | | | Notes: svn path=/head/; revision=7340
* Yikes! Fix stupid mistake I made in last commit that made getpwent() ignoreBill Paul1995-03-241-9/+12
| | | | | | | | local password entries when YP was enabled. (How the heck did that get by me!?) Notes: svn path=/head/; revision=7322
* As per Justin T. Gibbs's request, agument the +@netgroup/-@netgroupBill Paul1995-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. Notes: svn path=/head/; revision=7319
* Very important sanity checks: today I clobbered all four NIS servers onBill Paul1995-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. Notes: svn path=/head/; revision=7288
* Lots of fixes/improvements in the +user substitution handling:Bill Paul1995-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. Notes: svn path=/head/; revision=7278
* Small cleanups:Bill Paul1995-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() Notes: svn path=/head/; revision=7262
* Phew! Done at last: getpwent now understands +@netgroup/-@netgroup directivesBill Paul1995-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. Notes: svn path=/head/; revision=7258
* Collapsed _masterpw_breakout_yp() and _pw_breakout_yp() into aBill Paul1995-02-051-72/+20
| | | | | | | single function. Notes: svn path=/head/; revision=6190
* Fixed a rather serious bug that presents itself when FreeBSD is configuredBill Paul1995-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. Notes: svn path=/head/; revision=6145
* Fix for that last fix... pass the hat. :)Bill Paul1995-02-011-2/+1
| | | | Notes: svn path=/head/; revision=6096
* Small fix to _getyppass(): sometimes we can construct the wrong mapnameBill Paul1995-02-011-1/+2
| | | | | | | when looking for master.passwd.whatever. Notes: svn path=/head/; revision=6095
* Some changes for YP password map handling:Bill Paul1995-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. Notes: svn path=/head/; revision=6076
* Fix unbalanced #endif introduced by yesterday's change.Garrett Wollman1995-01-191-1/+1
| | | | Notes: svn path=/head/; revision=5714
* Prevent sites from shooting themselves in the foot while enabling/disablingGarrett Wollman1995-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.) Notes: svn path=/head/; revision=5703
* Second half of YP security hole fix. Needs updated passwordGarrett Wollman1994-09-201-5/+12
| | | | | | | database in order to operate. Notes: svn path=/head/; revision=2935
* Re-implement YP password file support from scratch. This implementationGarrett Wollman1994-09-201-3/+215
| | | | | | | correctly handles +user entries and + entries with local overrides. Notes: svn path=/head/; revision=2917
* BSD 4.4 Lite Lib SourcesRodney W. Grimes1994-05-271-0/+201
Notes: svn path=/cvs2svn/branches/unlabeled-1.1.1/; revision=1573