From f437eab3c4cb5bdc4b07980e394ba9f012739ffb Mon Sep 17 00:00:00 2001 From: Ilia Rostovtsev Date: Sun, 25 Apr 2021 12:34:40 +0300 Subject: [PATCH] Improve passwd change command https://github.com/webmin/webmin/pull/1477#issuecomment-825446689 1. Allow passing username as regular param 2. Do no print verbose `Success:` on success --- bin/passwd | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/passwd b/bin/passwd index e996d4753..26ffc5605 100755 --- a/bin/passwd +++ b/bin/passwd @@ -16,10 +16,18 @@ sub main 'config|c=s' => \$opt{'config'}, 'user|u=s' => \$opt{'user'}, 'password|p=s' => \$opt{'password'}); - pod2usage(0) if ($opt{'help'} || !$opt{'user'}); - $opt{'config'} ||= "/etc/webmin"; + # If username passed as regular param + my $user = scalar(@ARGV) == 1 && $ARGV[0]; + # Show usage + pod2usage(0) if ($opt{'help'} || (!$opt{'user'} && !$user)); + + # Assign defaults + $opt{'config'} ||= "/etc/webmin"; + $opt{'user'} = $user if ($user && !$opt{'user'}); + + # Catch kill signal my $sigkill = sub { system("stty echo"); print "\n^C"; @@ -28,6 +36,7 @@ sub main }; $SIG{INT} = \&$sigkill; + # Run change password command change_password(\%opt); return 0; @@ -87,7 +96,7 @@ sub change_password # Check for main user file &$conf_check([$minserv_uconf_file]); - + # Read and parse `miniserv.users` config file read_file($minserv_uconf_file, \%lusers, undef, undef, ":"); @users = keys %lusers; @@ -104,7 +113,7 @@ sub change_password } # Ask for password on stdin - my $suc_pre_msg = GREEN . 'Success:' . RESET; + my $suc_pre_msg = ""; my $suc_msg = 'updated successfully'; if (!$pass) { print "Enter password for user ", BRIGHT_YELLOW, $user, RESET, ":"; @@ -123,7 +132,7 @@ sub change_password } chomp $pass; if (!$pass) { - $suc_pre_msg = BOLD BRIGHT_RED ON_WHITE . 'Warning:' . RESET; + $suc_pre_msg = BOLD BRIGHT_RED ON_WHITE . 'Warning:' . RESET . " "; $suc_msg = "has been removed, enabling anyone to login without authentication"; } } @@ -142,7 +151,7 @@ sub change_password system("$confdif/start >/dev/null 2>&1"); # Print user message - say "$suc_pre_msg Password for Webmin user ", BRIGHT_YELLOW, $user, RESET, " $suc_msg"; + say "${suc_pre_msg}Password for Webmin user ", BRIGHT_YELLOW, $user, RESET, " $suc_msg"; exit 0; } @@ -199,6 +208,8 @@ Print this usage summary and exit. Examples of usage: + - passwd root + - passwd --user root - passwd --user root --password ycwyMQRVAZY