~ubuntu-branches/ubuntu/saucy/gnome-shell/saucy-proposed

« back to all changes in this revision

Viewing changes to src/shell-network-agent.c

Tags: upstream-3.3.90
ImportĀ upstreamĀ versionĀ 3.3.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "config.h"
23
23
#include <string.h>
24
24
#include <gnome-keyring.h>
 
25
#include <dbus/dbus-glib.h>
25
26
 
26
27
#include "shell-network-agent.h"
27
 
#include "shell-marshal.h"
28
28
 
29
29
enum {
30
30
  SIGNAL_NEW_REQUEST,
48
48
 
49
49
  /* <gchar *setting_key, gchar *secret> */
50
50
  GHashTable                    *entries;
 
51
  GHashTable                    *vpn_entries;
 
52
  gboolean                       is_vpn;
51
53
} ShellAgentRequest;
52
54
 
53
55
struct _ShellNetworkAgentPrivate {
69
71
  g_object_unref (request->connection);
70
72
  g_free (request->setting_name);
71
73
  g_strfreev (request->hints);
72
 
 
73
74
  g_hash_table_destroy (request->entries);
74
75
 
75
76
  g_slice_free (ShellAgentRequest, request);
123
124
                 request->request_id,
124
125
                 request->connection,
125
126
                 request->setting_name,
126
 
                 request->hints);
 
127
                 request->hints,
 
128
                 (int)request->flags);
127
129
}
128
130
 
129
131
static void
227
229
                        GList              *list,
228
230
                        gpointer            user_data)
229
231
{
230
 
  ShellAgentRequest *closure = user_data;
231
 
  ShellNetworkAgent *self = closure->self;
232
 
  ShellNetworkAgentPrivate *priv = self->priv;
 
232
  ShellAgentRequest *closure;
 
233
  ShellNetworkAgent *self;
 
234
  ShellNetworkAgentPrivate *priv;
233
235
  GError *error = NULL;
234
236
  gint n_found = 0;
235
237
  GList *iter;
236
238
  GHashTable *outer;
237
239
 
 
240
  if (result == GNOME_KEYRING_RESULT_CANCELLED)
 
241
    return;
 
242
 
 
243
  closure = user_data;
 
244
  self = closure->self;
 
245
  priv  = self->priv;
 
246
 
238
247
  closure->keyring_op = NULL;
239
248
 
240
 
  if (result == GNOME_KEYRING_RESULT_CANCELLED)
 
249
  if (result == GNOME_KEYRING_RESULT_DENIED)
241
250
    {
242
251
      g_set_error (&error,
243
252
                   NM_SECRET_AGENT_ERROR,
244
253
                   NM_SECRET_AGENT_ERROR_USER_CANCELED,
245
 
                   "The secret request was cancelled by the user");
 
254
                   "Access to the secret storage was denied by the user");
246
255
 
247
256
      closure->callback (NM_SECRET_AGENT (closure->self), closure->connection, NULL, error, closure->callback_data);
248
257
 
275
284
              && (attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING))
276
285
            {
277
286
              gchar *secret_name = g_strdup (attr->value.string);
278
 
              GValue *secret_value = g_slice_new0 (GValue);
279
 
              g_value_init (secret_value, G_TYPE_STRING);
280
 
              g_value_set_string (secret_value, item->secret);
281
 
 
282
 
              g_hash_table_insert (closure->entries, secret_name, secret_value);
 
287
 
 
288
              if (!closure->is_vpn)
 
289
                {
 
290
                  GValue *secret_value = g_slice_new0 (GValue);
 
291
                  g_value_init (secret_value, G_TYPE_STRING);
 
292
                  g_value_set_string (secret_value, item->secret);
 
293
 
 
294
                  g_hash_table_insert (closure->entries, secret_name, secret_value);
 
295
                }
 
296
              else
 
297
                g_hash_table_insert (closure->vpn_entries, secret_name, g_strdup (item->secret));
283
298
 
284
299
              if (closure->hints)
285
300
                n_found += strv_has (closure->hints, secret_name);
294
309
  if (n_found == 0 &&
295
310
      (closure->flags & NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION))
296
311
    {
297
 
      /* Even if n_found == 0, secrets is not necessarily empty */
298
312
      nm_connection_update_secrets (closure->connection, closure->setting_name, closure->entries, NULL);
299
313
 
300
314
      request_secrets_from_ui (closure);
328
342
  NMSettingConnection *setting_connection;
329
343
  const char *connection_type;
330
344
 
331
 
  /* VPN secrets are currently unimplemented - bail out early */
332
345
  setting_connection = nm_connection_get_setting_connection (connection);
333
346
  connection_type = nm_setting_connection_get_connection_type (setting_connection);
334
 
  if (strcmp (connection_type, "vpn") == 0)
335
 
    {
336
 
      GError *error = g_error_new (NM_SECRET_AGENT_ERROR,
337
 
                                   NM_SECRET_AGENT_ERROR_AGENT_CANCELED,
338
 
                                   "VPN secrets are currently unhandled.");
339
 
      callback (NM_SECRET_AGENT (self), connection, NULL, error, callback_data);
340
 
      return;
341
 
    }
342
347
 
343
348
  request = g_slice_new (ShellAgentRequest);
344
349
  request->self = g_object_ref (self);
348
353
  request->flags = flags;
349
354
  request->callback = callback;
350
355
  request->callback_data = callback_data;
 
356
  request->is_vpn = !strcmp(connection_type, NM_SETTING_VPN_SETTING_NAME);
 
357
  request->keyring_op = NULL;
351
358
  request->entries = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, gvalue_destroy_notify);
352
359
 
 
360
  if (request->is_vpn)
 
361
    {
 
362
      GValue *secret_value;
 
363
 
 
364
      request->vpn_entries = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 
365
 
 
366
      secret_value = g_slice_new0 (GValue);
 
367
      g_value_init (secret_value, dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRING));
 
368
      g_value_take_boxed (secret_value, request->vpn_entries);
 
369
      g_hash_table_insert (request->entries, g_strdup(NM_SETTING_VPN_SECRETS), secret_value);
 
370
    }
 
371
  else
 
372
    request->vpn_entries = NULL;
 
373
 
353
374
  request->request_id = g_strdup_printf ("%s/%s", connection_path, setting_name);
354
375
  g_hash_table_replace (self->priv->requests, request->request_id, request);
355
376
 
389
410
  priv = self->priv;
390
411
  request = g_hash_table_lookup (priv->requests, request_id);
391
412
 
392
 
  value = g_slice_new0 (GValue);
393
 
  g_value_init (value, G_TYPE_STRING);
394
 
  g_value_set_string (value, setting_value);
 
413
  if (!request->is_vpn)
 
414
    {
 
415
      value = g_slice_new0 (GValue);
 
416
      g_value_init (value, G_TYPE_STRING);
 
417
      g_value_set_string (value, setting_value);
395
418
 
396
 
  g_hash_table_replace (request->entries, g_strdup (setting_key), value);
 
419
      g_hash_table_replace (request->entries, g_strdup (setting_key), value);
 
420
    }
 
421
  else
 
422
    {
 
423
      g_hash_table_replace (request->vpn_entries, g_strdup (setting_key), g_strdup (setting_value));
 
424
    }
397
425
}
398
426
 
399
427
void
400
 
shell_network_agent_respond (ShellNetworkAgent *self,
401
 
                             gchar             *request_id,
402
 
                             gboolean           canceled)
 
428
shell_network_agent_respond (ShellNetworkAgent         *self,
 
429
                             gchar                     *request_id,
 
430
                             ShellNetworkAgentResponse  response)
403
431
{
404
432
  ShellNetworkAgentPrivate *priv;
405
433
  ShellAgentRequest *request;
411
439
  priv = self->priv;
412
440
  request = g_hash_table_lookup (priv->requests, request_id);
413
441
 
414
 
  if (canceled)
 
442
  if (response == SHELL_NETWORK_AGENT_USER_CANCELED)
415
443
    {
416
444
      GError *error = g_error_new (NM_SECRET_AGENT_ERROR,
417
445
                                   NM_SECRET_AGENT_ERROR_USER_CANCELED,
423
451
      return;
424
452
    }
425
453
 
 
454
  if (response == SHELL_NETWORK_AGENT_INTERNAL_ERROR)
 
455
    {
 
456
      GError *error = g_error_new (NM_SECRET_AGENT_ERROR,
 
457
                                   NM_SECRET_AGENT_ERROR_INTERNAL_ERROR,
 
458
                                   "An internal error occurred while processing the request.");
 
459
 
 
460
      request->callback (NM_SECRET_AGENT (self), request->connection, NULL, error, request->callback_data);
 
461
      g_error_free (error);
 
462
      g_hash_table_remove (priv->requests, request_id);
 
463
      return;
 
464
    }
 
465
 
 
466
  /* response == SHELL_NETWORK_AGENT_CONFIRMED */
 
467
 
426
468
  /* Save updated secrets */
427
469
  dup = nm_connection_duplicate (request->connection);
 
470
 
428
471
  nm_connection_update_secrets (dup, request->setting_name, request->entries, NULL);
429
 
 
430
472
  nm_secret_agent_save_secrets (NM_SECRET_AGENT (self), dup, NULL, NULL);
431
473
 
432
474
  outer = g_hash_table_new (g_str_hash, g_str_equal);
775
817
                                              0, /* class offset */
776
818
                                              NULL, /* accumulator */
777
819
                                              NULL, /* accu_data */
778
 
                                              _shell_marshal_VOID__STRING_OBJECT_STRING_BOXED,
 
820
                                              NULL, /* marshaller */
779
821
                                              G_TYPE_NONE, /* return */
780
 
                                              3, /* n_params */
 
822
                                              5, /* n_params */
781
823
                                              G_TYPE_STRING,
782
824
                                              NM_TYPE_CONNECTION,
783
825
                                              G_TYPE_STRING,
784
 
                                              G_TYPE_STRV);
 
826
                                              G_TYPE_STRV,
 
827
                                              G_TYPE_INT);
785
828
 
786
829
  signals[SIGNAL_CANCEL_REQUEST] = g_signal_new ("cancel-request",
787
830
                                                 G_TYPE_FROM_CLASS (klass),
789
832
                                                 0, /* class offset */
790
833
                                                 NULL, /* accumulator */
791
834
                                                 NULL, /* accu_data */
792
 
                                                 g_cclosure_marshal_VOID__STRING,
 
835
                                                 NULL, /* marshaller */
793
836
                                                 G_TYPE_NONE,
794
837
                                                 1, /* n_params */
795
838
                                                 G_TYPE_STRING);