From patchwork Mon Jan 13 11:53:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Granados X-Patchwork-Id: 13937222 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B89DA1C2DB4 for ; Mon, 13 Jan 2025 11:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736769195; cv=none; b=MuSB4cRG0ocLLGKvs0W3VteMezMxH3M72GUXNHMtcIVVns4UZRV1vzY80Xe0mxULLLQ77JKa8YdrUwerskjI6D6594lp6YLcJMyFztG/hNVDJ6CqlQtwYq1LWffclYZWhWC57h2kpMU1rWq5dV98KC8BXCD5dkhiE4hdtGLUOlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736769195; c=relaxed/simple; bh=l6fdWgpjKbFsO8OSF2C8SwibeLtb/ff0owgRzjJFREo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Epai2lKrWZ70ZGHk58Ge8jYImQmKHyWJ9msjqEWxrthtK7+6zPiUMG0hGynv0yoj+mrOBiCqV9Brt9w3kLfwzmR53Cjn9qD3j3HfgTstICFjvMzxhiOvh+SVhGmSS8sdWKH9vVJ2Z6fzy1cuTF+neLvxTFMRh1gbyhdsUOjW5tw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SUpQKn/w; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SUpQKn/w" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8E985C4CEE3; Mon, 13 Jan 2025 11:53:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1736769195; bh=l6fdWgpjKbFsO8OSF2C8SwibeLtb/ff0owgRzjJFREo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=SUpQKn/wdGFdnUtQIQpf2szI8mNvS+HJh5R5lupVoL8D1eOXbDNO9EH/XlSldZf0K 356XLIJkDRjgIIofLp9U1lowulxs4fM2RdVd5coqgZjs1FSXzaPcTfCVONy1b9i+oG wBLGTM0oUqwVLrLcP6chm1wHULo9cPWhC25/awNX8M0aYIvUA17bxa2VEkGrMxfN3Y uew4elvBvc3B6Esnkf2/I3SeshOdxXvZoJebfxAMp9udBhMbpf4LU0/05O2QH1I+GJ pNyXqWELNamWhCSyGLSiSEqNKVy7I0Zzj6kBpqWGanPCPoiG4/za6AF6S8Veo4NqPp fHLWceF8SCz2A== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78DB4C02184; Mon, 13 Jan 2025 11:53:15 +0000 (UTC) From: Joel Granados Date: Mon, 13 Jan 2025 12:53:00 +0100 Subject: [PATCH RESEND 02/12] scripts: Adjust heuristic to see if current user can sudo Precedence: bulk X-Mailing-List: kdevops@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250113-jag-bringup_fixes-v1-2-fb28030b1f26@kernel.org> References: <20250113-jag-bringup_fixes-v1-0-fb28030b1f26@kernel.org> In-Reply-To: <20250113-jag-bringup_fixes-v1-0-fb28030b1f26@kernel.org> To: kdevops@lists.linux.dev Cc: Joel Granados , mcgrof@kernel.org, da.gomez@samsung.com X-Mailer: b4 0.15-dev-00a43 X-Developer-Signature: v=1; a=openpgp-sha256; l=2158; i=joel.granados@kernel.org; h=from:subject:message-id; bh=l6fdWgpjKbFsO8OSF2C8SwibeLtb/ff0owgRzjJFREo=; b=kA0DAAoBupfNUreWQU8ByyZiAGeE/qKhqs3WN4N4sdaFXPB9a6rZ1Vdh2hYcDaYSFePad3Onn YkBswQAAQoAHRYhBK5HCVcl5jElzssnkLqXzVK3lkFPBQJnhP6iAAoJELqXzVK3lkFPEEkL/1F7 Yk9iCgc3wHGfmEWQHA8nOMz6aC3m5BPgfvCKRQP9xSjPDvyYjSpMaYCHn+fe4Ml6CAvevRdybhO uh3bn7ELojnMOBjrCYiXwiJoCwrGmXb1dIj6EvAuYDy2g352bqr2B6JJLU/gGs2a6pQrp4R+GjD n1ibbcXmZqRNUtZm0o3kqBE+xMQK1AAesM/DrsaukSOVM8pfkm3Dz/bOPCNacptNZ0kIg/miFuE AukJ2+zVcKrCPTArHAtDFpnGnQ0WlTtF1GyCQQiFDDNiPgtg24DLMkhjy4V/4F8kHk/C67ZlyN7 UKgZ6GZjN/J3GLjofC/Y75fgQi04wYnYP/r5ZQTy6UJ5Y3DcvlyayxRB0iN8iV2fVHBMof04X6r izUXuWMm8Decj27mWqz8nx/c1NP7HBCXCu00eFJjz/lx6FK2Io5n0IKvEdqZNkR48exM96A7Cic 1aHwmvQalnqNlTtwE1SEKoVptdTBz0WBJhGJpf5wSU/v4gglIk8l0pwLfJuA== X-Developer-Key: i=joel.granados@kernel.org; a=openpgp; fpr=F1F8E46D30F0F6C4A45FF4465895FAAC338C6E77 X-Endpoint-Received: by B4 Relay for joel.granados@kernel.org/default with auth_id=239 * New heuristic uses the following sudo command options: -n : "non-interactive"; will prevent sudo from prompting the user for any kind of input. -v : Update the user's cache credentials; has distinct output for users with and without sudo: 1. Without sudo the output is "Sorry, user __USER__ may not run sudo..." 2. With sudo it has two messages (with and without password). But we ignore the distinction as both of these mean that user can sudo. * Avoid setting SUDO_ASKPASS. This env variable is suppose to have the executable that will be executed when asking for sudo instead of a boolean. Signed-off-by: Joel Granados Reviewed-by: Daniel Gomez --- scripts/libvirt_pool.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scripts/libvirt_pool.sh b/scripts/libvirt_pool.sh index f8c309e..ffae928 100644 --- a/scripts/libvirt_pool.sh +++ b/scripts/libvirt_pool.sh @@ -1,6 +1,26 @@ #!/bin/bash # Helpers to work with virsh pools +get_can_sudo() +{ + # Heuristic to see if the current user can sudo + # -n : This is the non-interactive argument in sudo and will prevent + # sudo from prompting the user for any kind of input. + # -v : This tries to update the users cache credentials but also has + # distinct output for users with and without sudo: + # 1. Without sudo the output is + # "Sorry, user __USER__ may not run sudo..." + # 2. With sudo it has two messages: one for paswordless sudo and + # one passwordfull sudo. But we ignore the distinction as both + # of these mean that can_sudo is "y". + if [[ $(sudo -nv 2>&1 | grep 'may not' > /dev/null) -eq 0 ]]; then + echo "n" + exit + fi + echo "y" + exit +} + get_pool_vars() { if [[ -f $OS_FILE ]]; then @@ -10,10 +30,7 @@ get_pool_vars() fi fi - SUDO_ASKPASS=/bin/false sudo -A whoami > /dev/null 2>&1 - if [[ $? -eq 0 ]]; then - CAN_SUDO="y" - fi + CAN_SUDO=get_can_sudo if [[ "$USES_QEMU_USER_SESSION" != "y" ]]; then REQ_SUDO="sudo"