Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Dec 2001 12:55:55 +0100
From:      "Roger 'Rocky' Vetterberg" <listsub@rambo.simx.org>
To:        Noah Davidson <Noah@oopz.com>
Cc:        "FreeBSD Security List (E-mail)" <freebsd-security@FreeBSD.ORG>
Subject:   Re: password changes
Message-ID:  <3C1745CB.40305@rambo.simx.org>
References:  <A6A82340FB3DB643A0678E3B10CD5AC1062F55@xela.oopz.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Noah Davidson wrote:

>How can I change the password of a user and not be prompted to verify
>it.  We are changing our mail server to sendmail.  I have all of the
>passwords in plain text.  I want to write a script that changes all 5000
>or so passwords.  How can I do this?  I would like to call passwd or
>some command from a perl script to do this.  Any Ideas would be very
>helpful.
>

I once needed to generate several thousands of users, with passwords 
from a plain text file.
I did this using a perl script to write a new /etc/master.passwd and 
then rebuild using the pwd_mkdb command.
Generating the needed lines and create the needed /home directories was 
easy, and to get the correct passwords I used the following code snippet:

#!/usr/bin/perl
$pass = pop(@ARGV);
$cryptpwd = crypt($pass, &salt);
print "$cryptpwd";

sub salt {
local($salt);
    local($i, $rand);
    local(@itoa64) = ( '0' .. '9', 'a' .. 'z', 'A' .. 'Z' );
    for ($i = 0; $i < 8; $i++) {
        srand(time + $rand + $$);
        $rand = rand(25*29*17 + $rand);
        $salt .=  $itoa64[$rand & $#itoa64];
    }
    return $salt;
}


Just put it in a file and execute it with the plaintext password as 
first argument, and the script will print the encrypted password to use 
in /etc/master.passwd.
I dont remember exactly where I found this perl code, but it was ripped 
from one of the standard utilities in FreeBSD, probably adduser or 
something similar.
Hopes this helps.
--
R



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-security" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C1745CB.40305>