From ac817b590b0ba09314887d28b7312f8e300b2ffb Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 22 Aug 2012 16:08:33 +0200 Subject: [PATCH 4/4] Add support for choosing client and server software * New 'realm discover' options --client-software and --server-software * Same options for 'realm join' * These options limit the discovery results to the relevant client and server software listed in the realm Details property. https://bugs.freedesktop.org/show_bug.cgi?id=53934 --- dbus/org.freedesktop.realmd.xml | 6 ++++++ service/realm-provider.c | 23 +++++++++++++++++++++++ service/realm-provider.h | 4 ++++ service/realm-samba-provider.c | 12 +++++++++++- service/realm-sssd-ad-provider.c | 21 ++++++++++++++++----- service/realm-sssd-ipa-provider.c | 12 +++++++++++- tools/realm-discover.c | 20 ++++++++++++++++---- tools/realm-enroll.c | 17 ++++++++++++++--- 8 files changed, 101 insertions(+), 14 deletions(-) diff --git a/dbus/org.freedesktop.realmd.xml b/dbus/org.freedesktop.realmd.xml index d8fc288..a146980 100644 --- a/dbus/org.freedesktop.realmd.xml +++ b/dbus/org.freedesktop.realmd.xml @@ -62,6 +62,12 @@ identifier chosen by the client, which can then later be passed to org.freedesktop.realmd.Service.Cancel() in order to cancel the operation + client-software: a string + containing the client software identifier that the returned + realms should match. + server-software: a string + containing the client software identifier that the returned + realms should match. The @relevance returned can be used to rank results from diff --git a/service/realm-provider.c b/service/realm-provider.c index 2ad9f2c..adaf641 100644 --- a/service/realm-provider.c +++ b/service/realm-provider.c @@ -342,3 +342,26 @@ realm_provider_discover_finish (RealmProvider *self, return relevance; } + +gboolean +realm_provider_match_options (GVariant *options, + const gchar *server_software, + const gchar *client_software) +{ + const gchar *string; + + g_return_val_if_fail (server_software != NULL, FALSE); + g_return_val_if_fail (client_software != NULL, FALSE); + + if (g_variant_lookup (options, REALM_DBUS_OPTION_SERVER_SOFTWARE, "&s", &string)) { + if (!g_str_equal (server_software, string)) + return FALSE; + } + + if (g_variant_lookup (options, REALM_DBUS_OPTION_CLIENT_SOFTWARE, "&s", &string)) { + if (!g_str_equal (client_software, string)) + return FALSE; + } + + return TRUE; +} diff --git a/service/realm-provider.h b/service/realm-provider.h index 556d4f4..6d51aee 100644 --- a/service/realm-provider.h +++ b/service/realm-provider.h @@ -91,6 +91,10 @@ const gchar ** realm_provider_get_realms (RealmProvider void realm_provider_set_realms (RealmProvider *self, const gchar **value); +gboolean realm_provider_match_options (GVariant *options, + const gchar *server_software, + const gchar *client_software); + G_END_DECLS #endif /* __REALM_KERBEROS_PROVIDER_H__ */ diff --git a/service/realm-samba-provider.c b/service/realm-samba-provider.c index d850931..852ba5d 100644 --- a/service/realm-samba-provider.c +++ b/service/realm-samba-provider.c @@ -107,7 +107,15 @@ realm_samba_provider_discover_async (RealmProvider *provider, async = g_simple_async_result_new (G_OBJECT (provider), callback, user_data, realm_samba_provider_discover_async); - realm_ad_discover_async (string, invocation, on_ad_discover, g_object_ref (async)); + if (!realm_provider_match_options (options, + REALM_DBUS_IDENTIFIER_ACTIVE_DIRECTORY, + REALM_DBUS_IDENTIFIER_WINBIND)) { + g_simple_async_result_complete_in_idle (async); + + } else { + realm_ad_discover_async (string, invocation, on_ad_discover, + g_object_ref (async)); + } g_object_unref (async); } @@ -127,6 +135,8 @@ realm_samba_provider_discover_finish (RealmProvider *provider, async = G_SIMPLE_ASYNC_RESULT (result); ad_result = g_simple_async_result_get_op_res_gpointer (async); + if (ad_result == NULL) + return 0; name = realm_ad_discover_finish (ad_result, &discovery, error); if (name == NULL) diff --git a/service/realm-sssd-ad-provider.c b/service/realm-sssd-ad-provider.c index cfd30a5..ba0789d 100644 --- a/service/realm-sssd-ad-provider.c +++ b/service/realm-sssd-ad-provider.c @@ -103,17 +103,26 @@ on_ad_discover (GObject *source, static void realm_sssd_ad_provider_discover_async (RealmProvider *provider, - const gchar *string, - GDBusMethodInvocation *invocation, - GAsyncReadyCallback callback, - gpointer user_data) + const gchar *string, + GVariant *options, + GDBusMethodInvocation *invocation, + GAsyncReadyCallback callback, + gpointer user_data) { GSimpleAsyncResult *async; async = g_simple_async_result_new (G_OBJECT (provider), callback, user_data, realm_sssd_ad_provider_discover_async); - realm_ad_discover_async (string, invocation, on_ad_discover, g_object_ref (async)); + if (!realm_provider_match_options (options, + REALM_DBUS_IDENTIFIER_ACTIVE_DIRECTORY, + REALM_DBUS_IDENTIFIER_SSSD)) { + g_simple_async_result_complete_in_idle (async); + + } else { + realm_ad_discover_async (string, invocation, on_ad_discover, + g_object_ref (async)); + } g_object_unref (async); } @@ -133,6 +142,8 @@ realm_sssd_ad_provider_discover_finish (RealmProvider *provider, async = G_SIMPLE_ASYNC_RESULT (result); ad_result = g_simple_async_result_get_op_res_gpointer (async); + if (ad_result == NULL) + return 0; name = realm_ad_discover_finish (ad_result, &discovery, error); if (name == NULL) diff --git a/service/realm-sssd-ipa-provider.c b/service/realm-sssd-ipa-provider.c index 62e4ee8..4bf87a5 100644 --- a/service/realm-sssd-ipa-provider.c +++ b/service/realm-sssd-ipa-provider.c @@ -114,7 +114,15 @@ realm_sssd_ipa_provider_discover_async (RealmProvider *provider, async = g_simple_async_result_new (G_OBJECT (provider), callback, user_data, realm_sssd_ipa_provider_discover_async); - realm_ipa_discover_async (string, invocation, on_ipa_discover, g_object_ref (async)); + if (!realm_provider_match_options (options, + REALM_DBUS_IDENTIFIER_FREEIPA, + REALM_DBUS_IDENTIFIER_SSSD)) { + g_simple_async_result_complete_in_idle (async); + + } else { + realm_ipa_discover_async (string, invocation, on_ipa_discover, + g_object_ref (async)); + } g_object_unref (async); @@ -135,6 +143,8 @@ realm_sssd_ipa_provider_discover_finish (RealmProvider *provider, async = G_SIMPLE_ASYNC_RESULT (result); ipa_result = g_simple_async_result_get_op_res_gpointer (async); + if (ipa_result == NULL) + return 0; name = realm_ipa_discover_finish (ipa_result, &discovery, error); if (name == NULL) diff --git a/tools/realm-discover.c b/tools/realm-discover.c index 290e4c8..8cb901d 100644 --- a/tools/realm-discover.c +++ b/tools/realm-discover.c @@ -131,7 +131,9 @@ on_complete_get_result (GObject *source, static int perform_discover (GDBusConnection *connection, - const gchar *string) + const gchar *string, + const gchar *server_software, + const gchar *client_software) { RealmDbusProvider *provider; gboolean found = FALSE; @@ -155,7 +157,9 @@ perform_discover (GDBusConnection *connection, sync.result = NULL; sync.loop = g_main_loop_new (NULL, FALSE); - options = realm_build_options (NULL, NULL); + options = realm_build_options (REALM_DBUS_OPTION_CLIENT_SOFTWARE, client_software, + REALM_DBUS_OPTION_SERVER_SOFTWARE, server_software, + NULL); g_variant_ref_sink (options); g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (provider), G_MAXINT); @@ -203,6 +207,8 @@ realm_discover (int argc, GDBusConnection *connection; GOptionContext *context; gboolean arg_verbose = FALSE; + gchar *arg_client_software = NULL; + gchar *arg_server_software = NULL; GError *error = NULL; gint result = 0; gint ret; @@ -210,6 +216,8 @@ realm_discover (int argc, GOptionEntry option_entries[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &arg_verbose, N_("Verbose output"), NULL }, + { "client-software", 0, 0, G_OPTION_ARG_STRING, &arg_client_software, N_("Use specific client software"), NULL }, + { "server-software", 0, 0, G_OPTION_ARG_STRING, &arg_server_software, N_("Use specific server software"), NULL }, { NULL, } }; @@ -231,19 +239,23 @@ realm_discover (int argc, /* The default realm? */ } else if (argc == 1) { - ret = perform_discover (connection, NULL); + ret = perform_discover (connection, NULL, + arg_server_software, arg_client_software); g_object_unref (connection); /* Specific realms */ } else { for (i = 1; i < argc; i++) { - ret = perform_discover (connection, argv[i]); + ret = perform_discover (connection, argv[i], + arg_server_software, arg_client_software); if (ret != 0) result = ret; } g_object_unref (connection); } + g_free (arg_server_software); + g_free (arg_client_software); g_option_context_free (context); return result; } diff --git a/tools/realm-enroll.c b/tools/realm-enroll.c index b1a680d..f73c0aa 100644 --- a/tools/realm-enroll.c +++ b/tools/realm-enroll.c @@ -427,7 +427,9 @@ static int perform_join (GDBusConnection *connection, const gchar *string, const gchar *user_name, - const gchar *computer_ou) + const gchar *computer_ou, + const gchar *client_software, + const gchar *server_software) { RealmDbusKerberosMembership *membership; RealmDbusProvider *provider; @@ -446,7 +448,9 @@ perform_join (GDBusConnection *connection, return 1; } - options = realm_build_options (NULL, NULL); + options = realm_build_options (REALM_DBUS_OPTION_CLIENT_SOFTWARE, client_software, + REALM_DBUS_OPTION_SERVER_SOFTWARE, server_software, + NULL); g_variant_ref_sink (options); g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (provider), G_MAXINT); @@ -517,12 +521,16 @@ realm_join (int argc, GError *error = NULL; const gchar *realm_name; gchar *arg_computer_ou = NULL; + gchar *arg_client_software = NULL; + gchar *arg_server_software = NULL; gint ret = 0; GOptionEntry option_entries[] = { { "user", 'U', 0, G_OPTION_ARG_STRING, &arg_user, N_("User name to use for enrollment"), NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &arg_verbose, N_("Verbose output"), NULL }, { "computer-ou", 0, 0, G_OPTION_ARG_STRING, &arg_computer_ou, N_("Computer OU DN to join"), NULL }, + { "client-software", 0, 0, G_OPTION_ARG_STRING, &arg_client_software, N_("Use specific client software"), NULL }, + { "server-software", 0, 0, G_OPTION_ARG_STRING, &arg_server_software, N_("Use specific server software"), NULL }, { NULL, } }; @@ -544,7 +552,8 @@ realm_join (int argc, if (connection) { realm_name = argc < 2 ? "" : argv[1]; ret = perform_join (connection, realm_name, arg_user, - arg_computer_ou); + arg_computer_ou, arg_client_software, + arg_server_software); g_object_unref (connection); } else { ret = 1; @@ -553,6 +562,8 @@ realm_join (int argc, g_free (arg_user); g_free (arg_computer_ou); + g_free (arg_client_software); + g_free (arg_server_software); g_option_context_free (context); return ret; } -- 1.7.11.5