[gtk-vnc-devel] [patch] - implement preferable auth methods



Hi.

Currently we are just accepting the first auth method advertised by the
server. This is bad in cases when the server advertises "5, 6 and 2" for
instance. We don't support 5 and 6, but we do support 2. The connection
should go on here.

In this patch I implemented this feature, by adding a private array
which contains the preferable order of auth methods.

If it makes sense, we could add later a public method to let the app
manipulate this array, telling which auth methods it prefers. Does that
make sense to you?

Any comments about the patch?

Cheers,
-- 
Jonh Wendell
www.bani.com.br

diff -r adefa4c86b29 src/vncdisplay.c
--- a/src/vncdisplay.c	Thu Apr 24 11:48:00 2008 -0400
+++ b/src/vncdisplay.c	Fri Apr 25 13:33:52 2008 -0300
@@ -81,6 +81,8 @@ struct _VncDisplayPrivate
 	gboolean read_only;
 	gboolean allow_lossy;
 	gboolean allow_scaling;
+
+	GSList *preferable_auths;
 };
 
 /* Delayed signal emission.
@@ -1264,14 +1266,24 @@ static gboolean on_auth_type(void *opaqu
 {
 	VncDisplay *obj = VNC_DISPLAY(opaque);
 	VncDisplayPrivate *priv = obj->priv;
+	GSList *l;
+	guint i;
 
-	/*
-	 * XXX lame - we should have some prioritization. That
-	 * said most servers only support 1 auth type at any time
-	 */
-	if (ntype)
-		gvnc_set_auth_type(priv->gvnc, types[0]);
+	if (!ntype)
+		return TRUE;
 
+	for (l = priv->preferable_auths; l; l=l->next) {
+		gvnc_auth pref = GPOINTER_TO_UINT (l->data);
+
+		for (i=0; i<ntype; i++) {
+			if (pref == types[i]) {
+				gvnc_set_auth_type(priv->gvnc, types[i]);
+				return TRUE;
+			}
+		}
+	}
+	
+	gvnc_set_auth_type(priv->gvnc, types[0]);
 	return TRUE;
 }
 
@@ -1280,13 +1292,24 @@ static gboolean on_auth_subtype(void *op
 	VncDisplay *obj = VNC_DISPLAY(opaque);
 	VncDisplayPrivate *priv = obj->priv;
 
-	/*
-	 * XXX lame - we should have some prioritization. That
-	 * said most servers only support 1 auth type at any time
-	 */
-	if (ntype)
-		gvnc_set_auth_subtype(priv->gvnc, types[0]);
+	GSList *l;
+	guint i;
 
+	if (!ntype)
+		return TRUE;
+
+	for (l = priv->preferable_auths; l; l=l->next) {
+		gvnc_auth pref = GPOINTER_TO_UINT (l->data);
+
+		for (i=0; i<ntype; i++) {
+			if (pref == types[i]) {
+				gvnc_set_auth_subtype(priv->gvnc, types[i]);
+				return TRUE;
+			}
+		}
+	}
+	
+	gvnc_set_auth_subtype(priv->gvnc, types[0]);
 	return TRUE;
 }
 
@@ -1741,6 +1764,8 @@ static void vnc_display_finalize (GObjec
 		priv->image = NULL;
 	}
 
+	g_slist_free (priv->preferable_auths);
+
 	G_OBJECT_CLASS (vnc_display_parent_class)->finalize (obj);
 }
 
@@ -2070,6 +2095,11 @@ static void vnc_display_init(VncDisplay 
 	priv->grab_pointer = FALSE;
 	priv->grab_keyboard = FALSE;
 	priv->local_pointer = FALSE;
+
+	priv->preferable_auths = g_slist_append (priv->preferable_auths, GUINT_TO_POINTER (GVNC_AUTH_VENCRYPT));
+	priv->preferable_auths = g_slist_append (priv->preferable_auths, GUINT_TO_POINTER (GVNC_AUTH_TLS));
+	priv->preferable_auths = g_slist_append (priv->preferable_auths, GUINT_TO_POINTER (GVNC_AUTH_VNC));
+	priv->preferable_auths = g_slist_append (priv->preferable_auths, GUINT_TO_POINTER (GVNC_AUTH_NONE));
 
 #if WITH_GTKGLEXT
 	if (gtk_gl_init_check(NULL, NULL)) {


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