From cd6a396e88239b53bbe1d94f966c243ec6234588 Mon Sep 17 00:00:00 2001 From: Sam Zaydel Date: Thu, 4 Apr 2013 14:01:16 -0700 Subject: [PATCH] Added root check function to smf_import. --- tools/smf_import | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/smf_import b/tools/smf_import index af8d1aa37..0d385af5b 100755 --- a/tools/smf_import +++ b/tools/smf_import @@ -7,6 +7,17 @@ set -e SVCCFG="${ROOT}/projects/illumos/usr/src/cmd/svc/svccfg/svccfg-native" +function check_root () { + + ## If UID or EUID are not 0, we return 1, otherwise we return 0. + if [[ ! ${UID} -eq 0 && ! ${EUID} -eq 0 ]] ; then + echo "FATAL: $0 was not executed by root. User must be root." + return 1 + else + return 0 + fi +} + rdmnt=$1 if [ -z "${rdmnt}" ] || [ ! -d "${rdmnt}" ]; then echo "FATAL: Invalid ramdisk root '${rdmnt}'" @@ -24,7 +35,7 @@ if [[ ! -x ${SVCCFG} ]]; then exit 1 fi -# TODO check that we're root +check_root || exit 1 ## If not running as root, bail. REPO_DB=${rdmnt}/etc/svc/repository.db export SVCCFG_CHECKHASH=1