From patchwork Wed Mar 21 02:35:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Rue X-Patchwork-Id: 888507 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="JkxD33th"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 405Ynl4J3fz9rx7 for ; Wed, 21 Mar 2018 13:35:50 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0B2F13E780A for ; Wed, 21 Mar 2018 03:35:47 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 0C4263E6654 for ; Wed, 21 Mar 2018 03:35:45 +0100 (CET) Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id E257B2015B9 for ; Wed, 21 Mar 2018 03:35:43 +0100 (CET) Received: by mail-pf0-x241.google.com with SMTP id y186so1459996pfb.2 for ; Tue, 20 Mar 2018 19:35:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=1jRZhJrxFvZOWQV+63u2qbHyHqCSuYUtsWNdbqUsHeI=; b=JkxD33thjyn2rmhlVl9Q4C3UZhne8YJqwOdDoz5CItWN5GmbipTt1TyK3IRRX++VaS RXcn6fXBDXaRprJP8MT3DRJSXWJNqhvW9xSLRsHKT0hdZxMxjtQwrVKa407+do3Dd341 rQ1vGPJcE1ObnBB514LH3dHbNX4orY/W0eh5M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=1jRZhJrxFvZOWQV+63u2qbHyHqCSuYUtsWNdbqUsHeI=; b=H06FBtWCs/HHLx6VcuIdTCEzZRGjHtFvekZM4pvxNnjCn8PVbm0tvn5/yanDAdiHtF ApqXM5QpHdTFAsSE+mTjlVoMNdvKmW2E6Uu9BhakbQz6+2TYNVWOhKXQ0Nx37xLR/Tmi 5b/r3QiYlSB53+sEuYXJbDmocHI98E3sTbrcirnkDuhxKcK4zqO7e7dz4FXq5OJwSbMf 7i4at75mPPeVh4g9mFqTp15Yy3ZUaRE35TQZdiT4qeO3QKw+hVdjJeYvSMD3qwIbbHNm gYIfY41Wqf4rR+iJAXkP9ZSG7h8thGLBivUB4tdKd+bf0Q5zjwAGfx1lNfTCOlzIl1lN So5A== X-Gm-Message-State: AElRT7EXEKiPxpOZ1/H1rzDdWqGaKn1twnvFse6rO1gvBQVFgQY2AMq5 6dmMkOvLnImpjuex6aZ6VYlFq0ppdEk= X-Google-Smtp-Source: AG47ELuk69ndW+EboccrSB/hq/JtnU3eltmot2HEWVicmwDE2xZUxrfNuDCIfnwkPsW9GHC2htB38g== X-Received: by 10.101.70.72 with SMTP id k8mr8892551pgr.402.1521599741933; Tue, 20 Mar 2018 19:35:41 -0700 (PDT) Received: from localhost ([218.255.99.6]) by smtp.gmail.com with ESMTPSA id w27sm4981936pge.20.2018.03.20.19.35.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 20 Mar 2018 19:35:41 -0700 (PDT) From: Dan Rue To: ltp@lists.linux.it Date: Wed, 21 Mar 2018 10:35:15 +0800 Message-Id: <20180321023515.11356-1-dan.rue@linaro.org> X-Mailer: git-send-email 2.14.3 X-Virus-Scanned: clamav-milter 0.99.2 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-7.smtp.seeweb.it Cc: Lucas Magasweran Subject: [LTP] [PATCH] testcases: fix file path to control access to cron X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Lucas Magasweran 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 Signed-off-by: Lucas Magasweran Tested-by: Dan Rue --- 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 9a5e4d2406..7e05f7b7dd 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 0000000000..5ed90c4039 --- /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$' || 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 + diff --git a/testcases/commands/cron/cron_deny01 b/testcases/commands/cron/cron_deny01 index 9d32039251..263a7829b5 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 9c3d6f6c7c..49c5c4e5d0 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 ece114c84c..a0ddaea57b 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