From e434d6446a9d1b56d5f56f70dd60852c50e08bb3 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 22 Aug 2012 19:13:20 +0200 Subject: [PATCH 3/3] Add a generic kerberos provider * This discovers realms that aren't either IPA or Active Directory * The resulting realms are not enrollable https://bugs.freedesktop.org/show_bug.cgi?id=53958 --- service/Makefile.am | 1 + service/realm-daemon.c | 6 ++ service/realm-kerberos-provider.c | 137 ++++++++++++++++++++++++++++++++++++++ service/realm-kerberos-provider.h | 38 +++++++++++ service/realm-kerberos.c | 11 +++ 5 files changed, 193 insertions(+) create mode 100644 service/realm-kerberos-provider.c create mode 100644 service/realm-kerberos-provider.h diff --git a/service/Makefile.am b/service/Makefile.am index 750ebfa..507b35d 100644 --- a/service/Makefile.am +++ b/service/Makefile.am @@ -29,6 +29,7 @@ realmd_SOURCES = \ realm-kerberos.c realm-kerberos.h \ realm-kerberos-discover.c realm-kerberos-discover.h \ realm-kerberos-membership.c realm-kerberos-membership.h \ + realm-kerberos-provider.c realm-kerberos-provider.h \ realm-login-name.c realm-login-name.h \ realm-network.c realm-network.h \ realm-packages.c realm-packages.h \ diff --git a/service/realm-daemon.c b/service/realm-daemon.c index 029cdaf..7da4bcf 100644 --- a/service/realm-daemon.c +++ b/service/realm-daemon.c @@ -22,6 +22,7 @@ #include "realm-debug.h" #include "realm-diagnostics.h" #include "realm-errors.h" +#include "realm-kerberos-provider.h" #include "realm-samba-provider.h" #include "realm-settings.h" #include "realm-sssd-ad-provider.h" @@ -427,6 +428,11 @@ on_bus_get_connection (GObject *source, realm_all_provider_register (all_provider, provider); g_object_unref (provider); + provider = realm_kerberos_provider_new (); + g_dbus_object_manager_server_export (object_server, G_DBUS_OBJECT_SKELETON (provider)); + realm_all_provider_register (all_provider, provider); + g_object_unref (provider); + g_dbus_object_manager_server_set_connection (object_server, connection); owner_id = g_bus_own_name_on_connection (connection, diff --git a/service/realm-kerberos-provider.c b/service/realm-kerberos-provider.c new file mode 100644 index 0000000..2fdc71b --- /dev/null +++ b/service/realm-kerberos-provider.c @@ -0,0 +1,137 @@ +/* realmd -- Realm configuration service + * + * Copyright 2012 Red Hat Inc + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2 of the licence or (at + * your option) any later version. + * + * See the included COPYING file for more information. + * + * Author: Stef Walter + */ + +#include "config.h" + +#include "realm-dbus-constants.h" +#include "realm-discovery.h" +#include "realm-kerberos-discover.h" +#include "realm-kerberos-provider.h" + +#include + +struct _RealmKerberosProvider { + RealmProvider parent; +}; + +typedef struct { + RealmProviderClass parent_class; +} RealmKerberosProviderClass; + +#define REALM_DBUS_GENERIC_KERBEROS_PATH "/org/freedesktop/realmd/GenericKerberos" + +G_DEFINE_TYPE (RealmKerberosProvider, realm_kerberos_provider, REALM_TYPE_PROVIDER); + +static void +realm_kerberos_provider_init (RealmKerberosProvider *self) +{ + +} + +static void +on_kerberos_discover (GObject *source, + GAsyncResult *result, + gpointer user_data) +{ + GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data); + g_simple_async_result_set_op_res_gpointer (async, g_object_ref (result), g_object_unref); + g_simple_async_result_complete (async); + g_object_unref (async); +} + +static void +realm_kerberos_provider_discover_async (RealmProvider *provider, + const gchar *string, + GVariant *options, + GDBusMethodInvocation *invocation, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GSimpleAsyncResult *async; + const gchar *software; + + async = g_simple_async_result_new (G_OBJECT (provider), callback, user_data, + realm_kerberos_provider_discover_async); + + /* If filtering for specific software, don't return anything */ + if (g_variant_lookup (options, REALM_DBUS_OPTION_SERVER_SOFTWARE, "&s", &software) || + g_variant_lookup (options, REALM_DBUS_OPTION_CLIENT_SOFTWARE, "&s", &software)) { + g_simple_async_result_complete_in_idle (async); + + } else { + realm_kerberos_discover_async (string, invocation, on_kerberos_discover, + g_object_ref (async)); + } + + g_object_unref (async); +} + +static gint +realm_kerberos_provider_discover_finish (RealmProvider *provider, + GAsyncResult *result, + GVariant **realms, + GError **error) +{ + RealmKerberos *realm = NULL; + GSimpleAsyncResult *async; + GHashTable *discovery; + GAsyncResult *kerberos_result; + const gchar *object_path; + gchar *name; + + async = G_SIMPLE_ASYNC_RESULT (result); + kerberos_result = g_simple_async_result_get_op_res_gpointer (async); + if (kerberos_result == NULL) + return 0; + + name = realm_kerberos_discover_finish (kerberos_result, &discovery, error); + if (name == NULL) + return 0; + + /* If any known software, don't create the realm */ + if (!realm_discovery_get_string (discovery, REALM_DBUS_OPTION_SERVER_SOFTWARE)) { + realm = realm_provider_lookup_or_register_realm (provider, + REALM_TYPE_KERBEROS, + name, discovery); + } + + g_free (name); + g_hash_table_unref (discovery); + + if (realm == NULL) + return 0; + + object_path = g_dbus_object_get_object_path (G_DBUS_OBJECT (realm)); + *realms = g_variant_new_objv (&object_path, 1); + g_variant_ref_sink (*realms); + + /* Return a low priority as we can't handle enrollment */ + return 10; +} + +void +realm_kerberos_provider_class_init (RealmKerberosProviderClass *klass) +{ + RealmProviderClass *provider_class = REALM_PROVIDER_CLASS (klass); + provider_class->discover_async = realm_kerberos_provider_discover_async; + provider_class->discover_finish = realm_kerberos_provider_discover_finish; +} + +RealmProvider * +realm_kerberos_provider_new (void) +{ + return g_object_new (REALM_TYPE_KERBEROS_PROVIDER, + "g-object-path", REALM_DBUS_GENERIC_KERBEROS_PATH, + NULL); +} diff --git a/service/realm-kerberos-provider.h b/service/realm-kerberos-provider.h new file mode 100644 index 0000000..1a28ae1 --- /dev/null +++ b/service/realm-kerberos-provider.h @@ -0,0 +1,38 @@ +/* realmd -- Realm configuration service + * + * Copyright 2012 Red Hat Inc + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2 of the licence or (at + * your option) any later version. + * + * See the included COPYING file for more information. + * + * Author: Stef Walter + */ + +#include "config.h" + +#ifndef __REALM_KERBEROS_PROVIDER_H__ +#define __REALM_KERBEROS_PROVIDER_H__ + +#include + +#include "realm-provider.h" + +G_BEGIN_DECLS + +#define REALM_TYPE_KERBEROS_PROVIDER (realm_kerberos_provider_get_type ()) +#define REALM_KERBEROS_PROVIDER(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), REALM_TYPE_KERBEROS_PROVIDER, RealmKerberosProvider)) +#define REALM_IS_KERBEROS_PROVIDER(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), REALM_TYPE_KERBEROS_PROVIDER)) + +typedef struct _RealmKerberosProvider RealmKerberosProvider; + +GType realm_kerberos_provider_get_type (void) G_GNUC_CONST; + +RealmProvider * realm_kerberos_provider_new (void); + +G_END_DECLS + +#endif /* __REALM_KERBEROS_PROVIDER_H__ */ diff --git a/service/realm-kerberos.c b/service/realm-kerberos.c index 0969210..7db4465 100644 --- a/service/realm-kerberos.c +++ b/service/realm-kerberos.c @@ -20,6 +20,7 @@ #include "realm-dbus-constants.h" #include "realm-dbus-generated.h" #include "realm-diagnostics.h" +#include "realm-discovery.h" #include "realm-errors.h" #include "realm-kerberos.h" #include "realm-kerberos-membership.h" @@ -595,6 +596,7 @@ realm_kerberos_constructed (GObject *obj) { RealmKerberos *self = REALM_KERBEROS (obj); const gchar *supported_interfaces[3]; + const gchar *name; G_OBJECT_CLASS (realm_kerberos_parent_class)->constructed (obj); @@ -617,6 +619,15 @@ realm_kerberos_constructed (GObject *obj) realm_dbus_realm_set_supported_interfaces (self->pv->realm_iface, supported_interfaces); + + if (self->pv->discovery) { + name = realm_discovery_get_string (self->pv->discovery, REALM_DBUS_DISCOVERY_DOMAIN); + if (name) + realm_kerberos_set_domain_name (self, name); + name = realm_discovery_get_string (self->pv->discovery, REALM_DBUS_DISCOVERY_REALM); + if (name) + realm_kerberos_set_realm_name (self, name); + } } static void -- 1.7.12