aboutsummaryrefslogtreecommitdiff
path: root/qmp.c
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2011-12-07 11:17:51 -0200
committerLuiz Capitulino <lcapitulino@redhat.com>2012-01-18 10:23:38 -0200
commitfbf796fd6f855313d2c02b7d8e1a0c4241b1e0b6 (patch)
tree789cec2028477461ecfcc3b5b159b14464360aff /qmp.c
parenta6aa9d3e2681199d159963e46524625d90669619 (diff)
qapi: Convert set_password
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Diffstat (limited to 'qmp.c')
-rw-r--r--qmp.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/qmp.c b/qmp.c
index c74dde6c90..9ef43a857c 100644
--- a/qmp.c
+++ b/qmp.c
@@ -16,6 +16,8 @@
#include "qemu-common.h"
#include "sysemu.h"
#include "qmp-commands.h"
+#include "ui/qemu-spice.h"
+#include "ui/vnc.h"
#include "kvm.h"
#include "arch_init.h"
#include "hw/qdev.h"
@@ -249,3 +251,55 @@ out:
return 0;
}
+
+void qmp_set_password(const char *protocol, const char *password,
+ bool has_connected, const char *connected, Error **errp)
+{
+ int disconnect_if_connected = 0;
+ int fail_if_connected = 0;
+ int rc;
+
+ if (has_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 {
+ error_set(errp, QERR_INVALID_PARAMETER, "connected");
+ return;
+ }
+ }
+
+ if (strcmp(protocol, "spice") == 0) {
+ if (!using_spice) {
+ /* correct one? spice isn't a device ,,, */
+ error_set(errp, QERR_DEVICE_NOT_ACTIVE, "spice");
+ return;
+ }
+ rc = qemu_spice_set_passwd(password, fail_if_connected,
+ disconnect_if_connected);
+ if (rc != 0) {
+ error_set(errp, QERR_SET_PASSWD_FAILED);
+ }
+ return;
+ }
+
+ if (strcmp(protocol, "vnc") == 0) {
+ if (fail_if_connected || disconnect_if_connected) {
+ /* vnc supports "connected=keep" only */
+ error_set(errp, QERR_INVALID_PARAMETER, "connected");
+ return;
+ }
+ /* Note that setting an empty password will not disable login through
+ * this interface. */
+ rc = vnc_display_password(NULL, password);
+ if (rc < 0) {
+ error_set(errp, QERR_SET_PASSWD_FAILED);
+ }
+ return;
+ }
+
+ error_set(errp, QERR_INVALID_PARAMETER, "protocol");
+}