From 8ef2b5500fc8f6c74c26212ffd2abb0bcee9b12e Mon Sep 17 00:00:00 2001 From: Salma Police Date: Mon, 14 Nov 2022 11:21:19 -0500 Subject: [PATCH] Enhance collect tool to detect passwordless sudo The collect tool expects a password prompt for all sudo operations. When passwordless sudo is enabled the collect script times out waiting for a password prompt that never comes. This update enhances collect tool to detect passwordless sudo for getting a password prompt on its first sudo operaton and fails the collect if there is no password prompt. Test plan: Verify by enabling passwordless sudo PASS: collect fails with message Verify by disabling passwordless sudo PASS: No passwordless sudo passes and collect proceeds PASS: Collect is rejected when provided with incorrect password Story: 2009968 Task: 46767 Signed-off-by: Salma Police Change-Id: I11239a25757a929a5679441b7a90586657a623f8 --- tools/collector/scripts/collect | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tools/collector/scripts/collect b/tools/collector/scripts/collect index fddb4e43..9023250c 100755 --- a/tools/collector/scripts/collect +++ b/tools/collector/scripts/collect @@ -1088,12 +1088,11 @@ pw=${pw/\"/\\\"} # replace '"' with '\"' function password_test() { - local dir=${1} /usr/bin/expect << EOF log_user ${USER_LOG_MODE} spawn bash -i - set timeout 10 + set timeout 60 expect -re $ send "sudo cat /usr/local/sbin/expect_done\n" expect { @@ -1120,13 +1119,12 @@ password_test ########################################################################### # -# Name : check_host_reachable +# Name :function password_test # -# Purpose : Verify a host is reachable before trying to collect from it +# Purpose : Verify to detect passwordless sudo for getting a password prompt and fails the collect, +# if there is no password prompt # -# Description: ls the content of the scratch dir -# Parameters : $1 - remote hostname -# $2 - dir or file with full path +# Description: cat the content of the /usr/local/sbin/expect_done # ###########################################################################