summaryrefslogtreecommitdiff
authorumopapisdn <umopapisdn>2003-03-22 00:31:44 (UTC)
committer umopapisdn <umopapisdn>2003-03-22 00:31:44 (UTC)
commitebf65f250904e0619c10b69a0428fcc538ffc167 (patch) (unidiff)
tree1ed0ca90ff564a55116787acff758cb2e4dcb4f8
parentab8cb739c666f5f22049258a4bcbb06d1e1ad0c4 (diff)
downloadopie-ebf65f250904e0619c10b69a0428fcc538ffc167.zip
opie-ebf65f250904e0619c10b69a0428fcc538ffc167.tar.gz
opie-ebf65f250904e0619c10b69a0428fcc538ffc167.tar.bz2
Bugfix: Groupmembers should be separated by a comma and not by a space.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/passwd.cpp11
-rw-r--r--noncore/settings/usermanager/userdialog.cpp17
2 files changed, 23 insertions, 5 deletions
diff --git a/noncore/settings/usermanager/passwd.cpp b/noncore/settings/usermanager/passwd.cpp
index 0a2bfba..1e98778 100644
--- a/noncore/settings/usermanager/passwd.cpp
+++ b/noncore/settings/usermanager/passwd.cpp
@@ -107,33 +107,33 @@ void Passwd::splitPasswdEntry(QString &userString) {
107 pw_name=(*it++); 107 pw_name=(*it++);
108 pw_passwd=(*it++); 108 pw_passwd=(*it++);
109 pw_uid=(*it++).toInt(); 109 pw_uid=(*it++).toInt();
110 pw_gid=(*it++).toInt(); 110 pw_gid=(*it++).toInt();
111 pw_gecos=(*it++); 111 pw_gecos=(*it++);
112 pw_dir=(*it++); 112 pw_dir=(*it++);
113 pw_shell=(*it++); 113 pw_shell=(*it++);
114} 114}
115 115
116// Splits a "group" line into the components and stores them in the gr_* variables. 116// Splits a "group" line into the components and stores them in the gr_* variables.
117void Passwd::splitGroupEntry(QString &groupString) { 117void Passwd::splitGroupEntry(QString &groupString) {
118 groupdataStringList=QStringList::split(":",groupString,true); 118 groupdataStringList=QStringList::split(":",groupString,true);
119 QStringList::Iterator it=groupdataStringList.begin(); 119 QStringList::Iterator it=groupdataStringList.begin();
120 gr_name=(*it++); 120 gr_name=(*it++);
121 it++; 121 it++;
122 gr_gid=(*it++).toInt(); 122 gr_gid=(*it++).toInt();
123 gr_mem=QStringList::split(" ",(*it++)); 123 gr_mem=QStringList::split(",",(*it++));
124} 124}
125 125
126// Find a user in the passwdStringList. Return true if found and also fill the pw_* variables. 126// Find a user in the passwdStringList. Return true if found and also fill the pw_* variables.
127bool Passwd::searchUser(QRegExp &userRegExp) { 127bool Passwd::searchUser(QRegExp &userRegExp) {
128 QStringList tempStringList(passwdStringList.grep(userRegExp)); 128 QStringList tempStringList(passwdStringList.grep(userRegExp));
129 if((tempStringList.isEmpty())) { 129 if((tempStringList.isEmpty())) {
130 return false; 130 return false;
131 } else { 131 } else {
132 userString=(*(tempStringList.begin())); 132 userString=(*(tempStringList.begin()));
133 splitPasswdEntry(userString); 133 splitPasswdEntry(userString);
134 } 134 }
135 return true; 135 return true;
136} 136}
137 137
138// Find a user by login. 138// Find a user by login.
139bool Passwd::findUser(const char *username) { 139bool Passwd::findUser(const char *username) {
@@ -226,35 +226,36 @@ bool Passwd::findGroup(int gid) {
226} 226}
227 227
228// Add a group to groupStringList 228// Add a group to groupStringList
229bool Passwd::addGroup(QString gr_name, int gr_gid) { 229bool Passwd::addGroup(QString gr_name, int gr_gid) {
230 QString tempString; 230 QString tempString;
231 tempString=gr_name+":*:"+QString::number(gr_gid)+":"; 231 tempString=gr_name+":*:"+QString::number(gr_gid)+":";
232 groupStringList.append(tempString); 232 groupStringList.append(tempString);
233 return 1; 233 return 1;
234} 234}
235 235
236// Update fields for a group in groupStringList, take info from the gr_* variables. 236// Update fields for a group in groupStringList, take info from the gr_* variables.
237bool Passwd::updateGroup(int gid) { 237bool Passwd::updateGroup(int gid) {
238 QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid))); 238 QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid)));
239 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { 239 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) {
240 if(groupRegExp.find((*it),0)!=-1) { 240 if(groupRegExp.find((*it),0)!=-1) {
241 *it=QString(gr_name+":*:"+QString::number(gr_gid)+":"); 241 *it=QString(gr_name+":*:"+QString::number(gr_gid)+":");
242 for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end(); ++member) { 242 for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end();) {
243 *it+=*member; 243 *it+=*member;
244 *it+=" "; 244 ++member;
245 if(member!=gr_mem.end()) *it+=",";
245 } 246 }
246 return true; 247 return true;
247 } 248 }
248 } 249 }
249 return false; 250 return false;
250} 251}
251 252
252// Delete a group from groupStringList. 253// Delete a group from groupStringList.
253bool Passwd::deleteGroup(QRegExp &groupRegExp) { 254bool Passwd::deleteGroup(QRegExp &groupRegExp) {
254 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { 255 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) {
255 if(groupRegExp.find((*it),0)!=-1) { 256 if(groupRegExp.find((*it),0)!=-1) {
256 groupStringList.remove(it); 257 groupStringList.remove(it);
257 return true; 258 return true;
258 } 259 }
259 } 260 }
260 return false; 261 return false;
@@ -262,33 +263,35 @@ bool Passwd::deleteGroup(QRegExp &groupRegExp) {
262 263
263// Delete a group by groupname. 264// Delete a group by groupname.
264bool Passwd::delGroup(const char *groupname) { 265bool Passwd::delGroup(const char *groupname) {
265 QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); 266 QRegExp groupRegExp(QString("^%1\\:").arg(groupname));
266 return deleteGroup(groupRegExp); 267 return deleteGroup(groupRegExp);
267} 268}
268 269
269// Delete a group by gid. 270// Delete a group by gid.
270bool Passwd::delGroup(int gid) { 271bool Passwd::delGroup(int gid) {
271 QRegExp groupRegExp(QString(":%1\\:").arg(gid)); 272 QRegExp groupRegExp(QString(":%1\\:").arg(gid));
272 return deleteGroup(groupRegExp); 273 return deleteGroup(groupRegExp);
273} 274}
274 275
275// Add a user as a member to a group in groupStringList. 276// Add a user as a member to a group in groupStringList.
276bool Passwd::addGroupMember(QString groupname, QString member) { 277bool Passwd::addGroupMember(QString groupname, QString member) {
277 if(!(findGroup(groupname))) return false; 278 if(!(findGroup(groupname))) return false;
278 gr_mem << member; 279 QRegExp memberRegExp(QString("^%1$").arg(member));
280 QStringList templist=gr_mem.grep(memberRegExp);
281 if(templist.isEmpty()) gr_mem << member;
279 if(!(updateGroup(gr_gid))) return false; 282 if(!(updateGroup(gr_gid))) return false;
280 return true; 283 return true;
281} 284}
282 285
283// Delete a user as a groupmember from a group in groupStringList. 286// Delete a user as a groupmember from a group in groupStringList.
284bool Passwd::delGroupMember(QString groupname, QString member) { 287bool Passwd::delGroupMember(QString groupname, QString member) {
285 if(!(findGroup(groupname))) return false; 288 if(!(findGroup(groupname))) return false;
286 for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) { 289 for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) {
287 if(*it==member) { 290 if(*it==member) {
288 gr_mem.remove(it); 291 gr_mem.remove(it);
289 it=gr_mem.end(); 292 it=gr_mem.end();
290 } 293 }
291 } 294 }
292 if(!(updateGroup(gr_gid))) return false; 295 if(!(updateGroup(gr_gid))) return false;
293 return true; 296 return true;
294} 297}
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index c82cc9d..0d2122b 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -320,37 +320,52 @@ bool UserDialog::editUser(const char *username) {
320 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. 320 // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox.
321 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { 321 if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") {
322 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); 322 edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0);
323 edituserDialog->shellComboBox->setCurrentItem(0); 323 edituserDialog->shellComboBox->setCurrentItem(0);
324 } 324 }
325 // Select the primary group for this user. 325 // Select the primary group for this user.
326 for(int i=0;i<edituserDialog->groupComboBox->count();++i) { 326 for(int i=0;i<edituserDialog->groupComboBox->count();++i) {
327 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 327 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) {
328 edituserDialog->groupComboBox->setCurrentItem(i); 328 edituserDialog->groupComboBox->setCurrentItem(i);
329 break; 329 break;
330 } 330 }
331 } 331 }
332 if(invalid_group) { 332 if(invalid_group) {
333 edituserDialog->groupComboBox->insertItem("<Undefined group>",0); 333 edituserDialog->groupComboBox->insertItem("<Undefined group>",0);
334 edituserDialog->groupComboBox->setCurrentItem(0); 334 edituserDialog->groupComboBox->setCurrentItem(0);
335 } 335 }
336
336 // Select the groups in the listview, to which the user belongs. 337 // Select the groups in the listview, to which the user belongs.
337 QCheckListItem *temp; 338 QCheckListItem *temp;
338 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); 339 // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead.
340 QRegExp userRegExp(QString("[:,]%1$").arg(username));// The end of line variant.
339 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 341 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
340 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 342 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them.
343 qWarning(*it);
344 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
345 for ( ; lvit.current(); ++lvit ) {
346 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) {
347 temp=(QCheckListItem*)lvit.current();
348 temp->setOn(true);// If we find a line with that groupname, select it.;
349 }
350 }
351 }
352 userRegExp=QRegExp(QString("[:,]%1,").arg(username));// And the other one. (not end of line.)
353 tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
354 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them.
355 qWarning(*it);
341 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 356 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
342 for ( ; lvit.current(); ++lvit ) { 357 for ( ; lvit.current(); ++lvit ) {
343 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 358 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) {
344 temp=(QCheckListItem*)lvit.current(); 359 temp=(QCheckListItem*)lvit.current();
345 temp->setOn(true);// If we find a line with that groupname, select it.; 360 temp->setOn(true);// If we find a line with that groupname, select it.;
346 } 361 }
347 } 362 }
348 } 363 }
349 364
350 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! 365 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG!
351 366
352 accounts->findUser(username);// Fill user variables in 'acccounts' object. 367 accounts->findUser(username);// Fill user variables in 'acccounts' object.
353 accounts->pw_name=edituserDialog->loginLineEdit->text(); 368 accounts->pw_name=edituserDialog->loginLineEdit->text();
354 // Has the password been changed ? Make a new "crypt":ed password. 369 // Has the password been changed ? Make a new "crypt":ed password.
355 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 370 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
356 371