Diffstat (limited to 'noncore/settings/usermanager/userdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
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 | |||
@@ -1,247 +1,253 @@ | |||
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 | #include <qfile.h> | 15 | #include <qfile.h> |
16 | 16 | ||
17 | #include <stdlib.h> | 17 | #include <stdlib.h> |
18 | 18 | ||
19 | #include <stdio.h> | 19 | #include <stdio.h> |
20 | #include <sys/types.h> | 20 | #include <sys/types.h> |
21 | #include <sys/wait.h> | 21 | #include <sys/wait.h> |
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #include <signal.h> | 23 | #include <signal.h> |
24 | 24 | ||
25 | #include "passwd.h" | 25 | #include "passwd.h" |
26 | 26 | ||
27 | #include <opie/odevice.h> | 27 | #include <opie/odevice.h> |
28 | using namespace Opie; | 28 | using namespace Opie; |
29 | 29 | ||
30 | 30 | ||
31 | /** | 31 | /** |
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 | */ |
35 | UserDialog::UserDialog(QWidget* parent, const char* name, bool modal, WFlags fl) : QDialog(parent, name, modal, fl) { | 35 | UserDialog::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); |
39 | setupTab1(); | 40 | setupTab1(); |
40 | setupTab2(); | 41 | setupTab2(); |
41 | 42 | ||
42 | accounts->groupStringList.sort(); | 43 | accounts->groupStringList.sort(); |
43 | // And also fill the listview & the combobox with all available groups. | 44 | // And also fill the listview & the combobox with all available groups. |
44 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { | 45 | for( QStringList::Iterator it = accounts->groupStringList.begin(); it!=accounts->groupStringList.end(); ++it) { |
45 | accounts->splitGroupEntry(*it); | 46 | accounts->splitGroupEntry(*it); |
46 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); | 47 | new QCheckListItem(groupsListView,accounts->gr_name,QCheckListItem::CheckBox); |
47 | groupComboBox->insertItem(accounts->gr_name); | 48 | groupComboBox->insertItem(accounts->gr_name); |
48 | } | 49 | } |
49 | showMaximized(); | 50 | showMaximized(); |
50 | } | 51 | } |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * Empty destructor. | 54 | * Empty destructor. |
54 | * | 55 | * |
55 | */ | 56 | */ |
56 | UserDialog::~UserDialog() { | 57 | UserDialog::~UserDialog() { |
57 | } | 58 | } |
58 | 59 | ||
59 | /** | 60 | /** |
60 | * Creates the first tab, all userinfo is here. | 61 | * Creates the first tab, all userinfo is here. |
61 | * | 62 | * |
62 | */ | 63 | */ |
63 | void UserDialog::setupTab1() { | 64 | void UserDialog::setupTab1() { |
64 | QPixmap mypixmap; | 65 | QPixmap mypixmap; |
65 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); | 66 | QWidget *tabpage = new QWidget(myTabWidget,"page1"); |
66 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 67 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
67 | layout->setMargin(5); | 68 | layout->setMargin(5); |
68 | 69 | ||
69 | // Picture | 70 | // Picture |
70 | picturePushButton = new QPushButton(tabpage,"Label"); | 71 | picturePushButton = new QPushButton(tabpage,"Label"); |
71 | picturePushButton->setMinimumSize(48,48); | 72 | picturePushButton->setMinimumSize(48,48); |
72 | picturePushButton->setMaximumSize(48,48); | 73 | picturePushButton->setMaximumSize(48,48); |
73 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. | 74 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. |
74 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. | 75 | connect(picturePushButton,SIGNAL(clicked()),this,SLOT(clickedPicture()));// Clicking the picture should invoke pictureselector. |
75 | 76 | ||
76 | // Login | 77 | // Login |
77 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); | 78 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); |
78 | loginLabel->setText("Login: "); | 79 | loginLabel->setText("Login: "); |
79 | loginLineEdit=new QLineEdit(tabpage,"Login: "); | 80 | loginLineEdit=new QLineEdit(tabpage,"Login: "); |
80 | 81 | ||
81 | // UID | 82 | // UID |
82 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); | 83 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); |
83 | uidLabel->setText("UserID: "); | 84 | uidLabel->setText("UserID: "); |
84 | uidLineEdit=new QLineEdit(tabpage,"uid: "); | 85 | uidLineEdit=new QLineEdit(tabpage,"uid: "); |
85 | uidLineEdit->setEnabled(false); | 86 | uidLineEdit->setEnabled(false); |
86 | 87 | ||
87 | // Username (gecos) | 88 | // Username (gecos) |
88 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); | 89 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); |
89 | gecosLabel->setText("Username: "); | 90 | gecosLabel->setText("Username: "); |
90 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); | 91 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); |
91 | 92 | ||
92 | // Password | 93 | // Password |
93 | QLabel *passwordLabel=new QLabel(tabpage,"password"); | 94 | QLabel *passwordLabel=new QLabel(tabpage,"password"); |
94 | passwordLabel->setText("Password: "); | 95 | passwordLabel->setText("Password: "); |
95 | passwordLineEdit=new QLineEdit(tabpage,"password"); | 96 | passwordLineEdit=new QLineEdit(tabpage,"password"); |
96 | passwordLineEdit->setEchoMode(QLineEdit::Password); | 97 | passwordLineEdit->setEchoMode(QLineEdit::Password); |
97 | 98 | ||
98 | // Shell | 99 | // Shell |
99 | QLabel *shellLabel=new QLabel(tabpage,"shell"); | 100 | QLabel *shellLabel=new QLabel(tabpage,"shell"); |
100 | shellLabel->setText("Shell: "); | 101 | shellLabel->setText("Shell: "); |
101 | shellComboBox=new QComboBox(tabpage,"shell"); | 102 | shellComboBox=new QComboBox(tabpage,"shell"); |
102 | shellComboBox->setEditable(true); | 103 | shellComboBox->setEditable(true); |
103 | shellComboBox->insertItem("/bin/sh"); | 104 | shellComboBox->insertItem("/bin/sh"); |
104 | shellComboBox->insertItem("/bin/ash"); | 105 | shellComboBox->insertItem("/bin/ash"); |
105 | shellComboBox->insertItem("/bin/false"); | 106 | shellComboBox->insertItem("/bin/false"); |
106 | 107 | ||
107 | // Primary Group | 108 | // Primary Group |
108 | QLabel *groupLabel=new QLabel(tabpage,"group"); | 109 | QLabel *groupLabel=new QLabel(tabpage,"group"); |
109 | groupLabel->setText("Primary group: "); | 110 | groupLabel->setText("Primary group: "); |
110 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); | 111 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); |
111 | 112 | ||
113 | if(vm==VIEWMODE_NEW) { | ||
112 | // Copy /etc/skel | 114 | // Copy /etc/skel |
113 | QLabel *skelLabel=new QLabel(tabpage,"skel"); | 115 | skelLabel=new QLabel(tabpage,"skel"); |
114 | skelLabel->setText("Copy /etc/skel: "); | 116 | skelLabel->setText("Copy /etc/skel: "); |
115 | skelCheckBox=new QCheckBox(tabpage); | 117 | skelCheckBox=new QCheckBox(tabpage); |
116 | skelCheckBox->setChecked(true); | 118 | skelCheckBox->setChecked(true); |
117 | //skelLabel->setDisabled(true); | 119 | } |
118 | //skelCheckBox->setDisabled(true); | ||
119 | 120 | ||
120 | // Widget layout | 121 | // Widget layout |
121 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | 122 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); |
122 | layout->addWidget(picturePushButton); | 123 | layout->addWidget(picturePushButton); |
123 | layout->addSpacing(5); | 124 | layout->addSpacing(5); |
124 | layout->addLayout(hlayout); | 125 | layout->addLayout(hlayout); |
125 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); | 126 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); |
126 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); | 127 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); |
127 | // First column, labels | 128 | // First column, labels |
128 | vlayout1->addWidget(loginLabel); | 129 | vlayout1->addWidget(loginLabel); |
129 | vlayout1->addSpacing(5); | 130 | vlayout1->addSpacing(5); |
130 | vlayout1->addWidget(uidLabel); | 131 | vlayout1->addWidget(uidLabel); |
131 | vlayout1->addSpacing(5); | 132 | vlayout1->addSpacing(5); |
132 | vlayout1->addWidget(gecosLabel); | 133 | vlayout1->addWidget(gecosLabel); |
133 | vlayout1->addSpacing(5); | 134 | vlayout1->addSpacing(5); |
134 | vlayout1->addWidget(passwordLabel); | 135 | vlayout1->addWidget(passwordLabel); |
135 | vlayout1->addSpacing(5); | 136 | vlayout1->addSpacing(5); |
136 | vlayout1->addWidget(shellLabel); | 137 | vlayout1->addWidget(shellLabel); |
137 | vlayout1->addSpacing(5); | 138 | vlayout1->addSpacing(5); |
138 | vlayout1->addWidget(groupLabel); | 139 | vlayout1->addWidget(groupLabel); |
140 | if(vm==VIEWMODE_NEW) { | ||
139 | vlayout1->addSpacing(5); | 141 | vlayout1->addSpacing(5); |
140 | vlayout1->addWidget(skelLabel); | 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); |
144 | vlayout2->addWidget(uidLineEdit); | 147 | vlayout2->addWidget(uidLineEdit); |
145 | vlayout2->addSpacing(5); | 148 | vlayout2->addSpacing(5); |
146 | vlayout2->addWidget(gecosLineEdit); | 149 | vlayout2->addWidget(gecosLineEdit); |
147 | vlayout2->addSpacing(5); | 150 | vlayout2->addSpacing(5); |
148 | vlayout2->addWidget(passwordLineEdit); | 151 | vlayout2->addWidget(passwordLineEdit); |
149 | vlayout2->addSpacing(5); | 152 | vlayout2->addSpacing(5); |
150 | vlayout2->addWidget(shellComboBox); | 153 | vlayout2->addWidget(shellComboBox); |
151 | vlayout2->addSpacing(5); | 154 | vlayout2->addSpacing(5); |
152 | vlayout2->addWidget(groupComboBox); | 155 | vlayout2->addWidget(groupComboBox); |
156 | if(vm==VIEWMODE_NEW) { | ||
153 | vlayout2->addSpacing(5); | 157 | vlayout2->addSpacing(5); |
154 | vlayout2->addWidget(skelCheckBox); | 158 | vlayout2->addWidget(skelCheckBox); |
159 | } | ||
155 | hlayout->addLayout(vlayout1); | 160 | hlayout->addLayout(vlayout1); |
156 | hlayout->addLayout(vlayout2); | 161 | hlayout->addLayout(vlayout2); |
157 | 162 | ||
158 | myTabWidget->addTab(tabpage,"User Info"); | 163 | myTabWidget->addTab(tabpage,"User Info"); |
159 | } | 164 | } |
160 | 165 | ||
161 | /** | 166 | /** |
162 | * Creates the second tab containing additional groups for the user. | 167 | * Creates the second tab containing additional groups for the user. |
163 | * | 168 | * |
164 | */ | 169 | */ |
165 | void UserDialog::setupTab2() { | 170 | void UserDialog::setupTab2() { |
166 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 171 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
167 | QVBoxLayout *layout = new QVBoxLayout(tabpage); | 172 | QVBoxLayout *layout = new QVBoxLayout(tabpage); |
168 | layout->setMargin(5); | 173 | layout->setMargin(5); |
169 | 174 | ||
170 | // Additional groups | 175 | // Additional groups |
171 | groupsListView=new QListView(tabpage,"groups"); | 176 | groupsListView=new QListView(tabpage,"groups"); |
172 | groupsListView->addColumn("Additional groups"); | 177 | groupsListView->addColumn("Additional groups"); |
173 | groupsListView->setColumnWidthMode(0,QListView::Maximum); | 178 | groupsListView->setColumnWidthMode(0,QListView::Maximum); |
174 | groupsListView->setMultiSelection(false); | 179 | groupsListView->setMultiSelection(false); |
175 | groupsListView->setAllColumnsShowFocus(false); | 180 | groupsListView->setAllColumnsShowFocus(false); |
176 | 181 | ||
177 | layout->addSpacing(5); | 182 | layout->addSpacing(5); |
178 | // Grouplist | 183 | // Grouplist |
179 | layout->addWidget(groupsListView); | 184 | layout->addWidget(groupsListView); |
180 | 185 | ||
181 | myTabWidget->addTab(tabpage,"User Groups"); | 186 | myTabWidget->addTab(tabpage,"User Groups"); |
182 | } | 187 | } |
183 | 188 | ||
184 | /** | 189 | /** |
185 | * Static function that creates the userinfo dialog. | 190 | * Static function that creates the userinfo dialog. |
186 | * The user will be prompted to add a user. | 191 | * The user will be prompted to add a user. |
187 | * | 192 | * |
188 | * @param uid This is a suggested available UID. | 193 | * @param uid This is a suggested available UID. |
189 | * @param gid This is a suggested available GID. | 194 | * @param gid This is a suggested available GID. |
190 | * | 195 | * |
191 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. | 196 | * @return <code>true</code> if the user was successfully added, otherwise <code>false</code>. |
192 | * | 197 | * |
193 | */ | 198 | */ |
194 | bool UserDialog::addUser(int uid, int gid) { | 199 | bool UserDialog::addUser(int uid, int gid) { |
195 | QCheckListItem *temp; | 200 | QCheckListItem *temp; |
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. |
203 | // Insert default group into groupComboBox | 209 | // Insert default group into groupComboBox |
204 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 210 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
205 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 211 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
206 | // If we're running on OZ, add new users to some default groups. | 212 | // If we're running on OZ, add new users to some default groups. |
207 | if(oz) { | 213 | if(oz) { |
208 | QListViewItemIterator iter( adduserDialog->groupsListView ); | 214 | QListViewItemIterator iter( adduserDialog->groupsListView ); |
209 | for ( ; iter.current(); ++iter ) { | 215 | for ( ; iter.current(); ++iter ) { |
210 | temp=(QCheckListItem*)iter.current(); | 216 | temp=(QCheckListItem*)iter.current(); |
211 | if (temp->text()=="video") temp->setOn(true); | 217 | if (temp->text()=="video") temp->setOn(true); |
212 | if (temp->text()=="audio") temp->setOn(true); | 218 | if (temp->text()=="audio") temp->setOn(true); |
213 | if (temp->text()=="time") temp->setOn(true); | 219 | if (temp->text()=="time") temp->setOn(true); |
214 | if (temp->text()=="power") temp->setOn(true); | 220 | if (temp->text()=="power") temp->setOn(true); |
215 | if (temp->text()=="input") temp->setOn(true); | 221 | if (temp->text()=="input") temp->setOn(true); |
216 | if (temp->text()=="sharp") temp->setOn(true); | 222 | if (temp->text()=="sharp") temp->setOn(true); |
217 | if (temp->text()=="tty") temp->setOn(true); | 223 | if (temp->text()=="tty") temp->setOn(true); |
218 | } | 224 | } |
219 | } | 225 | } |
220 | // Show the dialog! | 226 | // Show the dialog! |
221 | if(!(adduserDialog->exec())) return false; | 227 | if(!(adduserDialog->exec())) return false; |
222 | if((adduserDialog->groupComboBox->currentItem()!=0)) { | 228 | if((adduserDialog->groupComboBox->currentItem()!=0)) { |
223 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 229 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); |
224 | adduserDialog->groupID=accounts->gr_gid; | 230 | adduserDialog->groupID=accounts->gr_gid; |
225 | qWarning(QString::number(accounts->gr_gid)); | 231 | qWarning(QString::number(accounts->gr_gid)); |
226 | } | 232 | } |
227 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 233 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
228 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 234 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
229 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { | 235 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { |
230 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 236 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
231 | return false; | 237 | return false; |
232 | } | 238 | } |
233 | 239 | ||
234 | // Add User to additional groups. | 240 | // Add User to additional groups. |
235 | QListViewItemIterator it( adduserDialog->groupsListView ); | 241 | QListViewItemIterator it( adduserDialog->groupsListView ); |
236 | for ( ; it.current(); ++it ) { | 242 | for ( ; it.current(); ++it ) { |
237 | temp=(QCheckListItem*)it.current(); | 243 | temp=(QCheckListItem*)it.current(); |
238 | if (temp->isOn() ) | 244 | if (temp->isOn() ) |
239 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 245 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
240 | } | 246 | } |
241 | // Copy image to pics/users/ | 247 | // Copy image to pics/users/ |
242 | if(!(adduserDialog->userImage.isNull())) { | 248 | if(!(adduserDialog->userImage.isNull())) { |
243 | QDir d; | 249 | QDir d; |
244 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 250 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
245 | d.mkdir("/opt/QtPalmtop/pics/users"); | 251 | d.mkdir("/opt/QtPalmtop/pics/users"); |
246 | } | 252 | } |
247 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 253 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
@@ -253,97 +259,98 @@ bool UserDialog::addUser(int uid, int gid) { | |||
253 | accounts->findUser(adduserDialog->loginLineEdit->text()); | 259 | accounts->findUser(adduserDialog->loginLineEdit->text()); |
254 | if(adduserDialog->skelCheckBox->isChecked()) { | 260 | if(adduserDialog->skelCheckBox->isChecked()) { |
255 | QString command_cp; | 261 | QString command_cp; |
256 | QString command_chown; | 262 | QString command_chown; |
257 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); | 263 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); |
258 | system(command_cp); | 264 | system(command_cp); |
259 | 265 | ||
260 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround? | 266 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround? |
261 | system(command_cp); | 267 | system(command_cp); |
262 | 268 | ||
263 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); | 269 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); |
264 | system(command_chown); | 270 | system(command_chown); |
265 | } | 271 | } |
266 | 272 | ||
267 | return true; | 273 | return true; |
268 | } | 274 | } |
269 | 275 | ||
270 | /** | 276 | /** |
271 | * Deletes the user account. | 277 | * Deletes the user account. |
272 | * | 278 | * |
273 | * @param username User to be deleted. | 279 | * @param username User to be deleted. |
274 | * | 280 | * |
275 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 281 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
276 | * | 282 | * |
277 | */ | 283 | */ |
278 | bool UserDialog::delUser(const char *username) { | 284 | bool UserDialog::delUser(const char *username) { |
279 | if((accounts->findUser(username))) {// Does that user exist? | 285 | if((accounts->findUser(username))) {// Does that user exist? |
280 | if(!(accounts->delUser(username))) {// Delete the user. | 286 | if(!(accounts->delUser(username))) {// Delete the user. |
281 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); | 287 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); |
282 | } | 288 | } |
283 | } else { | 289 | } else { |
284 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); | 290 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); |
285 | return false; | 291 | return false; |
286 | } | 292 | } |
287 | return true; | 293 | return true; |
288 | } | 294 | } |
289 | 295 | ||
290 | /** | 296 | /** |
291 | * This displays a confirmation dialog wether a user should be deleted or not. | 297 | * This displays a confirmation dialog wether a user should be deleted or not. |
292 | * (And also deletes the account) | 298 | * (And also deletes the account) |
293 | * | 299 | * |
294 | * @param username User to be deleted. | 300 | * @param username User to be deleted. |
295 | * | 301 | * |
296 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 302 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
297 | * | 303 | * |
298 | */ | 304 | */ |
299 | bool UserDialog::editUser(const char *username) { | 305 | bool 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. |
305 | invalid_group=1; | 312 | invalid_group=1; |
306 | } | 313 | } |
307 | // Fill widgets with userinfo. | 314 | // Fill widgets with userinfo. |
308 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 315 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |
309 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); | 316 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); |
310 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); | 317 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); |
311 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. | 318 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. |
312 | edituserDialog->passwordLineEdit->setText("........"); | 319 | edituserDialog->passwordLineEdit->setText("........"); |
313 | // 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. |
314 | 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") { |
315 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); | 322 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); |
316 | edituserDialog->shellComboBox->setCurrentItem(0); | 323 | edituserDialog->shellComboBox->setCurrentItem(0); |
317 | } | 324 | } |
318 | // Select the primary group for this user. | 325 | // Select the primary group for this user. |
319 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { | 326 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { |
320 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { | 327 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { |
321 | edituserDialog->groupComboBox->setCurrentItem(i); | 328 | edituserDialog->groupComboBox->setCurrentItem(i); |
322 | break; | 329 | break; |
323 | } | 330 | } |
324 | } | 331 | } |
325 | if(invalid_group) { | 332 | if(invalid_group) { |
326 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); | 333 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); |
327 | edituserDialog->groupComboBox->setCurrentItem(0); | 334 | edituserDialog->groupComboBox->setCurrentItem(0); |
328 | } | 335 | } |
329 | // Select the groups in the listview, to which the user belongs. | 336 | // Select the groups in the listview, to which the user belongs. |
330 | QCheckListItem *temp; | 337 | QCheckListItem *temp; |
331 | QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); | 338 | QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); |
332 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. | 339 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. |
333 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. | 340 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. |
334 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 341 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. |
335 | for ( ; lvit.current(); ++lvit ) { | 342 | for ( ; lvit.current(); ++lvit ) { |
336 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { | 343 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { |
337 | temp=(QCheckListItem*)lvit.current(); | 344 | temp=(QCheckListItem*)lvit.current(); |
338 | temp->setOn(true);// If we find a line with that groupname, select it.; | 345 | temp->setOn(true);// If we find a line with that groupname, select it.; |
339 | } | 346 | } |
340 | } | 347 | } |
341 | } | 348 | } |
342 | 349 | ||
343 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! | 350 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! |
344 | 351 | ||
345 | accounts->findUser(username);// Fill user variables in 'acccounts' object. | 352 | accounts->findUser(username);// Fill user variables in 'acccounts' object. |
346 | accounts->pw_name=edituserDialog->loginLineEdit->text(); | 353 | accounts->pw_name=edituserDialog->loginLineEdit->text(); |
347 | // Has the password been changed ? Make a new "crypt":ed password. | 354 | // Has the password been changed ? Make a new "crypt":ed password. |
348 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); | 355 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); |
349 | 356 | ||