#!/bin/sh

# Set default values
APPDIR=${APPDIR:-..}

. ${APPDIR}/common.subr

sect "User related information";

if check_privs /etc/passwd; then
	echo "There are `awk '/^[[:alnum:]]/ { if ($3>1000) i++} END { print i }' FS=":" /etc/passwd` local users (uid > 1000) \
and `awk '/^[[:alnum:]]/ { if ($3<1000) i++} END { print i }' FS=":" /etc/passwd` system users (uid < 1000)."
	echo
fi

if check_privs /etc/group; then
	echo "There are `awk '/^[[:alnum:]]/ { if ($3>1000) i++} END { print i }' FS=":" /etc/group` local groups (gid > 1000) \
and `awk '/^[[:alnum:]]/ { if ($3<1000) i++} END { print i }' FS=":" /etc/group` system groups (gid < 1000)."
	echo
	subsect "Users in wheel group (allowed to use su(1)):"
	awk '/^[[:alnum:]]/ { if ($4 == 0) print $1 }' FS=":" /etc/passwd | tr '\n' ','
	awk '/^wheel/ { print $4 }' FS=":" /etc/group
	echo
fi

if check_privs /var/run/utmp; then
	subsect "Currently logged-in users:"
	w -hi
fi

if check_privs /var/log/wtmp; then
	subsect "\nTop 10 logged-in users this month:"
	ac -p -w /var/log/wtmp.0 | sort -nr -k 2 | head -n 11 | grep -vw total | sed -E 's/^[[:space:]]+//'
fi

if check_privs /var/log/lastlog; then
	subsect "\nLast login dates per user:"
	lastlogin
fi

exit 0
