[Bug 263188] pw accepts an "illegal option" but completes the command without error

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 09 Apr 2022 22:31:31 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=263188

--- Comment #2 from Dennis Clarke <dclarke@blastwave.org> ---

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/
#

-- 
You are receiving this mail because:
You are the assignee for the bug.