bandaids for sanitize_username
authorChris Koeritz <fred@gruntose.com>
Fri, 7 Mar 2025 20:50:08 +0000 (20:50 +0000)
committerChris Koeritz <fred@gruntose.com>
Fri, 7 Mar 2025 20:50:08 +0000 (20:50 +0000)
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.

scripts/core/variables.sh

index 8a7a5fae3d56172723ac7b20d2c3ebafc21f90f5..a586eebe63b2d165aa2622903214208c861ccd5b 100644 (file)
@@ -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"