29
30
#include "nm-remote-connection.h"
30
31
#include "nm-remote-connection-private.h"
31
32
#include "nm-dbus-glib-types.h"
32
#include "nm-settings-connection-bindings.h"
33
#include "nm-glib-compat.h"
34
35
#define NM_REMOTE_CONNECTION_BUS "bus"
36
G_DEFINE_TYPE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION)
37
static void nm_remote_connection_initable_iface_init (GInitableIface *iface);
38
static void nm_remote_connection_async_initable_iface_init (GAsyncInitableIface *iface);
40
G_DEFINE_TYPE_WITH_CODE (NMRemoteConnection, nm_remote_connection, NM_TYPE_CONNECTION,
41
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_remote_connection_initable_iface_init);
42
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_remote_connection_async_initable_iface_init);
92
update_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
97
update_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data)
94
99
RemoteCall *call = user_data;
95
100
NMRemoteConnectionCommitFunc func = (NMRemoteConnectionCommitFunc) call->callback;
101
GError *error = NULL;
103
dbus_g_proxy_end_call (proxy, proxy_call, &error,
98
106
(*func)(call->self, error, call->user_data);
107
g_clear_error (&error);
99
108
remote_call_complete (call->self, call);
132
141
settings = nm_connection_to_hash (NM_CONNECTION (self), NM_SETTING_HASH_FLAG_ALL);
134
call->call = org_freedesktop_NetworkManager_Settings_Connection_update_async (priv->proxy,
143
call->call = dbus_g_proxy_begin_call (priv->proxy, "Update",
144
update_cb, call, NULL,
145
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, settings,
138
147
g_assert (call->call);
139
148
priv->calls = g_slist_append (priv->calls, call);
145
delete_cb (DBusGProxy *proxy, GError *error, gpointer user_data)
154
delete_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data)
147
156
RemoteCall *call = user_data;
148
157
NMRemoteConnectionDeleteFunc func = (NMRemoteConnectionDeleteFunc) call->callback;
158
GError *error = NULL;
160
dbus_g_proxy_end_call (proxy, proxy_call, &error,
150
162
if (func != NULL)
151
163
(*func)(call->self, error, call->user_data);
164
g_clear_error (&error);
152
165
remote_call_complete (call->self, call);
178
191
call->callback = (GFunc) callback;
179
192
call->user_data = user_data;
181
call->call = org_freedesktop_NetworkManager_Settings_Connection_delete_async (priv->proxy,
194
call->call = dbus_g_proxy_begin_call (priv->proxy, "Delete",
195
delete_cb, call, NULL,
184
197
g_assert (call->call);
185
198
priv->calls = g_slist_append (priv->calls, call);
189
get_secrets_cb (DBusGProxy *proxy, GHashTable *secrets, GError *error, gpointer user_data)
202
get_secrets_cb (DBusGProxy *proxy, DBusGProxyCall *proxy_call, gpointer user_data)
191
204
RemoteCall *call = user_data;
192
205
NMRemoteConnectionGetSecretsFunc func = (NMRemoteConnectionGetSecretsFunc) call->callback;
207
GError *error = NULL;
209
dbus_g_proxy_end_call (proxy, proxy_call, &error,
210
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &secrets,
194
212
(*func)(call->self, error ? NULL : secrets, error, call->user_data);
213
g_clear_error (&error);
195
214
remote_call_complete (call->self, call);
225
244
call->callback = (GFunc) callback;
226
245
call->user_data = user_data;
228
call->call = org_freedesktop_NetworkManager_Settings_Connection_get_secrets_async (priv->proxy,
247
call->call = dbus_g_proxy_begin_call (priv->proxy, "GetSecrets",
248
get_secrets_cb, call, NULL,
249
G_TYPE_STRING, setting_name,
232
251
g_assert (call->call);
233
252
priv->calls = g_slist_append (priv->calls, call);
258
init_get_settings_cb (DBusGProxy *proxy,
259
GHashTable *new_settings,
263
NMRemoteConnection *self = user_data;
264
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
267
/* Connection doesn't exist, or isn't visible to this user */
268
if (dbus_g_error_has_name (error, "org.freedesktop.NetworkManager.Settings.PermissionDenied"))
269
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_INVISIBLE;
271
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_ERROR;
273
g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_INIT_RESULT);
275
priv->visible = TRUE;
276
replace_settings (self, new_settings);
277
g_hash_table_destroy (new_settings);
278
priv->init_result = NM_REMOTE_CONNECTION_INIT_RESULT_SUCCESS;
279
g_object_notify (G_OBJECT (self), NM_REMOTE_CONNECTION_INIT_RESULT);
284
277
updated_get_settings_cb (DBusGProxy *proxy,
285
GHashTable *new_settings,
278
DBusGProxyCall *call,
287
279
gpointer user_data)
289
281
NMRemoteConnection *self = user_data;
290
282
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
283
GHashTable *new_settings;
284
GError *error = NULL;
286
dbus_g_proxy_end_call (proxy, call, &error,
287
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &new_settings,
293
290
GHashTable *hash;
292
g_error_free (error);
295
294
/* Connection is no longer visible to this user. Let the settings
296
295
* service handle this via 'visible'. The settings service will emit
297
296
* the "removed" signal for us since it handles the lifetime of this
322
321
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
324
323
/* The connection got updated; request the replacement settings */
325
org_freedesktop_NetworkManager_Settings_Connection_get_settings_async (priv->proxy,
326
updated_get_settings_cb,
324
dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
325
updated_get_settings_cb, self, NULL,
361
constructor (GType type,
362
guint n_construct_params,
363
GObjectConstructParam *construct_params)
360
constructed (GObject *object)
366
362
NMRemoteConnectionPrivate *priv;
368
object = G_OBJECT_CLASS (nm_remote_connection_parent_class)->constructor (type, n_construct_params, construct_params);
372
364
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (object);
373
365
g_assert (priv->bus);
374
366
g_assert (nm_connection_get_path (NM_CONNECTION (object)));
386
378
dbus_g_proxy_add_signal (priv->proxy, "Removed", G_TYPE_INVALID);
387
379
dbus_g_proxy_connect_signal (priv->proxy, "Removed", G_CALLBACK (removed_cb), object, NULL);
389
org_freedesktop_NetworkManager_Settings_Connection_get_settings_async (priv->proxy,
390
init_get_settings_cb,
383
init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
385
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
386
GHashTable *settings;
388
if (!dbus_g_proxy_call (priv->proxy, "GetSettings", error,
389
G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS,
391
DBUS_TYPE_G_MAP_OF_VARIANT, &settings,
395
priv->visible = TRUE;
396
replace_settings (NM_REMOTE_CONNECTION (initable), settings);
397
g_hash_table_destroy (settings);
402
NMRemoteConnection *connection;
403
GSimpleAsyncResult *result;
404
} NMRemoteConnectionInitData;
407
init_get_settings_cb (DBusGProxy *proxy,
408
DBusGProxyCall *call,
411
NMRemoteConnectionInitData *init_data = user_data;
412
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (init_data->connection);
413
GHashTable *settings;
414
GError *error = NULL;
416
dbus_g_proxy_end_call (proxy, call, &error,
417
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, &settings,
420
g_simple_async_result_take_error (init_data->result, error);
422
priv->visible = TRUE;
423
replace_settings (init_data->connection, settings);
424
g_hash_table_destroy (settings);
425
g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
428
g_simple_async_result_complete (init_data->result);
429
g_slice_free (NMRemoteConnectionInitData, init_data);
433
init_async (GAsyncInitable *initable, int io_priority,
434
GCancellable *cancellable, GAsyncReadyCallback callback,
437
NMRemoteConnectionInitData *init_data;
438
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (initable);
441
init_data = g_slice_new0 (NMRemoteConnectionInitData);
442
init_data->connection = NM_REMOTE_CONNECTION (initable);
443
init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
444
user_data, init_async);
446
dbus_g_proxy_begin_call (priv->proxy, "GetSettings",
447
init_get_settings_cb, init_data, NULL,
418
get_property (GObject *object, guint prop_id,
419
GValue *value, GParamSpec *pspec)
421
NMRemoteConnection *self = NM_REMOTE_CONNECTION (object);
422
NMRemoteConnectionPrivate *priv = NM_REMOTE_CONNECTION_GET_PRIVATE (self);
425
case PROP_INIT_RESULT:
426
g_value_set_uint (value, priv->init_result);
429
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
435
475
dispose (GObject *object)
437
477
NMRemoteConnection *self = NM_REMOTE_CONNECTION (object);
472
511
DBUS_TYPE_G_CONNECTION,
473
512
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
475
g_object_class_install_property
476
(object_class, PROP_INIT_RESULT,
477
g_param_spec_uint (NM_REMOTE_CONNECTION_INIT_RESULT,
478
"Initialization result (PRIVATE)",
479
"Initialization result (PRIVATE)",
480
NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN,
481
NM_REMOTE_CONNECTION_INIT_RESULT_ERROR,
482
NM_REMOTE_CONNECTION_INIT_RESULT_UNKNOWN,
487
516
* NMRemoteConnection::updated: