author | umopapisdn <umopapisdn> | 2002-10-14 21:58:41 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2002-10-14 21:58:41 (UTC) |
commit | 09ba6b7531801dde243469f05f5e5c31596cdd2d (patch) (unidiff) | |
tree | 07531378e9a05ff777dfb151276075b233bcb4d8 | |
parent | 14f450ead20011e5697bb36a4ad087cc648b439d (diff) | |
download | opie-09ba6b7531801dde243469f05f5e5c31596cdd2d.zip opie-09ba6b7531801dde243469f05f5e5c31596cdd2d.tar.gz opie-09ba6b7531801dde243469f05f5e5c31596cdd2d.tar.bz2 |
Support for a skeleton homedirectory in /etc/skel.
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index c43b391..42a9144 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -65,98 +65,98 @@ void UserDialog::setupTab1() { | |||
65 | // Picture | 65 | // Picture |
66 | picturePushButton = new QPushButton(tabpage,"Label"); | 66 | picturePushButton = new QPushButton(tabpage,"Label"); |
67 | picturePushButton->setMinimumSize(48,48); | 67 | picturePushButton->setMinimumSize(48,48); |
68 | picturePushButton->setMaximumSize(48,48); | 68 | picturePushButton->setMaximumSize(48,48); |
69 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. | 69 | picturePushButton->setPixmap(Resource::loadPixmap("usermanager/usericon"));// Load default usericon. |
70 | 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. |
71 | 71 | ||
72 | // Login | 72 | // Login |
73 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); | 73 | QLabel *loginLabel=new QLabel(tabpage,"Login: "); |
74 | loginLabel->setText("Login: "); | 74 | loginLabel->setText("Login: "); |
75 | loginLineEdit=new QLineEdit(tabpage,"Login: "); | 75 | loginLineEdit=new QLineEdit(tabpage,"Login: "); |
76 | 76 | ||
77 | // UID | 77 | // UID |
78 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); | 78 | QLabel *uidLabel=new QLabel(tabpage,"uid: "); |
79 | uidLabel->setText("UserID: "); | 79 | uidLabel->setText("UserID: "); |
80 | uidLineEdit=new QLineEdit(tabpage,"uid: "); | 80 | uidLineEdit=new QLineEdit(tabpage,"uid: "); |
81 | uidLineEdit->setEnabled(false); | 81 | uidLineEdit->setEnabled(false); |
82 | 82 | ||
83 | // Username (gecos) | 83 | // Username (gecos) |
84 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); | 84 | QLabel *gecosLabel=new QLabel(tabpage,"gecos"); |
85 | gecosLabel->setText("Username: "); | 85 | gecosLabel->setText("Username: "); |
86 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); | 86 | gecosLineEdit=new QLineEdit(tabpage,"gecos"); |
87 | 87 | ||
88 | // Password | 88 | // Password |
89 | QLabel *passwordLabel=new QLabel(tabpage,"password"); | 89 | QLabel *passwordLabel=new QLabel(tabpage,"password"); |
90 | passwordLabel->setText("Password: "); | 90 | passwordLabel->setText("Password: "); |
91 | passwordLineEdit=new QLineEdit(tabpage,"password"); | 91 | passwordLineEdit=new QLineEdit(tabpage,"password"); |
92 | passwordLineEdit->setEchoMode(QLineEdit::Password); | 92 | passwordLineEdit->setEchoMode(QLineEdit::Password); |
93 | 93 | ||
94 | // Shell | 94 | // Shell |
95 | QLabel *shellLabel=new QLabel(tabpage,"shell"); | 95 | QLabel *shellLabel=new QLabel(tabpage,"shell"); |
96 | shellLabel->setText("Shell: "); | 96 | shellLabel->setText("Shell: "); |
97 | shellComboBox=new QComboBox(tabpage,"shell"); | 97 | shellComboBox=new QComboBox(tabpage,"shell"); |
98 | shellComboBox->setEditable(true); | 98 | shellComboBox->setEditable(true); |
99 | shellComboBox->insertItem("/bin/sh"); | 99 | shellComboBox->insertItem("/bin/sh"); |
100 | shellComboBox->insertItem("/bin/ash"); | 100 | shellComboBox->insertItem("/bin/ash"); |
101 | shellComboBox->insertItem("/bin/false"); | 101 | shellComboBox->insertItem("/bin/false"); |
102 | 102 | ||
103 | // Primary Group | 103 | // Primary Group |
104 | QLabel *groupLabel=new QLabel(tabpage,"group"); | 104 | QLabel *groupLabel=new QLabel(tabpage,"group"); |
105 | groupLabel->setText("Primary group: "); | 105 | groupLabel->setText("Primary group: "); |
106 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); | 106 | groupComboBox=new QComboBox(tabpage,"PrimaryGroup"); |
107 | 107 | ||
108 | // Copy /etc/skel | 108 | // Copy /etc/skel |
109 | QLabel *skelLabel=new QLabel(tabpage,"skel"); | 109 | QLabel *skelLabel=new QLabel(tabpage,"skel"); |
110 | skelLabel->setText("Copy /etc/skel: "); | 110 | skelLabel->setText("Copy /etc/skel: "); |
111 | skelCheckBox=new QCheckBox(tabpage); | 111 | skelCheckBox=new QCheckBox(tabpage); |
112 | skelCheckBox->setChecked(true); | 112 | skelCheckBox->setChecked(true); |
113 | skelLabel->setDisabled(true); | 113 | //skelLabel->setDisabled(true); |
114 | skelCheckBox->setDisabled(true); | 114 | //skelCheckBox->setDisabled(true); |
115 | 115 | ||
116 | // Widget layout | 116 | // Widget layout |
117 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | 117 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); |
118 | layout->addWidget(picturePushButton); | 118 | layout->addWidget(picturePushButton); |
119 | layout->addSpacing(5); | 119 | layout->addSpacing(5); |
120 | layout->addLayout(hlayout); | 120 | layout->addLayout(hlayout); |
121 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); | 121 | QVBoxLayout *vlayout1=new QVBoxLayout(-1,"vlayout1"); |
122 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); | 122 | QVBoxLayout *vlayout2=new QVBoxLayout(-1,"vlayout2"); |
123 | // First column, labels | 123 | // First column, labels |
124 | vlayout1->addWidget(loginLabel); | 124 | vlayout1->addWidget(loginLabel); |
125 | vlayout1->addSpacing(5); | 125 | vlayout1->addSpacing(5); |
126 | vlayout1->addWidget(uidLabel); | 126 | vlayout1->addWidget(uidLabel); |
127 | vlayout1->addSpacing(5); | 127 | vlayout1->addSpacing(5); |
128 | vlayout1->addWidget(gecosLabel); | 128 | vlayout1->addWidget(gecosLabel); |
129 | vlayout1->addSpacing(5); | 129 | vlayout1->addSpacing(5); |
130 | vlayout1->addWidget(passwordLabel); | 130 | vlayout1->addWidget(passwordLabel); |
131 | vlayout1->addSpacing(5); | 131 | vlayout1->addSpacing(5); |
132 | vlayout1->addWidget(shellLabel); | 132 | vlayout1->addWidget(shellLabel); |
133 | vlayout1->addSpacing(5); | 133 | vlayout1->addSpacing(5); |
134 | vlayout1->addWidget(groupLabel); | 134 | vlayout1->addWidget(groupLabel); |
135 | vlayout1->addSpacing(5); | 135 | vlayout1->addSpacing(5); |
136 | vlayout1->addWidget(skelLabel); | 136 | vlayout1->addWidget(skelLabel); |
137 | // Second column, data | 137 | // Second column, data |
138 | vlayout2->addWidget(loginLineEdit); | 138 | vlayout2->addWidget(loginLineEdit); |
139 | vlayout2->addSpacing(5); | 139 | vlayout2->addSpacing(5); |
140 | vlayout2->addWidget(uidLineEdit); | 140 | vlayout2->addWidget(uidLineEdit); |
141 | vlayout2->addSpacing(5); | 141 | vlayout2->addSpacing(5); |
142 | vlayout2->addWidget(gecosLineEdit); | 142 | vlayout2->addWidget(gecosLineEdit); |
143 | vlayout2->addSpacing(5); | 143 | vlayout2->addSpacing(5); |
144 | vlayout2->addWidget(passwordLineEdit); | 144 | vlayout2->addWidget(passwordLineEdit); |
145 | vlayout2->addSpacing(5); | 145 | vlayout2->addSpacing(5); |
146 | vlayout2->addWidget(shellComboBox); | 146 | vlayout2->addWidget(shellComboBox); |
147 | vlayout2->addSpacing(5); | 147 | vlayout2->addSpacing(5); |
148 | vlayout2->addWidget(groupComboBox); | 148 | vlayout2->addWidget(groupComboBox); |
149 | vlayout2->addSpacing(5); | 149 | vlayout2->addSpacing(5); |
150 | vlayout2->addWidget(skelCheckBox); | 150 | vlayout2->addWidget(skelCheckBox); |
151 | hlayout->addLayout(vlayout1); | 151 | hlayout->addLayout(vlayout1); |
152 | hlayout->addLayout(vlayout2); | 152 | hlayout->addLayout(vlayout2); |
153 | 153 | ||
154 | myTabWidget->addTab(tabpage,"User Info"); | 154 | myTabWidget->addTab(tabpage,"User Info"); |
155 | } | 155 | } |
156 | 156 | ||
157 | /** | 157 | /** |
158 | * Creates the second tab containing additional groups for the user. | 158 | * Creates the second tab containing additional groups for the user. |
159 | * | 159 | * |
160 | */ | 160 | */ |
161 | void UserDialog::setupTab2() { | 161 | void UserDialog::setupTab2() { |
162 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); | 162 | QWidget *tabpage = new QWidget(myTabWidget,"page2"); |
@@ -198,96 +198,112 @@ bool UserDialog::addUser(int uid, int gid) { | |||
198 | // Insert default group into groupComboBox | 198 | // Insert default group into groupComboBox |
199 | adduserDialog->groupComboBox->insertItem("<create new group>",0); | 199 | adduserDialog->groupComboBox->insertItem("<create new group>",0); |
200 | adduserDialog->uidLineEdit->setText(QString::number(uid)); | 200 | adduserDialog->uidLineEdit->setText(QString::number(uid)); |
201 | // If we're running on OZ, add new users to some default groups. | 201 | // If we're running on OZ, add new users to some default groups. |
202 | if(oz) { | 202 | if(oz) { |
203 | QListViewItemIterator iter( adduserDialog->groupsListView ); | 203 | QListViewItemIterator iter( adduserDialog->groupsListView ); |
204 | for ( ; iter.current(); ++iter ) { | 204 | for ( ; iter.current(); ++iter ) { |
205 | temp=(QCheckListItem*)iter.current(); | 205 | temp=(QCheckListItem*)iter.current(); |
206 | if (temp->text()=="video") temp->setOn(true); | 206 | if (temp->text()=="video") temp->setOn(true); |
207 | if (temp->text()=="audio") temp->setOn(true); | 207 | if (temp->text()=="audio") temp->setOn(true); |
208 | if (temp->text()=="time") temp->setOn(true); | 208 | if (temp->text()=="time") temp->setOn(true); |
209 | if (temp->text()=="power") temp->setOn(true); | 209 | if (temp->text()=="power") temp->setOn(true); |
210 | if (temp->text()=="input") temp->setOn(true); | 210 | if (temp->text()=="input") temp->setOn(true); |
211 | if (temp->text()=="sharp") temp->setOn(true); | 211 | if (temp->text()=="sharp") temp->setOn(true); |
212 | if (temp->text()=="tty") temp->setOn(true); | 212 | if (temp->text()=="tty") temp->setOn(true); |
213 | } | 213 | } |
214 | } | 214 | } |
215 | // Show the dialog! | 215 | // Show the dialog! |
216 | if(!(adduserDialog->exec())) return false; | 216 | if(!(adduserDialog->exec())) return false; |
217 | if((adduserDialog->groupComboBox->currentItem()!=0)) { | 217 | if((adduserDialog->groupComboBox->currentItem()!=0)) { |
218 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); | 218 | accounts->findGroup(adduserDialog->groupComboBox->currentText()); |
219 | adduserDialog->groupID=accounts->gr_gid; | 219 | adduserDialog->groupID=accounts->gr_gid; |
220 | qWarning(QString::number(accounts->gr_gid)); | 220 | qWarning(QString::number(accounts->gr_gid)); |
221 | } | 221 | } |
222 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), | 222 | if(!(accounts->addUser(adduserDialog->loginLineEdit->text(), adduserDialog->passwordLineEdit->text(), |
223 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), | 223 | adduserDialog->uidLineEdit->text().toInt(), adduserDialog->groupID, adduserDialog->gecosLineEdit->text(), |
224 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { | 224 | QString("/home/")+adduserDialog->loginLineEdit->text() , adduserDialog->shellComboBox->currentText()))) { |
225 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); | 225 | QMessageBox::information(0,"Ooops!","Something went wrong!\nUnable to add user."); |
226 | return false; | 226 | return false; |
227 | } | 227 | } |
228 | 228 | ||
229 | // Add User to additional groups. | 229 | // Add User to additional groups. |
230 | QListViewItemIterator it( adduserDialog->groupsListView ); | 230 | QListViewItemIterator it( adduserDialog->groupsListView ); |
231 | for ( ; it.current(); ++it ) { | 231 | for ( ; it.current(); ++it ) { |
232 | temp=(QCheckListItem*)it.current(); | 232 | temp=(QCheckListItem*)it.current(); |
233 | if (temp->isOn() ) | 233 | if (temp->isOn() ) |
234 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 234 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
235 | } | 235 | } |
236 | // Copy image to pics/users/ | 236 | // Copy image to pics/users/ |
237 | if(!(adduserDialog->userImage.isNull())) { | 237 | if(!(adduserDialog->userImage.isNull())) { |
238 | QDir d; | 238 | QDir d; |
239 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 239 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
240 | d.mkdir("/opt/QtPalmtop/pics/users"); | 240 | d.mkdir("/opt/QtPalmtop/pics/users"); |
241 | } | 241 | } |
242 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 242 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
243 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 243 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
244 | adduserDialog->userImage.save(filename,"PNG"); | 244 | adduserDialog->userImage.save(filename,"PNG"); |
245 | } | 245 | } |
246 | |||
247 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? | ||
248 | accounts->findUser(adduserDialog->loginLineEdit->text()); | ||
249 | if(adduserDialog->skelCheckBox->isChecked()) { | ||
250 | QString command_cp; | ||
251 | QString command_chown; | ||
252 | command_cp.sprintf("cp -a /etc/skel/* %s/",accounts->pw_dir.latin1()); | ||
253 | system(command_cp); | ||
254 | |||
255 | command_cp.sprintf("cp -a /etc/skel/.[!.]* %s/",accounts->pw_dir.latin1());// Bug in busybox, ".*" includes parent directory, does this work as a workaround? | ||
256 | system(command_cp); | ||
257 | |||
258 | command_chown.sprintf("chown -R %d:%d %s",accounts->pw_uid,accounts->pw_gid,accounts->pw_dir.latin1()); | ||
259 | system(command_chown); | ||
260 | } | ||
261 | |||
246 | return true; | 262 | return true; |
247 | } | 263 | } |
248 | 264 | ||
249 | /** | 265 | /** |
250 | * Deletes the user account. | 266 | * Deletes the user account. |
251 | * | 267 | * |
252 | * @param username User to be deleted. | 268 | * @param username User to be deleted. |
253 | * | 269 | * |
254 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 270 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
255 | * | 271 | * |
256 | */ | 272 | */ |
257 | bool UserDialog::delUser(const char *username) { | 273 | bool UserDialog::delUser(const char *username) { |
258 | if((accounts->findUser(username))) {// Does that user exist? | 274 | if((accounts->findUser(username))) {// Does that user exist? |
259 | if(!(accounts->delUser(username))) {// Delete the user. | 275 | if(!(accounts->delUser(username))) {// Delete the user. |
260 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); | 276 | QMessageBox::information(0,"Ooops!","Something went wrong\nUnable to delete user: "+QString(username)+"."); |
261 | } | 277 | } |
262 | } else { | 278 | } else { |
263 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); | 279 | QMessageBox::information(0,"Invalid Username","That username ("+QString(username)+")does not exist."); |
264 | return false; | 280 | return false; |
265 | } | 281 | } |
266 | return true; | 282 | return true; |
267 | } | 283 | } |
268 | 284 | ||
269 | /** | 285 | /** |
270 | * This displays a confirmation dialog wether a user should be deleted or not. | 286 | * This displays a confirmation dialog wether a user should be deleted or not. |
271 | * (And also deletes the account) | 287 | * (And also deletes the account) |
272 | * | 288 | * |
273 | * @param username User to be deleted. | 289 | * @param username User to be deleted. |
274 | * | 290 | * |
275 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. | 291 | * @return <code>true</code> if the user was successfully deleted, otherwise <code>false</code>. |
276 | * | 292 | * |
277 | */ | 293 | */ |
278 | bool UserDialog::editUser(const char *username) { | 294 | bool UserDialog::editUser(const char *username) { |
279 | int invalid_group=0; | 295 | int invalid_group=0; |
280 | UserDialog *edituserDialog=new UserDialog();// Create Dialog | 296 | UserDialog *edituserDialog=new UserDialog();// Create Dialog |
281 | edituserDialog->setCaption(tr("Edit User")); | 297 | edituserDialog->setCaption(tr("Edit User")); |
282 | accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. | 298 | accounts->findUser(username);// Locate user in database and fill variables in 'accounts' object. |
283 | if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. | 299 | if(!(accounts->findGroup(accounts->pw_gid))) {// Locate the user's primary group, and fill group variables in 'accounts' object. |
284 | invalid_group=1; | 300 | invalid_group=1; |
285 | } | 301 | } |
286 | // Fill widgets with userinfo. | 302 | // Fill widgets with userinfo. |
287 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 303 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |
288 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); | 304 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); |
289 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); | 305 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); |
290 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. | 306 | // Set password to '........', we will later check if this still is the contents, if not, the password has been changed. |
291 | edituserDialog->passwordLineEdit->setText("........"); | 307 | edituserDialog->passwordLineEdit->setText("........"); |
292 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. | 308 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. |
293 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { | 309 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { |