[PC-BSD Commits] r17809 - pcbsd-projects/PCDM
svn at pcbsd.org
svn at pcbsd.org
Wed Jul 18 08:25:41 PDT 2012
Author: kenmoore
Date: 2012-07-18 15:25:41 +0000 (Wed, 18 Jul 2012)
New Revision: 17809
Modified:
pcbsd-projects/PCDM/pcdm-backend.cpp
Log:
Change over the PCDM user detection algorithm to be much more robust (and maybe a bit faster too)
Modified: pcbsd-projects/PCDM/pcdm-backend.cpp
===================================================================
--- pcbsd-projects/PCDM/pcdm-backend.cpp 2012-07-18 15:22:33 UTC (rev 17808)
+++ pcbsd-projects/PCDM/pcdm-backend.cpp 2012-07-18 15:25:41 UTC (rev 17809)
@@ -10,21 +10,29 @@
QStringList Backend::getSystemUsers(){
if(usernameList.isEmpty()){
- //get the names of all the directories in /usr/home (usernames)
- QDir dir("/usr/home");
- dir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
- usernameList = dir.entryList();
- //Also get the display names for each user
- displaynameList.clear();
- for(int i=0; i<usernameList.length(); i++){
- QString cmd = "cat /etc/passwd";//| grep USERNAME | cut -d: -f5";
- QString dsp = Utils::runShellCommandSearch( cmd, usernameList[i]).section(":",4,4).simplified();
- //qDebug() << "Username:"<<usernameList[i]<<" Display Name:"<<dsp;
- if(!dsp.isEmpty()){ displaynameList << dsp; }
- else{ usernameList.removeAt(i); i--; } //make sure to remove the username if there is no entry in the passwd file for it
+ usernameList.clear(); displaynameList.clear(); //make sure the lists are empty
+ //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();
+ }
}
}
- //qDebug() << "PCDM: Scanning for available usernames is not integrated yet";
return displaynameList;
}
More information about the Commits
mailing list