Commit Graph

49 Commits

Author SHA1 Message Date
Ruslan Ermilov
e2db8d3732 Add endianness support.
While version 4 entries are architecture-independent, we
also store old (version 3) entries in native byte order.
Also, the hash itself is created in a native byte order.

With this change, pwd_mkdb(8) can be used to cross-build
*pwd.db files for another architecture.

Tested on:	i386, amd64, alpha, sparc64
2005-02-28 21:05:30 +00:00
Stefan Farfeleder
bf94610c6b Turn K&R functions into prototypes. 2005-02-10 09:00:55 +00:00
Warner Losh
486c8cc4c6 Per letter dated July 22, 1999 remove 3rd clause of Berkeley derived software
(with permission of addtional copyright holders where appropriate)
2004-08-07 04:28:56 +00:00
Warner Losh
db7bacc61c Add 'i' to the getopt string.
Noticed by: jhein
2004-08-05 15:44:26 +00:00
Warner Losh
9906740e39 Add support for ignoring locking failures. This is only enabled when
you've specified a directory.  It is intended to be used in building
custom releases over NFS where locking may be unreliable at best and
there is no contention that the locking is designed to arbitrate.
Other uses of this flag are discouraged.  Document same in usage and
man page (including the warning about unwise).

Sponsored by: Timing Solutions
2004-07-21 17:38:04 +00:00
Warner Losh
24412bd1af Two style related changes:
(1) use strlcpy instead of strncpy since the use here of the latter
    was incorrect.
(2) Move 'N' case into proper sorted order (sorted the same way that
    ls sorts its args).
2004-07-21 17:02:36 +00:00
David E. O'Brien
b728350ee6 Use __FBSDID over rcsid[]. Protect copyright[] where needed. 2003-05-03 21:06:42 +00:00
Jacques Vidrine
257ca75f51 When updating a single entry (i.e. when the `-u' option is given),
do not add the "\xFF" "VERSION" key --- it should only be added once
ALL entries have been updated.

While I'm here, correct the logic that detects whether or not the
user-ID has changed so that it works even if all entries have not
yet been updated to the new format.

Users missing-in-action were
Reported by:	tjr, Vallo Kallaste <vallo@estcard.ee>,
		    leafy <leafy@leafy.idv.tw>

Sponsored by:	DARPA, Network Associates Laboratories
2003-04-28 11:41:56 +00:00
Jacques Vidrine
b4603f3dd4 Revert the definitions of _PW_KEY* to their previous values. There is
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
2003-04-18 14:11:17 +00:00
Jacques Vidrine
05f98035ee = Implement thread-safe versions of the getpwent(3) and getgrent(3)
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
2003-04-17 14:15:26 +00:00
Alfred Perlstein
2f9af24198 WARNS=4 cleanup, de-__P() 2002-07-11 21:16:52 +00:00
Dima Dorfman
524a875c78 When reporting that a line is too long, include the line number in the
error message.  While I'm here, add a note that the "line too long"
message isn't always accurate.

PR:		35395
Submitted by:	andrew@ugh.net.au
2002-03-09 03:52:14 +00:00
Peter Wemm
9213df7cda Explicitly use int32_t for on-disk records for pw_change and pw_expire,
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.
2001-10-27 02:13:41 +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
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
Peter Wemm
0c2b3c31aa Unifdef -DPASSWD_IGNORE_COMMENTS. This wasn't really optional and
we have enough pseudo-options already.
1999-09-06 17:30:03 +00:00
Peter Wemm
97d92980a9 $Id$ -> $FreeBSD$ 1999-08-28 01:35:59 +00:00
Bill Fumerola
0be7a84b8c Enable source file locking in pwd_mkdb by including the proper letter
in getopt(). The code was there, the means to use it wasn't.

Also update the usage() statment to reflect reality.

PR:		bin/9248
Submitted by:	Jos Backus <jbackus@plex.nl>
Forgotten By:	dillon
1999-01-01 20:39:37 +00:00
Matthew Dillon
be648216c6 PR: bin/3478
Have pwd_mkdb lock the source file while rebuilding the database.  When
    called by programs such as vipw, the source file is a temporary file and
    this does not conflict with the lock on /etc/master.passwd already held
    by vipw.  When run manually, however, master.passwd is typically specified
    as the argument and the locking prevents other programs from messing with
    master.passwd during the database rebuild.

    Also pwd_mkdb uses a blocking exclusive lock as it may be called from
    a script.  The -N option was added to cause pwd_mkdb to get the lock
    non-blocking and exit with an error if the attempt fails, again useful
    for scripts.
1998-12-13 01:53:50 +00:00
Foxfair Hu
17b09acac9 Close PR bin/8753 pwd_mkdb problem when having comments in passwd file
Submitted by Chia-liang Kao clkao@CirX.ORG .
1998-12-12 16:08:41 +00:00
Dmitrij Tejblum
5081946172 Rename a static variable, so it will not shadowed by a local variable.
Now comments will be ignored, rather than put junk in the password database.

Broken in:	rev. 1.21
1998-09-29 20:01:21 +00:00
Andrey A. Chernov
5c9f7df5dc Fix usage string 1998-06-09 20:19:59 +00:00
Poul-Henning Kamp
e6bb224e43 Allow specification of cache-size to pwd_mkdb
PR:		5193
Reviewed by:	phk
Submitted by:	Nick Hilliard <nick@foobar.org>
1998-04-19 07:15:34 +00:00
Guido van Rooij
5160056952 Reenable building of /etc/passwd.
Pointed out by: "Julie M. Juracich" <julie@xaqti.com>
1998-02-19 08:12:11 +00:00
Guido van Rooij
cf5643238e Apparently, if fprintf() fails, it can return any negative value
Pointed out by: Bruce
1998-02-16 19:08:18 +00:00
Guido van Rooij
1aa9837c94 Check return values of fprintf, fclose (this one is overdone I guess)
and pw_db->close.
PR:		4202 (probably, I askd the submitter)
Obtained from:	OpenBSD
1998-02-15 22:31:40 +00:00
Wolfram Schneider
d7f712093f Rename the pwd_mkdb(8) option '-c' to '-C' for better compatiblity
with BSD/OS.
1998-01-10 17:27:28 +00:00
Philippe Charnier
8b76e1d7a8 Staticize usage(). Cosmetics. 1997-10-10 06:27:07 +00:00
Jonathan Lemon
7256f6b3ab db close routine actually writes data out to disk; return value was
not being checked.  Change code to fail if db->close errors.

PR:		4202
1997-08-18 20:48:35 +00:00
Warner Losh
6c3f552a31 compare return value from getopt against -1 rather than EOF, per the final
posix standard on the topic.
1997-03-31 05:11:47 +00:00
David Nugent
dc7eb240ea Fix possible (not stack) overflow from -d <dir> commandline option. 1997-03-20 03:35:06 +00:00
Wolfram Schneider
eb0abfcc18 Allow comments in password database. The comments are copied from
the password file into /etc/master.passwd and optional (-p) into
/etc/passwd. Enable this feature with the compile
option -DPASSWD_IGNORE_COMMENTS.

The character `#' introduces a comment. Leading spaces and tabs are
ignored: '^[ \t]*#.*\n$'

Count an empty line - only spaces, tabs or newline - also as a comment.
An empty line at the bottom of /etc/master.passwd is a common
novice error and increased my mail load: '^[ \t]*\n$'
1997-03-08 14:09:24 +00:00
Bill Paul
8839484b47 Begin closing out PR #1519 (this requires a change to chpass too,
and both changes need to be pulled into the stable branch). The
problem here is that when pwd_mkdb creates /etc/passwd, it turns
empty UID and GID fields into zeroes. To fix this, we check the
_PWF_UID and _PWF_GID bits in the pw_fields flag: if the bits
are not set, we print an empty field instead of a zero. This way,
you don't get zeroes in the UID or GID fields unless you explicit
want them.
1996-10-22 03:18:11 +00:00
Wolfram Schneider
e2ab8bac10 New option: [-c]
Check if the password file is in the correct format. Do not
        change, add, or remove any files.
1996-08-19 16:03:15 +00:00
Bruce Evans
6151b31757 Fixed brackets in usage message.
Reformatted some of recent changes to KNF.
1996-07-12 08:20:28 +00:00
Martin Renters
ca7c8034d2 Check if username is a NULL pointer before dereferencing it. 1996-07-03 21:43:48 +00:00
Guido van Rooij
79a1b8d9e2 Implement incremental passwd database updates. This is done by ading a '-u'
option to pwd_mkdb and adding this option to utilities invoking it.
Further, the filling of both the secure and insecure databases has been
merged into one loop giving also a performance improvemnet.
Note that I did *not* change the adduser command. I don't read perl
(it is a write only language anyway).
The change will drastically improve performance for passwd and
friends with large passwd files. Vipw's performance won't change.
In order to do that some kind of diff should be made between the
old and new master.passwd and depending the amount of changes, an
incremental or complete update of the databases should be agreed
upon.
1996-07-01 19:38:50 +00:00
Bill Paul
6ec733f455 NIS cleanups and fixes, the next generation, continued.
pwd_mkdb.c:

- Don't save the PLUSCNT and MINUSCNT tokens: we don't need them anymore.

- Count the + and - entires for NIS together instead of counting + and -
  entries seperately. Index all special NIS entries using new _PW_KEYYPBYNUM
  token.

pwd.h:

- Remove the PLUSBYNUM, MINUSBYNUM, PLUSCNT and MINUSCNT tokens and replace
  then with a single _PW_KEYYPBYNUM token.
1996-04-16 00:23:59 +00:00
Rodney W. Grimes
709e8f9ae1 Remove trailing whitespace. 1995-05-30 03:57:47 +00:00
Jordan K. Hubbard
72a3d44887 Add what looks to be the right fix to this bogus code. 1995-03-24 16:07:09 +00:00
Bill Paul
d038db90e8 Re-enable +::::::::: wildcards that I had previously disallowed.
Note: if you put +::0:0:::::: in /etc/master.passwd as your only NIS
entry, it will cause all NIS uids and gids to be remapped to zero. This
is *intentional*. That's the way it's supposed to work. Enabling NIS with
no remapping at all is done with +:::::::::, not +::0:0::::::. Similarly,
+:::::::::/bin/csh will remap the shells of all NIS users to /bin/csh.
Or, you could do +wpaul:::::::::/bin/csh to remap NIS user wpaul's shell
to /bin/csh but leave everyone else alone.
1995-03-23 22:31:11 +00:00
Bill Paul
34876b9137 Summarily enable YP as soon as any a '+' is detected instead of generating
special values when +user substitutions are in effect. The new getpwent
code can handle all the special cases itself now.
1995-03-23 17:22:37 +00:00
Bill Paul
ad5d3ccd4d - Add support for embedding special entries in the password databases
for +@netgroup/-@netgroup entries. This saves the getpwent functions
from having to do all the work.

- Fix potential bug: when pwd_mkdb writes the YP-enabled flag to the secure
password database, it uses the wrong database descriptor. (It uses the
descriptor from the non-secure database, which is already closed by the time
things are being written into the secure dastabase).
1995-03-23 00:54:57 +00:00
Garrett Wollman
ab5f8d28a4 Fix security hole in YP password support, which wouldmake +user entries
act like + entries in some cases.  Requires support in libc from next
commit.
1994-09-20 21:40:12 +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
Gary Palmer
fb0e6acc6f Added the -d <directory> functionality to allow construction of the
password databases somewhere other than /etc.
1994-09-07 22:54:00 +00:00
Rodney W. Grimes
dea673e932 BSD 4.4 Lite usr.sbin Sources 1994-05-26 05:23:31 +00:00