From ad56d6f92bb19bdb53d8712a484bb943c1412f73 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 12 Apr 2013 15:37:41 +0200 Subject: [PATCH] Make realm_ini_config_set() accept more than one agrument pair This cleans up code a lot, and gives us a syntax similar to realm_ini_config_change(). https://bugs.freedesktop.org/show_bug.cgi?id=60679 --- service/realm-example.c | 2 +- service/realm-ini-config.c | 17 ++++++++++++++--- service/realm-ini-config.h | 3 ++- service/realm-samba-enroll.c | 14 +++++++++----- service/realm-sssd-config.c | 8 +++++--- service/realm-sssd.c | 6 +++--- tests/test-ini-config.c | 14 +++++++------- 7 files changed, 41 insertions(+), 23 deletions(-) diff --git a/service/realm-example.c b/service/realm-example.c index 1ddbdee..8a83e6b 100644 --- a/service/realm-example.c +++ b/service/realm-example.c @@ -367,7 +367,7 @@ realm_example_logins_async (RealmKerberos *realm, if (realm_ini_config_begin_change (self->config, &error)) { realm_ini_config_set (self->config, name, "login-policy", - realm_kerberos_login_policy_to_string (login_policy)); + realm_kerberos_login_policy_to_string (login_policy), NULL); realm_ini_config_set_list_diff (self->config, name, "login-permitted", ", ", add, remove); realm_ini_config_finish_change (self->config, &error); diff --git a/service/realm-ini-config.c b/service/realm-ini-config.c index 755c606..4661190 100644 --- a/service/realm-ini-config.c +++ b/service/realm-ini-config.c @@ -836,12 +836,23 @@ void realm_ini_config_set (RealmIniConfig *self, const gchar *section, const gchar *name, - const gchar *value) + const gchar *value, + ...) { + va_list va; + g_return_if_fail (REALM_IS_INI_CONFIG (self)); g_return_if_fail (section != NULL); - config_set_value (self, section, name, value); + va_start (va, value); + while (name != NULL) { + config_set_value (self, section, name, value); + name = va_arg (va, const gchar *); + if (name != NULL) + value = va_arg (va, const gchar *); + } + va_end (va); + if (!self->changing) g_signal_emit (self, signals[CHANGED], 0); } @@ -958,7 +969,7 @@ realm_ini_config_set_list (RealmIniConfig *self, g_return_if_fail (delimiter != NULL); value = g_strjoinv (delimiter, (gchar **)values); - realm_ini_config_set (self, section, name, value); + realm_ini_config_set (self, section, name, value, NULL); g_free (value); } diff --git a/service/realm-ini-config.h b/service/realm-ini-config.h index e3c9a9d..13d2fef 100644 --- a/service/realm-ini-config.h +++ b/service/realm-ini-config.h @@ -78,7 +78,8 @@ gboolean realm_ini_config_write_fd (RealmIniConfig *s void realm_ini_config_set (RealmIniConfig *self, const gchar *section, const gchar *name, - const gchar *value); + const gchar *value, + ...) G_GNUC_NULL_TERMINATED; gchar * realm_ini_config_get (RealmIniConfig *self, const gchar *section, diff --git a/service/realm-samba-enroll.c b/service/realm-samba-enroll.c index 6351b62..dd55b52 100644 --- a/service/realm-samba-enroll.c +++ b/service/realm-samba-enroll.c @@ -86,9 +86,11 @@ join_closure_init (GSimpleAsyncResult *async, g_simple_async_result_set_op_res_gpointer (async, join, join_closure_free); join->config = realm_ini_config_new (REALM_INI_NO_WATCH | REALM_INI_PRIVATE); - realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, "security", "ads"); - realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, "kerberos method", "system keytab"); - realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, "realm", join->realm); + realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, + "security", "ads", + "kerberos method", "system keytab", + "realm", join->realm, + NULL); /* Write out the config file for use by various net commands */ join->custom_smb_conf = g_build_filename (g_get_tmp_dir (), "realmd-smb-conf.XXXXXX", NULL); @@ -270,7 +272,8 @@ begin_config_and_join (JoinClosure *join, if (workgroup == NULL) { workgroup = fallback_workgroup (join->realm); realm_diagnostics_info (join->invocation, "Calculated workgroup name: %s", workgroup); - realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, "workgroup", workgroup); + realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, + "workgroup", workgroup, NULL); } free (workgroup); @@ -348,7 +351,8 @@ on_net_ads_workgroup (GObject *source, workgroup = find_workgroup_in_output (output); if (workgroup) { realm_diagnostics_info (join->invocation, "Looked up workgroup name: %s", workgroup); - realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, "workgroup", workgroup); + realm_ini_config_set (join->config, REALM_SAMBA_CONFIG_GLOBAL, + "workgroup", workgroup, NULL); g_free (workgroup); } diff --git a/service/realm-sssd-config.c b/service/realm-sssd-config.c index 68bd212..b3ad8d3 100644 --- a/service/realm-sssd-config.c +++ b/service/realm-sssd-config.c @@ -112,7 +112,7 @@ update_domain (RealmIniConfig *config, shell = realm_ini_config_get (config, "nss", "default_shell"); if (shell == NULL) { realm_ini_config_set (config, "nss", "default_shell", - realm_settings_string ("users", "default-shell")); + realm_settings_string ("users", "default-shell"), NULL); } g_free (shell); @@ -158,8 +158,10 @@ realm_sssd_config_add_domain (RealmIniConfig *config, /* Setup a default sssd section */ if (!realm_ini_config_have_section (config, "sssd")) { - realm_ini_config_set (config, "sssd", "services", "nss, pam"); - realm_ini_config_set (config, "sssd", "config_file_version", "2"); + realm_ini_config_set (config, "sssd", + "services", "nss, pam", + "config_file_version", "2", + NULL); } domains[0] = domain; diff --git a/service/realm-sssd.c b/service/realm-sssd.c index 7427c02..aaea8ee 100644 --- a/service/realm-sssd.c +++ b/service/realm-sssd.c @@ -85,7 +85,7 @@ sssd_config_change_login_policy (RealmIniConfig *config, return FALSE; if (access_provider) - realm_ini_config_set (config, section, "access_provider", access_provider); + realm_ini_config_set (config, section, "access_provider", access_provider, NULL); realm_ini_config_set_list_diff (config, section, "simple_allow_users", ",", add_names, remove_names); @@ -104,9 +104,9 @@ sssd_config_change_login_policy (RealmIniConfig *config, if (allow == NULL) { if (g_str_equal (access_provider, "simple")) - realm_ini_config_set (config, section, "simple_allow_users", "$"); + realm_ini_config_set (config, section, "simple_allow_users", "$", NULL); else - realm_ini_config_set (config, section, "simple_allow_users", NULL); + realm_ini_config_set (config, section, "simple_allow_users", NULL, NULL); } g_free (allow); diff --git a/tests/test-ini-config.c b/tests/test-ini-config.c index 2e418a4..bbdd21b 100644 --- a/tests/test-ini-config.c +++ b/tests/test-ini-config.c @@ -300,9 +300,9 @@ test_set (Test *test, g_signal_connect (test->config, "changed", G_CALLBACK (on_config_changed), &changed); - realm_ini_config_set (test->config, "section", "1", "the number one"); - realm_ini_config_set (test->config, "section", "3", NULL); - realm_ini_config_set (test->config, "section", "4", "four"); + realm_ini_config_set (test->config, "section", "1", "the number one", NULL); + realm_ini_config_set (test->config, "section", "3", NULL, + "4", "four", NULL); g_assert (changed == TRUE); @@ -321,7 +321,7 @@ test_set_middle (Test *test, realm_ini_config_read_string (test->config, data); - realm_ini_config_set (test->config, "section", "3", "three"); + realm_ini_config_set (test->config, "section", "3", "three", NULL); output = realm_ini_config_write_string (test->config); g_assert_cmpstr (check, ==, output); @@ -337,7 +337,7 @@ test_set_and_get (Test *test, realm_ini_config_read_string (test->config, data); - realm_ini_config_set (test->config, "section", "3", "three"); + realm_ini_config_set (test->config, "section", "3", "three", NULL); output = realm_ini_config_get (test->config, "section", "3"); g_assert_cmpstr (output, ==, "three"); @@ -354,8 +354,8 @@ test_set_section (Test *test, realm_ini_config_read_string (test->config, data); - realm_ini_config_set (test->config, "happy", "4", "four"); - realm_ini_config_set (test->config, "nope", "6", NULL); + realm_ini_config_set (test->config, "happy", "4", "four", NULL); + realm_ini_config_set (test->config, "nope", "6", NULL, NULL); output = realm_ini_config_write_string (test->config); g_assert_cmpstr (check, ==, output); -- 1.8.1.4