4
* Copyright (C) 2008 Stefan Walter
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as
8
* published by the Free Software Foundation; either version 2.1 of
9
* the License, or (at your option) any later version.
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 Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public
17
* License along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24
#include "gck-login.h"
26
#include "egg/egg-secure-memory.h"
36
G_DEFINE_TYPE (GckLogin, gck_login, G_TYPE_OBJECT);
38
/* -----------------------------------------------------------------------------
43
gck_login_init (GckLogin *self)
49
gck_login_dispose (GObject *obj)
51
GckLogin *self = GCK_LOGIN (obj);
53
egg_secure_strfree (self->password);
54
self->password = NULL;
57
G_OBJECT_CLASS (gck_login_parent_class)->dispose (obj);
61
gck_login_finalize (GObject *obj)
63
GckLogin *self = GCK_LOGIN (obj);
65
g_assert (!self->password);
66
g_assert (!self->n_password);
68
G_OBJECT_CLASS (gck_login_parent_class)->finalize (obj);
72
gck_login_set_property (GObject *obj, guint prop_id, const GValue *value,
77
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
83
gck_login_get_property (GObject *obj, guint prop_id, GValue *value,
88
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
94
gck_login_class_init (GckLoginClass *klass)
96
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
98
gobject_class->dispose = gck_login_dispose;
99
gobject_class->finalize = gck_login_finalize;
100
gobject_class->set_property = gck_login_set_property;
101
gobject_class->get_property = gck_login_get_property;
104
/* -----------------------------------------------------------------------------
109
gck_login_new (CK_UTF8CHAR_PTR pin, CK_ULONG n_pin)
111
GckLogin *login = g_object_new (GCK_TYPE_LOGIN, NULL);
114
if (n_pin == (CK_ULONG)-1) {
115
login->password = egg_secure_strdup ((const gchar*)pin);
116
login->n_password = strlen (login->password);
118
login->password = egg_secure_alloc (n_pin + 1);
119
memcpy (login->password, pin, n_pin);
120
login->n_password = n_pin;
123
login->password = NULL;
124
login->n_password = 0;
131
gck_login_get_password (GckLogin *self, gsize *n_password)
133
g_return_val_if_fail (GCK_IS_LOGIN (self), NULL);
134
g_return_val_if_fail (n_password, NULL);
135
*n_password = self->n_password;
136
return self->password;
140
gck_login_equals (GckLogin *self, CK_UTF8CHAR_PTR pin, CK_ULONG n_pin)
142
g_return_val_if_fail (GCK_IS_LOGIN (self), FALSE);
144
if (n_pin == (CK_ULONG)-1 && pin != NULL)
145
n_pin = strlen ((const gchar*)pin);
147
if (n_pin != self->n_password)
149
if (!pin && !self->password)
151
if (!pin || !self->password)
153
return memcmp (pin, self->password, n_pin) == 0;