Refactor run if not by root

This commit is contained in:
Evgeny Sinelnikov 2022-04-08 02:18:40 +04:00
parent 5dd5ac618e
commit 5c5b6eac30

View File

@ -39,25 +39,32 @@ run_by_root()
if test `id -u` != 0; then if test `id -u` != 0; then
echo -n "Running not by root, SKIP: " echo -n "Running not by root, SKIP: "
echo $* echo $*
return 2
else else
test -z "$msg" || test -z "$msg" ||
echo -n "$msg: " echo -n "$msg: "
$* $* || return 1
fi fi
} }
run() run()
{ {
local retval=126
local func="$1" local func="$1"
local msg_error=msg_fail
[ "${func#test_}" = "$func" ] ||
msg_error=msg_warn
if test -z $verbose; then if test -z $verbose; then
$func >/dev/null 2>&1 $func >/dev/null 2>&1 && retval=0 || retval=$?
else else
echo "--- $func ---" echo "--- $func ---"
$func $func && retval=0 || retval=$?
fi && (test -z $verbose || echo ---; msg_done "$2") || (test -z $verbose || echo ---; $msg_error "$2") fi
test -z $verbose || echo ---
case "$retval" in
0) msg_done "$2" ;;
2) msg_warn "$2" ;;
*) msg_fail "$2" ;;
esac
test -z $verbose || echo --- test -z $verbose || echo ---
test -z $verbose || echo test -z $verbose || echo
} }
@ -73,7 +80,7 @@ check_hostnamectl()
test_hostname() test_hostname()
{ {
local host=`hostname` local host=`hostname`
test "$host" != "${host/.}" test "$host" != "${host/.}" || return 2
} }
check_system_auth() check_system_auth()
@ -88,7 +95,7 @@ check_system_auth()
test_domain_system_auth() test_domain_system_auth()
{ {
local auth=$(/usr/sbin/control system-auth) local auth=$(/usr/sbin/control system-auth)
test -n "$auth" -a "$auth" != "local" test -n "$auth" -a "$auth" != "local" || return 2
} }
check_krb5_conf_ccache() check_krb5_conf_ccache()
@ -101,7 +108,7 @@ check_krb5_conf_ccache()
test_keyring_krb5_conf_ccache() test_keyring_krb5_conf_ccache()
{ {
local ccache=$(/usr/sbin/control krb5-conf-ccache) local ccache=$(/usr/sbin/control krb5-conf-ccache)
test -n "$ccache" -a "$ccache" == "keyring" test -n "$ccache" -a "$ccache" == "keyring" || return 2
} }
check_krb5_conf_kdc_lookup() check_krb5_conf_kdc_lookup()
@ -116,6 +123,7 @@ check_krb5_conf_kdc_lookup()
retval=1 retval=1
else else
echo "is enabled by default" echo "is enabled by default"
retval=2
fi fi
fi fi
return $retval return $retval
@ -127,6 +135,11 @@ check_krb5_keytab_exists()
test -e /etc/krb5.keytab test -e /etc/krb5.keytab
} }
check_keytab_credential_list()
{
run_by_root klist -ke
}
run check_hostnamectl "Check hostnamectl" run check_hostnamectl "Check hostnamectl"
run test_hostname "Test hostname is FQDN" run test_hostname "Test hostname is FQDN"
run check_system_auth "System authentication" run check_system_auth "System authentication"
@ -134,4 +147,5 @@ run test_domain_system_auth "Domain system authentication"
run check_krb5_conf_ccache "Kerberos credential cache" run check_krb5_conf_ccache "Kerberos credential cache"
run test_keyring_krb5_conf_ccache "Keyring as kerberos credential cache" run test_keyring_krb5_conf_ccache "Keyring as kerberos credential cache"
run check_krb5_conf_kdc_lookup "Check DNS lookup kerberos KDC" run check_krb5_conf_kdc_lookup "Check DNS lookup kerberos KDC"
run check_krb5_keytab_exists "Check machine crendetial cache" run check_krb5_keytab_exists "Check machine crendetial cache is exists"
run check_keytab_credential_list "Check keytab credential list"