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

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