Bug 263188 - pw accepts an "illegal option" but completes the command without error
Summary: pw accepts an "illegal option" but completes the command without error
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 13.1-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Baptiste Daroussin
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-09 22:19 UTC by Dennis Clarke
Modified: 2023-08-30 06:23 UTC (History)
2 users (show)

See Also:
bapt: mfc-stable13+
bapt: mfc-stable12+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dennis Clarke 2022-04-09 22:19:27 UTC
This may seem trivial but goes against basic UNIX concepts. I have a
list of users on a system and they all have home directories : 

blastwave# ls -lap /home
total 212
drwxr-xr-x   7 root     devl     7 Apr  9 22:08 ./
drwxr-xr-x  23 root     wheel   32 Apr  1 15:00 ../
drwxrwx---   6 dasbot   dasbot  20 Mar 28 10:03 dasbot/
drwx------   7 dclarke  devl    32 Apr  9 05:16 dclarke/
drwx------   5 debug    devl    15 Mar  8 16:43 debug/
drwxr-xr-x   6 nsonack  devl    20 Mar 28 20:56 nsonack/
blastwave# 

I choose to remove the user "debug" as well as the home directory :

blastwave# pw userdel -n debug -t
pw: illegal option -- t
blastwave# echo $?
0
blastwave# 

Above we see that there is an error message? Is that an error? The pw
command seems to issue no error status and simply ignores the faulty
option "-t" with the result being that indeed the user "debug" is gone
but the home directory remains : 

blastwave# ls -lap /home
total 178
drwxr-xr-x   6 root     devl     6 Apr  9 22:08 ./
drwxr-xr-x  23 root     wheel   32 Apr  1 15:00 ../
drwxrwx---   6 dasbot   dasbot  20 Mar 28 10:03 dasbot/
drwx------   7 dclarke  devl    32 Apr  9 05:16 dclarke/
drwx------   5 10001    devl    15 Mar  8 16:43 debug/
drwxr-xr-x   6 nsonack  devl    20 Mar 28 20:56 nsonack/
blastwave# 

This is bad voodoo. If there is an error message then indicate that it
is an "error" or a "warning". Regardless one should not be astonished by
the results. I disagree with a baseline UNIX command that surprises the
user with strange results and strange output.


-- 
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
GreyBeard and suspenders optional
Comment 1 Dennis Clarke 2022-04-09 22:21:02 UTC
This was seen on : 

# uname -apKU 
FreeBSD blastwave 13.0-RELEASE-p11 FreeBSD 13.0-RELEASE-p11 #0: Tue Apr  5 18:54:35 UTC 2022     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64 amd64 1300139 1300139
Comment 2 Dennis Clarke 2022-04-09 22:31:31 UTC
Testing the exit status and error message on another system where
I see that I may add a user reasonably : 
 
# uname -apKU 
FreeBSD callisto 13.0-RELEASE-p11 FreeBSD 13.0-RELEASE-p11 #0: Tue Apr  5 18:54:35 UTC 2022     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64 amd64 1300139 1300139
# 
# adduser
Username: testdude 
Full name: The Test Dude
Uid (Leave empty for default): 54321
Login group [testdude]: devl
Login group is devl. Invite testdude into other groups? []: 
Login class [default]: 
Shell (sh csh tcsh git-shell bash rbash nologin) [sh]: 
Home directory [/home/testdude]: 
Home directory permissions (Leave empty for default): 
Use password-based authentication? [yes]: 
Use an empty password? (yes/no) [no]: 
Use a random password? (yes/no) [no]: 
Enter password: 
Enter password again: 
Lock out the account after creation? [no]: 
Username   : testdude
Password   : *****
Full Name  : The Test Dude
Uid        : 54321
Class      : 
Groups     : devl 
Home       : /home/testdude
Home Mode  : 
Shell      : /bin/sh
Locked     : no
OK? (yes/no): yes
adduser: INFO: Successfully added (testdude) to the user database.
Add another user? (yes/no): no
Goodbye!
# 
#

There we see a valid adduser and a home directory :
 
# ls -lap /usr/home 
total 35
drwxr-xr-x   5 root      wheel    5 Apr  9 22:26 ./
drwxr-xr-x  16 root      wheel   16 Feb 20 02:04 ../
drwxr-xr-x   4 admsys    admsys  12 Mar 23 22:09 admsys/
drwxr-xr-x   8 dclarke   devl    21 Apr  8 05:16 dclarke/
drwxr-xr-x   2 testdude  devl     9 Apr  9 22:26 testdude/
# 

Now delete the user and the home directory but with a wrong option :
 
# pw userdel -n testdude -t
pw: illegal option -- t
# echo $?
0
#

Above we clearly see a clean zero value exist status.
 
# ls -lapb /usr/home
total 35
drwxr-xr-x   5 root     wheel    5 Apr  9 22:26 ./
drwxr-xr-x  16 root     wheel   16 Feb 20 02:04 ../
drwxr-xr-x   4 admsys   admsys  12 Mar 23 22:09 admsys/
drwxr-xr-x   8 dclarke  devl    21 Apr  8 05:16 dclarke/
drwxr-xr-x   2 54321    devl     9 Apr  9 22:26 testdude/
# 
# pw userdel -n testdude -r
pw: no such user `testdude'
# echo $?
67
# 
# rm -rf /usr/home/testdude
# 

So yes the user was in fact deleted from the system but the command
issues a strange message and a zero exit status whereas a more
reasonable behavior would be to issue a non-zero exit status and do no
change to the system. 


-- 
Dennis Clarke
RISC-V/SPARC/PPC/ARM/CISC
UNIX and Linux spoken
GreyBeard and suspenders optional














I see different behavior on another system where the exit status is
set to 67 but again the user is removed from the machine and the
home directory remains : 

# uname -apKU 
FreeBSD callisto 13.0-RELEASE-p11 FreeBSD 13.0-RELEASE-p11 #0: Tue Apr  5 18:54:35 UTC 2022     root@amd64-builder.daemonology.net:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64 amd64 1300139 1300139
# 
# ls -lap /usr/home 
total 27
drwxr-xr-x   5 root     wheel     5 Apr  4 14:30 ./
drwxr-xr-x  16 root     wheel    16 Feb 20 02:04 ../
drwxr-xr-x   4 admsys   admsys   12 Mar 23 22:09 admsys/
drwxr-xr-x   8 dclarke  devl     21 Apr  8 05:16 dclarke/
drwx------   2 54321    testnfs   2 Apr  4 14:30 testdude/
# 
# pw userdel -n testdude -t
pw: illegal option -- t
pw: no such user `testdude'
# echo $?
67
# 
# ls -lapb /usr/home 
total 27
drwxr-xr-x   5 root     wheel     5 Apr  4 14:30 ./
drwxr-xr-x  16 root     wheel    16 Feb 20 02:04 ../
drwxr-xr-x   4 admsys   admsys   12 Mar 23 22:09 admsys/
drwxr-xr-x   8 dclarke  devl     21 Apr  8 05:16 dclarke/
drwx------   2 54321    testnfs   2 Apr  4 14:30 testdude/
# 
# pw userdel -n testdude -r
pw: no such user `testdude'
# 
# ls -lapb /usr/home
total 27
drwxr-xr-x   5 root     wheel     5 Apr  4 14:30 ./
drwxr-xr-x  16 root     wheel    16 Feb 20 02:04 ../
drwxr-xr-x   4 admsys   admsys   12 Mar 23 22:09 admsys/
drwxr-xr-x   8 dclarke  devl     21 Apr  8 05:16 dclarke/
drwx------   2 54321    testnfs   2 Apr  4 14:30 testdude/
# 
# rm -rf /usr/home/testdude/
#
Comment 3 Dennis Clarke 2022-04-10 22:07:52 UTC
The README claims there is a maintainer.
Comment 4 Dennis Clarke 2022-04-10 22:08:36 UTC
https://cgit.freebsd.org/src/tree/usr.sbin/pw/README


pw is a command-line driven passwd/group editor utility that provides
an easy and safe means of modifying of any/all fields in the system
password files, and has an add, modify and delete mode for user and
group records. Command line options have been fashioned to be similar
to those used by the Sun/shadow commands: useradd, usermod, userdel,
groupadd, groupmod, groupdel, but combines all operations within the
single command `pw'.

User add mode also provides a means of easily setting system useradd
defaults (see pw.conf.5), so that adding a user is as easy as issuing
the command "pw useradd <loginid>". Creation of a unique primary
group for each user and automatic membership in secondary groups
is fully supported.

This program may be FreeBSD specific, but should be trivial to port to
other bsd4.4 variants.

Author and maintainer: David L. Nugent, <davidn@blaze.net.au>

$FreeBSD$
Comment 5 commit-hook freebsd_committer freebsd_triage 2022-10-12 10:08:27 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=c0358afd5bbc2c675941fed2905479ad109770bb

commit c0358afd5bbc2c675941fed2905479ad109770bb
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2022-10-12 10:06:32 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-10-12 10:06:32 +0000

    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

 usr.sbin/pw/pw_group.c | 10 ++++++++++
 usr.sbin/pw/pw_user.c  | 14 ++++++++++++++
 2 files changed, 24 insertions(+)
Comment 6 Baptiste Daroussin freebsd_committer freebsd_triage 2022-10-12 10:12:31 UTC
fixed, sorry it took that long
Comment 7 commit-hook freebsd_committer freebsd_triage 2022-10-19 08:01:55 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=06a079c69e843a796c5956b8e9a79a35d3401f38

commit 06a079c69e843a796c5956b8e9a79a35d3401f38
Author:     Baptiste Daroussin <bapt@FreeBSD.org>
AuthorDate: 2022-10-12 10:06:32 +0000
Commit:     Baptiste Daroussin <bapt@FreeBSD.org>
CommitDate: 2022-10-19 07:55:48 +0000

    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

    (cherry picked from commit c0358afd5bbc2c675941fed2905479ad109770bb)

 usr.sbin/pw/pw_group.c | 10 ++++++++++
 usr.sbin/pw/pw_user.c  | 14 ++++++++++++++
 2 files changed, 24 insertions(+)
Comment 8 Graham Perrin freebsd_committer freebsd_triage 2022-10-21 00:59:34 UTC
Thanks for resolution. 


> Flags: mfc-stable12+

I guess, not merging during the code slush for 12.4 … true?

<https://www.freebsd.org/releases/12.4R/>