From 7da5ae554c7b683ac919e40467fb4ec722e992b5 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 22 Aug 2012 15:04:00 +0200 Subject: [PATCH 1/4] Add helper to build options to pass to realmd * realm_build_options() https://bugs.freedesktop.org/show_bug.cgi?id=53934 --- tools/realm-discover.c | 2 +- tools/realm-enroll.c | 7 ++----- tools/realm-logins.c | 4 ++-- tools/realm.c | 31 +++++++++++++++++++++++++++++++ tools/realm.h | 3 +++ 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/tools/realm-discover.c b/tools/realm-discover.c index 3f1bfee..290e4c8 100644 --- a/tools/realm-discover.c +++ b/tools/realm-discover.c @@ -155,7 +155,7 @@ perform_discover (GDBusConnection *connection, sync.result = NULL; sync.loop = g_main_loop_new (NULL, FALSE); - options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + options = realm_build_options (NULL, NULL); g_variant_ref_sink (options); g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (provider), G_MAXINT); diff --git a/tools/realm-enroll.c b/tools/realm-enroll.c index 9c691fd..ed86ae0 100644 --- a/tools/realm-enroll.c +++ b/tools/realm-enroll.c @@ -383,16 +383,13 @@ realm_join_or_leave (RealmDbusKerberosMembership *membership, GVariant *options; GVariant *creds; SyncClosure sync; - GVariant *option = NULL; creds = build_ccache_or_password_creds (membership, user_name, join); sync.result = NULL; sync.loop = g_main_loop_new (NULL, FALSE); - if (computer_ou) - option = g_variant_new ("{sv}", "computer-ou", g_variant_new_string (computer_ou)); - options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), &option, option ? 1 : 0); + options = realm_build_options ("computer-ou", computer_ou, NULL); g_variant_ref_sink (options); /* Start actual operation */ @@ -449,7 +446,7 @@ perform_join (GDBusConnection *connection, return 1; } - options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + options = realm_build_options (NULL, NULL); g_variant_ref_sink (options); g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (provider), G_MAXINT); diff --git a/tools/realm-logins.c b/tools/realm-logins.c index 8b6956f..2573bff 100644 --- a/tools/realm-logins.c +++ b/tools/realm-logins.c @@ -66,7 +66,7 @@ perform_permit_or_deny_logins (GDBusConnection *connection, /* Start actual operation */ g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (realm), G_MAXINT); - options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + options = realm_build_options (NULL, NULL); g_variant_ref_sink (options); realm_dbus_realm_call_change_login_policy (realm, REALM_DBUS_LOGIN_POLICY_PERMITTED, @@ -108,7 +108,7 @@ perform_permit_or_deny_all (GDBusConnection *connection, if (realm == NULL) return 1; - options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0); + options = realm_build_options (NULL, NULL); g_variant_ref_sink (options); policy = permit ? REALM_DBUS_LOGIN_POLICY_ANY : REALM_DBUS_LOGIN_POLICY_DENY; diff --git a/tools/realm.c b/tools/realm.c index 46ff629..5bb5308 100644 --- a/tools/realm.c +++ b/tools/realm.c @@ -244,6 +244,37 @@ on_diagnostics_signal (GDBusConnection *connection, g_printerr ("%s", data); } +GVariant * +realm_build_options (const gchar *first, + ...) +{ + const gchar *value; + GPtrArray *opts; + GVariant *options; + GVariant *option; + va_list va; + + va_start (va, first); + + opts = g_ptr_array_new (); + while (first != NULL) { + value = va_arg (va, const gchar *); + if (value != NULL) { + option = g_variant_new ("{sv}", first, g_variant_new_string (value)); + g_ptr_array_add (opts, option); + } + + first = va_arg (va, const gchar *); + } + + va_end (va); + + options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), (GVariant * const*)opts->pdata, opts->len); + g_ptr_array_free (opts, TRUE); + + return options; +} + GDBusConnection * realm_get_connection (gboolean verbose) { diff --git a/tools/realm.h b/tools/realm.h index 0637204..424d7b8 100644 --- a/tools/realm.h +++ b/tools/realm.h @@ -42,6 +42,9 @@ int realm_permit (int argc, int realm_deny (int argc, char *argv[]); +GVariant * realm_build_options (const gchar *first, + ...) G_GNUC_NULL_TERMINATED; + GDBusConnection * realm_get_connection (gboolean verbose); void realm_print_error (const gchar *format, -- 1.7.11.5