#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

source /usr/libexec/helper-scripts/accountctl.sh

if ! user_list_str="$(/usr/libexec/helper-scripts/get-user-list)"; then
    printf '%s\n' "ERROR: Failed to get user list!" >&2
    exit 1
fi
readarray -t user_list <<< "$user_list_str"

for user_entry in "${user_list[@]}"; do
   pass_data="$(get_pass "${user_entry}")"
   pass_status=""
   if [ -n "${pass_data}" ]; then
      if [ "${pass_data:0:1}" = '!' ]; then
         pass_status='Locked'
         if [ -n "${pass_data:1:1}" ]; then
           pass_status+=' (Present)'
         else
           pass_status+=' (Absent)'
         fi
      elif [ "${pass_data:0:1}" = '*' ]; then
         pass_status='Restricted'
         if [ -n "${pass_data:1:1}" ]; then
           pass_status+=' (Present)'
         else
           pass_status+=' (Absent)'
         fi
      else
         pass_status='Present'
      fi
   else
      pass_status='Absent'
   fi

   printf '%s\n' "${pass_status}"
done
