~ubuntu-branches/ubuntu/oneiric/network-manager/oneiric

« back to all changes in this revision

Viewing changes to src/settings/nm-agent-manager.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2011-07-25 20:01:12 UTC
  • mfrom: (1.1.48 upstream)
  • Revision ID: james.westby@ubuntu.com-20110725200112-iwxhtsy6hko0ffkt
Tags: 0.8.9997+git.20110721t045648.36db194-0ubuntu1
* upstream snapshot 2011-07-21 04:56:48 (GMT)
  + 36db194ae95e35cc7b8f431ab984780dea24656d
  - libnm-util: default to allowing v6 connections to fail (set to optional)
* debian/patches/ipv6-dont-block-ipv4.patch: don't block waiting for IPv6 to
  apply IPv4 connection settings.
* debian/libnm-glib4.symbols: add new nm_client_get_device_by_iface symbol.
* debian/libnm-util2.symbols: add new symbols:
  - nm_setting_wired_get_mac_address_blacklist
  - nm_setting_wireless_get_mac_address_blacklist

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        NMDBusManager *dbus_mgr;
50
50
        NMSessionMonitor *session_monitor;
51
51
 
 
52
        /* Auth chains for checking agent permissions */
 
53
        GSList *chains;
 
54
 
52
55
        /* Hashed by owner name, not identifier, since two agents in different
53
56
         * sessions can use the same identifier.
54
57
         */
57
60
        GHashTable *requests;
58
61
} NMAgentManagerPrivate;
59
62
 
 
63
enum {
 
64
        AGENT_REGISTERED,
 
65
 
 
66
        LAST_SIGNAL
 
67
};
 
68
static guint signals[LAST_SIGNAL] = { 0 };
 
69
 
 
70
 
60
71
typedef struct _Request Request;
61
72
 
62
73
static void request_add_agent (Request *req,
218
229
}
219
230
 
220
231
static void
 
232
agent_register_permissions_done (NMAuthChain *chain,
 
233
                                 GError *error,
 
234
                                 DBusGMethodInvocation *context,
 
235
                                 gpointer user_data)
 
236
{
 
237
        NMAgentManager *self = NM_AGENT_MANAGER (user_data);
 
238
        NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self);
 
239
        NMSecretAgent *agent;
 
240
        const char *sender;
 
241
        GError *local = NULL;
 
242
        NMAuthCallResult result;
 
243
        GHashTableIter iter;
 
244
        Request *req;
 
245
 
 
246
        priv->chains = g_slist_remove (priv->chains, chain);
 
247
 
 
248
        if (error) {
 
249
                local = g_error_new (NM_AGENT_MANAGER_ERROR,
 
250
                                     NM_AGENT_MANAGER_ERROR_PERMISSION_DENIED,
 
251
                                     "Failed to request agent permissions: (%d) %s",
 
252
                                     error->code, error->message);
 
253
                dbus_g_method_return_error (context, local);
 
254
                g_error_free (local);
 
255
        } else {
 
256
                agent = nm_auth_chain_steal_data (chain, "agent");
 
257
 
 
258
                result = nm_auth_chain_get_result (chain, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED);
 
259
                if (result == NM_AUTH_CALL_RESULT_YES)
 
260
                        nm_secret_agent_add_permission (agent, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED, TRUE);
 
261
 
 
262
                result = nm_auth_chain_get_result (chain, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN);
 
263
                if (result == NM_AUTH_CALL_RESULT_YES)
 
264
                        nm_secret_agent_add_permission (agent, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN, TRUE);
 
265
 
 
266
                sender = nm_secret_agent_get_dbus_owner (agent);
 
267
                g_hash_table_insert (priv->agents, g_strdup (sender), agent);
 
268
                nm_log_dbg (LOGD_AGENTS, "(%s) agent registered",
 
269
                            nm_secret_agent_get_description (agent));
 
270
                dbus_g_method_return (context);
 
271
 
 
272
                /* Signal an agent was registered */
 
273
                g_signal_emit (self, signals[AGENT_REGISTERED], 0, agent);
 
274
 
 
275
                /* Add this agent to any in-progress secrets requests */
 
276
                g_hash_table_iter_init (&iter, priv->requests);
 
277
                while (g_hash_table_iter_next (&iter, NULL, (gpointer) &req))
 
278
                        request_add_agent (req, agent, priv->session_monitor);
 
279
        }
 
280
 
 
281
        nm_auth_chain_unref (chain);
 
282
}
 
283
 
 
284
static void
221
285
impl_agent_manager_register (NMAgentManager *self,
222
286
                             const char *identifier,
223
287
                             DBusGMethodInvocation *context)
227
291
        gulong sender_uid = G_MAXULONG;
228
292
        GError *error = NULL, *local = NULL;
229
293
        NMSecretAgent *agent;
230
 
        GHashTableIter iter;
231
 
        gpointer data;
 
294
        NMAuthChain *chain;
232
295
 
233
296
        if (!nm_auth_get_caller_uid (context, 
234
297
                                         priv->dbus_mgr,
272
335
                goto done;
273
336
        }
274
337
 
275
 
        g_hash_table_insert (priv->agents, g_strdup (sender), agent);
276
 
        nm_log_dbg (LOGD_AGENTS, "(%s) agent registered",
 
338
        nm_log_dbg (LOGD_AGENTS, "(%s) requesting permissions",
277
339
                    nm_secret_agent_get_description (agent));
278
 
        dbus_g_method_return (context);
279
 
 
280
 
        /* Add this agent to any in-progress secrets requests */
281
 
        g_hash_table_iter_init (&iter, priv->requests);
282
 
        while (g_hash_table_iter_next (&iter, NULL, &data))
283
 
                request_add_agent ((Request *) data, agent, priv->session_monitor);
 
340
 
 
341
        /* Kick off permissions requests for this agent */
 
342
        chain = nm_auth_chain_new (context, NULL, agent_register_permissions_done, self);
 
343
        nm_auth_chain_set_data (chain, "agent", agent, g_object_unref);
 
344
        nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED, FALSE);
 
345
        nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN, FALSE);
 
346
 
 
347
        priv->chains = g_slist_append (priv->chains, chain);
284
348
 
285
349
done:
286
350
        if (error)
945
1009
                        g_clear_error (&error);
946
1010
                } else {
947
1011
                        /* Do we have everything we need? */
948
 
                        /* FIXME: handle second check for VPN connections */
949
 
                        if ((nm_connection_need_secrets (tmp, NULL) == NULL) && (request_new == FALSE)) {
 
1012
                        if (   (req->flags & NM_SETTINGS_GET_SECRETS_FLAG_ONLY_SYSTEM)
 
1013
                            || ((nm_connection_need_secrets (tmp, NULL) == NULL) && (request_new == FALSE))) {
950
1014
                                nm_log_dbg (LOGD_AGENTS, "(%p/%s) system settings secrets sufficient",
951
1015
                                            req, req->setting_name);
952
1016
 
1059
1123
        g_hash_table_insert (priv->requests, GUINT_TO_POINTER (req->reqid), req);
1060
1124
 
1061
1125
        /* Kick off the request */
1062
 
        request_add_agents (self, req);
 
1126
        if (!(req->flags & NM_SETTINGS_GET_SECRETS_FLAG_ONLY_SYSTEM))
 
1127
                request_add_agents (self, req);
1063
1128
        req->idle_id = g_idle_add (get_start, req);
1064
1129
 
1065
1130
        return req->reqid;
1277
1342
 
1278
1343
/*************************************************************/
1279
1344
 
 
1345
NMSecretAgent *
 
1346
nm_agent_manager_get_agent_by_user (NMAgentManager *self, const char *username)
 
1347
{
 
1348
        NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self);
 
1349
        GHashTableIter iter;
 
1350
        NMSecretAgent *agent;
 
1351
 
 
1352
        g_hash_table_iter_init (&iter, priv->agents);
 
1353
        while (g_hash_table_iter_next (&iter, NULL, (gpointer) &agent)) {
 
1354
                if (g_strcmp0 (nm_secret_agent_get_owner_username (agent), username) == 0)
 
1355
                        return agent;
 
1356
        }
 
1357
 
 
1358
        return NULL;
 
1359
}
 
1360
 
 
1361
/*************************************************************/
 
1362
 
1280
1363
static void
1281
1364
name_owner_changed_cb (NMDBusManager *dbus_mgr,
1282
1365
                       const char *name,
1290
1373
        }
1291
1374
}
1292
1375
 
 
1376
static void
 
1377
agent_permissions_changed_done (NMAuthChain *chain,
 
1378
                                GError *error,
 
1379
                                DBusGMethodInvocation *context,
 
1380
                                gpointer user_data)
 
1381
{
 
1382
        NMAgentManager *self = NM_AGENT_MANAGER (user_data);
 
1383
        NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self);
 
1384
        NMSecretAgent *agent;
 
1385
        NMAuthCallResult result;
 
1386
 
 
1387
        priv->chains = g_slist_remove (priv->chains, chain);
 
1388
 
 
1389
        agent = nm_auth_chain_get_data (chain, "agent");
 
1390
 
 
1391
        if (error) {
 
1392
                nm_log_dbg (LOGD_AGENTS, "(%s) failed to request updated agent permissions",
 
1393
                            nm_secret_agent_get_description (agent));
 
1394
                nm_secret_agent_add_permission (agent, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED, FALSE);
 
1395
                nm_secret_agent_add_permission (agent, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN, FALSE);
 
1396
        } else {
 
1397
                nm_log_dbg (LOGD_AGENTS, "(%s) updated agent permissions",
 
1398
                            nm_secret_agent_get_description (agent));
 
1399
 
 
1400
                result = nm_auth_chain_get_result (chain, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED);
 
1401
                nm_secret_agent_add_permission (agent,
 
1402
                                                NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED,
 
1403
                                                (result == NM_AUTH_CALL_RESULT_YES));
 
1404
 
 
1405
                result = nm_auth_chain_get_result (chain, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN);
 
1406
                nm_secret_agent_add_permission (agent,
 
1407
                                                NM_AUTH_PERMISSION_WIFI_SHARE_OPEN,
 
1408
                                                (result == NM_AUTH_CALL_RESULT_YES));
 
1409
        }
 
1410
 
 
1411
        nm_auth_chain_unref (chain);
 
1412
}
 
1413
 
 
1414
static void
 
1415
authority_changed_cb (gpointer user_data)
 
1416
{
 
1417
        NMAgentManager *self = NM_AGENT_MANAGER (user_data);
 
1418
        NMAgentManagerPrivate *priv = NM_AGENT_MANAGER_GET_PRIVATE (self);
 
1419
        GHashTableIter iter;
 
1420
        NMSecretAgent *agent;
 
1421
 
 
1422
        /* Recheck the permissions of all secret agents */
 
1423
        g_hash_table_iter_init (&iter, priv->agents);
 
1424
        while (g_hash_table_iter_next (&iter, NULL, (gpointer) &agent)) {
 
1425
                NMAuthChain *chain;
 
1426
                const char *sender;
 
1427
 
 
1428
                /* Kick off permissions requests for this agent */
 
1429
                sender = nm_secret_agent_get_dbus_owner (agent);
 
1430
                chain = nm_auth_chain_new_dbus_sender (sender, agent_permissions_changed_done, self);
 
1431
 
 
1432
                /* Make sure if the agent quits while the permissions call is in progress
 
1433
                 * that the object sticks around until our callback.
 
1434
                 */
 
1435
                nm_auth_chain_set_data (chain, "agent", g_object_ref (agent), g_object_unref);
 
1436
                nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED, FALSE);
 
1437
                nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN, FALSE);
 
1438
 
 
1439
                priv->chains = g_slist_append (priv->chains, chain);
 
1440
        }
 
1441
}
 
1442
 
1293
1443
/*************************************************************/
1294
1444
 
1295
1445
NMAgentManager *
1319
1469
                          G_CALLBACK (name_owner_changed_cb),
1320
1470
                          singleton);
1321
1471
 
 
1472
        nm_auth_changed_func_register (authority_changed_cb, singleton);
 
1473
 
1322
1474
        return singleton;
1323
1475
}
1324
1476
 
1342
1494
        if (!priv->disposed) {
1343
1495
                priv->disposed = TRUE;
1344
1496
 
 
1497
                nm_auth_changed_func_unregister (authority_changed_cb, NM_AGENT_MANAGER (object));
 
1498
 
 
1499
                g_slist_foreach (priv->chains, (GFunc) nm_auth_chain_unref, NULL);
 
1500
 
1345
1501
                g_hash_table_destroy (priv->agents);
1346
1502
                g_hash_table_destroy (priv->requests);
1347
1503
 
1362
1518
        /* virtual methods */
1363
1519
        object_class->dispose = dispose;
1364
1520
 
 
1521
        /* Signals */
 
1522
        signals[AGENT_REGISTERED] =
 
1523
                g_signal_new ("agent-registered",
 
1524
                              G_OBJECT_CLASS_TYPE (object_class),
 
1525
                              G_SIGNAL_RUN_FIRST,
 
1526
                              G_STRUCT_OFFSET (NMAgentManagerClass, agent_registered),
 
1527
                              NULL, NULL,
 
1528
                              g_cclosure_marshal_VOID__OBJECT,
 
1529
                              G_TYPE_NONE, 1,
 
1530
                              G_TYPE_OBJECT);
 
1531
 
1365
1532
        dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (agent_manager_class),
1366
1533
                                         &dbus_glib_nm_agent_manager_object_info);
1367
1534