[PC-BSD Commits] r19433 - pcbsd-projects/PCDM
svn at pcbsd.org
svn at pcbsd.org
Fri Sep 21 10:37:01 PDT 2012
Author: kenmoore
Date: 2012-09-21 17:37:01 +0000 (Fri, 21 Sep 2012)
New Revision: 19433
Modified:
pcbsd-projects/PCDM/main.cpp
pcbsd-projects/PCDM/pcdm-backend.cpp
pcbsd-projects/PCDM/pcdm-backend.h
Log:
Setup the auto-login for PCDM
Modified: pcbsd-projects/PCDM/main.cpp
===================================================================
--- pcbsd-projects/PCDM/main.cpp 2012-09-21 16:07:23 UTC (rev 19432)
+++ pcbsd-projects/PCDM/main.cpp 2012-09-21 17:37:01 UTC (rev 19433)
@@ -15,26 +15,29 @@
int main(int argc, char *argv[])
{
-
- qDebug() << "argc:"<< argc << "argv" << argv;
int returnCode;
Backend::checkLocalDirs(); // Create and fill "/usr/local/share/PCDM" if needed
- Backend::openLogFile("/usr/local/share/PCDM/PCDM.log");
+ Backend::openLogFile("/usr/local/share/PCDM/PCDM.log");
+ //Check for the flag to try and auto-login
+ bool ALtriggered = FALSE;
+ if(QString(argv[2]) == "-AutoLogin"){ ALtriggered=TRUE; }
- QString changeLang;
- // Load the configuration file
- Config::loadConfigFile("/usr/local/share/PCDM/pcdm.conf");
+ QString changeLang;
+ // Load the configuration file
+ Config::loadConfigFile("/usr/local/share/PCDM/pcdm.conf");
+
+ if( ALtriggered && Config::useAutoLogin() ){
+ //Setup the Auto Login
+ Backend::startAutoLogin();
+ }else{
+ // ------START THE PCDM GUI-------
+
// Load the Desired Theme
Theme::loadTheme(Config::themeFile());
// Startup the main application
QApplication a(argc,argv);
// Check what directory our app is in
- QString appDir;
- if ( QFile::exists("/usr/local/bin/PCDM") ){
- appDir = "/usr/local/share/PCDM";
- } else {
- appDir = QCoreApplication::applicationDirPath();
- }
+ QString appDir = "/usr/local/share/PCDM";
// Load the translator
QTranslator translator;
QLocale mylocale;
@@ -62,7 +65,7 @@
Backend::log("Starting up PCDM interface");
PCDMgui w;
- //Set the proper size on the Application
+ //Set the proper size on the Application
if(Theme::isFullScreen() ){
w.setWindowFlags(w.windowFlags() ^Qt::WindowSoftkeysVisibleHint);
w.setWindowState(Qt::WindowFullScreen);
@@ -83,7 +86,7 @@
w.show();
splash.finish(&w);
returnCode = a.exec();
-
+ } // end of PCDM GUI running
/*
if ( QFile::exists(TMPLANGFILE) ) {
QFile lfile(TMPLANGFILE);
@@ -98,8 +101,8 @@
break;
}
*/
- // Startup the desktop environment if possible
- Backend::startXSession();
+ // Startup the desktop environment if possible
+ Backend::startXSession();
return returnCode;
}
Modified: pcbsd-projects/PCDM/pcdm-backend.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.cpp 2012-09-21 16:07:23 UTC (rev 19432)
+++ pcbsd-projects/PCDM/pcdm-backend.cpp 2012-09-21 17:37:01 UTC (rev 19433)
@@ -40,30 +40,7 @@
QStringList Backend::getSystemUsers(){
if(usernameList.isEmpty()){
- //make sure the lists are empty
- usernameList.clear(); displaynameList.clear(); homedirList.clear();
- //Get all the users from the file "/etc/passwd"
- QStringList uList = Utils::runShellCommand("cat /etc/passwd");
-
- //Remove all users that have:
- for(int i=0; i<uList.length(); i++){
- bool bad = FALSE;
- // "nologin" as their shell
- if(uList[i].section(":",6,6).contains("nologin")){bad=TRUE;}
- // "nonexistent" as their user directory
- else if(uList[i].section(":",5,5).contains("nonexistent")){bad=TRUE;}
- // uid > 1000
- else if(uList[i].section(":",2,2).toInt() < 1000){bad=TRUE;}
-
- //See if it failed any checks
- if(bad){ uList.removeAt(i); i--; }
- else{
- //Add this user to the lists if it is good
- usernameList << uList[i].section(":",0,0).simplified();
- displaynameList << uList[i].section(":",4,4).simplified();
- homedirList << uList[i].section(":",5,5).simplified();
- }
- }
+ readSystemUsers();
}
return displaynameList;
}
@@ -82,6 +59,46 @@
return allowed;
}
+void Backend::startAutoLogin(){
+ //Make sure the requested user is valid
+ readSystemUsers(); //first read the available users on this system
+ QString ruser = Config::autoLoginUsername();
+ int index = usernameList.indexOf(ruser);
+ if(index == -1){ //invalid username
+ //Check if a display name was given instead
+ index = displaynameList.indexOf(ruser);
+ if(index == -1){ //invalid display name
+ log("Invalid Auto-Login user requested - skipping....");
+ return;
+ }else{
+ //use the valid username for the given display name
+ ruser = usernameList[index];
+ }
+ }
+ // Make sure the desired desktop is valid
+ QString rdesktop = Config::autoLoginDesktop();
+ if(!QFile::exists(rdesktop)){ //requested file does not exist
+ log("Invalid Auto-Login desktop requested - skipping....");
+ return;
+ }
+ QStringList result = readXSessionsFile(rdesktop,"");
+ if(result.isEmpty()){ //requested file is not a valid xsessions file
+ log("Invalid Auto-Login desktop requested - skipping....");
+ return;
+ }
+ if(!result[0].startsWith("/")){ result[0] = "/usr/local/bin/"+result[0]; }
+ rdesktop = result[0]; //(absolute path) executable
+ if(!QFile::exists(rdesktop)){ //requested desktop is not currently installed
+ log("Invalid Auto-Login desktop requested - skipping....");
+ return;
+ }
+
+ //Save the appropriate variables to start the login process
+ saveX = rdesktop;
+ saveUsername = ruser;
+ log("Valid Auto-Login information found");
+}
+
void Backend::startXSession(){
// WARNING!! This function should *never* be called within the GUI
// It should only be called as part of the main event loop
@@ -455,3 +472,31 @@
//return verification result
return result;
}
+
+void Backend::readSystemUsers(){
+ //make sure the lists are empty
+ usernameList.clear(); displaynameList.clear(); homedirList.clear();
+ //Get all the users from the file "/etc/passwd"
+ QStringList uList = Utils::runShellCommand("cat /etc/passwd");
+
+ //Remove all users that have:
+ for(int i=0; i<uList.length(); i++){
+ bool bad = FALSE;
+ // "nologin" as their shell
+ if(uList[i].section(":",6,6).contains("nologin")){bad=TRUE;}
+ // "nonexistent" as their user directory
+ else if(uList[i].section(":",5,5).contains("nonexistent")){bad=TRUE;}
+ // uid > 1000
+ else if(uList[i].section(":",2,2).toInt() < 1000){bad=TRUE;}
+
+ //See if it failed any checks
+ if(bad){ uList.removeAt(i); i--; }
+ else{
+ //Add this user to the lists if it is good
+ usernameList << uList[i].section(":",0,0).simplified();
+ displaynameList << uList[i].section(":",4,4).simplified();
+ homedirList << uList[i].section(":",5,5).simplified();
+ }
+ }
+
+}
Modified: pcbsd-projects/PCDM/pcdm-backend.h
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.h 2012-09-21 16:07:23 UTC (rev 19432)
+++ pcbsd-projects/PCDM/pcdm-backend.h 2012-09-21 17:37:01 UTC (rev 19433)
@@ -33,6 +33,7 @@
static QString getDesktopBinary(QString);
static QStringList getSystemUsers();
static bool startUserLogin(QString, QString, QString);
+ static void startAutoLogin();
static QString getUsernameFromDisplayname(QString);
static QStringList keyModels();
static QStringList keyLayouts();
@@ -49,6 +50,7 @@
static void loadXSessionsData();
static QStringList readXSessionsFile(QString, QString);
static bool verifyUsernamePassword(QString, QString);
+ static void readSystemUsers();
};
More information about the Commits
mailing list