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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
/*
* Copyright 1993-1994 OpenVision Technologies, Inc., All Rights Reserved.
*
* $Header$
*
*
*/
static char rcsid_2[] = "$Id$";
#include <kadm5/admin.h>
#include <krb5.h>
#include "kpasswd_strings.h"
#define string_text error_message
#define initialize_kpasswd_strings initialize_kpws_error_table
#include <stdio.h>
#include <pwd.h>
#include <string.h>
char *whoami;
#include <Xm/Xm.h>
#include <Xm/MessageB.h>
#include <Xm/ScrolledW.h>
#include <Xm/Form.h>
#include <Xm/Text.h>
#include <Xm/PushB.h>
#include <Xm/Label.h>
#include <Xm/Separator.h>
#include <X11/cursorfont.h>
#include <X11/Shell.h>
Widget toplevel, scroll_text, prompt_text;
Widget quit_btn, help_btn, old_lbl, new_lbl, again_lbl, main_lbl;
XtAppContext app_con;
int looping;
int retval=0;
/***************************************************************************
*
* A few utility functions for setting/unsetting the busy cursor
* (i.e. the watch cursor).
*/
static void
SetCursor(w,c)
Widget w;
Cursor c;
{
while (XtIsSubclass(w, shellWidgetClass) != True)
w = XtParent(w);
XDefineCursor(XtDisplay(w), XtWindow(w), c);
XFlush(XtDisplay(w));
}
static void
SetStandardCursor()
{
static Cursor ArrowCursor = (Cursor)NULL;
if (ArrowCursor == (Cursor)NULL)
ArrowCursor = XCreateFontCursor(XtDisplay(toplevel), XC_top_left_arrow);
SetCursor(toplevel, ArrowCursor);
}
static void
SetWatchCursor()
{
static Cursor WatchCursor = (Cursor)NULL;
if (WatchCursor == (Cursor)NULL)
WatchCursor = XCreateFontCursor(XtDisplay(toplevel), XC_watch);
SetCursor(toplevel, WatchCursor);
}
/***************************************************************************
*
* Set up a com_err hook, for displaying to a motif scrolling widget.
*/
#include <stdarg.h>
static void
#ifdef __STDC__
motif_com_err (const char *whoami, long code, const char *fmt, va_list args)
#else
motif_com_err (whoami, code, fmt, args)
const char *whoami;
long code;
const char *fmt;
va_list args;
#endif
{
XEvent event;
char buf[2048];
buf[0] = '\0';
if (whoami)
{
strncpy(buf, whoami, sizeof(buf) - 1);
buf[sizeof(buf) - 1] = '\0';
strncat(buf, ": ", sizeof(buf) - 1 - strlen(buf));
}
if (code)
{
buf[sizeof(buf) - 1] = '\0';
strncat(buf, error_message(code), sizeof(buf) - 1 - strlen(buf));
strncat(buf, " ", sizeof(buf) - 1 - strlen(buf));
}
if (fmt)
{
vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, args);
}
XtVaSetValues(scroll_text, XmNvalue, buf, NULL);
for (; XtAppPending(app_con); )
{
XtAppNextEvent(app_con, &event);
XtDispatchEvent(&event);
}
}
/***************************************************************************
*
* Function to display help widget.
*/
static void
help()
{
static Widget help_dlg = NULL;
if (!help_dlg)
{
help_dlg = XmCreateInformationDialog(toplevel, "help_dlg", NULL,
0);
XtUnmanageChild(XmMessageBoxGetChild(help_dlg, XmDIALOG_CANCEL_BUTTON));
XtUnmanageChild(XmMessageBoxGetChild(help_dlg, XmDIALOG_HELP_BUTTON));
}
XtManageChild(help_dlg);
}
/***************************************************************************
*
* Unset the global "looping" when we want to get out of reading a
* password.
*/
static void
unset_looping()
{
looping = 0;
}
/***************************************************************************
*
* Function to exit the gui. Callback on the "Exit" button.
*/
static void
quit()
{
exit(retval);
}
/***************************************************************************
*
* Set up motif widgets, callbacks, etc.
*/
static void
create_widgets(argc, argv)
int *argc;
char *argv[];
{
Widget form, lbl_form,
sep,
scroll_win;
Pixel bg;
toplevel = XtAppInitialize(&app_con, "Kpasswd", NULL, 0, argc, argv,
NULL, NULL, 0);
form = XtCreateManagedWidget("form", xmFormWidgetClass, toplevel, NULL, 0);
quit_btn = XtVaCreateManagedWidget("Quit", xmPushButtonWidgetClass,
form,
XmNleftAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
XtAddCallback(quit_btn, XmNactivateCallback, quit, 0);
help_btn = XtVaCreateManagedWidget("Help", xmPushButtonWidgetClass,
form,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
/* XmNshowAsDefault, TRUE, */
NULL);
XtAddCallback(help_btn, XmNactivateCallback, help, 0);
sep = XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass,
form,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, quit_btn,
NULL);
lbl_form = XtVaCreateManagedWidget("lbl_form", xmFormWidgetClass,
form,
XmNspacing, 0,
XmNleftAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, sep,
NULL);
old_lbl = XtVaCreateManagedWidget("old_lbl", xmLabelWidgetClass,
lbl_form,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
new_lbl = XtVaCreateManagedWidget("new_lbl", xmLabelWidgetClass,
lbl_form,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
again_lbl = XtVaCreateManagedWidget("again_lbl", xmLabelWidgetClass,
lbl_form,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
prompt_text = XtVaCreateManagedWidget("prompt_text", xmTextWidgetClass,
form,
XmNeditMode, XmSINGLE_LINE_EDIT,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, lbl_form,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, sep,
NULL);
XtAddCallback(prompt_text, XmNactivateCallback, unset_looping, 0);
XtVaGetValues(prompt_text, XmNbackground, &bg, NULL);
XtVaSetValues(prompt_text, XmNforeground, bg, NULL);
main_lbl = XtVaCreateWidget("main_lbl", xmLabelWidgetClass,
form,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
scroll_win = XtVaCreateManagedWidget("scroll_win",
xmScrolledWindowWidgetClass,
form,
XmNscrollingPolicy, XmAPPLICATION_DEFINED,
XmNscrollBarDisplayPolicy, XmSTATIC,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, main_lbl,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, prompt_text,
NULL);
scroll_text = XtVaCreateManagedWidget("scroll_text", xmTextWidgetClass,
scroll_win,
XmNeditMode, XmMULTI_LINE_EDIT,
XmNeditable, FALSE,
NULL);
XtRealizeWidget(toplevel);
}
/***************************************************************************
*
*
*/
static long
read_password(password, pwsize)
char *password;
int *pwsize;
{
XEvent event;
char *text_val;
/* OK, this next part is gross... but this is due to the fact that */
/* this is not your traditional X program, which would be event */
/* driven. Instead, this program is more 'CLI' in nature, so we */
/* handle the dialogs synchronously... */
XtVaSetValues(prompt_text, XmNmaxLength, *pwsize, XmNvalue, "", NULL);
for (looping=1; looping; )
{
XtAppNextEvent(app_con, &event);
XtDispatchEvent(&event);
}
XtVaGetValues(prompt_text, XmNvalue, &text_val, NULL);
*pwsize = strlen(text_val);
strcpy(password, text_val);
memset(text_val, 0, *pwsize);
XtVaSetValues(prompt_text, XmNvalue, text_val, NULL);
return(0);
}
/***************************************************************************
*
*
*/
void
display_intro_message(fmt_string, arg_string)
const char *fmt_string;
const char *arg_string;
{
XmString xmstr;
char buf[1024];
snprintf(buf, sizeof(buf), fmt_string, arg_string);
xmstr = XmStringCreateLtoR(buf, XmSTRING_DEFAULT_CHARSET);
XtVaSetValues(main_lbl, XmNlabelString, xmstr, NULL);
XmStringFree(xmstr);
XtManageChild(main_lbl);
}
long
read_old_password(context, password, pwsize)
krb5_context context;
char *password;
unsigned int *pwsize;
{
long code;
XtManageChild(old_lbl);
code = read_password(password, pwsize);
SetWatchCursor();
return code;
}
long
read_new_password(server_handle, password, pwsize, msg_ret, princ)
void *server_handle;
char *password;
unsigned int *pwsize;
char *msg_ret;
krb5_principal princ;
{
char *password2 = (char *) malloc(*pwsize * sizeof(char));
int pwsize2 = *pwsize;
SetStandardCursor();
if (password2 == NULL)
{
strcpy(msg_ret, error_message(ENOMEM));
SetWatchCursor();
return(ENOMEM);
}
XtManageChild(new_lbl); XtUnmanageChild(old_lbl);
read_password(password, pwsize);
XtManageChild(again_lbl); XtUnmanageChild(new_lbl);
read_password(password2, &pwsize2);
if (strcmp(password, password2))
{
memset(password, 0, *pwsize);
memset(password2, 0, pwsize2);
free(password2);
strcpy(msg_ret, string_text(CHPASS_UTIL_NEW_PASSWORD_MISMATCH));
SetWatchCursor();
return(KRB5_LIBOS_BADPWDMATCH);
}
memset(password2, 0, pwsize2);
free(password2);
SetWatchCursor();
return (ovsec_kadm_chpass_principal_util(server_handle, princ, password,
NULL /* don't need new pw back */,
msg_ret));
}
/***************************************************************************
*
*
*/
void
main(argc, argv)
int argc;
char *argv[];
{
krb5_context context;
int code;
initialize_kpasswd_strings();
whoami = (whoami = strrchr(argv[0], '/')) ? whoami + 1 : argv[0];
(void) set_com_err_hook(motif_com_err);
create_widgets(&argc, argv);
XmProcessTraversal(prompt_text, XmTRAVERSE_CURRENT);
if (retval = krb5_init_context(&context)) {
com_err(whoami, retval, "initializing krb5 context");
exit(retval);
}
while (1)
{
retval = kpasswd(context, argc, argv);
SetStandardCursor();
if (!retval)
com_err(0, 0, string_text(KPW_STR_PASSWORD_CHANGED));
if (retval == 0) /* 0 is success, so presumably the user */
/* is done. */
XmProcessTraversal(quit_btn, XmTRAVERSE_CURRENT);
if ((retval == 1) || /* the rest are "fatal", so we should */
(retval == 3) || /* "force" the user to quit... */
(retval == 6) ||
(retval == 7))
{
XtSetSensitive(prompt_text, FALSE);
XmProcessTraversal(quit_btn, XmTRAVERSE_CURRENT);
XtAppMainLoop(app_con);
}
}
/* NOTREACHED */
exit(retval);
}
|