Commit Graph

450 Commits

Author SHA1 Message Date
Simon J. Gerraty
d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
John Baldwin
1055bedbed pw: Don't return a pointer to an on-stack buffer from grp_set_passwd.
Make 'line' static to move it to .bss instead as that pattern is used
elsewhere in pw(8) (e.g. the static buffer in pw_pwcrypt).

Reported by:	GCC -Wdangling-pointer
Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D37534
2022-12-04 16:28:22 -08:00
Eugene Grosbein
1cbe5012cf pw(8): fix combination of modes -N and -w random
The command "pw usermod nobody -Nw random" (or useradd)
generates random password and prints it in encrypted form
but skips choosen random string that makes not much sense
and contradicts the manual page pw.8

Fix it by showing random password in plain text with -N and
without it equally. Add yet another example of how to generate
pw-style random password.

MFC after:	2 weeks
2022-11-28 21:22:39 +07:00
Baptiste Daroussin
88e6c9a674 pw: remove the inaccurate anymore information from the README 2022-10-12 12:11:32 +02:00
Baptiste Daroussin
c0358afd5b pw: exit with an error in case of using an illegal option
PR:		263188
Reported by:	Dennis Clarke <dclarke@blastwave.org>
MFC After:	1 week
2022-10-12 12:06:32 +02:00
Dag-Erling Smørgrav
0aa2700123 Put OPIE to rest.
Differential Revision: https://reviews.freebsd.org/D36592
2022-10-02 03:37:29 +02:00
Mateusz Piotrowski
adf9cd56fa pw.8: Refernece to openssl-passwd(1) and crypt(3)
It may be unclear how to generate an encrypted password hash for -H,
so point users to openssl-passwd(1) and crypt(3).

MFC after:	2 weeks
2022-07-21 20:08:05 +02:00
Baptiste Daroussin
0a9541d9f3 pw: reinitialize struct tm before every call to strptime
This prevents corrupted result due to leftover of previous failed
call to strptime
2022-06-07 22:32:35 +02:00
Doug Rabson
5e9c888a7a pkgbase: Move pw to the runtime package
This allows building a container image with enough functionality for
downloading and installing packages without having to include the
utilities package.

Reviewed by: manu
MFC after:   2 weeks
2022-05-30 15:23:00 +01:00
Mateusz Piotrowski
84733f2e96 pw.8: Do not specify full path to shell in examples
Providing a full path to a shell is discouraged in the description of
the -s flag. Let's follow the best practices in the examples.

MFC after:	1 week
2022-04-03 14:52:08 +02:00
Mateusz Piotrowski
5243e560f6 pw.8: Fix synopsis of NIS flags
MFC after:	1 week
2022-04-03 13:54:10 +02:00
Mateusz Piotrowski
a0177bd56a pw.8: Sorty synopsis flag
MFC after:	1 week
2022-04-03 13:54:10 +02:00
Mateusz Piotrowski
feb04c7b7c pw.8: Improve argument names
Arguments passed to flags like -d and -k had ambiguous names like "dir".
Change that to more descriptive names like "homedir".

Also, clarify that -u min,max is for UIDs and -i min,max for GIDs.

MFC after:	1 week
2022-04-03 13:54:09 +02:00
Mateusz Piotrowski
39245a7d45 pw.8: Sort flags in synopsis
MFC after:	1 week
2022-04-02 00:49:53 +02:00
Mateusz Piotrowski
77fd0356ef pw.8: Use more appropriate mdoc macros
MFC after:	1 week
2022-04-02 00:49:53 +02:00
Mateusz Piotrowski
61e11ed9bd pw.8: Improve use of mdoc macros in description section
MFC after:	1 week
2022-04-02 00:49:52 +02:00
Mateusz Piotrowski
5392b4fbb7 pw.8: Use Cm and Ar correctly in synopsis
MFC after:	1 week
2022-04-02 00:49:52 +02:00
Baptiste Daroussin
0cd4b781a6 pw(8): use openmemstream instead of sbuf(9) 2021-04-27 05:09:07 +02:00
Kyle Evans
7cc42f6d25 Do a sweep and remove most WARNS=6 settings
Repeating the default WARNS here makes it slightly more difficult to
experiment with default WARNS changes, e.g. if we did something absolutely
bananas and introduced a WARNS=7 and wanted to try lifting the default to
that.

Drop most of them; there is one in the blake2 kernel module, but I suspect
it should be dropped -- the default WARNS in the rest of the build doesn't
currently apply to kernel modules, and I haven't put too much thought into
whether it makes sense to make it so.
2020-10-01 01:10:51 +00:00
Mark Johnston
645c2851e2 pw: Handle errors from ftell() when removing records from /etc/opiekeys.
Reported by:	Coverity
MFC after:	1 week
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
2020-09-01 15:15:09 +00:00
Mark Johnston
7a82cf511d pw: Fix a resource leak.
Reported by:	Coverity
MFC after:	1 week
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
2020-09-01 15:14:51 +00:00
Mark Johnston
45bfd3158c pw: Remove unnecessary errp checks.
The caller-supplied pointer is unconditionally dereferenced at the
beginning of the function, so there is no point in comparing it with
NULL thereafter.

Reported by:	Coverity
MFC after:	1 week
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
2020-09-01 15:14:26 +00:00
Mark Johnston
79c8ad8368 pw: Fix terminal handling when setting a group password.
Reported by:	Coverity
MFC after:	1 week
Sponsored by:	NetApp, Inc.
Sponsored by:	Klara, Inc.
2020-09-01 15:14:13 +00:00
Baptiste Daroussin
a75f9261d6 pw: do not removed home directories if not owned
When deleting a user, if its home directory does not belong to it, it should
not be removed. This is the promise that the manpage makes, the tool should
ensure that it respects that promise.

Add a regression test about it

PR:		244967
Submitted by:	Eric Hanneken <eric@erichanneken.com>
MFC after:	3 days
2020-03-23 08:23:22 +00:00
Li-Wen Hsu
60f043fe8e Remove an uneeded indentation introduced in r286196 to silence gcc warnging
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2019-05-25 21:57:01 +00:00
Benedict Reuschling
60c81cf107 Add an example to pw.8 about how to add an existing user to a group.
Instead of using pw to modify group membership, users often edit
/etc/group by hand, which is discouraged.  Provide an example of
adding a user to the wheel group, which is a common use case.
I'm using a different user here as in the previous example as that
deleted the user (although the examples don't necessarily have to
be followed in order).

Reviewed by:	rgrimes,0mp
Approved by:	0mp
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D19123
2019-02-08 22:10:40 +00: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
Ian Lepore
029a2d652e Remove some code that's no longer needed because it's now part of pw_scan(3).
It was also leading to segfaults; pw can be NULL when control reaches these
lines now, because of the way my previous change restructured the loops.

Reported by:	lwhsu@
2018-07-27 15:17:24 +00:00
Ian Lepore
3196b50827 Re-apply r336625 which was reverted with r336638, now that the underlying
pw_scan(3) has been fixed in a way that doesn't perturb other callers of
it or the getpwnam(3) family.

Make pw(8) showuser work the same with or without -R <path> for non-root
users.  Without -R, pw(8) uses getpwnam(3), which will open master.passwd
for the root user or passwd for non-root users.  With -R <path> pw(8) was
always opening <path>/master.passwd, which would fail for a non-root user,
then falsely claim the userid you're trying to show doesn't exist.

Now for a non-root user it opens <path>/passwd, and populates the fields in
the returned struct passwd which aren't present in that file with well-known
canonical values, which duplicates the behavior of getpwnam(3).  The net
effect is that the showuser output is identical whether using -R or not.
2018-07-26 20:03:11 +00:00
Ian Lepore
d05db9a4ff Revert r336625 until I figure out why it worked with simple testing but
reportedly fails the kyua tests and causes other real-world problems.

Reported by:	cy@ asomers@
2018-07-23 14:58:44 +00:00
Ian Lepore
1a61d99330 Make pw(8) showuser work the same with or without -R <path> for non-root
users.  Without -R, pw(8) uses getpwnam(3), which will open master.passwd
for the root user or passwd for non-root users.  With -R <path> pw(8) was
always opening <path>/master.passwd, which would fail for a non-root user,
then falsely claim the userid you're trying to show doesn't exist.

Now for a non-root user it opens <path>/passwd and zeroes out the 3 fields
that aren't available in the passwd file, which duplicates the behavior of
getpwnam(3).  The net effect is that the showuser output is identical
whether using -R or not.
2018-07-22 23:41:40 +00:00
David Bright
32bd1c2bb3 Allow the "@" and "!" characters in passwd file GECOS fields.
Two PRs (152084 & 210187) request allowing the "@" and/or "!"
characters in the passwd file GECOS field. The man page for pw does
not mention that those characters are disallowed, Linux supports those
characters in this field, and the "@" character in particular would be
useful for storing email addresses in that field.

PR:		152084, 210187
Submitted by:	jschauma@netmeister.org, Dave Cottlehuber <dch@freebsd.org>
Reported by:	jschauma@netmeister.org, Dave Cottlehuber <dch@freebsd.org>
Reviewed by:	delphij (secteam), vangyzen
MFC after:	1 week
Sponsored by:	Dell EMC
Differential Revision:	https://reviews.freebsd.org/D14519
2018-03-01 17:47:28 +00:00
Eugene Grosbein
a2c08ce75b pw(8): r326738 broke expiration arithmetic in case of `-D' flag not supplied.
Fix it and rename misnamed time_t variables `expire_days, password_days'
(always holding absolute time) to `expire_time, password_time'.

Add a comment for a case of overloading `cmdcnf->password_days'
and `cmdcnf->expire_days' with absolute time.

Reported by:	markj
Approved by:	mav (mentor)
MFC after:	1 week
2017-12-15 06:05:16 +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
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Ed Maste
8d2dbd281f pw useradd: Validate the user name before creating the entry
Previouly it was possible to create users with spaces in the name with:
pw useradd -u 1234 -g 1234 -n 'test user'

The "-g 1234" is relevant, without it the name was already rejected
as expected:

[fk@test ~]$ sudo pw useradd -u 1234 -n 'test user'
pw: invalid character ` ' at position 4 in userid/group name

Bug unintentionally found with a salt config without explicit name entry:

test user:
  user.present:
    - uid: 1234
    - gid: 1234
    - fullname: Test user
    - shell: /usr/local/bin/bash
    - home: /home/test
    - groups:
      - wheel
      - salt

"Luckily" salt modules rarely bother with input validation either ...

PR:		221416
Submitted by:	Fabian Keil
Obtained from:	ElectroBSD
MFC after:	1 week
2017-08-19 00:32:26 +00:00
Ed Maste
3dc869c257 pw usermod: Properly deal with empty secondary group lists (-G '')
"pw usermod someuser -G ''" is supposed make sure that someuser
doesn't have any secondary group memberships.

Previouly it was a nop because split_groups() only intitialised
"groups" if at least one group was specified. As a result the
existing secondary group memberships were kept.

PR:		221417
Submitted by:	Fabian Keil
Obtained from:	ElectroBSD
MFC after:	1 week
Relnotes:	yes
2017-08-19 00:19:23 +00:00
Enji Cooper
d511b20a69 Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.
2017-08-02 08:50:42 +00:00
Enji Cooper
4b330699f8 Convert traditional ${MK_TESTS} conditional idiom for including test
directories to SUBDIR.${MK_TESTS} idiom

This is being done to pave the way for future work (and homogenity) in
^/projects/make-check-sandbox .

No functional change intended.

MFC after:	1 weeks
2017-08-02 08:35:51 +00:00
Enji Cooper
b8504cc0a6 pw: add some basic testcases for groupshow and usershow
- groupshow: test out -a/-g/-n .
- usershow: test out -a/-n/-u .

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-05-28 02:15:57 +00:00
Alan Somers
0ce59aa848 Don't depend on assert(3) getting evaluated
Reported by:	imp
MFC after:	3 weeks
X-MFC-With:	318141, 318143
Sponsored by:	Spectra Logic Corp
2017-05-10 16:06:22 +00:00
Alan Somers
daccabe958 strcpy => strlcpy
Reported by:	Coverity
CID:		1006715
MFC after:	3 weeks
Sponsored by:	Spectra Logic Corp
2017-05-10 15:38:06 +00:00
Baptiste Daroussin
d1005f6a13 Add a regression test for r31512 fix
PR:		217934
MFC after:	1 week
2017-03-25 10:47:58 +00:00
Eugene Grosbein
92bb425e4e Properly initialise with content of pw.conf(5) that was mistakenly ignored.
Also, respect "defaultgroup" if specified there.

PR:		217934
Reported by:	Victor Sudakov <vas@mpeks.tomsk.su>
Reviewed by:	bapt
Approved by:	bapt, vsevolod (mentor)
MFC after:	1 week
2017-03-24 16:18:57 +00:00
Enji Cooper
458cbf0ae6 Rename tests from <foo> to <foo>_test to match the FreeBSD test suite
naming scheme

usr.bin/diff/diff_test was renamed to usr.bin/diff/netbsd_diff_test
to avoid collisions with the renamed FreeBSD test.

MFC after:	1 week
Sponsored by:	Dell EMC Isilon
2017-03-23 03:28:24 +00:00
Alan Somers
58fbd700fa Increase WARNS for pw tests
ATF tests have a default WARNS of 0, unlike other usermode programs.

Reviewed by:  ngie, julian
MFC after:    3 weeks
Sponsored by: Spectra Logic Corporation
Differential Revision:        https://reviews.freebsd.org/D9933
2017-03-11 00:11:20 +00:00
Baptiste Daroussin
b11244e721 Really restore the old behaviour for pw usermod -m
It again reinstall missing skel files without overwriting changed one
Add a regression test about it

Reported by:	ae
MFC after:	3 days
2017-01-22 20:03:18 +00:00