#!/bin/sh

# shellcheck disable=SC1090
# shellcheck disable=SC2034
# shellcheck disable=SC2154

# audit_remote_management
#
# Check remote management
#
# Refer to Section(s) 2.2.9   Page(s) 25-6  CIS Apple OS X 10.8  Benchmark v1.0.0
# Refer to Section(s) 2.2.9   Page(s) 48-9  CIS Apple OS X 10.12 Benchmark v1.0.0
# Refer to Section(S) 2.3.3.6 Page(s) 104-5 CIS Apple macOS 14 Sonoma Benchmark v1.0.0
#.

audit_remote_management () {
  print_function "audit_remote_management"
  string="Remote Management"
  check_message  "${string}"
  if [ "${os_name}" = "Darwin" ]; then
    if [ "${audit_mode}" != 2 ]; then
      command="launchctl list |awk '{print \$3}' |grep -c ARDAgent |sed \"s/ //g\""
      command_message      "${command}"
      actual_value=$( eval "${command}" )
      if [ "${actual_value}" = "1" ]; then
        inc_insecure "Remote Management is enabled"
        fix_message  "Open System Preferences"
        fix_message  "Select Sharing"
        fix_message  "Uncheck Remote Management"
      else
        inc_secure   "Remote Management is disabled"
      fi
    else
      fix_message    "Open System Preferences"
      fix_message    "Select Sharing"
      fix_message    "Uncheck Remote Management"
    fi
  else
    na_message "${string}"
  fi
}
