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

« back to all changes in this revision

Viewing changes to pkcs11/gkm/mock-locked-object.c

  • Committer: Package Import Robot
  • Author(s): Dimitri John Ledkov
  • Date: 2014-12-06 18:47:09 UTC
  • mfrom: (116.2.6 sid)
  • Revision ID: package-import@ubuntu.com-20141206184709-r2sbrchgej06j31z
Tags: 3.14.0-1ubuntu1
* Merge from debian, remaining changes:
  - Build with dh-autoreconf for new libtool.  
  - Provide upstart user session jobs.
  * debian/gnome-keyring.ubiquity, debian/rules:
    - Apply capabilities at the end of the ubiquity process to make sure new
      installs have gnome-keyring-daemon with cap_ipc_lock+ep.
  * debian/control, debian/*.install, debian/rules:
    - change for multiarch support, install pkcs11 in its own binary

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * gnome-keyring
 
3
 *
 
4
 * Copyright (C) 2009 Stefan Walter
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General  License as
 
8
 * published by the Free Software Foundation; either version 2.1 of
 
9
 * the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful, but
 
12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General  License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General
 
17
 * License along with this program; if not, see
 
18
 * <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include "mock-locked-object.h"
 
24
 
 
25
#include "gkm/gkm-attributes.h"
 
26
#include "gkm/gkm-credential.h"
 
27
 
 
28
G_DEFINE_TYPE (MockLockedObject, mock_locked_object, GKM_TYPE_OBJECT);
 
29
 
 
30
/* -----------------------------------------------------------------------------
 
31
 * INTERNAL
 
32
 */
 
33
 
 
34
/* -----------------------------------------------------------------------------
 
35
 * KEY
 
36
 */
 
37
 
 
38
static CK_RV
 
39
mock_locked_object_real_get_attribute (GkmObject *base, GkmSession *session, CK_ATTRIBUTE* attr)
 
40
{
 
41
        switch (attr->type) {
 
42
        case CKA_CLASS:
 
43
                return gkm_attribute_set_ulong (attr, CKO_DATA);
 
44
        case CKA_ALWAYS_AUTHENTICATE:
 
45
                return gkm_attribute_set_bool (attr, TRUE);
 
46
        };
 
47
 
 
48
        return GKM_OBJECT_CLASS (mock_locked_object_parent_class)->get_attribute (base, session, attr);
 
49
}
 
50
 
 
51
static CK_RV
 
52
mock_locked_object_real_unlock (GkmObject *base, GkmCredential *auth)
 
53
{
 
54
        const gchar *password;
 
55
        gsize n_password;
 
56
 
 
57
        password = gkm_credential_get_password (auth, &n_password);
 
58
        if (n_password == 4 && memcmp (password, "mock", 4) == 0)
 
59
                return CKR_OK;
 
60
 
 
61
        return CKR_USER_NOT_LOGGED_IN;
 
62
}
 
63
 
 
64
static void
 
65
mock_locked_object_init (MockLockedObject *self)
 
66
{
 
67
 
 
68
}
 
69
 
 
70
static void
 
71
mock_locked_object_class_init (MockLockedObjectClass *klass)
 
72
{
 
73
        GkmObjectClass *gkm_class = GKM_OBJECT_CLASS (klass);
 
74
        mock_locked_object_parent_class = g_type_class_peek_parent (klass);
 
75
        gkm_class->get_attribute = mock_locked_object_real_get_attribute;
 
76
        gkm_class->unlock = mock_locked_object_real_unlock;
 
77
}
 
78
 
 
79
/* -----------------------------------------------------------------------------
 
80
 * PUBLIC
 
81
 */
 
82
 
 
83
GkmObject*
 
84
mock_locked_object_new (GkmModule *module, GkmManager *manager)
 
85
{
 
86
        return g_object_new (MOCK_TYPE_LOCKED_OBJECT,
 
87
                             "module", module,
 
88
                             "manager", manager,
 
89
                             NULL);
 
90
}