Changeset 90dc161


Ignore:
Timestamp:
Jul 11, 2013 2:28:19 PM (9 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1
Children:
ed51bc3
Parents:
8679296
Message:

Completely revamp how PCDM uses the previous login information. Now you no longer need to specify which desktop to auto-login to if you have auto-login selected. It will first try to check for previous login information for that user, then fall back on the last login for the system in order to try and auto login. Also fix the PCDMd script a bit so that autologins work properly when triggered.

Location:
src-qt4/PCDM
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/PCDM/PCDMd

    r39fe8b0 r90dc161  
    1818 
    1919  # Allow Auto-Login the first time PCDM starts 
    20   touch /tmp/.PCDMAUTOLOGINFILE 
     20  touch /tmp/.PCDMAutoLogin 
    2121  # Now start the X Server 
    2222  while [ ! -e /var/run/nologin ]; do 
  • src-qt4/PCDM/src/main.cpp

    r39fe8b0 r90dc161  
    4242  // Load the configuration file 
    4343  QString confFile = "/usr/local/etc/pcdm.conf"; 
    44   if(!QFile::exists(confFile)){ confFile = ":samples/pcdm.conf"; } 
     44  if(!QFile::exists(confFile)){  
     45    qDebug() << "PCDM: Configuration file missing:"<<confFile<<"\n  - Using default configuration"; 
     46    confFile = ":samples/pcdm.conf";  
     47  } 
     48   
    4549  Config::loadConfigFile(confFile); 
    4650  //qDebug() << "Config File Loaded:" << QString::number(clock.elapsed())+" ms"; 
     
    6165  //*** STARTUP THE PROGRAM *** 
    6266  bool goodAL = FALSE; //Flag for whether the autologin was successful 
    63    
    6467  // Start the autologin procedure if applicable 
    6568  if( ALtriggered && Config::useAutoLogin() ){ 
    6669    //Setup the Auto Login 
    6770    QString user = Backend::getALUsername(); 
    68     QString dcmd = Backend::getALDesktopCmd(); 
    6971    QString pwd = Backend::getALPassword(); 
    70     if( user.isEmpty() || dcmd.isEmpty() ){ 
     72    QString dsk = Backend::getLastDE(user); 
     73    if( user.isEmpty() || dsk.isEmpty() ){ 
    7174         goodAL=FALSE;    
    7275    }else{ 
    73         desktop.loginToXSession(user,pwd, Backend::getUserHomeDir(user), dcmd); 
     76        desktop.loginToXSession(user,pwd, Backend::getUserHomeDir(user), dsk); 
    7477        splash.close(); 
    7578        if(desktop.isRunning()){ 
  • src-qt4/PCDM/src/pcdm-backend.cpp

    r1620346 r90dc161  
    1414QStringList displaynameList,usernameList,homedirList,instXNameList,instXBinList,instXCommentList,instXIconList; 
    1515QString logFile; 
    16 QString saveX,saveUsername; 
     16QString saveX,saveUsername, lastUser, lastDE; 
    1717 
    1818QStringList Backend::getAvailableDesktops(){   
     
    6969} 
    7070 
    71 QString Backend::getALDesktopCmd(){ 
    72    // Make sure the desired desktop is valid 
    73   QString rdesktop = Config::autoLoginDesktop(); 
    74   if(!QFile::exists(rdesktop)){ //requested file does not exist 
    75     log("Invalid Auto-Login desktop requested - skipping...."); 
    76     return ""; 
    77   } 
    78   QStringList result = readXSessionsFile(rdesktop,""); 
    79   if(result.isEmpty()){  //requested file is not a valid xsessions file 
    80     log("Invalid Auto-Login desktop requested - skipping...."); 
    81     return "";             
    82   } 
    83   if(!result[0].startsWith("/")){ result[0] = "/usr/local/bin/"+result[0]; } 
    84   rdesktop = result[0]; //(absolute path) executable 
    85   if(!QFile::exists(rdesktop)){  //requested desktop is not currently installed 
    86     log("Invalid Auto-Login desktop requested - skipping...."); 
    87     return "";             
    88   } 
    89   return rdesktop; 
    90 } 
    91  
    9271QString Backend::getALPassword(){ 
    9372  QString rpassword = Config::autoLoginPassword(); 
     
    9978  return usernameList[i]; 
    10079} 
     80 
     81QString Backend::getDisplayNameFromUsername(QString username){ 
     82  int i = usernameList.indexOf(username); 
     83  return displaynameList[i];   
     84} 
     85 
    10186QString Backend::getUserHomeDir(QString username){ 
    10287  int i = usernameList.indexOf(username); 
     
    234219  if(!mainDir.exists("themes")){ mainDir.mkdir("themes"); } 
    235220  //Check for sample files 
    236   if(!mainDir.exists("pcdm.conf.sample")){ QFile::copy(":samples/pcdm.conf",base+"/pcdm.conf.sample"); } 
    237   //if(!mainDir.exists("pcdm.theme.sample")){ QFile::copy(":samples/themes/default/default.theme",base+"/pcdm.theme.sample"); } 
     221  if(!mainDir.exists("pcdm.conf.sample")){ QFile::copy(":samples/pcdm.conf",base+"/pcdm.conf.sample"); }  
     222} 
     223 
     224QString Backend::getLastUser(){ 
     225  //Load the file if necessary 
     226  if(lastUser.isEmpty()){ 
     227    readSystemLastLogin();   
     228  } 
     229  //return the value 
     230  return lastUser; 
     231} 
     232 
     233QString Backend::getLastDE(QString user){ 
     234  if(lastDE.isEmpty()){ 
     235    readSystemLastLogin(); 
     236  } 
     237  QString de = readUserLastDesktop(user); 
     238  if(de.isEmpty()){ return lastDE; } 
     239  else{ return de; } 
    238240   
     241} 
     242 
     243void Backend::saveLoginInfo(QString user, QString desktop){ 
     244  writeSystemLastLogin(user,desktop); //save the system file (/usr/local/share/PCDM/.lastlogin) 
     245  writeUserLastDesktop(user,desktop); //save the user file (~/.lastlogin) 
    239246} 
    240247 
     
    360367   
    361368} 
     369 
     370void Backend::readSystemLastLogin(){ 
     371    if(!QFile::exists("/usr/local/share/PCDM/.lastlogin")){ 
     372      lastUser.clear(); 
     373      Backend::log("PCDM: No previous login data found"); 
     374    }else{ 
     375      //Load the previous login data 
     376      QFile file("/usr/local/share/PCDM/.lastlogin"); 
     377      if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ 
     378        Backend::log("PCDM: Unable to open previous login data file");     
     379      }else{ 
     380        QTextStream in(&file); 
     381        lastUser= in.readLine(); 
     382        lastDE= in.readLine(); 
     383        file.close(); 
     384      } 
     385    }   
     386} 
     387 
     388void Backend::writeSystemLastLogin(QString user, QString desktop){ 
     389  QFile file1("/usr/local/share/PCDM/.lastlogin"); 
     390  if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){ 
     391    Backend::log("PCDM: Unable to save last login data to system directory");      
     392  }else{ 
     393    QTextStream out(&file1); 
     394    out << user << "\n" << desktop; 
     395    file1.close(); 
     396  } 
     397 
     398} 
     399 
     400QString Backend::readUserLastDesktop(QString user){ 
     401  QString desktop; 
     402  QString LLpath = Backend::getUserHomeDir(user) + "/.lastlogin"; 
     403  if(!QFile::exists(LLpath)){ 
     404    Backend::log("PCDM: No previous user login data found for user: "+user); 
     405  }else{ 
     406    //Load the previous login data 
     407    QFile file(LLpath); 
     408    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ 
     409      Backend::log("PCDM: Unable to open previous user login file: "+user);     
     410    }else{ 
     411      QTextStream in(&file); 
     412      desktop = in.readLine(); 
     413      file.close(); 
     414    } 
     415  } 
     416  return desktop; 
     417} 
     418 
     419void Backend::writeUserLastDesktop(QString user, QString desktop){ 
     420  QFile file2( Backend::getUserHomeDir(user) + "/.lastlogin" ); 
     421  if(!file2.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){ 
     422    Backend::log("PCDM: Unable to save last login data for user:"+user);           
     423  }else{ 
     424    QTextStream out(&file2); 
     425    out << desktop; 
     426    file2.close(); 
     427  } 
     428} 
  • src-qt4/PCDM/src/pcdm-backend.h

    r1620346 r90dc161  
    1313#include <QDir> 
    1414#include <QProcess> 
     15#include <QFile> 
    1516 
    1617#include "pcdm-config.h" 
     
    3536    static QStringList getSystemUsers(); 
    3637    static QString getUsernameFromDisplayname(QString); 
     38    static QString getDisplayNameFromUsername(QString); 
    3739    static QStringList keyModels(); 
    3840    static QStringList keyLayouts(); 
     
    4951    static QString getALPassword(); 
    5052     
     53    static QString getLastUser(); 
     54    static QString getLastDE(QString); 
     55    static void saveLoginInfo(QString, QString); 
     56     
    5157private:         
    5258    static void loadXSessionsData(); 
    5359    static QStringList readXSessionsFile(QString, QString); 
    5460    static void readSystemUsers(); 
    55   
     61    static void readSystemLastLogin(); 
     62    static void writeSystemLastLogin(QString, QString); 
     63    static QString readUserLastDesktop(QString); 
     64    static void writeUserLastDesktop(QString, QString); 
    5665     
    5766}; 
  • src-qt4/PCDM/src/pcdm-gui.cpp

    r1d2d46a r90dc161  
    2020PCDMgui::PCDMgui() : QMainWindow() 
    2121{ 
    22     lastUser.clear(); 
    23     lastDE.clear(); 
    2422    //Load the Theme 
    2523    loadTheme(); 
     
    5250    } 
    5351  } 
    54   //Load the data from the last successful login 
    55   loadLastUser(); 
    5652   
    5753} 
     
    178174    loginW = new LoginWidget; 
    179175    loginW->setUsernames(Backend::getSystemUsers()); //add in the detected users 
     176    QString lastUser = Backend::getLastUser(); 
    180177    if(!lastUser.isEmpty()){ //set the previously used user 
    181178        loginW->setCurrentUser(lastUser);  
    182         loadLastDE(lastUser); //make sure the DE switcher reflects the last user choice 
    183179    }  
    184180    //Set Icons from theme 
     
    248244  if(DEBUG_MODE){ qDebug() << " - Fill GUI with data"; } 
    249245  retranslateUi(); 
    250   if(simpleDESwitcher && !lastUser.isEmpty()){ 
    251      
    252   } 
    253246  if(DEBUG_MODE){ qDebug() << "Done with initialization"; } 
    254247 
     
    258251  //Get user inputs 
    259252  QString username = Backend::getUsernameFromDisplayname(displayname); 
    260   QString binary; 
     253  QString desktop; 
    261254  if(simpleDESwitcher){ 
    262     binary = Backend::getDesktopBinary(loginW->currentDE()); 
     255    desktop = loginW->currentDE(); 
    263256  }else{ 
    264     binary = Backend::getDesktopBinary(deSwitcher->currentItem()); 
     257    desktop = deSwitcher->currentItem(); 
    265258  } 
    266259  QString homedir = Backend::getUserHomeDir(username); 
     
    270263  toolbar->setEnabled(FALSE); 
    271264  //Try to login 
    272   emit xLoginAttempt(username, password, homedir, binary); 
     265  emit xLoginAttempt(username, password, homedir, desktop); 
    273266  //Return signals are connected to the slotLogin[Success/Failure] functions 
    274267   
     
    276269 
    277270void PCDMgui::slotLoginSuccess(){ 
    278   QString de; 
     271  /*QString de; 
    279272  if(simpleDESwitcher){ de = loginW->currentDE(); } 
    280273  else{ de = deSwitcher->currentItem(); } 
    281   saveLastLogin( loginW->currentUsername(), de ); 
     274  saveLastLogin( loginW->currentUsername(), de );*/ 
    282275  slotClosePCDM(); //now start to close down the PCDM GUI 
    283276} 
     
    316309  }else{ 
    317310    if(!simpleDESwitcher){ deSwitcher->setVisible(TRUE); } 
    318     //Try to load the user's last DE 
    319     loadLastDE(newuser); 
    320311    //Try to load the custom user icon 
    321312    slotUserChanged(newuser); 
     
    472463    //Get the new desktop list (translated) 
    473464    QStringList deList = Backend::getAvailableDesktops(); 
     465    QString lastDE = Backend::getLastDE(loginW->currentUsername()); 
    474466    //Now fill the switcher 
    475467    if(!simpleDESwitcher){ 
     
    497489      loginW->setDesktops(deList, deIcons, deInfo); 
    498490      //Set the switcher to the last used desktop environment 
    499       if( !lastDE.isEmpty() ){ loginW->setCurrentDE(lastDE); } 
    500     } 
    501  
    502 } 
    503  
    504 void PCDMgui::loadLastUser(){ 
    505   lastUser.clear(); 
    506   if(!QFile::exists("/usr/local/share/PCDM/.lastlogin")){ 
    507     Backend::log("PCDM: No previous login data found"); 
    508   }else{ 
    509     //Load the previous login data 
    510     QFile file("/usr/local/share/PCDM/.lastlogin"); 
    511     if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ 
    512       Backend::log("PCDM: Unable to open previous login data file");     
    513     }else{ 
    514       QTextStream in(&file); 
    515       lastUser= in.readLine(); 
    516       file.close(); 
    517     } 
    518   } 
    519 } 
    520  
    521 void PCDMgui::loadLastDE(QString user){ 
    522   lastDE.clear(); 
    523   QString LLpath = Backend::getUserHomeDir(user) + "/.lastlogin"; 
    524   if(!QFile::exists(LLpath)){ 
    525     Backend::log("PCDM: No previous user login data found for user: "+user); 
    526   }else{ 
    527     //Load the previous login data 
    528     QFile file(LLpath); 
    529     if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){ 
    530       Backend::log("PCDM: Unable to open previous user login file: "+user);     
    531     }else{ 
    532       QTextStream in(&file); 
    533       lastDE= in.readLine(); 
    534       file.close(); 
    535     } 
    536   } 
    537  
    538 } 
    539  
    540 void PCDMgui::saveLastLogin(QString USER, QString DE){ 
    541   QFile file1("/usr/local/share/PCDM/.lastlogin"); 
    542   if(!file1.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){ 
    543     Backend::log("PCDM: Unable to save last login data");          
    544   }else{ 
    545     QTextStream out(&file1); 
    546     out << USER; 
    547     file1.close(); 
    548   } 
    549   QFile file2( Backend::getUserHomeDir(USER) + "/.lastlogin" ); 
    550   if(!file2.open(QIODevice::Truncate | QIODevice::WriteOnly | QIODevice::Text)){ 
    551     Backend::log("PCDM: Unable to save last login data for user:"+USER);           
    552   }else{ 
    553     QTextStream out(&file2); 
    554     out << DE; 
    555     file2.close(); 
    556   } 
    557 } 
    558  
     491      loginW->setCurrentDE(lastDE); 
     492    } 
     493 
     494} 
     495 
  • src-qt4/PCDM/src/pcdm-gui.h

    r1d2d46a r90dc161  
    7373 
    7474    QTranslator* m_translator; 
    75     QString translationDir, lastUser, lastDE; 
     75    QString translationDir; 
    7676     
    7777    QString hostname; 
  • src-qt4/PCDM/src/pcdm-xprocess.cpp

    r1add85d r90dc161  
    3030} 
    3131 
    32 void XProcess::loginToXSession(QString username, QString password, QString homedir, QString cmd){ 
     32void XProcess::loginToXSession(QString username, QString password, QString homedir, QString desktop){ 
    3333  //Setup the variables 
    3434  xuser = username; 
    3535  xpwd = password; 
    3636  xhome = homedir; 
    37   xcmd = cmd; 
     37  xcmd = Backend::getDesktopBinary(desktop); 
     38  xde = desktop; 
    3839  //Now start the login process 
    3940  startXSession(); 
     
    5960bool XProcess::startXSession(){ 
    6061  //Check that the necessary info to start the session is available 
    61   if( xuser.isEmpty() || xcmd.isEmpty() || xhome.isEmpty() ){ 
     62  if( xuser.isEmpty() || xcmd.isEmpty() || xhome.isEmpty() || xde.isEmpty() ){ 
    6263    emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
    6364    return FALSE; 
     
    7071  if( !pam_startSession() ){ pam_shutdown(); return FALSE; } 
    7172  pam_session_open = TRUE; //flag that pam has an open session 
     73   
     74  //Save the current user/desktop as the last login 
     75  Backend::saveLoginInfo(Backend::getDisplayNameFromUsername(xuser),xde); 
    7276   
    7377  // Configure the DE startup command 
     
    100104  environ.insert("MAIL","/var/mail/"+xuser); //Set the mail variable 
    101105  environ.insert("GROUP",xuser); //Set the proper group id 
    102   environ.insert("SHLVL","1"); //Set the proper shell level 
     106  environ.insert("SHLVL","0"); //Set the proper shell level 
    103107  this->setProcessEnvironment(environ); 
    104108  this->setWorkingDirectory(xhome); //set the current directory to the user's home directory 
  • src-qt4/PCDM/src/pcdm-xprocess.h

    r1620346 r90dc161  
    3434   
    3535  public slots: 
    36         void loginToXSession(QString, QString, QString, QString); //user, pwd, homedir, cmd 
     36        void loginToXSession(QString, QString, QString, QString); //user, pwd, homedir, desktop 
    3737         
    3838  private: 
    39         QString xuser, xcmd, xhome, xpwd; 
     39        QString xuser, xcmd, xhome, xpwd, xde; 
    4040        bool startXSession(); 
    4141         
Note: See TracChangeset for help on using the changeset viewer.