From nobody Tue Mar 24 00:57:01 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=1772733073; cv=none; d=zohomail.com; s=zohoarc; b=hleZCmOu8mIYMX+omzkIit6Z89uXL955kj59e+EtrGfVtq52+betXVv7K1f9NBbGJeU2Zt9aij8EKcJJWIS8JJ2bzIHVwyKyl91fKPQziorANZYen3kOXm6GE1DvXFATQgO9pFjvmibvU9Y2pOsageIFpLY8qGbHaeoMTAmtiPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772733073; 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=IiN9PaA/HvESWthoRAuGuhtL1I5A0JmrBn2/1frL4v31opEIUabKcIPZfS+sYY3zIuW4/1WDX97K8q4Ui4cf5jY3lVzwoiKfUK4rcwWokpZ4VWtmLZTE40TZV5V0t48gw82b2sCWfiRW+QVozPopPvk7ecb9wnpe8+Q5b1xTDjE= 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 1772733073856517.6405205445443; Thu, 5 Mar 2026 09:51:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyCpP-0005UN-WD; Thu, 05 Mar 2026 12:49:40 -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 1vyCpO-0005GZ-7e for qemu-devel@nongnu.org; Thu, 05 Mar 2026 12:49:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyCpL-0002IU-Gc for qemu-devel@nongnu.org; Thu, 05 Mar 2026 12:49:37 -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-104-0MlElerGM8qyCthmcB0OtQ-1; Thu, 05 Mar 2026 12:49:31 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 C3DCA195609F; Thu, 5 Mar 2026 17:49:29 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.44.34.61]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0D63B195419E; Thu, 5 Mar 2026 17:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772732974; 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=ZiCaHq4FfHZENJuzvba9Fpr3rCH4HigV/IKl+j9d/IZGKajwaBLBl16wbew/oL1XS+7+ZA TP9c76SALgSwH1ZmEzVDFw4jWqddfV1Fr3G240p348PY6YIOI/QQjg4SNtNnuX4W76eLX5 h00M9sSUL7u1fDSRq0BceVU2Lxq2Zxk= X-MC-Unique: 0MlElerGM8qyCthmcB0OtQ-1 X-Mimecast-MFC-AGG-ID: 0MlElerGM8qyCthmcB0OtQ_1772732969 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , devel@lists.libvirt.org, qemu-rust@nongnu.org, "Dr. David Alan Gilbert" , Gerd Hoffmann , Christian Schoenebeck , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Manos Pitsidianakis , Eduardo Habkost , Pierrick Bouvier , Paolo Bonzini , Stefan Weil Subject: [PULL 18/27] ui: add proper error reporting for password changes Date: Thu, 5 Mar 2026 17:47:34 +0000 Message-ID: <20260305174743.3084606-19-berrange@redhat.com> In-Reply-To: <20260305174743.3084606-1-berrange@redhat.com> References: <20260305174743.3084606-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.0 on 10.30.177.17 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.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.892, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.622, 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: 1772733077997154100 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