Fix group detection - improve error handling and variable capture for id -Gn command
parent
44297955d1
commit
02990680ba
|
|
@ -58,10 +58,12 @@ echo
|
|||
|
||||
echo "=== 2. USER GROUPS CHECK ==="
|
||||
if id "$USERNAME" &>/dev/null; then
|
||||
GROUPS=$(id -Gn "$USERNAME" 2>/dev/null)
|
||||
GROUPS_LIST="$GROUPS"
|
||||
# Get groups using id command - ensure we capture the output correctly
|
||||
GROUPS_OUTPUT=$(id -Gn "$USERNAME" 2>&1)
|
||||
GROUPS_EXIT=$?
|
||||
|
||||
# Debug: Show actual groups
|
||||
if [ $GROUPS_EXIT -eq 0 ] && [ -n "$GROUPS_OUTPUT" ]; then
|
||||
GROUPS_LIST="$GROUPS_OUTPUT"
|
||||
echo " All groups: $GROUPS_LIST"
|
||||
|
||||
# Check for sftpusers or sshusers group
|
||||
|
|
@ -82,6 +84,13 @@ if id "$USERNAME" &>/dev/null; then
|
|||
else
|
||||
print_status "WARNING" "User is NOT in litespeed group (may affect file access)"
|
||||
fi
|
||||
else
|
||||
print_status "ERROR" "Failed to retrieve groups for user $USERNAME"
|
||||
echo " Command exit code: $GROUPS_EXIT"
|
||||
echo " Output: $GROUPS_OUTPUT"
|
||||
fi
|
||||
else
|
||||
print_status "ERROR" "User $USERNAME does not exist"
|
||||
fi
|
||||
echo
|
||||
|
||||
|
|
@ -308,7 +317,11 @@ echo
|
|||
echo "=== 9. AUTHENTICATION TEST (SIMULATED) ==="
|
||||
if id "$USERNAME" &>/dev/null; then
|
||||
USER_SHELL=$(getent passwd $USERNAME | cut -d: -f7)
|
||||
AUTH_GROUPS=$(id -Gn "$USERNAME" 2>/dev/null)
|
||||
AUTH_GROUPS_OUTPUT=$(id -Gn "$USERNAME" 2>&1)
|
||||
AUTH_GROUPS_EXIT=$?
|
||||
|
||||
if [ $AUTH_GROUPS_EXIT -eq 0 ] && [ -n "$AUTH_GROUPS_OUTPUT" ]; then
|
||||
AUTH_GROUPS="$AUTH_GROUPS_OUTPUT"
|
||||
|
||||
if [ "$USER_SHELL" = "/sbin/nologin" ]; then
|
||||
if echo "$AUTH_GROUPS" | grep -qw "sftpusers"; then
|
||||
|
|
@ -329,6 +342,13 @@ if id "$USERNAME" &>/dev/null; then
|
|||
else
|
||||
print_status "WARNING" "Unexpected shell: $USER_SHELL"
|
||||
fi
|
||||
else
|
||||
print_status "ERROR" "Failed to retrieve groups for authentication check"
|
||||
echo " Command exit code: $AUTH_GROUPS_EXIT"
|
||||
echo " Output: $AUTH_GROUPS_OUTPUT"
|
||||
fi
|
||||
else
|
||||
print_status "ERROR" "User $USERNAME does not exist"
|
||||
fi
|
||||
echo
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue