Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Small update to PCDM:
Browse files Browse the repository at this point in the history
1) Clean up session management/restarts (in case login fails during all the PAM or user/group changes)
2) Update the location of the lastlogin file (/var/db/pcdm/lastlogin), and make sure it is getting saved/loaded properly.
  • Loading branch information
Ken Moore committed Mar 14, 2014
1 parent 370de21 commit fdf420c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
15 changes: 4 additions & 11 deletions src-qt4/PCDM/src/main.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -144,11 +144,8 @@ int runSingleSession(int argc, char *argv[]){
w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint); w.setWindowFlags(Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
w.setWindowState(Qt::WindowMaximized); //Qt::WindowFullScreen); w.setWindowState(Qt::WindowMaximized); //Qt::WindowFullScreen);


//Setup the signals/slots to startup the desktop session //Setup the signals/slots to startup the desktop session
//if(USECLIBS){ QObject::connect( &w,SIGNAL(xLoginAttempt(QString,QString,QString)), &desktop,SLOT(setupDesktop(QString,QString,QString))); } QObject::connect( &w,SIGNAL(xLoginAttempt(QString,QString,QString,QString)), &desktop,SLOT(loginToXSession(QString,QString,QString,QString)) );
//else{
QObject::connect( &w,SIGNAL(xLoginAttempt(QString,QString,QString,QString)), &desktop,SLOT(loginToXSession(QString,QString,QString,QString)) );
//}
//Setup the signals/slots for return information for the GUI //Setup the signals/slots for return information for the GUI
QObject::connect( &desktop, SIGNAL(InvalidLogin()), &w, SLOT(slotLoginFailure()) ); QObject::connect( &desktop, SIGNAL(InvalidLogin()), &w, SLOT(slotLoginFailure()) );
QObject::connect( &desktop, SIGNAL(started()), &w, SLOT(slotLoginSuccess()) ); QObject::connect( &desktop, SIGNAL(started()), &w, SLOT(slotLoginSuccess()) );
Expand All @@ -159,10 +156,7 @@ int runSingleSession(int argc, char *argv[]){
retCode = a.exec(); retCode = a.exec();
} // end of PCDM GUI running } // end of PCDM GUI running
//Wait for the desktop session to finish before exiting //Wait for the desktop session to finish before exiting
//if(USECLIBS){ desktop.startDesktop(); }
//else{
desktop.waitForSessionClosed(); desktop.waitForSessionClosed();
//}
splash.show(); //show the splash screen again splash.show(); //show the splash screen again
//Now wait a couple seconds for things to settle //Now wait a couple seconds for things to settle
QTime wTime = QTime::currentTime().addSecs(2); QTime wTime = QTime::currentTime().addSecs(2);
Expand All @@ -179,8 +173,6 @@ int runSingleSession(int argc, char *argv[]){
//Keep processing events during the wait (for splashscreen) //Keep processing events during the wait (for splashscreen)
QCoreApplication::processEvents(QEventLoop::AllEvents, 100); QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
} }
//set the return code for a shutdown
retCode = -1; //make sure it does not start a new session
} }


//Clean up Code //Clean up Code
Expand Down Expand Up @@ -213,7 +205,8 @@ int main(int argc, char *argv[])
int retCode = runSingleSession(argc,argv); int retCode = runSingleSession(argc,argv);
qDebug() << "-- PCDM Session Ended --"; qDebug() << "-- PCDM Session Ended --";
//check for special exit code //check for special exit code
if(retCode != 0){ neverquit=FALSE; } if(retCode == -1){ neverquit=true; } //make sure we go around again at least once
else if(retCode != 0){ neverquit=FALSE; }
//Now kill the shild process (whole session) //Now kill the shild process (whole session)
qDebug() << "Exiting child process"; qDebug() << "Exiting child process";
exit(3); exit(3);
Expand Down
29 changes: 17 additions & 12 deletions src-qt4/PCDM/src/pcdm-backend.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ QString Backend::getUsernameFromDisplayname(QString dspname){


QString Backend::getDisplayNameFromUsername(QString username){ QString Backend::getDisplayNameFromUsername(QString username){
int i = usernameList.indexOf(username); int i = usernameList.indexOf(username);
return displaynameList[i]; if(i==-1){ i = displaynameList.indexOf(username); } //make sure it was not a display name passed in
if(i==-1){ return ""; }
else{
return displaynameList[i];
}
} }


QString Backend::getUserHomeDir(QString username){ QString Backend::getUserHomeDir(QString username){
Expand Down Expand Up @@ -249,8 +253,8 @@ void Backend::checkLocalDirs(){
//Check for sample files //Check for sample files
if(!mainDir.exists("pcdm.conf.sample")){ QFile::copy(":samples/pcdm.conf",base+"/pcdm.conf.sample"); } if(!mainDir.exists("pcdm.conf.sample")){ QFile::copy(":samples/pcdm.conf",base+"/pcdm.conf.sample"); }
//Check for the PCDM runtime directory //Check for the PCDM runtime directory
mainDir.cd("/var/db/pcdm"); mainDir.cd(DBDIR);
if(!mainDir.exists()){ mainDir.mkdir("/var/db/pcdm"); } if(!mainDir.exists()){ mainDir.mkpath(DBDIR); }
} }


QString Backend::getLastUser(){ QString Backend::getLastUser(){
Expand All @@ -259,7 +263,8 @@ QString Backend::getLastUser(){
readSystemLastLogin(); readSystemLastLogin();
} }
//return the value //return the value
return lastUser; QString user = getDisplayNameFromUsername(lastUser);
return user;
} }


QString Backend::getLastDE(QString user){ QString Backend::getLastDE(QString user){
Expand All @@ -273,7 +278,7 @@ QString Backend::getLastDE(QString user){
} }


void Backend::saveLoginInfo(QString user, QString desktop){ void Backend::saveLoginInfo(QString user, QString desktop){
writeSystemLastLogin(user,desktop); //save the system file (/usr/local/share/PCDM/.lastlogin) writeSystemLastLogin(user,desktop); //save the system file (DBDIR/lastlogin)
writeUserLastDesktop(user,desktop); //save the user file (~/.lastlogin) writeUserLastDesktop(user,desktop); //save the user file (~/.lastlogin)
} }


Expand All @@ -284,7 +289,7 @@ void Backend::readDefaultSysEnvironment(QString &lang, QString &keymodel, QStrin
keylayout = "us"; keylayout = "us";
keyvariant = ""; keyvariant = "";
//Read the current inputs file and overwrite default values //Read the current inputs file and overwrite default values
QFile file("/var/db/pcdm/defaultInputs"); QFile file(DBDIR+"defaultInputs");
bool goodFile=false; bool goodFile=false;
if(file.exists()){ if(file.exists()){
if(file.open(QIODevice::ReadOnly | QIODevice::Text) ){ if(file.open(QIODevice::ReadOnly | QIODevice::Text) ){
Expand All @@ -308,11 +313,11 @@ void Backend::readDefaultSysEnvironment(QString &lang, QString &keymodel, QStrin
} }


void Backend::saveDefaultSysEnvironment(QString lang, QString keymodel, QString keylayout, QString keyvariant){ void Backend::saveDefaultSysEnvironment(QString lang, QString keymodel, QString keylayout, QString keyvariant){
QFile file("/var/db/pcdm/defaultInputs"); QFile file(DBDIR+"defaultInputs");
//Make sure the containing directory exists //Make sure the containing directory exists
if(!QFile::exists("/var/db/pcdm")){ if(!QFile::exists(DBDIR)){
QDir dir; QDir dir;
dir.mkpath("/var/db/pcdm"); dir.mkpath(DBDIR);
} }
//Now save the file //Now save the file
if(file.open(QIODevice::WriteOnly | QIODevice::Text) ){ if(file.open(QIODevice::WriteOnly | QIODevice::Text) ){
Expand Down Expand Up @@ -540,12 +545,12 @@ void Backend::readSystemUsers(){
} }


void Backend::readSystemLastLogin(){ void Backend::readSystemLastLogin(){
if(!QFile::exists("/usr/local/share/PCDM/.lastlogin")){ if(!QFile::exists(DBDIR+"lastlogin")){
lastUser.clear(); lastUser.clear();
Backend::log("PCDM: No previous login data found"); Backend::log("PCDM: No previous login data found");
}else{ }else{
//Load the previous login data //Load the previous login data
QFile file("/usr/local/share/PCDM/.lastlogin"); QFile file(DBDIR+"lastlogin");
if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
Backend::log("PCDM: Unable to open previous login data file"); Backend::log("PCDM: Unable to open previous login data file");
}else{ }else{
Expand All @@ -558,7 +563,7 @@ void Backend::readSystemLastLogin(){
} }


void Backend::writeSystemLastLogin(QString user, QString desktop){ void Backend::writeSystemLastLogin(QString user, QString desktop){
QFile file1("/usr/local/share/PCDM/.lastlogin"); QFile file1(DBDIR+"lastlogin");
if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){ if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){
Backend::log("PCDM: Unable to save last login data to system directory"); Backend::log("PCDM: Unable to save last login data to system directory");
}else{ }else{
Expand Down
1 change: 1 addition & 0 deletions src-qt4/PCDM/src/pcdm-backend.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "pcbsd-utils.h" #include "pcbsd-utils.h"


#define PCSYSINSTALL QString("/usr/sbin/pc-sysinstall") #define PCSYSINSTALL QString("/usr/sbin/pc-sysinstall")
#define DBDIR QString("/var/db/pcdm/")


class Process : public QProcess { class Process : public QProcess {
public: public:
Expand Down
18 changes: 9 additions & 9 deletions src-qt4/PCDM/src/pcdm-xprocess.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ void XProcess::loginToXSession(QString username, QString password, QString deskt
xde = desktop; xde = desktop;
xlang = lang; xlang = lang;
//Now start the login process //Now start the login process
startXSession(); if( !startXSession() ){
//Could not continue after session changed significantly - close down the session to restart
QCoreApplication::exit(-1); //special code to make sure we are just restarting the PCDM session (not the full X session)
}
} }


bool XProcess::isRunning(){ bool XProcess::isRunning(){
Expand All @@ -68,20 +71,21 @@ void XProcess::waitForSessionClosed(){
*/ */


bool XProcess::startXSession(){ bool XProcess::startXSession(){
//disconnect(SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotCleanup()) ); //Returns TRUE if the session can continue, or FALSE if it needs to be closed down

//Check that the necessary info to start the session is available //Check that the necessary info to start the session is available
if( xuser.isEmpty() || xcmd.isEmpty() || xhome.isEmpty() || xde.isEmpty() ){ if( xuser.isEmpty() || xcmd.isEmpty() || xhome.isEmpty() || xde.isEmpty() ){
emit InvalidLogin(); //Make sure the GUI knows that it was a failure emit InvalidLogin(); //Make sure the GUI knows that it was a failure
return FALSE; return true;
} }
//Backend::log("Starting up Desktop environment ("+xcmd+") as user ("+xuser+")"); //Backend::log("Starting up Desktop environment ("+xcmd+") as user ("+xuser+")");


//Check for PAM username/password validity //Check for PAM username/password validity
if( !pam_checkPW() ){ emit InvalidLogin(); pam_shutdown(); return FALSE; } if( !pam_checkPW() ){ emit InvalidLogin(); pam_shutdown(); return true; }




//Save the current user/desktop as the last login //Save the current user/desktop as the last login
Backend::saveLoginInfo(Backend::getDisplayNameFromUsername(xuser),xde); Backend::saveLoginInfo(xuser,xde);


// Get the users uid/gid information // Get the users uid/gid information
struct passwd *pw; struct passwd *pw;
Expand All @@ -91,7 +95,6 @@ bool XProcess::startXSession(){
if (!(pw = getpwnam(xuser.toLatin1()))) { if (!(pw = getpwnam(xuser.toLatin1()))) {
uid = strtol(xuser.toLatin1(), &ok, 10); uid = strtol(xuser.toLatin1(), &ok, 10);
if (!(pw = getpwuid(uid))) { if (!(pw = getpwuid(uid))) {
emit InvalidLogin(); //Make sure the GUI knows that it was a failure
return FALSE; return FALSE;
} }
} }
Expand All @@ -109,22 +112,19 @@ bool XProcess::startXSession(){
//QWidget *wid = new QWidget(); //QWidget *wid = new QWidget();
if (setgid(pw->pw_gid) < 0) { if (setgid(pw->pw_gid) < 0) {
qDebug() << "setgid() failed!"; qDebug() << "setgid() failed!";
emit InvalidLogin(); //Make sure the GUI knows that it was a failure
return FALSE; return FALSE;
} }


// Setup our other groups // Setup our other groups
if (initgroups(xuser.toLatin1(), pw->pw_gid) < 0) { if (initgroups(xuser.toLatin1(), pw->pw_gid) < 0) {
qDebug() << "initgroups() failed!"; qDebug() << "initgroups() failed!";
emit InvalidLogin(); //Make sure the GUI knows that it was a failure
setgid(0); setgid(0);
return FALSE; return FALSE;
} }


// Lets drop to user privs // Lets drop to user privs
if (setuid(pw->pw_uid) < 0) { if (setuid(pw->pw_uid) < 0) {
qDebug() << "setuid() failed!"; qDebug() << "setuid() failed!";
emit InvalidLogin(); //Make sure the GUI knows that it was a failure
return FALSE; return FALSE;
} }
//Startup the PAM session //Startup the PAM session
Expand Down

0 comments on commit fdf420c

Please sign in to comment.