~ubuntu-branches/ubuntu/natty/gnome-keyring/natty

« back to all changes in this revision

Viewing changes to pkcs11/secret-store/gck-secret-module.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2010-03-22 11:00:39 UTC
  • mfrom: (1.1.60 upstream)
  • Revision ID: james.westby@ubuntu.com-20100322110039-wwp3283t0pz923ld
Tags: 2.92.92git20100322-0ubuntu1
* Upstream git snapshot:
  - "Don't save session keyring to disk".(lp: #539180)
  - better errors handling, fixes a crash (lp: #525410)
  - let "automatically unlock" unlock the keyring (lp: #526560)
* debian/patches/04_remove_assert_on_va_list.patch:
  - the change is in the new version

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
        GckFileTracker *tracker;
43
43
        GHashTable *collections;
44
44
        gchar *directory;
45
 
 
46
 
        /* Special 'session' keyring */
47
45
        GckCredential *session_credential;
48
 
        GckSecretCollection *session_collection;
49
46
};
50
47
 
51
48
static const CK_SLOT_INFO gck_secret_module_slot_info = {
301
298
}
302
299
 
303
300
static void
 
301
gck_secret_module_real_add_object (GckModule *module, GckTransaction *transaction,
 
302
                                   GckObject *object)
 
303
{
 
304
        GckSecretModule *self = GCK_SECRET_MODULE (module);
 
305
        GckSecretCollection *collection;
 
306
        const gchar *identifier;
 
307
        gchar *filename;
 
308
 
 
309
        g_return_if_fail (!gck_transaction_get_failed (transaction));
 
310
 
 
311
        if (GCK_IS_SECRET_COLLECTION (object)) {
 
312
                collection = GCK_SECRET_COLLECTION (object);
 
313
 
 
314
                /* Setup a filename for this collection */
 
315
                identifier = gck_secret_object_get_identifier (GCK_SECRET_OBJECT (collection));
 
316
                filename = identifier_to_new_filename (self, identifier);
 
317
                gck_secret_collection_set_filename (collection, filename);
 
318
                g_free (filename);
 
319
 
 
320
                add_collection (self, transaction, collection);
 
321
        }
 
322
}
 
323
 
 
324
static void
304
325
gck_secret_module_real_store_object (GckModule *module, GckTransaction *transaction,
305
326
                                     GckObject *object)
306
327
{
307
328
        GckSecretModule *self = GCK_SECRET_MODULE (module);
308
329
        GckSecretCollection *collection = NULL;
309
 
        const gchar *identifier;
310
 
        gchar *filename;
311
330
 
312
 
        /* Storing an item */
 
331
        /* Store the item's collection */
313
332
        if (GCK_IS_SECRET_ITEM (object)) {
314
333
                collection = gck_secret_item_get_collection (GCK_SECRET_ITEM (object));
315
334
                g_return_if_fail (GCK_IS_SECRET_COLLECTION (collection));
 
335
                gck_module_store_token_object (GCK_MODULE (self), transaction, GCK_OBJECT (collection));
316
336
 
317
337
        /* Storing a collection */
318
338
        } else if (GCK_IS_SECRET_COLLECTION (object)) {
319
339
                collection = GCK_SECRET_COLLECTION (object);
320
 
        }
 
340
                gck_secret_collection_save (collection, transaction);
321
341
 
322
342
        /* No other kind of token object */
323
 
        if (collection == NULL) {
 
343
        } else {
324
344
                g_warning ("can't store object of type '%s' on secret token", G_OBJECT_TYPE_NAME (object));
325
345
                gck_transaction_fail (transaction, CKR_GENERAL_ERROR);
326
 
                return;
327
 
        }
328
 
 
329
 
        /* Setup a filename for this collection */
330
 
        if (!gck_secret_collection_get_filename (collection)) {
331
 
                identifier = gck_secret_object_get_identifier (GCK_SECRET_OBJECT (collection));
332
 
                filename = identifier_to_new_filename (self, identifier);
333
 
                gck_secret_collection_set_filename (collection, filename);
334
 
                g_free (filename);
335
 
        }
336
 
 
337
 
        gck_secret_collection_save (collection, transaction);
338
 
        if (!gck_transaction_get_failed (transaction))
339
 
                add_collection (self, transaction, collection);
 
346
        }
340
347
}
341
348
 
342
349
static void
351
358
            GCK_OBJECT (self->session_credential) == object)
352
359
                return;
353
360
 
354
 
        /* Ignore the session keyring collection */
355
 
        if (self->session_collection != NULL &&
356
 
            GCK_OBJECT (self->session_collection) == object)
357
 
                return;
358
 
 
359
361
        /* Removing an item */
360
362
        if (GCK_IS_SECRET_ITEM (object)) {
361
363
                collection = gck_secret_item_get_collection (GCK_SECRET_ITEM (object));
384
386
{
385
387
        GckSecretModule *self = GCK_SECRET_MODULE (G_OBJECT_CLASS (gck_secret_module_parent_class)->constructor(type, n_props, props));
386
388
        GckManager *manager;
 
389
        GckObject *collection;
387
390
        CK_RV rv;
388
391
 
389
392
        g_return_val_if_fail (self, NULL);
401
404
 
402
405
        manager = gck_module_get_manager (GCK_MODULE (self));
403
406
 
 
407
        collection = g_object_new (GCK_TYPE_SECRET_COLLECTION,
 
408
                                   "module", self,
 
409
                                   "identifier", "session",
 
410
                                   "manager", manager,
 
411
                                   "transient", TRUE,
 
412
                                   NULL);
 
413
 
404
414
        /* Create the 'session' keyring, which is not stored to disk */
405
 
        self->session_collection = g_object_new (GCK_TYPE_SECRET_COLLECTION,
406
 
                                                 "module", self,
407
 
                                                 "identifier", "session",
408
 
                                                 "manager", manager,
409
 
                                                 NULL);
410
 
        gck_object_expose (GCK_OBJECT (self->session_collection), TRUE);
 
415
        g_return_val_if_fail (gck_object_is_transient (collection), NULL);
 
416
        gck_module_add_token_object (GCK_MODULE (self), NULL, collection);
 
417
        gck_object_expose (collection, TRUE);
411
418
 
412
419
        /* Unlock the 'session' keyring */
413
 
        rv = gck_credential_create (GCK_MODULE (self), manager, GCK_OBJECT (self->session_collection),
 
420
        rv = gck_credential_create (GCK_MODULE (self), manager, GCK_OBJECT (collection),
414
421
                                    NULL, 0, &self->session_credential);
415
422
        if (rv == CKR_OK)
416
423
                gck_object_expose (GCK_OBJECT (self->session_credential), TRUE);
417
424
        else
418
425
                g_warning ("couldn't unlock the 'session' keyring");
419
426
 
 
427
        g_object_unref (collection);
420
428
        return G_OBJECT (self);
421
429
}
422
430
 
438
446
                g_object_unref (self->tracker);
439
447
        self->tracker = NULL;
440
448
 
441
 
        if (self->session_collection)
442
 
                g_object_unref (self->session_collection);
443
 
        self->session_collection = NULL;
444
 
 
445
449
        if (self->session_credential)
446
450
                g_object_unref (self->session_credential);
447
451
        self->session_credential = NULL;
465
469
        self->directory = NULL;
466
470
 
467
471
        g_assert (!self->session_credential);
468
 
        g_assert (!self->session_collection);
469
472
 
470
473
        G_OBJECT_CLASS (gck_secret_module_parent_class)->finalize (obj);
471
474
}
484
487
        module_class->get_token_info = gck_secret_module_real_get_token_info;
485
488
        module_class->parse_argument = gck_secret_module_real_parse_argument;
486
489
        module_class->refresh_token = gck_secret_module_real_refresh_token;
 
490
        module_class->add_token_object = gck_secret_module_real_add_object;
 
491
        module_class->store_token_object = gck_secret_module_real_store_object;
487
492
        module_class->remove_token_object = gck_secret_module_real_remove_object;
488
 
        module_class->store_token_object = gck_secret_module_real_store_object;
489
493
}
490
494
 
491
495
/* ---------------------------------------------------------------------------------------