You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1005 lines
27 KiB
1005 lines
27 KiB
15 years ago
|
//===========================================================================
|
||
|
//
|
||
13 years ago
|
// This file is part of the TDE project
|
||
15 years ago
|
//
|
||
|
// Copyright (c) 1999 Martin R. Jones <mjones@kde.org>
|
||
13 years ago
|
// Copyright (c) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net>
|
||
15 years ago
|
//
|
||
|
|
||
|
|
||
|
#include <config.h>
|
||
|
|
||
|
#include <stdlib.h>
|
||
6 years ago
|
#include <sys/stat.h>
|
||
15 years ago
|
|
||
9 years ago
|
#include <ksslcertificate.h>
|
||
|
|
||
|
#include <tdehardwaredevices.h>
|
||
|
#include <tdecryptographiccarddevice.h>
|
||
|
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <kservicegroup.h>
|
||
6 years ago
|
#include <ksimpleconfig.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
9 years ago
|
#include <kuser.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
15 years ago
|
#include <tqfile.h>
|
||
13 years ago
|
#include <tqtimer.h>
|
||
10 years ago
|
#include <tqeventloop.h>
|
||
15 years ago
|
#include <dcopclient.h>
|
||
|
#include <assert.h>
|
||
|
|
||
10 years ago
|
#include <dmctl.h>
|
||
|
|
||
11 years ago
|
#include <dbus/dbus-shared.h>
|
||
|
#include <tqdbusdata.h>
|
||
|
#include <tqdbuserror.h>
|
||
|
#include <tqdbusmessage.h>
|
||
|
#include <tqdbusobjectpath.h>
|
||
|
#include <tqdbusproxy.h>
|
||
|
|
||
15 years ago
|
#include "lockeng.h"
|
||
|
#include "lockeng.moc"
|
||
|
#include "kdesktopsettings.h"
|
||
|
|
||
11 years ago
|
#define SYSTEMD_LOGIN1_SERVICE "org.freedesktop.login1"
|
||
|
#define SYSTEMD_LOGIN1_PATH "/org/freedesktop/login1"
|
||
|
#define SYSTEMD_LOGIN1_MANAGER_IFACE "org.freedesktop.login1.Manager"
|
||
|
#define SYSTEMD_LOGIN1_SESSION_IFACE "org.freedesktop.login1.Session"
|
||
|
#define SYSTEMD_LOGIN1_SEAT_IFACE "org.freedesktop.login1.Seat"
|
||
|
|
||
|
#define DBUS_CONN_NAME "kdesktop_lock"
|
||
|
|
||
15 years ago
|
#include "xautolock_c.h"
|
||
|
extern xautolock_corner_t xautolock_corners[ 4 ];
|
||
|
|
||
13 years ago
|
bool trinity_lockeng_sak_available = TRUE;
|
||
15 years ago
|
|
||
13 years ago
|
SaverEngine* m_masterSaverEngine = NULL;
|
||
|
static void sigusr1_handler(int)
|
||
|
{
|
||
10 years ago
|
if (m_masterSaverEngine) {
|
||
10 years ago
|
m_masterSaverEngine->m_threadHelperObject->slotLockProcessWaiting();
|
||
10 years ago
|
}
|
||
13 years ago
|
}
|
||
13 years ago
|
static void sigusr2_handler(int)
|
||
|
{
|
||
10 years ago
|
if (m_masterSaverEngine) {
|
||
10 years ago
|
m_masterSaverEngine->m_threadHelperObject->slotLockProcessFullyActivated();
|
||
10 years ago
|
}
|
||
13 years ago
|
}
|
||
11 years ago
|
static void sigttin_handler(int)
|
||
|
{
|
||
10 years ago
|
if (m_masterSaverEngine) {
|
||
|
m_masterSaverEngine->slotLockProcessReady();
|
||
|
}
|
||
11 years ago
|
}
|
||
13 years ago
|
|
||
15 years ago
|
//===========================================================================
|
||
|
//
|
||
|
// Screen saver engine. Doesn't handle the actual screensaver window,
|
||
|
// starting screensaver hacks, or password entry. That's done by
|
||
|
// a newly started process.
|
||
|
//
|
||
|
SaverEngine::SaverEngine()
|
||
10 years ago
|
: TQWidget(),
|
||
|
KScreensaverIface(),
|
||
|
mBlankOnly(false),
|
||
|
mSAKProcess(NULL),
|
||
|
mTerminationRequested(false),
|
||
|
mSaverProcessReady(false),
|
||
10 years ago
|
mNewVTAfterLockEngage(false),
|
||
9 years ago
|
mValidCryptoCardInserted(false),
|
||
10 years ago
|
mSwitchVTAfterLockEngage(-1),
|
||
10 years ago
|
dBusLocal(0),
|
||
|
dBusWatch(0),
|
||
|
systemdSession(0)
|
||
15 years ago
|
{
|
||
10 years ago
|
// handle SIGUSR1
|
||
|
m_masterSaverEngine = this;
|
||
|
mSignalAction.sa_handler= sigusr1_handler;
|
||
|
sigemptyset(&(mSignalAction.sa_mask));
|
||
|
sigaddset(&(mSignalAction.sa_mask), SIGUSR1);
|
||
|
mSignalAction.sa_flags = 0;
|
||
|
sigaction(SIGUSR1, &mSignalAction, 0L);
|
||
|
|
||
|
// handle SIGUSR2
|
||
|
m_masterSaverEngine = this;
|
||
|
mSignalAction.sa_handler= sigusr2_handler;
|
||
|
sigemptyset(&(mSignalAction.sa_mask));
|
||
|
sigaddset(&(mSignalAction.sa_mask), SIGUSR2);
|
||
|
mSignalAction.sa_flags = 0;
|
||
|
sigaction(SIGUSR2, &mSignalAction, 0L);
|
||
|
|
||
|
// handle SIGTTIN
|
||
|
m_masterSaverEngine = this;
|
||
|
mSignalAction.sa_handler= sigttin_handler;
|
||
|
sigemptyset(&(mSignalAction.sa_mask));
|
||
|
sigaddset(&(mSignalAction.sa_mask), SIGTTIN);
|
||
|
mSignalAction.sa_flags = 0;
|
||
|
sigaction(SIGTTIN, &mSignalAction, 0L);
|
||
|
|
||
|
// Save X screensaver parameters
|
||
|
XGetScreenSaver(tqt_xdisplay(), &mXTimeout, &mXInterval,
|
||
|
&mXBlanking, &mXExposures);
|
||
|
|
||
|
mState = Waiting;
|
||
|
mXAutoLock = 0;
|
||
|
mEnabled = false;
|
||
|
|
||
10 years ago
|
m_helperThread = new TQEventLoopThread;
|
||
|
m_helperThread->start();
|
||
|
m_threadHelperObject = new SaverEngineThreadHelperObject;
|
||
|
m_threadHelperObject->moveToThread(m_helperThread);
|
||
|
connect(this, TQT_SIGNAL(terminateHelperThread()), m_threadHelperObject, TQT_SLOT(terminateThread()));
|
||
|
connect(m_threadHelperObject, TQT_SIGNAL(lockProcessWaiting()), this, TQT_SLOT(lockProcessWaiting()));
|
||
|
connect(m_threadHelperObject, TQT_SIGNAL(lockProcessFullyActivated()), this, TQT_SLOT(lockProcessFullyActivated()));
|
||
|
|
||
10 years ago
|
connect(&mLockProcess, TQT_SIGNAL(processExited(TDEProcess *)),
|
||
|
TQT_SLOT(lockProcessExited()));
|
||
|
|
||
|
configure();
|
||
|
|
||
6 years ago
|
// Create SAK process only if SAK is enabled
|
||
|
KSimpleConfig *config;
|
||
|
struct stat st;
|
||
|
if (stat( KDE_CONFDIR "/tdm/tdmdistrc" , &st) == 0) {
|
||
|
config = new KSimpleConfig( TQString::fromLatin1( KDE_CONFDIR "/tdm/tdmdistrc" ));
|
||
|
}
|
||
|
else {
|
||
|
config = new KSimpleConfig( TQString::fromLatin1( KDE_CONFDIR "/tdm/tdmrc" ));
|
||
|
}
|
||
|
config->setGroup("X-:*-Greeter");
|
||
|
bool useSAKProcess = false;
|
||
|
#ifdef BUILD_TSAK
|
||
|
useSAKProcess = config->readBoolEntry("UseSAK", false) && KDesktopSettings::useTDESAK();
|
||
|
#endif
|
||
|
if (useSAKProcess) {
|
||
|
mSAKProcess = new TDEProcess;
|
||
|
*mSAKProcess << "tdmtsak";
|
||
|
connect(mSAKProcess, TQT_SIGNAL(processExited(TDEProcess*)), this, TQT_SLOT(slotSAKProcessExited()));
|
||
|
TQTimer::singleShot( 0, this, TQT_SLOT(handleSecureDialog()) );
|
||
|
}
|
||
|
|
||
10 years ago
|
mLockProcess.clearArguments();
|
||
|
TQString path = TDEStandardDirs::findExe( "kdesktop_lock" );
|
||
|
if( path.isEmpty())
|
||
|
{
|
||
|
kdDebug( 1204 ) << "Can't find kdesktop_lock!" << endl;
|
||
|
}
|
||
|
mLockProcess << path;
|
||
|
mLockProcess << TQString( "--internal" ) << TQString( "%1" ).arg(getpid());
|
||
|
if (mLockProcess.start() == false )
|
||
|
{
|
||
|
kdDebug( 1204 ) << "Failed to start kdesktop_lock!" << endl;
|
||
|
}
|
||
|
|
||
10 years ago
|
// Prevent kdesktop_lock signals from being handled by the wrong (GUI) thread
|
||
|
sigemptyset(&mThreadBlockSet);
|
||
|
sigaddset(&mThreadBlockSet, SIGUSR1);
|
||
|
sigaddset(&mThreadBlockSet, SIGUSR2);
|
||
|
sigaddset(&mThreadBlockSet, SIGTTIN);
|
||
|
pthread_sigmask(SIG_BLOCK, &mThreadBlockSet, NULL);
|
||
|
|
||
6 years ago
|
// Wait for the saver process to signal ready...
|
||
|
if (!waitForLockProcessStart()) {
|
||
|
kdDebug( 1204 ) << "Failed to initialize kdesktop_lock (unexpected termination)!" << endl;
|
||
|
}
|
||
|
|
||
|
// lock the desktop if required
|
||
|
config->setGroup("X-:0-Core");
|
||
|
bool autoLoginEnable = config->readBoolEntry("AutoLoginEnable", false);
|
||
|
bool autoLoginLocked = config->readBoolEntry("AutoLoginLocked", false);
|
||
|
if (autoLoginEnable && autoLoginLocked) {
|
||
|
mLockProcess.kill(SIGTTOU);
|
||
|
mLockProcess.kill(SIGUSR1);
|
||
|
}
|
||
|
delete config;
|
||
|
config = NULL;
|
||
|
|
||
9 years ago
|
// Initialize SmartCard readers
|
||
|
TDEGenericDevice *hwdevice;
|
||
|
TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
|
||
|
TDEGenericHardwareList cardReaderList = hwdevices->listByDeviceClass(TDEGenericDeviceType::CryptographicCard);
|
||
|
for (hwdevice = cardReaderList.first(); hwdevice; hwdevice = cardReaderList.next()) {
|
||
|
TDECryptographicCardDevice* cdevice = static_cast<TDECryptographicCardDevice*>(hwdevice);
|
||
|
connect(cdevice, TQT_SIGNAL(certificateListAvailable(TDECryptographicCardDevice*)), this, TQT_SLOT(cryptographicCardInserted(TDECryptographicCardDevice*)));
|
||
|
connect(cdevice, TQT_SIGNAL(cardRemoved(TDECryptographicCardDevice*)), this, TQT_SLOT(cryptographicCardRemoved(TDECryptographicCardDevice*)));
|
||
|
cdevice->enableCardMonitoring(true);
|
||
|
}
|
||
|
|
||
9 years ago
|
// Check card login status
|
||
|
KUser userinfo;
|
||
|
TQString fileName = userinfo.homeDir() + "/.tde_card_login_state";
|
||
|
TQFile flagFile(fileName);
|
||
|
if (flagFile.open(IO_ReadOnly)) {
|
||
|
TQTextStream stream(&flagFile);
|
||
|
if (stream.readLine().startsWith("1")) {
|
||
|
// Card was likely used to log in
|
||
|
TQTimer::singleShot(5000, this, SLOT(cardStartupTimeout()));
|
||
|
}
|
||
|
flagFile.close();
|
||
|
}
|
||
|
|
||
10 years ago
|
dBusConnect();
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
//
|
||
|
// Destructor - usual cleanups.
|
||
|
//
|
||
|
SaverEngine::~SaverEngine()
|
||
|
{
|
||
10 years ago
|
if (mState == Waiting) {
|
||
|
kill(mLockProcess.pid(), SIGKILL);
|
||
|
}
|
||
13 years ago
|
|
||
10 years ago
|
mLockProcess.detach(); // don't kill it if we crash
|
||
|
delete mXAutoLock;
|
||
15 years ago
|
|
||
10 years ago
|
dBusClose();
|
||
11 years ago
|
|
||
10 years ago
|
// Restore X screensaver parameters
|
||
|
XSetScreenSaver(tqt_xdisplay(), mXTimeout, mXInterval, mXBlanking,
|
||
|
mXExposures);
|
||
10 years ago
|
|
||
|
terminateHelperThread();
|
||
|
m_helperThread->wait();
|
||
|
delete m_threadHelperObject;
|
||
|
delete m_helperThread;
|
||
15 years ago
|
}
|
||
|
|
||
9 years ago
|
void SaverEngine::cardStartupTimeout() {
|
||
|
if (!mValidCryptoCardInserted) {
|
||
|
// Restore saver timeout
|
||
|
configure();
|
||
|
|
||
|
// Force lock
|
||
|
lockScreen();
|
||
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
void SaverEngine::cryptographicCardInserted(TDECryptographicCardDevice* cdevice) {
|
||
|
TQString login_name = TQString::null;
|
||
|
X509CertificatePtrList certList = cdevice->cardX509Certificates();
|
||
|
if (certList.count() > 0) {
|
||
|
KSSLCertificate* card_cert = NULL;
|
||
|
card_cert = KSSLCertificate::fromX509(certList[0]);
|
||
|
TQStringList cert_subject_parts = TQStringList::split("/", card_cert->getSubject(), false);
|
||
|
for (TQStringList::Iterator it = cert_subject_parts.begin(); it != cert_subject_parts.end(); ++it ) {
|
||
|
TQString lcpart = (*it).lower();
|
||
|
if (lcpart.startsWith("cn=")) {
|
||
|
login_name = lcpart.right(lcpart.length() - strlen("cn="));
|
||
|
}
|
||
|
}
|
||
|
delete card_cert;
|
||
|
}
|
||
|
|
||
|
if (login_name != "") {
|
||
|
KUser user;
|
||
|
if (login_name == user.loginName()) {
|
||
|
mValidCryptoCardInserted = true;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void SaverEngine::cryptographicCardRemoved(TDECryptographicCardDevice* cdevice) {
|
||
|
if (mValidCryptoCardInserted) {
|
||
9 years ago
|
mValidCryptoCardInserted = false;
|
||
|
|
||
9 years ago
|
// Restore saver timeout
|
||
|
configure();
|
||
|
|
||
|
// Force lock
|
||
|
lockScreen();
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
//---------------------------------------------------------------------------
|
||
10 years ago
|
//
|
||
15 years ago
|
// This should be called only using DCOP.
|
||
10 years ago
|
//
|
||
15 years ago
|
void SaverEngine::lock()
|
||
10 years ago
|
{
|
||
10 years ago
|
lockScreen(true);
|
||
10 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
//
|
||
|
// Lock the screen
|
||
|
//
|
||
|
void SaverEngine::lockScreen(bool DCOP)
|
||
15 years ago
|
{
|
||
9 years ago
|
if (mValidCryptoCardInserted) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
10 years ago
|
bool ok = true;
|
||
9 years ago
|
if (mState == Waiting)
|
||
10 years ago
|
{
|
||
|
ok = startLockProcess( ForceLock );
|
||
|
// It takes a while for kdesktop_lock to start and lock the screen.
|
||
|
// Therefore delay the DCOP call until it tells kdesktop that the locking is in effect.
|
||
|
// This is done only for --forcelock .
|
||
|
if( ok && mState != Saving )
|
||
|
{
|
||
|
if (DCOP) {
|
||
|
DCOPClientTransaction* trans = kapp->dcopClient()->beginTransaction();
|
||
|
if (trans) {
|
||
|
mLockTransactions.append( trans );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mLockProcess.kill( SIGHUP );
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
void SaverEngine::processLockTransactions()
|
||
|
{
|
||
10 years ago
|
for( TQValueVector< DCOPClientTransaction* >::ConstIterator it = mLockTransactions.begin();
|
||
|
it != mLockTransactions.end();
|
||
|
++it )
|
||
|
{
|
||
|
TQCString replyType = "void";
|
||
|
TQByteArray arr;
|
||
|
kapp->dcopClient()->endTransaction( *it, replyType, arr );
|
||
|
}
|
||
|
mLockTransactions.clear();
|
||
15 years ago
|
}
|
||
|
|
||
|
void SaverEngine::saverLockReady()
|
||
|
{
|
||
10 years ago
|
if( mState != Engaging )
|
||
|
{
|
||
|
kdDebug( 1204 ) << "Got unexpected saverReady()" << endl;
|
||
|
}
|
||
|
kdDebug( 1204 ) << "Saver Lock Ready" << endl;
|
||
|
processLockTransactions();
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
void SaverEngine::save()
|
||
|
{
|
||
9 years ago
|
if (!mValidCryptoCardInserted) {
|
||
|
if (mState == Waiting) {
|
||
|
startLockProcess( DefaultLock );
|
||
|
}
|
||
10 years ago
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
void SaverEngine::quit()
|
||
|
{
|
||
10 years ago
|
if (mState == Saving || mState == Engaging)
|
||
|
{
|
||
|
stopLockProcess();
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
bool SaverEngine::isEnabled()
|
||
|
{
|
||
10 years ago
|
return mEnabled;
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
bool SaverEngine::enable( bool e )
|
||
|
{
|
||
10 years ago
|
if ( e == mEnabled )
|
||
15 years ago
|
return true;
|
||
|
|
||
10 years ago
|
// If we aren't in a suitable state, we will not reconfigure.
|
||
|
if (mState != Waiting)
|
||
|
return false;
|
||
15 years ago
|
|
||
10 years ago
|
mEnabled = e;
|
||
15 years ago
|
|
||
9 years ago
|
if (mEnabled) {
|
||
10 years ago
|
if ( !mXAutoLock ) {
|
||
|
mXAutoLock = new XAutoLock();
|
||
|
connect(mXAutoLock, TQT_SIGNAL(timeout()), TQT_SLOT(idleTimeout()));
|
||
|
}
|
||
9 years ago
|
mXAutoLock->setTimeout(mTimeout);
|
||
|
mXAutoLock->setDPMS(true);
|
||
10 years ago
|
//mXAutoLock->changeCornerLockStatus( mLockCornerTopLeft, mLockCornerTopRight, mLockCornerBottomLeft, mLockCornerBottomRight);
|
||
|
|
||
9 years ago
|
// We'll handle blanking
|
||
|
XSetScreenSaver(tqt_xdisplay(), mTimeout + 10, mXInterval, PreferBlanking, mXExposures);
|
||
|
kdDebug() << "XSetScreenSaver " << mTimeout + 10 << endl;
|
||
|
|
||
|
mXAutoLock->start();
|
||
|
|
||
|
kdDebug(1204) << "Saver Engine started, timeout: " << mTimeout << endl;
|
||
15 years ago
|
}
|
||
9 years ago
|
else {
|
||
|
if (mXAutoLock) {
|
||
10 years ago
|
delete mXAutoLock;
|
||
|
mXAutoLock = 0;
|
||
|
}
|
||
|
|
||
|
XForceScreenSaver(tqt_xdisplay(), ScreenSaverReset );
|
||
|
XSetScreenSaver(tqt_xdisplay(), 0, mXInterval, PreferBlanking, DontAllowExposures);
|
||
|
kdDebug(1204) << "Saver Engine disabled" << endl;
|
||
15 years ago
|
}
|
||
|
|
||
10 years ago
|
return true;
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
bool SaverEngine::isBlanked()
|
||
|
{
|
||
10 years ago
|
return (mState != Waiting);
|
||
15 years ago
|
}
|
||
|
|
||
13 years ago
|
void SaverEngine::enableExports()
|
||
|
{
|
||
|
#ifdef Q_WS_X11
|
||
|
kdDebug(270) << k_lineinfo << "activating background exports.\n";
|
||
|
DCOPClient *client = kapp->dcopClient();
|
||
|
if (!client->isAttached()) {
|
||
|
client->attach();
|
||
|
}
|
||
|
TQByteArray data;
|
||
|
TQDataStream args( data, IO_WriteOnly );
|
||
|
args << 1;
|
||
|
|
||
|
TQCString appname( "kdesktop" );
|
||
|
int screen_number = DefaultScreen(tqt_xdisplay());
|
||
10 years ago
|
if ( screen_number ) {
|
||
|
appname.sprintf("kdesktop-screen-%d", screen_number );
|
||
|
}
|
||
13 years ago
|
|
||
|
client->send( appname, "KBackgroundIface", "setExport(int)", data );
|
||
|
#endif
|
||
|
}
|
||
|
|
||
13 years ago
|
//---------------------------------------------------------------------------
|
||
|
void SaverEngine::handleSecureDialog()
|
||
|
{
|
||
10 years ago
|
// Wait for SAK press
|
||
6 years ago
|
if (mSAKProcess && !mSAKProcess->isRunning()) {
|
||
|
mSAKProcess->start();
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
12 years ago
|
void SaverEngine::slotSAKProcessExited()
|
||
13 years ago
|
{
|
||
6 years ago
|
if (!mSAKProcess) {
|
||
|
printf("[kdesktop] SAK process does not exist. Something went wrong. Ignoring...\n"); fflush(stdout);
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
int retcode = mSAKProcess->exitStatus();
|
||
|
if ((retcode != 0) && (mSAKProcess->normalExit())) {
|
||
|
trinity_lockeng_sak_available = FALSE;
|
||
|
printf("[kdesktop] SAK driven secure dialog is not available for use (retcode %d). Check tdmtsak for proper functionality.\n", retcode); fflush(stdout);
|
||
|
}
|
||
|
|
||
|
if (mState == Preparing) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if ((mSAKProcess->normalExit()) && (trinity_lockeng_sak_available == TRUE)) {
|
||
|
bool ok = true;
|
||
|
if (mState == Waiting)
|
||
|
{
|
||
|
ok = startLockProcess( SecureDialog );
|
||
|
if( ok && mState != Saving )
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
mLockProcess.kill( SIGHUP );
|
||
|
}
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
15 years ago
|
//---------------------------------------------------------------------------
|
||
|
//
|
||
|
// Read and apply configuration.
|
||
|
//
|
||
|
void SaverEngine::configure()
|
||
|
{
|
||
10 years ago
|
// If we aren't in a suitable state, we will not reconfigure.
|
||
|
if (mState != Waiting) {
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
|
||
10 years ago
|
// create a new config obj to ensure we read the latest options
|
||
|
KDesktopSettings::self()->readConfig();
|
||
15 years ago
|
|
||
10 years ago
|
bool e = KDesktopSettings::screenSaverEnabled();
|
||
|
mTimeout = KDesktopSettings::timeout();
|
||
15 years ago
|
|
||
10 years ago
|
mEnabled = !e; // force the enable()
|
||
15 years ago
|
|
||
10 years ago
|
int action;
|
||
|
action = KDesktopSettings::actionTopLeft();
|
||
|
xautolock_corners[0] = applyManualSettings(action);
|
||
|
action = KDesktopSettings::actionTopRight();
|
||
|
xautolock_corners[1] = applyManualSettings(action);
|
||
|
action = KDesktopSettings::actionBottomLeft();
|
||
|
xautolock_corners[2] = applyManualSettings(action);
|
||
|
action = KDesktopSettings::actionBottomRight();
|
||
|
xautolock_corners[3] = applyManualSettings(action);
|
||
15 years ago
|
|
||
10 years ago
|
enable( e );
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
//
|
||
|
// Set a variable to indicate only using the blanker and not the saver.
|
||
|
//
|
||
|
void SaverEngine::setBlankOnly( bool blankOnly )
|
||
|
{
|
||
|
mBlankOnly = blankOnly;
|
||
11 years ago
|
// FIXME: if running, stop and restart? What about security
|
||
15 years ago
|
// implications of this?
|
||
|
}
|
||
|
|
||
11 years ago
|
bool SaverEngine::restartDesktopLockProcess()
|
||
15 years ago
|
{
|
||
10 years ago
|
if (!mLockProcess.isRunning()) {
|
||
|
mSaverProcessReady = false;
|
||
|
mLockProcess.clearArguments();
|
||
|
TQString path = TDEStandardDirs::findExe( "kdesktop_lock" );
|
||
|
if (path.isEmpty()) {
|
||
|
kdDebug( 1204 ) << "Can't find kdesktop_lock!" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
mLockProcess << path;
|
||
|
mLockProcess << TQString( "--internal" ) << TQString( "%1" ).arg(getpid());
|
||
|
if (mLockProcess.start() == false) {
|
||
|
kdDebug( 1204 ) << "Failed to start kdesktop_lock!" << endl;
|
||
|
return false;
|
||
|
}
|
||
|
// Wait for the saver process to signal ready...
|
||
10 years ago
|
if (!waitForLockProcessStart()) {
|
||
|
kdDebug( 1204 ) << "Failed to initialize kdesktop_lock (unexpected termination)!" << endl;
|
||
|
return false;
|
||
10 years ago
|
}
|
||
13 years ago
|
}
|
||
10 years ago
|
return true;
|
||
11 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
//
|
||
|
// Start the screen saver.
|
||
|
//
|
||
|
bool SaverEngine::startLockProcess( LockType lock_type )
|
||
|
{
|
||
10 years ago
|
int ret;
|
||
|
|
||
|
if (mState == Saving) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
mState = Preparing;
|
||
6 years ago
|
if (mSAKProcess) {
|
||
|
mSAKProcess->kill(SIGTERM);
|
||
|
}
|
||
10 years ago
|
|
||
|
enableExports();
|
||
|
|
||
|
kdDebug(1204) << "SaverEngine: starting saver" << endl;
|
||
|
emitDCOPSignal("KDE_start_screensaver()", TQByteArray());
|
||
|
|
||
|
if (!restartDesktopLockProcess()) {
|
||
|
mState = Waiting;
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
switch( lock_type )
|
||
|
{
|
||
|
case ForceLock:
|
||
|
mLockProcess.kill(SIGUSR1); // Request forcelock
|
||
|
break;
|
||
|
case DontLock:
|
||
|
mLockProcess.kill(SIGUSR2); // Request dontlock
|
||
|
break;
|
||
|
case SecureDialog:
|
||
|
mLockProcess.kill(SIGWINCH); // Request secure dialog
|
||
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
if (mBlankOnly) {
|
||
|
mLockProcess.kill(SIGTTIN); // Request blanking
|
||
|
}
|
||
|
|
||
|
ret = mLockProcess.kill(SIGTTOU); // Start lock
|
||
|
if (!ret) {
|
||
|
mState = Waiting;
|
||
|
return false;
|
||
|
}
|
||
|
XSetScreenSaver(tqt_xdisplay(), 0, mXInterval, PreferBlanking, mXExposures);
|
||
|
|
||
|
mState = Engaging;
|
||
|
if (mXAutoLock) {
|
||
|
mXAutoLock->stop();
|
||
|
}
|
||
|
return true;
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
//
|
||
|
// Stop the screen saver.
|
||
|
//
|
||
|
void SaverEngine::stopLockProcess()
|
||
|
{
|
||
10 years ago
|
if (mState == Waiting) {
|
||
|
kdWarning(1204) << "SaverEngine::stopSaver() saver not active" << endl;
|
||
|
return;
|
||
|
}
|
||
|
kdDebug(1204) << "SaverEngine: stopping lock" << endl;
|
||
|
emitDCOPSignal("KDE_stop_screensaver()", TQByteArray());
|
||
|
|
||
|
mTerminationRequested = true;
|
||
|
mLockProcess.kill();
|
||
|
|
||
|
if (mEnabled) {
|
||
|
if (mXAutoLock) {
|
||
|
mXAutoLock->start();
|
||
|
}
|
||
|
XForceScreenSaver(tqt_xdisplay(), ScreenSaverReset );
|
||
|
XSetScreenSaver(tqt_xdisplay(), mTimeout + 10, mXInterval, PreferBlanking, mXExposures);
|
||
|
}
|
||
|
processLockTransactions();
|
||
|
mState = Waiting;
|
||
|
|
||
|
if( systemdSession && systemdSession->canSend() ) {
|
||
|
TQValueList<TQT_DBusData> params;
|
||
|
params << TQT_DBusData::fromBool(false);
|
||
|
TQT_DBusMessage reply = systemdSession->sendWithReply("SetIdleHint", params);
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
11 years ago
|
void SaverEngine::recoverFromHackingAttempt()
|
||
|
{
|
||
10 years ago
|
// Try to relaunch saver with forcelock
|
||
|
if (!startLockProcess(ForceLock)) {
|
||
|
// Terminate the TDE session ASAP!
|
||
|
// Values are explained at http://lists.kde.org/?l=kde-linux&m=115770988603387
|
||
|
TQByteArray data;
|
||
|
TQDataStream arg(data, IO_WriteOnly);
|
||
|
arg << (int)0 << (int)0 << (int)2;
|
||
|
if (!kapp->dcopClient()->send("ksmserver", "default", "logout(int,int,int)", data)) {
|
||
|
// Someone got to DCOP before we did
|
||
|
// Try an emergency system logout
|
||
|
system("logout");
|
||
|
}
|
||
|
}
|
||
11 years ago
|
}
|
||
|
|
||
15 years ago
|
void SaverEngine::lockProcessExited()
|
||
|
{
|
||
10 years ago
|
bool abnormalExit = false;
|
||
|
if (mLockProcess.normalExit() == false) {
|
||
|
abnormalExit = true;
|
||
|
}
|
||
|
else {
|
||
|
if (mLockProcess.exitStatus() != 0) {
|
||
|
abnormalExit = true;
|
||
|
}
|
||
|
}
|
||
|
if (mTerminationRequested == true) {
|
||
|
abnormalExit = false;
|
||
|
mTerminationRequested = false;
|
||
|
}
|
||
|
if (abnormalExit == true) {
|
||
|
// PROBABLE HACKING ATTEMPT DETECTED
|
||
|
restartDesktopLockProcess();
|
||
|
mState = Waiting;
|
||
|
TQTimer::singleShot( 100, this, SLOT(recoverFromHackingAttempt()) );
|
||
|
}
|
||
|
else {
|
||
|
// Restart the lock process
|
||
|
restartDesktopLockProcess();
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
10 years ago
|
void SaverEngineThreadHelperObject::slotLockProcessWaiting()
|
||
13 years ago
|
{
|
||
10 years ago
|
// lockProcessWaiting cannot be called directly from a signal handler, as it will hang in certain obscure circumstances
|
||
|
// Instead we use a single-shot timer to immediately call lockProcessWaiting once control has returned to the Qt main loop
|
||
10 years ago
|
lockProcessWaiting();
|
||
|
}
|
||
|
|
||
|
void SaverEngineThreadHelperObject::slotLockProcessFullyActivated()
|
||
|
{
|
||
|
lockProcessFullyActivated();
|
||
13 years ago
|
}
|
||
|
|
||
10 years ago
|
void SaverEngine::lockProcessFullyActivated()
|
||
13 years ago
|
{
|
||
10 years ago
|
mState = Saving;
|
||
11 years ago
|
|
||
10 years ago
|
if( systemdSession && systemdSession->canSend() ) {
|
||
|
TQValueList<TQT_DBusData> params;
|
||
|
params << TQT_DBusData::fromBool(true);
|
||
|
TQT_DBusMessage reply = systemdSession->sendWithReply("SetIdleHint", params);
|
||
|
}
|
||
10 years ago
|
|
||
|
if (mNewVTAfterLockEngage) {
|
||
|
DM().startReserve();
|
||
|
mNewVTAfterLockEngage = false;
|
||
|
}
|
||
|
else if (mSwitchVTAfterLockEngage != -1) {
|
||
|
DM().switchVT(mSwitchVTAfterLockEngage);
|
||
|
mSwitchVTAfterLockEngage = -1;
|
||
|
}
|
||
13 years ago
|
}
|
||
|
|
||
11 years ago
|
void SaverEngine::slotLockProcessReady()
|
||
|
{
|
||
10 years ago
|
mSaverProcessReady = true;
|
||
11 years ago
|
}
|
||
|
|
||
13 years ago
|
void SaverEngine::lockProcessWaiting()
|
||
|
{
|
||
10 years ago
|
kdDebug(1204) << "SaverEngine: lock exited" << endl;
|
||
|
if (trinity_lockeng_sak_available == TRUE) {
|
||
|
handleSecureDialog();
|
||
|
}
|
||
|
if( mState == Waiting ) {
|
||
|
return;
|
||
|
}
|
||
|
emitDCOPSignal("KDE_stop_screensaver()", TQByteArray());
|
||
|
if (mEnabled) {
|
||
|
if (mXAutoLock) {
|
||
|
mXAutoLock->start();
|
||
|
}
|
||
|
XForceScreenSaver(tqt_xdisplay(), ScreenSaverReset );
|
||
|
XSetScreenSaver(tqt_xdisplay(), mTimeout + 10, mXInterval, PreferBlanking, mXExposures);
|
||
|
}
|
||
|
processLockTransactions();
|
||
|
mState = Waiting;
|
||
|
|
||
|
if( systemdSession && systemdSession->canSend() ) {
|
||
|
TQValueList<TQT_DBusData> params;
|
||
|
params << TQT_DBusData::fromBool(false);
|
||
|
TQT_DBusMessage reply = systemdSession->sendWithReply("SetIdleHint", params);
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
//---------------------------------------------------------------------------
|
||
|
//
|
||
|
// XAutoLock has detected the required idle time.
|
||
|
//
|
||
|
void SaverEngine::idleTimeout()
|
||
|
{
|
||
9 years ago
|
if (!mValidCryptoCardInserted) {
|
||
|
// disable X screensaver
|
||
|
XForceScreenSaver(tqt_xdisplay(), ScreenSaverReset );
|
||
|
XSetScreenSaver(tqt_xdisplay(), 0, mXInterval, PreferBlanking, DontAllowExposures);
|
||
|
startLockProcess( DefaultLock );
|
||
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
xautolock_corner_t SaverEngine::applyManualSettings(int action)
|
||
|
{
|
||
10 years ago
|
if (action == 0) {
|
||
15 years ago
|
kdDebug() << "no lock" << endl;
|
||
|
return ca_nothing;
|
||
|
}
|
||
10 years ago
|
else if (action == 1) {
|
||
15 years ago
|
kdDebug() << "lock screen" << endl;
|
||
|
return ca_forceLock;
|
||
|
}
|
||
10 years ago
|
else if (action == 2) {
|
||
15 years ago
|
kdDebug() << "prevent lock" << endl;
|
||
|
return ca_dontLock;
|
||
|
}
|
||
10 years ago
|
else{
|
||
15 years ago
|
kdDebug() << "no lock nothing" << endl;
|
||
|
return ca_nothing;
|
||
|
}
|
||
|
}
|
||
11 years ago
|
|
||
|
/*!
|
||
|
* This function try a reconnect to D-Bus.
|
||
|
* \return boolean with the result of the operation
|
||
|
* \retval true if successful reconnected to D-Bus
|
||
|
* \retval false if unsuccessful
|
||
|
*/
|
||
|
bool SaverEngine::dBusReconnect() {
|
||
|
// close D-Bus connection
|
||
|
dBusClose();
|
||
|
// init D-Bus conntection
|
||
|
return (dBusConnect());
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* This function is used to close D-Bus connection.
|
||
|
*/
|
||
|
void SaverEngine::dBusClose() {
|
||
|
if( dBusConn.isConnected() ) {
|
||
|
if( dBusLocal ) {
|
||
|
delete dBusLocal;
|
||
|
dBusLocal = 0;
|
||
|
}
|
||
|
if( dBusWatch ) {
|
||
|
delete dBusWatch;
|
||
|
dBusWatch = 0;
|
||
|
}
|
||
|
if( systemdSession ) {
|
||
|
delete systemdSession;
|
||
|
systemdSession = 0;
|
||
|
}
|
||
|
}
|
||
|
dBusConn.closeConnection(DBUS_CONN_NAME);
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* This function is used to connect to D-Bus.
|
||
|
*/
|
||
|
bool SaverEngine::dBusConnect() {
|
||
|
dBusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus, DBUS_CONN_NAME);
|
||
|
if( !dBusConn.isConnected() ) {
|
||
10 years ago
|
kdError() << "Failed to open connection to system message bus: " << dBusConn.lastError().message() << endl;
|
||
|
TQTimer::singleShot(4000, this, TQT_SLOT(dBusReconnect()));
|
||
|
return false;
|
||
11 years ago
|
}
|
||
|
|
||
|
// watcher for Disconnect signal
|
||
|
dBusLocal = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_LOCAL, DBUS_INTERFACE_LOCAL, dBusConn);
|
||
|
TQObject::connect(dBusLocal, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
|
||
|
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
|
||
|
|
||
|
// watcher for NameOwnerChanged signals
|
||
|
dBusWatch = new TQT_DBusProxy(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
|
||
|
TQObject::connect(dBusWatch, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
|
||
|
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
|
||
|
|
||
|
// find already running SystemD
|
||
|
TQT_DBusProxy checkSystemD(DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, dBusConn);
|
||
|
if( checkSystemD.canSend() ) {
|
||
|
TQValueList<TQT_DBusData> params;
|
||
|
params << TQT_DBusData::fromString(SYSTEMD_LOGIN1_SERVICE);
|
||
|
TQT_DBusMessage reply = checkSystemD.sendWithReply("NameHasOwner", params);
|
||
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 && reply[0].toBool() ) {
|
||
|
onDBusServiceRegistered(SYSTEMD_LOGIN1_SERVICE);
|
||
|
}
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* This function handles D-Bus service registering
|
||
|
*/
|
||
|
void SaverEngine::onDBusServiceRegistered(const TQString& service) {
|
||
|
if( service == SYSTEMD_LOGIN1_SERVICE ) {
|
||
|
// get current systemd session
|
||
|
TQT_DBusProxy managerIface(SYSTEMD_LOGIN1_SERVICE, SYSTEMD_LOGIN1_PATH, SYSTEMD_LOGIN1_MANAGER_IFACE, dBusConn);
|
||
|
TQT_DBusObjectPath systemdSessionPath = TQT_DBusObjectPath();
|
||
|
if( managerIface.canSend() ) {
|
||
|
TQValueList<TQT_DBusData> params;
|
||
|
params << TQT_DBusData::fromUInt32( getpid() );
|
||
|
TQT_DBusMessage reply = managerIface.sendWithReply("GetSessionByPID", params);
|
||
|
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1 ) {
|
||
|
systemdSessionPath = reply[0].toObjectPath();
|
||
|
}
|
||
|
}
|
||
|
// wather for systemd session signals
|
||
|
if( systemdSessionPath.isValid() ) {
|
||
|
systemdSession = new TQT_DBusProxy(SYSTEMD_LOGIN1_SERVICE, systemdSessionPath, SYSTEMD_LOGIN1_SESSION_IFACE, dBusConn);
|
||
|
TQObject::connect(systemdSession, TQT_SIGNAL(dbusSignal(const TQT_DBusMessage&)),
|
||
|
this, TQT_SLOT(handleDBusSignal(const TQT_DBusMessage&)));
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* This function handles D-Bus service unregistering
|
||
|
*/
|
||
|
void SaverEngine::onDBusServiceUnregistered(const TQString& service) {
|
||
|
if( service == SYSTEMD_LOGIN1_SERVICE ) {
|
||
|
if( systemdSession ) {
|
||
|
delete systemdSession;
|
||
|
systemdSession = 0;
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
* This function handles signals from the D-Bus daemon.
|
||
|
*/
|
||
|
void SaverEngine::handleDBusSignal(const TQT_DBusMessage& msg) {
|
||
|
// dbus terminated
|
||
|
if( msg.path() == DBUS_PATH_LOCAL
|
||
|
&& msg.interface() == DBUS_INTERFACE_LOCAL
|
||
|
&& msg.member() == "Disconnected" ) {
|
||
|
dBusClose();
|
||
|
TQTimer::singleShot(1000, this, TQT_SLOT(dBusReconnect()));
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// service registered / unregistered
|
||
|
if( msg.path() == DBUS_PATH_DBUS
|
||
|
&& msg.interface() == DBUS_INTERFACE_DBUS
|
||
|
&& msg.member() == "NameOwnerChanged" ) {
|
||
|
if( msg[1].toString().isEmpty() ) {
|
||
|
// old-owner is empty
|
||
|
onDBusServiceRegistered(msg[0].toString());
|
||
|
}
|
||
|
if( msg[2].toString().isEmpty() ) {
|
||
|
// new-owner is empty
|
||
|
onDBusServiceUnregistered(msg[0].toString());
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// systemd signal Lock()
|
||
|
if( systemdSession && systemdSession->canSend()
|
||
|
&& msg.path() == systemdSession->path()
|
||
|
&& msg.interface() == SYSTEMD_LOGIN1_SESSION_IFACE
|
||
|
&& msg.member() == "Lock") {
|
||
10 years ago
|
lockScreen();
|
||
11 years ago
|
return;
|
||
|
}
|
||
|
|
||
|
// systemd signal Unlock()
|
||
|
if( systemdSession && systemdSession->canSend()
|
||
|
&& msg.path() == systemdSession->path()
|
||
|
&& msg.interface() == SYSTEMD_LOGIN1_SESSION_IFACE
|
||
|
&& msg.member() == "Unlock") {
|
||
|
// unlock?
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
bool SaverEngine::waitForLockProcessStart() {
|
||
|
sigset_t new_mask;
|
||
10 years ago
|
sigset_t empty_mask;
|
||
|
sigemptyset(&empty_mask);
|
||
10 years ago
|
|
||
10 years ago
|
// ensure that SIGCHLD is not subject to a race condition
|
||
10 years ago
|
sigemptyset(&new_mask);
|
||
|
sigaddset(&new_mask, SIGCHLD);
|
||
|
|
||
10 years ago
|
pthread_sigmask(SIG_BLOCK, &new_mask, NULL);
|
||
10 years ago
|
while ((mLockProcess.isRunning()) && (!mSaverProcessReady)) {
|
||
10 years ago
|
// wait for any signal(s) to arrive
|
||
10 years ago
|
sigsuspend(&empty_mask);
|
||
10 years ago
|
}
|
||
10 years ago
|
pthread_sigmask(SIG_UNBLOCK, &new_mask, NULL);
|
||
10 years ago
|
|
||
|
return mLockProcess.isRunning();
|
||
|
}
|
||
|
|
||
|
bool SaverEngine::waitForLockEngage() {
|
||
10 years ago
|
sigset_t empty_mask;
|
||
|
sigemptyset(&empty_mask);
|
||
10 years ago
|
|
||
|
// wait for SIGUSR1, SIGUSR2, SIGTTIN
|
||
10 years ago
|
while ((mLockProcess.isRunning()) && (mState != Waiting) && (mState != Saving)) {
|
||
10 years ago
|
// wait for any signal(s) to arrive
|
||
10 years ago
|
sigsuspend(&empty_mask);
|
||
10 years ago
|
}
|
||
10 years ago
|
|
||
|
return mLockProcess.isRunning();
|
||
10 years ago
|
}
|
||
|
|
||
10 years ago
|
void SaverEngine::lockScreenAndDoNewSession() {
|
||
|
mNewVTAfterLockEngage = true;
|
||
|
lockScreen();
|
||
|
}
|
||
|
|
||
|
void SaverEngine::lockScreenAndSwitchSession(int vt) {
|
||
|
mSwitchVTAfterLockEngage = vt;
|
||
|
lockScreen();
|
||
|
}
|
||
|
|
||
10 years ago
|
void SaverEngineThreadHelperObject::terminateThread() {
|
||
|
TQEventLoop* eventLoop = TQApplication::eventLoop();
|
||
|
if (eventLoop) {
|
||
|
eventLoop->exit(0);
|
||
|
}
|
||
10 years ago
|
}
|