From: Chris Koeritz Date: Fri, 7 Mar 2025 20:50:08 +0000 (+0000) Subject: bandaids for sanitize_username X-Git-Tag: 2.140.189^2~14 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=296f70025c5d4c3ccf64a652468b48d13f7ab478;p=feisty_meow.git bandaids for sanitize_username making sure this should never produce an empty string as the sanitized username, something we wanted to be sure about after seeing some really odd log file names for our www-data user. --- diff --git a/scripts/core/variables.sh b/scripts/core/variables.sh index 8a7a5fae..a586eebe 100644 --- a/scripts/core/variables.sh +++ b/scripts/core/variables.sh @@ -42,8 +42,16 @@ return 0 # a nice clean one (by removing email domains). export SANITIZED_USER function sanitized_username() { + if [ -z "$USER" ]; then + # this isn't quite normal, but maybe we have a cron user variable. + USER=$CRONUSER + if [ -z "$USER" ]; then + # well, now we're just baffled at the lack of a user, but don't want + # a blank coming back from this function. + USER="unknown-user" + fi + fi if [ -z "$SANITIZED_USER" ]; then -#old inefficient... export SANITIZED_USER="$(echo "$USER" | sed -e 's/@[a-zA-Z0-9_.]*//')" export SANITIZED_USER="${USER//@*/}" fi echo -n "$SANITIZED_USER"