Blame 0001-Kerberos-fall-back-to-tcp-SRV-lookup.patch

5fa30d
From 6f0aa79c3e8dd93e723f29bf46e1b8b14403254f Mon Sep 17 00:00:00 2001
5fa30d
From: Sumit Bose <sbose@redhat.com>
5fa30d
Date: Mon, 5 Dec 2016 18:25:44 +0100
5fa30d
Subject: [PATCH] Kerberos: fall back to tcp SRV lookup
5fa30d
5fa30d
---
5fa30d
 service/realm-kerberos-provider.c | 48 +++++++++++++++++++++++++++++++--------
5fa30d
 1 file changed, 39 insertions(+), 9 deletions(-)
5fa30d
5fa30d
diff --git a/service/realm-kerberos-provider.c b/service/realm-kerberos-provider.c
5fa30d
index 2b3a0f8..1477ae8 100644
5fa30d
--- a/service/realm-kerberos-provider.c
5fa30d
+++ b/service/realm-kerberos-provider.c
5fa30d
@@ -19,6 +19,7 @@
5fa30d
 #include "realm-kerberos-provider.h"
5fa30d
 
5fa30d
 #include <errno.h>
5fa30d
+#include <string.h>
5fa30d
 
5fa30d
 struct _RealmKerberosProvider {
5fa30d
 	RealmProvider parent;
5fa30d
@@ -38,28 +39,54 @@ realm_kerberos_provider_init (RealmKerberosProvider *self)
5fa30d
 
5fa30d
 }
5fa30d
 
5fa30d
+typedef struct {
5fa30d
+	gchar *name;
5fa30d
+	const char *prot;
5fa30d
+} NameProtPair;
5fa30d
+
5fa30d
+static void
5fa30d
+name_prot_pair_free (gpointer data)
5fa30d
+{
5fa30d
+	NameProtPair *name_prot_pair = data;
5fa30d
+	g_free (name_prot_pair->name);
5fa30d
+	g_free (name_prot_pair);
5fa30d
+}
5fa30d
+
5fa30d
 static void
5fa30d
 on_kerberos_discover (GObject *source,
5fa30d
                       GAsyncResult *result,
5fa30d
                       gpointer user_data)
5fa30d
 {
5fa30d
 	GTask *task = G_TASK (user_data);
5fa30d
-	const gchar *domain = g_task_get_task_data (task);
5fa30d
+	NameProtPair *name_prot_pair = g_task_get_task_data (task);
5fa30d
 	GError *error = NULL;
5fa30d
 	RealmDisco *disco;
5fa30d
 	GList *targets;
5fa30d
+	GResolver *resolver;
5fa30d
 
5fa30d
 	targets = g_resolver_lookup_service_finish (G_RESOLVER (source), result, &error);
5fa30d
 	if (targets) {
5fa30d
 		g_list_free_full (targets, (GDestroyNotify)g_srv_target_free);
5fa30d
-		disco = realm_disco_new (domain);
5fa30d
-		disco->kerberos_realm = g_ascii_strup (domain, -1);
5fa30d
+		disco = realm_disco_new (name_prot_pair->name);
5fa30d
+		disco->kerberos_realm = g_ascii_strup (name_prot_pair->name, -1);
5fa30d
 		g_task_return_pointer (task, disco, realm_disco_unref);
5fa30d
 
5fa30d
 	} else if (error) {
5fa30d
-		g_debug ("Resolving %s failed: %s", domain, error->message);
5fa30d
+		g_debug ("Resolving %s failed: %s", name_prot_pair->name, error->message);
5fa30d
 		g_error_free (error);
5fa30d
-		g_task_return_pointer (task, NULL, NULL);
5fa30d
+
5fa30d
+		if (strcmp (name_prot_pair->prot, "tcp") == 0) {
5fa30d
+			g_task_return_pointer (task, NULL, NULL);
5fa30d
+		} else {
5fa30d
+			/* Try tcp */
5fa30d
+			name_prot_pair->prot = "tcp";
5fa30d
+			resolver = g_resolver_get_default ();
5fa30d
+			g_resolver_lookup_service_async (resolver, "kerberos", name_prot_pair->prot,
5fa30d
+			                                 name_prot_pair->name,
5fa30d
+			                                 g_task_get_cancellable (task),
5fa30d
+			                                 on_kerberos_discover, g_object_ref (task));
5fa30d
+			g_object_unref (resolver);
5fa30d
+		}
5fa30d
 	}
5fa30d
 
5fa30d
 	g_object_unref (task);
5fa30d
@@ -76,7 +103,7 @@ realm_kerberos_provider_discover_async (RealmProvider *provider,
5fa30d
 	GTask *task;
5fa30d
 	const gchar *software;
5fa30d
 	GResolver *resolver;
5fa30d
-	gchar *name;
5fa30d
+	NameProtPair *name_prot_pair;
5fa30d
 
5fa30d
 	task = g_task_new (provider, NULL, callback, user_data);
5fa30d
 
5fa30d
@@ -86,12 +113,15 @@ realm_kerberos_provider_discover_async (RealmProvider *provider,
5fa30d
 		g_task_return_pointer (task, NULL, NULL);
5fa30d
 
5fa30d
 	} else {
5fa30d
-		name = g_hostname_to_ascii (string);
5fa30d
+		name_prot_pair = g_new0 (NameProtPair, 1);
5fa30d
+		name_prot_pair->name = g_hostname_to_ascii (string);
5fa30d
+		name_prot_pair->prot = "udp";
5fa30d
 		resolver = g_resolver_get_default ();
5fa30d
-		g_resolver_lookup_service_async (resolver, "kerberos", "udp", name,
5fa30d
+		g_resolver_lookup_service_async (resolver, "kerberos", name_prot_pair->prot,
5fa30d
+		                                 name_prot_pair->name,
5fa30d
 		                                 realm_invocation_get_cancellable (invocation),
5fa30d
 		                                 on_kerberos_discover, g_object_ref (task));
5fa30d
-		g_task_set_task_data (task, name, g_free);
5fa30d
+		g_task_set_task_data (task, name_prot_pair, name_prot_pair_free);
5fa30d
 		g_object_unref (resolver);
5fa30d
 	}
5fa30d
 
5fa30d
-- 
5fa30d
2.9.3
5fa30d