info-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help: passwd file


From: Lan Barnes
Subject: Re: help: passwd file
Date: Fri, 18 May 2001 11:40:23 -0700

Andy Nuss wrote:
> 
> Hi,
> 
> I'm trying to figure out how to create entries
> in the passwd file.  Somewhere a few days
> ago I saw the hash-algorithm posted on the net,
> but can't find it now.
> 
> Does anyone know this doc?  Or is there a script
> that has been written?
> 
> Note: I can't seem to find the answer on my Linux 7.2
> system, as I don't know the "salt" used by both
> Linux and by CVS.
> 
> Thanks,
> Andy

Try this:

#!/usr/bin/perl
# from Fogel p 114

$arg1 = shift;

if($arg1 eq "-f")
{
        $outfile = shift;
        $plaintxt = shift;
        $salt = shift;
}
else
{
        $plaintxt = $arg1;
        $salt = shift;
}

if ($plaintxt eq "")
{
print "Usage: cvspasswd [-f <filename>] <plaintext> [seed]\n";
exit;
}

if($salt eq "")
        {
        srand (time());
        my $randltr = "(int(rand(26)) + (int(rand(1) + .5) % 2 ? 65 :
97))";
        $salt = sprintf("%c%c", eval $randltr, eval $randltr);
        }

if(length($salt) != 2) {die "Err: Provided seed must be 2 char\n";}

my $crypttxt = crypt ($plaintxt, $salt);

if ($outfile eq "")
{
        print "${crypttxt}\n";
}
else
{
        open (OF,">$outfile") || die "Can't open outfile $outfile\n";
        print OF "${crypttxt}\n";
        close OF;
}

# *** End script ***

This has gotten a little elaborate over time. For example, I have it able
to write to an outfile, useful if I'm automating filling a large passwd
file. But I'm a bit of a perl klutz, and I'm sure there are more elegant
ways to do all this.

-- 
Lan Barnes                 address@hidden
Icon Consulting, Inc       858-273-6677

[It is] the most absurd of all suppositions that every successive 
generation of men have not an equal right to the earth.
                                   - Adam Smith



reply via email to

[Prev in Thread] Current Thread [Next in Thread]