From: Paul Hänsch Date: Wed, 27 Oct 2021 23:22:35 +0000 (+0200) Subject: idmap functions X-Git-Url: https://git.plutz.net/?a=commitdiff_plain;h=dba2d399378581f5129a4b600bef81dcb815be8e;p=cgilite idmap functions --- 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 '