From 4dcace083a219b76548758155290b61f41061517 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 12 Apr 2013 15:27:35 +0200 Subject: [PATCH] Make realm_settings_boolean() accept a default value We're using these settings for a lot of admin configurable stuff and we can't expect per-realm defaults to be present in the installed files, so specify them in the code. https://bugs.freedesktop.org/show_bug.cgi?id=60679 --- service/realm-daemon.c | 6 +++--- service/realm-example.c | 2 +- service/realm-options.c | 3 +-- service/realm-settings.c | 9 ++++----- service/realm-settings.h | 3 ++- tests/test-settings.c | 10 ++++++++-- 6 files changed, 19 insertions(+), 14 deletions(-) diff --git a/service/realm-daemon.c b/service/realm-daemon.c index 1ba63dc..73621d6 100644 --- a/service/realm-daemon.c +++ b/service/realm-daemon.c @@ -173,14 +173,14 @@ initialize_service (GDBusConnection *connection) all_provider = realm_all_provider_new_and_export (connection); - if (realm_settings_boolean ("providers", REALM_DBUS_IDENTIFIER_SSSD)) { + if (realm_settings_boolean ("providers", REALM_DBUS_IDENTIFIER_SSSD, TRUE)) { provider = realm_sssd_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); } - if (realm_settings_boolean ("providers", REALM_DBUS_IDENTIFIER_SAMBA)) { + if (realm_settings_boolean ("providers", REALM_DBUS_IDENTIFIER_SAMBA, TRUE)) { provider = realm_samba_provider_new (); g_dbus_object_manager_server_export (object_server, G_DBUS_OBJECT_SKELETON (provider)); realm_all_provider_register (all_provider, provider); @@ -196,7 +196,7 @@ initialize_service (GDBusConnection *connection) realm_all_provider_register (all_provider, provider); g_object_unref (provider); - if (realm_settings_boolean ("providers", REALM_DBUS_IDENTIFIER_EXAMPLE)) { + if (realm_settings_boolean ("providers", REALM_DBUS_IDENTIFIER_EXAMPLE, FALSE)) { provider = realm_example_provider_new (); g_dbus_object_manager_server_export (object_server, G_DBUS_OBJECT_SKELETON (provider)); realm_all_provider_register (all_provider, provider); diff --git a/service/realm-example.c b/service/realm-example.c index a30b6e3..1ddbdee 100644 --- a/service/realm-example.c +++ b/service/realm-example.c @@ -308,7 +308,7 @@ realm_example_leave_automatic_async (RealmKerberosMembership *membership, realm_name = realm_kerberos_get_name (REALM_KERBEROS (self)); - if (realm_settings_boolean (realm_name, "example-no-auto-leave") == TRUE) { + if (realm_settings_boolean (realm_name, "example-no-auto-leave", FALSE) == TRUE) { g_simple_async_result_set_error (async, REALM_ERROR, REALM_ERROR_AUTH_FAILED, _("Need credentials for leaving this domain")); g_simple_async_result_complete_in_idle (async); diff --git a/service/realm-options.c b/service/realm-options.c index 0463029..fe75c0b 100644 --- a/service/realm-options.c +++ b/service/realm-options.c @@ -41,8 +41,7 @@ realm_options_user_principal (GVariant *options, if (!principal) { section = g_utf8_casefold (realm_name, -1); - if (realm_settings_value (section, REALM_DBUS_OPTION_USER_PRINCIPAL) && - realm_settings_boolean (section, REALM_DBUS_OPTION_USER_PRINCIPAL)) + if (realm_settings_boolean (section, REALM_DBUS_OPTION_USER_PRINCIPAL, FALSE)) principal = ""; /* auto-generate */ g_free (section); } diff --git a/service/realm-settings.c b/service/realm-settings.c index 6d5ad1b..cb346ff 100644 --- a/service/realm-settings.c +++ b/service/realm-settings.c @@ -206,15 +206,14 @@ realm_settings_double (const gchar *section, gboolean realm_settings_boolean (const gchar *section, - const gchar *key) + const gchar *key, + gboolean def) { const gchar *string; string = realm_settings_value (section, key); - if (string == NULL) { - g_warning ("no value found for '%s/%s' in realmd config", section, key); - return FALSE; - } + if (string == NULL) + return def; return g_ascii_strcasecmp (string, "true") == 0 || g_ascii_strcasecmp (string, "1") == 0 || diff --git a/service/realm-settings.h b/service/realm-settings.h index 9bd14ce..287614c 100644 --- a/service/realm-settings.h +++ b/service/realm-settings.h @@ -47,7 +47,8 @@ gdouble realm_settings_double (const gchar *section, gdouble def); gboolean realm_settings_boolean (const gchar *section, - const gchar *key); + const gchar *key, + gboolean def); G_END_DECLS diff --git a/tests/test-settings.c b/tests/test-settings.c index a16d377..c2b3c76 100644 --- a/tests/test-settings.c +++ b/tests/test-settings.c @@ -99,11 +99,11 @@ test_boolean (Test *test, "false-4 = nope\n"); #define ASSERT_TRUE(n) \ - value = realm_settings_boolean ("one", n); \ + value = realm_settings_boolean ("one", n, FALSE); \ g_assert_cmpint (value, ==, TRUE); #define ASSERT_FALSE(n) \ - value = realm_settings_boolean ("one", n); \ + value = realm_settings_boolean ("one", n, TRUE); \ g_assert_cmpint (value, ==, FALSE); realm_settings_init (); @@ -116,6 +116,12 @@ test_boolean (Test *test, ASSERT_FALSE("false-2"); ASSERT_FALSE("false-3"); ASSERT_FALSE("false-4"); + + value = realm_settings_boolean ("one", "invalid", TRUE); + g_assert_cmpint (value, ==, TRUE); + value = realm_settings_boolean ("one", "invalid", FALSE); + g_assert_cmpint (value, ==, FALSE); + realm_settings_uninit (); } -- 1.8.1.4