summaryrefslogtreecommitdiffstats
path: root/tdmlib
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2015-09-17 17:30:17 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2015-09-17 17:30:17 -0500
commitce477303019c7f3ba18dcab48e4205d59614ce5a (patch)
tree19e49c43c92ba12de306af4f92f3fda64d9e92b8 /tdmlib
parent5d20ad97bffa56b2e366989e71ac9429116c017d (diff)
downloadtdebase-ce477303019c7f3ba18dcab48e4205d59614ce5a.tar.gz
tdebase-ce477303019c7f3ba18dcab48e4205d59614ce5a.zip
Add initial cryptographic card login support
Tested with themed greeter and SAK disabled
Diffstat (limited to 'tdmlib')
-rw-r--r--tdmlib/dmctl.cpp88
-rw-r--r--tdmlib/kgreet_classic.cpp69
-rw-r--r--tdmlib/kgreet_classic.h3
-rw-r--r--tdmlib/kgreet_pam.cpp4
-rw-r--r--tdmlib/kgreet_pam.h1
-rw-r--r--tdmlib/kgreet_winbind.cpp4
-rw-r--r--tdmlib/kgreet_winbind.h1
-rw-r--r--tdmlib/kgreeterplugin.h8
8 files changed, 148 insertions, 30 deletions
diff --git a/tdmlib/dmctl.cpp b/tdmlib/dmctl.cpp
index 75e88fc6e..00c3cb489 100644
--- a/tdmlib/dmctl.cpp
+++ b/tdmlib/dmctl.cpp
@@ -25,6 +25,7 @@
#include <dcopclient.h>
#include <tqregexp.h>
+#include <tqfile.h>
#include <X11/Xauth.h>
#include <X11/Xlib.h>
@@ -37,8 +38,34 @@
#include <fcntl.h>
#include <errno.h>
+#include <config.h>
+
+static TQString readcfg(const char *cfg_file) {
+ TQString ctl = "/var/run/xdmctl";
+
+ TQStringList lines;
+ TQFile file(cfg_file);
+ if ( file.open( IO_ReadOnly ) ) {
+ TQTextStream stream(&file);
+ TQString line;
+ while ( !stream.atEnd() ) {
+ line = stream.readLine();
+ TQStringList keyvaluepair = TQStringList::split("=", line, false);
+ if (keyvaluepair.count() > 1) {
+ if (keyvaluepair[0].lower() == "FifoDir") {
+ ctl = keyvaluepair[1];
+ }
+ }
+ }
+ file.close();
+ }
+
+ return ctl;
+}
+
static int DMType = DM::Unknown;
-static const char *ctl, *dpy;
+static const char *dpy;
+static TQString ctl;
DM::DM() : fd( -1 )
{
@@ -46,16 +73,27 @@ DM::DM() : fd( -1 )
struct sockaddr_un sa;
if (DMType == Unknown) {
- if (!(dpy = ::getenv( "DISPLAY" )))
- DMType = NoDM;
- else if ((ctl = ::getenv( "DM_CONTROL" )))
+ if (!(dpy = ::getenv( "DISPLAY" ))) {
+ // Try to read TDM control file
+ if ((ctl = readcfg(KDE_CONFDIR "/tdm/tdmrc")) != TQString::null) {
+ DMType = NewTDM;
+ }
+ else {
+ DMType = NoDM;
+ }
+ }
+ else if ((ctl = ::getenv( "DM_CONTROL" )) != TQString::null) {
DMType = NewTDM;
- else if ((ctl = ::getenv( "XDM_MANAGED" )) && ctl[0] == '/')
+ }
+ else if (((ctl = ::getenv( "XDM_MANAGED" )) != TQString::null) && ctl[0] == '/') {
DMType = OldTDM;
- else if (::getenv( "GDMSESSION" ))
+ }
+ else if (::getenv( "GDMSESSION" )) {
DMType = GDM;
- else
+ }
+ else {
DMType = NoDM;
+ }
}
switch (DMType) {
default:
@@ -76,12 +114,17 @@ DM::DM() : fd( -1 )
}
}
GDMAuthenticate();
- } else {
- if ((ptr = const_cast<char*>(strchr( dpy, ':' ))))
- ptr = strchr( ptr, '.' );
- snprintf( sa.sun_path, sizeof(sa.sun_path),
- "%s/dmctl-%.*s/socket",
- ctl, ptr ? int(ptr - dpy) : 512, dpy );
+ }
+ else {
+ if (!dpy) {
+ snprintf( sa.sun_path, sizeof(sa.sun_path), "%s/dmctl/socket", ctl.ascii() );
+ }
+ else {
+ if ((ptr = const_cast<char*>(strchr( dpy, ':' )))) {
+ ptr = strchr( ptr, '.' );
+ }
+ snprintf( sa.sun_path, sizeof(sa.sun_path), "%s/dmctl-%.*s/socket", ctl.ascii(), ptr ? int(ptr - dpy) : 512, dpy );
+ }
if (::connect( fd, (struct sockaddr *)&sa, sizeof(sa) )) {
::close( fd );
fd = -1;
@@ -100,8 +143,9 @@ DM::DM() : fd( -1 )
DM::~DM()
{
- if (fd >= 0)
+ if (fd >= 0) {
close( fd );
+ }
}
bool
@@ -172,13 +216,15 @@ DM::exec( const char *cmd, TQCString &buf )
bool
DM::canShutdown()
{
- if (DMType == OldTDM)
- return strstr( ctl, ",maysd" ) != 0;
+ if (DMType == OldTDM) {
+ return strstr( ctl.ascii(), ",maysd" ) != 0;
+ }
TQCString re;
- if (DMType == GDM)
+ if (DMType == GDM) {
return exec( "QUERY_LOGOUT_ACTION\n", re ) && re.find("HALT") >= 0;
+ }
return exec( "caps\n", re ) && re.find( "\tshutdown" ) >= 0;
}
@@ -282,7 +328,7 @@ DM::numReserve()
return 1; /* Bleh */
if (DMType == OldTDM)
- return strstr( ctl, ",rsvd" ) ? 1 : -1;
+ return strstr( ctl.ascii(), ",rsvd" ) ? 1 : -1;
TQCString re;
int p;
@@ -304,8 +350,9 @@ DM::startReserve()
bool
DM::localSessions( SessList &list )
{
- if (DMType == OldTDM)
+ if (DMType == OldTDM) {
return false;
+ }
TQCString re;
@@ -325,8 +372,9 @@ DM::localSessions( SessList &list )
list.append( se );
}
} else {
- if (!exec( "list\talllocal\n", re ))
+ if (!exec( "list\talllocal\n", re )) {
return false;
+ }
TQStringList sess = TQStringList::split( TQChar('\t'), re.data() + 3 );
for (TQStringList::ConstIterator it = sess.begin(); it != sess.end(); ++it) {
TQStringList ts = TQStringList::split( TQChar(','), *it, true );
diff --git a/tdmlib/kgreet_classic.cpp b/tdmlib/kgreet_classic.cpp
index 3d1cedc19..6aac4d96a 100644
--- a/tdmlib/kgreet_classic.cpp
+++ b/tdmlib/kgreet_classic.cpp
@@ -45,6 +45,15 @@ protected:
static int echoMode;
+TQString KClassicGreeter::passwordPrompt() {
+ if (func == Authenticate) {
+ return i18n("&Password:");
+ }
+ else {
+ return i18n("Current &password:");
+ }
+}
+
KClassicGreeter::KClassicGreeter( KGreeterPluginHandler *_handler,
KdmThemer *themer,
TQWidget *parent, TQWidget *pred,
@@ -60,7 +69,7 @@ KClassicGreeter::KClassicGreeter( KGreeterPluginHandler *_handler,
running( false )
{
KdmItem *user_entry = 0, *pw_entry = 0;
- TQGridLayout *grid = 0;
+ grid = 0;
int line = 0;
layoutItem = 0;
@@ -120,11 +129,7 @@ KClassicGreeter::KClassicGreeter( KGreeterPluginHandler *_handler,
passwdEdit->adjustSize();
pw_entry->setWidget( passwdEdit );
} else {
- passwdLabel = new TQLabel( passwdEdit,
- func == Authenticate ?
- i18n("&Password:") :
- i18n("Current &password:"),
- parent );
+ passwdLabel = new TQLabel( passwdEdit, passwordPrompt(), parent );
grid->addWidget( passwdLabel, line, 0 );
grid->addWidget( passwdEdit, line++, 1 );
}
@@ -217,6 +222,10 @@ KClassicGreeter::setUser( const TQString &user )
passwdEdit->selectAll();
}
+void KClassicGreeter::lockUserEntry( const bool lock ) {
+ loginEdit->setEnabled(!lock);
+}
+
void // virtual
KClassicGreeter::setPassword( const TQString &pass )
{
@@ -276,10 +285,24 @@ void // virtual
KClassicGreeter::textPrompt( const char *prompt, bool echo, bool nonBlocking )
{
pExp = exp;
- if (echo)
+ if (echo) {
exp = 0;
- else if (!authTok)
+ }
+ else if (!authTok) {
exp = 1;
+ if (passwdLabel) {
+ if (prompt && (prompt[0] != 0)) {
+ passwdLabel->setText(prompt);
+ }
+ else {
+ passwdLabel->setText(passwordPrompt());
+ }
+ if (grid) {
+ grid->invalidate();
+ grid->activate();
+ }
+ }
+ }
else {
TQString pr( prompt );
if (pr.find( TQRegExp( "\\bpassword\\b", false ) ) >= 0) {
@@ -294,7 +317,8 @@ KClassicGreeter::textPrompt( const char *prompt, bool echo, bool nonBlocking )
KGreeterPluginHandler::IsSecret );
return;
}
- } else {
+ }
+ else {
handler->gplugMsgBox( TQMessageBox::Critical,
i18n("Unrecognized prompt \"%1\"")
.arg( prompt ) );
@@ -392,6 +416,15 @@ KClassicGreeter::succeeded()
void // virtual
KClassicGreeter::failed()
{
+ if (passwdLabel) {
+ // reset password prompt
+ passwdLabel->setText(passwordPrompt());
+ if (grid) {
+ grid->invalidate();
+ grid->activate();
+ }
+ }
+
// assert( running || timed_login );
setActive( false );
setActive2( false );
@@ -402,6 +435,15 @@ KClassicGreeter::failed()
void // virtual
KClassicGreeter::revive()
{
+ if (passwdLabel) {
+ // reset password prompt
+ passwdLabel->setText(passwordPrompt());
+ if (grid) {
+ grid->invalidate();
+ grid->activate();
+ }
+ }
+
// assert( !running );
setActive2( true );
if (authTok) {
@@ -425,6 +467,15 @@ KClassicGreeter::revive()
void // virtual
KClassicGreeter::clear()
{
+ if (passwdLabel) {
+ // reset password prompt
+ passwdLabel->setText(passwordPrompt());
+ if (grid) {
+ grid->invalidate();
+ grid->activate();
+ }
+ }
+
// assert( !running && !passwd1Edit );
passwdEdit->erase();
if (loginEdit) {
diff --git a/tdmlib/kgreet_classic.h b/tdmlib/kgreet_classic.h
index 1f467a528..78bacf50d 100644
--- a/tdmlib/kgreet_classic.h
+++ b/tdmlib/kgreet_classic.h
@@ -50,6 +50,7 @@ class KClassicGreeter : public TQObject, public KGreeterPlugin {
virtual void presetEntity( const TQString &entity, int field );
virtual TQString getEntity() const;
virtual void setUser( const TQString &user );
+ virtual void lockUserEntry( const bool lock );
virtual void setPassword( const TQString &pass );
virtual void setEnabled( bool on );
virtual bool textMessage( const char *message, bool error );
@@ -70,6 +71,7 @@ class KClassicGreeter : public TQObject, public KGreeterPlugin {
void slotActivity();
private:
+ TQString passwordPrompt();
void setActive( bool enable );
void setActive2( bool enable );
void returnData();
@@ -81,6 +83,7 @@ class KClassicGreeter : public TQObject, public KGreeterPlugin {
TQString fixedUser, curUser;
Function func;
Context ctx;
+ TQGridLayout* grid;
int exp, pExp, has;
bool running, authTok;
};
diff --git a/tdmlib/kgreet_pam.cpp b/tdmlib/kgreet_pam.cpp
index b16dfb440..97d19afde 100644
--- a/tdmlib/kgreet_pam.cpp
+++ b/tdmlib/kgreet_pam.cpp
@@ -263,6 +263,10 @@ KPamGreeter::setUser( const TQString &user )
}
}
+void KPamGreeter::lockUserEntry( const bool lock ) {
+ loginEdit->setEnabled(!lock);
+}
+
void // virtual
KPamGreeter::setPassword( const TQString &pass )
{
diff --git a/tdmlib/kgreet_pam.h b/tdmlib/kgreet_pam.h
index 03c404c1e..7772880a1 100644
--- a/tdmlib/kgreet_pam.h
+++ b/tdmlib/kgreet_pam.h
@@ -50,6 +50,7 @@ class KPamGreeter : public TQObject, public KGreeterPlugin {
virtual void presetEntity( const TQString &entity, int field );
virtual TQString getEntity() const;
virtual void setUser( const TQString &user );
+ virtual void lockUserEntry( const bool lock );
virtual void setPassword( const TQString &pass );
virtual void setEnabled( bool on );
virtual bool textMessage( const char *message, bool error );
diff --git a/tdmlib/kgreet_winbind.cpp b/tdmlib/kgreet_winbind.cpp
index aa7e39b18..53b992fa6 100644
--- a/tdmlib/kgreet_winbind.cpp
+++ b/tdmlib/kgreet_winbind.cpp
@@ -297,6 +297,10 @@ KWinbindGreeter::setUser( const TQString &user )
passwdEdit->selectAll();
}
+void KWinbindGreeter::lockUserEntry( const bool lock ) {
+ loginEdit->setEnabled(!lock);
+}
+
void // virtual
KWinbindGreeter::setPassword( const TQString &pass )
{
diff --git a/tdmlib/kgreet_winbind.h b/tdmlib/kgreet_winbind.h
index 54f2653fc..8c41ca5d7 100644
--- a/tdmlib/kgreet_winbind.h
+++ b/tdmlib/kgreet_winbind.h
@@ -54,6 +54,7 @@ class KWinbindGreeter : public TQObject, public KGreeterPlugin {
virtual void presetEntity( const TQString &entity, int field );
virtual TQString getEntity() const;
virtual void setUser( const TQString &user );
+ virtual void lockUserEntry( const bool lock );
virtual void setPassword( const TQString &pass );
virtual void setEnabled( bool on );
virtual bool textMessage( const char *message, bool error );
diff --git a/tdmlib/kgreeterplugin.h b/tdmlib/kgreeterplugin.h
index 925828455..4604a6aac 100644
--- a/tdmlib/kgreeterplugin.h
+++ b/tdmlib/kgreeterplugin.h
@@ -152,6 +152,12 @@ public:
virtual void setUser( const TQString &user ) = 0;
/**
+ * Lock or unlock editing of the username entry field
+ * @param lock true to lock, false to unlock
+ */
+ virtual void lockUserEntry( const bool lock ) = 0;
+
+ /**
* "Push" a password into the talker.
* @param pass the password to set.
*/
@@ -183,7 +189,7 @@ public:
/**
* Prompt the user for data. Reply by calling handler->gplugReturnText().
- * @param propmt the prompt to display. It may be null, in which case
+ * @param prompt the prompt to display. It may be null, in which case
* "Username"/"Password" should be shown and the replies should be tagged
* with the respective Is* flag.
* @param echo if true, a normal input widget can be used, otherwise one that