]> git.plutz.net Git - rawnet/commitdiff
Squashed 'cgilite/' changes from f477dc5..dba2d39
authorPaul Hänsch <paul@plutz.net>
Wed, 27 Oct 2021 23:22:58 +0000 (01:22 +0200)
committerPaul Hänsch <paul@plutz.net>
Wed, 27 Oct 2021 23:22:58 +0000 (01:22 +0200)
dba2d39 idmap functions

git-subtree-dir: cgilite
git-subtree-split: dba2d399378581f5129a4b600bef81dcb815be8e

users.sh

index a389f15c6fb81ef361c13c36b3f9a82e6dd22142..873edf05ffbb72fa9729ff1eb7792c39ac2a86c3 100755 (executable)
--- 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 '