summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/passwd.cpp23
-rw-r--r--noncore/settings/usermanager/userdialog.cpp35
-rw-r--r--noncore/settings/usermanager/userdialog.h9
3 files changed, 51 insertions, 16 deletions
diff --git a/noncore/settings/usermanager/passwd.cpp b/noncore/settings/usermanager/passwd.cpp
index 5063661..0a2bfba 100644
--- a/noncore/settings/usermanager/passwd.cpp
+++ b/noncore/settings/usermanager/passwd.cpp
@@ -52,4 +52,5 @@ char *Passwd::crypt_make_salt() {
52} 52}
53 53
54// opens the files /etc/passwd & /etc/group and loads the contents into passwdStringList & groupStringList
54bool Passwd::open() { 55bool Passwd::open() {
55 int returnvalue=false; 56 int returnvalue=false;
@@ -77,4 +78,5 @@ bool Passwd::open() {
77} 78}
78 79
80// Writes back the contents of passwdStringList to /etc/passwd & groupStringList to /etc/group
79bool Passwd::close() { 81bool Passwd::close() {
80 int returnvalue=false; 82 int returnvalue=false;
@@ -99,4 +101,5 @@ bool Passwd::close() {
99} 101}
100 102
103// Splits a "passwd" line into the components and stores them in the pw_* variables.
101void Passwd::splitPasswdEntry(QString &userString) { 104void Passwd::splitPasswdEntry(QString &userString) {
102 userdataStringList=QStringList::split(":",userString,true); 105 userdataStringList=QStringList::split(":",userString,true);
@@ -111,4 +114,5 @@ void Passwd::splitPasswdEntry(QString &userString) {
111} 114}
112 115
116// Splits a "group" line into the components and stores them in the gr_* variables.
113void Passwd::splitGroupEntry(QString &groupString) { 117void Passwd::splitGroupEntry(QString &groupString) {
114 groupdataStringList=QStringList::split(":",groupString,true); 118 groupdataStringList=QStringList::split(":",groupString,true);
@@ -120,4 +124,5 @@ void Passwd::splitGroupEntry(QString &groupString) {
120} 124}
121 125
126// Find a user in the passwdStringList. Return true if found and also fill the pw_* variables.
122bool Passwd::searchUser(QRegExp &userRegExp) { 127bool Passwd::searchUser(QRegExp &userRegExp) {
123 QStringList tempStringList(passwdStringList.grep(userRegExp)); 128 QStringList tempStringList(passwdStringList.grep(userRegExp));
@@ -131,4 +136,5 @@ bool Passwd::searchUser(QRegExp &userRegExp) {
131} 136}
132 137
138// Find a user by login.
133bool Passwd::findUser(const char *username) { 139bool Passwd::findUser(const char *username) {
134 QRegExp userRegExp(QString("^%1\\:").arg(username)); 140 QRegExp userRegExp(QString("^%1\\:").arg(username));
@@ -136,4 +142,5 @@ bool Passwd::findUser(const char *username) {
136} 142}
137 143
144// Find a user by uid.
138bool Passwd::findUser(int uid) { 145bool Passwd::findUser(int uid) {
139 QRegExp userRegExp(QString(":%1\\:").arg(uid)); 146 QRegExp userRegExp(QString(":%1\\:").arg(uid));
@@ -141,4 +148,5 @@ bool Passwd::findUser(int uid) {
141} 148}
142 149
150// Add a user to the passwdStringList, create home directory, and optionally create a group for the user.
143bool Passwd::addUser(QString pw_name, QString pw_passwd, int pw_uid, int pw_gid, QString pw_gecos,QString pw_dir, QString pw_shell, bool createGroup) { 151bool Passwd::addUser(QString pw_name, QString pw_passwd, int pw_uid, int pw_gid, QString pw_gecos,QString pw_dir, QString pw_shell, bool createGroup) {
144 QString tempString; 152 QString tempString;
@@ -157,4 +165,5 @@ bool Passwd::addUser(QString pw_name, QString pw_passwd, int pw_uid, int pw_gid,
157} 165}
158 166
167// Update info for a user in passwdStringList, take info from the pw_* fields.
159bool Passwd::updateUser(QString login) { 168bool Passwd::updateUser(QString login) {
160 QRegExp userRegExp(QString("^%1\\:").arg(login)); 169 QRegExp userRegExp(QString("^%1\\:").arg(login));
@@ -168,4 +177,5 @@ bool Passwd::updateUser(QString login) {
168} 177}
169 178
179// Delete a user from passwdStringList.
170bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) { 180bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) {
171 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { 181 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
@@ -180,4 +190,5 @@ bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) {
180} 190}
181 191
192// Delete a user by login, and optionally also delete group.
182bool Passwd::delUser(const char *username, bool delGroup) { 193bool Passwd::delUser(const char *username, bool delGroup) {
183 QRegExp userRegExp(QString("^%1\\:").arg(username)); 194 QRegExp userRegExp(QString("^%1\\:").arg(username));
@@ -185,4 +196,5 @@ bool Passwd::delUser(const char *username, bool delGroup) {
185} 196}
186 197
198// Delete a user by uid, and optionally also delete group.
187bool Passwd::delUser(int uid, bool delGroup) { 199bool Passwd::delUser(int uid, bool delGroup) {
188 QRegExp userRegExp(QString(":%1\\:").arg(uid)); 200 QRegExp userRegExp(QString(":%1\\:").arg(uid));
@@ -190,4 +202,5 @@ bool Passwd::delUser(int uid, bool delGroup) {
190} 202}
191 203
204// Locate a group in the groupStringList, fill out the gr_* variables and return "true" if found.
192bool Passwd::searchGroup(QRegExp &groupRegExp) { 205bool Passwd::searchGroup(QRegExp &groupRegExp) {
193 QStringList tempStringList(groupStringList.grep(groupRegExp)); 206 QStringList tempStringList(groupStringList.grep(groupRegExp));
@@ -201,4 +214,5 @@ bool Passwd::searchGroup(QRegExp &groupRegExp) {
201} 214}
202 215
216// Find a group by groupname.
203bool Passwd::findGroup(const char *groupname) { 217bool Passwd::findGroup(const char *groupname) {
204 QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); 218 QRegExp groupRegExp(QString("^%1\\:").arg(groupname));
@@ -206,4 +220,5 @@ bool Passwd::findGroup(const char *groupname) {
206} 220}
207 221
222// Find a group by gid.
208bool Passwd::findGroup(int gid) { 223bool Passwd::findGroup(int gid) {
209 QRegExp groupRegExp(QString(":%1\\:").arg(gid)); 224 QRegExp groupRegExp(QString(":%1\\:").arg(gid));
@@ -211,4 +226,5 @@ bool Passwd::findGroup(int gid) {
211} 226}
212 227
228// Add a group to groupStringList
213bool Passwd::addGroup(QString gr_name, int gr_gid) { 229bool Passwd::addGroup(QString gr_name, int gr_gid) {
214 QString tempString; 230 QString tempString;
@@ -218,4 +234,5 @@ bool Passwd::addGroup(QString gr_name, int gr_gid) {
218} 234}
219 235
236// Update fields for a group in groupStringList, take info from the gr_* variables.
220bool Passwd::updateGroup(int gid) { 237bool Passwd::updateGroup(int gid) {
221 QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid))); 238 QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid)));
@@ -233,4 +250,5 @@ bool Passwd::updateGroup(int gid) {
233} 250}
234 251
252// Delete a group from groupStringList.
235bool Passwd::deleteGroup(QRegExp &groupRegExp) { 253bool Passwd::deleteGroup(QRegExp &groupRegExp) {
236 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { 254 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) {
@@ -243,4 +261,5 @@ bool Passwd::deleteGroup(QRegExp &groupRegExp) {
243} 261}
244 262
263// Delete a group by groupname.
245bool Passwd::delGroup(const char *groupname) { 264bool Passwd::delGroup(const char *groupname) {
246 QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); 265 QRegExp groupRegExp(QString("^%1\\:").arg(groupname));
@@ -248,4 +267,5 @@ bool Passwd::delGroup(const char *groupname) {
248} 267}
249 268
269// Delete a group by gid.
250bool Passwd::delGroup(int gid) { 270bool Passwd::delGroup(int gid) {
251 QRegExp groupRegExp(QString(":%1\\:").arg(gid)); 271 QRegExp groupRegExp(QString(":%1\\:").arg(gid));
@@ -253,4 +273,5 @@ bool Passwd::delGroup(int gid) {
253} 273}
254 274
275// Add a user as a member to a group in groupStringList.
255bool Passwd::addGroupMember(QString groupname, QString member) { 276bool Passwd::addGroupMember(QString groupname, QString member) {
256 if(!(findGroup(groupname))) return false; 277 if(!(findGroup(groupname))) return false;
@@ -260,4 +281,5 @@ bool Passwd::addGroupMember(QString groupname, QString member) {
260} 281}
261 282
283// Delete a user as a groupmember from a group in groupStringList.
262bool Passwd::delGroupMember(QString groupname, QString member) { 284bool Passwd::delGroupMember(QString groupname, QString member) {
263 if(!(findGroup(groupname))) return false; 285 if(!(findGroup(groupname))) return false;
@@ -272,3 +294,4 @@ bool Passwd::delGroupMember(QString groupname, QString member) {
272} 294}
273 295
296// Global Object
274Passwd *accounts; 297Passwd *accounts;
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index 36bcf86..c82cc9d 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -33,5 +33,6 @@ using namespace Opie;
33 * 33 *
34 */ 34 */
35UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 35UserDialog::UserDialog(int viewmode, QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
36 vm=viewmode;
36 QVBoxLayout *layout = new QVBoxLayout(this); 37 QVBoxLayout *layout = new QVBoxLayout(this);
37 myTabWidget=new QTabWidget(this,"User Tab Widget"); 38 myTabWidget=new QTabWidget(this,"User Tab Widget");
@@ -110,11 +111,11 @@ void UserDialog::setupTab1() {
110 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 111 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
111 112
112 // Copy /etc/skel 113 if(vm==VIEWMODE_NEW) {
113 QLabel *skelLabel=new QLabel(tabpage,"skel"); 114 // Copy /etc/skel
114 skelLabel->setText("Copy /etc/skel: "); 115 skelLabel=new QLabel(tabpage,"skel");
115 skelCheckBox=new QCheckBox(tabpage); 116 skelLabel->setText("Copy /etc/skel: ");
116 skelCheckBox->setChecked(true); 117 skelCheckBox=new QCheckBox(tabpage);
117 //skelLabel->setDisabled(true); 118 skelCheckBox->setChecked(true);
118 //skelCheckBox->setDisabled(true); 119 }
119 120
120 // Widget layout 121 // Widget layout
@@ -137,6 +138,8 @@ void UserDialog::setupTab1() {
137 vlayout1->addSpacing(5); 138 vlayout1->addSpacing(5);
138 vlayout1->addWidget(groupLabel); 139 vlayout1->addWidget(groupLabel);
139 vlayout1->addSpacing(5); 140 if(vm==VIEWMODE_NEW) {
140 vlayout1->addWidget(skelLabel); 141 vlayout1->addSpacing(5);
142 vlayout1->addWidget(skelLabel);
143 }
141 // Second column, data 144 // Second column, data
142 vlayout2->addWidget(loginLineEdit); 145 vlayout2->addWidget(loginLineEdit);
@@ -151,6 +154,8 @@ void UserDialog::setupTab1() {
151 vlayout2->addSpacing(5); 154 vlayout2->addSpacing(5);
152 vlayout2->addWidget(groupComboBox); 155 vlayout2->addWidget(groupComboBox);
153 vlayout2->addSpacing(5); 156 if(vm==VIEWMODE_NEW) {
154 vlayout2->addWidget(skelCheckBox); 157 vlayout2->addSpacing(5);
158 vlayout2->addWidget(skelCheckBox);
159 }
155 hlayout->addLayout(vlayout1); 160 hlayout->addLayout(vlayout1);
156 hlayout->addLayout(vlayout2); 161 hlayout->addLayout(vlayout2);
@@ -197,5 +202,6 @@ bool UserDialog::addUser(int uid, int gid) {
197 int oz=false; 202 int oz=false;
198 if(ODevice::inst()->system()==System_OpenZaurus) oz=true; 203 if(ODevice::inst()->system()==System_OpenZaurus) oz=true;
199 UserDialog *adduserDialog=new UserDialog(); 204 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating adduserDialog's widgets here.
205 UserDialog *adduserDialog=new UserDialog(VIEWMODE_NEW);
200 adduserDialog->setCaption(tr("Add User")); 206 adduserDialog->setCaption(tr("Add User"));
201 adduserDialog->userID=uid;// Set next available UID as default uid. 207 adduserDialog->userID=uid;// Set next available UID as default uid.
@@ -299,5 +305,6 @@ bool UserDialog::delUser(const char *username) {
299bool UserDialog::editUser(const char *username) { 305bool UserDialog::editUser(const char *username) {
300 int invalid_group=0; 306 int invalid_group=0;
301 UserDialog *edituserDialog=new UserDialog();// Create Dialog 307 // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here.
308 UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog
302 edituserDialog->setCaption(tr("Edit User")); 309 edituserDialog->setCaption(tr("Edit User"));
303 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. 310 accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object.
diff --git a/noncore/settings/usermanager/userdialog.h b/noncore/settings/usermanager/userdialog.h
index 133b35d..b7b925d 100644
--- a/noncore/settings/usermanager/userdialog.h
+++ b/noncore/settings/usermanager/userdialog.h
@@ -43,5 +43,10 @@ private:
43 int groupID; 43 int groupID;
44 int userID; 44 int userID;
45 45 int vm;
46 enum VIEWMODE {
47 VIEWMODE_NEW,
48 VIEWMODE_EDIT
49 };
50
46 void setupTab1(void); 51 void setupTab1(void);
47 void setupTab2(void); 52 void setupTab2(void);
@@ -52,5 +57,5 @@ private slots:
52 57
53public: 58public:
54 UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); 59 UserDialog( int viewmode=VIEWMODE_NEW, QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 );
55 ~UserDialog(); 60 ~UserDialog();
56 static bool addUser(int uid, int gid); 61 static bool addUser(int uid, int gid);