From 05e87c0da97cf157e7facd371dad09de0fadfcb2 Mon Sep 17 00:00:00 2001 From: Dan Brodjieski Date: Thu, 25 Jun 2026 12:34:33 -0400 Subject: [PATCH] fix: update CURRENT_USER discovery change method to use the loginwindow.plist instead of console --- src/mscp/data/rules/os/os_show_filename_extensions_enable.yaml | 2 +- .../data/templates/shell_scripts/compliance_script.sh.jinja | 2 +- src/mscp/data/templates/shell_scripts/restore_script.sh.jinja | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mscp/data/rules/os/os_show_filename_extensions_enable.yaml b/src/mscp/data/rules/os/os_show_filename_extensions_enable.yaml index 48b8a95d..ac67daa2 100644 --- a/src/mscp/data/rules/os/os_show_filename_extensions_enable.yaml +++ b/src/mscp/data/rules/os/os_show_filename_extensions_enable.yaml @@ -8,7 +8,7 @@ discussion: | The check and fix are for the currently logged in user. To get the currently logged in user, run the following. [source,bash] ---- - CURRENT_USER=$( /usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }' ) + CURRENT_USER=$( /usr/bin/defaults read /Library/Preferences/com.apple.loginwindow lastUserName ) ---- ==== references: diff --git a/src/mscp/data/templates/shell_scripts/compliance_script.sh.jinja b/src/mscp/data/templates/shell_scripts/compliance_script.sh.jinja index 996314a4..6a4ccaf5 100644 --- a/src/mscp/data/templates/shell_scripts/compliance_script.sh.jinja +++ b/src/mscp/data/templates/shell_scripts/compliance_script.sh.jinja @@ -70,7 +70,7 @@ fi plb="/usr/libexec/PlistBuddy" # get the currently logged in user and hostname -CURRENT_USER=$( /usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }') +CURRENT_USER=$( /usr/bin/defaults read /Library/Preferences/com.apple.loginwindow lastUserName ) CURR_USER_UID=$(/usr/bin/id -u $CURRENT_USER) CURR_HOSTNAME=$(/usr/sbin/scutil --get HostName) diff --git a/src/mscp/data/templates/shell_scripts/restore_script.sh.jinja b/src/mscp/data/templates/shell_scripts/restore_script.sh.jinja index c92a0a85..114064b3 100644 --- a/src/mscp/data/templates/shell_scripts/restore_script.sh.jinja +++ b/src/mscp/data/templates/shell_scripts/restore_script.sh.jinja @@ -67,7 +67,7 @@ fi plb="/usr/libexec/PlistBuddy" # get the currently logged in user -CURRENT_USER=$( /usr/sbin/scutil <<< "show State:/Users/ConsoleUser" | /usr/bin/awk '/Name :/ && ! /loginwindow/ { print $3 }') +CURRENT_USER=$( /usr/bin/defaults read /Library/Preferences/com.apple.loginwindow lastUserName ) CURR_USER_UID=$(/usr/bin/id -u $CURRENT_USER) # get system architecture