Add stdout support for passwd sub-command based on system hash type

This commit is contained in:
Ilia
2022-06-15 19:57:54 +03:00
parent f8758d663d
commit 6402eb9e9b

View File

@@ -18,7 +18,8 @@ sub main
GetOptions('help|h' => \$opt{'help'},
'config|c=s' => \$opt{'config'},
'user|u=s' => \$opt{'user'},
'password|p=s' => \$opt{'password'});
'password|p=s' => \$opt{'password'},
'stdout|o!' => \$opt{'stdout'});
# If username passed as regular param
my $user = scalar(@ARGV) == 1 && $ARGV[0];
@@ -71,8 +72,9 @@ sub change_password
my $root = root($confdif, \&$conf_check);
# Use pre-defined encryption (forced by Webmin config)
if ($gconfig->{'md5pass'} == 1 ||
$gconfig->{'md5pass'} == 2)
if (!$optref->{'stdout'} &&
($gconfig->{'md5pass'} == 1 ||
$gconfig->{'md5pass'} == 2))
{
do "$root/acl/md5-lib.pl";
@@ -160,6 +162,12 @@ sub change_password
# Update with new password and store timestamp
$uinfos{$user}->[0] = &$encrypt_password($pass, \%gconfig, \%config);
# Print the hash and exit
if ($optref->{'stdout'}) {
say $uinfos{$user}->[0];
exit 0;
}
$uinfos{$user}->[5] = time() if ($uinfos{$user}->[5]);
map {$ulines{$_} = join(":", @{ $uinfos{$_} })} keys %uinfos;
@@ -232,6 +240,7 @@ sub root
- webmin passwd --user root
- webmin passwd --user root --password ycwyMQRVAZY
- webmin passwd --config /usr/local/etc/webmin --user root --password ycwyMQRVAZY
- webmin passwd --config /usr/local/etc/webmin --user root --password ycwyMQRVAZY --stdout
=item --config, -c