Permalink
Browse files

Couple new features for PCDM

1) Add option to require that the user type in the username instead of just selecting one from a list (does not recognize "root" or "toor", I made sure of that)
2) Move the backend system user detection to using "getent" after conversation with john @ ixsystems. That should properly pick up LDAP/ActiveDirectory users as well, whereas "pw" might not.
  • Loading branch information...
1 parent 7c53dd2 commit ae41693d4b23c0e9a46de19f0ed609eacdb20fe8 Ken Moore committed Feb 27, 2014
@@ -17,10 +17,12 @@ LoginWidget::LoginWidget(QWidget* parent) : QGroupBox(parent)
userSelected = FALSE; //focus on the username first
pwVisible = FALSE; //Have the password box hide the input behind dots
allowPWVisible = TRUE; //Allow the password button to show the password text
-
+ showUsers = true; //Display the available users on the system
+
//Create the Grid layout
QHBoxLayout* hlayout1 = new QHBoxLayout();
QHBoxLayout* hlayout2 = new QHBoxLayout();
+ QHBoxLayout* hlayout3 = new QHBoxLayout();
QVBoxLayout* vlayout = new QVBoxLayout();
QFormLayout* flayout = new QFormLayout();
//Create the items
@@ -35,6 +37,8 @@ LoginWidget::LoginWidget(QWidget* parent) : QGroupBox(parent)
listUsers->setFocusPolicy(Qt::NoFocus); //big one gets keyboard focus instead
linePassword = new QLineEdit;
linePassword->setFocusPolicy(Qt::StrongFocus);
+ lineUsername = new QLineEdit;
+ lineUsername->setFocusPolicy(Qt::StrongFocus);
pushLogin = new QToolButton;
QAction* tmp1 = new QAction(this);
pushLogin->setDefaultAction( tmp1 );
@@ -56,7 +60,9 @@ LoginWidget::LoginWidget(QWidget* parent) : QGroupBox(parent)
vlayout->addLayout(hlayout1);
vlayout->addWidget(listUserBig);
//User selected widgets
- flayout->addRow(pushUserIcon, listUsers);
+ hlayout3->addWidget(listUsers);
+ hlayout3->addWidget(lineUsername);
+ flayout->addRow(pushUserIcon, hlayout3);
flayout->addRow(pushViewPassword, linePassword);
flayout->addRow(deIcon,listDE);
vlayout->addSpacing(15);
@@ -87,17 +93,31 @@ LoginWidget::~LoginWidget(){
void LoginWidget::updateWidget(){
//Setup the visibility/sizes
- if(userSelected){
+ if(userSelected && showUsers){
userIcon->setVisible(FALSE);
listUserBig->setVisible(FALSE);
pushUserIcon->setVisible(TRUE);
listUsers->setVisible(TRUE);
+ lineUsername->setVisible(false);
+ linePassword->setVisible(TRUE);
+ pushLogin->setVisible(TRUE);
+ pushViewPassword->setVisible(TRUE);
+ if( listDE->count() < 1 ){ listDE->setVisible(FALSE); deIcon->setVisible(FALSE); }
+ else{ listDE->setVisible(TRUE); deIcon->setVisible(TRUE); }
+ }else if(!showUsers){
+ //Do not show either of the user selection widgets
+ userIcon->setVisible(FALSE);
+ listUserBig->setVisible(FALSE);
+ pushUserIcon->setVisible(TRUE);
+ listUsers->setVisible(false);
+ lineUsername->setVisible(true);
linePassword->setVisible(TRUE);
pushLogin->setVisible(TRUE);
pushViewPassword->setVisible(TRUE);
if( listDE->count() < 1 ){ listDE->setVisible(FALSE); deIcon->setVisible(FALSE); }
else{ listDE->setVisible(TRUE); deIcon->setVisible(TRUE); }
}else{
+ //ShowUsers and none selected
userIcon->setVisible(TRUE);
listUserBig->setVisible(TRUE);
pushUserIcon->setVisible(FALSE);
@@ -153,7 +173,12 @@ void LoginWidget::slotUserHighlighted(int row){
}
void LoginWidget::slotTryLogin(){
- QString user = listUsers->currentText();
+ QString user;
+ if(showUsers){
+ user = listUsers->currentText();
+ }else{
+ user = lineUsername->text();
+ }
QString pw = linePassword->text();
emit loginRequested(user,pw);
linePassword->setText(""); //always clear the box after a login attempt
@@ -363,3 +388,8 @@ void LoginWidget::allowPasswordView(bool allow){
connect(pushViewPassword,SIGNAL(released()),this,SLOT(slotChangePWView()));
}
}
+
+void LoginWidget::allowUserSelection(bool allow){
+ showUsers = allow;
+ updateWidget();
+}
@@ -53,12 +53,13 @@ class LoginWidget : public QGroupBox
void retranslateUi();
void resetFocus(QString item="");
void allowPasswordView(bool);
+ void allowUserSelection(bool);
private:
QComboBox* listUsers;
QComboBox* listDE;
QListWidget* listUserBig;
- QLineEdit* linePassword;
+ QLineEdit *linePassword, *lineUsername;
QToolButton* pushLogin;
QToolButton* pushViewPassword;
QToolButton *pushUserIcon, *userIcon;
@@ -68,7 +69,7 @@ class LoginWidget : public QGroupBox
QStringList idL, desktopIcons, desktopInfo;
QSize desktopIconSize;
QString hostName;
- bool userSelected, pwVisible, allowPWVisible;
+ bool userSelected, pwVisible, allowPWVisible, showUsers;
void updateWidget();
@@ -470,13 +470,13 @@ void Backend::readSystemUsers(){
QStringList uList;
bool usepw = true; //for testing purposes
if(usepw){
- //Use "pw" to get all possible users
+ //Use "getent" to get all possible users
QProcess p;
p.setProcessChannelMode(QProcess::MergedChannels);
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("MM_CHARSET","UTF-8");
p.setProcessEnvironment(env);
- p.start("pw usershow -a");
+ p.start("getent passwd");
while(p.state()==QProcess::Starting || p.state() == QProcess::Running){
p.waitForFinished(200);
QCoreApplication::processEvents();
@@ -487,9 +487,9 @@ void Backend::readSystemUsers(){
for(int i=0; i<uList.length(); i++){
bool bad = FALSE;
// "nologin" as their shell
- if(uList[i].section(":",9,9).contains("nologin")){bad=TRUE;}
+ if(uList[i].section(":",6,6).contains("nologin")){bad=TRUE;}
// "nonexistent" as their user directory
- else if(uList[i].section(":",8,8).contains("nonexistent")){bad=TRUE;}
+ else if(uList[i].section(":",5,5).contains("nonexistent")){bad=TRUE;}
// uid > 1000
else if(uList[i].section(":",2,2).toInt() < 1000){bad=TRUE;}
@@ -498,9 +498,9 @@ void Backend::readSystemUsers(){
else{
//Add this user to the lists if it is good
usernameList << uList[i].section(":",0,0).simplified();
- displaynameList << uList[i].section(":",7,7).simplified();
- homedirList << uList[i].section(":",8,8).simplified();
- usershellList << uList[i].section(":",9,9).simplified();
+ displaynameList << uList[i].section(":",4,4).simplified();
+ homedirList << uList[i].section(":",5,5).simplified();
+ usershellList << uList[i].section(":",6,6).simplified();
}
}
}else{
@@ -24,6 +24,7 @@ void Config::loadDefaults(){
confStruct << "/usr/local/share/PCDM/images/default-splash.png"; // [7] Splash Screen File
confStruct << "TRUE"; // [8] Password view button enabled
confStruct << "10"; // [9] Auto-login delay (seconds)
+ confStruct << "TRUE"; // [10] Show System Users
return;
}
@@ -55,6 +56,7 @@ void Config::readConfigFile(QString filePath){
else if(var=="SPLASHSCREEN_FILE"){ confStruct[7] = val; }
else if(var=="ENABLE_VIEW_PASSWORD_BUTTON"){ confStruct[8] = val; }
else if(var=="AUTO_LOGIN_DELAY"){ confStruct[9] = val; }
+ else if(var=="SHOW_SYSTEM_USERS"){ confStruct[10] = val; }
else{}
}
@@ -116,3 +118,7 @@ bool Config::allowPasswordView(){
else{ return FALSE; }
}
+bool Config::allowUserSelection(){
+ if(confStruct[10].toLower()=="true"){ return TRUE; }
+ else{ return FALSE; }
+}
@@ -33,6 +33,7 @@ class Config{
static int autoLoginDelay(); //Returns the number of seconds to delay auto-login
static QString splashscreen(); //return the image file for the splashscreen
static bool allowPasswordView(); //returns whether password view button is enabled
+ static bool allowUserSelection(); //returns whether to display system users for selection
};
@@ -191,6 +191,7 @@ void PCDMgui::createGUIfromTheme(){
loginW->changeButtonIcon("pwview",tmpIcon, currentTheme->itemIconSize("password"));
//Enable/disable the password view functionality
loginW->allowPasswordView( Config::allowPasswordView() );
+ loginW->allowUserSelection( Config::allowUserSelection() );
//Add item to the grid
grid->addWidget( loginW, currentTheme->itemLocation("login","row"), \
currentTheme->itemLocation("login","col"), \

0 comments on commit ae41693

Please sign in to comment.