From b7be313cb8f0aa60f828f0d6386d08d6332d081a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 28 Oct 2021 01:22:58 +0200 Subject: [PATCH] Squashed 'cgilite/' changes from f477dc5..dba2d39 dba2d39 idmap functions git-subtree-dir: cgilite git-subtree-split: dba2d399378581f5129a4b600bef81dcb815be8e --- users.sh | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/users.sh b/users.sh index a389f15..873edf0 100755 --- a/users.sh +++ b/users.sh @@ -27,9 +27,10 @@ LOCAL_USER='local \ USER_EXPIRE USER_DEVICES USER_FUTUREUSE ' +unset USER_IDMAP eval "$UNSET_USER" -user_db="${_DATA}/users.db" +user_db="${user_db:-${_DATA}/users.db}" read_user() { local user="$1" @@ -127,6 +128,40 @@ new_user(){ fi } +user_idmap(){ + local uid="$1" ret + eval "$LOCAL_USER" + + if [ ! "$USER_IDMAP" ]; then + while read_user; do + USER_IDMAP="${USER_IDMAP}${USER_ID} ${USER_NAME}${BR}" + done <"$user_db" + fi + if [ "$uid" -a "$USER_IDMAP" != "${USER_IDMAP##*${uid} }" ]; then + ret="${USER_IDMAP##*${uid} }"; ret="${ret%%${BR}*}"; + printf '%s\n' "$ret" + return 0 + elif [ "$uid" ]; then + return 1 + else + printf '%s' "$USER_IDMAP" + return 0 + fi +} + +user_idof(){ + local name="$(STRING "$1")" ret + [ "$USER_IDMAP" ] || user_idmap >/dev/null + + if [ "${name%\\}" -a "$USER_IDMAP" != "${USER_IDMAP% ${name}${BR}*}" ]; then + ret="${USER_IDMAP% ${name}${BR}*}"; ret="${ret##*${BR}}" + printf '%s\n' "$ret" + return 0 + else + return 1 + fi +} + user_checkname(){ { [ $# -gt 0 ] && printf %s "$*" || cat; } \ | sed -nE ' -- 2.39.2