libnm-glib: drop private bus support

Anything that actually *needs* private bus support will be built
against libnm these days anyway.
This commit is contained in:
Dan Winship 2015-07-07 10:29:45 -04:00
parent 3452ee2a0e
commit ee707ba95a
7 changed files with 100 additions and 204 deletions

View file

@ -1798,23 +1798,19 @@ constructed (GObject *object)
object,
NULL);
if (_nm_object_is_connection_private (NM_OBJECT (object)))
priv->manager_running = TRUE;
else {
priv->bus_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->bus_proxy);
priv->bus_proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->bus_proxy);
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->bus_proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
object, NULL);
}
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->bus_proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
object, NULL);
g_signal_connect (object, "notify::" NM_CLIENT_WIRELESS_ENABLED,
G_CALLBACK (wireless_enabled_cb), NULL);
@ -1835,15 +1831,13 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
if (!nm_client_parent_initable_iface->init (initable, cancellable, error))
return FALSE;
if (!_nm_object_is_connection_private (NM_OBJECT (client))) {
if (!dbus_g_proxy_call (priv->bus_proxy,
"NameHasOwner", error,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->manager_running,
G_TYPE_INVALID))
return FALSE;
}
if (!dbus_g_proxy_call (priv->bus_proxy,
"NameHasOwner", error,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->manager_running,
G_TYPE_INVALID))
return FALSE;
if (priv->manager_running && !get_permissions_sync (client, error))
return FALSE;
@ -1953,16 +1947,12 @@ init_async (GAsyncInitable *initable, int io_priority,
user_data, init_async);
g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
if (_nm_object_is_connection_private (NM_OBJECT (init_data->client)))
finish_init (init_data);
else {
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_manager_running,
init_data, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_manager_running,
init_data, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
static gboolean

View file

@ -28,8 +28,6 @@
DBusGConnection *_nm_dbus_new_connection (GError **error);
gboolean _nm_dbus_is_connection_private (DBusGConnection *connection);
DBusGProxy * _nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
const char *path,
const char *interface);

View file

@ -27,74 +27,21 @@
#include "nm-dbus-helpers-private.h"
#include "NetworkManager.h"
static dbus_int32_t priv_slot = -1;
static gboolean
_ensure_dbus_data_slot (void)
{
static gsize init_value = 0;
gboolean success = TRUE;
if (g_once_init_enter (&init_value)) {
success = dbus_connection_allocate_data_slot (&priv_slot);
g_once_init_leave (&init_value, 1);
}
return success;
}
DBusGConnection *
_nm_dbus_new_connection (GError **error)
{
DBusGConnection *connection = NULL;
if (!_ensure_dbus_data_slot ()) {
g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED, "failed to allocated data slot");
return NULL;
}
#if HAVE_DBUS_GLIB_100
/* If running as root try the private bus first */
if (0 == geteuid ()) {
connection = dbus_g_connection_open ("unix:path=" NMRUNDIR "/private", error);
if (connection) {
DBusConnection *dbus_connection = dbus_g_connection_get_connection (connection);
/* Mark this connection as private */
dbus_connection_set_data (dbus_connection, priv_slot, GUINT_TO_POINTER (TRUE), NULL);
dbus_connection_set_exit_on_disconnect (dbus_connection, FALSE);
return connection;
}
/* Fall back to a bus if for some reason private socket isn't available */
g_clear_error (error);
}
#endif
if (connection == NULL)
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
return connection;
}
gboolean
_nm_dbus_is_connection_private (DBusGConnection *connection)
{
if (!_ensure_dbus_data_slot ())
return FALSE;
return !!dbus_connection_get_data (dbus_g_connection_get_connection (connection), priv_slot);
}
DBusGProxy *
_nm_dbus_new_proxy_for_connection (DBusGConnection *connection,
const char *path,
const char *interface)
{
/* Private connections can't use dbus_g_proxy_new_for_name() or
* dbus_g_proxy_new_for_name_owner() because peer-to-peer connections don't
* have either a bus daemon or name owners, both of which those functions
* require.
*/
if (_nm_dbus_is_connection_private (connection))
return dbus_g_proxy_new_for_peer (connection, path, interface);
return dbus_g_proxy_new_for_name (connection, NM_DBUS_SERVICE, path, interface);
}

View file

@ -42,8 +42,6 @@ DBusGProxy *_nm_object_new_proxy (NMObject *self,
const char *path,
const char *interface);
gboolean _nm_object_is_connection_private (NMObject *self);
void _nm_object_register_properties (NMObject *object,
DBusGProxy *proxy,
const NMPropertiesInfo *info);

View file

@ -174,23 +174,19 @@ constructed (GObject *object)
priv->properties_proxy = _nm_object_new_proxy (self, NULL, DBUS_INTERFACE_PROPERTIES);
if (_nm_object_is_connection_private (self))
priv->nm_running = TRUE;
else {
priv->bus_proxy = dbus_g_proxy_new_for_name (priv->connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->bus_proxy);
priv->bus_proxy = dbus_g_proxy_new_for_name (priv->connection,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->bus_proxy);
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->bus_proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
object, NULL);
}
dbus_g_proxy_add_signal (priv->bus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->bus_proxy,
"NameOwnerChanged",
G_CALLBACK (proxy_name_owner_changed),
object, NULL);
}
static gboolean
@ -272,16 +268,12 @@ init_async (GAsyncInitable *initable, int io_priority,
simple = g_simple_async_result_new (G_OBJECT (initable), callback, user_data, init_async);
if (_nm_object_is_connection_private (NM_OBJECT (initable)))
_nm_object_reload_properties_async (NM_OBJECT (initable), init_async_got_properties, simple);
else {
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_manager_running,
simple, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->bus_proxy, "NameHasOwner",
init_async_got_manager_running,
simple, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
static gboolean
@ -1438,9 +1430,3 @@ _nm_object_new_proxy (NMObject *self, const char *path, const char *interface)
return _nm_dbus_new_proxy_for_connection (priv->connection, path ? path : priv->path, interface);
}
gboolean
_nm_object_is_connection_private (NMObject *self)
{
return _nm_dbus_is_connection_private (NM_OBJECT_GET_PRIVATE (self)->connection);
}

View file

@ -132,7 +132,6 @@ G_DEFINE_TYPE_WITH_CODE (NMRemoteSettings, nm_remote_settings, G_TYPE_OBJECT,
typedef struct {
DBusGConnection *bus;
gboolean private_bus;
gboolean inited;
DBusGProxy *proxy;
@ -1177,26 +1176,24 @@ constructed (GObject *object)
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object);
if (priv->private_bus == FALSE) {
/* D-Bus proxy for clearing connections on NameOwnerChanged */
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->dbus_proxy);
/* D-Bus proxy for clearing connections on NameOwnerChanged */
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->dbus_proxy);
dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
G_TYPE_NONE,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->dbus_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
object, NULL);
}
dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
G_TYPE_NONE,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->dbus_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
object, NULL);
priv->proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
NM_DBUS_PATH_SETTINGS,
@ -1239,23 +1236,20 @@ init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
GHashTable *props;
if (priv->private_bus == FALSE) {
if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", error,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->service_running,
G_TYPE_INVALID)) {
priv->service_running = FALSE;
return FALSE;
}
if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", error,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &priv->service_running,
G_TYPE_INVALID)) {
priv->service_running = FALSE;
return FALSE;
}
/* If NM isn't running we'll grab properties from name_owner_changed()
* when it starts.
*/
if (!priv->service_running)
return TRUE;
} else
priv->service_running = TRUE;
/* If NM isn't running we'll grab properties from name_owner_changed()
* when it starts.
*/
if (!priv->service_running)
return TRUE;
priv->listcon_call = dbus_g_proxy_begin_call (priv->proxy, "ListConnections",
fetch_connections_done, NM_REMOTE_SETTINGS (initable), NULL,
@ -1376,17 +1370,12 @@ init_async (GAsyncInitable *initable, int io_priority,
init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
user_data, init_async);
if (priv->private_bus) {
priv->service_running = TRUE;
init_get_properties (init_data);
} else {
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->dbus_proxy, "NameHasOwner",
init_async_got_manager_running,
init_data, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
/* Check if NM is running */
dbus_g_proxy_begin_call (priv->dbus_proxy, "NameHasOwner",
init_async_got_manager_running,
init_data, NULL,
G_TYPE_STRING, NM_DBUS_SERVICE,
G_TYPE_INVALID);
}
static gboolean
@ -1444,10 +1433,8 @@ set_property (GObject *object, guint prop_id,
case PROP_BUS:
/* Construct only */
priv->bus = g_value_dup_boxed (value);
if (!priv->bus) {
if (!priv->bus)
priv->bus = _nm_dbus_new_connection (NULL);
priv->private_bus = _nm_dbus_is_connection_private (priv->bus);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);

View file

@ -65,7 +65,6 @@ typedef struct {
NMSecretAgentCapabilities capabilities;
DBusGConnection *bus;
gboolean private_bus;
DBusGProxy *dbus_proxy;
DBusGProxy *manager_proxy;
DBusGProxyCall *reg_call;
@ -227,12 +226,6 @@ verify_sender (NMSecretAgent *self,
g_return_val_if_fail (context != NULL, FALSE);
/* Private bus connection is always to NetworkManager, which is always
* UID 0.
*/
if (priv->private_bus)
return TRUE;
/* Verify the sender's UID is 0, and that the sender is the same as
* NetworkManager's bus name owner.
*/
@ -626,7 +619,7 @@ nm_secret_agent_register (NMSecretAgent *self)
g_return_val_if_fail (class->save_secrets != NULL, FALSE);
g_return_val_if_fail (class->delete_secrets != NULL, FALSE);
if (!priv->nm_owner && !priv->private_bus)
if (!priv->nm_owner)
return FALSE;
priv->suppress_auto = FALSE;
@ -671,7 +664,7 @@ nm_secret_agent_unregister (NMSecretAgent *self)
g_return_val_if_fail (priv->bus != NULL, FALSE);
g_return_val_if_fail (priv->manager_proxy != NULL, FALSE);
if (!priv->nm_owner && !priv->private_bus)
if (!priv->nm_owner)
return FALSE;
dbus_g_proxy_call_no_reply (priv->manager_proxy, "Unregister", G_TYPE_INVALID);
@ -853,29 +846,26 @@ nm_secret_agent_init (NMSecretAgent *self)
g_error_free (error);
return;
}
priv->private_bus = _nm_dbus_is_connection_private (priv->bus);
if (priv->private_bus == FALSE) {
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->dbus_proxy);
priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus,
DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS,
DBUS_INTERFACE_DBUS);
g_assert (priv->dbus_proxy);
dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
G_TYPE_NONE,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->dbus_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
self, NULL);
dbus_g_object_register_marshaller (g_cclosure_marshal_generic,
G_TYPE_NONE,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged",
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_INVALID);
dbus_g_proxy_connect_signal (priv->dbus_proxy,
"NameOwnerChanged",
G_CALLBACK (name_owner_changed),
self, NULL);
get_nm_owner (self);
}
get_nm_owner (self);
priv->manager_proxy = _nm_dbus_new_proxy_for_connection (priv->bus,
NM_DBUS_PATH_AGENT_MANAGER,
@ -885,7 +875,7 @@ nm_secret_agent_init (NMSecretAgent *self)
return;
}
if (priv->nm_owner || priv->private_bus)
if (priv->nm_owner)
priv->auto_register_id = g_idle_add (auto_register_cb, self);
}