From 9900c9451e04c1e1e9ddb53a10eec84cc31e0dea Mon Sep 17 00:00:00 2001 From: Lucas Magasweran Date: Wed, 21 Jun 2017 17:38:37 -0700 Subject: [PATCH] testcases: fix file path to control access to cron crontab uses /etc/cron.{allow,deny} to control access on most distributions, as well as RHEL. To maintain backwards compatibility with older still supported distributions, the test setup will search the man page for the correct paths (e.g. /var/spool/cron/allow). The repeating code has been moved into a common shell script library to simplify maintenance. Reported-by: Myungho Jung Signed-off-by: Lucas Magasweran --- testcases/commands/cron/cron_allow01 | 12 +----------- testcases/commands/cron/cron_common.sh | 15 +++++++++++++++ testcases/commands/cron/cron_deny01 | 14 +------------- testcases/commands/cron/cron_neg_tests.sh | 2 +- testcases/commands/cron/cron_pos_tests.sh | 13 +------------ 5 files changed, 19 insertions(+), 37 deletions(-) create mode 100755 testcases/commands/cron/cron_common.sh diff --git a/testcases/commands/cron/cron_allow01 b/testcases/commands/cron/cron_allow01 index 9a5e4d2406b..7e05f7b7ddb 100755 --- a/testcases/commands/cron/cron_allow01 +++ b/testcases/commands/cron/cron_allow01 @@ -26,17 +26,7 @@ echo "This script contains bashism that needs to be fixed!" -iam=`whoami` - -tvar=${MACHTYPE%-*} -tvar=${tvar#*-} - -if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ] -then -CRON_ALLOW="/etc/cron.allow" -else -CRON_ALLOW="/var/spool/cron/allow" -fi +. cron_common.sh TEST_USER1="ca_user1" TEST_USER1_HOME="/home/$TEST_USER1" diff --git a/testcases/commands/cron/cron_common.sh b/testcases/commands/cron/cron_common.sh new file mode 100755 index 00000000000..6f3180e8131 --- /dev/null +++ b/testcases/commands/cron/cron_common.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +iam=`whoami` + +tvar=${MACHTYPE%-*} +tvar=${tvar#*-} + +setup_path() { + # Support paths used by older distributions of RHEL or SLES. + export CRON_DENY="$(man crontab 2>/dev/null | grep -m 1 -o '[\/a-z.]*deny\b' || echo "/etc/cron.deny")" + export CRON_ALLOW="$(man crontab 2>/dev/null | grep -m 1 -o '[\/a-z.]*allow\b' || echo "/etc/cron.allow")" +} + +setup_path + diff --git a/testcases/commands/cron/cron_deny01 b/testcases/commands/cron/cron_deny01 index 9d320392512..263a7829b58 100755 --- a/testcases/commands/cron/cron_deny01 +++ b/testcases/commands/cron/cron_deny01 @@ -26,19 +26,7 @@ echo "This script contains bashism that needs to be fixed!" -iam=`whoami` - -tvar=${MACHTYPE%-*} -tvar=${tvar#*-} - -if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ] -then -CRON_DENY="/etc/cron.deny" -CRON_ALLOW="/etc/cron.allow" -else -CRON_DENY="/var/spool/cron/deny" -CRON_ALLOW="/var/spool/cron/allow" -fi +. cron_common.sh TEST_USER1="cd_user1" TEST_USER1_HOME="/home/$TEST_USER1" diff --git a/testcases/commands/cron/cron_neg_tests.sh b/testcases/commands/cron/cron_neg_tests.sh index 9c3d6f6c7cc..49c5c4e5d07 100755 --- a/testcases/commands/cron/cron_neg_tests.sh +++ b/testcases/commands/cron/cron_neg_tests.sh @@ -9,7 +9,7 @@ # 12/03/04 Marty Ridgeway Pull RHEl4 tests out from script ######################################################## -iam=`whoami` +. cron_common.sh if [ $iam = "root" ]; then if [ $# -lt 1 ] ; then diff --git a/testcases/commands/cron/cron_pos_tests.sh b/testcases/commands/cron/cron_pos_tests.sh index ece114c84cf..a0ddaea57bd 100755 --- a/testcases/commands/cron/cron_pos_tests.sh +++ b/testcases/commands/cron/cron_pos_tests.sh @@ -2,18 +2,7 @@ # Positive tests for cron, that means these tests have to pass -iam=`whoami` - -tvar=${MACHTYPE%-*} -tvar=${tvar#*-} - -if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ] -then - CRON_ALLOW="/etc/cron.allow" -else - CRON_ALLOW="/var/spool/cron/allow" -fi - +. cron_common.sh if [ $iam = "root" ]; then if [ $# -lt 1 ] ; then