|
|
dec65d8 |
From 5e28cf702ad338e399f8fff0b3fa18736a297318 Mon Sep 17 00:00:00 2001
|
|
|
dec65d8 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
dec65d8 |
Date: Tue, 21 Aug 2018 13:09:20 +0200
|
|
|
dec65d8 |
Subject: [PATCH 3/3] discover: try to get domain name from hostname
|
|
|
dec65d8 |
|
|
|
dec65d8 |
If there is no domain name returned by DHCP check if the hostname
|
|
|
dec65d8 |
contains a domain part and use this to discover a realm.
|
|
|
dec65d8 |
|
|
|
dec65d8 |
Related to https://bugzilla.redhat.com/show_bug.cgi?id=1619162
|
|
|
dec65d8 |
---
|
|
|
dec65d8 |
service/realm-provider.c | 28 +++++++++++++++++++++++++++-
|
|
|
dec65d8 |
1 file changed, 27 insertions(+), 1 deletion(-)
|
|
|
dec65d8 |
|
|
|
dec65d8 |
diff --git a/service/realm-provider.c b/service/realm-provider.c
|
|
|
dec65d8 |
index d647c7a..258e8e1 100644
|
|
|
dec65d8 |
--- a/service/realm-provider.c
|
|
|
dec65d8 |
+++ b/service/realm-provider.c
|
|
|
dec65d8 |
@@ -28,6 +28,8 @@
|
|
|
dec65d8 |
#include <glib/gi18n.h>
|
|
|
dec65d8 |
#include <gio/gio.h>
|
|
|
dec65d8 |
|
|
|
dec65d8 |
+#include <errno.h>
|
|
|
dec65d8 |
+
|
|
|
dec65d8 |
#define TIMEOUT_SECONDS 15
|
|
|
dec65d8 |
|
|
|
dec65d8 |
G_DEFINE_TYPE (RealmProvider, realm_provider, G_TYPE_DBUS_OBJECT_SKELETON);
|
|
|
dec65d8 |
@@ -181,6 +183,25 @@ on_discover_complete (GObject *source,
|
|
|
dec65d8 |
return_discover_result (method, realms, relevance, error);
|
|
|
dec65d8 |
}
|
|
|
dec65d8 |
|
|
|
dec65d8 |
+static gchar *
|
|
|
dec65d8 |
+get_domain_from_hostname (void)
|
|
|
dec65d8 |
+{
|
|
|
dec65d8 |
+ gchar hostname[HOST_NAME_MAX + 1];
|
|
|
dec65d8 |
+ gchar *dot;
|
|
|
dec65d8 |
+
|
|
|
dec65d8 |
+ if (gethostname (hostname, sizeof (hostname)) < 0) {
|
|
|
dec65d8 |
+ g_warning ("Couldn't get the computer host name: %s", g_strerror (errno));
|
|
|
dec65d8 |
+ return NULL;
|
|
|
dec65d8 |
+ }
|
|
|
dec65d8 |
+
|
|
|
dec65d8 |
+ dot = strchr (hostname, '.');
|
|
|
dec65d8 |
+ if (dot != NULL) {
|
|
|
dec65d8 |
+ return g_strdup (dot + 1);
|
|
|
dec65d8 |
+ }
|
|
|
dec65d8 |
+
|
|
|
dec65d8 |
+ return NULL;
|
|
|
dec65d8 |
+}
|
|
|
dec65d8 |
+
|
|
|
dec65d8 |
static void
|
|
|
dec65d8 |
on_discover_default (GObject *source,
|
|
|
dec65d8 |
GAsyncResult *result,
|
|
|
dec65d8 |
@@ -195,6 +216,10 @@ on_discover_default (GObject *source,
|
|
|
dec65d8 |
g_clear_error (&error);
|
|
|
dec65d8 |
}
|
|
|
dec65d8 |
|
|
|
dec65d8 |
+ if (method->string == NULL) {
|
|
|
dec65d8 |
+ method->string = get_domain_from_hostname ();
|
|
|
dec65d8 |
+ }
|
|
|
dec65d8 |
+
|
|
|
dec65d8 |
if (method->string) {
|
|
|
dec65d8 |
g_strstrip (method->string);
|
|
|
dec65d8 |
if (g_str_equal (method->string, "")) {
|
|
|
dec65d8 |
@@ -210,7 +235,8 @@ on_discover_default (GObject *source,
|
|
|
dec65d8 |
on_discover_complete, method);
|
|
|
dec65d8 |
|
|
|
dec65d8 |
} else {
|
|
|
dec65d8 |
- realm_diagnostics_info (method->invocation, "No default domain received via DHCP");
|
|
|
dec65d8 |
+ realm_diagnostics_info (method->invocation,
|
|
|
dec65d8 |
+ "No default domain received via DHCP or given by hostname");
|
|
|
dec65d8 |
return_discover_result (method, NULL, 0, NULL);
|
|
|
dec65d8 |
}
|
|
|
dec65d8 |
}
|
|
|
dec65d8 |
--
|
|
|
dec65d8 |
2.17.1
|
|
|
dec65d8 |
|