freebsd-dev/lib/libc
Bill Paul a393cc06f5 Fixed a rather serious bug that presents itself when FreeBSD is configured
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.
1995-02-03 01:09:35 +00:00
..
amd64 First round of changes to clean up the RCSID mess in libc: 1995-01-23 01:30:24 +00:00
compat-43 gethostid.2 is now gethostid.3. Instal the correct one. 1994-08-28 17:08:36 +00:00
db Added the mpool.3 manpage to the installed manpages. It is referred from the 1994-12-11 22:03:05 +00:00
gen Fixed a rather serious bug that presents itself when FreeBSD is configured 1995-02-03 01:09:35 +00:00
gmon Added support for kernel profiling to mcount.c 1994-09-15 16:00:41 +00:00
i386 First round of changes to clean up the RCSID mess in libc: 1995-01-23 01:30:24 +00:00
locale Sync with ctype.h (remove EOF handling) 1994-10-09 11:20:55 +00:00
net In _gethostbydnsaddr(), force RES_RECURSE into _res.options. This is 1994-12-01 22:25:38 +00:00
quad BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
regex First crack at making libc work with the new make macros. It compiles on 1994-08-05 01:19:12 +00:00
rpc Comment out the man page of rstat.1 from Makefile.inc. There is no rstat 1994-12-11 22:08:10 +00:00
stdio Fix handling of 'e' format floating point so that it prints trailing zeros 1995-01-19 12:05:53 +00:00
stdlib u_int -> unsigned int, so that we don't have to include <sys/types.h> 1994-09-05 13:26:40 +00:00
stdtime Use latest Arthur Olson timezone code rather than that supplied with 1994-09-13 21:26:08 +00:00
string Obtained from: 386BSD-0.1 patchkit; also fixed in 1.1.5 1994-12-12 01:23:33 +00:00
sys Add the sys/types.h include to the necessary documented includes for the 1994-12-31 18:50:57 +00:00
xdr More directory cleanup after YP merge. 1994-08-07 22:21:14 +00:00
yp Add back in the YP code from 1.1.5. (This attribution brought to you 1994-08-07 23:04:55 +00:00
Makefile Changed LIB_SCCS and SYSLIB_SCCS #defines to LIB_RCS and SYSLIB_RCS. 1995-01-23 01:22:08 +00:00