qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 5/7] Split vnc authentication code


From: Alexander Graf
Subject: [Qemu-devel] [PATCH 5/7] Split vnc authentication code
Date: Thu, 29 Jan 2009 12:24:56 +0100

This patch splits the authentication code, mostly for readability
reasons.

Signed-off-by: Alexander Graf <address@hidden>
---
 vnc.c |   67 ++++++++++++++++++++++++++++++++++------------------------------
 1 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/vnc.c b/vnc.c
index d0d9580..b4b0843 100644
--- a/vnc.c
+++ b/vnc.c
@@ -180,6 +180,7 @@ static void vnc_write_u8(VncState *vs, uint8_t value);
 static void vnc_flush(VncState *vs);
 static void vnc_update_client(void *opaque);
 static void vnc_client_read(void *opaque);
+static int protocol_client_auth(VncState *vs, uint8_t *data, size_t len);
 
 static void vnc_colordepth(DisplayState *ds);
 
@@ -1555,6 +1556,39 @@ static int start_auth_vnc(VncState *vs)
     return 0;
 }
 
+static int vnc_start_auth(VncState *vs, int auth)
+{
+    switch (auth) {
+    case VNC_AUTH_NONE:
+        VNC_DEBUG("Accept auth none\n");
+        if (vs->minor >= 8) {
+            vnc_write_u32(vs, 0); /* Accept auth completion */
+            vnc_flush(vs);
+        }
+        vnc_read_when(vs, protocol_client_init, 1);
+        break;
+    case VNC_AUTH_VNC:
+        VNC_DEBUG("Start VNC auth\n");
+        return start_auth_vnc(vs);
+#ifdef CONFIG_VNC_TLS
+    case VNC_AUTH_VENCRYPT:
+        VNC_DEBUG("Accept VeNCrypt auth\n");;
+        return start_auth_vencrypt(vs);
+#endif /* CONFIG_VNC_TLS */
+    default: /* Should not be possible, but just in case */
+        VNC_DEBUG("Reject auth %d unknown\n", auth);
+        vnc_write_u8(vs, 1);
+        if (vs->minor >= 8) {
+            static const char err[] = "Authentication failed";
+            vnc_write_u32(vs, sizeof(err));
+            vnc_write(vs, err, sizeof(err));
+        }
+        vnc_client_error(vs);
+    }
+
+    return 0;
+}
+
 
 #ifdef CONFIG_VNC_TLS
 #define DH_BITS 1024
@@ -1979,37 +2013,8 @@ static int protocol_client_auth(VncState *vs, uint8_t 
*data, size_t len)
        }
        vnc_client_error(vs);
     } else { /* Accept requested auth */
-       VNC_DEBUG("Client requested auth %d\n", (int)data[0]);
-       switch (vs->auth) {
-       case VNC_AUTH_NONE:
-           VNC_DEBUG("Accept auth none\n");
-           if (vs->minor >= 8) {
-               vnc_write_u32(vs, 0); /* Accept auth completion */
-               vnc_flush(vs);
-           }
-           vnc_read_when(vs, protocol_client_init, 1);
-           break;
-
-       case VNC_AUTH_VNC:
-           VNC_DEBUG("Start VNC auth\n");
-           return start_auth_vnc(vs);
-
-#ifdef CONFIG_VNC_TLS
-       case VNC_AUTH_VENCRYPT:
-           VNC_DEBUG("Accept VeNCrypt auth\n");;
-           return start_auth_vencrypt(vs);
-#endif /* CONFIG_VNC_TLS */
-
-       default: /* Should not be possible, but just in case */
-           VNC_DEBUG("Reject auth %d\n", vs->auth);
-           vnc_write_u8(vs, 1);
-           if (vs->minor >= 8) {
-               static const char err[] = "Authentication failed";
-               vnc_write_u32(vs, sizeof(err));
-               vnc_write(vs, err, sizeof(err));
-           }
-           vnc_client_error(vs);
-       }
+       VNC_DEBUG("Client requested auth %d\n", auth);
+       return vnc_start_auth(vs, data[0]);
     }
     return 0;
 }
-- 
1.6.0.2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]