testcases: fix file path to control access to cron
PATCH 1/1 testcases: fix file path to control access to cron
From: Lucas Magasweran <[email protected]>
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). If the man page is not available (e.g. on an embedded device), it will default to the /etc paths. This method supports vixie-cron, cronie, etc...
The repeating code has been moved into a common shell script library to simplify maintenance.
--- 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
testcases/commands/cron/cron_allow01 +1 -11
@@ -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"
testcases/commands/cron/cron_common.sh new file +15 -0
@@ -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$' || echo "/etc/cron.deny")" + export CRON_ALLOW="$(man crontab 2>/dev/null | grep -m 1 -o '/[\/a-z.]*allow$' || echo "/etc/cron.allow")" +} + +setup_path +
testcases/commands/cron/cron_deny01 +1 -13
@@ -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"
testcases/commands/cron/cron_neg_tests.sh +1 -1
@@ -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
testcases/commands/cron/cron_pos_tests.sh +1 -12
@@ -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
PATCH 1/1 testcases: fix file path to control access to cron
Hi Dan,
thanks for your patch.
Cron scripts would deserver rewriting to use new shell API (+ cleanup).
Quoted 6 lines
From: Lucas Magasweran <[email protected]>
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). If the man page is not available (e.g. on an
Do you know which distros and cron versions are really affected? Is it RHEL 4? SLES 10 SP4 uses vixie cron 4.1 with files in /etc. I wonder if we need still to support old path.
Quoted 2 lines
embedded device), it will default to the /etc paths. This method supports vixie-cron, cronie, etc...
BTW (looking at busybox source) busybox crond does not support allow/deny, but that's another issue.
Quoted 45 lines
The repeating code has been moved into a common shell script library to simplify maintenance.
Reported-by Myungho Jung <[email protected]>Signed-off-by Lucas Magasweran <[email protected]>Tested-by Dan Rue <[email protected]>--- 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.shtestcases/commands/cron/cron_allow01 +1
-11@@ -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"
testcases/commands/cron/cron_common.sh new file +0
-0
testcases/commands/cron/cron_common.sh line 6
Quoted 6 lines
testcases/commands/cron/cron_common.sh new file +6
-0@@ -0,0 +1,15 @@ +#!/bin/sh + +iam=`whoami` + +tvar=${MACHTYPE%-*} +tvar=${tvar#*-}
Can you please removed tvar? It's not needed any more and MACHTYPE is a bashism. This will remove most of bashisms (the only left will be function keyword in cron_pos_tests.sh).
testcases/commands/cron/cron_common.sh line 11
Quoted 5 lines
testcases/commands/cron/cron_common.sh new file +5
-0+ +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$' || echo "/etc/cron.deny")" + export CRON_ALLOW="$(man crontab 2>/dev/null | grep -m 1 -o '/[\/a-z.]*allow$' || echo "/etc/cron.allow")"
This has wrong quotation marks (although it's working. Better would be:
export CRON_DENY="$(man crontab 2>/dev/null | grep -m 1 -o '/[\/a-z.]*deny$' || echo '/etc/cron.deny')" export CRON_ALLOW="$(man crontab 2>/dev/null | grep -m 1 -o '/[\/a-z.]*allow$' || echo '/etc/cron.allow')"
Quoted 56 lines
testcases/commands/cron/cron_common.sh new file +4
-0+} + +setup_path +testcases/commands/cron/cron_deny01 +1
-13@@ -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"testcases/commands/cron/cron_neg_tests.sh +1
-1@@ -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 ] ; thentestcases/commands/cron/cron_pos_tests.sh +0
-6@@ -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" ]
testcases/commands/cron/cron_pos_tests.sh line 8
Quoted 10 lines
testcases/commands/cron/cron_pos_tests.sh +1
-6-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
Kind regards,
Petr
PATCH 1/1 testcases: fix file path to control access to cron
In reply to Dan RueHi!
Quoted 10 lines
TEST_USER1="ca_user1"
TEST_USER1_HOME="/home/$TEST_USER1"testcases/commands/cron/cron_common.sh new file +2
-0@@ -0,0 +1,15 @@ +#!/bin/sh +
testcases/commands/cron/cron_common.sh line 12
Quoted 10 lines
testcases/commands/cron/cron_common.sh new file +10
-0+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$' || echo "/etc/cron.deny")" + export CRON_ALLOW="$(man crontab 2>/dev/null | grep -m 1 -o '/[\/a-z.]*allow$' || echo "/etc/cron.allow")" +}
FYI I do have three crontab manual pages installed on my system, two by the cron package and one by man-pages-posix package. The 'man 1 crontab' seems to be the one we want to parse though, it will be picked by default since the predefined order starts with the section 1, but we may as well specify it explicitly.
Also I will check my collection of virtual machines, with a bit of luck all of the SLES versions that used /var/spool/cron/ are out of support now.
Signature · 1 line
[email protected]
PATCH 1/1 testcases: fix file path to control access to cron
In reply to Dan RueQuoted 16 lines
From: Lucas Magasweran <[email protected]>
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). If the man page is not available (e.g. on an embedded device), it will default to the /etc paths. This method supports vixie-cron, cronie, etc...The repeating code has been moved into a common shell script library to simplify maintenance.
Reported-by Myungho Jung <[email protected]>Signed-off-by Lucas Magasweran <[email protected]>Tested-by Dan Rue <[email protected]>---
<snip>
testcases/commands/cron/cron_allow01 line 29
Quoted 7 lines
testcases/commands/cron/cron_allow01 +1
-6-if [ "$tvar" = "redhat" -o "$tvar" = "redhat-linux" ] -then -CRON_ALLOW="/etc/cron.allow" -else -CRON_ALLOW="/var/spool/cron/allow" -fi +. cron_common.sh
We've decided to drop support for /var/spool/cron/{allow,deny} entirely. Please change your patch.
If you wonder why we drop the support:
This old path used original Vixie-cron / ISC, cronie which is a fork of Vixie-cron version 4.1 used changed the path in 2007 [1], [2].
Original patch used for RHEL /etc/cron.{allow,deny} anyway, even SLE 9.3 used vixie-cron with patched to the new path.
Debian changed the path in it's vixie-cron in 1999 [3]
Kind regards,
Petr
[1] https://github.com/cronie-crond/cronie/commit/7f6c24bc5aaddcc95556764fa3f801f2166e86b9
[2] https://github.com/cronie-crond/cronie/commit/9ff26cfe84d14af46dcf8af39fba9c25534df6f7
[3] https://anonscm.debian.org/cgit/pkg-cron/pkg-cron.git/commit/?id=546d93985f662362005109e2f069ebe15c0112aa