From f6af340515ca0f5405ee4b893e24630450e07d4a Mon Sep 17 00:00:00 2001 From: tpearson Date: Thu, 15 Sep 2011 03:43:12 +0000 Subject: [PATCH] Add very preliminary SAK support Don't worry, if your system is not configured for SAK usability you won't notice anything different git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1253698 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kdesktop/kdesktop.kcfg | 7 ++ kdesktop/lock/CMakeLists.txt | 2 +- kdesktop/lock/lockdlg.cc | 7 +- kdesktop/lock/lockprocess.cc | 12 +++ kdesktop/lock/main.cc | 4 +- kdesktop/lock/sakdlg.cc | 171 +++++++++++++++++++++++++++++++++++ kdesktop/lock/sakdlg.h | 63 +++++++++++++ 7 files changed, 261 insertions(+), 5 deletions(-) create mode 100644 kdesktop/lock/sakdlg.cc create mode 100644 kdesktop/lock/sakdlg.h diff --git a/kdesktop/kdesktop.kcfg b/kdesktop/kdesktop.kcfg index 8f6899ea0..5849a798e 100644 --- a/kdesktop/kdesktop.kcfg +++ b/kdesktop/kdesktop.kcfg @@ -311,6 +311,13 @@ + + true + + Set to true to enable usage of the Trinity SAK anti-spoofing system + + + true diff --git a/kdesktop/lock/CMakeLists.txt b/kdesktop/lock/CMakeLists.txt index c3e64b55a..216c9ae9f 100644 --- a/kdesktop/lock/CMakeLists.txt +++ b/kdesktop/lock/CMakeLists.txt @@ -29,7 +29,7 @@ link_directories( set( target kdesktop_lock ) set( ${target}_SRCS - lockprocess.cc lockdlg.cc infodlg.cc querydlg.cc + lockprocess.cc lockdlg.cc infodlg.cc querydlg.cc sakdlg.cc autologout.cc main.cc ) diff --git a/kdesktop/lock/lockdlg.cc b/kdesktop/lock/lockdlg.cc index 95d5ab00a..8059a28c7 100644 --- a/kdesktop/lock/lockdlg.cc +++ b/kdesktop/lock/lockdlg.cc @@ -65,6 +65,7 @@ extern bool trinity_desktop_lock_autohide_lockdlg; extern bool trinity_desktop_lock_delay_screensaver_start; extern bool trinity_desktop_lock_use_system_modal_dialogs; +extern bool trinity_desktop_lock_use_sak; int dialogHideTimeout = 10*1000; @@ -114,7 +115,7 @@ PasswordDlg::PasswordDlg(LockProcess *parent, GreeterPluginHandle *plugin) mNewSessButton = new KPushButton( KGuiItem(i18n("Sw&itch User..."), "fork"), frame ); ok = new KPushButton( i18n("Unl&ock"), frame ); cancel = new KPushButton( KStdGuiItem::cancel(), frame ); - if (!trinity_desktop_lock_autohide_lockdlg) cancel->setEnabled(false); + if (!trinity_desktop_lock_autohide_lockdlg && !trinity_desktop_lock_use_sak) cancel->setEnabled(false); greet = plugin->info->create( this, 0, this, mLayoutButton, TQString::null, KGreeterPlugin::Authenticate, KGreeterPlugin::ExUnlock ); @@ -188,7 +189,7 @@ PasswordDlg::~PasswordDlg() void PasswordDlg::reject() { - if (trinity_desktop_lock_autohide_lockdlg) + if (trinity_desktop_lock_autohide_lockdlg || trinity_desktop_lock_use_sak) TQDialog::reject(); } @@ -253,7 +254,7 @@ void PasswordDlg::timerEvent(TQTimerEvent *ev) mUnlockingFailed = false; updateLabel(); ok->setEnabled(true); - if (trinity_desktop_lock_autohide_lockdlg) cancel->setEnabled(true); + if (trinity_desktop_lock_autohide_lockdlg || trinity_desktop_lock_use_sak) cancel->setEnabled(true); mNewSessButton->setEnabled( true ); greet->revive(); greet->start(); diff --git a/kdesktop/lock/lockprocess.cc b/kdesktop/lock/lockprocess.cc index 47ff886f3..206dc9718 100644 --- a/kdesktop/lock/lockprocess.cc +++ b/kdesktop/lock/lockprocess.cc @@ -4,6 +4,7 @@ // // Copyright (c) 1999 Martin R. Jones // Copyright (c) 2003 Oswald Buddenhagen +// Copyright (c) 2010-2011 Timothy Pearson // //kdesktop keeps running and checks user inactivity @@ -21,6 +22,7 @@ #include "lockdlg.h" #include "infodlg.h" #include "querydlg.h" +#include "sakdlg.h" #include "autologout.h" #include "kdesktopsettings.h" @@ -128,6 +130,7 @@ static void segv_handler(int) extern Atom qt_wm_state; extern bool trinity_desktop_lock_use_system_modal_dialogs; extern bool trinity_desktop_lock_delay_screensaver_start; +extern bool trinity_desktop_lock_use_sak; extern bool trinity_desktop_lock_forced; bool trinity_desktop_lock_autohide_lockdlg = TRUE; @@ -1359,6 +1362,9 @@ void LockProcess::suspend() void LockProcess::resume( bool force ) { + if (trinity_desktop_lock_use_sak && mHackDelayStartupTimer->isActive()) { + return; + } if( !force && (!mDialogs.isEmpty() || !mVisibility )) { // no resuming with dialog visible or when not visible if (backingPixmap.isNull()) @@ -1392,6 +1398,12 @@ bool LockProcess::checkPass() if (mAutoLogout) killTimer(mAutoLogoutTimerId); + if (trinity_desktop_lock_use_sak) { + // Wait for SAK press before continuing... + SAKDlg inDlg( this ); + int ret = execDialog( &inDlg ); + } + showVkbd(); PasswordDlg passDlg( this, &greetPlugin); int ret = execDialog( &passDlg ); diff --git a/kdesktop/lock/main.cc b/kdesktop/lock/main.cc index 90883f61e..587ad49db 100644 --- a/kdesktop/lock/main.cc +++ b/kdesktop/lock/main.cc @@ -34,9 +34,10 @@ #include #include -// [FIXME] Add GUI configuration checkboxes for these two settings (see kdesktoprc [ScreenSaver] UseUnmanagedLockWindows and DelaySaverStart) +// [FIXME] Add GUI configuration checkboxes for these three settings (see kdesktoprc [ScreenSaver] UseUnmanagedLockWindows, DelaySaverStart, and UseTDESAK) bool trinity_desktop_lock_use_system_modal_dialogs = FALSE; bool trinity_desktop_lock_delay_screensaver_start = FALSE; +bool trinity_desktop_lock_use_sak = FALSE; bool trinity_desktop_lock_forced = FALSE; @@ -153,6 +154,7 @@ int main( int argc, char **argv ) trinity_desktop_lock_use_system_modal_dialogs = !KDesktopSettings::useUnmanagedLockWindows(); trinity_desktop_lock_delay_screensaver_start = KDesktopSettings::delaySaverStart(); + trinity_desktop_lock_use_sak = KDesktopSettings::useTDESAK(); LockProcess process(child, args->isSet( "blank" )); if (!child) diff --git a/kdesktop/lock/sakdlg.cc b/kdesktop/lock/sakdlg.cc new file mode 100644 index 000000000..719f2122f --- /dev/null +++ b/kdesktop/lock/sakdlg.cc @@ -0,0 +1,171 @@ +//=========================================================================== +// +// This file is part of the KDE project +// +// Copyright (c) 2010-2011 Timothy Pearson + +#include + +#include "sakdlg.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifndef AF_LOCAL +# define AF_LOCAL AF_UNIX +#endif + +extern bool trinity_desktop_lock_use_system_modal_dialogs; +extern bool trinity_desktop_lock_use_sak; + +//=========================================================================== +// +// Simple dialog for displaying an unlock status or recurring error message +// +SAKDlg::SAKDlg(LockProcess *parent) + : TQDialog(parent, "information dialog", true, (trinity_desktop_lock_use_system_modal_dialogs?((WFlags)WStyle_StaysOnTop):((WFlags)WX11BypassWM))), + mUnlockingFailed(false) +{ + if (trinity_desktop_lock_use_system_modal_dialogs) { + // Signal that we do not want any window controls to be shown at all + Atom kde_wm_system_modal_notification; + kde_wm_system_modal_notification = XInternAtom(qt_xdisplay(), "_KDE_WM_MODAL_SYS_NOTIFICATION", False); + XChangeProperty(qt_xdisplay(), winId(), kde_wm_system_modal_notification, XA_INTEGER, 32, PropModeReplace, (unsigned char *) "TRUE", 1L); + } + setCaption(i18n("Desktop Session Locked")); + + frame = new TQFrame( this ); + if (trinity_desktop_lock_use_system_modal_dialogs) + frame->setFrameStyle( TQFrame::NoFrame ); + else + frame->setFrameStyle( TQFrame::Panel | TQFrame::Raised ); + frame->setLineWidth( 2 ); + + mpixLabel = new TQLabel( frame, "pixlabel" ); + mpixLabel->setPixmap(DesktopIcon("unlock")); + + KUser user; + + mStatusLabel = new TQLabel( " ", frame ); + mStatusLabel->tqsetAlignment( TQLabel::AlignCenter ); + + TQVBoxLayout *unlockDialogLayout = new TQVBoxLayout( this ); + unlockDialogLayout->addWidget( frame ); + + TQHBoxLayout *layStatus = new TQHBoxLayout( 0, 0, KDialog::spacingHint()); + layStatus->addWidget( mStatusLabel ); + + frameLayout = new TQGridLayout( frame, 1, 1, KDialog::marginHint(), KDialog::spacingHint() ); + frameLayout->addMultiCellWidget( mpixLabel, 0, 2, 0, 0, Qt::AlignTop ); + frameLayout->addLayout( layStatus, 1, 1 ); + + setKDEIcon(); + mStatusLabel->setText("" + i18n("Press Ctrl+Alt+Del to begin.") + ""); + + installEventFilter(this); + + mSAKProcess = new KProcess; + *mSAKProcess << "kdmtsak"; + connect(mSAKProcess, TQT_SIGNAL(processExited(KProcess*)), this, TQT_SLOT(slotSAKProcessExited())); + mSAKProcess->start(); +} + +void SAKDlg::slotSAKProcessExited() +{ + int retcode = mSAKProcess->exitStatus(); + if (retcode != 0) trinity_desktop_lock_use_sak = false; + hide(); +} + +SAKDlg::~SAKDlg() +{ + if ((mSAKProcess) && (mSAKProcess->isRunning())) { + mSAKProcess->kill(SIGTERM); + delete mSAKProcess; + } + hide(); +} + +void SAKDlg::reject() +{ + +} + +void SAKDlg::updateLabel(TQString &txt) +{ + mStatusLabel->setPaletteForegroundColor(Qt::black); + mStatusLabel->setText("" + txt + ""); +} + +void SAKDlg::setUnlockIcon() +{ + mpixLabel->setPixmap(DesktopIcon("unlock")); +} + +void SAKDlg::setKDEIcon() +{ + mpixLabel->setPixmap(DesktopIcon("about_kde")); +} + +void SAKDlg::setInfoIcon() +{ + mpixLabel->setPixmap(DesktopIcon("messagebox_info")); +} + +void SAKDlg::setWarningIcon() +{ + mpixLabel->setPixmap(DesktopIcon("messagebox_warning")); +} + +void SAKDlg::setErrorIcon() +{ + mpixLabel->setPixmap(DesktopIcon("messagebox_critical")); +} + +void SAKDlg::show() +{ + TQDialog::show(); + TQApplication::flushX(); +} + +#include "sakdlg.moc" diff --git a/kdesktop/lock/sakdlg.h b/kdesktop/lock/sakdlg.h new file mode 100644 index 000000000..a9a3c31a0 --- /dev/null +++ b/kdesktop/lock/sakdlg.h @@ -0,0 +1,63 @@ +//=========================================================================== +// +// This file is part of the KDE project +// +// Copyright (c) 2010 Timothy Pearson +// + +#ifndef __SAKDLG_H__ +#define __SAKDLG_H__ + +#include +#include + +#include "lockprocess.h" + +class TQFrame; +class TQGridLayout; +class TQLabel; +class KPushButton; +class TQListView; + +//=========================================================================== +// +// Simple dialog for displaying an info message. +// It does not handle password validation. +// +class SAKDlg : public TQDialog +{ + Q_OBJECT + +public: + SAKDlg(LockProcess *parent); + ~SAKDlg(); + virtual void show(); + + void updateLabel( TQString &txt ); + void setUnlockIcon(); + void setKDEIcon(); + void setInfoIcon(); + void setWarningIcon(); + void setErrorIcon(); + +private slots: + void slotSAKProcessExited(); + +protected slots: + virtual void reject(); + +private: + TQFrame *frame; + TQGridLayout *frameLayout; + TQLabel *mStatusLabel; + TQLabel *mpixLabel; + int mCapsLocked; + bool mUnlockingFailed; + TQStringList layoutsList; + TQStringList::iterator currLayout; + int sPid, sFd; + KProcess* mSAKProcess; +}; + +#endif +