Commit Graph

67 Commits

Author SHA1 Message Date
Dag-Erling Smørgrav
508aee9681 pwd_mkdb: Sort options and update usage message.
Sponsored by:	Klara, Inc.
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D39266
2023-03-25 14:15:40 +00:00
Andre Albsmeier
0deb25bd9d pwd_mkdb(8): Don't copy comments from /etc/master.passwd to /etc/passwd.
The intention of /etc/passwd was to support legacy applications that are
not yet converted to use modern API like getpwent(3). Comments are not
defined in the legacy format, so copying them could break these
applications. Plus, it could leak sensitive information (e.g. encrypted
form of password of an user that was commented out instead of deleted
or disabled).

PR:		bin/144652
MFC after:	1 month
2023-01-04 22:18:09 -08:00
Ed Maste
8e1887fa1a pwd_mkdb: retire -B and -L endianness options
Legacy v3 db support was retired in r333133, and it was v3 support that
required the -B and -L options.  The options were retained temporarily,
but now that stable/12 has branched they can be removed.

Sponsored by:	The FreeBSD Foundation
2018-10-21 00:48:38 +00:00
Ed Maste
c20dbeb676 pwd_mkdb: retire legacy v3 db support (-l option)
pwd_mkdb has emitted v4 password database records since 2003 (r113596)
in addition to v3, and as of r283981 by default it emitted only v4.
As described in r283981, retire the -l legacy option.

The -B and -L options were originally added to set the endianness of v3
records emitted by pwd_mkdb, but they also set the db hash endiannes and
so have been retained temporarily.

Announced on the FreeBSD-Current and FreeBSD-Stable lists.  In stable/11
the man page contains a deprecation notice, and pwd_mkdb will emit a
deprecation notice if the -l option is specified.

Reviewed by:	delphij, lidl, rgrimes
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D15144
2018-05-01 00:53:46 +00:00
Ed Maste
e936bb9f69 pwd_mkdb: default to network (big) endian hash order
For cross-architecture reproducibility.  The db(3) functions work with
hashes of either endianness, and the current (v4) version password db
entries already store integers in network order.  Do so with the hash as
well so that identical password databases can be created on big- and
little-endian hosts.

The -B and -L flags exist to set the endianness for legacy (v3) entries
when the -l flag is used, and they will still control hash endianness
(at least until the backwards compatibility infrastructure is removed).

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2018-04-24 01:22:57 +00:00
Ed Maste
97303f37f8 pwd_mkdb: warn that legacy support is deprecated (if specified)
r283981 switched pwd_mkdb to emit only v4 database entries by default,
and introduced a -l (legacy) option emit v3 entries in addition.  The
commit message claims that legacy support will be removed in 12.0, so
emit a warning now if it is used.
2018-04-19 20:25:19 +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
David Malone
95bcaf513b Following revision r295924, the changes to a db file should be fsynced
before the file is closed. Consequently, it shouldn't be necessary to
open the file with O_SYNC any more.

This improves the performance of building large .db files for large
password files a lot and should resolve this problem:

	https://forums.freebsd.org/threads/10-2-pre-pwd_mkdb-slow-on-larger-master-passwd.52700/

Differential Revision:	https://reviews.freebsd.org/D5186
Reviewed by:	garga, vangyzen, bapt, se
MFC after:	1 week
2016-02-23 15:28:13 +00:00
Marcelo Araujo
daa3baeb1d The sdp opens the database with PERM_SECURE mode and it is different than
dp that opens the database with PERM_INSECURE, so we need to check sdp->put
against sdp instead of use dp->put.

PR:		bin/191720
Submitted by:	Miles Ohlrich <turingsboy@yahoo.com>
Approved by:	rodrigc (mentor)
Differential Revision:	https://reviews.freebsd.org/D4255
2015-12-28 05:48:22 +00:00
Renato Botelho
d32a66b2a2 When passwd or group information is changed (by pw, vipw, chpass, ...)
temporary file is created and then a rename() call move it to official file.
This operation didn't have any check to make sure data was written to disk
and if a power cycle happens system could end up with a 0 length passwd
or group database.

There is a pfSense bug with more infor about it:

https://redmine.pfsense.org/issues/4523

The following changes were made to protect passwd and group operations:

* lib/libutil/gr_util.c:
 - Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file
 - After rename(), fsync() call on directory for faster result

* lib/libutil/pw_util.c
 - Replace mkstemp() by mkostemp() with O_SYNC flag to create temp file

* usr.sbin/pwd_mkdb/pwd_mkdb.c
 - Added O_SYNC flag on dbopen() calls
 - After rename(), fsync() call on directory for faster result

* lib/libutil/pw_util.3
 - pw_lock() returns a file descriptor to master password file on success

Differential Revision:	https://reviews.freebsd.org/D2978
Approved by:	bapt
Sponsored by:	Netgate
2015-07-02 17:30:59 +00:00
Xin LI
ac57983523 Whitespace changes for r283981. No actual code changes. 2015-06-04 07:25:40 +00:00
Xin LI
3e08b16eca In r113596, version 4 of entries have been added but pwd_mkdb have
been generating both new (machine independent) and legacy version
entries (endianness sensitive).

The base system have been using the new format for quite some time,
so disable the generation by default.

An interim option, -l, have been added to re-enable old behavior.
The -l, -B and -L options are considered deprecated and will be
removed in FreeBSD 12.0 release.
2015-06-04 07:24:56 +00:00
Ed Schouten
4da4d0013d Mark global functions and/or variables in pwd_mkdb(8) static where possible.
This allows compilers and static analyzers to do more thorough analysis.
2011-11-06 19:02:25 +00:00
Gordon Tetlow
c909243f40 Only increment the ypcnt once per data record. The old implementation
was incrementing it twice making it impossible to iterate the table
since the records were 1, 3, 5, 7 (or 2, 4, 6, 8 for the v3 records).

MFC after:	10 days
2011-07-06 06:34:08 +00:00
Brian Somers
15344a5690 Verify that the username length is smaller than MAXLOGNAME when
asked to verify a passwd file (pwd_mkdb -C).

Entries with oversized usernames are still permitted when building
the passwd database.

When entries are >= MAXLOGNAME in length, they are correctly stored
in passwd, pwd.db and spwd.db but are only correctly retrieved by
getpwent*() and getpwuid*().  getpwnam*() truncates to MAXLOGNAME - 1
when reading from a file (breaking at least sh, tcsh and bash)
and utilities such as su(1) check, complain and fail if the
passed name is >= MAXLOGNAME in length.

MFC after:	3 weeks
2009-05-20 08:32:25 +00:00
Dima Dorfman
ff900deda6 Correctly handle an input file without a newline on the last line (and
avoid the confusing error message about the line being too long). This
change uses fgetln to detect the right conditions, but the fixed-width
line buffer is kept because too many other places in the program make
assumptions about its maximum width.

Approved by:	re (scottl)
2005-06-15 10:13:04 +00:00
Philippe Charnier
ce2657c007 Even if variable is never used uninitialized by the semantic, reduce compiler
warning by giving an initial value in all cases.
2005-05-29 16:01:12 +00:00
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