Bug 20489

Summary: pw problems: -w random not working correctly for useradd and usermod
Product: Base System Reporter: celeste.copeland <celeste.copeland>
Component: binAssignee: davidn
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description celeste.copeland 2000-08-08 22:00:01 UTC
The section of code dealing with generating random passwords (-w option) appears to be in the wrong place in the code.  The fix for the -w problem (which Jonathan Bresler and myself came up with) is below.  I am working on a fix for the -m issue.  We need pw fixed for a contract which BSDi has with our company.  Jordan Hubbard (jkh@freebsd.org) is the engineer for this project.

Fix: 

# diff pw_user.c.orig pw_user.c
269a270
> /*  CEC/jmb  
272a274
> */
292a295,301
>         /*  CEC/jmb */
>         if ((mode == M_ADD || mode == M_UPDATE) && (arg = getarg(args, 'w')) != NULL) {  
>                 cnf->default_password = boolean_val(arg->val, cnf->default_password);
>         }
> 
> 
> 
583a593,599
> 
>       /* CEC/jmb */
>       if ( mode==M_UPDATE && (arg = getarg(args, 'w')) != NULL && getarg(args, 'h') == NULL) {  
>               pwd->pw_passwd = pw_password(cnf, args, pwd->pw_name);
>               edited = 1;
>       }
How-To-Repeat: /usr/sbin/pw useradd test1 -c "Test User 1" -d /home/test1 -m -s /bin/sh -w random
/usr/sbin/pw usermod test1 -w random
Does not generate a random password.
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 2000-08-10 10:39:32 UTC
Responsible Changed
From-To: freebsd-bugs->davidn

Over to the maintainer.
Comment 2 Jeroen Ruigrok van der Werven freebsd_committer freebsd_triage 2001-11-15 19:53:23 UTC
State Changed
From-To: open->closed

My 4.4-STABLE box disagrees happily: 

[20:54] [root@purgatory] (3) {0} # /usr/sbin/pw usermod posix -w random      
Password for 'posix' is: LdmRa3fcUzw3lap 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (4) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: 1PBCjiJ6Rld7MF 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (5) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: vi5cLv0zt8 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (6) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: UsL3mXqE4 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (7) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: RDk4f0Y3JRS4fP 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (8) {0} #  
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (8) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: aTss02zxUXzgJ4v 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (9) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: lQokDoJyOq.tB5 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (10) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: Mb7NsUDDPEb 
(/home/asmodai/work/FreeBSD/smpng) 
[20:54] [root@purgatory] (11) {0} # /usr/sbin/pw usermod posix -w random 
Password for 'posix' is: 0jhLwLUTDU9r8 

Seems random enough for me.