From 8f4b1760904c84fddae2a6bda9fccf1683067adc Mon Sep 17 00:00:00 2001 From: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> Date: Wed, 13 Sep 2017 17:06:42 +0100 Subject: [PATCH 1/4] Update users_no_password.sh --- users_no_password.sh | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/users_no_password.sh b/users_no_password.sh index 0134824..40959f6 100644 --- a/users_no_password.sh +++ b/users_no_password.sh @@ -10,16 +10,25 @@ # Description : This will show all OS accounts that don't have a password set. -if [[ `uname -s` == 'Linux' ]]; then - nopass=`passwd -Sa | grep NP | awk '{print $1}'` -elif [[ `uname -s` == 'SunOS' ]]; then - nopass=`passwd -sa | grep NP | awk '{print $1}'` -fi +get_user_names(){ + # Unless you have a weird setup. Using the regex from: man useradd(8) + nopass=`passwd -${1}a | grep -o "^[a-z_][a-z0-9_-]*[$]\? NP"` + + for i in ${nopass/ /_} + { + nopassnames="${nopassnames:- } $i" + } +} - if [ -z "$nopass" ] - then - echo "Good - All user accounts have a password" - else - echo "Not Good - $nopass has no password set" - fi +if [[ "$OSTYPE" == *linux-gnu* ]]; then + get_user_names S +elif [[ "$OSTYPE" == *sunos* ]]; then + get_user_names s +fi +if [ -z "$nopassnames" ] + then + echo "Good - All user accounts have a password" + else + echo "Not Good - ${nopassnames//_NP/} has no password set" +fi From 1e403d477919e4da5e6d89503f7d070ab01d048e Mon Sep 17 00:00:00 2001 From: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> Date: Wed, 13 Sep 2017 17:25:54 +0100 Subject: [PATCH 2/4] Update users_no_password.sh --- users_no_password.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/users_no_password.sh b/users_no_password.sh index 40959f6..7662f6e 100644 --- a/users_no_password.sh +++ b/users_no_password.sh @@ -12,7 +12,7 @@ get_user_names(){ # Unless you have a weird setup. Using the regex from: man useradd(8) - nopass=`passwd -${1}a | grep -o "^[a-z_][a-z0-9_-]*[$]\? NP"` + nopass=`passwd -${1}a | grep -o "^.* NP"` for i in ${nopass/ /_} { @@ -21,6 +21,7 @@ get_user_names(){ } if [[ "$OSTYPE" == *linux-gnu* ]]; then + # NOTE: I required root access for the -a flag on my Ubuntu-based setup of Linux. get_user_names S elif [[ "$OSTYPE" == *sunos* ]]; then get_user_names s @@ -30,5 +31,8 @@ if [ -z "$nopassnames" ] then echo "Good - All user accounts have a password" else - echo "Not Good - ${nopassnames//_NP/} has no password set" + # Might be handy to add a loop to include the UID of each user. + echo "ERROR: The users listed below have no password set:"\ + " ${nopassnames//_NP/}" + exit 1 fi From 61c4c69fd350294c23a7a43734de00e43f5acb87 Mon Sep 17 00:00:00 2001 From: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> Date: Wed, 13 Sep 2017 17:34:43 +0100 Subject: [PATCH 3/4] Update users_no_password.sh --- users_no_password.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/users_no_password.sh b/users_no_password.sh index 7662f6e..f67ee02 100644 --- a/users_no_password.sh +++ b/users_no_password.sh @@ -11,7 +11,6 @@ # Description : This will show all OS accounts that don't have a password set. get_user_names(){ - # Unless you have a weird setup. Using the regex from: man useradd(8) nopass=`passwd -${1}a | grep -o "^.* NP"` for i in ${nopass/ /_} @@ -29,7 +28,7 @@ fi if [ -z "$nopassnames" ] then - echo "Good - All user accounts have a password" + echo "Good - All user accounts have a password." else # Might be handy to add a loop to include the UID of each user. echo "ERROR: The users listed below have no password set:"\ From ec73ed324cad41e1cd1b8a2449cb789f18058631 Mon Sep 17 00:00:00 2001 From: Terminal for Life <31768530+terminalforlife@users.noreply.github.com> Date: Wed, 13 Sep 2017 17:40:48 +0100 Subject: [PATCH 4/4] Update users_no_password.sh --- users_no_password.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/users_no_password.sh b/users_no_password.sh index f67ee02..e8110a6 100644 --- a/users_no_password.sh +++ b/users_no_password.sh @@ -20,7 +20,6 @@ get_user_names(){ } if [[ "$OSTYPE" == *linux-gnu* ]]; then - # NOTE: I required root access for the -a flag on my Ubuntu-based setup of Linux. get_user_names S elif [[ "$OSTYPE" == *sunos* ]]; then get_user_names s @@ -30,8 +29,7 @@ if [ -z "$nopassnames" ] then echo "Good - All user accounts have a password." else - # Might be handy to add a loop to include the UID of each user. echo "ERROR: The users listed below have no password set:"\ - " ${nopassnames//_NP/}" + " ${nopassnames//_NP/}" 1>&2 exit 1 fi