From 50dfaf6e1e98caa0c39570f83b2eeaff53bf52ab Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 18 Jul 2022 11:58:39 +0200 Subject: [pam-bwidm] Try UID gen 10 times, invert counting to simplify check --- core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'core/modules/pam-bwidm') diff --git a/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm b/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm index 5215eccc..41ac2636 100755 --- a/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm +++ b/core/modules/pam-bwidm/data/opt/openslx/scripts/pam_bwidm @@ -243,14 +243,14 @@ write_user_data() { gexp="$( printf "%s" "${PAM_USER}" | sed 's/[][$^\.*]/\\&/g' )" # Basic regexp if ! grep -q "^${gexp}:" /etc/passwd; then # create a random 6digit UID - LOOPS=0 - while [ "$LOOPS" -lt 5 ]; do + LOOPS=10 + while [ "$LOOPS" -gt 0 ]; do USER_UID="$(( 100000 + RANDOM % 100000 ))" - # check existence of this UID, if its free, use it + # check existence of this UID, if it's free, use it getent passwd "$USER_UID" || break - let LOOPS++ + let LOOPS-- done - if [ "$LOOPS" -eq 5 ]; then + if [ "$LOOPS" -eq 0 ]; then # could not find an empty random 6-digit UID, so we will use demo's UID... USER_UID="$(id -u demo)" [ -z "$USER_UID" ] && echo "Could not use UID of 'demo' as a fallback, aborting..." && exit 1 -- cgit v1.2.3-55-g7522