From nobody Mon Feb 9 10:33:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1673972478; cv=none; d=zohomail.com; s=zohoarc; b=DuvFJMFI9g4nV9SJDhny6SDTZJ1+KdEi+s0murUO8gZdWaGD1oTCkPvbQawp4Gl+XjKGoSiv3/YagKDOtwlCCHikWHWFJoqZr86g7WOQ4ARDhSXfzLXxbHefLziEjJ+QVqJzzh0odsLlZga3YnDGXELq2OZe6i4BHs7NZomE4tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673972478; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZC42vDRbtQGM2tW2cn7FFMUe173T7FpBTsRIOh8YsyU=; b=l9fMG2FhGzSLA1k+I9I1uCZdlJU1ZTp/riZ+/zoAm5uMOK72tIr7x3e/qO6IX1FSSPI3ObG1wrhvrwlRyEQJk6jpB8cRkxq4C3demIaRMGgcfKOrmx8SXxdqzGn4fjthCwW1wayAvp58T7yRK0kV+SHXZMv5j0mO0sQ4vQ0GN9I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1673972478783191.20275680501038; Tue, 17 Jan 2023 08:21:18 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-311-kd2xWkQqOzmYmVkoVRIqlQ-1; Tue, 17 Jan 2023 11:21:14 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C15B1810BD5; Tue, 17 Jan 2023 16:20:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id A616F39D6D; Tue, 17 Jan 2023 16:20:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 68DE51947044; Tue, 17 Jan 2023 16:20:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B416419465A3 for ; Tue, 17 Jan 2023 16:20:55 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 973311121318; Tue, 17 Jan 2023 16:20:55 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E0881121315 for ; Tue, 17 Jan 2023 16:20:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673972477; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ZC42vDRbtQGM2tW2cn7FFMUe173T7FpBTsRIOh8YsyU=; b=PYsSkgebaZ67hV6ygnV9MnSIvEbKfjvGDYcBg7/0cG1+sqVlXVltb1ODsDYGKCU6cnov6r 0tR4wSnqMOyKKCLzzDAi98ZIpDk8r336K3KV8dFxW0lhUe8BHnlFQOZp4Ncw6USNMwmhXO QBUfq8yil3KbjCne1SBfIizwG3OuEQ4= X-MC-Unique: kd2xWkQqOzmYmVkoVRIqlQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/15] virNetLibsshCheckHostKey: Use virAuthAskCredential Date: Tue, 17 Jan 2023 17:20:38 +0100 Message-Id: <7f7e81e972ec68c426831f60d74e5737827345e7.1673972406.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673972480674100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/rpc/virnetlibsshsession.c | 57 +++++------------------------------ 1 file changed, 7 insertions(+), 50 deletions(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 748c1ed569..ecee30e5df 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -218,27 +218,6 @@ virLibsshServerKeyAsString(virNetLibsshSession *sess) return str; } -static int -virCredTypeForPrompt(virConnectAuthPtr cred, char echo) -{ - size_t i; - - for (i =3D 0; i < cred->ncredtype; ++i) { - int type =3D cred->credtype[i]; - if (echo) { - if (type =3D=3D VIR_CRED_ECHOPROMPT) - return type; - } else { - if (type =3D=3D VIR_CRED_PASSPHRASE || - type =3D=3D VIR_CRED_NOECHOPROMPT) { - return type; - } - } - } - - return -1; -} - static int virLengthForPromptString(const char *str) { @@ -296,9 +275,8 @@ virNetLibsshCheckHostKey(virNetLibsshSession *sess) case SSH_SERVER_NOT_KNOWN: /* key was not found, query to add it to database */ if (sess->hostKeyVerify =3D=3D VIR_NET_LIBSSH_HOSTKEY_VERIFY_NORMA= L) { - virConnectCredential askKey; - int cred_type; - char *tmp; + g_autoptr(virConnectCredential) cred =3D NULL; + g_autofree char *prompt =3D NULL; /* ask to add the key */ if (!sess->cred || !sess->cred->cb) { @@ -308,48 +286,27 @@ virNetLibsshCheckHostKey(virNetLibsshSession *sess) return -1; } - cred_type =3D virCredTypeForPrompt(sess->cred, 1 /* echo */); - if (cred_type =3D=3D -1) { - virReportError(VIR_ERR_LIBSSH, "%s", - _("no suitable callback for host key " - "verification")); - return -1; - } - - /* prepare data for the callback */ - memset(&askKey, 0, sizeof(virConnectCredential)); - askKey.type =3D cred_type; - keyhashstr =3D virLibsshServerKeyAsString(sess); if (!keyhashstr) return -1; - tmp =3D g_strdup_printf(_("Accept SSH host key with hash '%s' = for " "host '%s:%d' (%s/%s)?"), - keyhashstr, sess->hostname, sess->port, = "y", "n"); - askKey.prompt =3D tmp; + prompt =3D g_strdup_printf(_("Accept SSH host key with hash '%= s' for " "host '%s:%d' (%s/%s)?"), + keyhashstr, sess->hostname, sess->por= t, "y", "n"); - if (sess->cred->cb(&askKey, 1, sess->cred->cbdata)) { - virReportError(VIR_ERR_LIBSSH, "%s", - _("failed to retrieve decision to accept " - "host key")); - VIR_FREE(tmp); + if (!(cred =3D virAuthAskCredential(sess->cred, prompt, false)= )) { ssh_string_free_char(keyhashstr); return -1; } - VIR_FREE(tmp); - - if (!askKey.result || - STRCASENEQ(askKey.result, "y")) { + if (!cred->result || + STRCASENEQ(cred->result, "y")) { virReportError(VIR_ERR_LIBSSH, _("SSH host key for '%s' (%s) was not accep= ted"), sess->hostname, keyhashstr); ssh_string_free_char(keyhashstr); - VIR_FREE(askKey.result); return -1; } ssh_string_free_char(keyhashstr); - VIR_FREE(askKey.result); } /* write the host key file, if specified */ --=20 2.38.1