summaryrefslogtreecommitdiff
authorumopapisdn <umopapisdn>2002-11-01 21:29:35 (UTC)
committer umopapisdn <umopapisdn>2002-11-01 21:29:35 (UTC)
commit7ccfa11a1ccbb4cfb047bd1fa1eb19402d9c8dd6 (patch) (unidiff)
treebb2d0b7a66a188ffd7ad6f9729b9691aa8452682
parent89567519b98853932093e06af4a28f6cc4cc8fd9 (diff)
downloadopie-7ccfa11a1ccbb4cfb047bd1fa1eb19402d9c8dd6.zip
opie-7ccfa11a1ccbb4cfb047bd1fa1eb19402d9c8dd6.tar.gz
opie-7ccfa11a1ccbb4cfb047bd1fa1eb19402d9c8dd6.tar.bz2
* "Copy /etc/skel" option is now only available when adding a user.
* Documented some more of the source code.
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
@@ -51,6 +51,7 @@ char *Passwd::crypt_make_salt() {
51 return result; 51 return result;
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;
56 57
@@ -76,6 +77,7 @@ bool Passwd::open() {
76 return returnvalue; 77 return returnvalue;
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;
81 QFile passwd_file("/etc/passwd"); 83 QFile passwd_file("/etc/passwd");
@@ -98,6 +100,7 @@ bool Passwd::close() {
98 return returnvalue; 100 return returnvalue;
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);
103 QStringList::Iterator it=userdataStringList.begin(); 106 QStringList::Iterator it=userdataStringList.begin();
@@ -110,6 +113,7 @@ void Passwd::splitPasswdEntry(QString &userString) {
110 pw_shell=(*it++); 113 pw_shell=(*it++);
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);
115 QStringList::Iterator it=groupdataStringList.begin(); 119 QStringList::Iterator it=groupdataStringList.begin();
@@ -119,6 +123,7 @@ void Passwd::splitGroupEntry(QString &groupString) {
119 gr_mem=QStringList::split(" ",(*it++)); 123 gr_mem=QStringList::split(" ",(*it++));
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));
124 if((tempStringList.isEmpty())) { 129 if((tempStringList.isEmpty())) {
@@ -130,16 +135,19 @@ bool Passwd::searchUser(QRegExp &userRegExp) {
130 return true; 135 return true;
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));
135 return searchUser(userRegExp); 141 return searchUser(userRegExp);
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));
140 return searchUser(userRegExp); 147 return searchUser(userRegExp);
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;
145 if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid); 153 if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid);
@@ -156,6 +164,7 @@ bool Passwd::addUser(QString pw_name, QString pw_passwd, int pw_uid, int pw_gid,
156 return 1; 164 return 1;
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));
161 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { 170 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
@@ -167,6 +176,7 @@ bool Passwd::updateUser(QString login) {
167 return false; 176 return false;
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) {
172 if(userRegExp.find((*it),0)!=-1) { 182 if(userRegExp.find((*it),0)!=-1) {
@@ -179,16 +189,19 @@ bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) {
179 return false; 189 return false;
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));
184 return deleteUser(userRegExp,delGroup); 195 return deleteUser(userRegExp,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));
189 return deleteUser(userRegExp,delGroup); 201 return deleteUser(userRegExp,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));
194 if((tempStringList.isEmpty())) { 207 if((tempStringList.isEmpty())) {
@@ -200,16 +213,19 @@ bool Passwd::searchGroup(QRegExp &groupRegExp) {
200 return true; 213 return true;
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));
205 return searchGroup(groupRegExp); 219 return searchGroup(groupRegExp);
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));
210 return searchGroup(groupRegExp); 225 return searchGroup(groupRegExp);
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;
215 tempString=gr_name+":*:"+QString::number(gr_gid)+":"; 231 tempString=gr_name+":*:"+QString::number(gr_gid)+":";
@@ -217,6 +233,7 @@ bool Passwd::addGroup(QString gr_name, int gr_gid) {
217 return 1; 233 return 1;
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)));
222 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { 239 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) {
@@ -232,6 +249,7 @@ bool Passwd::updateGroup(int gid) {
232 return false; 249 return false;
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) {
237 if(groupRegExp.find((*it),0)!=-1) { 255 if(groupRegExp.find((*it),0)!=-1) {
@@ -242,16 +260,19 @@ bool Passwd::deleteGroup(QRegExp &groupRegExp) {
242 return false; 260 return false;
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));
247 return deleteGroup(groupRegExp); 266 return deleteGroup(groupRegExp);
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));
252 return deleteGroup(groupRegExp); 272 return deleteGroup(groupRegExp);
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;
257 gr_mem << member; 278 gr_mem << member;
@@ -259,6 +280,7 @@ bool Passwd::addGroupMember(QString groupname, QString member) {
259 return true; 280 return true;
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;
264 for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) { 286 for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) {
@@ -271,4 +293,5 @@ bool Passwd::delGroupMember(QString groupname, QString member) {
271 return true; 293 return true;
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
@@ -32,7 +32,8 @@ using namespace Opie;
32 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 32 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
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");
38 layout->addWidget(myTabWidget); 39 layout->addWidget(myTabWidget);
@@ -109,13 +110,13 @@ void UserDialog::setupTab1() {
109 groupLabel->setText("Primary group: "); 110 groupLabel->setText("Primary group: ");
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
121 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 122 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
@@ -136,8 +137,10 @@ void UserDialog::setupTab1() {
136 vlayout1->addWidget(shellLabel); 137 vlayout1->addWidget(shellLabel);
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);
143 vlayout2->addSpacing(5); 146 vlayout2->addSpacing(5);
@@ -150,8 +153,10 @@ void UserDialog::setupTab1() {
150 vlayout2->addWidget(shellComboBox); 153 vlayout2->addWidget(shellComboBox);
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);
157 162
@@ -196,7 +201,8 @@ bool UserDialog::addUser(int uid, int gid) {
196 QFile ozTest; 201 QFile ozTest;
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.
202 adduserDialog->groupID=gid;// Set next available GID as default gid. 208 adduserDialog->groupID=gid;// Set next available GID as default gid.
@@ -298,7 +304,8 @@ bool UserDialog::delUser(const char *username) {
298 */ 304 */
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.
304 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. 311 if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group 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
@@ -42,7 +42,12 @@ private:
42 QImage userImage; 42 QImage userImage;
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);
48 void accept(void); 53 void accept(void);
@@ -51,7 +56,7 @@ private slots:
51 void clickedPicture(void); 56 void clickedPicture(void);
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);
57 static bool editUser(const char *username); 62 static bool editUser(const char *username);