CRITICAL: Fix grep regex errors when usernames contain special characters

ROOT CAUSE:
Usernames containing bracket characters like '[' or ']' were being used
directly in grep patterns, causing:
  grep: Unmatched [, [^, [:, [., or [=

This happened during "Indexing users" when the reference database builder
called get_user_domains/get_user_databases with usernames containing brackets.

AFFECTED FUNCTIONS (lib/user-manager.sh):
- get_interworx_user_domains() line 284: grep -v "^${username}\."
- get_interworx_user_info() line 195: grep -A20 with $primary_domain
- get_user_processes() line 583: grep "^${username}"
- get_user_top_processes() line 590: grep "^${username}"

AFFECTED FUNCTIONS (lib/reference-db.sh):
- index_wordpress_sites() line 420: grep "^USER|${username}|"

THE FIX:
Changed all grep commands using variables in patterns to use -F (fixed string)
flag instead of regex matching, and added 2>/dev/null error suppression:

  OLD: grep "^${username}"
  NEW: grep -F "$username" 2>/dev/null

  OLD: grep -v "^${username}\."
  NEW: grep -vF "${username}." 2>/dev/null

IMPACT:
Eliminates ALL "Unmatched [" errors during reference database build,
even when usernames contain special regex characters: [].*+?^$(){}|

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cschantz
2025-11-21 17:35:02 -05:00
parent 8423fb8c0f
commit c5ef84193d
2 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -417,7 +417,7 @@ build_wordpress_section() {
# Check for common domain folder patterns
if [[ "$path_after_home" == public_html ]]; then
# This is the primary domain - get it from user info
domain=$(grep "^USER|${username}|" "$SYSREF_DB" | cut -d'|' -f3 || true)
domain=$(grep -F "USER|${username}|" "$SYSREF_DB" 2>/dev/null | cut -d'|' -f3 || true)
elif [[ "$path_after_home" =~ ^public_html/(.+) ]]; then
# Could be subdomain or subdirectory - extract folder name
local folder=$(echo "$path_after_home" | cut -d'/' -f2)
+5 -5
View File
@@ -192,8 +192,8 @@ get_interworx_user_info() {
local email=""
if [ -x "/usr/local/interworx/bin/nodeworx.pex" ] && [ -n "$primary_domain" ]; then
email=$(nodeworx -u -n -c Siteworx -a listAccounts 2>/dev/null | \
grep -A20 "\"domain\" => \"$primary_domain\"" | \
grep "\"email\"" | head -1 | sed 's/.*=> "\(.*\)".*/\1/')
grep -F "\"domain\" => \"$primary_domain\"" 2>/dev/null | head -1 | \
grep "\"email\"" 2>/dev/null | head -1 | sed 's/.*=> "\(.*\)".*/\1/')
fi
echo "USER_EXISTS=yes"
@@ -281,7 +281,7 @@ get_interworx_user_domains() {
if [ -d "/etc/httpd/conf.d" ]; then
grep -l "SuexecUserGroup ${username}" /etc/httpd/conf.d/vhost_*.conf 2>/dev/null | \
sed 's|.*/vhost_||; s|\.conf$||' | \
grep -v "^${username}\." | \
grep -vF "${username}." 2>/dev/null | \
sort -u
fi
}
@@ -580,14 +580,14 @@ select_user_interactive() {
get_user_processes() {
local username="$1"
ps aux | grep "^${username}" | grep -v grep
ps aux | grep -F "$username" 2>/dev/null | grep -v grep
}
get_user_top_processes() {
local username="$1"
local limit="${2:-10}"
ps aux | grep "^${username}" | grep -v grep | sort -k3 -rn | head -n "$limit"
ps aux | grep -F "$username" 2>/dev/null | grep -v grep | sort -k3 -rn | head -n "$limit"
}
#############################################################################