Files
mastering-unix-ss/chapter26/chk_passwd_gid_0.bash
Fabio Scotto di Santolo 4cc88d2f6e initial commit
2020-07-28 19:28:25 +02:00

34 lines
763 B
Bash
Executable File

#!/bin/bash
#
# SCRIPT: chk_passwd_gid_0.bash
#
# PURPOSE: This script searches the /etc/passwd
# for all non-root users who are a member of
# the system/root group, GID=0
#
###########################################
# DECLARE FILES AND VARIABLES HERE
###########################################
case $(uname) in
SunOS) alias awk=nawk
;;
esac
###########################################
# BEGINNING OF MAIN
###########################################
awk -F ':' '{print $1, $3}' /etc/passwd | while read U G
do
# If the user is root skip the test
if [ $U != 'root' ]
then
# Test for GID=0
if $(id $U | grep -q 'gid=0' )
then
echo "WARNING: $U is a member of the root/system group"
fi
fi
done