diff mbox

[3/3] vnc: Implement set_password without password

Message ID 695757b637d3506d0a6672942f16150b3d2502b6.1424190993.git.mprivozn@redhat.com
State New
Headers show

Commit Message

Michal Prívozník Feb. 17, 2015, 4:40 p.m. UTC
Well, this is a bit difficult since VNC has many ways of
authentication. So, if no password was provided, the current
authentication method is held in a variable (oldauth) and the
method is set to VNC_AUTH_NONE to mark it explicitly that no
password is required. However, as soon as the password is
provided, the old method is restored. But, what happens if
there's no old method? What if no authentication method was
provided at the command line? Well, in that case the VNC_AUTH_VNC
is set, which boils down to the same state as if the password was
put onto command line.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 ui/vnc.c | 18 ++++++++++++++----
 ui/vnc.h |  1 +
 2 files changed, 15 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/ui/vnc.c b/ui/vnc.c
index 02552ee..c6886ac 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3161,6 +3161,7 @@  void vnc_display_init(const char *id)
 
     QTAILQ_INIT(&vs->clients);
     vs->expires = TIME_MAX;
+    vs->oldauth = VNC_AUTH_NONE;
 
     if (keyboard_layout) {
         trace_vnc_key_map_init(keyboard_layout);
@@ -3214,10 +3215,19 @@  int vnc_display_password(const char *id, const char *password)
     if (!vs) {
         return -EINVAL;
     }
-    if (vs->auth == VNC_AUTH_NONE) {
-        error_printf_unless_qmp("If you want use passwords please enable "
-                                "password auth using '-vnc ${dpy},password'.");
-        return -EINVAL;
+
+    if (password) {
+        if (vs->auth == VNC_AUTH_NONE && vs->oldauth == VNC_AUTH_NONE) {
+            vs->auth = VNC_AUTH_VNC;
+        } else if (vs->oldauth != VNC_AUTH_NONE) {
+            vs->auth = vs->oldauth;
+            vs->oldauth = VNC_AUTH_NONE;
+        }
+    } else {
+        if (vs->auth != VNC_AUTH_NONE) {
+            vs->oldauth = vs->auth;
+            vs->auth = VNC_AUTH_NONE;
+        }
     }
 
     g_free(vs->password);
diff --git a/ui/vnc.h b/ui/vnc.h
index 5e2b1a5..ec4a566 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -180,6 +180,7 @@  struct VncDisplay
     char *password;
     time_t expires;
     int auth;
+    int oldauth;    /* Used to store value of auth, when temporary disabled */
     bool lossy;
     bool non_adaptive;
 #ifdef CONFIG_VNC_TLS