ui: Improve some set_passwd, expire_password error messages

set_passwd and expire_password reject invalid "protocol" with "Invalid
parameter 'protocol'".  Misleading; the parameter is valid, its value
isn't.  Improve to "Parameter 'protocol' expects 'vnc' or 'spice'".

expire_password fails with "Could not set password".  Misleading;
improve to "Could not set password expire time".

QERR_SET_PASSWD_FAILED is now unused.  Drop.

Cc: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201113082626.2725812-5-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2020-11-13 09:26:20 +01:00
parent b0d7be2a62
commit 9272186d3d
2 changed files with 15 additions and 26 deletions

View File

@ -65,9 +65,6 @@
#define QERR_REPLAY_NOT_SUPPORTED \ #define QERR_REPLAY_NOT_SUPPORTED \
"Record/replay feature is not supported for '%s'" "Record/replay feature is not supported for '%s'"
#define QERR_SET_PASSWD_FAILED \
"Could not set password"
#define QERR_UNDEFINED_ERROR \ #define QERR_UNDEFINED_ERROR \
"An undefined error has occurred" "An undefined error has occurred"

View File

@ -199,13 +199,7 @@ void qmp_set_password(const char *protocol, const char *password,
} }
rc = qemu_spice.set_passwd(password, fail_if_connected, rc = qemu_spice.set_passwd(password, fail_if_connected,
disconnect_if_connected); disconnect_if_connected);
if (rc != 0) { } else if (strcmp(protocol, "vnc") == 0) {
error_setg(errp, QERR_SET_PASSWD_FAILED);
}
return;
}
if (strcmp(protocol, "vnc") == 0) {
if (fail_if_connected || disconnect_if_connected) { if (fail_if_connected || disconnect_if_connected) {
/* vnc supports "connected=keep" only */ /* vnc supports "connected=keep" only */
error_setg(errp, QERR_INVALID_PARAMETER, "connected"); error_setg(errp, QERR_INVALID_PARAMETER, "connected");
@ -214,13 +208,15 @@ void qmp_set_password(const char *protocol, const char *password,
/* Note that setting an empty password will not disable login through /* Note that setting an empty password will not disable login through
* this interface. */ * this interface. */
rc = vnc_display_password(NULL, password); rc = vnc_display_password(NULL, password);
if (rc < 0) { } else {
error_setg(errp, QERR_SET_PASSWD_FAILED); error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol",
} "'vnc' or 'spice'");
return; return;
} }
error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); if (rc != 0) {
error_setg(errp, "Could not set password");
}
} }
void qmp_expire_password(const char *protocol, const char *whenstr, void qmp_expire_password(const char *protocol, const char *whenstr,
@ -244,28 +240,24 @@ void qmp_expire_password(const char *protocol, const char *whenstr,
return; return;
} }
rc = qemu_spice.set_pw_expire(when); rc = qemu_spice.set_pw_expire(when);
if (rc != 0) { } else if (strcmp(protocol, "vnc") == 0) {
error_setg(errp, QERR_SET_PASSWD_FAILED);
}
return;
}
if (strcmp(protocol, "vnc") == 0) {
rc = vnc_display_pw_expire(NULL, when); rc = vnc_display_pw_expire(NULL, when);
if (rc != 0) { } else {
error_setg(errp, QERR_SET_PASSWD_FAILED); error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "protocol",
} "'vnc' or 'spice'");
return; return;
} }
error_setg(errp, QERR_INVALID_PARAMETER, "protocol"); if (rc != 0) {
error_setg(errp, "Could not set password expire time");
}
} }
#ifdef CONFIG_VNC #ifdef CONFIG_VNC
void qmp_change_vnc_password(const char *password, Error **errp) void qmp_change_vnc_password(const char *password, Error **errp)
{ {
if (vnc_display_password(NULL, password) < 0) { if (vnc_display_password(NULL, password) < 0) {
error_setg(errp, QERR_SET_PASSWD_FAILED); error_setg(errp, "Could not set password");
} }
} }