+
+int gdbus_switch_to_private_connection(void)
+{
+ // This function is called by launchpad during the application preparation
+ // process. Launchpad is running with high privileges (label User). If a call
+ // to dbus is made before the process privileges are changed to lower (wich is
+ // what happens now), any method call sent with this connection will be
+ // visible as a call from a privileged process.
+ //
+ // From outside glib we can't effectively close the current connection so as
+ // to receive a new one (with application label), so this function forces to
+ // use of a private connection.
+
+ // Close current connection so that it can not be used.
+ dbus_handle_s *connection = _gdbus_get_connection(gdbus_get_default_bus_type());
+ int ret;
+ if ((ret = _gdbus_free_connection(connection, true)) != 0)
+ return ret;
+
+ // Switch to a private connection.
+ pthread_mutex_lock(&g_mutex);
+ g_default_priv = true;
+ pthread_mutex_unlock(&g_mutex);
+
+ _I("Switched to private connection.");
+
+ return 0;
+}