Commit Graph

49 Commits

Author SHA1 Message Date
Baptiste Daroussin
0cd4b781a6 pw(8): use openmemstream instead of sbuf(9) 2021-04-27 05:09:07 +02:00
Yuri Pankov
ea7fdebe80 pw: fix the checks in boolean_str() after r326738. Add related test
cases for `pw useradd -D -w`.

PR:		231649
Reviewed by:	eugen
Approved by:	kib (mentor)
Differential Revision:	https://reviews.freebsd.org/D17299
2018-10-21 14:23:56 +00:00
Yuri Pankov
4835c3b1df pw: (file == NULL) check is always false in read_userconfig(), remove
it.  Drop the now unused _PATH_PW_CONF definition. [1]

While here, change the last remaining hardcoded "/etc" to _PATH_PWD.

Noted by:	glebius [1]
Reviewed by:	eugen
Approved by:	re (gjb), kib (mentor)
Differential Revision:	https://reviews.freebsd.org/D17575
2018-10-16 16:00:41 +00:00
Yuri Pankov
03da20c5fa pw: respect path specified using -V when writing pw.conf, and -C is not
explicitly specified.  -V path is already used to determine which file
to read default values from, so it's only logical to write them to the
same file.

PR:		231653
Reviewed by:	eugen, bapt
Approved by:	re (gjb), kib (mentor)
Differential Revision:	https://reviews.freebsd.org/D17566
2018-10-15 20:11:53 +00:00
Eugene Grosbein
d30f122fa6 pw(8): correct expiration period handling and command line overrides
to preconfigured values for -e, -p and -w flags.

Use non-negative symbols instead of magic values
in passwd_val/pw_password functions.

PR:		223431
Submitted by:	Yuri Pankov (in part, patch for the manual)
Reported by:	mav (mentor)
MFC after:	3 days
Relnotes:	yes
2017-12-09 23:34:00 +00:00
Pedro F. Giffuni
1de7b4b805 various: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

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.

No functional change intended.
2017-11-27 15:37:16 +00:00
Alan Somers
7c46e6ef06 pw should sanitize the argument of -w.
Otherwise, it will silently disable the login for the selected account if
the argument is unrecognizable.

usr.sbin/pw/pw.h
usr.sbin/pw/pw_conf.c
usr.sbin/pw/pw_user.c
	Use separate rules to validate boolean parameters and passwd
	parameters.  Error out if a password parameter cannot be parsed.

usr.sbin/pw/tests/Makefile
usr.sbin/pw/tests/crypt.c
usr.sbin/pw/tests/pw_useradd.sh
usr.sbin/pw/tests/pw_usermod.sh
	Add tests for the validation.  Also, enhance existing
	password-related tests to actually validate that the correct hash is
	written to master.passwd.

Reviewed by:	bapt
MFC after:	4 weeks
Sponsored by:	Spectra Logic Corp
Differential Revision:	https://reviews.freebsd.org/D6840
2016-07-13 17:09:20 +00:00
Baptiste Daroussin
49d448f523 Simplify code for parsing extra groups 2015-12-29 00:08:32 +00:00
Baptiste Daroussin
5cc12db1c7 Use intmax_t rather than long long 2015-08-02 19:49:24 +00:00
Baptiste Daroussin
fc5079452d Fix build on 32bits 2015-08-02 13:50:11 +00:00
Baptiste Daroussin
bcbdb01e56 Cleanup a bit includes 2015-08-02 13:22:46 +00:00
Baptiste Daroussin
d2d022b9fd Rewrite parsing subcommands arguments of pw(8)
Now each subcommands checks its arguments in a dedicated functions.

This helps improving input validation, code readability/maintainability
While here:
- Add a -y option to pw userdel/usermod so it can maintain NIS servers if
  nispasswd is not defined in pw.conf(5)
- Allow pw -r <rootdir> to remove directory with userdel -r
- Fix bug when renaming a user which was not renaming the user name it groups
  it is a member of.
- Only parse pw.conf(5) when needed.
2015-08-02 12:47:50 +00:00
Baptiste Daroussin
458fdd97ab Remove things that crept in after badly checked revert 2015-08-01 12:20:55 +00:00
Baptiste Daroussin
7493058fb6 Partial revert of r286152
More work needed on the cli validation
2015-08-01 12:18:48 +00:00
Baptiste Daroussin
7391bf5ada Fix build 2015-08-01 11:52:48 +00:00
Baptiste Daroussin
510113b84d Fix formatting of new code
Fix sorting or errstr
Remove useless initialisation or errstr

Reported by:	bde
2015-08-01 11:31:59 +00:00
Baptiste Daroussin
80d9f89289 Validate expiration days and password days from commmand line and pw.conf 2015-08-01 10:25:55 +00:00
Baptiste Daroussin
e5e7ef48eb Validate the max_uid/max_gid boundaries and entry type in pw.conf 2015-08-01 10:10:13 +00:00
Baptiste Daroussin
50698e6718 Cast uid/git to uintmax_t when using printf-like functions so the size of
uid/gid size remains a implementation detail
2015-08-01 09:55:47 +00:00
Baptiste Daroussin
10e6a51cf3 Replace custom string array with stringlist(3) 2015-07-11 23:07:17 +00:00
Baptiste Daroussin
68cea7d570 Remove useless cast in printf and printf-like functions:
use %u for uid_t and gid_t
2015-05-31 22:07:03 +00:00
Baptiste Daroussin
7fc593dd82 Move cleanup functions to the right place 2015-05-31 12:04:06 +00:00
Baptiste Daroussin
2e6d97a407 Remove useless test before free() 2015-05-31 11:56:59 +00:00
Baptiste Daroussin
c69b42d00b Return early in case we cannot read the configuration file
This drops one level of indentation
2015-05-31 11:55:28 +00:00
Baptiste Daroussin
a1d3bf2e8f Use calloc(3) instead of malloc(3) + memset(3)
While here check the return of calloc(3)
2015-05-10 11:18:01 +00:00
Baptiste Daroussin
36dc2e6885 The initial logic for allocating the new string was wrong, the conversion
to strndup(3) duplicated the same mistake, actually strdup(3) is good enough
to allocate the new string.
2015-05-10 10:15:36 +00:00
Baptiste Daroussin
a84caa72b0 Use strndup(3) instead of malloc(3) + memcpy(3)
Check the return of strndup
2015-05-10 10:02:09 +00:00
Baptiste Daroussin
2c3065da9c Remove useless call to extendarray 2015-05-10 09:33:15 +00:00
Baptiste Daroussin
8592cfc58e Remove now unused LNBUFSZ buffer size 2015-05-09 22:08:30 +00:00
Baptiste Daroussin
5963cf64b5 Return from the function as early as possible
This reduces the depth of the if statements and improves clarity of the code
2015-05-09 21:53:33 +00:00
Baptiste Daroussin
a8e37ee0ac Use sbuf(9) instead of homebrewed buffered string 2015-05-09 19:00:16 +00:00
Baptiste Daroussin
c145c34c09 Simplify reading pw.conf(5) by using getline(3) 2014-04-22 21:07:56 +00:00
Jung-uk Kim
644af48df6 Stop hard-coding default directory mode as 0777. 2011-03-08 20:13:29 +00:00
Lukas Ertl
85204142eb Add home directory creation mode to pw.conf(5) and be a bit
more specific about the effect of the current umask on -M.
2007-03-30 11:23:10 +00:00
Brian Somers
2313781df2 Handle snprintf() returning < 0 (not just -1)
MFC after:	2 weeks
2001-08-20 15:09:34 +00:00
Brian Somers
36c1612b5e Handle snprintf() returning -1.
MFC after:	2 weeks
2001-08-20 13:24:39 +00:00
Doug Barton
fc308a5491 Make the comment generated in /etc/pw.conf match reality
PR:				misc/23451
Submitted by:	Ben Rosengart, ben@narcissus.net
2000-12-18 01:35:56 +00:00
David Nugent
670eb236c0 Catch up to the fact that we now have tcsh in the tree. 2000-07-16 01:46:26 +00:00
Peter Wemm
97d92980a9 $Id$ -> $FreeBSD$ 1999-08-28 01:35:59 +00:00
David Nugent
479bcf69f7 Remove some more warnings. 1999-07-28 12:49:34 +00:00
David Nugent
5f12594a29 1) Do not blindly ignore file update errors which may occur due to concurrent
updating
2) Add -V <etcdir>, which allows maintaining user/group database in alternate
   locations other than /etc.
1999-02-23 07:15:11 +00:00
Philippe Charnier
1dcc6ec750 Use err(3) instead of local redefinition. Add rcsid string. 1997-10-10 06:23:42 +00:00
David Nugent
d3329f56fa Unquote default group in pw.conf.
PR: 4365
Submitted by: "Andrew L. Moore" <alm@mclink.com>
1997-09-01 09:33:08 +00:00
Peter Wemm
476602a9d0 Revert $FreeBSD$ to $Id$ 1997-02-22 16:15:28 +00:00
Jordan K. Hubbard
1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00
David Nugent
f1d684fad9 Adds optional NIS passwd file updating and optionally rebuilding
NIS maps.

Suggested by:	Peter Wemm
1997-01-05 07:15:37 +00:00
David Nugent
0970881ff6 1) 200 users per group limitation removed and pw
will handle lines of any length in /etc/group.
2)	Fixed bug with usermod -d not updating user's home
	directory.
3)	Minor formatting display changes/fixes with *show -P.
1996-12-21 15:35:45 +00:00
Joerg Wunsch
ad7cf975be Copyright update by the author, to be more in line with our sample
copyright.

Submitted by:	David Nugent
1996-12-10 23:59:04 +00:00
Joerg Wunsch
d6f907dc7a pw(8) -- a backend utility to manage the user and group databases.
sysinstall's new User&group menu will use it, hence it's a 2.2
candidate despite of providing new functionality.

Submitted by:	David L. Nugent, <davidn@blaze.net.au>
1996-12-09 14:05:35 +00:00