<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# change-passwd.pl
# Changes a user's password on all cluster servers. Also changes
# the password in other modules.

$no_acl_check++;
$ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin";
$ENV{'WEBMIN_VAR'} ||= "/var/webmin";
if ($0 =~ /^(.*\/)[^\/]+$/) {
	chdir($1);
	}
chop($pwd = `pwd`);
$0 = "$pwd/change-passwd.pl";
do './cluster-passwd-lib.pl';

if ($ARGV[0] eq "--old" || $ARGV[0] eq "-old") {
	$askold = 1;
	shift(@ARGV);
	}
@ARGV == 1 || &amp;errordie("usage: change-passwd.pl [-old] &lt;username&gt;");
if (&amp;foreign_installed("cluster-useradmin") != 1) {
	&amp;errordie("Cluster Users and Groups module is not available");
	}

# Find the user
@hosts = &amp;cluster_useradmin::list_useradmin_hosts();
@ulist = &amp;get_all_users(\@hosts);
($user) = grep { $_-&gt;{'user'} eq $ARGV[0] } @ulist;
$user || &amp;errordie("User $ARGV[0] does not exist");

$| = 1;
if ($askold) {
	# Ask for the old password
	print "(current) UNIX password: ";
	$old = &lt;STDIN&gt;;
	$old =~ s/\r|\n//g;
	&amp;unix_crypt($old, $user-&gt;{'pass'}) eq $user-&gt;{'pass'} ||
		&amp;errordie("Old password is incorrect");
	}

# Ask for password
print "New password: ";
$pass = &lt;STDIN&gt;;
$pass =~ s/\r|\n//g;
print "Retype new password: ";
$again = &lt;STDIN&gt;;
$again =~ s/\r|\n//g;
$pass eq $again || &amp;errordie("Passwords don't match");

# Check password sanity
$err = &amp;useradmin::check_password_restrictions($pass, $ARGV[0], $user);
&amp;errordie($err) if ($err);

# Do it on all servers
&amp;modify_on_hosts(\@hosts, $user-&gt;{'user'}, $pass, 1, \&amp;print_func);

# All done
exit(0);

sub errordie
{
print STDERR @_,"\n";
exit(1);
}

# print_func(mode, message)
sub print_func
{
if ($_[0] == -1) {
	print "$_[1]\n\n";
	$indent = "    ";
	}
elsif ($_[0] == -2) {
	print "$indent$_[1]\n";
	}
elsif ($_[0] == -3) {
	print "$indent$_[1]\n\n";
	}
elsif ($_[0] == -4) {
	$indent = "";
	print "\n";
	}
elsif ($_[0] &gt; 0) {
	print "$indent$_[1]\n\n";
	$indent = "";
	}
}
</pre></body></html>