~ubuntu-branches/ubuntu/maverick/gnome-keyring/maverick-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-03-02 17:00:10 UTC
  • mto: (2.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: james.westby@ubuntu.com-20090302170010-1bakcvrq713wq2q0
Tags: upstream-2.25.92
ImportĀ upstreamĀ versionĀ 2.25.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
        GckModule parent;
41
41
        GckUserStorage *storage;
42
42
        gchar *directory;
43
 
        GHashTable *logged_in_apps;
 
43
        GHashTable *unlocked_apps;
44
44
        CK_TOKEN_INFO token_info;
45
45
};
46
46
 
181
181
        CK_RV rv;
182
182
 
183
183
        /* See if this application has logged in */
184
 
        if (g_hash_table_lookup (self->logged_in_apps, &slot_id))
 
184
        if (g_hash_table_lookup (self->unlocked_apps, &slot_id))
185
185
                return CKR_USER_ALREADY_LOGGED_IN;
186
186
 
187
187
        login = gck_user_storage_get_login (self->storage);
188
188
        
189
189
        /* No application is logged in */
190
 
        if (g_hash_table_size (self->logged_in_apps) == 0) {
 
190
        if (g_hash_table_size (self->unlocked_apps) == 0) {
191
191
 
192
192
                g_return_val_if_fail (login == NULL, CKR_GENERAL_ERROR);
193
193
 
210
210
 
211
211
        /* Note that this application logged in */
212
212
        if (rv == CKR_OK) {
213
 
                g_hash_table_insert (self->logged_in_apps, gck_util_ulong_alloc (slot_id), UNUSED_VALUE);
 
213
                g_hash_table_insert (self->unlocked_apps, gck_util_ulong_alloc (slot_id), UNUSED_VALUE);
214
214
                rv = GCK_MODULE_CLASS (gck_user_module_parent_class)->login_user (base, slot_id, pin, n_pin);
215
215
        }
216
216
        
218
218
}
219
219
 
220
220
static CK_RV 
 
221
gck_user_module_real_login_so (GckModule *base, CK_SLOT_ID slot_id, CK_UTF8CHAR_PTR pin, CK_ULONG n_pin)
 
222
{
 
223
        GckUserModule *self = GCK_USER_MODULE (base);
 
224
        
 
225
        /* See if this application has unlocked, in which case we can't login */
 
226
        if (g_hash_table_lookup (self->unlocked_apps, &slot_id))
 
227
                return CKR_USER_ALREADY_LOGGED_IN;
 
228
        
 
229
        /* Note that for an SO login, we don't actually unlock, and pin is always blank */
 
230
        if (n_pin != 0)
 
231
                return CKR_PIN_INCORRECT;
 
232
 
 
233
        return GCK_MODULE_CLASS (gck_user_module_parent_class)->login_so (base, slot_id, pin, n_pin);
 
234
}
 
235
 
 
236
static CK_RV 
221
237
gck_user_module_real_logout_user (GckModule *base, CK_SLOT_ID slot_id)
222
238
{
223
239
        GckUserModule *self = GCK_USER_MODULE (base);
224
240
        CK_RV rv;
225
241
        
226
 
        if (!g_hash_table_remove (self->logged_in_apps, &slot_id))
 
242
        if (!g_hash_table_remove (self->unlocked_apps, &slot_id))
227
243
                return CKR_USER_NOT_LOGGED_IN;
228
244
        
229
 
        if (g_hash_table_size (self->logged_in_apps) > 0)
 
245
        if (g_hash_table_size (self->unlocked_apps) > 0)
230
246
                return CKR_OK;
231
247
        
232
248
        rv = gck_user_storage_lock (self->storage);
252
268
static void
253
269
gck_user_module_init (GckUserModule *self)
254
270
{
255
 
        self->logged_in_apps = g_hash_table_new_full (gck_util_ulong_hash, gck_util_ulong_equal, gck_util_ulong_free, NULL);
 
271
        self->unlocked_apps = g_hash_table_new_full (gck_util_ulong_hash, gck_util_ulong_equal, gck_util_ulong_free, NULL);
256
272
        
257
273
        /* Our default token info, updated as module runs */
258
274
        memcpy (&self->token_info, &user_module_token_info, sizeof (CK_TOKEN_INFO));
271
287
                g_object_unref (self->storage);
272
288
        self->storage = NULL;
273
289
        
274
 
        g_hash_table_remove_all (self->logged_in_apps);
 
290
        g_hash_table_remove_all (self->unlocked_apps);
275
291
    
276
292
        G_OBJECT_CLASS (gck_user_module_parent_class)->dispose (obj);
277
293
}
283
299
        
284
300
        g_assert (self->storage == NULL);
285
301
        
286
 
        g_assert (self->logged_in_apps);
287
 
        g_hash_table_destroy (self->logged_in_apps);
288
 
        self->logged_in_apps = NULL;
 
302
        g_assert (self->unlocked_apps);
 
303
        g_hash_table_destroy (self->unlocked_apps);
 
304
        self->unlocked_apps = NULL;
289
305
        
290
306
        g_free (self->directory);
291
307
        self->directory = NULL;
310
326
        module_class->store_token_object = gck_user_module_real_store_token_object;
311
327
        module_class->remove_token_object = gck_user_module_real_remove_token_object;
312
328
        module_class->login_user = gck_user_module_real_login_user;
 
329
        module_class->login_so = gck_user_module_real_login_so;
313
330
        module_class->logout_user = gck_user_module_real_logout_user;
314
331
        module_class->login_change = gck_user_module_real_login_change;
315
332
}