smeserver-sogo/root/etc/e-smith/db/configuration/migrate/SOGoPassword

34 lines
831 B
Plaintext
Raw Permalink Normal View History

{
my $sogodrec = $DB->get('sogod')
|| $DB->new_record('sogod', {type => 'service'});
my $sogod_pw = $sogodrec->prop('DbPassword');
if (not $sogod_pw or length($sogod_pw) < 57)
{
use MIME::Base64 qw(encode_base64);
$sogod_pw = "not set due to error";
if ( open( RANDOM, "/dev/urandom" ) )
{
my $buf;
# 57 bytes is a full line of Base64 coding, and contains
# 456 bits of randomness - given a perfectly random /dev/random
if ( read( RANDOM, $buf, 57 ) != 57 )
{
warn("Short read from /dev/random: $!");
}
else
{
$sogod_pw = encode_base64($buf);
chomp $sogod_pw;
$sogod_pw =~ s/\//\./g; # SOGo hates passwords with slashes
}
close RANDOM;
}
else
{
warn "Could not open /dev/urandom: $!";
}
$sogodrec->set_prop('DbPassword', $sogod_pw);
}
}