From ebaa8a57541a7deabcb12225363d6b200d1b7344 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 24 Jan 2011 13:13:51 -0200 Subject: [PATCH 48/48] spice monitor commands: restore rhel6.0 compatibility RH-Author: Gerd Hoffmann Message-id: <1295874831-12225-3-git-send-email-kraxel@redhat.com> Patchwork-id: 16841 O-Subject: [RHEL-6 kvm PATCH 2/2] spice monitor commands: restore rhel6.0 compatibility Bugzilla: 615947 631832 632458 634153 642131 647865 RH-Acked-by: Alon Levy RH-Acked-by: Hans de Goede Signed-off-by: Gerd Hoffmann --- monitor.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-monitor.hx | 18 +++++++++++ 2 files changed, 103 insertions(+), 0 deletions(-) Signed-off-by: Luiz Capitulino --- monitor.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-monitor.hx | 18 +++++++++++ 2 files changed, 103 insertions(+), 0 deletions(-) diff --git a/monitor.c b/monitor.c index 692fb97..ab1406f 100644 --- a/monitor.c +++ b/monitor.c @@ -1283,6 +1283,70 @@ static int expire_password(Monitor *mon, const QDict *qdict, QObject **ret_data) return -1; } +static int redhat_set_password(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + const char *protocol = qdict_get_str(qdict, "protocol"); + const char *password = qdict_get_str(qdict, "password"); + const char *connected = qdict_get_try_str(qdict, "connected"); + int lifetime = qdict_get_int(qdict, "expiration"); + time_t when; + int disconnect_if_connected = 0; + int fail_if_connected = 0; + int rc; + + if (lifetime == 0) { + when = TIME_MAX; + } else { + when = time(NULL) + lifetime; + } + + if (connected) { + if (strcmp(connected, "fail") == 0) { + fail_if_connected = 1; + } else if (strcmp(connected, "disconnect") == 0) { + disconnect_if_connected = 1; + } else if (strcmp(connected, "keep") == 0) { + /* nothing */ + } else { + qerror_report(QERR_INVALID_PARAMETER, "connected"); + return -1; + } + } + + if (strcmp(protocol, "spice") == 0) { + if (!using_spice) { + /* correct one? spice isn't a device ,,, */ + qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice"); + return -1; + } + rc = qemu_spice_set_passwd(password, fail_if_connected, + disconnect_if_connected); + if (rc != 0) { + qerror_report(QERR_SET_PASSWD_FAILED); + return -1; + } + qemu_spice_set_pw_expire(when); + + } else if (strcmp(protocol, "vnc") == 0) { + if (fail_if_connected || disconnect_if_connected) { + /* vnc supports "connected=keep" only */ + qerror_report(QERR_INVALID_PARAMETER, "connected"); + return -1; + } + if (vnc_display_password(NULL, password) < 0) { + qerror_report(QERR_SET_PASSWD_FAILED); + return -1; + } + vnc_display_pw_expire(NULL, when); + + } else { + qerror_report(QERR_INVALID_PARAMETER, "protocol"); + return -1; + } + + return 0; +} + static int client_migrate_info(Monitor *mon, const QDict *qdict, QObject **ret_data) { const char *protocol = qdict_get_str(qdict, "protocol"); @@ -1310,6 +1374,27 @@ static int client_migrate_info(Monitor *mon, const QDict *qdict, QObject **ret_d return -1; } +static int redhat_spice_migrate_info(Monitor *mon, const QDict *qdict, QObject **ret_data) +{ + const char *hostname = qdict_get_str(qdict, "hostname"); + const char *subject = qdict_get_try_str(qdict, "cert-subject"); + int port = qdict_get_try_int(qdict, "port", -1); + int tls_port = qdict_get_try_int(qdict, "tls-port", -1); + int ret; + + if (!using_spice) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, "spice"); + return -1; + } + + ret = qemu_spice_migrate_info(hostname, port, tls_port, subject); + if (ret != 0) { + qerror_report(QERR_UNDEFINED_ERROR); + return -1; + } + return 0; +} + static void do_screen_dump(Monitor *mon, const QDict *qdict) { vga_hw_screen_dump(qdict_get_str(qdict, "filename")); diff --git a/qemu-monitor.hx b/qemu-monitor.hx index c9da54d..8368a53 100644 --- a/qemu-monitor.hx +++ b/qemu-monitor.hx @@ -1655,6 +1655,24 @@ Example: EQMP { + .name = RFQDN_REDHAT "set_password", + .args_type = "protocol:s,password:s,expiration:i,connected:s?", + .params = "protocol password expiration action-if-connected", + .help = "set spice/vnc password", + .user_print = monitor_user_noop, + .mhandler.cmd_new = redhat_set_password, + }, + { + .name = RFQDN_REDHAT "spice_migrate_info", + .args_type = "hostname:s,port:i?,tls-port:i?,cert-subject:s?", + .params = "hostname port tls-port cert-subject", + .help = "send migration info to spice client", + .user_print = monitor_user_noop, + .mhandler.cmd_new = redhat_spice_migrate_info, + }, + + + { .name = "qmp_capabilities", .args_type = "", .params = "", -- 1.7.4.rc1.16.gd2f15e