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

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