From 6931ddc3e68749304d54ce53901352ad024f2f79 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 7 Mar 2021 19:07:12 -0700 Subject: [PATCH] usertool.pl: allow specifying old email for email change If the old email address does not match the specified value, refuse to make the change. Providing the old email address is optional. Signed-off-by: Kyle J. McKay --- toolbox/usertool.pl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/toolbox/usertool.pl b/toolbox/usertool.pl index 875c777..1352905 100755 --- a/toolbox/usertool.pl +++ b/toolbox/usertool.pl @@ -67,8 +67,9 @@ Usage: %s [...] match against user email instead of name with --email treat as a regex with --regex - [set]email [--force] + [set]email [--force] [] set user email to + if given it must match before changing to without "set" and only 1 arg, just show current user email [set]keys [--force] @@ -482,7 +483,7 @@ sub cmd_getval { sub cmd_setemail { my $force = 0; shift(@ARGV), $force=1 if @ARGV && $ARGV[0] eq '--force'; - @ARGV == 2 || (@ARGV == 1 && !$setopt) or die_usage; + (@ARGV == 2 || @ARGV == 3) || (@ARGV == 1 && !$setopt) or die_usage; my $user = get_user_carefully($ARGV[0], 0, $force && @ARGV==1); if (@ARGV == 2 && !valid_email($ARGV[1])) { die "invalid email/info (use --force to accept): \"$ARGV[1]\"\n" @@ -503,6 +504,9 @@ sub cmd_setemail { warn $user->{name}, ": skipping update of email/info to same value\n" unless $quiet; } else { $user = get_user($ARGV[0]); + $old = $user->{email}; # just in case it got changed + @ARGV == 3 && $old ne $ARGV[2] and + die "old email (\"$old\") does not match value specified: \"$ARGV[2]\"\n"; $user->{email} = $ARGV[1]; $user->_passwd_update; warn $user->{name}, ": email/info updated to \"$ARGV[1]\" (was \"$old\")\n" unless $quiet; -- 2.11.4.GIT