Changeset 5b07f4a


Ignore:
Timestamp:
07/16/13 09:17:35 (14 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
fb67bb2
Parents:
577dd9b
Message:

Update PCDM, git rid of the calls to "su" and instead drop priv
the proper way.

Doesn't fix the leftover process problem, but geting closer

Location:
src-qt4/PCDM
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/PCDM/PCDM.pro

    rf5122ae r5b07f4a  
    44TEMPLATE = app 
    55 
    6 LIBS += -L../libpcbsd -L/usr/local/lib -lpcbsd-ui -lpcbsd-utils -lpam -lX11 
     6LIBS += -L../libpcbsd -L/usr/local/lib -lpcbsd-ui -lpcbsd-utils -lpam -lX11 -lutil 
    77INCLUDEPATH += ../libpcbsd/utils /usr/local/include 
    88 
  • src-qt4/PCDM/src/main.cpp

    r577dd9b r5b07f4a  
    3232//#endif 
    3333 
    34 bool USECLIBS=false; 
     34bool USECLIBS=true; 
    3535 
    3636int runSingleSession(int argc, char *argv[]){ 
     
    3838  //clock.start(); 
    3939  Backend::checkLocalDirs();  // Create and fill "/usr/local/share/PCDM" if needed 
    40   Backend::openLogFile("/usr/local/share/PCDM/PCDM.log");   
     40  Backend::openLogFile("/var/log/PCDM.log");   
    4141  //qDebug() << "Backend Checks Finished:" << QString::number(clock.elapsed())+" ms"; 
    4242  //Check for the flag to try and auto-login 
  • src-qt4/PCDM/src/pcdm-xprocess.cpp

    r577dd9b r5b07f4a  
    11/* PCDM Login Manager: 
    22*  Written by Ken Moore (ken@pcbsd.org) 2012/2013 
     3*  Modified by Kris Moore (kris@pcbsd.org) 2013 
    34*  Copyright(c) 2013 by the PC-BSD Project 
    45*  Available under the 3-clause BSD license 
    56*/ 
     7 
     8#include <sys/types.h> 
     9#include <unistd.h> 
     10#include <pwd.h> 
     11#include <login_cap.h> 
     12#include <QMessageBox> 
    613 
    714/* 
     
    6774  //Check for PAM username/password validity 
    6875  if( !pam_checkPW() ){ emit InvalidLogin(); pam_shutdown(); return FALSE; } 
     76 
     77 
     78  //Save the current user/desktop as the last login 
     79  Backend::saveLoginInfo(Backend::getDisplayNameFromUsername(xuser),xde); 
     80 
     81  // Get the users uid/gid information 
     82  struct passwd *pw; 
     83  int uid; 
     84  char *ok; 
     85 
     86  if (!(pw = getpwnam(xuser.toLatin1()))) { 
     87      uid = strtol(xuser.toLatin1(), &ok, 10); 
     88      if (!(pw = getpwuid(uid))) { 
     89          emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
     90          return FALSE; 
     91      } 
     92  } 
     93 
     94  // Get the environment before we drop priv 
     95  QProcessEnvironment environ = QProcessEnvironment::systemEnvironment(); //current environment 
     96 
     97  QWidget *wid = new QWidget(); 
     98  if (setgid(pw->pw_gid) < 0) { 
     99      qDebug() << "setgid() failed!"; 
     100      emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
     101      return FALSE; 
     102  } 
     103 
     104  // Lets drop to user privs 
     105  if (setuid(pw->pw_uid) < 0) { 
     106      qDebug() << "setuid() failed!"; 
     107      emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
     108      return FALSE; 
     109  } 
     110 
     111  /* 
     112  struct login_cap *lc; 
     113  lc = login_getclass(pw->pw_class); 
     114  if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL)) { 
     115  QMessageBox::warning(wid, "My Application", "setusercfailed", QMessageBox::Ok, QMessageBox::Ok); 
     116        emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
     117        return FALSE; 
     118  } 
     119  */ 
     120 
    69121  //Startup the PAM session 
    70122  if( !pam_startSession() ){ pam_shutdown(); return FALSE; } 
    71123  pam_session_open = TRUE; //flag that pam has an open session 
    72124   
    73   //Save the current user/desktop as the last login 
    74   Backend::saveLoginInfo(Backend::getDisplayNameFromUsername(xuser),xde); 
    75    
    76  QString cmd; 
     125  QString cmd; 
    77126  // Configure the DE startup command 
    78   cmd = "su "+xuser+" -c \""; //switch user command to start QProcess properly 
    79127  //  - Setup to run the user's <home-dir>/.xprofile startup script 
    80128  if(QFile::exists(xhome+"/.xprofile")){ 
    81     cmd.append("(/bin/sh "+xhome+"/.xprofile) &; ");  //make sure to start it in parallel 
     129    //cmd.append(". "+xhome+"/.xprofile; ");  //make sure to start it in parallel 
    82130  } 
    83131  //  - Add the DE startup command to the end 
    84   cmd.append("dbus-launch --exit-with-session "+xcmd); 
     132  //cmd.append("dbus-launch --exit-with-session "+xcmd); 
     133  cmd.append(xcmd); 
    85134  //cmd.append("; kill -l KILL"); //to clean up the session afterwards 
    86135  // Get the current locale code 
     
    88137  QString langCode = mylocale.name(); 
    89138   
    90   //  - Finish up the command formatting 
    91   cmd.append("\""); 
    92    
    93139  //Backend::log("Startup command: "+cmd); 
    94140  // Setup the process environment 
    95   QProcessEnvironment environ = QProcessEnvironment::systemEnvironment(); //current environment 
    96141 
    97142  // Setup any specialized environment variables 
     
    107152  environ.insert("GROUP",xuser); //Set the proper group id 
    108153  environ.insert("SHLVL","0"); //Set the proper shell level 
     154  environ.insert("DISPLAY",":0"); //Set the proper shell level 
     155  environ.insert("HOME",xhome); //Set the users home directory 
    109156  this->setProcessEnvironment(environ); 
    110157  this->setWorkingDirectory(xhome); //set the current directory to the user's home directory 
    111158  //Log the DE startup outputs as well 
    112159  this->setStandardOutputFile(xhome+"/.pcdm-startup.log",QIODevice::Truncate); 
     160  this->setStandardErrorFile(xhome+"/.pcdm-startup.err",QIODevice::Truncate); 
    113161  // Startup the process 
     162  QMessageBox::warning(wid, "My Application", "CMD: " + cmd, QMessageBox::Ok, QMessageBox::Ok); 
    114163  this->start(cmd); 
    115164  return TRUE; 
    116   
    117165} 
    118166 
     
    132180  Backend::saveLoginInfo(Backend::getDisplayNameFromUsername(xuser),xde); 
    133181   
     182  // Get the users uid/gid information 
     183  struct passwd *pw; 
     184  int uid; 
     185  char *ok; 
     186 
     187  if (!(pw = getpwnam(xuser.toLatin1()))) { 
     188      uid = strtol(xuser.toLatin1(), &ok, 10); 
     189      if (!(pw = getpwuid(uid))) { 
     190          emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
     191          return; 
     192      } 
     193  } 
     194 
     195  if (setgid(pw->pw_gid) < 0) { 
     196      qDebug() << "setgid() failed!"; 
     197      emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
     198      return; 
     199  } 
     200 
     201  // Lets drop to user privs 
     202  if (setuid(pw->pw_uid) < 0) { 
     203      qDebug() << "setuid() failed!"; 
     204      emit InvalidLogin();  //Make sure the GUI knows that it was a failure 
     205      return; 
     206  } 
     207 
    134208  QString cmd; 
    135209  // Configure the DE startup command 
    136   cmd = "su "+xuser+" -c \""; //switch user command to start QProcess properly 
    137210  //  - Setup to run the user's <home-dir>/.xprofile startup script 
    138   if(QFile::exists(xhome+"/.xprofile")){ 
    139     cmd.append("(/bin/sh "+xhome+"/.xprofile) &; ");  //make sure to start it in parallel 
    140   } 
     211  //if(QFile::exists(xhome+"/.xprofile")){ 
     212  //  cmd.append("(/bin/sh "+xhome+"/.xprofile) &; ");  //make sure to start it in parallel 
     213  //} 
    141214  //  - Add the DE startup command to the end 
    142215  cmd.append("dbus-launch --exit-with-session "+xcmd); 
    143   //cmd.append("; kill -l KILL"); //to clean up the session afterwards 
     216 
    144217  // Get the current locale code 
    145218  QLocale mylocale; 
     
    148221  //Alternate way of starting a process using c library functions 
    149222  
    150      //setup the environment variables 
    151      setenv("LOGNAME",xuser.toUtf8(),1); 
    152      setenv("USERNAME",xuser.toUtf8(),1); 
    153      QString pth = QString(getenv("PATH"))+":"+xhome+"/bin"; 
    154      setenv("PATH",pth.toUtf8(),1); 
    155      if(langCode.toLower()=="c"){} 
    156      else if(QString(getenv("MM_CHARSET")).isEmpty() ){ langCode.append("."+QString(getenv("MM_CHARSET"))); } 
    157      else{ langCode.append(".UTF-8"); } 
    158      setenv("LANG",langCode.toUtf8(),1); 
    159      setenv("MAIL",QString("/var/mail/"+xuser).toUtf8(),1); 
    160      setenv("GROUP",xuser.toUtf8(),1); 
    161      setenv("SHLVL","0",1); 
    162      chdir(xhome.toUtf8()); //move to home dir 
    163       
    164      //Now start the process 
    165      qDebug() << "Start the desktop"; 
    166      system(cmd.toUtf8()); 
    167 } 
     223  //setup the environment variables 
     224  setenv("LOGNAME",xuser.toUtf8(),1); 
     225  setenv("USERNAME",xuser.toUtf8(),1); 
     226  QString pth = QString(getenv("PATH"))+":"+xhome+"/bin"; 
     227  setenv("PATH",pth.toUtf8(),1); 
     228  if(langCode.toLower()=="c"){} 
     229  else if(QString(getenv("MM_CHARSET")).isEmpty() ){ langCode.append("."+QString(getenv("MM_CHARSET"))); } 
     230  else{ langCode.append(".UTF-8"); } 
     231  setenv("LANG",langCode.toUtf8(),1); 
     232  setenv("MAIL",QString("/var/mail/"+xuser).toUtf8(),1); 
     233  setenv("GROUP",xuser.toUtf8(),1); 
     234  setenv("HOME",xhome.toUtf8(),1); 
     235  setenv("SHLVL","0",1); 
     236  chdir(xhome.toUtf8()); //move to home dir 
     237    
     238  //Now start the process 
     239  qDebug() << "Start the desktop"; 
     240  system(cmd.toLatin1()); 
     241} 
     242 
    168243   
    169244void XProcess::setupDesktop(QString user, QString pwd, QString desktop){ 
Note: See TracChangeset for help on using the changeset viewer.