qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com
Subject: [Qemu-devel] [PATCH 03/14] qapi: Convert expire_password
Date: Wed, 18 Jan 2012 15:41:13 -0200	[thread overview]
Message-ID: <1326908484-13389-4-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1326908484-13389-1-git-send-email-lcapitulino@redhat.com>

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 console.h        |    2 --
 hmp-commands.hx  |    3 +--
 hmp.c            |   10 ++++++++++
 hmp.h            |    1 +
 monitor.c        |   39 ---------------------------------------
 qapi-schema.json |   27 +++++++++++++++++++++++++++
 qmp-commands.hx  |    5 +----
 qmp.c            |   40 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 80 insertions(+), 47 deletions(-)

diff --git a/console.h b/console.h
index be3b7c8..6ba0d5d 100644
--- a/console.h
+++ b/console.h
@@ -4,7 +4,6 @@
 #include "qemu-char.h"
 #include "qdict.h"
 #include "notify.h"
-#include "qerror.h"
 #include "monitor.h"
 
 /* keyboard/mouse support */
@@ -388,7 +387,6 @@ static inline int vnc_display_password(DisplayState *ds, const char *password)
 }
 static inline int vnc_display_pw_expire(DisplayState *ds, time_t expires)
 {
-    qerror_report(QERR_FEATURE_DISABLED, "vnc");
     return -ENODEV;
 };
 #endif
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 4355a6f..047fba2 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1239,8 +1239,7 @@ ETEXI
         .args_type  = "protocol:s,time:s",
         .params     = "protocol time",
         .help       = "set spice/vnc password expire-time",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = expire_password,
+        .mhandler.cmd = hmp_expire_password,
     },
 
 STEXI
diff --git a/hmp.c b/hmp.c
index 888e1b9..081acab 100644
--- a/hmp.c
+++ b/hmp.c
@@ -692,3 +692,13 @@ void hmp_set_password(Monitor *mon, const QDict *qdict)
     qmp_set_password(protocol, password, !!connected, connected, &err);
     hmp_handle_error(mon, &err);
 }
+
+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");
+    Error *err = NULL;
+
+    qmp_expire_password(protocol, whenstr, &err);
+    hmp_handle_error(mon, &err);
+}
diff --git a/hmp.h b/hmp.h
index 4ed0fee..575f529 100644
--- a/hmp.h
+++ b/hmp.h
@@ -50,5 +50,6 @@ void hmp_migrate_cancel(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_downtime(Monitor *mon, const QDict *qdict);
 void hmp_migrate_set_speed(Monitor *mon, const QDict *qdict);
 void hmp_set_password(Monitor *mon, const QDict *qdict);
+void hmp_expire_password(Monitor *mon, const QDict *qdict);
 
 #endif
diff --git a/monitor.c b/monitor.c
index 1f5d343..aa7259c 100644
--- a/monitor.c
+++ b/monitor.c
@@ -884,45 +884,6 @@ static int do_change(Monitor *mon, const QDict *qdict, QObject **ret_data)
     return ret;
 }
 
-static int expire_password(Monitor *mon, const QDict *qdict, QObject **ret_data)
-{
-    const char *protocol  = qdict_get_str(qdict, "protocol");
-    const char *whenstr = qdict_get_str(qdict, "time");
-    time_t when;
-    int rc;
-
-    if (strcmp(whenstr, "now") == 0) {
-        when = 0;
-    } else if (strcmp(whenstr, "never") == 0) {
-        when = TIME_MAX;
-    } else if (whenstr[0] == '+') {
-        when = time(NULL) + strtoull(whenstr+1, NULL, 10);
-    } else {
-        when = strtoull(whenstr, NULL, 10);
-    }
-
-    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_pw_expire(when);
-        if (rc != 0) {
-            qerror_report(QERR_SET_PASSWD_FAILED);
-            return -1;
-        }
-        return 0;
-    }
-
-    if (strcmp(protocol, "vnc") == 0) {
-        return vnc_display_pw_expire(NULL, when);
-    }
-
-    qerror_report(QERR_INVALID_PARAMETER, "protocol");
-    return -1;
-}
-
 static int add_graphics_client(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     const char *protocol  = qdict_get_str(qdict, "protocol");
diff --git a/qapi-schema.json b/qapi-schema.json
index 092ff6e..dc92a79 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1304,3 +1304,30 @@
 ##
 { 'command': 'set_password',
   'data': {'protocol': 'str', 'password': 'str', '*connected': 'str'} }
+
+##
+# @expire_password:
+#
+# Expire the password of a remote display server.
+#
+# @protocol: the name of the remote display protocol `vnc' or `spice'
+#
+# @time: when to expire the password.
+#        `now' to expire the password immediately
+#        `never' to cancel password expiration
+#        `+INT' where INT is the number of seconds from now (integer)
+#        `INT' where INT is the absolute time in seconds
+#
+# Returns: Nothing on success
+#          If @protocol is `spice' and Spice is not active, DeviceNotFound
+#          If an error occurs setting password expiration, SetPasswdFailed
+#          If @protocol is not `spice' or 'vnc', InvalidParameter
+#
+# Since: 0.14.0
+#
+# Notes: Time is relative to the server and currently there is no way to
+#        coordinate server time with client time.  It is not recommended to
+#        use the absolute time version of the @time parameter unless you're
+#        sure you are on the same machine as the QEMU instance.
+##
+{ 'command': 'expire_password', 'data': {'protocol': 'str', 'time': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index eadad05..d7264b2 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -877,10 +877,7 @@ EQMP
     {
         .name       = "expire_password",
         .args_type  = "protocol:s,time:s",
-        .params     = "protocol time",
-        .help       = "set spice/vnc password expire-time",
-        .user_print = monitor_user_noop,
-        .mhandler.cmd_new = expire_password,
+        .mhandler.cmd_new = qmp_marshal_input_expire_password,
     },
 
 SQMP
diff --git a/qmp.c b/qmp.c
index 9ef43a8..8b7b379 100644
--- a/qmp.c
+++ b/qmp.c
@@ -303,3 +303,43 @@ void qmp_set_password(const char *protocol, const char *password,
 
     error_set(errp, QERR_INVALID_PARAMETER, "protocol");
 }
+
+void qmp_expire_password(const char *protocol, const char *whenstr,
+                         Error **errp)
+{
+    time_t when;
+    int rc;
+
+    if (strcmp(whenstr, "now") == 0) {
+        when = 0;
+    } else if (strcmp(whenstr, "never") == 0) {
+        when = TIME_MAX;
+    } else if (whenstr[0] == '+') {
+        when = time(NULL) + strtoull(whenstr+1, NULL, 10);
+    } else {
+        when = strtoull(whenstr, NULL, 10);
+    }
+
+    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_pw_expire(when);
+        if (rc != 0) {
+            error_set(errp, QERR_SET_PASSWD_FAILED);
+        }
+        return;
+    }
+
+    if (strcmp(protocol, "vnc") == 0) {
+        rc = vnc_display_pw_expire(NULL, when);
+        if (rc != 0) {
+            error_set(errp, QERR_SET_PASSWD_FAILED);
+        }
+        return;
+    }
+
+    error_set(errp, QERR_INVALID_PARAMETER, "protocol");
+}
-- 
1.7.9.rc0.dirty

  parent reply	other threads:[~2012-01-18 17:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-18 17:41 [Qemu-devel] [PULL 00/14]: QMP queue Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 01/14] vnc: Simplify vnc_display_password() Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 02/14] qapi: Convert set_password Luiz Capitulino
2012-01-18 17:41 ` Luiz Capitulino [this message]
2012-01-18 17:41 ` [Qemu-devel] [PATCH 04/14] block: eject_device(): Use error_set() Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 05/14] qapi: Convert eject Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 06/14] monitor: expose readline state Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 07/14] qapi: Introduce change-vnc-password Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 08/14] qerror: Extend QERR_DEVICE_ENCRYPTED Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 09/14] qapi: Convert change Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 10/14] qapi: Convert block_set_io_throttle Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 11/14] qmp: Add missing gcc format attribute and fix format string Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 12/14] qerror: add check-qerror.sh to verify alphabetical order Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 13/14] qerror: restore alphabetical order over qerrors Luiz Capitulino
2012-01-18 17:41 ` [Qemu-devel] [PATCH 14/14] block: use proper qerrors in qmp_block_resize Luiz Capitulino
2012-01-24  9:35   ` Markus Armbruster
2012-01-19 18:47 ` [Qemu-devel] [PULL 00/14]: QMP queue Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1326908484-13389-4-git-send-email-lcapitulino@redhat.com \
    --to=lcapitulino@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).