From e5a14f7382f658a8b3e6349a13f1c468f2d7e3e8 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 25 Apr 2013 14:39:30 +0200 Subject: [PATCH] Add option to disable automatic package installs * Correctly report missing packages when disabled * Refactor a bit for clarity * Assume that packages are installed when in install mode https://bugs.freedesktop.org/show_bug.cgi?id=61215 --- dbus/org.freedesktop.realmd.xml | 3 -- dbus/realm-dbus-constants.h | 1 - service/realm-options.c | 9 ++---- service/realm-options.h | 2 +- service/realm-packages.c | 66 +++++++++++++++++++++++------------------ service/realm-packages.h | 1 + service/realm-samba.c | 11 +------ service/realm-sssd-ad.c | 8 +---- service/realm-sssd-ipa.c | 11 +------ service/realmd-defaults.conf | 3 ++ tools/realm.c | 5 ---- 11 files changed, 47 insertions(+), 73 deletions(-) diff --git a/dbus/org.freedesktop.realmd.xml b/dbus/org.freedesktop.realmd.xml index bacf42f..dee0895 100644 --- a/dbus/org.freedesktop.realmd.xml +++ b/dbus/org.freedesktop.realmd.xml @@ -613,9 +613,6 @@ user-principal: a string containing an kerberos user principal name to be set on the computer account - assume-packages: a boolean - which makes the join assume that all needed - software packages have already been installed membership-software: a string containing the membership software identifier that the returned realms should match. diff --git a/dbus/realm-dbus-constants.h b/dbus/realm-dbus-constants.h index 8a0220f..9c2c14d 100644 --- a/dbus/realm-dbus-constants.h +++ b/dbus/realm-dbus-constants.h @@ -62,7 +62,6 @@ G_BEGIN_DECLS #define REALM_DBUS_OPTION_SERVER_SOFTWARE "server-software" #define REALM_DBUS_OPTION_CLIENT_SOFTWARE "client-software" #define REALM_DBUS_OPTION_MEMBERSHIP_SOFTWARE "membership-software" -#define REALM_DBUS_OPTION_ASSUME_PACKAGES "assume-packages" #define REALM_DBUS_OPTION_USER_PRINCIPAL "user-principal" #define REALM_DBUS_OPTION_MANAGE_SYSTEM "manage-system" diff --git a/service/realm-options.c b/service/realm-options.c index fc28a3a..4530671 100644 --- a/service/realm-options.c +++ b/service/realm-options.c @@ -19,14 +19,9 @@ #include "realm-settings.h" gboolean -realm_options_assume_packages (GVariant *options) +realm_options_automatic_install (GVariant *options) { - gboolean assume; - - if (!g_variant_lookup (options, REALM_DBUS_OPTION_ASSUME_PACKAGES, "b", &assume)) - assume = FALSE; - - return assume; + return realm_settings_boolean ("packages", "automatic-install", TRUE); } gboolean diff --git a/service/realm-options.h b/service/realm-options.h index 090e477..c2c234a 100644 --- a/service/realm-options.h +++ b/service/realm-options.h @@ -24,7 +24,7 @@ G_BEGIN_DECLS gboolean realm_options_manage_system (GVariant *options, const gchar *realm_name); -gboolean realm_options_assume_packages (GVariant *options); +gboolean realm_options_automatic_install (GVariant *options); const gchar * realm_options_computer_ou (GVariant *options, const gchar *realm_name); diff --git a/service/realm-packages.c b/service/realm-packages.c index d09e80a..a84b54b 100644 --- a/service/realm-packages.c +++ b/service/realm-packages.c @@ -19,6 +19,7 @@ #include "realm-daemon.h" #include "realm-errors.h" #include "realm-invocation.h" +#include "realm-options.h" #include "realm-packages.h" #include "realm-settings.h" @@ -29,8 +30,9 @@ typedef struct { PkTask *task; - GHashTable *packages; + GHashTable *check; GDBusMethodInvocation *invocation; + gboolean automatic; } InstallClosure; static void @@ -39,8 +41,8 @@ install_closure_free (gpointer data) InstallClosure *install = data; g_object_ref (install->task); g_clear_object (&install->invocation); - if (install->packages) - g_hash_table_destroy (install->packages); + if (install->check) + g_hash_table_destroy (install->check); g_slice_free (InstallClosure, install); } @@ -129,56 +131,48 @@ package_names_to_list (GHashTable *packages) } static gchar ** -extract_results (PkResults *results, - GDBusMethodInvocation *invocation, - GHashTable *require, +extract_results (InstallClosure *install, + PkResults *results, + GHashTable *names, GError **error) { GPtrArray *packages; GPtrArray *messages; PkPackage *package; GPtrArray *ids; - GString *installing; const gchar *name; gchar *missing; guint i; messages = pk_results_get_message_array (results); for (i = 0; i < messages->len; i++) { - realm_diagnostics_info (invocation, "%s", + realm_diagnostics_info (install->invocation, "%s", pk_message_get_details (messages->pdata[i])); } g_ptr_array_free (messages, TRUE); packages = pk_results_get_package_array (results); ids = g_ptr_array_new_with_free_func (g_free); - installing = g_string_new (""); for (i = 0; i < packages->len; i++) { package = PK_PACKAGE (packages->pdata[i]); name = pk_package_get_name (package); - g_hash_table_remove (require, name); + g_hash_table_remove (install->check, name); if (pk_package_get_info (package) != PK_INFO_ENUM_INSTALLED) { g_ptr_array_add (ids, g_strdup (pk_package_get_id (package))); - if (installing->len) - g_string_append (installing, ", "); - g_string_append (installing, name); + g_hash_table_add (names, g_strdup (name)); } } g_ptr_array_free (packages, TRUE); - if (g_hash_table_size (require) == 0) { - if (ids->len > 0) - realm_diagnostics_info (invocation, "Installing: %s", installing->str); + if (g_hash_table_size (install->check) == 0) { g_ptr_array_add (ids, NULL); - g_string_free (installing, TRUE); return (gchar **)g_ptr_array_free (ids, FALSE); /* If not all packages were found, then this is an error */ } else { - g_string_free (installing, TRUE); - missing = package_names_to_list (require); + missing = package_names_to_list (install->check); g_set_error (error, REALM_ERROR, REALM_ERROR_INTERNAL, _("The following packages are not available for installation: %s"), missing); g_free (missing); @@ -216,15 +210,18 @@ on_install_resolved (GObject *source, EggTask *task = EGG_TASK (user_data); InstallClosure *install = egg_task_get_task_data (task); gchar **package_ids = NULL; + GHashTable *names; GCancellable *cancellable; GError *error = NULL; PkResults *results; gchar *remote; gchar *missing; + names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + results = pk_task_generic_finish (install->task, result, &error); if (error == NULL) { - package_ids = extract_results (results, install->invocation, install->packages, &error); + package_ids = extract_results (install, results, names, &error); g_object_unref (results); } @@ -232,15 +229,21 @@ on_install_resolved (GObject *source, if (package_ids == NULL || *package_ids == NULL) { egg_task_return_boolean (task, TRUE); + } else if (!install->automatic) { + missing = package_names_to_list (names); + g_set_error (&error, REALM_ERROR, REALM_ERROR_FAILED, + _("Necessary packages are not installed: %s"), missing); + g_free (missing); + } else { cancellable = realm_invocation_get_cancellable (install->invocation); pk_task_install_packages_async (install->task, package_ids, cancellable, on_install_progress, install, on_install_installed, g_object_ref (task)); } + } - - } else { + if (error != NULL) { /* * This is after our first interaction with package-kit. If it's * not installed then we'll get a standard DBus error that it @@ -257,7 +260,7 @@ on_install_resolved (GObject *source, g_dbus_error_strip_remote_error (error); realm_diagnostics_error (install->invocation, error, "PackageKit not available"); g_clear_error (&error); - missing = package_names_to_list (install->packages); + missing = package_names_to_list (install->check); g_set_error (&error, REALM_ERROR, REALM_ERROR_FAILED, _("Necessary packages are not installed: %s"), missing); g_free (missing); @@ -268,6 +271,7 @@ on_install_resolved (GObject *source, egg_task_return_error (task, error); } + g_hash_table_unref (names); g_strfreev (package_ids); g_object_unref (task); } @@ -350,6 +354,7 @@ realm_packages_expand_sets (const gchar **package_sets) void realm_packages_install_async (const gchar **package_sets, GDBusMethodInvocation *invocation, + GVariant *options, GAsyncReadyCallback callback, gpointer user_data) { @@ -370,20 +375,23 @@ realm_packages_install_async (const gchar **package_sets, task = egg_task_new (NULL, NULL, callback, user_data); install = g_slice_new0 (InstallClosure); install->task = pk_task_new (); + install->automatic = realm_options_automatic_install (options); pk_task_set_interactive (install->task, FALSE); pk_client_set_background (PK_CLIENT (install->task), FALSE); install->invocation = invocation ? g_object_ref (invocation) : NULL; egg_task_set_task_data (task, install, install_closure_free); - if (unconditional) { + if (realm_daemon_is_install_mode ()) { + have = TRUE; + realm_diagnostics_info (invocation, "Assuming packages are installed"); + + } else if (unconditional) { have = FALSE; realm_diagnostics_info (invocation, "Unconditionally checking packages"); } else { have = realm_packages_check_paths ((const gchar **)required_files, invocation); - if (required_files[0] == NULL) { - realm_diagnostics_info (invocation, "Assuming packages installed"); - } else { + if (required_files[0] != NULL) { string = g_strjoinv (", ", required_files); realm_diagnostics_info (invocation, "Required files: %s", string); g_free (string); @@ -405,9 +413,9 @@ realm_packages_install_async (const gchar **package_sets, * So we make a note of the ones we requested here, to compare against * what we get back. */ - install->packages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); + install->check = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; packages[i] != NULL; i++) - g_hash_table_add (install->packages, g_strdup (packages[i])); + g_hash_table_add (install->check, g_strdup (packages[i])); pk_task_resolve_async (install->task, pk_filter_bitfield_from_string ("arch"), diff --git a/service/realm-packages.h b/service/realm-packages.h index d6836fd..3052f5c 100644 --- a/service/realm-packages.h +++ b/service/realm-packages.h @@ -28,6 +28,7 @@ gboolean realm_packages_check_paths (const gchar **paths, void realm_packages_install_async (const gchar **package_sets, GDBusMethodInvocation *invocation, + GVariant *options, GAsyncReadyCallback callback, gpointer user_data); diff --git a/service/realm-samba.c b/service/realm-samba.c index 178b89f..6b897e8 100644 --- a/service/realm-samba.c +++ b/service/realm-samba.c @@ -59,10 +59,6 @@ static const gchar *SAMBA_PACKAGES[] = { NULL }; -const gchar *NO_PACKAGES[] = { - NULL -}; - static void realm_samba_kerberos_membership_iface (RealmKerberosMembershipIface *iface); G_DEFINE_TYPE_WITH_CODE (RealmSamba, realm_samba, REALM_TYPE_KERBEROS, @@ -265,7 +261,6 @@ realm_samba_join_async (RealmKerberosMembership *membership, RealmSamba *self = REALM_SAMBA (realm); EggTask *task; EnrollClosure *enroll; - const gchar **packages; GError *error = NULL; gchar *enrolled; @@ -287,11 +282,7 @@ realm_samba_join_async (RealmKerberosMembership *membership, egg_task_return_error (task, error); } else { - if (realm_options_assume_packages (options)) - packages = NO_PACKAGES; - else - packages = SAMBA_PACKAGES; - realm_packages_install_async (packages, enroll->invocation, + realm_packages_install_async (SAMBA_PACKAGES, enroll->invocation, options, on_install_do_join, g_object_ref (task)); } diff --git a/service/realm-sssd-ad.c b/service/realm-sssd-ad.c index 9fa67e2..5699539 100644 --- a/service/realm-sssd-ad.c +++ b/service/realm-sssd-ad.c @@ -62,10 +62,6 @@ static const gchar *ALL_PACKAGES[] = { NULL }; -static const gchar *NO_PACKAGES[] = { - NULL, -}; - static void realm_sssd_ad_kerberos_membership_iface (RealmKerberosMembershipIface *iface); G_DEFINE_TYPE_WITH_CODE (RealmSssdAd, realm_sssd_ad, REALM_TYPE_SSSD, @@ -400,9 +396,7 @@ realm_sssd_ad_join_async (RealmKerberosMembership *membership, /* Prepared successfully without an error */ } else { - if (realm_options_assume_packages (options)) - join->packages = NO_PACKAGES; - realm_packages_install_async (join->packages, join->invocation, + realm_packages_install_async (join->packages, join->invocation, options, on_install_do_join, g_object_ref (task)); } diff --git a/service/realm-sssd-ipa.c b/service/realm-sssd-ipa.c index b3df78d..b036401 100644 --- a/service/realm-sssd-ipa.c +++ b/service/realm-sssd-ipa.c @@ -44,10 +44,6 @@ typedef struct { RealmSssdClass parent_class; } RealmSssdIpaClass; -static const gchar *NO_PACKAGES[] = { - NULL, -}; - static const gchar *IPA_PACKAGES[] = { REALM_DBUS_IDENTIFIER_FREEIPA, REALM_DBUS_IDENTIFIER_SSSD, @@ -297,7 +293,6 @@ realm_sssd_ipa_join_async (RealmKerberosMembership *membership, const gchar *domain_name; const gchar *computer_ou; const gchar *software; - const gchar **packages; GPtrArray *argv; domain_name = realm_kerberos_get_name (realm); @@ -326,10 +321,6 @@ realm_sssd_ipa_join_async (RealmKerberosMembership *membership, _("A domain with this name is already configured")); } else { - packages = IPA_PACKAGES; - if (realm_options_assume_packages (options)) - packages = NO_PACKAGES; - disco = realm_kerberos_get_disco (realm); g_return_if_fail (disco != NULL); @@ -384,7 +375,7 @@ realm_sssd_ipa_join_async (RealmKerberosMembership *membership, g_ptr_array_add (argv, NULL); enroll->argv = argv; - realm_packages_install_async (packages, invocation, + realm_packages_install_async (IPA_PACKAGES, invocation, options, on_install_do_join, g_object_ref (task)); } diff --git a/service/realmd-defaults.conf b/service/realmd-defaults.conf index f020bf0..0e2da54 100644 --- a/service/realmd-defaults.conf +++ b/service/realmd-defaults.conf @@ -18,6 +18,9 @@ sssd = yes samba = yes example = no +[packages] +automatic-install = yes + [samba-packages] [winbind-packages] diff --git a/tools/realm.c b/tools/realm.c index e6d3352..fe74455 100644 --- a/tools/realm.c +++ b/tools/realm.c @@ -128,11 +128,6 @@ realm_build_options (const gchar *first, va_end (va); - if (arg_install) { - option = g_variant_new ("{sv}", "assume-packages", g_variant_new_boolean (TRUE)); - g_ptr_array_add (opts, option); - } - if (!realm_operation_id) { realm_operation_id = g_strdup_printf ("r%lld.%d", (long long int)g_get_monotonic_time () / G_TIME_SPAN_SECOND, -- 1.8.1.4