65
void KGVerifyHandler::updateStatus( bool, bool, int )
65
void KGVerifyHandler::updateStatus(bool, bool, int)
69
KGVerify::KGVerify( KGVerifyHandler *_handler,
70
QWidget *_parent, QWidget *_predecessor,
71
const QString &_fixedUser,
72
const PluginList &_pluginList,
73
KGreeterPlugin::Function _func,
74
KGreeterPlugin::Context _ctx )
76
, coreState( CoreIdle )
77
, fixedEntity( _fixedUser )
78
, pluginList( _pluginList )
81
, predecessor( _predecessor )
69
KGVerify::KGVerify(KGVerifyHandler *_handler,
70
QWidget *_parent, QWidget *_predecessor,
71
const QString &_fixedUser,
72
const PluginList &_pluginList,
73
KGreeterPlugin::Function _func,
74
KGreeterPlugin::Context _ctx)
77
, fixedEntity(_fixedUser)
78
, pluginList(_pluginList)
81
, predecessor(_predecessor)
93
sockNot = new QSocketNotifier( rfd, QSocketNotifier::Read, this );
94
sockNot->setEnabled( false );
95
connect( sockNot, SIGNAL(activated( int )), SLOT(handleVerify()) );
97
connect( &timer, SIGNAL(timeout()), SLOT(slotTimeout()) );
98
connect( qApp, SIGNAL(activity()), SLOT(slotActivity()) );
100
_parent->installEventFilter( this );
93
sockNot = new QSocketNotifier(rfd, QSocketNotifier::Read, this);
94
sockNot->setEnabled(false);
95
connect(sockNot, SIGNAL(activated(int)), SLOT(handleVerify()));
97
connect(&timer, SIGNAL(timeout()), SLOT(slotTimeout()));
98
connect(qApp, SIGNAL(activity()), SLOT(slotActivity()));
100
_parent->installEventFilter(this);
103
103
KGVerify::~KGVerify()
105
debug( "delete %s\n", pName.data() );
105
debug("delete %s\n", pName.data());
110
110
KGVerify::getPlugMenu()
112
// assert( coreState != CoreBusy );
114
uint np = pluginList.count();
116
plugMenu = new QMenu( parent );
117
QActionGroup *plugGroup = new QActionGroup( parent );
118
connect( plugMenu, SIGNAL(triggered( QAction * )),
119
SLOT(slotPluginSelected( QAction * )) );
120
for (uint i = 0; i < np; i++) {
121
int pid = pluginList[i];
122
greetPlugins[pid].action = plugGroup->addAction(
123
i18nc("@item:inmenu authentication method",
124
greetPlugins[pid].info->name) );
125
greetPlugins[pid].action->setData( i );
126
greetPlugins[pid].action->setCheckable( true );
128
plugMenu->addActions( plugGroup->actions() );
112
// assert(coreState != CoreBusy);
114
uint np = pluginList.count();
116
plugMenu = new QMenu(parent);
117
QActionGroup *plugGroup = new QActionGroup(parent);
118
connect(plugMenu, SIGNAL(triggered(QAction *)),
119
SLOT(slotPluginSelected(QAction *)));
120
for (uint i = 0; i < np; i++) {
121
int pid = pluginList[i];
122
greetPlugins[pid].action = plugGroup->addAction(
123
i18nc("@item:inmenu authentication method",
124
greetPlugins[pid].info->name));
125
greetPlugins[pid].action->setData(i);
126
greetPlugins[pid].action->setCheckable(true);
128
plugMenu->addActions(plugGroup->actions());
135
135
KGVerify::entitiesLocal() const
137
return greetPlugins[pluginList[curPlugin]].info->flags & KGreeterPluginInfo::Local;
137
return greetPlugins[pluginList[curPlugin]].info->flags & KGreeterPluginInfo::Local;
141
141
KGVerify::entitiesFielded() const
143
return greetPlugins[pluginList[curPlugin]].info->flags & KGreeterPluginInfo::Fielded;
143
return greetPlugins[pluginList[curPlugin]].info->flags & KGreeterPluginInfo::Fielded;
147
147
KGVerify::entityPresettable() const
149
return greetPlugins[pluginList[curPlugin]].info->flags & KGreeterPluginInfo::Presettable;
149
return greetPlugins[pluginList[curPlugin]].info->flags & KGreeterPluginInfo::Presettable;
153
153
KGVerify::isClassic() const
155
return !strcmp( greetPlugins[pluginList[curPlugin]].info->method, "classic" );
155
return !strcmp(greetPlugins[pluginList[curPlugin]].info->method, "classic");
158
158
QString // public
159
159
KGVerify::pluginName() const
161
QString name( greetPlugins[pluginList[curPlugin]].library->fileName() );
162
uint st = name.lastIndexOf( '/' ) + 1;
163
uint en = name.indexOf( '.', st );
164
if (en - st > 7 && QString::fromRawData( name.unicode() + st, 7 ) == QLatin1String("kgreet_"))
166
return name.mid( st, en - st );
161
QString name(greetPlugins[pluginList[curPlugin]].library->fileName());
162
uint st = name.lastIndexOf('/') + 1;
163
uint en = name.indexOf('.', st);
164
if (en - st > 7 && QString::fromRawData(name.unicode() + st, 7) == QLatin1String("kgreet_"))
166
return name.mid(st, en - st);
170
setTabOrder( QWidget *&pred, const QObjectList &list )
170
setTabOrder(QWidget *&pred, const QObjectList &list)
172
foreach (QObject *o, list)
173
if (QWidget *w = qobject_cast<QWidget *>(o)) {
174
if (w->focusPolicy() & Qt::TabFocus) {
175
QWidget::setTabOrder( pred, w );
178
setTabOrder( pred, o->children() );
172
foreach (QObject *o, list)
173
if (QWidget *w = qobject_cast<QWidget *>(o)) {
174
if (w->focusPolicy() & Qt::TabFocus) {
175
QWidget::setTabOrder(pred, w);
178
setTabOrder(pred, o->children());
183
KGVerify::selectPlugin( int id )
184
KGVerify::selectPlugin(int id)
185
if (pluginList.isEmpty()) {
186
msgBox( errorbox, i18n("No greeter widget plugin loaded. Check the configuration.") );
187
::exit( EX_UNMANAGE_DPY );
191
greetPlugins[pluginList[id]].action->setChecked( true );
192
pName = ("greet_" + pluginName()).toLatin1();
193
debug( "new %s\n", pName.data() );
194
greet = greetPlugins[pluginList[id]].info->create( this, parent, fixedEntity, func, ctx );
195
if (QWidget *pred = predecessor)
196
setTabOrder( pred, *(const QObjectList *)&greet->getWidgets() );
197
timeable = _autoLoginDelay && entityPresettable() && isClassic();
186
if (pluginList.isEmpty()) {
187
msgBox(errorbox, i18n("No greeter widget plugin loaded. Check the configuration."));
188
::exit(EX_UNMANAGE_DPY);
192
greetPlugins[pluginList[id]].action->setChecked(true);
193
pName = ("greet_" + pluginName()).toLatin1();
194
debug("new %s\n", pName.data());
195
greet = greetPlugins[pluginList[id]].info->create(this, parent, fixedEntity, func, ctx);
196
if (QWidget *pred = predecessor)
197
setTabOrder(pred, *(const QObjectList *)&greet->getWidgets());
198
timeable = _autoLoginDelay && entityPresettable() && isClassic();
200
201
void // private slot
201
KGVerify::slotPluginSelected( QAction *action )
205
int id = action->data().toInt();
206
if (id != curPlugin) {
207
parent->setUpdatesEnabled( false );
208
debug( "delete %s\n", pName.data() );
211
handler->verifyPluginChanged( id );
214
parent->setUpdatesEnabled( true );
219
KGVerify::loadUsers( const QStringList &users )
221
debug( "%s->loadUsers(...)\n", pName.data() );
222
greet->loadUsers( users );
226
KGVerify::presetEntity( const QString &entity, int field )
202
KGVerify::slotPluginSelected(QAction *action)
206
int id = action->data().toInt();
207
if (id != curPlugin) {
208
parent->setUpdatesEnabled(false);
209
debug("delete %s\n", pName.data());
212
handler->verifyPluginChanged(id);
215
parent->setUpdatesEnabled(true);
220
KGVerify::loadUsers(const QStringList &users)
222
debug("%s->loadUsers(...)\n", pName.data());
223
greet->loadUsers(users);
227
KGVerify::presetEntity(const QString &entity, int field)
233
234
KGVerify::applyPreset()
235
if (!presEnt.isEmpty()) {
236
debug( "%s->presetEntity(%\"s, %d)\n", pName.data(),
237
qPrintable( presEnt ), presFld );
238
greet->presetEntity( presEnt, presFld );
239
if (entitiesLocal()) {
242
handler->verifySetUser( presEnt );
236
if (!presEnt.isEmpty()) {
237
debug("%s->presetEntity(%\"s, %d)\n", pName.data(),
238
qPrintable(presEnt), presFld);
239
greet->presetEntity(presEnt, presFld);
240
if (entitiesLocal()) {
243
handler->verifySetUser(presEnt);
250
KGVerify::scheduleAutoLogin( bool initial )
251
KGVerify::scheduleAutoLogin(bool initial)
253
debug( "%s->presetEntity(%\"s, -1)\n", pName.data(),
254
qPrintable( _autoLoginUser ), -1 );
255
greet->presetEntity( _autoLoginUser, -1 );
256
curUser = _autoLoginUser;
257
handler->verifySetUser( _autoLoginUser );
260
timedLeft = _autoLoginDelay;
263
timedLeft = qMax( _autoLoginDelay - TIMED_GREET_TO, MIN_TIMED_TO );
264
deadTicks = DEAD_TIMED_TO;
267
sockNot->setEnabled( false );
254
debug("%s->presetEntity(%\"s, -1)\n", pName.data(),
255
qPrintable(_autoLoginUser), -1);
256
greet->presetEntity(_autoLoginUser, -1);
257
curUser = _autoLoginUser;
258
handler->verifySetUser(_autoLoginUser);
261
timedLeft = _autoLoginDelay;
264
timedLeft = qMax(_autoLoginDelay - TIMED_GREET_TO, MIN_TIMED_TO);
265
deadTicks = DEAD_TIMED_TO;
268
sockNot->setEnabled(false);
276
277
KGVerify::performAutoLogin()
279
gSendInt( G_AutoLogin );
280
coreState = CoreBusy;
280
gSendInt(G_AutoLogin);
281
coreState = CoreBusy;
283
284
QString // public
284
285
KGVerify::getEntity() const
286
debug( "%s->getEntity()\n", pName.data() );
287
QString ent = greet->getEntity();
288
debug( " entity: %s\n", qPrintable( ent ) );
287
debug("%s->getEntity()\n", pName.data());
288
QString ent = greet->getEntity();
289
debug(" entity: %s\n", qPrintable(ent));
293
KGVerify::setUser( const QString &user )
294
KGVerify::setUser(const QString &user)
295
// assert( fixedEntity.isEmpty() );
297
debug( "%s->setUser(%\"s)\n", pName.data(), qPrintable( user ) );
298
greet->setUser( user );
296
// assert(fixedEntity.isEmpty());
298
debug("%s->setUser(%\"s)\n", pName.data(), qPrintable(user));
299
greet->setUser(user);
303
304
KGVerify::start()
305
authTok = (func == KGreeterPlugin::ChAuthTok);
306
if (func == KGreeterPlugin::Authenticate && ctx == KGreeterPlugin::Login) {
307
if (scheduleAutoLogin( true )) {
308
if (!_autoLoginAgain)
309
_autoLoginDelay = 0, timeable = false;
314
sockNot->setEnabled( true );
316
if (!(func == KGreeterPlugin::Authenticate ||
317
ctx == KGreeterPlugin::ChangeTok ||
318
ctx == KGreeterPlugin::ExChangeTok))
320
coreState = CoreBusy;
322
debug( "%s->start()\n", pName.data() );
306
authTok = (func == KGreeterPlugin::ChAuthTok);
307
if (func == KGreeterPlugin::Authenticate && ctx == KGreeterPlugin::Login) {
308
if (scheduleAutoLogin(true)) {
309
if (!_autoLoginAgain)
310
_autoLoginDelay = 0, timeable = false;
316
sockNot->setEnabled(true);
318
if (!(func == KGreeterPlugin::Authenticate ||
319
ctx == KGreeterPlugin::ChangeTok ||
320
ctx == KGreeterPlugin::ExChangeTok))
322
coreState = CoreBusy;
324
debug("%s->start()\n", pName.data());
327
329
KGVerify::abort()
329
debug( "%s->abort()\n", pName.data() );
331
sockNot->setEnabled( false );
331
debug("%s->abort()\n", pName.data());
333
sockNot->setEnabled(false);
336
338
KGVerify::suspend()
338
// assert( coreState != CoreBusy );
340
debug( "%s->abort()\n", pName.data() );
346
sockNot->setEnabled( false );
340
// assert(coreState != CoreBusy);
342
debug("%s->abort()\n", pName.data());
348
sockNot->setEnabled(false);
350
352
KGVerify::resume()
352
sockNot->setEnabled( true );
357
debug( "%s->start()\n", pName.data() );
359
} else if (delayed) {
362
sockNot->setEnabled( true );
363
debug( "%s->start()\n", pName.data() );
354
sockNot->setEnabled(true);
359
debug("%s->start()\n", pName.data());
361
} else if (delayed) {
364
sockNot->setEnabled(true);
365
debug("%s->start()\n", pName.data());
368
370
void // not a slot - called manually by greeter
369
371
KGVerify::accept()
371
debug( "%s->next()\n", pName.data() );
373
debug("%s->next()\n", pName.data());
376
KGVerify::doReject( bool initial )
378
KGVerify::doReject(bool initial)
378
// assert( coreState != CoreBusy );
380
debug( "%s->abort()\n", pName.data() );
383
handler->verifyClear();
384
debug( "%s->clear()\n", pName.data() );
388
if (!scheduleAutoLogin( initial )) {
389
isClear = !(isClear && applyPreset());
391
debug( "%s->start()\n", pName.data() );
380
// assert(coreState != CoreBusy);
382
debug("%s->abort()\n", pName.data());
385
handler->verifyClear();
386
debug("%s->clear()\n", pName.data());
390
if (!scheduleAutoLogin(initial)) {
391
isClear = !(isClear && applyPreset());
393
debug("%s->start()\n", pName.data());
399
401
void // not a slot - called manually by greeter
400
402
KGVerify::reject()
406
KGVerify::setEnabled( bool on )
408
KGVerify::setEnabled(bool on)
408
debug( "%s->setEnabled(%s)\n", pName.data(), on ? "true" : "false" );
409
greet->setEnabled( on );
410
debug("%s->setEnabled(%s)\n", pName.data(), on ? "true" : "false");
411
greet->setEnabled(on);
415
417
KGVerify::slotTimeout()
420
debug( "%s->revive()\n", pName.data() );
422
handler->verifyRetry();
427
sockNot->setEnabled( true );
428
debug( "%s->start()\n", pName.data() );
433
} else if (timedLeft) {
441
// assert( ctx == Login );
422
debug("%s->revive()\n", pName.data());
424
handler->verifyRetry();
429
sockNot->setEnabled(true);
430
debug("%s->start()\n", pName.data());
435
} else if (timedLeft) {
443
// assert(ctx == Login);
448
450
KGVerify::slotActivity()
451
// timed login countdown running. cancel and reschedule it.
452
debug( "%s->revive()\n", pName.data() );
454
debug( "%s->start()\n", pName.data() );
456
sockNot->setEnabled( true );
460
timer.start( TIMED_GREET_TO * SECONDS );
462
// timed login is possible and thus scheduled. reschedule it.
463
timer.start( TIMED_GREET_TO * SECONDS );
453
// timed login countdown running. cancel and reschedule it.
454
debug("%s->revive()\n", pName.data());
456
debug("%s->start()\n", pName.data());
458
sockNot->setEnabled(true);
462
timer.start(TIMED_GREET_TO * SECONDS);
463
} else if (timeable) {
464
// timed login is possible and thus scheduled. reschedule it.
465
timer.start(TIMED_GREET_TO * SECONDS);
467
470
KGVerify::talkerEdits()
469
if (func == KGreeterPlugin::Authenticate &&
470
ctx == KGreeterPlugin::Login)
474
timer.start( FULL_GREET_TO * SECONDS );
472
if (func == KGreeterPlugin::Authenticate &&
473
ctx == KGreeterPlugin::Login)
477
timer.start(FULL_GREET_TO * SECONDS);
479
482
void // private static
480
KGVerify::vrfMsgBox( QWidget *parent, const QString &user,
481
QMessageBox::Icon type, const QString &mesg )
483
KGVerify::vrfMsgBox(QWidget *parent, const QString &user,
484
QMessageBox::Icon type, const QString &mesg)
483
KFMsgBox::box( parent, type, user.isEmpty() ?
484
mesg : i18n("Logging in %1...\n\n", user ) + mesg );
486
KFMsgBox::box(parent, type, user.isEmpty() ?
487
mesg : i18n("Logging in %1...\n\n", user) + mesg);
487
static const char * const msgs[]= {
488
I18N_NOOP( "You are required to change your password immediately (password aged)." ),
489
I18N_NOOP( "You are required to change your password immediately (root enforced)." ),
490
I18N_NOOP( "You are not allowed to login at the moment." ),
491
I18N_NOOP( "Home folder not available." ),
492
I18N_NOOP( "Logins are not allowed at the moment.\nTry again later." ),
493
I18N_NOOP( "Your login shell is not listed in /etc/shells." ),
494
I18N_NOOP( "Root logins are not allowed." ),
495
I18N_NOOP( "Your account has expired; please contact your system administrator." )
490
static const char * const msgs[] = {
491
I18N_NOOP("You are required to change your password immediately (password aged)."),
492
I18N_NOOP("You are required to change your password immediately (root enforced)."),
493
I18N_NOOP("You are not allowed to login at the moment."),
494
I18N_NOOP("Home folder not available."),
495
I18N_NOOP("Logins are not allowed at the moment.\nTry again later."),
496
I18N_NOOP("Your login shell is not listed in /etc/shells."),
497
I18N_NOOP("Root logins are not allowed."),
498
I18N_NOOP("Your account has expired; please contact your system administrator.")
498
501
void // private static
499
KGVerify::vrfErrBox( QWidget *parent, const QString &user, const char *msg )
502
KGVerify::vrfErrBox(QWidget *parent, const QString &user, const char *msg)
501
QMessageBox::Icon icon;
504
QMessageBox::Icon icon;
505
mesg = i18n("A critical error occurred.\n"
506
"Please look at KDM's logfile(s) for more information\n"
507
"or contact your system administrator.");
510
mesg = QString::fromLocal8Bit( msg );
511
QString mesg1 = mesg + '.';
512
for (uint i = 0; i < as(msgs); i++)
513
if (mesg1 == msgs[i]) {
514
mesg = i18n(msgs[i]);
519
vrfMsgBox( parent, user, icon, mesg );
508
mesg = i18n("A critical error occurred.\n"
509
"Please look at KDM's logfile(s) for more information\n"
510
"or contact your system administrator.");
513
mesg = QString::fromLocal8Bit(msg);
514
QString mesg1 = mesg + '.';
515
for (uint i = 0; i < as(msgs); i++)
516
if (mesg1 == msgs[i]) {
517
mesg = i18n(msgs[i]);
522
vrfMsgBox(parent, user, icon, mesg);
522
525
void // private static
523
KGVerify::vrfInfoBox( QWidget *parent, const QString &user, const char *msg )
526
KGVerify::vrfInfoBox(QWidget *parent, const QString &user, const char *msg)
525
QString mesg = QString::fromLocal8Bit( msg );
526
QRegExp rx( "^Warning: your account will expire in (\\d+) day" );
527
if (rx.indexIn( mesg ) >= 0) {
528
int expire = rx.cap( 1 ).toInt();
530
i18np("Your account expires tomorrow.",
531
"Your account expires in %1 days.", expire) :
532
i18n("Your account expires today.");
534
rx.setPattern( "^Warning: your password will expire in (\\d+) day" );
535
if (rx.indexIn( mesg ) >= 0) {
536
int expire = rx.cap( 1 ).toInt();
538
i18np("Your password expires tomorrow.",
539
"Your password expires in %1 days.", expire) :
540
i18n("Your password expires today.");
543
vrfMsgBox( parent, user, infobox, mesg );
528
QString mesg = QString::fromLocal8Bit(msg);
529
QRegExp rx("^Warning: your account will expire in (\\d+) day");
530
if (rx.indexIn(mesg) >= 0) {
531
int expire = rx.cap(1).toInt();
533
i18np("Your account expires tomorrow.",
534
"Your account expires in %1 days.", expire) :
535
i18n("Your account expires today.");
537
rx.setPattern("^Warning: your password will expire in (\\d+) day");
538
if (rx.indexIn(mesg) >= 0) {
539
int expire = rx.cap(1).toInt();
541
i18np("Your password expires tomorrow.",
542
"Your password expires in %1 days.", expire) :
543
i18n("Your password expires today.");
546
vrfMsgBox(parent, user, infobox, mesg);
546
549
bool // public static
547
KGVerify::handleFailVerify( QWidget *parent, bool showUser )
550
KGVerify::handleFailVerify(QWidget *parent, bool showUser)
552
debug( "handleFailVerify ...\n" );
556
user = QString::fromLocal8Bit( msg );
561
int ret = gRecvInt();
563
// non-terminal status
565
/* case V_PUT_USER: cannot happen - we are in "classic" mode */
566
/* case V_PRE_OK: cannot happen - not in ChTok dialog */
567
/* case V_CHTOK: cannot happen - called by non-interactive verify */
569
debug( " V_CHTOK_AUTH\n" );
571
QStringList pgs( _pluginsLogin );
572
pgs += _pluginsShutdown;
573
foreach (const QString& pg, pgs)
574
if (pg == "classic" || pg == "modern") {
575
pgs = QStringList( pg );
577
} else if (pg == "generic") {
578
pgs = QStringList( "modern" );
581
pgs = QStringList( "classic" );
583
KGChTok chtok( parent, user, init( pgs ), 0,
584
KGreeterPlugin::AuthChAuthTok,
585
KGreeterPlugin::Login );
589
debug( " V_MSG_ERR\n" );
591
debug( " message %\"s\n", msg );
592
vrfErrBox( parent, user, msg );
596
case V_MSG_INFO_AUTH: // should not happen
598
debug( " V_MSG_INFO\n" );
600
debug( " message %\"s\n", msg );
601
vrfInfoBox( parent, user, msg );
613
debug( " V_AUTH\n" );
614
vrfMsgBox( parent, user, sorrybox, i18n("Authentication failed") );
617
debug( " V_FAIL\n" );
620
logPanic( "Unknown V_xxx code %d from core\n", ret );
555
debug("handleFailVerify ...\n");
559
user = QString::fromLocal8Bit(msg);
564
int ret = gRecvInt();
566
// non-terminal status
568
/* case V_PUT_USER: cannot happen - we are in "classic" mode */
569
/* case V_PRE_OK: cannot happen - not in ChTok dialog */
570
/* case V_CHTOK: cannot happen - called by non-interactive verify */
572
debug(" V_CHTOK_AUTH\n");
574
QStringList pgs(_pluginsLogin);
575
pgs += _pluginsShutdown;
576
foreach (const QString& pg, pgs)
577
if (pg == "classic" || pg == "modern") {
578
pgs = QStringList(pg);
580
} else if (pg == "generic") {
581
pgs = QStringList("modern");
584
pgs = QStringList("classic");
586
KGChTok chtok(parent, user, init(pgs), 0,
587
KGreeterPlugin::AuthChAuthTok,
588
KGreeterPlugin::Login);
592
debug(" V_MSG_ERR\n");
594
debug(" message %\"s\n", msg);
595
vrfErrBox(parent, user, msg);
599
case V_MSG_INFO_AUTH: // should not happen
601
debug(" V_MSG_INFO\n");
603
debug(" message %\"s\n", msg);
604
vrfInfoBox(parent, user, msg);
617
vrfMsgBox(parent, user, sorrybox, i18n("Authentication failed"));
623
logPanic("Unknown V_xxx code %d from core\n", ret);
626
629
KGVerify::handleVerify()
628
debug( "handleVerify ...\n" );
631
int ret, echo, ndelay;
632
KGreeterPlugin::Function nfunc;
637
coreState = CorePrompting;
640
debug( " V_GET_TEXT\n" );
642
debug( " prompt %\"s\n", msg );
644
debug( " echo = %d\n", echo );
646
debug( " ndelay = %d\n%s->textPrompt(...)\n", ndelay, pName.data() );
647
greet->textPrompt( msg, echo, ndelay );
651
debug( " V_GET_BINARY\n" );
652
msg = gRecvArr( &ret );
653
debug( " %d bytes prompt\n", ret );
655
debug( " ndelay = %d\n%s->binaryPrompt(...)\n", ndelay, pName.data() );
656
greet->binaryPrompt( msg, ndelay );
661
// non-terminal status
662
coreState = CoreBusy;
665
debug( " V_PUT_USER\n" );
667
curUser = pamUser = QString::fromLocal8Bit( msg );
668
// greet needs this to be able to return something useful from
669
// getEntity(). but the backend is still unable to tell a domain ...
670
debug( " %s->setUser(%\"s)\n", pName.data(), qPrintable( user ) );
671
greet->setUser( curUser );
672
handler->verifySetUser( curUser );
675
case V_PRE_OK: // this is only for func == AuthChAuthTok
676
debug( " V_PRE_OK\n" );
677
// With the "classic" method, the wrong user simply cannot be
678
// authenticated, even with the generic plugin. Other methods
679
// could do so, but this applies only to ctx == ChangeTok, which
680
// is not implemented yet.
682
debug( "%s->succeeded()\n", pName.data() );
686
debug( " V_MSG_ERR\n" );
689
debug( " %s->textMessage(%\"s, true)\n", pName.data(), msg );
690
if (!greet->textMessage( msg, true )) { // XXX little point in filtering
691
debug( " message passed\n" );
692
vrfErrBox( parent, pamUser, msg );
694
debug( " message swallowed\n" );
699
case V_MSG_INFO_AUTH:
700
debug( " V_MSG_INFO_AUTH\n" );
703
debug( " %s->textMessage(%\"s, false)\n", pName.data(), msg );
704
if (!greet->textMessage( msg, false )) {
705
debug( " message passed\n" );
706
vrfInfoBox( parent, pamUser, msg );
708
debug( " message swallowed\n" );
714
debug( " V_MSG_INFO\n" );
717
debug( " display %\"s\n", msg );
718
vrfInfoBox( parent, pamUser, msg );
726
coreState = CoreIdle;
728
sockNot->setEnabled( false );
731
// These codes are not really terminal as far as the core is concerned,
732
// but the branches as a whole are.
733
if (ret == V_CHTOK_AUTH) {
734
debug( " V_CHTOK_AUTH\n" );
735
nfunc = KGreeterPlugin::AuthChAuthTok;
738
} else if (ret == V_CHTOK) {
739
debug( " V_CHTOK\n" );
740
nfunc = KGreeterPlugin::ChAuthTok;
743
debug( "%s->succeeded()\n", pName.data() );
745
KGChTok chtok( parent, user, pluginList, curPlugin, nfunc, KGreeterPlugin::Login );
754
if (!fixedEntity.isEmpty()) {
755
debug( " %s->getEntity()\n", pName.data() );
756
QString ent = greet->getEntity();
757
debug( " entity %\"s\n", qPrintable( ent ) );
758
if (ent != fixedEntity) {
759
debug( "%s->failed()\n", pName.data() );
762
i18n("Authenticated user (%1) does not match requested user (%2).\n",
763
ent, fixedEntity ) );
767
debug( "%s->succeeded()\n", pName.data() );
773
debug( "%s->failed()\n", pName.data() );
777
debug( " V_AUTH\n" );
780
handler->verifyFailed();
781
timer.start( 1500 + KRandom::random()/(RAND_MAX/1000) );
785
logPanic( "Unknown V_xxx code %d from core\n", ret );
786
debug( " V_FAIL\n" );
631
debug("handleVerify ...\n");
634
int ret, echo, ndelay;
635
KGreeterPlugin::Function nfunc;
640
coreState = CorePrompting;
643
debug(" V_GET_TEXT\n");
645
debug(" prompt %\"s\n", msg);
647
debug(" echo = %d\n", echo);
649
debug(" ndelay = %d\n%s->textPrompt(...)\n", ndelay, pName.data());
650
greet->textPrompt(msg, echo, ndelay);
654
debug(" V_GET_BINARY\n");
655
msg = gRecvArr(&ret);
656
debug(" %d bytes prompt\n", ret);
658
debug(" ndelay = %d\n%s->binaryPrompt(...)\n", ndelay, pName.data());
659
greet->binaryPrompt(msg, ndelay);
664
// non-terminal status
665
coreState = CoreBusy;
668
debug(" V_PUT_USER\n");
670
curUser = pamUser = QString::fromLocal8Bit(msg);
671
// greet needs this to be able to return something useful from
672
// getEntity(). but the backend is still unable to tell a domain ...
673
debug(" %s->setUser(%\"s)\n", pName.data(), qPrintable(user));
674
greet->setUser(curUser);
675
handler->verifySetUser(curUser);
678
case V_PRE_OK: // this is only for func == AuthChAuthTok
679
debug(" V_PRE_OK\n");
680
// With the "classic" method, the wrong user simply cannot be
681
// authenticated, even with the generic plugin. Other methods
682
// could do so, but this applies only to ctx == ChangeTok, which
683
// is not implemented yet.
685
debug("%s->succeeded()\n", pName.data());
689
debug(" V_MSG_ERR\n");
692
debug(" %s->textMessage(%\"s, true)\n", pName.data(), msg);
693
if (!greet->textMessage(msg, true)) { // XXX little point in filtering
694
debug(" message passed\n");
695
vrfErrBox(parent, pamUser, msg);
697
debug(" message swallowed\n");
703
case V_MSG_INFO_AUTH:
704
debug(" V_MSG_INFO_AUTH\n");
707
debug(" %s->textMessage(%\"s, false)\n", pName.data(), msg);
708
if (!greet->textMessage(msg, false)) {
709
debug(" message passed\n");
710
vrfInfoBox(parent, pamUser, msg);
712
debug(" message swallowed\n");
719
debug(" V_MSG_INFO\n");
722
debug(" display %\"s\n", msg);
723
vrfInfoBox(parent, pamUser, msg);
731
coreState = CoreIdle;
733
sockNot->setEnabled(false);
736
// These codes are not really terminal as far as the core is concerned,
737
// but the branches as a whole are.
738
if (ret == V_CHTOK_AUTH) {
739
debug(" V_CHTOK_AUTH\n");
740
nfunc = KGreeterPlugin::AuthChAuthTok;
743
} else if (ret == V_CHTOK) {
745
nfunc = KGreeterPlugin::ChAuthTok;
748
debug("%s->succeeded()\n", pName.data());
750
KGChTok chtok(parent, user, pluginList, curPlugin, nfunc, KGreeterPlugin::Login);
759
if (!fixedEntity.isEmpty()) {
760
debug(" %s->getEntity()\n", pName.data());
761
QString ent = greet->getEntity();
762
debug(" entity %\"s\n", qPrintable(ent));
763
if (ent != fixedEntity) {
764
debug("%s->failed()\n", pName.data());
767
i18n("Authenticated user (%1) does not match requested user (%2).\n",
772
debug("%s->succeeded()\n", pName.data());
778
debug("%s->failed()\n", pName.data());
785
handler->verifyFailed();
786
timer.start(1500 + KRandom::random() / (RAND_MAX / 1000));
790
logPanic("Unknown V_xxx code %d from core\n", ret);
788
debug( "%s->revive()\n", pName.data() );
790
sockNot->setEnabled( true );
792
debug( "%s->start()\n", pName.data() );
799
KGVerify::gplugReturnText( const char *text, int tag )
801
debug( "%s: gplugReturnText(%\"s, %d)\n", pName.data(),
802
tag & V_IS_SECRET ? "<masked>" : text, tag );
806
coreState = CoreBusy;
808
coreState = CoreIdle;
812
KGVerify::gplugReturnBinary( const char *data )
815
unsigned const char *up = (unsigned const char *)data;
816
int len = up[3] | (up[2] << 8) | (up[1] << 16) | (up[0] << 24);
817
debug( "%s: gplugReturnBinary(%d bytes)\n", pName.data(), len );
818
gSendArr( len, data );
819
coreState = CoreBusy;
821
debug( "%s: gplugReturnBinary(NULL)\n", pName.data() );
823
coreState = CoreIdle;
828
KGVerify::gplugSetUser( const QString &user )
830
debug( "%s: gplugSetUser(%\"s)\n", pName.data(), qPrintable( user ) );
832
handler->verifySetUser( user );
793
debug("%s->revive()\n", pName.data());
795
sockNot->setEnabled(true);
797
debug("%s->start()\n", pName.data());
804
KGVerify::gplugReturnText(const char *text, int tag)
806
debug("%s: gplugReturnText(%\"s, %d)\n", pName.data(),
807
tag & V_IS_SECRET ? "<masked>" : text, tag);
811
coreState = CoreBusy;
813
coreState = CoreIdle;
818
KGVerify::gplugReturnBinary(const char *data)
821
unsigned const char *up = (unsigned const char *)data;
822
int len = up[3] | (up[2] << 8) | (up[1] << 16) | (up[0] << 24);
823
debug("%s: gplugReturnBinary(%d bytes)\n", pName.data(), len);
825
coreState = CoreBusy;
827
debug("%s: gplugReturnBinary(NULL)\n", pName.data());
829
coreState = CoreIdle;
834
KGVerify::gplugSetUser(const QString &user)
836
debug("%s: gplugSetUser(%\"s)\n", pName.data(), qPrintable(user));
838
handler->verifySetUser(user);
836
842
KGVerify::gplugStart()
838
// XXX handle func != Authenticate
839
if (coreState != CoreIdle)
841
debug( "%s: gplugStart()\n", pName.data() );
842
gSendInt( ctx == KGreeterPlugin::Shutdown ? G_VerifyRootOK : G_Verify );
843
gSendStr( greetPlugins[pluginList[curPlugin]].info->method );
844
coreState = CoreBusy;
844
// XXX handle func != Authenticate
845
if (coreState != CoreIdle)
847
debug("%s: gplugStart()\n", pName.data());
848
gSendInt(ctx == KGreeterPlugin::Shutdown ? G_VerifyRootOK : G_Verify);
849
gSendStr(greetPlugins[pluginList[curPlugin]].info->method);
850
coreState = CoreBusy;
848
854
KGVerify::gplugChanged()
850
debug( "%s: gplugChanged()\n", pName.data() );
851
if (parent->isActiveWindow())
856
debug("%s: gplugChanged()\n", pName.data());
857
if (parent->isActiveWindow())
856
862
KGVerify::gplugActivity()
858
debug( "%s: gplugActivity()\n", pName.data() );
864
debug("%s: gplugActivity()\n", pName.data());
863
KGVerify::gplugMsgBox( QMessageBox::Icon type, const QString &text )
869
KGVerify::gplugMsgBox(QMessageBox::Icon type, const QString &text)
865
debug( "%s: gplugMsgBox(%d, %\"s)\n", pName.data(), type, qPrintable( text ) );
866
msgBox( type, text );
871
debug("%s: gplugMsgBox(%d, %\"s)\n", pName.data(), type, qPrintable(text));
870
KGVerify::eventFilter( QObject *o, QEvent *e )
876
KGVerify::eventFilter(QObject *o, QEvent *e)
873
case QEvent::KeyPress:
875
QKeyEvent *ke = (QKeyEvent *)e;
876
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) {
877
if (deadTicks <= 0) {
885
case QEvent::KeyRelease:
891
return inherited::eventFilter( o, e );
879
case QEvent::KeyPress:
881
QKeyEvent *ke = (QKeyEvent *)e;
882
if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter) {
883
if (deadTicks <= 0) {
891
case QEvent::KeyRelease:
897
return inherited::eventFilter(o, e);
895
901
KGVerify::updateLockStatus()
898
Window dummy1, dummy2;
899
int dummy3, dummy4, dummy5, dummy6;
900
XQueryPointer( QX11Info::display(), DefaultRootWindow( QX11Info::display() ),
901
&dummy1, &dummy2, &dummy3, &dummy4, &dummy5, &dummy6,
903
capsLocked = lmask & LockMask;
904
Window dummy1, dummy2;
905
int dummy3, dummy4, dummy5, dummy6;
906
XQueryPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()),
907
&dummy1, &dummy2, &dummy3, &dummy4, &dummy5, &dummy6,
909
capsLocked = lmask & LockMask;
908
KGVerify::msgBox( QMessageBox::Icon typ, const QString &msg )
914
KGVerify::msgBox(QMessageBox::Icon typ, const QString &msg)
911
KFMsgBox::box( parent, typ, msg );
917
KFMsgBox::box(parent, typ, msg);
916
922
QVariant // public static
917
KGVerify::getConf( void *, const char *key, const QVariant &dflt )
923
KGVerify::getConf(void *, const char *key, const QVariant &dflt)
919
if (!qstrcmp( key, "EchoPasswd" ))
920
return QVariant( _echoPasswd );
922
QString fkey = QString::fromLatin1( key ) + '=';
923
foreach (const QString& pgo, _pluginOptions)
924
if (pgo.startsWith( fkey ))
925
return pgo.mid( fkey.length() );
925
if (!qstrcmp(key, "EchoPasswd")) {
926
return QVariant(_echoPasswd);
928
QString fkey = QString::fromLatin1(key) + '=';
929
foreach (const QString& pgo, _pluginOptions)
930
if (pgo.startsWith(fkey))
931
return pgo.mid(fkey.length());
930
936
QVector<GreeterPluginHandle> KGVerify::greetPlugins;
933
KGVerify::init( const QStringList &plugins )
939
KGVerify::init(const QStringList &plugins)
935
PluginList pluginList;
937
foreach (const QString& pg, plugins) {
938
GreeterPluginHandle plugin;
939
KLibrary *lib = new KLibrary( pg[0] == '/' ? pg : "kgreet_" + pg );
940
if (lib->fileName().isEmpty()) {
941
logError( "GreeterPlugin %s does not exist\n", qPrintable( pg ) );
945
uint i, np = greetPlugins.count();
946
for (i = 0; i < np; i++)
947
if (greetPlugins[i].library->fileName() == lib->fileName()) {
952
logError( "Cannot load GreeterPlugin %s (%s)\n",
953
qPrintable( pg ), qPrintable( lib->fileName() ) );
957
plugin.library = lib;
958
plugin.info = (KGreeterPluginInfo *)lib->resolveSymbol( "kgreeterplugin_info" );
960
logError( "GreeterPlugin %s (%s) is no valid greet widget plugin\n",
961
qPrintable( pg ), qPrintable( lib->fileName() ) );
967
if (!plugin.info->init( QString(), getConf, 0 )) {
968
logError( "GreeterPlugin %s (%s) refuses to serve\n",
969
qPrintable( pg ), qPrintable( lib->fileName() ) );
974
debug( "GreeterPlugin %s (%s) loaded\n", qPrintable( pg ), plugin.info->name );
975
greetPlugins.append( plugin );
977
pluginList.append( i );
941
PluginList pluginList;
943
foreach (const QString& pg, plugins) {
944
GreeterPluginHandle plugin;
945
KLibrary *lib = new KLibrary(pg[0] == '/' ? pg : "kgreet_" + pg);
946
if (lib->fileName().isEmpty()) {
947
logError("GreeterPlugin %s does not exist\n", qPrintable(pg));
951
uint i, np = greetPlugins.count();
952
for (i = 0; i < np; i++)
953
if (greetPlugins[i].library->fileName() == lib->fileName()) {
958
logError("Cannot load GreeterPlugin %s (%s)\n",
959
qPrintable(pg), qPrintable(lib->fileName()));
963
plugin.library = lib;
964
plugin.info = (KGreeterPluginInfo *)lib->resolveSymbol("kgreeterplugin_info");
966
logError("GreeterPlugin %s (%s) is no valid greet widget plugin\n",
967
qPrintable(pg), qPrintable(lib->fileName()));
973
if (!plugin.info->init(QString(), getConf, 0)) {
974
logError("GreeterPlugin %s (%s) refuses to serve\n",
975
qPrintable(pg), qPrintable(lib->fileName()));
980
debug("GreeterPlugin %s (%s) loaded\n", qPrintable(pg), plugin.info->name);
981
greetPlugins.append(plugin);
983
pluginList.append(i);
985
for (int i = 0; i < greetPlugins.count(); i++) {
986
if (greetPlugins[i].info->done)
987
greetPlugins[i].info->done();
988
greetPlugins[i].library->unload();
991
for (int i = 0; i < greetPlugins.count(); i++) {
992
if (greetPlugins[i].info->done)
993
greetPlugins[i].info->done();
994
greetPlugins[i].library->unload();
993
KGStdVerify::KGStdVerify( KGVerifyHandler *_handler, QWidget *_parent,
994
QWidget *_predecessor, const QString &_fixedUser,
995
const PluginList &_pluginList,
996
KGreeterPlugin::Function _func,
997
KGreeterPlugin::Context _ctx )
998
: inherited( _handler, _parent, _predecessor, _fixedUser,
999
_pluginList, _func, _ctx )
1000
, failedLabelState( 0 )
999
KGStdVerify::KGStdVerify(KGVerifyHandler *_handler, QWidget *_parent,
1000
QWidget *_predecessor, const QString &_fixedUser,
1001
const PluginList &_pluginList,
1002
KGreeterPlugin::Function _func,
1003
KGreeterPlugin::Context _ctx)
1004
: inherited(_handler, _parent, _predecessor, _fixedUser,
1005
_pluginList, _func, _ctx)
1006
, failedLabelState(0)
1002
grid = new QGridLayout;
1003
grid->setAlignment( Qt::AlignCenter );
1005
failedLabel = new QLabel( parent );
1006
failedLabel->setFont( *_failFont );
1007
grid->addWidget( failedLabel, 1, 0, Qt::AlignCenter );
1008
grid = new QGridLayout;
1009
grid->setAlignment(Qt::AlignCenter);
1011
failedLabel = new QLabel(parent);
1012
failedLabel->setFont(*_failFont);
1013
grid->addWidget(failedLabel, 1, 0, Qt::AlignCenter);
1012
1018
KGStdVerify::~KGStdVerify()