]> git.cameronkatri.com Git - pw-darwin.git/log
pw-darwin.git
3 years agoadduser rmuser: Customizable prefix
Cameron Katri [Wed, 25 Aug 2021 23:10:49 +0000 (19:10 -0400)]
adduser rmuser: Customizable prefix

3 years agoMake all calls to install POSIX
Cameron Katri [Wed, 25 Aug 2021 22:59:18 +0000 (18:59 -0400)]
Make all calls to install POSIX

3 years agousr.bin/chpass: Correct manpage regarding path to temp files
Ceri Davies [Tue, 25 May 2021 15:11:45 +0000 (16:11 +0100)]
usr.bin/chpass: Correct manpage regarding path to temp files

Approved by: blackend (mentor)

3 years agoUse system not RunCmd
Cameron Katri [Tue, 4 May 2021 12:56:28 +0000 (08:56 -0400)]
Use system not RunCmd

3 years agoAssume manpages are compressed with zst
Cameron Katri [Mon, 3 May 2021 18:30:12 +0000 (14:30 -0400)]
Assume manpages are compressed with zst

3 years agoRecommit everything, add chpass, improve history (except for a few files that git...
Cameron Katri [Sun, 2 May 2021 20:00:07 +0000 (16:00 -0400)]
Recommit everything, add chpass, improve history (except for a few files that git-filter-repo dislikes for some reason [_secure_path.c and login_cap.h])

3 years agopw(8): use openmemstream instead of sbuf(9)
Baptiste Daroussin [Tue, 27 Apr 2021 03:05:13 +0000 (05:05 +0200)]
pw(8): use openmemstream instead of sbuf(9)

4 years agoAdd function getlocalbase() to libutil.
Stefan Eßer [Wed, 18 Nov 2020 19:44:30 +0000 (19:44 +0000)]
Add function getlocalbase() to libutil.

This function returns the path to the local software base directory, by
default "/usr/local" (or the value of _PATH_LOCALBASE in include/paths.h
when building the world).

The value returned can be overridden by 2 methods:

- the LOCALBASE environment variable (ignored by SUID programs)
- else a non-default user.localbase sysctl value

Reviewed by: hps (earlier version)
Relnotes: yes
Differential Revision: https://reviews.freebsd.org/D27236

4 years agoPartially revert r367756 (chpass(1) synopsis changes)
Mateusz Piotrowski [Tue, 17 Nov 2020 16:54:12 +0000 (16:54 +0000)]
Partially revert r367756 (chpass(1) synopsis changes)

Let's have two entries in the synopsis:
- chpass now lists options which can be used for non-NIS-specific
  functionalities.
- ypchpass additionally lists the NIS-specific flags.

Technically, it is an artificial distinction, as chpass and ypchpass behave
identically. Nevertheless, it might help navigating the synopsis section.

Reviewed by: imp
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D27251

4 years agoAdd an example for the -s flag
Mateusz Piotrowski [Tue, 17 Nov 2020 12:04:29 +0000 (12:04 +0000)]
Add an example for the -s flag

MFC after: 2 weeks

4 years agoImprove readability of the lists of options
Mateusz Piotrowski [Tue, 17 Nov 2020 10:57:28 +0000 (10:57 +0000)]
Improve readability of the lists of options

- Sort options alphabetically
- Add missing arguments (e.g., "list" to -a)
- Adjust the width of Bl

MFC after: 1 week

4 years agoClean up the synopsis section & fix mandoc warnings
Mateusz Piotrowski [Tue, 17 Nov 2020 10:48:01 +0000 (10:48 +0000)]
Clean up the synopsis section & fix mandoc warnings

The synopsis section had two very similar entries. The flags documented by
the first one were a strict subset of the second one. Let's just keep only
the second entry for simplicity.

MFC after: 1 week

4 years agoRevert the whole getlocalbase() set of changes while a different design is
Scott Long [Sun, 15 Nov 2020 20:24:59 +0000 (20:24 +0000)]
Revert the whole getlocalbase() set of changes while a different design is
hashed out.

4 years agoFix a problem with r367686 related to the use of ssize_t. Not sure how this
Scott Long [Sat, 14 Nov 2020 19:04:36 +0000 (19:04 +0000)]
Fix a problem with r367686 related to the use of ssize_t.  Not sure how this
escaped prior testing, but it should be better now.

Reported by: lots

4 years agoAdd the library function getlocalbase and its manual page. This helps to
Scott Long [Sat, 14 Nov 2020 17:57:50 +0000 (17:57 +0000)]
Add the library function getlocalbase and its manual page.  This helps to
unify the retrieval of the various ways that the local software base directory,
typically "/usr/local", is expressed in the system.

Reviewed by: se
Differential Revision: https://reviews.freebsd.org/D27022

4 years agopw: Handle errors from ftell() when removing records from /etc/opiekeys.
Mark Johnston [Tue, 1 Sep 2020 15:15:09 +0000 (15:15 +0000)]
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.

4 years agopw: Fix a resource leak.
Mark Johnston [Tue, 1 Sep 2020 15:14:51 +0000 (15:14 +0000)]
pw: Fix a resource leak.

Reported by: Coverity
MFC after: 1 week
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.

4 years agopw: Remove unnecessary errp checks.
Mark Johnston [Tue, 1 Sep 2020 15:14:26 +0000 (15:14 +0000)]
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.

4 years agopw: Fix terminal handling when setting a group password.
Mark Johnston [Tue, 1 Sep 2020 15:14:13 +0000 (15:14 +0000)]
pw: Fix terminal handling when setting a group password.

Reported by: Coverity
MFC after: 1 week
Sponsored by: NetApp, Inc.
Sponsored by: Klara, Inc.

4 years agoFix i386 build of chpass after r363992
Alex Richardson [Sat, 8 Aug 2020 10:05:27 +0000 (10:05 +0000)]
Fix i386 build of chpass after r363992

My change to allow bootstrapping pwd_mkdb (r363992) resulted in i386 build
failures because the bootstrap header was being included in non-bootstrap chpass.
Dropping the no longer required pwd_mkdb include path from chpass fixes
the build, but to be certain that the failure doesn't get re-introduced,
I've also moved the bootstrap pwd.h into a subdirectory so that adding
-I${SRCTOP}/usr.sbin/pwd_mkdb doesn't pull it in.

Reported by: mjg

4 years agoMake vipw error message less cryptic
Piotr Pawel Stefaniak [Sat, 20 Jun 2020 06:20:00 +0000 (06:20 +0000)]
Make vipw error message less cryptic

Unable to find an editor, vipw would give this error:
# env EDITOR=fnord vipw
vipw: pw_edit(): No such file or directory

vigr or crontab do better:
# env EDITOR=fnord crontab -e
crontab: no crontab for root - using an empty one
crontab: fnord: No such file or directory
crontab: "fnord" exited with status 1

After this change, vipw behaves more like vigr or crontab:
# env EDITOR=fnord vipw
vipw: fnord: No such file or directory
vipw: "fnord" exited with status 1

Reviewed by: rpokala, emaste
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D25369

4 years agolibutil: remove extraneous ": " from error messages
Piotr Pawel Stefaniak [Sat, 20 Jun 2020 06:10:42 +0000 (06:10 +0000)]
libutil: remove extraneous ": " from error messages

Each of the err() family of functions already takes care of that.

4 years agoadduser: allow standard IFS characters in passwords
Kyle Evans [Sun, 5 Apr 2020 19:25:46 +0000 (19:25 +0000)]
adduser: allow standard IFS characters in passwords

Notably, the default IFS contains space/tab, thus any leading/trailing
whitespace characters tend to be removed.

Set IFS= for just the read lines to mitigate this, allowing the user to be
less surprised when their leading/trailing spaces weren't actually captured
in the password as they are with other means of setting a user's password.

PR: 245342
Submitted by: dereks_lifeofadishwasher.com
Reviewed by: jilles
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D24292

4 years agopw: do not removed home directories if not owned
Baptiste Daroussin [Mon, 23 Mar 2020 08:23:22 +0000 (08:23 +0000)]
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

5 years agoRemove an uneeded indentation introduced in r286196 to silence gcc warnging
Li-Wen Hsu [Sat, 25 May 2019 21:57:01 +0000 (21:57 +0000)]
Remove an uneeded indentation introduced in r286196 to silence gcc warnging

MFC after: 3 days
Sponsored by: The FreeBSD Foundation

5 years agoAdd an example to pw.8 about how to add an existing user to a group.
Benedict Reuschling [Fri, 8 Feb 2019 22:10:40 +0000 (22:10 +0000)]
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

6 years agopw: fix the checks in boolean_str() after r326738. Add related test
Yuri Pankov [Sun, 21 Oct 2018 14:23:56 +0000 (14:23 +0000)]
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

6 years agopw: (file == NULL) check is always false in read_userconfig(), remove
Yuri Pankov [Tue, 16 Oct 2018 16:00:41 +0000 (16:00 +0000)]
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

6 years agopw: respect path specified using -V when writing pw.conf, and -C is not
Yuri Pankov [Mon, 15 Oct 2018 20:11:53 +0000 (20:11 +0000)]
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

6 years agoRemove some code that's no longer needed because it's now part of pw_scan(3).
Ian Lepore [Fri, 27 Jul 2018 15:17:24 +0000 (15:17 +0000)]
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@

6 years agoRe-apply r336625 which was reverted with r336638, now that the underlying
Ian Lepore [Thu, 26 Jul 2018 20:03:11 +0000 (20:03 +0000)]
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.

6 years agoMake pw_scan(3) more compatible with getpwent(3) et. al. when processing
Ian Lepore [Thu, 26 Jul 2018 18:34:38 +0000 (18:34 +0000)]
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.

6 years agoRevert r336619, it appears to cause problems with ssh, and probably other
Ian Lepore [Mon, 23 Jul 2018 17:26:38 +0000 (17:26 +0000)]
Revert r336619, it appears to cause problems with ssh, and probably other
things which use pw_scan().

6 years agoRevert r336625 until I figure out why it worked with simple testing but
Ian Lepore [Mon, 23 Jul 2018 14:58:44 +0000 (14:58 +0000)]
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@

6 years agoMake pw(8) showuser work the same with or without -R <path> for non-root
Ian Lepore [Sun, 22 Jul 2018 23:41:40 +0000 (23:41 +0000)]
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.

6 years agoSet the pw_class field to NULL when scanning the non-master passwd file.
Ian Lepore [Sun, 22 Jul 2018 22:34:20 +0000 (22:34 +0000)]
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.

6 years agoClean up the vcs ID strings in libc's gen/ directory.
John Baldwin [Tue, 3 Jul 2018 17:31:45 +0000 (17:31 +0000)]
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

6 years agoUse __SCCSID() for SCCS IDs.
John Baldwin [Wed, 23 May 2018 17:02:12 +0000 (17:02 +0000)]
Use __SCCSID() for SCCS IDs.

- Define NO__SCCSID in CFLAGS to preserve existing behavior of omitting
  SCCS IDs by default.
- While here, fix the $FreeBSD$ in pw_util.c to use __FBSDID.

6 years agochpass: reject change/expiry dates beyond y2106
Ed Maste [Thu, 19 Apr 2018 12:50:49 +0000 (12:50 +0000)]
chpass: reject change/expiry dates beyond y2106

The pwd.db and spwd.db files store the change and expire dates as
unsigned 32-bit ints, which overflow in 2106.  Reject larger values for
now, until the introduction of a v5 password database.

i386 has 32-bit time_t and so dates beyond y2038 are already rejected by
mktime.

PR: 227589
Reviewed by: lidl
MFC after: 1 week
Sponsored by: The FreeBSD Foundation

6 years agoAllow the "@" and "!" characters in passwd file GECOS fields.
David Bright [Thu, 1 Mar 2018 17:47:28 +0000 (17:47 +0000)]
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

7 years agoRemove unused includes.
Xin LI [Mon, 1 Jan 2018 08:01:26 +0000 (08:01 +0000)]
Remove unused includes.

7 years agopw(8): r326738 broke expiration arithmetic in case of `-D' flag not supplied.
Eugene Grosbein [Fri, 15 Dec 2017 06:05:16 +0000 (06:05 +0000)]
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

7 years agopw(8): correct expiration period handling and command line overrides
Eugene Grosbein [Sat, 9 Dec 2017 23:34:00 +0000 (23:34 +0000)]
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

7 years agovarious: general adoption of SPDX licensing ID tags.
Pedro F. Giffuni [Mon, 27 Nov 2017 15:37:16 +0000 (15:37 +0000)]
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.

7 years agolib: further adoption of SPDX licensing ID tags.
Pedro F. Giffuni [Sun, 26 Nov 2017 02:00:33 +0000 (02:00 +0000)]
lib: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using mis-identified 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.

7 years agoGeneral further adoption of SPDX licensing ID tags.
Pedro F. Giffuni [Mon, 20 Nov 2017 19:49:47 +0000 (19:49 +0000)]
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.

7 years agospdx: initial adoption of licensing ID tags.
Pedro F. Giffuni [Sat, 18 Nov 2017 14:26:50 +0000 (14:26 +0000)]
spdx: initial adoption of licensing ID tags.

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.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes: yes
Differential Revision: https://reviews.freebsd.org/D13133

7 years agoRemove 'adding_user.7'
Eitan Adler [Wed, 1 Nov 2017 01:22:33 +0000 (01:22 +0000)]
Remove 'adding_user.7'

Not to be confused with adduser.
Not to be confused with useful information.

Differential Revision: https://reviews.freebsd.org/D12848

7 years agochpass(1): Check crypt(3) return and handle error appropriately
Conrad Meyer [Wed, 4 Oct 2017 01:12:26 +0000 (01:12 +0000)]
chpass(1): Check crypt(3) return and handle error appropriately

This change is spiritually similar to the earlier r231994.

PR: 222756
Submitted by: Lubos Boucek <bouceklubos AT gmail.com>
Obtained from: DragonflyBSD 2020c8fec4168a5020f984a093224fade3074b25

7 years agopw useradd: Validate the user name before creating the entry
Ed Maste [Sat, 19 Aug 2017 00:32:26 +0000 (00:32 +0000)]
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

7 years agopw usermod: Properly deal with empty secondary group lists (-G '')
Ed Maste [Sat, 19 Aug 2017 00:19:23 +0000 (00:19 +0000)]
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

7 years agoMFhead@r322057
Enji Cooper [Fri, 4 Aug 2017 17:41:49 +0000 (17:41 +0000)]
MFhead@r322057

7 years agoIntroduce the flopenat(3) function.
Mariusz Zaborski [Fri, 4 Aug 2017 14:24:24 +0000 (14:24 +0000)]
Introduce the flopenat(3) function.

Reviewed by: des, emaste
Differential Revision: https://reviews.freebsd.org/D11690

7 years agoAdd HAS_TESTS to all Makefiles that are currently using the
Enji Cooper [Wed, 2 Aug 2017 08:50:42 +0000 (08:50 +0000)]
Add HAS_TESTS to all Makefiles that are currently using the
`SUBDIR.${MK_TESTS}+= tests` idiom.

This is a follow up to r321912.

7 years agoConvert traditional ${MK_TESTS} conditional idiom for including test
Enji Cooper [Wed, 2 Aug 2017 08:35:51 +0000 (08:35 +0000)]
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

7 years agoDon't depend on assert(3) getting evaluated
Alan Somers [Wed, 10 May 2017 16:06:22 +0000 (16:06 +0000)]
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

7 years agostrcpy => strlcpy
Alan Somers [Wed, 10 May 2017 15:38:06 +0000 (15:38 +0000)]
strcpy => strlcpy

Reported by: Coverity
CID: 1006715
MFC after: 3 weeks
Sponsored by: Spectra Logic Corp

7 years agolib: initial use of reallocarray(3).
Pedro F. Giffuni [Fri, 21 Apr 2017 19:27:33 +0000 (19:27 +0000)]
lib: initial use of reallocarray(3).

Make some use of reallocarray, attempting to limit it to cases where the
parameters are unsigned and there is some theoretical chance of overflow.

MFC afer: 2 weeks
Differential Revision: https://reviews.freebsd.org/D9980

7 years agoProperly initialise with content of pw.conf(5) that was mistakenly ignored.
Eugene Grosbein [Fri, 24 Mar 2017 16:18:57 +0000 (16:18 +0000)]
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

7 years agoAdopt SRCTOP in usr.bin
Warner Losh [Sun, 12 Mar 2017 18:58:44 +0000 (18:58 +0000)]
Adopt SRCTOP in usr.bin

Prefer ${SRCTOP}/foo over ${.CURDIR}/../../foo and ${SRCTOP}/usr.bin/foo
over ${.CURDIR}/../foo for paths in Makefiles.

Differential Revision: https://reviews.freebsd.org/D9932
Sponsored by: Netflix
Silence on: arch@ (twice)

7 years agoConvert absolute links to relative links.
Rodney W. Grimes [Tue, 7 Mar 2017 05:10:38 +0000 (05:10 +0000)]
Convert absolute links to relative links.
Style.Makefile(9) has been ignored to produce minimal diffs.

Approved by: grehan (mentor)
MFC after: 1 week

7 years agoRenumber copyright clause 4
Warner Losh [Tue, 28 Feb 2017 23:42:47 +0000 (23:42 +0000)]
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

7 years agoReally restore the old behaviour for pw usermod -m
Baptiste Daroussin [Sun, 22 Jan 2017 20:03:18 +0000 (20:03 +0000)]
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

7 years agoReadd a feature lost in pw(8) refactoring
Baptiste Daroussin [Sun, 22 Jan 2017 18:55:01 +0000 (18:55 +0000)]
Readd a feature lost in pw(8) refactoring

pw usermod foo -m

It used to be able to (re)create the home directory if it didn't exists

PR: 216224
Reported by: ae
MFC after: 3 days

8 years agoFix pkg groupshow <gid>
Baptiste Daroussin [Sat, 10 Dec 2016 12:48:48 +0000 (12:48 +0000)]
Fix pkg groupshow <gid>

PR: 204676
Submitted by: longwitz@incore.de
MFC after: 2 days

8 years agoRemove a death threat from the FreeBSD sources
Conrad Meyer [Thu, 1 Dec 2016 02:21:36 +0000 (02:21 +0000)]
Remove a death threat from the FreeBSD sources

Reported by: koobs@, araujo@, linimon@, bjk@, emaste@, jhb@, ngie@, cem@
Maintainer timeout: des@

8 years agoUse malloc()ed buffers instead of stack buffers in gr_copy() and pw_copy().
Dag-Erling Smørgrav [Mon, 28 Nov 2016 21:00:19 +0000 (21:00 +0000)]
Use malloc()ed buffers instead of stack buffers in gr_copy() and pw_copy().
This allows pw(8) to operate on passwd and group files with longer lines
than could be accomodated by a stack buffer.  It doesn't take more than a
few hundred users to exceed 8192 bytes in /etc/group.

MFC after: 3 weeks
Sponsored by: The University of Oslo

8 years agoUpgrade our copies of clang, llvm, lldb, compiler-rt and libc++ to 3.9.0
Dimitry Andric [Thu, 24 Nov 2016 22:54:55 +0000 (22:54 +0000)]
Upgrade our copies of clang, llvm, lldb, compiler-rt and libc++ to 3.9.0
release, and add lld 3.9.0.  Also completely revamp the build system for
clang, llvm, lldb and their related tools.

Please note that from 3.5.0 onwards, clang, llvm and lldb require C++11
support to build; see UPDATING for more information.

Release notes for llvm, clang and lld are available here:
<http://llvm.org/releases/3.9.0/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/clang/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.9.0/tools/lld/docs/ReleaseNotes.html>

Thanks to Ed Maste, Bryan Drewery, Andrew Turner, Antoine Brodin and Jan
Beich for their help.

Relnotes: yes
MFC after: 1 month

8 years agoMerge ^/head r309106 through r309117.
Dimitry Andric [Thu, 24 Nov 2016 21:14:22 +0000 (21:14 +0000)]
Merge ^/head r309106 through r309117.

8 years agoAdd a warning against modifying this code without understanding it, and
Dag-Erling Smørgrav [Thu, 24 Nov 2016 14:50:21 +0000 (14:50 +0000)]
Add a warning against modifying this code without understanding it, and
an example of how not to make it more portable.  I've had this lying
around uncommitted since 2009...

8 years agoMerge ^/head r308491 through r308841.
Dimitry Andric [Sat, 19 Nov 2016 16:05:55 +0000 (16:05 +0000)]
Merge ^/head r308491 through r308841.

8 years agoSpeed up pw operations that edit /etc/group or /etc/passwd
Alan Somers [Fri, 18 Nov 2016 16:07:08 +0000 (16:07 +0000)]
Speed up pw operations that edit /etc/group or /etc/passwd

r285050 fixed a bug in pw that could lead to /etc/passwd or /etc/group
corruption on power loss. However, it fixed it by opening those files with
O_SYNC, which is very slow, especially on ZFS. This change replaces O_SYNC
with appropriately placed fsync()s instead, which is much faster. Using a
ZFS tmpdir, the time to run pw's kyua tests drops from 245s to 35s.

Reviewed by: allanjude, bapt, vangyzen, garga
Tested on pfSense by: garga
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D8319

8 years agoMerge ^/head r307736 through r308146.
Dimitry Andric [Mon, 31 Oct 2016 19:02:42 +0000 (19:02 +0000)]
Merge ^/head r307736 through r308146.

8 years agoClose some file descriptor leaks in pw
Alan Somers [Fri, 21 Oct 2016 20:17:19 +0000 (20:17 +0000)]
Close some file descriptor leaks in pw

MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D8245

8 years agoMerge ^/head r305687 through r305890.
Dimitry Andric [Fri, 16 Sep 2016 20:49:12 +0000 (20:49 +0000)]
Merge ^/head r305687 through r305890.

8 years agoAdd another badly-needed simple example to the pw(8) man page.
Warren Block [Tue, 13 Sep 2016 02:18:29 +0000 (02:18 +0000)]
Add another badly-needed simple example to the pw(8) man page.

8 years agoMerge ^/head r303250 through r304235.
Dimitry Andric [Tue, 16 Aug 2016 20:19:05 +0000 (20:19 +0000)]
Merge ^/head r303250 through r304235.

8 years agoFix up setgrent(3) to have a POSIX-compliant prototype.
Ed Schouten [Sun, 31 Jul 2016 08:05:15 +0000 (08:05 +0000)]
Fix up setgrent(3) to have a POSIX-compliant prototype.

Just like with freelocale(3), I haven't been able to find any piece of
code that actually makes use of this function's return value, both in
base and in ports. The reason for this is that FreeBSD seems to be the
only operating system to have such a prototype. This is why I'm deciding
to not use symbol versioning for this.

It does seem that the pw(8) utility depends on the function's typing and
already had a switch in place to toggle between the FreeBSD and POSIX
variant of this function. Clean this up by always expecting the POSIX
variant.

There is also a single port that has a couple of local declarations of
setgrent(3) that need to be patched up. This is in the process of being
fixed.

PR: 211394 (exp-run)

8 years agoRemove usage of _WITH_GETLINE from usr.sbin
Baptiste Daroussin [Sat, 30 Jul 2016 01:10:05 +0000 (01:10 +0000)]
Remove usage of _WITH_GETLINE from usr.sbin

8 years agoDo not try to delete the home of the user if is is not a directory for example
Baptiste Daroussin [Sat, 23 Jul 2016 10:19:10 +0000 (10:19 +0000)]
Do not try to delete the home of the user if is is not a directory for example
"/dev/null"

PR: 211195
Submitted by: rday <ryan@ryanday.net>
Reported by: eniorm <eniorm@gmail.com>
MFC after: 1 day

8 years agopw should sanitize the argument of -w.
Alan Somers [Wed, 13 Jul 2016 17:09:20 +0000 (17:09 +0000)]
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

8 years agoFix typo preventing pw {user,group}next -C from working as expected
Baptiste Daroussin [Sat, 4 Jun 2016 16:31:33 +0000 (16:31 +0000)]
Fix typo preventing pw {user,group}next -C from working as expected

Reported by: Mike Selnet via forums.freebsd.org
MFC after: 3 days

8 years agoFix CID 1006692 in /usr/sbin/pw pw_log() function and other fixes
Don Lewis [Tue, 24 May 2016 05:02:24 +0000 (05:02 +0000)]
Fix CID 1006692 in /usr/sbin/pw pw_log() function and other fixes

The length of the name returned from the $LOGNAME and $USER can be
very long and it was being concatenated to a fixed length buffer
with no bounds checking.  Fix this problem by limiting the length
of the name copied.

Additionally, this name is actually used to create a format string
to be used in adding log file entries so embedded % characters in
the name could confuse *printf(), and embedded whitespace could
confuse a log file parser.  Handle the former by escaping each %
with an additional %, and handle the latter by simply stripping it
out.

Clean up the code by moving the variable declarations to the top
of the function, formatting them to conform with style, and moving
intialization elsewhere.

Reduce code indentation by returning early in a couple of places.

Reported by: Coverity
CID: 1006692
Reviewed by: markj (previous version)
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D6490

8 years agolibutil: minor spelling fixes.
Pedro F. Giffuni [Wed, 18 May 2016 15:25:45 +0000 (15:25 +0000)]
libutil: minor spelling fixes.

8 years agoRemove useless calls to basename().
Ed Schouten [Sun, 1 May 2016 08:22:11 +0000 (08:22 +0000)]
Remove useless calls to basename().

There are a couple of places in the source three where we call
basename() on constant strings. This is bad, because the prototype
standardized by POSIX allows the implementation to use its argument as a
storage buffer.

This change eliminates some of these unportable calls to basename() in
cases where it was only added for cosmetical reasons, namely to trim
argv[0]. There's nothing wrong with setting argv[0] to the full path.

Reviewed by: jilles
Differential Revision: https://reviews.freebsd.org/D6093

8 years agoAdd a single example of adding a user that roughly corresponds with the
Warren Block [Sat, 23 Apr 2016 22:57:54 +0000 (22:57 +0000)]
Add a single example of adding a user that roughly corresponds with the
adduser example in the Handbook.

MFC after: 1 week

8 years agoMFH
Glen Barber [Mon, 4 Apr 2016 23:55:32 +0000 (23:55 +0000)]
MFH

Sponsored by: The FreeBSD Foundation

8 years agoAdjust misleading wording of the -G option and simplify a few
Warren Block [Mon, 28 Mar 2016 02:05:35 +0000 (02:05 +0000)]
Adjust misleading wording of the -G option and simplify a few
surrounding sentences.  From a discussion on -ports.

Reviewed by: David Wolfskill <david@catwhisker.org>

8 years agoRemove some unneeded headers
Baptiste Daroussin [Sat, 26 Mar 2016 11:41:35 +0000 (11:41 +0000)]
Remove some unneeded headers

Found by 'include-what-you-use'

8 years agoMFH
Glen Barber [Wed, 2 Mar 2016 16:14:46 +0000 (16:14 +0000)]
MFH

Sponsored by: The FreeBSD Foundation

8 years agoFix a typo that prevented pw(8) from setting a user's UID to 0.
Mark Johnston [Wed, 2 Mar 2016 04:56:36 +0000 (04:56 +0000)]
Fix a typo that prevented pw(8) from setting a user's UID to 0.

MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division

8 years agoRestore the 'beforeinstall' for chpass(1), so files with the
Glen Barber [Thu, 28 Jan 2016 02:56:30 +0000 (02:56 +0000)]
Restore the 'beforeinstall' for chpass(1), so files with the
schg flag are handled before being replaced by a symbolic link.

Fix passwd(1)/yppasswd(1) schg issue similarly to chpass(1).

Note:  These are likely temporary fixes while identifying any
remaining files that are not marked as 'flags=schg' via mtree(8).

Sponsored by: The FreeBSD Foundation

8 years agoEnsure mtree(8) recognizes chpass(1) is schg.
Glen Barber [Thu, 28 Jan 2016 01:15:57 +0000 (01:15 +0000)]
Ensure mtree(8) recognizes chpass(1) is schg.

Convert hard links to symbolic links, and remove the
'beforeinstall' and 'afterinstall' chflags(8) execution.

Sponsored by: The FreeBSD Foundation

9 years agoFix svn:mergeinfo, and MFH a commit that was previously missed.
Glen Barber [Mon, 4 Jan 2016 22:32:37 +0000 (22:32 +0000)]
Fix svn:mergeinfo, and MFH a commit that was previously missed.

Sponsored by: The FreeBSD Foundation

9 years agoMFH r289384-r293170
Glen Barber [Mon, 4 Jan 2016 19:19:48 +0000 (19:19 +0000)]
MFH r289384-r293170

Sponsored by: The FreeBSD Foundation

9 years agoSimplify code for parsing extra groups
Baptiste Daroussin [Tue, 29 Dec 2015 00:08:32 +0000 (00:08 +0000)]
Simplify code for parsing extra groups

9 years agoRemove useless assignement of linelen
Baptiste Daroussin [Tue, 29 Dec 2015 00:02:08 +0000 (00:02 +0000)]
Remove useless assignement of linelen

9 years agoRestore dryrun support for pw groupmod
Baptiste Daroussin [Mon, 28 Dec 2015 23:57:22 +0000 (23:57 +0000)]
Restore dryrun support for pw groupmod

9 years agopw_checkname since the beginning if too strict on GECOS field,
Baptiste Daroussin [Wed, 2 Dec 2015 22:35:25 +0000 (22:35 +0000)]
pw_checkname since the beginning if too strict on GECOS field,
relax it a bit so gecos can be used to store multibytes data.

This was unseen before FreeBSD 10.2 as this validation function was motly unused
since FreeBSD 10.2 the usage of this function has been generalized to improve
validation.

Reported by: des
MFC after: 1 week

9 years agoFix handling of numeric-only names with pw lock
Baptiste Daroussin [Wed, 2 Dec 2015 22:01:37 +0000 (22:01 +0000)]
Fix handling of numeric-only names with pw lock
Add a regression test about it

PR: 204968
MFC after: 1 week