Submitted by Anonymous on Sat, 03/10/2001 - 18:18. Developers
Hello,
Here is a program which allows to enter a login and a password.
Normally, when password is correct, an XmFormDialog is displayed...
But the program crash when I have entered the password.
// Routine
// *******************
// Filename
// ***************
// GetLoginatt.c
// ***************
// Description
// ***************************************************
// Program who allows to get the username and the
// password of an administrator.
// A dialogbox is displayed.
// ***************************************************
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "Arg.h"
void CheckPasswd();
void CheckUsername();
char *passwd;
void FindUsername(char *, Widget);
int FindPassword(char *, Widget);
void ListParams(Widget);
void UnManage(Widget w);
Widget w;
static Widget main_area;
static Widget password;
void GetLoginatt(Widget w, XtPointer client_data, XtPointer call_data)
{
Widget rowcol, username, ok, undo, pane, dialog;
Arg args[10];
int n = 0;
XmString ok_str = XmStringCreateLocalized("OK");
XmString undo_str = XmStringCreateLocalized("Annuler");
n=0;
XtSetArg(args[n],XmNheight, 250);n++;
XtSetArg(args[n],XmNwidth, 300);n++;
dialog = XmCreateFormDialog(w, "dialog", args, n);
main_area = XtVaCreateWidget("main_area",xmFormWidgetClass,dialog,
NULL,
0, NULL);
n = 0;
ok = XmCreatePushButton(dialog,"OK",args, n);
XtSetArg (args[n], XmNlabelString, ok_str); n++;
XtSetArg (args[n], XmNx, 10); n++;
XtSetArg (args[n], XmNy, 120); n++;
XtSetValues(ok,args,n);
XtManageChild (ok);
n = 0;
undo = XmCreatePushButton(dialog,"Undo",args, n);
XtSetArg (args[n], XmNlabelString, undo_str); n++;
XtSetArg (args[n], XmNx, 70); n++;
XtSetArg (args[n], XmNy, 120); n++;
XtSetValues(undo,args,n);
XtManageChild (undo);
rowcol = XtVaCreateManagedWidget ("rowcol",
xmRowColumnWidgetClass, main_area,NULL);
XtVaCreateManagedWidget ("Nom d`utilisateur",
xmLabelGadgetClass, rowcol, NULL);
username = XtVaCreateManagedWidget ("username",
xmTextFieldWidgetClass, rowcol, NULL);
XtVaCreateManagedWidget ("Mot de passe",
xmLabelGadgetClass, rowcol, NULL);
password = XtVaCreateManagedWidget ("password",
xmTextFieldWidgetClass, rowcol, NULL);
XtManageChild (main_area);
XtManageChild(dialog);
XtPopup(XtParent(dialog), XtGrabNone);
XtAddCallback(username, XmNactivateCallback, CheckUsername, w);
XtAddCallback(password, XmNmodifyVerifyCallback, CheckPasswd, w);
XtAddCallback(password, XmNactivateCallback, CheckPasswd, w);
XtAddCallback(ok, XmNactivateCallback, CheckPasswd, w);
}
void CheckUsername(username, client_data, call_data)
Widget username;
XtPointer client_data;
XtPointer call_data;
{
XmTextVerifyCallbackStruct *cbs =
(XmTextVerifyCallbackStruct *) call_data;
Widget target = (Widget) client_data;
if (cbs->reason == XmCR_ACTIVATE || cbs->reason == XmCR_OK)
{
char *uname = XmTextFieldGetString (username);
printf ("Username %s
", uname);
FindUsername(uname, target);
XmProcessTraversal(username, XmTRAVERSE_NEXT_TAB_GROUP);
XtFree(uname);
return;
}
}
void CheckPasswd(password, client_data, call_data)
Widget password;
XtPointer client_data;
XtPointer call_data;
{
char *new;
int len = 0;
int status = 0;
XmTextVerifyCallbackStruct *cbs =
(XmTextVerifyCallbackStruct *) call_data;
Widget target = (Widget) client_data;
if (cbs->reason == XmCR_ACTIVATE)
{
status = FindPassword(passwd, target);
printf("status=%d
",status);
if (status == 1 )
{
ListParams(target);
}
else
{
return;
}
}
if (cbs->startPos < cbs->currInsert)
{ /* backspace */
cbs->endPos = strlen (passwd); /* delete from here to end */
passwd[cbs->startPos] = 0; /* backspace--terminate */
return;
}
if (cbs->text->length > 1)
{
cbs->doit = False; /* don`t allow "paste" operations */
return; /* make the user *type* the password! */
}
new = XtMalloc (cbs->endPos + 2); /* new char + NULL terminator */
if (passwd)
{
strcpy (new, passwd);
XtFree (passwd);
}
else
{
new[0] = ``;
}
passwd = new;
strncat (passwd, cbs->text->ptr, cbs->text->length);
passwd[cbs->endPos + cbs->text->length] = 0;
for (len = 0; len < cbs->text->length; len++)
cbs->text->ptr[len] = `*`;
}
/******************************************************************/
In function CheckPasswd();
If I write the following syntax
Widget target = (Widget) client_data;
ListParams(target);
the window is displayed but the password isn`t controled.
Does it come of declaration of
XmTextVerifyCallbackStruct *cbs =
(XmTextVerifyCallbackStruct *) call_data;
Widget target = (Widget) client_data;
Or
XtAddCallback(username, XmNactivateCallback, CheckUsername, w);
XtAddCallback(password, XmNmodifyVerifyCallback, CheckPasswd, w);
XtAddCallback(password, XmNactivateCallback, CheckPasswd, w);
I call twice function CheckPasswd() so the secound call I lose
the Widget target, I think.....
But if the callback ListParams(target) is into if condition, the
dilaog box isn`t displayed!!!
It`s very important for me that someone finds a solution.
Sincerly.
Emile.
What is the stack trace for the core dump? It should point you to the offending line.
You can find password-entry code in the O`Reilly Volume 6A book.