Commit Graph

33 Commits

Author SHA1 Message Date
Ian Lepore
34e9190d82 Make pw_scan(3) more compatible with getpwent(3) et. al. when processing
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.
2018-07-26 18:34:38 +00:00
Ian Lepore
c798532ffa Revert r336619, it appears to cause problems with ssh, and probably other
things which use pw_scan().
2018-07-23 17:26:38 +00:00
Ian Lepore
cbc397fd10 Set the pw_class field to NULL when scanning the non-master passwd file.
This avoids a null pointer deref in pw_dup(), which assumes that all
pointers are either NULL or valid.
2018-07-22 22:34:20 +00:00
John Baldwin
c1920558b3 Clean up the vcs ID strings in libc's gen/ directory.
- Move CSRG IDs into __SCCSID().
- When a file has been copied, consistently use 'From: <tag>' for strings
  referencing the version of the source file copied from in the license
  block comment.
- Some of the 'From:' tags were using $FreeBSD$ that was being expanded on
  each checkout.  Fix those to hardcode the FreeBSD tag from the file that
  was copied at the time of the copy.
- When multiple strings are present list them in "chronological" order,
  so CSRG (__SCCSID) before FreeBSD (__FBSDID).  If a file came from
  OtherBSD and contains a CSRG ID from the OtherBSD file, use the order
  CSRG -> OtherBSD -> FreeBSD.

Reviewed by:	imp
Differential Revision:	https://reviews.freebsd.org/D15831
2018-07-03 17:31:45 +00:00
Xin LI
73aaa45510 Remove unused includes. 2018-01-01 08:01:26 +00:00
Pedro F. Giffuni
8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

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.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Warner Losh
fbbd9655e5 Renumber copyright clause 4
Renumber cluase 4 to 3, per what everybody else did when BSD granted
them permission to remove clause 3. My insistance on keeping the same
numbering for legal reasons is too pedantic, so give up on that point.

Submitted by:	Jan Schaumann <jschauma@stevens.edu>
Pull Request:	https://github.com/freebsd/freebsd/pull/96
2017-02-28 23:42:47 +00:00
Ken Smith
764eca2591 It is believed the last subsystem that limited ID sizes to something
other than the current system-wide size (32-bits) has been updated so
for now just cautiously turn the check off.  While here fix the check
for IDs being too large which doesn't work due to type mis-matches.

Reviewed by:    jhb (previous version)
Approved by:	re (kib)
MFC after:	1 month (type mis-match fixes only)
2009-07-22 20:46:17 +00:00
Warner Losh
c879ae3536 Per Regents of the University of Calfornia letter, remove advertising
clause.

# If I've done so improperly on a file, please let me know.
2007-01-09 00:28:16 +00:00
Philippe Charnier
c4fe9d664a add missing endusershell() call. Original version was incorrect.
PR: bin/2442
Reviewed by: Friedemann Becker <zxmxy33@mail.uni-tuebingen.de>
2004-01-18 21:33:25 +00:00
Maxim Konovalov
65edeb2358 Do not allow empty GIDs for non-NIS entries.
MFC after:	2 weeks
2002-10-11 11:35:30 +00:00
Maxim Konovalov
9b7c7ff8ce Too strict error checking in rev. 1.22 broke pwd_mkdb(8) in NIS
environment. An empty UID and GID are valid there.

Spotted by:	rwatson
2002-10-02 07:02:46 +00:00
Maxim Konovalov
05a7daf5ca Disqualify UID/GID with non-numeric character.
PR:		bin/41721
Reviewed by:	tjr, silence on -audit
MFC after:	2 weeks
2002-09-25 08:49:19 +00:00
Dima Dorfman
235d6772d5 Bring a comment in line with the code, and fix some spelling errors
while I'm here.

PR:		35394
Submitted by:	andrew@ugh.net.au
2002-03-09 04:00:53 +00:00
David E. O'Brien
ea8d448a92 Fix SCM ID's. 2002-02-01 00:57:29 +00:00
Dag-Erling Smørgrav
6478822fba Correct some egregious style bugs. 2001-12-04 12:32:35 +00:00
Dag-Erling Smørgrav
a8adfe18ce Add a missing error check. This fixes a bug that would cause pwd_mkdb to
dump core if invoked with an input file that looks like a password file
but isn't (e.g. /etc/group).

PR:		32378
Submitted by:	Maxim Konovalov <maxim@macomnet.ru>
MFC after:	1 week
2001-12-04 12:31:02 +00:00
David Malone
aa9ab917d7 Use the right format string for printing ULONG_MAX. 2001-03-05 11:58:12 +00:00
Jacques Vidrine
248aee623c Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.

= Hesiod has been added to libc (see hesiod(3)).

= A library routine for parsing nsswitch.conf and invoking callback
  functions as specified has been added to libc (see nsdispatch(3)).

= The following C library functions have been modified to use nsdispatch:
    . getgrent, getgrnam, getgrgid
    . getpwent, getpwnam, getpwuid
    . getusershell
    . getaddrinfo
    . gethostbyname, gethostbyname2, gethostbyaddr
    . getnetbyname, getnetbyaddr
    . getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr

= host.conf has been removed from src/etc.  rc.network has been modified
  to warn that host.conf is no longer used at boot time.  In addition, if
  there is a host.conf but no nsswitch.conf, the latter is created at boot
  time from the former.

Obtained from:	NetBSD
2000-09-06 18:16:48 +00:00
Paul Richards
cd7b8d78c7 Fix various unsigned vs signed errors that caused problems with uids
and gids bigger than 16 bits. Added checks for uids and gids that are
bigger than 32 bits.

Approved by:	jkh (partly, this fix is bigger than I first intended)
2000-03-09 18:11:16 +00:00
Sheldon Hearn
9a602acc36 Replace the -q option to pwd_mkdb with a test for PW_SCAN_BIG_IDS in
the environment.  This allows big ID warnings to be suppressed for
vipw and chpass as well.

Since the environment variable test is only performed for callers
of pw_scan() that do not set pw_big_ids_warning, the test can still
be overriden.  Currently, chpass and pwd_mkdb are the only users
of pw_scan() and neither of them overrides the environment variable
test.
1999-12-02 16:39:15 +00:00
Eivind Eklund
637bc59616 Allow empty UIDs if we are processing NIS records. I am not entirely
happy with how this end up and will re-visit the entire empty field
problem, but this patch solves the NIS problem for now.

Submitted by:	Dan Nelson <dan@emsphone.com>
PR:	14865,14984
1999-11-22 12:42:38 +00:00
Sheldon Hearn
18138b08d8 Add to pwd_mkdb a -q option to silence warnings about large IDs. Add a
suitably ominous warning in the manual page.

The diff applied is not the one provided in the attributed PR.

PR:		13344
Reviewed by:	bde
1999-11-15 16:45:37 +00:00
Eivind Eklund
aa510d6741 Flag empty UID entries as errors (to stop typos from turning into
alternate root accounts).
1999-11-06 20:21:04 +00:00
Sheldon Hearn
33d37c13fc Back out previous commit. I mistook passing commentary from bde for
review.

Requested by:	bde
1999-08-31 13:11:39 +00:00
Sheldon Hearn
8559ed58e8 Only issue a warning for the first occurrence of a UID > USHRT_MAX and
the first occurrence of a GID > USHRT_MAX.

PR:	13344
Reviewed by:	bde
1999-08-30 09:55:42 +00:00
Peter Wemm
97d92980a9 $Id$ -> $FreeBSD$ 1999-08-28 01:35:59 +00:00
Philippe Charnier
8b76e1d7a8 Staticize usage(). Cosmetics. 1997-10-10 06:27:07 +00:00
Julian Elischer
6ede0fb59d Submitted by: archie@whistle.com
This program should COMPLAIN about uids > 65K but not abort.. they are after
all legal, and some of us NEED them!
1996-06-20 19:19:29 +00:00
Rodney W. Grimes
709e8f9ae1 Remove trailing whitespace. 1995-05-30 03:57:47 +00:00
David Greenman
cc6f628176 Be sure to properly fail if there are not enough fields. Problem
reported by MARC Giannoni <marc@cmc.eng.comsat.com>, this fix is by me.
1995-01-27 22:30:03 +00:00
Garrett Wollman
28ca30918a Maintain pw_fields, and output same to password database.
!!!!!!!!
NB
!!!!!!!!
You MUST pwd_mkdb /etc/master.passwd before attempting to use the new
libc, or things may go wrong.  (I doubt anything actually /will/ go
wrong, but the actual behavior is undefined.  YOU HAVE BEEN WARNED.)
The database format is, however, backwards-compatible, so old executables
will still work.
1994-09-20 01:15:08 +00:00
Rodney W. Grimes
dea673e932 BSD 4.4 Lite usr.sbin Sources 1994-05-26 05:23:31 +00:00