Use DM library in tdmtsak instead of making command line calls

pull/2/head
Timothy Pearson 9 years ago
parent cd13be0789
commit 6d028f3b52

@ -124,7 +124,7 @@ void SAKDlg::slotSAKProcessExited()
SAKDlg::~SAKDlg() SAKDlg::~SAKDlg()
{ {
if ((mSAKProcess) && (mSAKProcess->isRunning())) { if ((mSAKProcess) && (mSAKProcess->isRunning())) {
mSAKProcess->kill(SIGTERM); mSAKProcess->kill(SIGKILL);
delete mSAKProcess; delete mSAKProcess;
} }
hide(); hide();

@ -222,7 +222,7 @@ void SAKDlg::cryptographicCardRemoved(TDECryptographicCardDevice* cdevice) {
SAKDlg::~SAKDlg() SAKDlg::~SAKDlg()
{ {
if ((mSAKProcess) && (mSAKProcess->isRunning())) { if ((mSAKProcess) && (mSAKProcess->isRunning())) {
mSAKProcess->kill(SIGTERM); mSAKProcess->kill(SIGKILL);
delete mSAKProcess; delete mSAKProcess;
} }

@ -77,7 +77,7 @@ endif( )
if( BUILD_TSAK ) if( BUILD_TSAK )
tde_add_executable( tdmtsak tde_add_executable( tdmtsak
SOURCES tdmtsak.cpp SOURCES tdmtsak.cpp
LINK ${TQT_LIBRARIES} LINK ${TQT_LIBRARIES} tdecore-shared dmctl-static
DESTINATION ${BIN_INSTALL_DIR} DESTINATION ${BIN_INSTALL_DIR}
SETUID SETUID
DESCRIPTION "Secure Attention Key interface for TDM" DESCRIPTION "Secure Attention Key interface for TDM"

@ -1,6 +1,6 @@
/* /*
This file is part of the TDE project This file is part of the TDE project
Copyright (C) 2011 Timothy Pearson <kb9vqf@pearsoncomputing.net> Copyright (C) 2011 - 2015 Timothy Pearson <kb9vqf@pearsoncomputing.net>
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
@ -18,10 +18,12 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#include "tdmtsak.h"
#include <tqstringlist.h> #include <tqstringlist.h>
#include "dmctl.h"
#include "tdmtsak.h"
#define FIFO_FILE "/tmp/tdesocket-global/tsak" #define FIFO_FILE "/tmp/tdesocket-global/tsak"
TQString exec(const char * cmd) { TQString exec(const char * cmd) {
@ -44,15 +46,17 @@ bool is_vt_local() {
return false; return false;
} }
else { else {
TQString cvtName = ""; DM dm;
TQString output = exec("tdmctl list"); SessList sess;
TQStringList sessionList = TQStringList::split('\t', output, false); if (dm.localSessions(sess)) {
// See if the current session is local TQString user, loc;
for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) { for (SessList::ConstIterator it = sess.begin(); it != sess.end(); ++it) {
TQStringList sessionInfoList = TQStringList::split(',', *it, true); DM::sess2Str2(*it, user, loc);
if ((*(sessionInfoList.at(0))).startsWith(":")) { TQStringList sessionInfoList = TQStringList::split(',', loc, true);
if (TQString(currentDisplay).startsWith(*(sessionInfoList.at(0)))) { if ((*(sessionInfoList.at(0))).startsWith(":")) {
return true; if (TQString(currentDisplay).startsWith(*(sessionInfoList.at(0)))) {
return true;
}
} }
} }
} }
@ -68,44 +72,54 @@ bool is_vt_active() {
return true; return true;
} }
else { else {
DM dm;
SessList sess;
TQString cvtName = ""; TQString cvtName = "";
TQString output = exec("tdmctl list"); TQString curConsole;
TQString curConsole = exec("fgconsole"); int curConsoleNum = dm.activeVT();
bool intFound; if (curConsoleNum < 0) {
int curConsoleNum = curConsole.toInt(&intFound);
if (intFound == false) {
return true; return true;
} }
curConsole = TQString("vt%1").arg(curConsoleNum);; curConsole = TQString("vt%1").arg(curConsoleNum);
TQStringList sessionList = TQStringList::split('\t', output, false); if (dm.localSessions(sess)) {
for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) { TQString user, loc;
TQStringList sessionInfoList = TQStringList::split(',', *it, true); for (SessList::ConstIterator it = sess.begin(); it != sess.end(); ++it) {
if ((*(sessionInfoList.at(0))).startsWith(":")) { DM::sess2Str2(*it, user, loc);
if ((*(sessionInfoList.at(1))) == TQString(curConsole)) { TQStringList sessionInfoList = TQStringList::split(',', loc, true);
cvtName = (*(sessionInfoList.at(0))); if ((*(sessionInfoList.at(0))).startsWith(":")) {
if ((*(sessionInfoList.at(1))).stripWhiteSpace() == TQString(curConsole)) {
cvtName = (*(sessionInfoList.at(0)));
}
} }
} }
} if (cvtName != "") {
if (cvtName != "") { if (TQString(currentDisplay).startsWith(cvtName)) {
if (TQString(currentDisplay).startsWith(cvtName)) { return true;
return true; }
else {
return false;
}
} }
else { else {
return false; // See if the current session is local
} // If it is, then the VT is not currently active and the SAK must be requested later when it is active
} for (SessList::ConstIterator it = sess.begin(); it != sess.end(); ++it) {
else { DM::sess2Str2(*it, user, loc);
// See if the current session is local if ((*it).self) {
// If it is, then the VT is not currently active and the SAK must be requested later when it is active TQStringList sessionInfoList = TQStringList::split(',', loc, true);
for ( TQStringList::Iterator it = sessionList.begin(); it != sessionList.end(); ++it ) { if ((*(sessionInfoList.at(1))).startsWith(" vt")) {
TQStringList sessionInfoList = TQStringList::split(',', *it, true); // Local and inactive
if ((*(sessionInfoList.at(0))).startsWith(":")) { return false;
if (TQString(currentDisplay).startsWith(*(sessionInfoList.at(0)))) { }
return false;
} }
} }
// Hmm, not local
// Do not reject the SAK
return true;
} }
// Hmm, not local }
else {
// Failure!
// Do not reject the SAK // Do not reject the SAK
return true; return true;
} }

Loading…
Cancel
Save