From: Michal Privoznik <[email protected]> Our bash completion script parses (partially incomplete) command line and looks for two arguments: --readonly and --connect because in the next step it executes virsh with those two arguments like this:
virsh --readonly --connect $URI complete -- "text to complete" Now, whenever virsh sees connection URI specified on its cmd line it connects to it right away (before executing any command). This happens inside virshConnect(). Here, virConnectOpenAuth() is called with the default auth callback (virConnectAuthPtrDefault). In majority of the cases this is desirable, as it might ask user for credentials (password for example). But in case of bash completion this is not desired because bash completion script must not expect users to input anything (that's why we even close stdin in cmdComplete()). Therefore, when connecting from virsh that's executed by the bash completion script provide no auth callbacks to prevent virsh from asking for credentials. Resolves: https://gitlab.com/libvirt/libvirt/-/work_items/879 Signed-off-by: Michal Privoznik <[email protected]> --- tools/virsh.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/virsh.c b/tools/virsh.c index fdce3220b3..72d233f98d 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -124,8 +124,16 @@ virshConnect(vshControl *ctl, const char *uri, bool readonly) do { virErrorPtr err; + virConnectAuthPtr auth = virConnectAuthPtrDefault; - if ((c = virConnectOpenAuth(uri, virConnectAuthPtrDefault, + if (ctl->cmd->def->handler == cmdComplete) { + /* When running from a bash completer we need to avoid any kind of + * keyboard input (e.g. ssh asking for a password). To achieve + * this, provide no authentication callbacks. */ + auth = NULL; + } + + if ((c = virConnectOpenAuth(uri, auth, readonly ? VIR_CONNECT_RO : 0))) break; -- 2.53.0
