qapi/monitor: allow VNC display id in set/expire_password

It is possible to specify more than one VNC server on the command line,
either with an explicit ID or the auto-generated ones à la "default",
"vnc2", "vnc3", ...

It is not possible to change the password on one of these extra VNC
displays though. Fix this by adding a "display" parameter to the
"set_password" and "expire_password" QMP and HMP commands.

For HMP, the display is specified using the "-d" value flag.

For QMP, the schema is updated to explicitly express the supported
variants of the commands with protocol-discriminated unions.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
[FE: update "Since: " from 6.2 to 7.0
     make @connected a common member of @SetPasswordOptions]
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
Message-Id: <20220225084949.35746-4-f.ebner@proxmox.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
This commit is contained in:
Stefan Reiter 2022-02-25 09:49:49 +01:00 committed by Dr. David Alan Gilbert
parent 7277db9103
commit 675fd3c96b
4 changed files with 129 additions and 65 deletions

View file

@ -1396,24 +1396,33 @@ void hmp_set_password(Monitor *mon, const QDict *qdict)
{
const char *protocol = qdict_get_str(qdict, "protocol");
const char *password = qdict_get_str(qdict, "password");
const char *display = qdict_get_try_str(qdict, "display");
const char *connected = qdict_get_try_str(qdict, "connected");
Error *err = NULL;
DisplayProtocol proto;
SetPasswordAction conn;
proto = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
DISPLAY_PROTOCOL_VNC, &err);
SetPasswordOptions opts = {
.password = (char *)password,
.has_connected = !!connected,
};
opts.connected = qapi_enum_parse(&SetPasswordAction_lookup, connected,
SET_PASSWORD_ACTION_KEEP, &err);
if (err) {
goto out;
}
conn = qapi_enum_parse(&SetPasswordAction_lookup, connected,
SET_PASSWORD_ACTION_KEEP, &err);
opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
DISPLAY_PROTOCOL_VNC, &err);
if (err) {
goto out;
}
qmp_set_password(proto, password, !!connected, conn, &err);
if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
opts.u.vnc.has_display = !!display;
opts.u.vnc.display = (char *)display;
}
qmp_set_password(&opts, &err);
out:
hmp_handle_error(mon, err);
@ -1423,16 +1432,25 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict)
{
const char *protocol = qdict_get_str(qdict, "protocol");
const char *whenstr = qdict_get_str(qdict, "time");
const char *display = qdict_get_try_str(qdict, "display");
Error *err = NULL;
DisplayProtocol proto;
proto = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
DISPLAY_PROTOCOL_VNC, &err);
ExpirePasswordOptions opts = {
.time = (char *)whenstr,
};
opts.protocol = qapi_enum_parse(&DisplayProtocol_lookup, protocol,
DISPLAY_PROTOCOL_VNC, &err);
if (err) {
goto out;
}
qmp_expire_password(proto, whenstr, &err);
if (opts.protocol == DISPLAY_PROTOCOL_VNC) {
opts.u.vnc.has_display = !!display;
opts.u.vnc.display = (char *)display;
}
qmp_expire_password(&opts, &err);
out:
hmp_handle_error(mon, err);