summaryrefslogtreecommitdiff
authorumopapisdn <umopapisdn>2002-09-28 06:36:30 (UTC)
committer umopapisdn <umopapisdn>2002-09-28 06:36:30 (UTC)
commit8a95ca149ff5eedc9215bb012c8d7d09cdcaf96c (patch) (unidiff)
tree50aed468fa8888266c589ce47131d0acaf7f82b7
parent996c0d02d16c185acc3190baa5b4a1fc934e730c (diff)
downloadopie-8a95ca149ff5eedc9215bb012c8d7d09cdcaf96c.zip
opie-8a95ca149ff5eedc9215bb012c8d7d09cdcaf96c.tar.gz
opie-8a95ca149ff5eedc9215bb012c8d7d09cdcaf96c.tar.bz2
Now actually makes the homedirectories owned by the user they belong to. :)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/usermanager/passwd.cpp5
-rw-r--r--noncore/settings/usermanager/userdialog.cpp10
-rw-r--r--noncore/settings/usermanager/userdialog.h2
-rw-r--r--noncore/settings/usermanager/usermanager.pro2
4 files changed, 15 insertions, 4 deletions
diff --git a/noncore/settings/usermanager/passwd.cpp b/noncore/settings/usermanager/passwd.cpp
index 310cef8..5063661 100644
--- a/noncore/settings/usermanager/passwd.cpp
+++ b/noncore/settings/usermanager/passwd.cpp
@@ -1,215 +1,218 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10#include "passwd.h" 10#include "passwd.h"
11 11
12// Needed for crypt_make_salt(); 12// Needed for crypt_make_salt();
13#include <sys/types.h> 13#include <sys/types.h>
14#include <sys/stat.h>
14#include <unistd.h> 15#include <unistd.h>
15#include <time.h> 16#include <time.h>
16 17
17Passwd::Passwd() { 18Passwd::Passwd() {
18} 19}
19 20
20Passwd::~Passwd() { 21Passwd::~Passwd() {
21} 22}
22 23
23// This function is taken from 'busybox'. 24// This function is taken from 'busybox'.
24int Passwd::i64c(int i) 25int Passwd::i64c(int i)
25{ 26{
26 if (i <= 0) 27 if (i <= 0)
27 return ('.'); 28 return ('.');
28 if (i == 1) 29 if (i == 1)
29 return ('/'); 30 return ('/');
30 if (i >= 2 && i < 12) 31 if (i >= 2 && i < 12)
31 return ('0' - 2 + i); 32 return ('0' - 2 + i);
32 if (i >= 12 && i < 38) 33 if (i >= 12 && i < 38)
33 return ('A' - 12 + i); 34 return ('A' - 12 + i);
34 if (i >= 38 && i < 63) 35 if (i >= 38 && i < 63)
35 return ('a' - 38 + i); 36 return ('a' - 38 + i);
36 return ('z'); 37 return ('z');
37} 38}
38 39
39// This function is taken from 'busybox'. 40// This function is taken from 'busybox'.
40char *Passwd::crypt_make_salt() { 41char *Passwd::crypt_make_salt() {
41 time_t now; 42 time_t now;
42 static unsigned long x; 43 static unsigned long x;
43 static char result[3]; 44 static char result[3];
44 45
45 time(&now); 46 time(&now);
46 x += now + getpid() + clock(); 47 x += now + getpid() + clock();
47 result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077); 48 result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077);
48 result[1] = i64c(((x >> 12) ^ x) & 077); 49 result[1] = i64c(((x >> 12) ^ x) & 077);
49 result[2] = '\0'; 50 result[2] = '\0';
50 return result; 51 return result;
51} 52}
52 53
53bool Passwd::open() { 54bool Passwd::open() {
54 int returnvalue=false; 55 int returnvalue=false;
55 56
56 QFile passwd_file("/etc/passwd"); 57 QFile passwd_file("/etc/passwd");
57 QFile group_file("/etc/group"); 58 QFile group_file("/etc/group");
58 passwdStringList.clear(); 59 passwdStringList.clear();
59 groupStringList.clear(); 60 groupStringList.clear();
60 if((passwd_file.open(IO_ReadOnly))) { 61 if((passwd_file.open(IO_ReadOnly))) {
61 if((group_file.open(IO_ReadOnly))) { 62 if((group_file.open(IO_ReadOnly))) {
62 QTextStream ts_passwd(&passwd_file); 63 QTextStream ts_passwd(&passwd_file);
63 while(!(ts_passwd.eof())) { 64 while(!(ts_passwd.eof())) {
64 passwdStringList << ts_passwd.readLine(); 65 passwdStringList << ts_passwd.readLine();
65 } 66 }
66 QTextStream ts_group(&group_file); 67 QTextStream ts_group(&group_file);
67 while(!(ts_group.eof())) { 68 while(!(ts_group.eof())) {
68 groupStringList << ts_group.readLine(); 69 groupStringList << ts_group.readLine();
69 } 70 }
70 returnvalue=true; 71 returnvalue=true;
71 group_file.close(); 72 group_file.close();
72 } 73 }
73 passwd_file.close(); 74 passwd_file.close();
74 } 75 }
75 return returnvalue; 76 return returnvalue;
76} 77}
77 78
78bool Passwd::close() { 79bool Passwd::close() {
79 int returnvalue=false; 80 int returnvalue=false;
80 QFile passwd_file("/etc/passwd"); 81 QFile passwd_file("/etc/passwd");
81 QFile group_file("/etc/group"); 82 QFile group_file("/etc/group");
82 if((passwd_file.open(IO_WriteOnly))) { 83 if((passwd_file.open(IO_WriteOnly))) {
83 if((group_file.open(IO_WriteOnly))) { 84 if((group_file.open(IO_WriteOnly))) {
84 QTextStream ts_passwd(&passwd_file); 85 QTextStream ts_passwd(&passwd_file);
85 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { 86 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
86 ts_passwd << (*it) + "\n"; 87 ts_passwd << (*it) + "\n";
87 } 88 }
88 QTextStream ts_group(&group_file); 89 QTextStream ts_group(&group_file);
89 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { 90 for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) {
90 ts_group << (*it) + "\n"; 91 ts_group << (*it) + "\n";
91 } 92 }
92 returnvalue=true; 93 returnvalue=true;
93 group_file.close(); 94 group_file.close();
94 } 95 }
95 passwd_file.close(); 96 passwd_file.close();
96 } 97 }
97 return returnvalue; 98 return returnvalue;
98} 99}
99 100
100void Passwd::splitPasswdEntry(QString &userString) { 101void Passwd::splitPasswdEntry(QString &userString) {
101 userdataStringList=QStringList::split(":",userString,true); 102 userdataStringList=QStringList::split(":",userString,true);
102 QStringList::Iterator it=userdataStringList.begin(); 103 QStringList::Iterator it=userdataStringList.begin();
103 pw_name=(*it++); 104 pw_name=(*it++);
104 pw_passwd=(*it++); 105 pw_passwd=(*it++);
105 pw_uid=(*it++).toInt(); 106 pw_uid=(*it++).toInt();
106 pw_gid=(*it++).toInt(); 107 pw_gid=(*it++).toInt();
107 pw_gecos=(*it++); 108 pw_gecos=(*it++);
108 pw_dir=(*it++); 109 pw_dir=(*it++);
109 pw_shell=(*it++); 110 pw_shell=(*it++);
110} 111}
111 112
112void Passwd::splitGroupEntry(QString &groupString) { 113void Passwd::splitGroupEntry(QString &groupString) {
113 groupdataStringList=QStringList::split(":",groupString,true); 114 groupdataStringList=QStringList::split(":",groupString,true);
114 QStringList::Iterator it=groupdataStringList.begin(); 115 QStringList::Iterator it=groupdataStringList.begin();
115 gr_name=(*it++); 116 gr_name=(*it++);
116 it++; 117 it++;
117 gr_gid=(*it++).toInt(); 118 gr_gid=(*it++).toInt();
118 gr_mem=QStringList::split(" ",(*it++)); 119 gr_mem=QStringList::split(" ",(*it++));
119} 120}
120 121
121bool Passwd::searchUser(QRegExp &userRegExp) { 122bool Passwd::searchUser(QRegExp &userRegExp) {
122 QStringList tempStringList(passwdStringList.grep(userRegExp)); 123 QStringList tempStringList(passwdStringList.grep(userRegExp));
123 if((tempStringList.isEmpty())) { 124 if((tempStringList.isEmpty())) {
124 return false; 125 return false;
125 } else { 126 } else {
126 userString=(*(tempStringList.begin())); 127 userString=(*(tempStringList.begin()));
127 splitPasswdEntry(userString); 128 splitPasswdEntry(userString);
128 } 129 }
129 return true; 130 return true;
130} 131}
131 132
132bool Passwd::findUser(const char *username) { 133bool Passwd::findUser(const char *username) {
133 QRegExp userRegExp(QString("^%1\\:").arg(username)); 134 QRegExp userRegExp(QString("^%1\\:").arg(username));
134 return searchUser(userRegExp); 135 return searchUser(userRegExp);
135} 136}
136 137
137bool Passwd::findUser(int uid) { 138bool Passwd::findUser(int uid) {
138 QRegExp userRegExp(QString(":%1\\:").arg(uid)); 139 QRegExp userRegExp(QString(":%1\\:").arg(uid));
139 return searchUser(userRegExp); 140 return searchUser(userRegExp);
140} 141}
141 142
142bool 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=true) { 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) {
143 QString tempString; 144 QString tempString;
144 if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid); 145 if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid);
145 pw_passwd = crypt(pw_passwd, crypt_make_salt()); 146 pw_passwd = crypt(pw_passwd, crypt_make_salt());
146 tempString=pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell; 147 tempString=pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell;
147 passwdStringList.append(tempString); 148 passwdStringList.append(tempString);
148 // Make home dir. 149 // Make home dir.
149 QDir d; 150 QDir d;
150 if(!(d.exists(pw_dir))) { 151 if(!(d.exists(pw_dir))) {
151 d.mkdir(pw_dir); 152 d.mkdir(pw_dir);
153 chown(pw_dir,pw_uid,pw_gid);
154 chmod(pw_dir,S_IRUSR|S_IWUSR|S_IXUSR);
152 } 155 }
153 return 1; 156 return 1;
154} 157}
155 158
156bool Passwd::updateUser(QString login) { 159bool Passwd::updateUser(QString login) {
157 QRegExp userRegExp(QString("^%1\\:").arg(login)); 160 QRegExp userRegExp(QString("^%1\\:").arg(login));
158 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { 161 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
159 if(userRegExp.find((*it),0)!=-1) { 162 if(userRegExp.find((*it),0)!=-1) {
160 *it=QString(pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell); 163 *it=QString(pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell);
161 return true; 164 return true;
162 } 165 }
163 } 166 }
164 return false; 167 return false;
165} 168}
166 169
167bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) { 170bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) {
168 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { 171 for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) {
169 if(userRegExp.find((*it),0)!=-1) { 172 if(userRegExp.find((*it),0)!=-1) {
170 splitPasswdEntry(*it); 173 splitPasswdEntry(*it);
171 if(delGroup) this->delGroup(pw_gid); 174 if(delGroup) this->delGroup(pw_gid);
172 passwdStringList.remove(it); 175 passwdStringList.remove(it);
173 return true; 176 return true;
174 } 177 }
175 } 178 }
176 return false; 179 return false;
177} 180}
178 181
179bool Passwd::delUser(const char *username, bool delGroup) { 182bool Passwd::delUser(const char *username, bool delGroup) {
180 QRegExp userRegExp(QString("^%1\\:").arg(username)); 183 QRegExp userRegExp(QString("^%1\\:").arg(username));
181 return deleteUser(userRegExp,delGroup); 184 return deleteUser(userRegExp,delGroup);
182} 185}
183 186
184bool Passwd::delUser(int uid, bool delGroup) { 187bool Passwd::delUser(int uid, bool delGroup) {
185 QRegExp userRegExp(QString(":%1\\:").arg(uid)); 188 QRegExp userRegExp(QString(":%1\\:").arg(uid));
186 return deleteUser(userRegExp,delGroup); 189 return deleteUser(userRegExp,delGroup);
187} 190}
188 191
189bool Passwd::searchGroup(QRegExp &groupRegExp) { 192bool Passwd::searchGroup(QRegExp &groupRegExp) {
190 QStringList tempStringList(groupStringList.grep(groupRegExp)); 193 QStringList tempStringList(groupStringList.grep(groupRegExp));
191 if((tempStringList.isEmpty())) { 194 if((tempStringList.isEmpty())) {
192 return false; 195 return false;
193 } else { 196 } else {
194 groupString=(*(tempStringList.begin())); 197 groupString=(*(tempStringList.begin()));
195 splitGroupEntry(groupString); 198 splitGroupEntry(groupString);
196 } 199 }
197 return true; 200 return true;
198} 201}
199 202
200bool Passwd::findGroup(const char *groupname) { 203bool Passwd::findGroup(const char *groupname) {
201 QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); 204 QRegExp groupRegExp(QString("^%1\\:").arg(groupname));
202 return searchGroup(groupRegExp); 205 return searchGroup(groupRegExp);
203} 206}
204 207
205bool Passwd::findGroup(int gid) { 208bool Passwd::findGroup(int gid) {
206 QRegExp groupRegExp(QString(":%1\\:").arg(gid)); 209 QRegExp groupRegExp(QString(":%1\\:").arg(gid));
207 return searchGroup(groupRegExp); 210 return searchGroup(groupRegExp);
208} 211}
209 212
210bool Passwd::addGroup(QString gr_name, int gr_gid) { 213bool Passwd::addGroup(QString gr_name, int gr_gid) {
211 QString tempString; 214 QString tempString;
212 tempString=gr_name+":*:"+QString::number(gr_gid)+":"; 215 tempString=gr_name+":*:"+QString::number(gr_gid)+":";
213 groupStringList.append(tempString); 216 groupStringList.append(tempString);
214 return 1; 217 return 1;
215} 218}
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp
index f31775d..6940a3b 100644
--- a/noncore/settings/usermanager/userdialog.cpp
+++ b/noncore/settings/usermanager/userdialog.cpp
@@ -1,221 +1,223 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10#include "userdialog.h" 10#include "userdialog.h"
11 11
12#include <qlayout.h> 12#include <qlayout.h>
13#include <qlabel.h> 13#include <qlabel.h>
14#include <qmessagebox.h> 14#include <qmessagebox.h>
15 15
16#include <stdlib.h> 16#include <stdlib.h>
17 17
18#include <stdio.h> 18#include <stdio.h>
19#include <sys/types.h> 19#include <sys/types.h>
20#include <sys/wait.h> 20#include <sys/wait.h>
21#include <unistd.h> 21#include <unistd.h>
22#include <signal.h> 22#include <signal.h>
23 23
24#include "passwd.h" 24#include "passwd.h"
25 25
26/** 26/**
27 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups. 27 * UserDialog constructor. Setup the dialog, fill the groupComboBox & groupsListView with all groups.
28 * 28 *
29 */ 29 */
30UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { 30UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) {
31 QVBoxLayout *layout = new QVBoxLayout(this); 31 QVBoxLayout *layout = new QVBoxLayout(this);
32 myTabWidget=new QTabWidget(this,"User Tab Widget"); 32 myTabWidget=new QTabWidget(this,"User Tab Widget");
33 layout->addWidget(myTabWidget); 33 layout->addWidget(myTabWidget);
34 setupTab1(); 34 setupTab1();
35 setupTab2(); 35 setupTab2();
36 36
37 // And also fill the listview & the combobox with all available groups. 37 // And also fill the listview & the combobox with all available groups.
38 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { 38 for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) {
39 accounts->splitGroupEntry(*it); 39 accounts->splitGroupEntry(*it);
40 new QListViewItem(groupsListView,accounts->gr_name); 40 //new QListViewItem(groupsListView,accounts->gr_name);
41 new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox);
41 groupComboBox->insertItem(accounts->gr_name); 42 groupComboBox->insertItem(accounts->gr_name);
42 } 43 }
43 44
44 showMaximized(); 45 showMaximized();
45} 46}
46 47
47/** 48/**
48 * Empty destructor. 49 * Empty destructor.
49 * 50 *
50 */ 51 */
51UserDialog::~UserDialog() { 52UserDialog::~UserDialog() {
52} 53}
53 54
54/** 55/**
55 * Creates the first tab, all userinfo is here. 56 * Creates the first tab, all userinfo is here.
56 * 57 *
57 */ 58 */
58void UserDialog::setupTab1() { 59void UserDialog::setupTab1() {
59 QPixmap mypixmap; 60 QPixmap mypixmap;
60 QWidget *tabpage = new QWidget(myTabWidget,"page1"); 61 QWidget *tabpage = new QWidget(myTabWidget,"page1");
61 QVBoxLayout *layout = new QVBoxLayout(tabpage); 62 QVBoxLayout *layout = new QVBoxLayout(tabpage);
62 layout->setMargin(5); 63 layout->setMargin(5);
63 64
64 // Picture 65 // Picture
65 picturePushButton = new QPushButton(tabpage,"Label"); 66 picturePushButton = new QPushButton(tabpage,"Label");
66 picturePushButton->setMinimumSize(48,48); 67 picturePushButton->setMinimumSize(48,48);
67 picturePushButton->setMaximumSize(48,48); 68 picturePushButton->setMaximumSize(48,48);
68 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. 69 picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon.
69 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. 70 connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector.
70 71
71 // Login 72 // Login
72 QLabel *loginLabel=new QLabel(tabpage,"Login: "); 73 QLabel *loginLabel=new QLabel(tabpage,"Login: ");
73 loginLabel->setText("Login: "); 74 loginLabel->setText("Login: ");
74 loginLineEdit=new QLineEdit(tabpage,"Login: "); 75 loginLineEdit=new QLineEdit(tabpage,"Login: ");
75 76
76 // UID 77 // UID
77 QLabel *uidLabel=new QLabel(tabpage,"uid: "); 78 QLabel *uidLabel=new QLabel(tabpage,"uid: ");
78 uidLabel->setText("UserID: "); 79 uidLabel->setText("UserID: ");
79 uidLineEdit=new QLineEdit(tabpage,"uid: "); 80 uidLineEdit=new QLineEdit(tabpage,"uid: ");
80 uidLineEdit->setEnabled(false); 81 uidLineEdit->setEnabled(false);
81 82
82 // Username (gecos) 83 // Username (gecos)
83 QLabel *gecosLabel=new QLabel(tabpage,"gecos"); 84 QLabel *gecosLabel=new QLabel(tabpage,"gecos");
84 gecosLabel->setText("Username: "); 85 gecosLabel->setText("Username: ");
85 gecosLineEdit=new QLineEdit(tabpage,"gecos"); 86 gecosLineEdit=new QLineEdit(tabpage,"gecos");
86 87
87 // Password 88 // Password
88 QLabel *passwordLabel=new QLabel(tabpage,"password"); 89 QLabel *passwordLabel=new QLabel(tabpage,"password");
89 passwordLabel->setText("Password: "); 90 passwordLabel->setText("Password: ");
90 passwordLineEdit=new QLineEdit(tabpage,"password"); 91 passwordLineEdit=new QLineEdit(tabpage,"password");
91 passwordLineEdit->setEchoMode(QLineEdit::Password); 92 passwordLineEdit->setEchoMode(QLineEdit::Password);
92 93
93 // Shell 94 // Shell
94 QLabel *shellLabel=new QLabel(tabpage,"shell"); 95 QLabel *shellLabel=new QLabel(tabpage,"shell");
95 shellLabel->setText("Shell: "); 96 shellLabel->setText("Shell: ");
96 shellComboBox=new QComboBox(tabpage,"shell"); 97 shellComboBox=new QComboBox(tabpage,"shell");
97 shellComboBox->setEditable(true); 98 shellComboBox->setEditable(true);
98 shellComboBox->insertItem("/bin/sh"); 99 shellComboBox->insertItem("/bin/sh");
99 shellComboBox->insertItem("/bin/ash"); 100 shellComboBox->insertItem("/bin/ash");
100 shellComboBox->insertItem("/bin/false"); 101 shellComboBox->insertItem("/bin/false");
101 102
102 // Primary Group 103 // Primary Group
103 QLabel *groupLabel=new QLabel(tabpage,"group"); 104 QLabel *groupLabel=new QLabel(tabpage,"group");
104 groupLabel->setText("Primary group: "); 105 groupLabel->setText("Primary group: ");
105 groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); 106 groupComboBox=new QComboBox(tabpage,"PrimaryGroup");
106 107
107 // Widget layout 108 // Widget layout
108 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); 109 QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout");
109 layout->addWidget(picturePushButton); 110 layout->addWidget(picturePushButton);
110 layout->addSpacing(5); 111 layout->addSpacing(5);
111 layout->addLayout(hlayout); 112 layout->addLayout(hlayout);
112 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); 113 QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1");
113 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); 114 QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2");
114 // First column, labels 115 // First column, labels
115 vlayout1->addWidget(loginLabel); 116 vlayout1->addWidget(loginLabel);
116 vlayout1->addSpacing(5); 117 vlayout1->addSpacing(5);
117 vlayout1->addWidget(uidLabel); 118 vlayout1->addWidget(uidLabel);
118 vlayout1->addSpacing(5); 119 vlayout1->addSpacing(5);
119 vlayout1->addWidget(gecosLabel); 120 vlayout1->addWidget(gecosLabel);
120 vlayout1->addSpacing(5); 121 vlayout1->addSpacing(5);
121 vlayout1->addWidget(passwordLabel); 122 vlayout1->addWidget(passwordLabel);
122 vlayout1->addSpacing(5); 123 vlayout1->addSpacing(5);
123 vlayout1->addWidget(shellLabel); 124 vlayout1->addWidget(shellLabel);
124 vlayout1->addSpacing(5); 125 vlayout1->addSpacing(5);
125 vlayout1->addWidget(groupLabel); 126 vlayout1->addWidget(groupLabel);
126 // Second column, data 127 // Second column, data
127 vlayout2->addWidget(loginLineEdit); 128 vlayout2->addWidget(loginLineEdit);
128 vlayout2->addSpacing(5); 129 vlayout2->addSpacing(5);
129 vlayout2->addWidget(uidLineEdit); 130 vlayout2->addWidget(uidLineEdit);
130 vlayout2->addSpacing(5); 131 vlayout2->addSpacing(5);
131 vlayout2->addWidget(gecosLineEdit); 132 vlayout2->addWidget(gecosLineEdit);
132 vlayout2->addSpacing(5); 133 vlayout2->addSpacing(5);
133 vlayout2->addWidget(passwordLineEdit); 134 vlayout2->addWidget(passwordLineEdit);
134 vlayout2->addSpacing(5); 135 vlayout2->addSpacing(5);
135 vlayout2->addWidget(shellComboBox); 136 vlayout2->addWidget(shellComboBox);
136 vlayout2->addSpacing(5); 137 vlayout2->addSpacing(5);
137 vlayout2->addWidget(groupComboBox); 138 vlayout2->addWidget(groupComboBox);
138 hlayout->addLayout(vlayout1); 139 hlayout->addLayout(vlayout1);
139 hlayout->addLayout(vlayout2); 140 hlayout->addLayout(vlayout2);
140 141
141 myTabWidget->addTab(tabpage,"User Info"); 142 myTabWidget->addTab(tabpage,"User Info");
142} 143}
143 144
144/** 145/**
145 * Creates the second tab containing additional groups for the user. 146 * Creates the second tab containing additional groups for the user.
146 * 147 *
147 */ 148 */
148void UserDialog::setupTab2() { 149void UserDialog::setupTab2() {
149 QWidget *tabpage = new QWidget(myTabWidget,"page2"); 150 QWidget *tabpage = new QWidget(myTabWidget,"page2");
150 QVBoxLayout *layout = new QVBoxLayout(tabpage); 151 QVBoxLayout *layout = new QVBoxLayout(tabpage);
151 layout->setMargin(5); 152 layout->setMargin(5);
152 153
153 // Additional groups 154 // Additional groups
154 groupsListView=new QListView(tabpage,"groups"); 155 groupsListView=new QListView(tabpage,"groups");
155 groupsListView->addColumn("Additional groups"); 156 groupsListView->addColumn("Additional groups");
156 groupsListView->setColumnWidthMode(0,QListView::Maximum); 157 groupsListView->setColumnWidthMode(0,QListView::Maximum);
157 groupsListView->setMultiSelection(true); 158 groupsListView->setMultiSelection(true);
159 groupsListView->setAllColumnsShowFocus(false);
158 160
159 layout->addSpacing(5); 161 layout->addSpacing(5);
160 // Grouplist 162 // Grouplist
161 layout->addWidget(groupsListView); 163 layout->addWidget(groupsListView);
162 164
163 myTabWidget->addTab(tabpage,"User Groups"); 165 myTabWidget->addTab(tabpage,"User Groups");
164} 166}
165 167
166/** 168/**
167 * Static function that creates the userinfo dialog. 169 * Static function that creates the userinfo dialog.
168 * The user will be prompted to add a user. 170 * The user will be prompted to add a user.
169 * 171 *
170 * @param uid This is a suggested available UID. 172 * @param uid This is a suggested available UID.
171 * @param gid This is a suggested available GID. 173 * @param gid This is a suggested available GID.
172 * 174 *
173 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. 175 * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>.
174 * 176 *
175 */ 177 */
176bool UserDialog::addUser(int uid, int gid) { 178bool UserDialog::addUser(int uid, int gid) {
177 UserDialog *adduserDialog=new UserDialog(); 179 UserDialog *adduserDialog=new UserDialog();
178 adduserDialog->setCaption(tr("Add User")); 180 adduserDialog->setCaption(tr("Add User"));
179 adduserDialog->userID=uid;// Set next available UID as default uid. 181 adduserDialog->userID=uid;// Set next available UID as default uid.
180 adduserDialog->groupID=gid;// Set next available GID as default gid. 182 adduserDialog->groupID=gid;// Set next available GID as default gid.
181 // Insert default group into groupComboBox 183 // Insert default group into groupComboBox
182 adduserDialog->groupComboBox->insertItem("<create new group>",0); 184 adduserDialog->groupComboBox->insertItem("<create new group>",0);
183 adduserDialog->uidLineEdit->setText(QString::number(uid)); 185 adduserDialog->uidLineEdit->setText(QString::number(uid));
184 // Show the dialog! 186 // Show the dialog!
185 if(!(adduserDialog->exec())) return false; 187 if(!(adduserDialog->exec())) return false;
186 if((adduserDialog->groupComboBox->currentItem()!=0)) { 188 if((adduserDialog->groupComboBox->currentItem()!=0)) {
187 accounts->findGroup(adduserDialog->groupComboBox->currentText()); 189 accounts->findGroup(adduserDialog->groupComboBox->currentText());
188 adduserDialog->groupID=accounts->gr_gid; 190 adduserDialog->groupID=accounts->gr_gid;
189 qWarning(QString::number(accounts->gr_gid)); 191 qWarning(QString::number(accounts->gr_gid));
190 } 192 }
191 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), 193 if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(),
192 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), 194 adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(),
193 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { 195 QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) {
194 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); 196 QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user.");
195 return false; 197 return false;
196 } 198 }
197 199
198 // Add User to additional groups. 200 // Add User to additional groups.
199 QListViewItemIterator it( adduserDialog->groupsListView ); 201 QListViewItemIterator it( adduserDialog->groupsListView );
200 for ( ; it.current(); ++it ) { 202 for ( ; it.current(); ++it ) {
201 if ( it.current()->isSelected() ) 203 if ( it.current()->isSelected() )
202 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); 204 accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text());
203 } 205 }
204 return true; 206 return true;
205} 207}
206 208
207/** 209/**
208 * Deletes the user account. 210 * Deletes the user account.
209 * 211 *
210 * @param username User to be deleted. 212 * @param username User to be deleted.
211 * 213 *
212 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. 214 * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>.
213 * 215 *
214 */ 216 */
215bool UserDialog::delUser(const char *username) { 217bool UserDialog::delUser(const char *username) {
216 if((accounts->findUser(username))) {// Does that user exist? 218 if((accounts->findUser(username))) {// Does that user exist?
217 if(!(accounts->delUser(username))) {// Delete the user. 219 if(!(accounts->delUser(username))) {// Delete the user.
218 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); 220 QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+".");
219 } 221 }
220 } else { 222 } else {
221 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); 223 QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist.");
@@ -254,66 +256,70 @@ bool UserDialog::editUser(const char *username) {
254 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { 256 if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) {
255 edituserDialog->groupComboBox->setCurrentItem(i); 257 edituserDialog->groupComboBox->setCurrentItem(i);
256 } 258 }
257 } 259 }
258 // Select the groups in the listview, to which the user belongs. 260 // Select the groups in the listview, to which the user belongs.
259 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); 261 QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username));
260 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. 262 QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of.
261 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. 263 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them.
262 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. 264 QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups.
263 for ( ; lvit.current(); ++lvit ) { 265 for ( ; lvit.current(); ++lvit ) {
264 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { 266 if(lvit.current()->text(0)==(*it).left((*it).find(":"))) {
265 lvit.current()->setSelected(true);// If we find a line with that groupname, select it.; 267 lvit.current()->setSelected(true);// If we find a line with that groupname, select it.;
266 } 268 }
267 } 269 }
268 } 270 }
269 271
270 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! 272 if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG!
271 273
272 accounts->findUser(username);// Fill user variables in 'acccounts' object. 274 accounts->findUser(username);// Fill user variables in 'acccounts' object.
273 accounts->pw_name=edituserDialog->loginLineEdit->text(); 275 accounts->pw_name=edituserDialog->loginLineEdit->text();
274 // Has the password been changed ? Make a new "crypt":ed password. 276 // Has the password been changed ? Make a new "crypt":ed password.
275 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); 277 if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt());
276 278
277 // Set all variables in accounts object, that will be used when calling 'updateUser()' 279 // Set all variables in accounts object, that will be used when calling 'updateUser()'
278 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); 280 accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt();
279 accounts->findGroup(edituserDialog->groupComboBox->currentText());// Fill all group variables in 'accounts' object. 281 accounts->findGroup(edituserDialog->groupComboBox->currentText());// Fill all group variables in 'accounts' object.
280 accounts->pw_gid=accounts->gr_gid; 282 accounts->pw_gid=accounts->gr_gid;
281 accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); 283 accounts->pw_gecos=edituserDialog->gecosLineEdit->text();
282 accounts->pw_shell=edituserDialog->shellComboBox->currentText(); 284 accounts->pw_shell=edituserDialog->shellComboBox->currentText();
283 // Update userinfo, using the information stored in the user variables stored in the accounts object. 285 // Update userinfo, using the information stored in the user variables stored in the accounts object.
284 accounts->updateUser(username); 286 accounts->updateUser(username);
285 287
286 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) 288 // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.)
287 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { 289 for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {
288 accounts->delGroupMember((*it).left((*it).find(":")),username); 290 accounts->delGroupMember((*it).left((*it).find(":")),username);
289 } 291 }
290 292
291 // Add User to additional groups that he/she is a member of. 293 // Add User to additional groups that he/she is a member of.
292 QListViewItemIterator it( edituserDialog->groupsListView ); 294 QListViewItemIterator it( edituserDialog->groupsListView );
293 for ( ; it.current(); ++it ) { 295 for ( ; it.current(); ++it ) {
294 if ( it.current()->isSelected() ) 296 if ( it.current()->isSelected() )
295 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); 297 accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text());
296 } 298 }
297 return true; 299 return true;
298} 300}
299 301
300/** 302/**
301 * "OK" has been clicked. Verify some information before closing the dialog. 303 * "OK" has been clicked. Verify some information before closing the dialog.
302 * 304 *
303 */ 305 */
304void UserDialog::accept() { 306void UserDialog::accept() {
305 // Add checking... valid username? username taken? 307 // Add checking... valid username? username taken?
306 if(loginLineEdit->text().isEmpty()) { 308 if(loginLineEdit->text().isEmpty()) {
307 QMessageBox::information(0,"Empty Login","Please enter a login."); 309 QMessageBox::information(0,"Empty Login","Please enter a login.");
308 return; 310 return;
309 } 311 }
310 QDialog::accept(); 312 QDialog::accept();
311} 313}
312 314
313/** 315/**
314 * This slot is called when the usericon is clicked, this loads (should) the iconselector. 316 * This slot is called when the usericon is clicked, this loads (should) the iconselector.
315 * 317 *
316 */ 318 */
317void UserDialog::clickedPicture() { 319void UserDialog::clickedPicture() {
318 QMessageBox::information(0,"Sorry!","Icon selection not yet implemented.\nComming real soon now! (tm)"); 320 QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics");
321 // OFileDialog *fd=new OFileDialog("Select Icon",this, OFileSelector::OPEN, OFileSelector::EXTENDED,"/");
322 //fd->showMaximized();
323 //fd->exec();
324 QMessageBox::information(0,"Sorry!","Icon selection not yet implemented.\nComming real soon now! (tm)\n"+filename);
319} 325}
diff --git a/noncore/settings/usermanager/userdialog.h b/noncore/settings/usermanager/userdialog.h
index b44de9e..df54269 100644
--- a/noncore/settings/usermanager/userdialog.h
+++ b/noncore/settings/usermanager/userdialog.h
@@ -1,55 +1,57 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9#ifndef USERDIALOG_H 9#ifndef USERDIALOG_H
10#define USERDIALOG_H 10#define USERDIALOG_H
11 11
12#include <qdialog.h> 12#include <qdialog.h>
13#include <qlineedit.h> 13#include <qlineedit.h>
14#include <qcombobox.h> 14#include <qcombobox.h>
15#include <qlistview.h> 15#include <qlistview.h>
16#include <qtabwidget.h> 16#include <qtabwidget.h>
17#include <qpushbutton.h> 17#include <qpushbutton.h>
18 18
19#include <qpe/resource.h> 19#include <qpe/resource.h>
20 20
21#include <opie/ofiledialog.h>
22
21class UserDialog : public QDialog 23class UserDialog : public QDialog
22{ 24{
23 Q_OBJECT 25 Q_OBJECT
24private: 26private:
25 QTabWidget *myTabWidget; 27 QTabWidget *myTabWidget;
26 QPushButton *picturePushButton; 28 QPushButton *picturePushButton;
27 QLineEdit *loginLineEdit; 29 QLineEdit *loginLineEdit;
28 QLineEdit *uidLineEdit; 30 QLineEdit *uidLineEdit;
29 QLineEdit *gecosLineEdit; 31 QLineEdit *gecosLineEdit;
30 QLineEdit *passwordLineEdit; 32 QLineEdit *passwordLineEdit;
31 QComboBox *shellComboBox; 33 QComboBox *shellComboBox;
32 QComboBox *groupComboBox; 34 QComboBox *groupComboBox;
33 QListView *groupsListView; 35 QListView *groupsListView;
34 36
35 QStringList groupMembers; 37 QStringList groupMembers;
36 QString pictureLocation; 38 QString pictureLocation;
37 int groupID; 39 int groupID;
38 int userID; 40 int userID;
39 41
40 void setupTab1(void); 42 void setupTab1(void);
41 void setupTab2(void); 43 void setupTab2(void);
42 void accept(void); 44 void accept(void);
43 45
44private slots: 46private slots:
45 void clickedPicture(void); 47 void clickedPicture(void);
46 48
47public: 49public:
48 UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); 50 UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 );
49 ~UserDialog(); 51 ~UserDialog();
50 static bool addUser(int uid, int gid); 52 static bool addUser(int uid, int gid);
51 static bool editUser(const char *username); 53 static bool editUser(const char *username);
52 static bool delUser(const char *username); 54 static bool delUser(const char *username);
53}; 55};
54 56
55#endif 57#endif
diff --git a/noncore/settings/usermanager/usermanager.pro b/noncore/settings/usermanager/usermanager.pro
index fc45f93..2f3212f 100644
--- a/noncore/settings/usermanager/usermanager.pro
+++ b/noncore/settings/usermanager/usermanager.pro
@@ -1,10 +1,10 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 #CONFIG = qt warn_on debug 2 #CONFIG = qt warn_on debug
3 CONFIG = qt warn_on release 3 CONFIG = qt warn_on release
4 HEADERS = usermanager.h userdialog.h groupdialog.h passwd.h 4 HEADERS = usermanager.h userdialog.h groupdialog.h passwd.h
5 SOURCES = usermanager.cpp userdialog.cpp groupdialog.cpp passwd.h main.cpp 5 SOURCES = usermanager.cpp userdialog.cpp groupdialog.cpp passwd.h main.cpp
6 INCLUDEPATH+= $(OPIEDIR)/include 6 INCLUDEPATH+= $(OPIEDIR)/include
7 DEPENDPATH+= $(OPIEDIR)/include 7 DEPENDPATH+= $(OPIEDIR)/include
8LIBS += -lqpe -lcrypt 8LIBS += -lqpe -lopie -lcrypt
9 TARGET = usermanager 9 TARGET = usermanager
10DESTDIR = $(OPIEDIR)/bin 10DESTDIR = $(OPIEDIR)/bin