From nobody Sun Apr 12 00:54:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772550463; cv=none; d=zohomail.com; s=zohoarc; b=b6i90XCcPruCJ6GCpuL2OTgoTN2BG21Uoct217MwuA3U5De4A7CqfmvlOIepj3b6ZOIvjgDGb3+Fn685/+JoHydDZqLe2OOv377DhT6hmNkUeuUQAf59OoNpFVFQ4cBut06qJCSww1GgIp+eoKKZ8VvklJLwrQd0QdKl+4JsviM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772550463; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rcN7DQExjvjyGMmKRJnmIAAqYVz0suzlQQBhUNBJEzQ=; b=PrYnJNLP9cOj7EA9owG8y78pr+8iu2VTqpX0C5avPgtarG9b8w/3gkq4pHvGwonijTvLNX3zpuOkWrpCNjb6ILg0PeLD40ZjImilO/BMmvnMc47JSiHuGItLgMcHpH/l76xrOhlNSUlWF2pjUO2TIIegctBqFyQwN1rTrDajhHU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772550463110339.0669199421121; Tue, 3 Mar 2026 07:07:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vxRKp-0006gk-PK; Tue, 03 Mar 2026 10:06:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxRKl-0006cX-AH for qemu-devel@nongnu.org; Tue, 03 Mar 2026 10:06:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vxRKj-00028C-H9 for qemu-devel@nongnu.org; Tue, 03 Mar 2026 10:06:51 -0500 Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-121-gIJzPcszPR6gtTQkZVW1Fg-1; Tue, 03 Mar 2026 10:06:47 -0500 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DF94719560A5 for ; Tue, 3 Mar 2026 15:06:45 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.45.225.185]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7DC941800349; Tue, 3 Mar 2026 15:06:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772550408; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rcN7DQExjvjyGMmKRJnmIAAqYVz0suzlQQBhUNBJEzQ=; b=Ub926cAn0MqJAvddLHyRCtmGL6T00z+tX2b1rnc542/loMB1xrx3C1v4ymXcXFH77eim6E ZxWATTiXCu/gxDgOuRux/WXLA1xygFsr/5+NofMAGfvnYOT4jUFmJGW7p4OskYAQagpook lXL7QLfl5yVuIs1jtAKHzBexEDwXM2U= X-MC-Unique: gIJzPcszPR6gtTQkZVW1Fg-1 X-Mimecast-MFC-AGG-ID: gIJzPcszPR6gtTQkZVW1Fg_1772550406 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Markus Armbruster Subject: [PULL 18/27] ui: add proper error reporting for password changes Date: Tue, 3 Mar 2026 15:05:55 +0000 Message-ID: <20260303150604.2402872-19-berrange@redhat.com> In-Reply-To: <20260303150604.2402872-1-berrange@redhat.com> References: <20260303150604.2402872-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 27 X-Spam_score: 2.7 X-Spam_bar: ++ X-Spam_report: (2.7 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.322, RCVD_IN_VALIDITY_SAFE_BLOCKED=1.141, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1772550464956154100 Neither the VNC or SPICE code for password changes provides error reporting at source, leading the callers to report a largely useless generic error message. Fixing this removes one of the two remaining needs for the undesirable error_printf_unless_qmp() method. While fixing this the error message hint is improved to recommend the 'password-secret' option which allows securely passing a password at startup. Reported-by: Markus Armbruster Reviewed-by: Markus Armbruster Signed-off-by: Daniel P. Berrang=C3=A9 --- include/ui/console.h | 2 +- include/ui/qemu-spice-module.h | 3 ++- tests/functional/generic/test_vnc.py | 4 ++-- ui/spice-core.c | 25 ++++++++++++++++++------- ui/spice-module.c | 7 ++++--- ui/ui-qmp-cmds.c | 19 ++++++------------- ui/vnc-stubs.c | 6 +++--- ui/vnc.c | 10 +++++++--- 8 files changed, 43 insertions(+), 33 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 98feaa58bd..3677a9d334 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -457,7 +457,7 @@ void qemu_display_help(void); void vnc_display_init(const char *id, Error **errp); void vnc_display_open(const char *id, Error **errp); void vnc_display_add_client(const char *id, int csock, bool skipauth); -int vnc_display_password(const char *id, const char *password); +int vnc_display_password(const char *id, const char *password, Error **err= p); int vnc_display_pw_expire(const char *id, time_t expires); void vnc_parse(const char *str); int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp); diff --git a/include/ui/qemu-spice-module.h b/include/ui/qemu-spice-module.h index 1f22d557ea..072efa0c83 100644 --- a/include/ui/qemu-spice-module.h +++ b/include/ui/qemu-spice-module.h @@ -29,7 +29,8 @@ struct QemuSpiceOps { void (*display_init)(void); int (*migrate_info)(const char *h, int p, int t, const char *s); int (*set_passwd)(const char *passwd, - bool fail_if_connected, bool disconnect_if_connected= ); + bool fail_if_connected, bool disconnect_if_connected, + Error **errp); int (*set_pw_expire)(time_t expires); int (*display_add_client)(int csock, int skipauth, int tls); #ifdef CONFIG_SPICE diff --git a/tests/functional/generic/test_vnc.py b/tests/functional/generi= c/test_vnc.py index f1dd1597cf..097f858ca1 100755 --- a/tests/functional/generic/test_vnc.py +++ b/tests/functional/generic/test_vnc.py @@ -48,7 +48,7 @@ def test_no_vnc_change_password(self): self.assertEqual(set_password_response['error']['class'], 'GenericError') self.assertEqual(set_password_response['error']['desc'], - 'Could not set password') + 'No VNC display is present'); =20 def launch_guarded(self): try: @@ -73,7 +73,7 @@ def test_change_password_requires_a_password(self): self.assertEqual(set_password_response['error']['class'], 'GenericError') self.assertEqual(set_password_response['error']['desc'], - 'Could not set password') + 'VNC password authentication is disabled') =20 def test_change_password(self): self.set_machine('none') diff --git a/ui/spice-core.c b/ui/spice-core.c index ee13ecc4a5..ef1c00134f 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -757,7 +757,7 @@ static void qemu_spice_init(void) tls_ciphers); } if (password) { - qemu_spice.set_passwd(password, false, false); + qemu_spice.set_passwd(password, false, false, NULL); } if (qemu_opt_get_bool(opts, "sasl", 0)) { if (spice_server_set_sasl(spice_server, 1) =3D=3D -1) { @@ -920,8 +920,10 @@ int qemu_spice_add_display_interface(QXLInstance *qxli= n, QemuConsole *con) return qemu_spice_add_interface(&qxlin->base); } =20 -static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_con= n) +static int qemu_spice_set_ticket(bool fail_if_conn, bool disconnect_if_con= n, + Error **errp) { + int ret; time_t lifetime, now =3D time(NULL); char *passwd; =20 @@ -935,26 +937,35 @@ static int qemu_spice_set_ticket(bool fail_if_conn, b= ool disconnect_if_conn) passwd =3D NULL; lifetime =3D 1; } - return spice_server_set_ticket(spice_server, passwd, lifetime, - fail_if_conn, disconnect_if_conn); + ret =3D spice_server_set_ticket(spice_server, passwd, lifetime, + fail_if_conn, disconnect_if_conn); + if (ret < 0) { + error_setg(errp, "Unable to set SPICE server ticket"); + return -1; + } + return 0; } =20 static int qemu_spice_set_passwd(const char *passwd, - bool fail_if_conn, bool disconnect_if_con= n) + bool fail_if_conn, bool disconnect_if_con= n, + Error **errp) { if (strcmp(auth, "spice") !=3D 0) { + error_setg(errp, "SPICE authentication is disabled"); + error_append_hint(errp, + "To enable it use '-spice ...,password-secret=3D= ID'"); return -1; } =20 g_free(auth_passwd); auth_passwd =3D g_strdup(passwd); - return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn); + return qemu_spice_set_ticket(fail_if_conn, disconnect_if_conn, errp); } =20 static int qemu_spice_set_pw_expire(time_t expires) { auth_expires =3D expires; - return qemu_spice_set_ticket(false, false); + return qemu_spice_set_ticket(false, false, NULL); } =20 static int qemu_spice_display_add_client(int csock, int skipauth, int tls) diff --git a/ui/spice-module.c b/ui/spice-module.c index 3222335872..7651c85885 100644 --- a/ui/spice-module.c +++ b/ui/spice-module.c @@ -45,14 +45,15 @@ static int qemu_spice_migrate_info_stub(const char *h, = int p, int t, =20 static int qemu_spice_set_passwd_stub(const char *passwd, bool fail_if_connected, - bool disconnect_if_connected) + bool disconnect_if_connected, + Error **errp) { - return -1; + g_assert_not_reached(); } =20 static int qemu_spice_set_pw_expire_stub(time_t expires) { - return -1; + g_assert_not_reached(); } =20 static int qemu_spice_display_add_client_stub(int csock, int skipauth, diff --git a/ui/ui-qmp-cmds.c b/ui/ui-qmp-cmds.c index b49b636152..1173c82cf7 100644 --- a/ui/ui-qmp-cmds.c +++ b/ui/ui-qmp-cmds.c @@ -31,15 +31,14 @@ =20 void qmp_set_password(SetPasswordOptions *opts, Error **errp) { - int rc; - if (opts->protocol =3D=3D DISPLAY_PROTOCOL_SPICE) { if (!qemu_using_spice(errp)) { return; } - rc =3D qemu_spice.set_passwd(opts->password, - opts->connected =3D=3D SET_PASSWORD_ACTION_FAIL, - opts->connected =3D=3D SET_PASSWORD_ACTION_DISCONNECT); + qemu_spice.set_passwd(opts->password, + opts->connected =3D=3D SET_PASSWORD_ACTION_F= AIL, + opts->connected =3D=3D SET_PASSWORD_ACTION_D= ISCONNECT, + errp); } else { assert(opts->protocol =3D=3D DISPLAY_PROTOCOL_VNC); if (opts->connected !=3D SET_PASSWORD_ACTION_KEEP) { @@ -52,11 +51,7 @@ void qmp_set_password(SetPasswordOptions *opts, Error **= errp) * Note that setting an empty password will not disable login * through this interface. */ - rc =3D vnc_display_password(opts->u.vnc.display, opts->password); - } - - if (rc !=3D 0) { - error_setg(errp, "Could not set password"); + vnc_display_password(opts->u.vnc.display, opts->password, errp); } } =20 @@ -107,9 +102,7 @@ void qmp_expire_password(ExpirePasswordOptions *opts, E= rror **errp) #ifdef CONFIG_VNC void qmp_change_vnc_password(const char *password, Error **errp) { - if (vnc_display_password(NULL, password) < 0) { - error_setg(errp, "Could not set password"); - } + vnc_display_password(NULL, password, errp); } #endif =20 diff --git a/ui/vnc-stubs.c b/ui/vnc-stubs.c index a96bc86236..5de9bf9d70 100644 --- a/ui/vnc-stubs.c +++ b/ui/vnc-stubs.c @@ -2,11 +2,11 @@ #include "ui/console.h" #include "qapi/error.h" =20 -int vnc_display_password(const char *id, const char *password) +int vnc_display_password(const char *id, const char *password, Error **err= p) { - return -ENODEV; + g_assert_not_reached(); } int vnc_display_pw_expire(const char *id, time_t expires) { - return -ENODEV; + g_assert_not_reached(); }; diff --git a/ui/vnc.c b/ui/vnc.c index daf5b01d34..8bf14cf9a7 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3526,16 +3526,20 @@ static void vnc_display_close(VncDisplay *vd) #endif } =20 -int vnc_display_password(const char *id, const char *password) +int vnc_display_password(const char *id, const char *password, Error **err= p) { VncDisplay *vd =3D vnc_display_find(id); =20 if (!vd) { + error_setg(errp, "No VNC display is present"); + error_append_hint(errp, + "To enable it, use '-vnc ...'"); return -EINVAL; } if (vd->auth =3D=3D VNC_AUTH_NONE) { - error_printf_unless_qmp("If you want use passwords please enable " - "password auth using '-vnc ${dpy},password= '.\n"); + error_setg(errp, "VNC password authentication is disabled"); + error_append_hint(errp, + "To enable it, use '-vnc ...,password-secret=3DI= D'"); return -EINVAL; } =20 --=20 2.53.0