1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
/* Krb5 Auth Applet -- Acquire and release kerberos tickets
*
* (C) 2008,2009 Guido Guenther <agx@sigxcpu.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include "config.h"
#include <gconf/gconf-client.h>
#include <string.h>
#include "ka-applet-priv.h"
#include "ka-gconf-tools.h"
#include "ka-gconf.h"
static gboolean
ka_gconf_set_principal (GConfClient* client, KaApplet* applet)
{
gchar* principal = NULL;
if(!ka_gconf_get_string (client, KA_GCONF_KEY_PRINCIPAL, &principal)
|| !strlen(principal)) {
g_free (principal);
principal = g_strdup (g_get_user_name());
}
g_object_set(applet, "principal", principal, NULL);
g_free (principal);
return TRUE;
}
static gboolean
ka_gconf_set_pk_userid (GConfClient* client, KaApplet* applet)
{
gchar* pk_userid = NULL;
if(!ka_gconf_get_string (client, KA_GCONF_KEY_PK_USERID, &pk_userid)) {
pk_userid = g_strdup ("");
}
g_object_set(applet, "pk_userid", pk_userid, NULL);
g_free (pk_userid);
return TRUE;
}
static gboolean
ka_gconf_set_pk_anchors (GConfClient* client, KaApplet* applet)
{
gchar* pk_anchors = NULL;
if(!ka_gconf_get_string (client, KA_GCONF_KEY_PK_ANCHORS, &pk_anchors)) {
pk_anchors = g_strdup ("");
}
g_object_set(applet, "pk_anchors", pk_anchors, NULL);
g_free (pk_anchors);
return TRUE;
}
static gboolean
ka_gconf_set_prompt_mins (GConfClient* client, KaApplet* applet)
{
gint prompt_mins = 0;
if(!ka_gconf_get_int (client, KA_GCONF_KEY_PROMPT_MINS, &prompt_mins)) {
prompt_mins = MINUTES_BEFORE_PROMPTING;
}
g_object_set(applet, "pw-prompt-mins", prompt_mins, NULL);
return TRUE;
}
static gboolean
ka_gconf_set_tgt_forwardable (GConfClient* client, KaApplet* applet)
{
gboolean forwardable = FALSE;
if(!ka_gconf_get_bool(client, KA_GCONF_KEY_FORWARDABLE, &forwardable)) {
forwardable = FALSE;
}
g_object_set(applet, "tgt-forwardable", forwardable, NULL);
return TRUE;
}
static gboolean
ka_gconf_set_tgt_renewable (GConfClient* client, KaApplet* applet)
{
gboolean renewable = FALSE;
if(!ka_gconf_get_bool(client, KA_GCONF_KEY_RENEWABLE, &renewable)) {
renewable = FALSE;
}
g_object_set(applet, "tgt-renewable", renewable, NULL);
return TRUE;
}
static gboolean
ka_gconf_set_tgt_proxiable (GConfClient* client, KaApplet* applet)
{
gboolean proxiable = FALSE;
if(!ka_gconf_get_bool(client, KA_GCONF_KEY_PROXIABLE, &proxiable)) {
proxiable = FALSE;
}
g_object_set(applet, "tgt-proxiable", proxiable, NULL);
return TRUE;
}
static void
ka_gconf_key_changed_callback (GConfClient* client,
guint cnxn_id G_GNUC_UNUSED,
GConfEntry* entry,
gpointer user_data)
{
const char* key;
KaApplet* applet = KA_APPLET(user_data);
key = gconf_entry_get_key (entry);
if (!key)
return;
KA_DEBUG("Key %s changed", key);
if (g_strcmp0 (key, KA_GCONF_KEY_PRINCIPAL) == 0) {
ka_gconf_set_principal (client, applet);
} else if (g_strcmp0 (key, KA_GCONF_KEY_PROMPT_MINS) == 0) {
ka_gconf_set_prompt_mins (client, applet);
} else if (g_strcmp0 (key, KA_GCONF_KEY_PK_USERID) == 0) {
ka_gconf_set_pk_userid (client, applet);
} else if (g_strcmp0 (key, KA_GCONF_KEY_PK_ANCHORS) == 0) {
ka_gconf_set_pk_anchors(client, applet);
} else if (g_strcmp0 (key, KA_GCONF_KEY_FORWARDABLE) == 0) {
ka_gconf_set_tgt_forwardable (client, applet);
} else if (g_strcmp0 (key, KA_GCONF_KEY_RENEWABLE) == 0) {
ka_gconf_set_tgt_renewable (client, applet);
} else if (g_strcmp0 (key, KA_GCONF_KEY_PROXIABLE) == 0) {
ka_gconf_set_tgt_proxiable (client, applet);
} else if (g_strcmp0 (key, KA_GCONF_KEY_NOTIFY_VALID)
|| g_strcmp0 (key, KA_GCONF_KEY_NOTIFY_EXPIRING)
|| g_strcmp0 (key, KA_GCONF_KEY_NOTIFY_EXPIRED)
|| g_strcmp0 (key, KA_GCONF_KEY_PLUGINS_ENABLED)) {
/* nothing to do */
} else
g_warning("Received notification for unknown gconf key %s", key);
return;
}
GConfClient*
ka_gconf_init (KaApplet* applet)
{
GError *error = NULL;
GConfClient *client;
client = gconf_client_get_default ();
gconf_client_add_dir (client, KA_GCONF_PATH, GCONF_CLIENT_PRELOAD_ONELEVEL, &error);
if (error)
goto out;
gconf_client_notify_add (client, KA_GCONF_PATH,
ka_gconf_key_changed_callback, applet, NULL, &error);
if (error)
goto out;
/* setup defaults */
ka_gconf_set_principal (client, applet);
ka_gconf_set_prompt_mins (client, applet);
ka_gconf_set_pk_userid(client, applet);
ka_gconf_set_pk_anchors(client, applet);
ka_gconf_set_tgt_forwardable(client, applet);
ka_gconf_set_tgt_renewable(client, applet);
ka_gconf_set_tgt_proxiable(client, applet);
out:
if (error) {
client = NULL;
g_warning ("%s", error->message);
g_clear_error (&error);
}
return client;
}
|