Ignore:
Timestamp:
02/27/14 05:43:13 (6 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
97252e15
Parents:
a4b4e3d
Message:

Turn on using "ps" for getting the system users instead of parsing /etc/passwd manually in PCDM. This should help make sure that LDAP users are also detected, but needs testing to verify that.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/PCDM/src/pcdm-backend.cpp

    rfefc988 r7af9bd1  
    468468  //make sure the lists are empty 
    469469  usernameList.clear(); displaynameList.clear(); homedirList.clear(); 
    470   //Get all the users from the file "/etc/passwd" 
    471   QStringList uList; 
    472   QFile PWF("/etc/passwd"); 
    473   if( PWF.open(QIODevice::ReadOnly | QIODevice::Text) ){ 
    474     QTextStream in(&PWF); 
    475       in.setCodec( "UTF-8" ); 
    476     while( !in.atEnd() ){ 
    477       uList << QString( in.readLine() ); 
    478     } 
    479     PWF.close();     
    480   } 
     470  QStringList uList;     
     471  bool usepw = true; //for testing purposes 
     472  if(usepw){ 
     473    //Use "pw" to get all possible users 
     474    QProcess p; 
     475    p.setProcessChannelMode(QProcess::MergedChannels); 
     476      QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); 
     477      env.insert("MM_CHARSET","UTF-8"); 
     478    p.setProcessEnvironment(env); 
     479    p.start("pw usershow -a"); 
     480    while(p.state()==QProcess::Starting || p.state() == QProcess::Running){ 
     481      p.waitForFinished(200); 
     482      QCoreApplication::processEvents(); 
     483    } 
     484    uList = QString( p.readAllStandardOutput() ).split("\n"); 
     485     
     486    //Remove all users that have: 
     487   for(int i=0; i<uList.length(); i++){ 
     488    bool bad = FALSE; 
     489    // "nologin" as their shell 
     490    if(uList[i].section(":",9,9).contains("nologin")){bad=TRUE;} 
     491    // "nonexistent" as their user directory 
     492    else if(uList[i].section(":",8,8).contains("nonexistent")){bad=TRUE;} 
     493    // uid > 1000 
     494    else if(uList[i].section(":",2,2).toInt() < 1000){bad=TRUE;} 
     495 
     496    //See if it failed any checks 
     497    if(bad){ uList.removeAt(i); i--; } 
     498    else{ 
     499      //Add this user to the lists if it is good 
     500      usernameList << uList[i].section(":",0,0).simplified(); 
     501      displaynameList << uList[i].section(":",7,7).simplified(); 
     502      homedirList << uList[i].section(":",8,8).simplified(); 
     503      usershellList << uList[i].section(":",9,9).simplified(); 
     504    } 
     505   } 
     506  }else{  
     507    //Get all the users from the file "/etc/passwd" 
     508    QFile PWF("/etc/passwd"); 
     509    if( PWF.open(QIODevice::ReadOnly | QIODevice::Text) ){ 
     510      QTextStream in(&PWF); 
     511        in.setCodec( "UTF-8" ); 
     512      while( !in.atEnd() ){ 
     513        uList << QString( in.readLine() ); 
     514      } 
     515      PWF.close();     
     516    } 
    481517  //Remove all users that have: 
    482518  for(int i=0; i<uList.length(); i++){ 
     
    498534      usershellList << uList[i].section(":",6,6).simplified(); 
    499535    } 
     536  } 
     537   
    500538  } 
    501539   
Note: See TracChangeset for help on using the changeset viewer.