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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
#include "config.h"
#include <gtk/gtk.h>
#include <libgnome/libgnome.h>
#include <gdk/gdkkeysyms.h>
#include "greeter_item_pam.h"
#include "greeter_parser.h"
#include "gdm.h"
#include "gdmwm.h"
#include "vicious.h"
#include <string.h>
static gboolean messages_to_give = FALSE;
static gboolean replace_msg = TRUE;
static guint err_box_clear_handler = 0;
static gboolean entry_is_login = FALSE;
extern gboolean DOING_GDM_DEVELOPMENT;
extern gboolean GdmSystemMenu;
gchar *greeter_current_user = NULL;
void
greeter_item_pam_set_user (const char *user)
{
g_free (greeter_current_user);
greeter_current_user = g_strdup (user);
}
static void
user_pw_activate (GtkEntry *entry, GreeterItemInfo *info)
{
char *tmp;
GreeterItemInfo *error_info;
gtk_widget_set_sensitive (GTK_WIDGET (entry), FALSE);
/* Save login. I'm making the assumption that login is always
* the first thing entered. This might not be true for all PAM
* setups. Needs thinking!
*/
if (entry_is_login) {
g_free (greeter_current_user);
greeter_current_user = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
}
/* clear the err_box */
if (err_box_clear_handler > 0)
{
g_source_remove (err_box_clear_handler);
err_box_clear_handler = 0;
}
error_info = greeter_lookup_id ("pam-error");
if (error_info)
g_object_set (G_OBJECT (error_info->item),
"text", "",
NULL);
entry_is_login = FALSE;
tmp = ve_locale_from_utf8 (gtk_entry_get_text (GTK_ENTRY (entry)));
printf ("%c%s\n", STX, tmp);
fflush (stdout);
g_free (tmp);
}
gboolean
greeter_item_pam_setup (void)
{
GreeterItemInfo *entry_info;
entry_info = greeter_lookup_id ("user-pw-entry");
if (entry_info && entry_info->item &&
GNOME_IS_CANVAS_WIDGET (entry_info->item))
{
GtkWidget *entry;
entry = GNOME_CANVAS_WIDGET (entry_info->item)->widget;
gtk_widget_grab_focus (entry);
if ( ! DOING_GDM_DEVELOPMENT)
{
/* hack. For some reason if we leave it blank,
* we'll get a little bit of activity on first keystroke,
* this way we get rid of it, it will be cleared for the
* first prompt anyway. */
gtk_entry_set_text (GTK_ENTRY (entry), "...");
/* initially insensitive */
gtk_widget_set_sensitive (entry, FALSE);
}
g_signal_connect (entry, "activate",
GTK_SIGNAL_FUNC (user_pw_activate), entry_info);
}
return TRUE;
}
void
greeter_item_pam_prompt (const char *message,
int entry_len,
gboolean entry_visible,
gboolean is_login)
{
GreeterItemInfo *conversation_info;
GreeterItemInfo *entry_info;
GtkWidget *entry;
entry_is_login = is_login;
conversation_info = greeter_lookup_id ("pam-prompt");
entry_info = greeter_lookup_id ("user-pw-entry");
if (conversation_info)
g_object_set (G_OBJECT (conversation_info->item),
"text", message,
NULL);
if (entry_info && entry_info->item &&
GNOME_IS_CANVAS_WIDGET (entry_info->item))
{
entry = GNOME_CANVAS_WIDGET (entry_info->item)->widget;
gtk_entry_set_visibility (GTK_ENTRY (entry), entry_visible);
gtk_widget_set_sensitive (GTK_WIDGET (entry), TRUE);
gtk_entry_set_max_length (GTK_ENTRY (entry), entry_len);
gtk_entry_set_text (GTK_ENTRY (entry), "");
gtk_widget_grab_focus (entry);
}
messages_to_give = FALSE;
replace_msg = TRUE;
}
void
greeter_item_pam_message (const char *message)
{
GreeterItemInfo *message_info;
char *oldtext;
char *newtext;
/* the user has not yet seen messages */
messages_to_give = TRUE;
message_info = greeter_lookup_id ("pam-message");
if (message_info)
{
/* HAAAAAAACK. Sometimes pam sends many many messages, SO
* we try to collect them until the next prompt or reset or
* whatnot */
if (!replace_msg)
{
g_object_get (G_OBJECT (message_info->item),
"text", &oldtext,
NULL);
if (strlen (oldtext) > 0)
{
newtext = g_strdup_printf ("%s\n%s", oldtext, message);
g_object_set (G_OBJECT (message_info->item),
"text", newtext,
NULL);
g_free (newtext);
}
else
g_object_set (G_OBJECT (message_info->item),
"text", message,
NULL);
}
else
g_object_set (G_OBJECT (message_info->item),
"text", message,
NULL);
}
replace_msg = FALSE;
}
static gboolean
error_clear (gpointer data)
{
GreeterItemInfo *error_info = data;
g_object_set (G_OBJECT (error_info->item),
"text", "",
NULL);
err_box_clear_handler = 0;
return FALSE;
}
static char *
break_at (const char *orig, int len)
{
char *text, *p, *newline;
int i;
text = g_strdup (orig);
p = text;
while (strlen (p) > len)
{
newline = strchr (p, '\n');
if (newline &&
((newline - p) < len))
{
p = newline + 1;
continue;
}
for (i = MIN (len, strlen (p)-1); i > 0; i--)
{
if (p[i] == ' ')
{
p[i] = '\n';
p = p + i + 1;
goto out;
}
}
/* No place to break. give up */
p = p + 80;
out:
}
return text;
}
void
greeter_item_pam_error (const char *message)
{
GreeterItemInfo *error_info;
char *text;
/* The message I got from pam had a silly newline
* in the beginning. That may make sense for a
* terminal based conversation, but it sucks for
* us, so skip it.
*/
if (message[0] == '\n')
message++;
error_info = greeter_lookup_id ("pam-error");
if (error_info)
{
/* This is a bad hack that I added because
* the canvas text item doesn't support
* text wrapping...
*/
text = break_at (message, 50);
g_object_set (G_OBJECT (error_info->item),
"text", text,
NULL);
g_free (text);
if (err_box_clear_handler > 0)
g_source_remove (err_box_clear_handler);
if (strlen (message) == 0)
err_box_clear_handler = 0;
else
err_box_clear_handler = g_timeout_add (30000,
error_clear,
error_info);
}
}
void
greeter_item_pam_leftover_messages (void)
{
if (messages_to_give)
{
char *oldtext = NULL;
GreeterItemInfo *message_info;
message_info = greeter_lookup_id ("pam-message");
if (message_info != NULL)
{
g_object_get (G_OBJECT (message_info->item),
"text", &oldtext,
NULL);
}
if ( ! ve_string_empty (oldtext))
{
GtkWidget *dlg;
/* we should be now fine for focusing new windows */
gdm_wm_focus_new_windows (TRUE);
dlg = gtk_message_dialog_new (NULL /* parent */,
GTK_DIALOG_MODAL /* flags */,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"%s",
oldtext);
gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);
gdm_wm_center_window (GTK_WINDOW (dlg));
gdm_wm_no_login_focus_push ();
gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_destroy (dlg);
gdm_wm_no_login_focus_pop ();
}
messages_to_give = FALSE;
}
}
|