-rw-r--r-- | noncore/settings/usermanager/passwd.cpp | 23 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 35 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.h | 9 |
3 files changed, 51 insertions, 16 deletions
diff --git a/noncore/settings/usermanager/passwd.cpp b/noncore/settings/usermanager/passwd.cpp index 5063661..0a2bfba 100644 --- a/noncore/settings/usermanager/passwd.cpp +++ b/noncore/settings/usermanager/passwd.cpp | |||
@@ -22,253 +22,276 @@ Passwd::~Passwd() { | |||
22 | } | 22 | } |
23 | 23 | ||
24 | // This function is taken from 'busybox'. | 24 | // This function is taken from 'busybox'. |
25 | int Passwd::i64c(int i) | 25 | int Passwd::i64c(int i) |
26 | { | 26 | { |
27 | if (i <= 0) | 27 | if (i <= 0) |
28 | return ('.'); | 28 | return ('.'); |
29 | if (i == 1) | 29 | if (i == 1) |
30 | return ('/'); | 30 | return ('/'); |
31 | if (i >= 2 && i < 12) | 31 | if (i >= 2 && i < 12) |
32 | return ('0' - 2 + i); | 32 | return ('0' - 2 + i); |
33 | if (i >= 12 && i < 38) | 33 | if (i >= 12 && i < 38) |
34 | return ('A' - 12 + i); | 34 | return ('A' - 12 + i); |
35 | if (i >= 38 && i < 63) | 35 | if (i >= 38 && i < 63) |
36 | return ('a' - 38 + i); | 36 | return ('a' - 38 + i); |
37 | return ('z'); | 37 | return ('z'); |
38 | } | 38 | } |
39 | 39 | ||
40 | // This function is taken from 'busybox'. | 40 | // This function is taken from 'busybox'. |
41 | char *Passwd::crypt_make_salt() { | 41 | char *Passwd::crypt_make_salt() { |
42 | time_t now; | 42 | time_t now; |
43 | static unsigned long x; | 43 | static unsigned long x; |
44 | static char result[3]; | 44 | static char result[3]; |
45 | 45 | ||
46 | time(&now); | 46 | time(&now); |
47 | x += now + getpid() + clock(); | 47 | x += now + getpid() + clock(); |
48 | result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077); | 48 | result[0] = i64c(((x >> 18) ^ (x >> 6)) & 077); |
49 | result[1] = i64c(((x >> 12) ^ x) & 077); | 49 | result[1] = i64c(((x >> 12) ^ x) & 077); |
50 | result[2] = '\0'; | 50 | result[2] = '\0'; |
51 | return result; | 51 | return result; |
52 | } | 52 | } |
53 | 53 | ||
54 | // opens the files /etc/passwd & /etc/group and loads the contents into passwdStringList & groupStringList | ||
54 | bool Passwd::open() { | 55 | bool Passwd::open() { |
55 | int returnvalue=false; | 56 | int returnvalue=false; |
56 | 57 | ||
57 | QFile passwd_file("/etc/passwd"); | 58 | QFile passwd_file("/etc/passwd"); |
58 | QFile group_file("/etc/group"); | 59 | QFile group_file("/etc/group"); |
59 | passwdStringList.clear(); | 60 | passwdStringList.clear(); |
60 | groupStringList.clear(); | 61 | groupStringList.clear(); |
61 | if((passwd_file.open(IO_ReadOnly))) { | 62 | if((passwd_file.open(IO_ReadOnly))) { |
62 | if((group_file.open(IO_ReadOnly))) { | 63 | if((group_file.open(IO_ReadOnly))) { |
63 | QTextStream ts_passwd(&passwd_file); | 64 | QTextStream ts_passwd(&passwd_file); |
64 | while(!(ts_passwd.eof())) { | 65 | while(!(ts_passwd.eof())) { |
65 | passwdStringList << ts_passwd.readLine(); | 66 | passwdStringList << ts_passwd.readLine(); |
66 | } | 67 | } |
67 | QTextStream ts_group(&group_file); | 68 | QTextStream ts_group(&group_file); |
68 | while(!(ts_group.eof())) { | 69 | while(!(ts_group.eof())) { |
69 | groupStringList << ts_group.readLine(); | 70 | groupStringList << ts_group.readLine(); |
70 | } | 71 | } |
71 | returnvalue=true; | 72 | returnvalue=true; |
72 | group_file.close(); | 73 | group_file.close(); |
73 | } | 74 | } |
74 | passwd_file.close(); | 75 | passwd_file.close(); |
75 | } | 76 | } |
76 | return returnvalue; | 77 | return returnvalue; |
77 | } | 78 | } |
78 | 79 | ||
80 | // Writes back the contents of passwdStringList to /etc/passwd & groupStringList to /etc/group | ||
79 | bool Passwd::close() { | 81 | bool Passwd::close() { |
80 | int returnvalue=false; | 82 | int returnvalue=false; |
81 | QFile passwd_file("/etc/passwd"); | 83 | QFile passwd_file("/etc/passwd"); |
82 | QFile group_file("/etc/group"); | 84 | QFile group_file("/etc/group"); |
83 | if((passwd_file.open(IO_WriteOnly))) { | 85 | if((passwd_file.open(IO_WriteOnly))) { |
84 | if((group_file.open(IO_WriteOnly))) { | 86 | if((group_file.open(IO_WriteOnly))) { |
85 | QTextStream ts_passwd(&passwd_file); | 87 | QTextStream ts_passwd(&passwd_file); |
86 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { | 88 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { |
87 | ts_passwd << (*it) + "\n"; | 89 | ts_passwd << (*it) + "\n"; |
88 | } | 90 | } |
89 | QTextStream ts_group(&group_file); | 91 | QTextStream ts_group(&group_file); |
90 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { | 92 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { |
91 | ts_group << (*it) + "\n"; | 93 | ts_group << (*it) + "\n"; |
92 | } | 94 | } |
93 | returnvalue=true; | 95 | returnvalue=true; |
94 | group_file.close(); | 96 | group_file.close(); |
95 | } | 97 | } |
96 | passwd_file.close(); | 98 | passwd_file.close(); |
97 | } | 99 | } |
98 | return returnvalue; | 100 | return returnvalue; |
99 | } | 101 | } |
100 | 102 | ||
103 | // Splits a "passwd" line into the components and stores them in the pw_* variables. | ||
101 | void Passwd::splitPasswdEntry(QString &userString) { | 104 | void Passwd::splitPasswdEntry(QString &userString) { |
102 | userdataStringList=QStringList::split(":",userString,true); | 105 | userdataStringList=QStringList::split(":",userString,true); |
103 | QStringList::Iterator it=userdataStringList.begin(); | 106 | QStringList::Iterator it=userdataStringList.begin(); |
104 | pw_name=(*it++); | 107 | pw_name=(*it++); |
105 | pw_passwd=(*it++); | 108 | pw_passwd=(*it++); |
106 | pw_uid=(*it++).toInt(); | 109 | pw_uid=(*it++).toInt(); |
107 | pw_gid=(*it++).toInt(); | 110 | pw_gid=(*it++).toInt(); |
108 | pw_gecos=(*it++); | 111 | pw_gecos=(*it++); |
109 | pw_dir=(*it++); | 112 | pw_dir=(*it++); |
110 | pw_shell=(*it++); | 113 | pw_shell=(*it++); |
111 | } | 114 | } |
112 | 115 | ||
116 | // Splits a "group" line into the components and stores them in the gr_* variables. | ||
113 | void Passwd::splitGroupEntry(QString &groupString) { | 117 | void Passwd::splitGroupEntry(QString &groupString) { |
114 | groupdataStringList=QStringList::split(":",groupString,true); | 118 | groupdataStringList=QStringList::split(":",groupString,true); |
115 | QStringList::Iterator it=groupdataStringList.begin(); | 119 | QStringList::Iterator it=groupdataStringList.begin(); |
116 | gr_name=(*it++); | 120 | gr_name=(*it++); |
117 | it++; | 121 | it++; |
118 | gr_gid=(*it++).toInt(); | 122 | gr_gid=(*it++).toInt(); |
119 | gr_mem=QStringList::split(" ",(*it++)); | 123 | gr_mem=QStringList::split(" ",(*it++)); |
120 | } | 124 | } |
121 | 125 | ||
126 | // Find a user in the passwdStringList. Return true if found and also fill the pw_* variables. | ||
122 | bool Passwd::searchUser(QRegExp &userRegExp) { | 127 | bool Passwd::searchUser(QRegExp &userRegExp) { |
123 | QStringList tempStringList(passwdStringList.grep(userRegExp)); | 128 | QStringList tempStringList(passwdStringList.grep(userRegExp)); |
124 | if((tempStringList.isEmpty())) { | 129 | if((tempStringList.isEmpty())) { |
125 | return false; | 130 | return false; |
126 | } else { | 131 | } else { |
127 | userString=(*(tempStringList.begin())); | 132 | userString=(*(tempStringList.begin())); |
128 | splitPasswdEntry(userString); | 133 | splitPasswdEntry(userString); |
129 | } | 134 | } |
130 | return true; | 135 | return true; |
131 | } | 136 | } |
132 | 137 | ||
138 | // Find a user by login. | ||
133 | bool Passwd::findUser(const char *username) { | 139 | bool Passwd::findUser(const char *username) { |
134 | QRegExp userRegExp(QString("^%1\\:").arg(username)); | 140 | QRegExp userRegExp(QString("^%1\\:").arg(username)); |
135 | return searchUser(userRegExp); | 141 | return searchUser(userRegExp); |
136 | } | 142 | } |
137 | 143 | ||
144 | // Find a user by uid. | ||
138 | bool Passwd::findUser(int uid) { | 145 | bool Passwd::findUser(int uid) { |
139 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); | 146 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); |
140 | return searchUser(userRegExp); | 147 | return searchUser(userRegExp); |
141 | } | 148 | } |
142 | 149 | ||
150 | // Add a user to the passwdStringList, create home directory, and optionally create a group for the user. | ||
143 | bool 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) { | 151 | bool Passwd::addUser(QString pw_name, QString pw_passwd, int pw_uid, int pw_gid, QString pw_gecos,QString pw_dir, QString pw_shell, bool createGroup) { |
144 | QString tempString; | 152 | QString tempString; |
145 | if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid); | 153 | if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid); |
146 | pw_passwd = crypt(pw_passwd, crypt_make_salt()); | 154 | pw_passwd = crypt(pw_passwd, crypt_make_salt()); |
147 | tempString=pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell; | 155 | tempString=pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell; |
148 | passwdStringList.append(tempString); | 156 | passwdStringList.append(tempString); |
149 | // Make home dir. | 157 | // Make home dir. |
150 | QDir d; | 158 | QDir d; |
151 | if(!(d.exists(pw_dir))) { | 159 | if(!(d.exists(pw_dir))) { |
152 | d.mkdir(pw_dir); | 160 | d.mkdir(pw_dir); |
153 | chown(pw_dir,pw_uid,pw_gid); | 161 | chown(pw_dir,pw_uid,pw_gid); |
154 | chmod(pw_dir,S_IRUSR|S_IWUSR|S_IXUSR); | 162 | chmod(pw_dir,S_IRUSR|S_IWUSR|S_IXUSR); |
155 | } | 163 | } |
156 | return 1; | 164 | return 1; |
157 | } | 165 | } |
158 | 166 | ||
167 | // Update info for a user in passwdStringList, take info from the pw_* fields. | ||
159 | bool Passwd::updateUser(QString login) { | 168 | bool Passwd::updateUser(QString login) { |
160 | QRegExp userRegExp(QString("^%1\\:").arg(login)); | 169 | QRegExp userRegExp(QString("^%1\\:").arg(login)); |
161 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { | 170 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { |
162 | if(userRegExp.find((*it),0)!=-1) { | 171 | if(userRegExp.find((*it),0)!=-1) { |
163 | *it=QString(pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell); | 172 | *it=QString(pw_name+":"+pw_passwd+":"+QString::number(pw_uid)+":"+QString::number(pw_gid)+":"+pw_gecos+":"+pw_dir+":"+pw_shell); |
164 | return true; | 173 | return true; |
165 | } | 174 | } |
166 | } | 175 | } |
167 | return false; | 176 | return false; |
168 | } | 177 | } |
169 | 178 | ||
179 | // Delete a user from passwdStringList. | ||
170 | bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) { | 180 | bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) { |
171 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { | 181 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { |
172 | if(userRegExp.find((*it),0)!=-1) { | 182 | if(userRegExp.find((*it),0)!=-1) { |
173 | splitPasswdEntry(*it); | 183 | splitPasswdEntry(*it); |
174 | if(delGroup) this->delGroup(pw_gid); | 184 | if(delGroup) this->delGroup(pw_gid); |
175 | passwdStringList.remove(it); | 185 | passwdStringList.remove(it); |
176 | return true; | 186 | return true; |
177 | } | 187 | } |
178 | } | 188 | } |
179 | return false; | 189 | return false; |
180 | } | 190 | } |
181 | 191 | ||
192 | // Delete a user by login, and optionally also delete group. | ||
182 | bool Passwd::delUser(const char *username, bool delGroup) { | 193 | bool Passwd::delUser(const char *username, bool delGroup) { |
183 | QRegExp userRegExp(QString("^%1\\:").arg(username)); | 194 | QRegExp userRegExp(QString("^%1\\:").arg(username)); |
184 | return deleteUser(userRegExp,delGroup); | 195 | return deleteUser(userRegExp,delGroup); |
185 | } | 196 | } |
186 | 197 | ||
198 | // Delete a user by uid, and optionally also delete group. | ||
187 | bool Passwd::delUser(int uid, bool delGroup) { | 199 | bool Passwd::delUser(int uid, bool delGroup) { |
188 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); | 200 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); |
189 | return deleteUser(userRegExp,delGroup); | 201 | return deleteUser(userRegExp,delGroup); |
190 | } | 202 | } |
191 | 203 | ||
204 | // Locate a group in the groupStringList, fill out the gr_* variables and return "true" if found. | ||
192 | bool Passwd::searchGroup(QRegExp &groupRegExp) { | 205 | bool Passwd::searchGroup(QRegExp &groupRegExp) { |
193 | QStringList tempStringList(groupStringList.grep(groupRegExp)); | 206 | QStringList tempStringList(groupStringList.grep(groupRegExp)); |
194 | if((tempStringList.isEmpty())) { | 207 | if((tempStringList.isEmpty())) { |
195 | return false; | 208 | return false; |
196 | } else { | 209 | } else { |
197 | groupString=(*(tempStringList.begin())); | 210 | groupString=(*(tempStringList.begin())); |
198 | splitGroupEntry(groupString); | 211 | splitGroupEntry(groupString); |
199 | } | 212 | } |
200 | return true; | 213 | return true; |
201 | } | 214 | } |
202 | 215 | ||
216 | // Find a group by groupname. | ||
203 | bool Passwd::findGroup(const char *groupname) { | 217 | bool Passwd::findGroup(const char *groupname) { |
204 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); | 218 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); |
205 | return searchGroup(groupRegExp); | 219 | return searchGroup(groupRegExp); |
206 | } | 220 | } |
207 | 221 | ||
222 | // Find a group by gid. | ||
208 | bool Passwd::findGroup(int gid) { | 223 | bool Passwd::findGroup(int gid) { |
209 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); | 224 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); |
210 | return searchGroup(groupRegExp); | 225 | return searchGroup(groupRegExp); |
211 | } | 226 | } |
212 | 227 | ||
228 | // Add a group to groupStringList | ||
213 | bool Passwd::addGroup(QString gr_name, int gr_gid) { | 229 | bool Passwd::addGroup(QString gr_name, int gr_gid) { |
214 | QString tempString; | 230 | QString tempString; |
215 | tempString=gr_name+":*:"+QString::number(gr_gid)+":"; | 231 | tempString=gr_name+":*:"+QString::number(gr_gid)+":"; |
216 | groupStringList.append(tempString); | 232 | groupStringList.append(tempString); |
217 | return 1; | 233 | return 1; |
218 | } | 234 | } |
219 | 235 | ||
236 | // Update fields for a group in groupStringList, take info from the gr_* variables. | ||
220 | bool Passwd::updateGroup(int gid) { | 237 | bool Passwd::updateGroup(int gid) { |
221 | QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid))); | 238 | QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid))); |
222 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { | 239 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { |
223 | if(groupRegExp.find((*it),0)!=-1) { | 240 | if(groupRegExp.find((*it),0)!=-1) { |
224 | *it=QString(gr_name+":*:"+QString::number(gr_gid)+":"); | 241 | *it=QString(gr_name+":*:"+QString::number(gr_gid)+":"); |
225 | for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end(); ++member) { | 242 | for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end(); ++member) { |
226 | *it+=*member; | 243 | *it+=*member; |
227 | *it+=" "; | 244 | *it+=" "; |
228 | } | 245 | } |
229 | return true; | 246 | return true; |
230 | } | 247 | } |
231 | } | 248 | } |
232 | return false; | 249 | return false; |
233 | } | 250 | } |
234 | 251 | ||
252 | // Delete a group from groupStringList. | ||
235 | bool Passwd::deleteGroup(QRegExp &groupRegExp) { | 253 | bool Passwd::deleteGroup(QRegExp &groupRegExp) { |
236 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { | 254 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { |
237 | if(groupRegExp.find((*it),0)!=-1) { | 255 | if(groupRegExp.find((*it),0)!=-1) { |
238 | groupStringList.remove(it); | 256 | groupStringList.remove(it); |
239 | return true; | 257 | return true; |
240 | } | 258 | } |
241 | } | 259 | } |
242 | return false; | 260 | return false; |
243 | } | 261 | } |
244 | 262 | ||
263 | // Delete a group by groupname. | ||
245 | bool Passwd::delGroup(const char *groupname) { | 264 | bool Passwd::delGroup(const char *groupname) { |
246 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); | 265 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); |
247 | return deleteGroup(groupRegExp); | 266 | return deleteGroup(groupRegExp); |
248 | } | 267 | } |
249 | 268 | ||
269 | // Delete a group by gid. | ||
250 | bool Passwd::delGroup(int gid) { | 270 | bool Passwd::delGroup(int gid) { |
251 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); | 271 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); |
252 | return deleteGroup(groupRegExp); | 272 | return deleteGroup(groupRegExp); |
253 | } | 273 | } |
254 | 274 | ||
275 | // Add a user as a member to a group in groupStringList. | ||
255 | bool Passwd::addGroupMember(QString groupname, QString member) { | 276 | bool Passwd::addGroupMember(QString groupname, QString member) { |
256 | if(!(findGroup(groupname))) return false; | 277 | if(!(findGroup(groupname))) return false; |
257 | gr_mem << member; | 278 | gr_mem << member; |
258 | if(!(updateGroup(gr_gid))) return false; | 279 | if(!(updateGroup(gr_gid))) return false; |
259 | return true; | 280 | return true; |
260 | } | 281 | } |
261 | 282 | ||
283 | // Delete a user as a groupmember from a group in groupStringList. | ||
262 | bool Passwd::delGroupMember(QString groupname, QString member) { | 284 | bool Passwd::delGroupMember(QString groupname, QString member) { |
263 | if(!(findGroup(groupname))) return false; | 285 | if(!(findGroup(groupname))) return false; |
264 | for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) { | 286 | for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) { |
265 | if(*it==member) { | 287 | if(*it==member) { |
266 | gr_mem.remove(it); | 288 | gr_mem.remove(it); |
267 | it=gr_mem.end(); | 289 | it=gr_mem.end(); |
268 | } | 290 | } |
269 | } | 291 | } |
270 | if(!(updateGroup(gr_gid))) return false; | 292 | if(!(updateGroup(gr_gid))) return false; |
271 | return true; | 293 | return true; |
272 | } | 294 | } |
273 | 295 | ||
296 | // Global Object | ||
274 | Passwd *accounts; | 297 | Passwd *accounts; |
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index 36bcf86..c82cc9d 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -3,65 +3,66 @@ | |||
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); |
@@ -80,152 +81,157 @@ void UserDialog::setupTab1() { | |||
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 | ||
112 | // Copy /etc/skel | 113 | if(vm==VIEWMODE_NEW) { |
113 | QLabel *skelLabel=new QLabel(tabpage,"skel"); | 114 | // Copy /etc/skel |
114 | skelLabel->setText("Copy /etc/skel: "); | 115 | skelLabel=new QLabel(tabpage,"skel"); |
115 | skelCheckBox=new QCheckBox(tabpage); | 116 | skelLabel->setText("Copy /etc/skel: "); |
116 | skelCheckBox->setChecked(true); | 117 | skelCheckBox=new QCheckBox(tabpage); |
117 | //skelLabel->setDisabled(true); | 118 | skelCheckBox->setChecked(true); |
118 | //skelCheckBox->setDisabled(true); | 119 | } |
119 | 120 | ||
120 | // Widget layout | 121 | // Widget layout |
121 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); | 122 | QHBoxLayout *hlayout=new QHBoxLayout(-1,"hlayout"); |
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); |
139 | vlayout1->addSpacing(5); | 140 | if(vm==VIEWMODE_NEW) { |
140 | vlayout1->addWidget(skelLabel); | 141 | vlayout1->addSpacing(5); |
142 | vlayout1->addWidget(skelLabel); | ||
143 | } | ||
141 | // Second column, data | 144 | // Second column, data |
142 | vlayout2->addWidget(loginLineEdit); | 145 | vlayout2->addWidget(loginLineEdit); |
143 | vlayout2->addSpacing(5); | 146 | vlayout2->addSpacing(5); |
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); |
153 | vlayout2->addSpacing(5); | 156 | if(vm==VIEWMODE_NEW) { |
154 | vlayout2->addWidget(skelCheckBox); | 157 | vlayout2->addSpacing(5); |
158 | vlayout2->addWidget(skelCheckBox); | ||
159 | } | ||
155 | hlayout->addLayout(vlayout1); | 160 | hlayout->addLayout(vlayout1); |
156 | hlayout->addLayout(vlayout2); | 161 | hlayout->addLayout(vlayout2); |
157 | 162 | ||
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; |
@@ -269,65 +275,66 @@ bool UserDialog::addUser(int uid, int gid) { | |||
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. |
diff --git a/noncore/settings/usermanager/userdialog.h b/noncore/settings/usermanager/userdialog.h index 133b35d..b7b925d 100644 --- a/noncore/settings/usermanager/userdialog.h +++ b/noncore/settings/usermanager/userdialog.h | |||
@@ -13,49 +13,54 @@ | |||
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 | #include <qcheckbox.h> | 18 | #include <qcheckbox.h> |
19 | 19 | ||
20 | #include <qpe/resource.h> | 20 | #include <qpe/resource.h> |
21 | 21 | ||
22 | #include <opie/ofiledialog.h> | 22 | #include <opie/ofiledialog.h> |
23 | 23 | ||
24 | class UserDialog : public QDialog | 24 | class UserDialog : public QDialog |
25 | { | 25 | { |
26 | Q_OBJECT | 26 | Q_OBJECT |
27 | private: | 27 | private: |
28 | QTabWidget *myTabWidget; | 28 | QTabWidget *myTabWidget; |
29 | QPushButton *picturePushButton; | 29 | QPushButton *picturePushButton; |
30 | QLineEdit *loginLineEdit; | 30 | QLineEdit *loginLineEdit; |
31 | QLineEdit *uidLineEdit; | 31 | QLineEdit *uidLineEdit; |
32 | QLineEdit *gecosLineEdit; | 32 | QLineEdit *gecosLineEdit; |
33 | QLineEdit *passwordLineEdit; | 33 | QLineEdit *passwordLineEdit; |
34 | QComboBox *shellComboBox; | 34 | QComboBox *shellComboBox; |
35 | QComboBox *groupComboBox; | 35 | QComboBox *groupComboBox; |
36 | QLabel *skelLabel; | 36 | QLabel *skelLabel; |
37 | QCheckBox *skelCheckBox; | 37 | QCheckBox *skelCheckBox; |
38 | QListView *groupsListView; | 38 | QListView *groupsListView; |
39 | 39 | ||
40 | QStringList groupMembers; | 40 | QStringList groupMembers; |
41 | QString pictureLocation; | 41 | QString pictureLocation; |
42 | QImage userImage; | 42 | QImage userImage; |
43 | int groupID; | 43 | int groupID; |
44 | int userID; | 44 | int userID; |
45 | 45 | int vm; | |
46 | enum VIEWMODE { | ||
47 | VIEWMODE_NEW, | ||
48 | VIEWMODE_EDIT | ||
49 | }; | ||
50 | |||
46 | void setupTab1(void); | 51 | void setupTab1(void); |
47 | void setupTab2(void); | 52 | void setupTab2(void); |
48 | void accept(void); | 53 | void accept(void); |
49 | 54 | ||
50 | private slots: | 55 | private slots: |
51 | void clickedPicture(void); | 56 | void clickedPicture(void); |
52 | 57 | ||
53 | public: | 58 | public: |
54 | UserDialog( QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); | 59 | UserDialog( int viewmode=VIEWMODE_NEW, QWidget* parent = 0, const char* name = 0, bool modal=true, WFlags fl = 0 ); |
55 | ~UserDialog(); | 60 | ~UserDialog(); |
56 | static bool addUser(int uid, int gid); | 61 | static bool addUser(int uid, int gid); |
57 | static bool editUser(const char *username); | 62 | static bool editUser(const char *username); |
58 | static bool delUser(const char *username); | 63 | static bool delUser(const char *username); |
59 | }; | 64 | }; |
60 | 65 | ||
61 | #endif | 66 | #endif |