From c9a44e882b368b8a47c564571838787a26b1f74d Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sun, 7 Mar 2021 19:45:05 -0700 Subject: [PATCH] edit-user-email/remove-user: redirect to usertool.pl Changing a user's email address and removing a user can both be performed by usertool.pl. These scripts are quite possibly outdated and may be unsafe. Redirect them to the equivalent usertool.pl command instead. Signed-off-by: Kyle J. McKay --- toolbox/edit-user-email.sh | 47 ++++++++++---------------------------------- toolbox/remove-user.sh | 49 ++++++++++------------------------------------ 2 files changed, 20 insertions(+), 76 deletions(-) rewrite toolbox/edit-user-email.sh (91%) rewrite toolbox/remove-user.sh (95%) diff --git a/toolbox/edit-user-email.sh b/toolbox/edit-user-email.sh dissimilarity index 91% index 00a92f9..d5eee71 100755 --- a/toolbox/edit-user-email.sh +++ b/toolbox/edit-user-email.sh @@ -1,37 +1,10 @@ -#!/bin/sh - -set -e - -. @basedir@/shlib.sh - -if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then - echo "Usage: $0 " - exit 1 -fi -ETC="$cfg_chroot/etc" -COUNT="$(grep -E -c "^$1:" "$ETC/passwd")" -if [ "$COUNT" -ne "1" ]; then - echo "fatal: user '$1' doesn't appear to exist (or exists multiple times, or contains regexpy characters)." - exit 1 -fi -if echo "$2" | grep -q '[,:]'; then - echo "fatal: e-mail '$2' has illegal characters ([,:])." - exit 1 -fi -if ! echo "$3" | grep -E -q '^[a-zA-Z0-9+._-]+@[a-zA-Z0-9.-]+$'; then - echo "fatal: e-mail '$3' is not valid (^[a-zA-Z0-9+._-]+@[a-zA-Z0-9.-]+$)." - exit 1 -fi -sed \ - -e "s/^$1\(:[^:]*:[^:]*:[^:]*:\)$2\([,:]\)/$1\\1$3\\2/" \ - -e "t show" \ - -e "b" \ - -e ": show" \ - -e "w /dev/stderr" \ - "$ETC/passwd" >"$ETC/passwd.$$" -mv -f "$ETC/passwd.$$" "$ETC/passwd" -rm -f "$ETC/passwd.$$" -if [ -n "$cfg_update_pwd_db" ] && [ "$cfg_update_pwd_db" != "0" ]; then - "$cfg_basedir/bin/update-pwd-db" "$ETC/passwd" "$1" -fi -echo "All changed lines listed above." +#!/bin/sh + +set -e + +if [ $# -ne 3 ] || [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then + echo "Usage: $0 " + exit 1 +fi +echo "Redirecting to usertool.pl..." +exec @basedir@/toolbox/usertool.pl setemail "$1" "$3" "$2" diff --git a/toolbox/remove-user.sh b/toolbox/remove-user.sh dissimilarity index 95% index f6b61d0..9834dfb 100755 --- a/toolbox/remove-user.sh +++ b/toolbox/remove-user.sh @@ -1,39 +1,10 @@ -#!/bin/sh - -set -e - -. @basedir@/shlib.sh - -if [ -z "$1" ]; then - echo "Usage: $0 " - exit 1 -fi -u="$1" -qu="$(printf '%s' "$u" | sed -e 's/\./\\./g' -e 's/+/[+]/g')" -ETC="$cfg_chroot/etc" -COUNT="$(grep -E -c "^$qu:" "$ETC/passwd")" || : -if [ "$COUNT" -ne "1" ]; then - echo "fatal: user '$u' doesn't appear to exist (or exists multiple times, or contains regexpy characters)." - exit 1 -fi -ENTRY="$(grep -E "^$qu:" "$ETC/passwd" | cut -d : -f 1-5)" -GRPS="$( (grep -E '^[^:]+:[^:]+:[^:]+.*(:|,)'"$qu"'(,|:|$)' "$ETC/group" || :) | cut -d : -f 1 )" || : -if [ "$GRPS" ]; then - echo "User '$u' is still part of these groups:" $GRPS - echo "fatal: this simplistic script cannot remove users from groups." - exit 1 -fi -sed -e "/^$qu:/ d" "$ETC/passwd" > "$ETC/passwd.$$" -mv -f "$ETC/passwd.$$" "$ETC/passwd" || : -rm -f "$ETC/passwd.$$" || : -rm -f "$ETC/sshkeys/$u" || : -rm -f "$ETC/sshcerts/$cfg_nickname"_"$u"_user_*.pem || : -rm -f "$ETC/sshactive/$u" || : -rm -f "$ETC/sshactive/$u",* || : -! [ -e "$ETC/sshkeys/$u" ] || echo "Warning: unable to remove $ETC/sshkeys/$u" >&2 -[ "$(echo "$ETC/sshcerts/$cfg_nickname"_"$u"_user_*.pem)" = "$ETC/sshcerts/$cfg_nickname"_"$u"_user_"*".pem ] || - echo "Warning: unable to remove $(echo "$ETC/sshcerts/$cfg_nickname"_"$u"_user_*.pem)" >&2 -if [ -n "$cfg_update_pwd_db" ] && [ "$cfg_update_pwd_db" != "0" ]; then - "$cfg_basedir/bin/update-pwd-db" "$ETC/passwd" "$u" -fi -echo "User \"$ENTRY\" (+SSH key/certs) removed." +#!/bin/sh + +set -e + +if [ $# -ne 1 ] || [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi +echo "Redirecting to usertool.pl..." +exec @basedir@/toolbox/usertool.pl remove "$1" -- 2.11.4.GIT