source: src-qt4/PCDM/src/pcdm-config.cpp @ ae41693

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since ae41693 was ae41693, checked in by Ken Moore <ken@…>, 8 months ago

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.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/* PCDM Login Manager:
2*  Written by Ken Moore (ken@pcbsd.org) 2012/2013
3*  Copyright(c) 2013 by the PC-BSD Project
4*  Available under the 3-clause BSD license
5*/
6
7#include "pcdm-config.h"
8#include "pcdm-backend.h"
9
10//Setup variables that save the current configuration data
11QStringList confStruct;
12
13
14//******** PRIVATE FUNCTIONS *************
15void Config::loadDefaults(){
16  confStruct.clear();
17  confStruct << "/usr/local/share/PCDM/pcdm.theme";     // [0] Theme File Path
18  confStruct << "/usr/local/share/xsessions";           // [1] *.desktop files directory
19  confStruct << "/usr/local/share/pixmaps";             // [2] Images directory for *.desktop icons
20  confStruct << "FALSE";                                // [3] Auto-login enabled
21  confStruct << "no-username";                          // [4] Auto-login username
22  confStruct << "no-desktop";                           // [5] Auto-login desktop environment (legacy)
23  confStruct << "no-password";                          // [6] Auto-login password
24  confStruct << "/usr/local/share/PCDM/images/default-splash.png"; // [7] Splash Screen File
25  confStruct << "TRUE";                                 // [8] Password view button enabled
26  confStruct << "10";                                           // [9] Auto-login delay (seconds)
27  confStruct << "TRUE";                                 // [10] Show System Users
28  return;
29}
30
31void Config::readConfigFile(QString filePath){
32  QFile conf(filePath);
33  bool ok = conf.open(QIODevice::ReadOnly | QIODevice::Text);
34  if(!ok){ 
35    Backend::log("Could not open configuration file: "+filePath+"\nLoading default configuration");
36    if(filePath!=":samples/pcdm.conf"){ readConfigFile(":samples/pcdm.conf"); }
37    return;
38  }
39  QTextStream in(&conf);
40  while( !in.atEnd() ){
41    QString line = in.readLine().simplified();
42    //Skip comment lines
43    if(!line.startsWith("#")){
44      line = line.section("#",0,0).simplified(); //cut any comments off the end of the line
45      QString var = line.section("=",0,0).simplified(); // get the variable
46      QString val = line.section("=",1,1).simplified(); // get the value
47     
48      //Parse the Configuration File
49      if(var=="THEME_FILE"){ confStruct[0] = val; }
50      else if(var=="DE_STARTUP_DIR"){ confStruct[1] = val; }
51      else if(var=="DE_STARTUP_IMAGE_DIR"){ confStruct[2] = val; }
52      else if(var=="ENABLE_AUTO_LOGIN"){ confStruct[3] = val; }
53      else if(var=="AUTO_LOGIN_USER"){ confStruct[4] = val; }
54      //else if(var=="AUTO_LOGIN_DESKTOP"){ confStruct[5] = val; } //legacy option
55      else if(var=="AUTO_LOGIN_PASSWORD"){ confStruct[6] = val; }
56      else if(var=="SPLASHSCREEN_FILE"){ confStruct[7] = val; }
57      else if(var=="ENABLE_VIEW_PASSWORD_BUTTON"){ confStruct[8] = val; }
58      else if(var=="AUTO_LOGIN_DELAY"){ confStruct[9] = val; }
59      else if(var=="SHOW_SYSTEM_USERS"){ confStruct[10] = val; }
60      else{}
61     
62    }
63  }
64  conf.close();
65}
66
67//******** PUBLIC FUNCTIONS **************
68void Config::loadConfigFile(QString filePath){
69  loadDefaults();
70  if(!QFile::exists(filePath)){
71    Backend::log("Configuration file does not exist: "+filePath+"\nLoading default configuration");
72    filePath=":samples/pcdm.conf";
73  }
74  readConfigFile(filePath);
75}
76
77QString Config::themeFile(){
78  return confStruct[0];
79}
80
81QString Config::xSessionsDir(){
82  return confStruct[1];
83}
84
85QString Config::xSessionsImageDir(){
86  return confStruct[2];
87}
88
89bool Config::useAutoLogin(){
90  //qDebug() << "confStruct[3]:" << confStruct[3];
91  if(confStruct[3].toLower()=="true"){ return TRUE; }
92  else{ return FALSE; } 
93}
94
95QString Config::autoLoginUsername(){
96  return confStruct[4]; 
97}
98
99QString Config::autoLoginDesktop(){
100  if(confStruct.startsWith("/")){  return confStruct[5]; } //already an absolute path
101  else{ return (confStruct[1]+"/"+confStruct[5]); } //prepend the xsessions directory path
102}
103
104QString Config::autoLoginPassword(){
105  return confStruct[6]; 
106}
107
108int Config::autoLoginDelay(){
109  return confStruct[9].toInt(); 
110}
111
112QString Config::splashscreen(){
113  return confStruct[7]; 
114}
115
116bool Config::allowPasswordView(){
117  if(confStruct[8].toLower()=="true"){ return TRUE; }
118  else{ return FALSE; } 
119}
120
121bool Config::allowUserSelection(){
122  if(confStruct[10].toLower()=="true"){ return TRUE; }
123  else{ return FALSE; } 
124}
Note: See TracBrowser for help on using the repository browser.