summaryrefslogtreecommitdiff
path: root/mate-session/gsm-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'mate-session/gsm-util.c')
-rw-r--r--mate-session/gsm-util.c123
1 files changed, 94 insertions, 29 deletions
diff --git a/mate-session/gsm-util.c b/mate-session/gsm-util.c
index 6320b24..b026f12 100644
--- a/mate-session/gsm-util.c
+++ b/mate-session/gsm-util.c
@@ -435,54 +435,119 @@ gsm_util_update_activation_environment (const char *variable,
const char *value,
GError **error)
{
- DBusGConnection *dbus_connection;
- DBusGProxy *bus_proxy;
- GHashTable *environment;
+ GDBusConnection *connection;
gboolean environment_updated;
+ GVariantBuilder builder;
+ GVariant *reply;
+ GError *bus_error = NULL;
environment_updated = FALSE;
- bus_proxy = NULL;
- environment = NULL;
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
- dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+ if (connection == NULL) {
+ return FALSE;
+ }
+
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+ g_variant_builder_add (&builder, "{ss}", variable, value);
+
+ reply = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "UpdateActivationEnvironment",
+ g_variant_new ("(@a{ss})",
+ g_variant_builder_end (&builder)),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &bus_error);
+
+ if (bus_error != NULL) {
+ g_propagate_error (error, bus_error);
+ } else {
+ environment_updated = TRUE;
+ g_variant_unref (reply);
+ }
- if (dbus_connection == NULL) {
+ g_clear_object (&connection);
+
+ return environment_updated;
+}
+
+gboolean
+gsm_util_export_activation_environment (GError **error)
+{
+ GDBusConnection *connection;
+ gboolean environment_updated = FALSE;
+ char **entry_names;
+ int i = 0;
+ GVariantBuilder builder;
+ GRegex *name_regex, *value_regex;
+ GVariant *reply;
+ GError *bus_error = NULL;
+
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
+
+ if (connection == NULL) {
return FALSE;
}
- bus_proxy = dbus_g_proxy_new_for_name_owner (dbus_connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS,
- error);
+ name_regex = g_regex_new ("^[a-zA-Z_][a-zA-Z0-9_]*$", G_REGEX_OPTIMIZE, 0, error);
- if (bus_proxy == NULL) {
- goto out;
+ if (name_regex == NULL) {
+ return FALSE;
}
- environment = g_hash_table_new (g_str_hash, g_str_equal);
+ value_regex = g_regex_new ("^([[:blank:]]|[^[:cntrl:]])*$", G_REGEX_OPTIMIZE, 0, error);
- g_hash_table_insert (environment, (void *) variable, (void *) value);
+ if (value_regex == NULL) {
+ return FALSE;
+ }
- if (!dbus_g_proxy_call (bus_proxy,
- "UpdateActivationEnvironment", error,
- DBUS_TYPE_G_STRING_STRING_HASHTABLE,
- environment, G_TYPE_INVALID,
- G_TYPE_INVALID))
- goto out;
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{ss}"));
+ for (entry_names = g_listenv (); entry_names[i] != NULL; i++) {
+ const char *entry_name = entry_names[i];
+ const char *entry_value = g_getenv (entry_name);
- environment_updated = TRUE;
+ if (!g_utf8_validate (entry_name, -1, NULL))
+ continue;
- out:
+ if (!g_regex_match (name_regex, entry_name, 0, NULL))
+ continue;
- if (bus_proxy != NULL) {
- g_object_unref (bus_proxy);
- }
+ if (!g_utf8_validate (entry_value, -1, NULL))
+ continue;
- if (environment != NULL) {
- g_hash_table_destroy (environment);
+ if (!g_regex_match (value_regex, entry_value, 0, NULL))
+ continue;
+
+ g_variant_builder_add (&builder, "{ss}", entry_name, entry_value);
+ }
+ g_regex_unref (name_regex);
+ g_regex_unref (value_regex);
+
+ g_strfreev (entry_names);
+
+ reply = g_dbus_connection_call_sync (connection,
+ "org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "UpdateActivationEnvironment",
+ g_variant_new ("(@a{ss})",
+ g_variant_builder_end (&builder)),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &bus_error);
+
+ if (bus_error != NULL) {
+ g_propagate_error (error, bus_error);
+ } else {
+ environment_updated = TRUE;
+ g_variant_unref (reply);
}
+ g_clear_object (&connection);
+
return environment_updated;
}