From 406b7c2db9928c08c20316a3d1129e607844a30d 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-adcli-enroll.c | 2 +- service/realm-daemon.c | 6 +++--- service/realm-example.c | 2 +- service/realm-samba-enroll.c | 2 +- service/realm-settings.c | 9 ++++----- service/realm-settings.h | 3 ++- tests/test-settings.c | 10 ++++++++-- 7 files changed, 20 insertions(+), 14 deletions(-) diff --git a/service/realm-adcli-enroll.c b/service/realm-adcli-enroll.c index f788d4b..c6ef3b8 100644 --- a/service/realm-adcli-enroll.c +++ b/service/realm-adcli-enroll.c @@ -150,7 +150,7 @@ realm_adcli_enroll_join_async (const gchar *realm, } upn = realm_options_user_principal (options); - if (upn || realm_settings_boolean ("active-directory", "user-principal")) { + if (upn || realm_settings_boolean ("active-directory", "user-principal", FALSE)) { if (upn && !g_str_equal (upn, "")) { upn_arg = g_strdup_printf ("--user-principal=%s", upn); g_ptr_array_add (args, upn_arg); 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-samba-enroll.c b/service/realm-samba-enroll.c index ea4dafa..6351b62 100644 --- a/service/realm-samba-enroll.c +++ b/service/realm-samba-enroll.c @@ -444,7 +444,7 @@ begin_join (GSimpleAsyncResult *async, join->join_args[at++] = g_strdup_printf ("osVer=%s", os); upn = realm_options_user_principal (options); - if (upn || realm_settings_boolean ("active-directory", "user-principal")) { + if (upn || realm_settings_boolean ("active-directory", "user-principal", FALSE)) { if (upn && g_str_equal (upn, "")) upn = NULL; join->join_args[at++] = g_strdup_printf ("createupn%s%s", 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