Line data Source code
1 : /*
2 : * gnome-keyring
3 : *
4 : * Copyright (C) 2018 Red Hat, Inc.
5 : *
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.
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 Public License for more details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public
17 : * License along with this program; if not, see
18 : * <http://www.gnu.org/licenses/>.
19 : *
20 : * Author: Daiki Ueno
21 : */
22 :
23 : #include "config.h"
24 :
25 : #include "gkd-login-password.h"
26 :
27 : #include <gcr/gcr-unlock-options.h>
28 : #include "gkd-login.h"
29 :
30 : enum {
31 : PROP_0,
32 : PROP_BASE,
33 : PROP_LOGIN_AVAILABLE
34 : };
35 :
36 : struct _GkdLoginPassword
37 : {
38 : GTlsPassword password;
39 :
40 : GTlsPassword *base;
41 : gboolean login_available;
42 : gboolean store_password;
43 : };
44 :
45 0 : G_DEFINE_TYPE (GkdLoginPassword, gkd_login_password, G_TYPE_TLS_PASSWORD);
46 :
47 : static void
48 0 : gkd_login_password_init (GkdLoginPassword *self)
49 : {
50 0 : }
51 :
52 : static const guchar *
53 0 : gkd_login_password_get_value (GTlsPassword *password,
54 : gsize *length)
55 : {
56 0 : GkdLoginPassword *self = GKD_LOGIN_PASSWORD (password);
57 :
58 0 : return g_tls_password_get_value (self->base, length);
59 : }
60 :
61 : static void
62 0 : gkd_login_password_set_value (GTlsPassword *password,
63 : guchar *value,
64 : gssize length,
65 : GDestroyNotify destroy)
66 : {
67 0 : GkdLoginPassword *self = GKD_LOGIN_PASSWORD (password);
68 :
69 0 : g_tls_password_set_value_full (self->base, value, length, destroy);
70 0 : }
71 :
72 : static void
73 0 : gkd_login_password_set_property (GObject *object,
74 : guint prop_id,
75 : const GValue *value,
76 : GParamSpec *pspec)
77 : {
78 0 : GkdLoginPassword *self = GKD_LOGIN_PASSWORD (object);
79 :
80 0 : switch (prop_id)
81 : {
82 0 : case PROP_BASE:
83 0 : self->base = g_value_dup_object (value);
84 0 : break;
85 0 : case PROP_LOGIN_AVAILABLE:
86 0 : self->login_available = g_value_get_boolean (value);
87 0 : break;
88 0 : default:
89 0 : G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
90 0 : break;
91 : }
92 0 : }
93 :
94 : static void
95 0 : gkd_login_password_dispose (GObject *object)
96 : {
97 0 : GkdLoginPassword *self = GKD_LOGIN_PASSWORD (object);
98 :
99 0 : g_clear_object (&self->base);
100 :
101 0 : G_OBJECT_CLASS (gkd_login_password_parent_class)->dispose (object);
102 0 : }
103 :
104 : static void
105 0 : gkd_login_password_class_init (GkdLoginPasswordClass *klass)
106 : {
107 0 : GTlsPasswordClass *password_class = G_TLS_PASSWORD_CLASS (klass);
108 0 : GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
109 :
110 0 : password_class->get_value = gkd_login_password_get_value;
111 0 : password_class->set_value = gkd_login_password_set_value;
112 :
113 0 : gobject_class->set_property = gkd_login_password_set_property;
114 0 : gobject_class->dispose = gkd_login_password_dispose;
115 :
116 0 : g_object_class_install_property (gobject_class, PROP_BASE,
117 : g_param_spec_object ("base", "Base", "Base",
118 : G_TYPE_TLS_PASSWORD,
119 : G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
120 0 : g_object_class_install_property (gobject_class, PROP_LOGIN_AVAILABLE,
121 : g_param_spec_boolean ("login-available", "Login-available", "Login-available",
122 : FALSE,
123 : G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
124 0 : }
125 :
126 : gboolean
127 0 : gkd_login_password_get_login_available (GkdLoginPassword *self)
128 : {
129 0 : return self->login_available;
130 : }
131 :
132 : void
133 0 : gkd_login_password_set_store_password (GkdLoginPassword *self,
134 : gboolean store_password)
135 : {
136 0 : self->store_password = store_password;
137 0 : }
138 :
139 : gboolean
140 0 : gkd_login_password_get_store_password (GkdLoginPassword *self)
141 : {
142 0 : return self->store_password;
143 : }
|