author | umopapisdn <umopapisdn> | 2003-03-22 00:31:44 (UTC) |
---|---|---|
committer | umopapisdn <umopapisdn> | 2003-03-22 00:31:44 (UTC) |
commit | ebf65f250904e0619c10b69a0428fcc538ffc167 (patch) (unidiff) | |
tree | 1ed0ca90ff564a55116787acff758cb2e4dcb4f8 | |
parent | ab8cb739c666f5f22049258a4bcbb06d1e1ad0c4 (diff) | |
download | opie-ebf65f250904e0619c10b69a0428fcc538ffc167.zip opie-ebf65f250904e0619c10b69a0428fcc538ffc167.tar.gz opie-ebf65f250904e0619c10b69a0428fcc538ffc167.tar.bz2 |
Bugfix: Groupmembers should be separated by a comma and not by a space.
-rw-r--r-- | noncore/settings/usermanager/passwd.cpp | 11 | ||||
-rw-r--r-- | noncore/settings/usermanager/userdialog.cpp | 17 |
2 files changed, 23 insertions, 5 deletions
diff --git a/noncore/settings/usermanager/passwd.cpp b/noncore/settings/usermanager/passwd.cpp index 0a2bfba..1e98778 100644 --- a/noncore/settings/usermanager/passwd.cpp +++ b/noncore/settings/usermanager/passwd.cpp | |||
@@ -27,271 +27,274 @@ int Passwd::i64c(int i) | |||
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 | // opens the files /etc/passwd & /etc/group and loads the contents into passwdStringList & groupStringList |
55 | bool Passwd::open() { | 55 | bool Passwd::open() { |
56 | int returnvalue=false; | 56 | int returnvalue=false; |
57 | 57 | ||
58 | QFile passwd_file("/etc/passwd"); | 58 | QFile passwd_file("/etc/passwd"); |
59 | QFile group_file("/etc/group"); | 59 | QFile group_file("/etc/group"); |
60 | passwdStringList.clear(); | 60 | passwdStringList.clear(); |
61 | groupStringList.clear(); | 61 | groupStringList.clear(); |
62 | if((passwd_file.open(IO_ReadOnly))) { | 62 | if((passwd_file.open(IO_ReadOnly))) { |
63 | if((group_file.open(IO_ReadOnly))) { | 63 | if((group_file.open(IO_ReadOnly))) { |
64 | QTextStream ts_passwd(&passwd_file); | 64 | QTextStream ts_passwd(&passwd_file); |
65 | while(!(ts_passwd.eof())) { | 65 | while(!(ts_passwd.eof())) { |
66 | passwdStringList << ts_passwd.readLine(); | 66 | passwdStringList << ts_passwd.readLine(); |
67 | } | 67 | } |
68 | QTextStream ts_group(&group_file); | 68 | QTextStream ts_group(&group_file); |
69 | while(!(ts_group.eof())) { | 69 | while(!(ts_group.eof())) { |
70 | groupStringList << ts_group.readLine(); | 70 | groupStringList << ts_group.readLine(); |
71 | } | 71 | } |
72 | returnvalue=true; | 72 | returnvalue=true; |
73 | group_file.close(); | 73 | group_file.close(); |
74 | } | 74 | } |
75 | passwd_file.close(); | 75 | passwd_file.close(); |
76 | } | 76 | } |
77 | return returnvalue; | 77 | return returnvalue; |
78 | } | 78 | } |
79 | 79 | ||
80 | // Writes back the contents of passwdStringList to /etc/passwd & groupStringList to /etc/group | 80 | // Writes back the contents of passwdStringList to /etc/passwd & groupStringList to /etc/group |
81 | bool Passwd::close() { | 81 | bool Passwd::close() { |
82 | int returnvalue=false; | 82 | int returnvalue=false; |
83 | QFile passwd_file("/etc/passwd"); | 83 | QFile passwd_file("/etc/passwd"); |
84 | QFile group_file("/etc/group"); | 84 | QFile group_file("/etc/group"); |
85 | if((passwd_file.open(IO_WriteOnly))) { | 85 | if((passwd_file.open(IO_WriteOnly))) { |
86 | if((group_file.open(IO_WriteOnly))) { | 86 | if((group_file.open(IO_WriteOnly))) { |
87 | QTextStream ts_passwd(&passwd_file); | 87 | QTextStream ts_passwd(&passwd_file); |
88 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { | 88 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { |
89 | ts_passwd << (*it) + "\n"; | 89 | ts_passwd << (*it) + "\n"; |
90 | } | 90 | } |
91 | QTextStream ts_group(&group_file); | 91 | QTextStream ts_group(&group_file); |
92 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { | 92 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { |
93 | ts_group << (*it) + "\n"; | 93 | ts_group << (*it) + "\n"; |
94 | } | 94 | } |
95 | returnvalue=true; | 95 | returnvalue=true; |
96 | group_file.close(); | 96 | group_file.close(); |
97 | } | 97 | } |
98 | passwd_file.close(); | 98 | passwd_file.close(); |
99 | } | 99 | } |
100 | return returnvalue; | 100 | return returnvalue; |
101 | } | 101 | } |
102 | 102 | ||
103 | // Splits a "passwd" line into the components and stores them in the pw_* variables. | 103 | // Splits a "passwd" line into the components and stores them in the pw_* variables. |
104 | void Passwd::splitPasswdEntry(QString &userString) { | 104 | void Passwd::splitPasswdEntry(QString &userString) { |
105 | userdataStringList=QStringList::split(":",userString,true); | 105 | userdataStringList=QStringList::split(":",userString,true); |
106 | QStringList::Iterator it=userdataStringList.begin(); | 106 | QStringList::Iterator it=userdataStringList.begin(); |
107 | pw_name=(*it++); | 107 | pw_name=(*it++); |
108 | pw_passwd=(*it++); | 108 | pw_passwd=(*it++); |
109 | pw_uid=(*it++).toInt(); | 109 | pw_uid=(*it++).toInt(); |
110 | pw_gid=(*it++).toInt(); | 110 | pw_gid=(*it++).toInt(); |
111 | pw_gecos=(*it++); | 111 | pw_gecos=(*it++); |
112 | pw_dir=(*it++); | 112 | pw_dir=(*it++); |
113 | pw_shell=(*it++); | 113 | pw_shell=(*it++); |
114 | } | 114 | } |
115 | 115 | ||
116 | // Splits a "group" line into the components and stores them in the gr_* variables. | 116 | // Splits a "group" line into the components and stores them in the gr_* variables. |
117 | void Passwd::splitGroupEntry(QString &groupString) { | 117 | void Passwd::splitGroupEntry(QString &groupString) { |
118 | groupdataStringList=QStringList::split(":",groupString,true); | 118 | groupdataStringList=QStringList::split(":",groupString,true); |
119 | QStringList::Iterator it=groupdataStringList.begin(); | 119 | QStringList::Iterator it=groupdataStringList.begin(); |
120 | gr_name=(*it++); | 120 | gr_name=(*it++); |
121 | it++; | 121 | it++; |
122 | gr_gid=(*it++).toInt(); | 122 | gr_gid=(*it++).toInt(); |
123 | gr_mem=QStringList::split(" ",(*it++)); | 123 | gr_mem=QStringList::split(",",(*it++)); |
124 | } | 124 | } |
125 | 125 | ||
126 | // Find a user in the passwdStringList. Return true if found and also fill the pw_* variables. | 126 | // Find a user in the passwdStringList. Return true if found and also fill the pw_* variables. |
127 | bool Passwd::searchUser(QRegExp &userRegExp) { | 127 | bool Passwd::searchUser(QRegExp &userRegExp) { |
128 | QStringList tempStringList(passwdStringList.grep(userRegExp)); | 128 | QStringList tempStringList(passwdStringList.grep(userRegExp)); |
129 | if((tempStringList.isEmpty())) { | 129 | if((tempStringList.isEmpty())) { |
130 | return false; | 130 | return false; |
131 | } else { | 131 | } else { |
132 | userString=(*(tempStringList.begin())); | 132 | userString=(*(tempStringList.begin())); |
133 | splitPasswdEntry(userString); | 133 | splitPasswdEntry(userString); |
134 | } | 134 | } |
135 | return true; | 135 | return true; |
136 | } | 136 | } |
137 | 137 | ||
138 | // Find a user by login. | 138 | // Find a user by login. |
139 | bool Passwd::findUser(const char *username) { | 139 | bool Passwd::findUser(const char *username) { |
140 | QRegExp userRegExp(QString("^%1\\:").arg(username)); | 140 | QRegExp userRegExp(QString("^%1\\:").arg(username)); |
141 | return searchUser(userRegExp); | 141 | return searchUser(userRegExp); |
142 | } | 142 | } |
143 | 143 | ||
144 | // Find a user by uid. | 144 | // Find a user by uid. |
145 | bool Passwd::findUser(int uid) { | 145 | bool Passwd::findUser(int uid) { |
146 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); | 146 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); |
147 | return searchUser(userRegExp); | 147 | return searchUser(userRegExp); |
148 | } | 148 | } |
149 | 149 | ||
150 | // Add a user to the passwdStringList, create home directory, and optionally create a group for the user. | 150 | // Add a user to the passwdStringList, create home directory, and optionally create a group for the user. |
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) { | 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) { |
152 | QString tempString; | 152 | QString tempString; |
153 | if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid); | 153 | if((createGroup) && (!(findGroup(pw_gid)))) addGroup(pw_name,pw_gid); |
154 | pw_passwd = crypt(pw_passwd, crypt_make_salt()); | 154 | pw_passwd = crypt(pw_passwd, crypt_make_salt()); |
155 | 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; |
156 | passwdStringList.append(tempString); | 156 | passwdStringList.append(tempString); |
157 | // Make home dir. | 157 | // Make home dir. |
158 | QDir d; | 158 | QDir d; |
159 | if(!(d.exists(pw_dir))) { | 159 | if(!(d.exists(pw_dir))) { |
160 | d.mkdir(pw_dir); | 160 | d.mkdir(pw_dir); |
161 | chown(pw_dir,pw_uid,pw_gid); | 161 | chown(pw_dir,pw_uid,pw_gid); |
162 | chmod(pw_dir,S_IRUSR|S_IWUSR|S_IXUSR); | 162 | chmod(pw_dir,S_IRUSR|S_IWUSR|S_IXUSR); |
163 | } | 163 | } |
164 | return 1; | 164 | return 1; |
165 | } | 165 | } |
166 | 166 | ||
167 | // Update info for a user in passwdStringList, take info from the pw_* fields. | 167 | // Update info for a user in passwdStringList, take info from the pw_* fields. |
168 | bool Passwd::updateUser(QString login) { | 168 | bool Passwd::updateUser(QString login) { |
169 | QRegExp userRegExp(QString("^%1\\:").arg(login)); | 169 | QRegExp userRegExp(QString("^%1\\:").arg(login)); |
170 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { | 170 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { |
171 | if(userRegExp.find((*it),0)!=-1) { | 171 | if(userRegExp.find((*it),0)!=-1) { |
172 | *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); |
173 | return true; | 173 | return true; |
174 | } | 174 | } |
175 | } | 175 | } |
176 | return false; | 176 | return false; |
177 | } | 177 | } |
178 | 178 | ||
179 | // Delete a user from passwdStringList. | 179 | // Delete a user from passwdStringList. |
180 | bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) { | 180 | bool Passwd::deleteUser(QRegExp &userRegExp, bool delGroup) { |
181 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { | 181 | for(QStringList::Iterator it=passwdStringList.begin(); it!=passwdStringList.end(); ++it) { |
182 | if(userRegExp.find((*it),0)!=-1) { | 182 | if(userRegExp.find((*it),0)!=-1) { |
183 | splitPasswdEntry(*it); | 183 | splitPasswdEntry(*it); |
184 | if(delGroup) this->delGroup(pw_gid); | 184 | if(delGroup) this->delGroup(pw_gid); |
185 | passwdStringList.remove(it); | 185 | passwdStringList.remove(it); |
186 | return true; | 186 | return true; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | return false; | 189 | return false; |
190 | } | 190 | } |
191 | 191 | ||
192 | // Delete a user by login, and optionally also delete group. | 192 | // Delete a user by login, and optionally also delete group. |
193 | bool Passwd::delUser(const char *username, bool delGroup) { | 193 | bool Passwd::delUser(const char *username, bool delGroup) { |
194 | QRegExp userRegExp(QString("^%1\\:").arg(username)); | 194 | QRegExp userRegExp(QString("^%1\\:").arg(username)); |
195 | return deleteUser(userRegExp,delGroup); | 195 | return deleteUser(userRegExp,delGroup); |
196 | } | 196 | } |
197 | 197 | ||
198 | // Delete a user by uid, and optionally also delete group. | 198 | // Delete a user by uid, and optionally also delete group. |
199 | bool Passwd::delUser(int uid, bool delGroup) { | 199 | bool Passwd::delUser(int uid, bool delGroup) { |
200 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); | 200 | QRegExp userRegExp(QString(":%1\\:").arg(uid)); |
201 | return deleteUser(userRegExp,delGroup); | 201 | return deleteUser(userRegExp,delGroup); |
202 | } | 202 | } |
203 | 203 | ||
204 | // Locate a group in the groupStringList, fill out the gr_* variables and return "true" if found. | 204 | // Locate a group in the groupStringList, fill out the gr_* variables and return "true" if found. |
205 | bool Passwd::searchGroup(QRegExp &groupRegExp) { | 205 | bool Passwd::searchGroup(QRegExp &groupRegExp) { |
206 | QStringList tempStringList(groupStringList.grep(groupRegExp)); | 206 | QStringList tempStringList(groupStringList.grep(groupRegExp)); |
207 | if((tempStringList.isEmpty())) { | 207 | if((tempStringList.isEmpty())) { |
208 | return false; | 208 | return false; |
209 | } else { | 209 | } else { |
210 | groupString=(*(tempStringList.begin())); | 210 | groupString=(*(tempStringList.begin())); |
211 | splitGroupEntry(groupString); | 211 | splitGroupEntry(groupString); |
212 | } | 212 | } |
213 | return true; | 213 | return true; |
214 | } | 214 | } |
215 | 215 | ||
216 | // Find a group by groupname. | 216 | // Find a group by groupname. |
217 | bool Passwd::findGroup(const char *groupname) { | 217 | bool Passwd::findGroup(const char *groupname) { |
218 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); | 218 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); |
219 | return searchGroup(groupRegExp); | 219 | return searchGroup(groupRegExp); |
220 | } | 220 | } |
221 | 221 | ||
222 | // Find a group by gid. | 222 | // Find a group by gid. |
223 | bool Passwd::findGroup(int gid) { | 223 | bool Passwd::findGroup(int gid) { |
224 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); | 224 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); |
225 | return searchGroup(groupRegExp); | 225 | return searchGroup(groupRegExp); |
226 | } | 226 | } |
227 | 227 | ||
228 | // Add a group to groupStringList | 228 | // Add a group to groupStringList |
229 | bool Passwd::addGroup(QString gr_name, int gr_gid) { | 229 | bool Passwd::addGroup(QString gr_name, int gr_gid) { |
230 | QString tempString; | 230 | QString tempString; |
231 | tempString=gr_name+":*:"+QString::number(gr_gid)+":"; | 231 | tempString=gr_name+":*:"+QString::number(gr_gid)+":"; |
232 | groupStringList.append(tempString); | 232 | groupStringList.append(tempString); |
233 | return 1; | 233 | return 1; |
234 | } | 234 | } |
235 | 235 | ||
236 | // Update fields for a group in groupStringList, take info from the gr_* variables. | 236 | // Update fields for a group in groupStringList, take info from the gr_* variables. |
237 | bool Passwd::updateGroup(int gid) { | 237 | bool Passwd::updateGroup(int gid) { |
238 | QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid))); | 238 | QRegExp groupRegExp(QString(":%1\\:").arg(QString::number(gid))); |
239 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { | 239 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { |
240 | if(groupRegExp.find((*it),0)!=-1) { | 240 | if(groupRegExp.find((*it),0)!=-1) { |
241 | *it=QString(gr_name+":*:"+QString::number(gr_gid)+":"); | 241 | *it=QString(gr_name+":*:"+QString::number(gr_gid)+":"); |
242 | for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end(); ++member) { | 242 | for(QStringList::Iterator member=gr_mem.begin(); member!=gr_mem.end();) { |
243 | *it+=*member; | 243 | *it+=*member; |
244 | *it+=" "; | 244 | ++member; |
245 | if(member!=gr_mem.end()) *it+=","; | ||
245 | } | 246 | } |
246 | return true; | 247 | return true; |
247 | } | 248 | } |
248 | } | 249 | } |
249 | return false; | 250 | return false; |
250 | } | 251 | } |
251 | 252 | ||
252 | // Delete a group from groupStringList. | 253 | // Delete a group from groupStringList. |
253 | bool Passwd::deleteGroup(QRegExp &groupRegExp) { | 254 | bool Passwd::deleteGroup(QRegExp &groupRegExp) { |
254 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { | 255 | for(QStringList::Iterator it=groupStringList.begin(); it!=groupStringList.end(); ++it) { |
255 | if(groupRegExp.find((*it),0)!=-1) { | 256 | if(groupRegExp.find((*it),0)!=-1) { |
256 | groupStringList.remove(it); | 257 | groupStringList.remove(it); |
257 | return true; | 258 | return true; |
258 | } | 259 | } |
259 | } | 260 | } |
260 | return false; | 261 | return false; |
261 | } | 262 | } |
262 | 263 | ||
263 | // Delete a group by groupname. | 264 | // Delete a group by groupname. |
264 | bool Passwd::delGroup(const char *groupname) { | 265 | bool Passwd::delGroup(const char *groupname) { |
265 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); | 266 | QRegExp groupRegExp(QString("^%1\\:").arg(groupname)); |
266 | return deleteGroup(groupRegExp); | 267 | return deleteGroup(groupRegExp); |
267 | } | 268 | } |
268 | 269 | ||
269 | // Delete a group by gid. | 270 | // Delete a group by gid. |
270 | bool Passwd::delGroup(int gid) { | 271 | bool Passwd::delGroup(int gid) { |
271 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); | 272 | QRegExp groupRegExp(QString(":%1\\:").arg(gid)); |
272 | return deleteGroup(groupRegExp); | 273 | return deleteGroup(groupRegExp); |
273 | } | 274 | } |
274 | 275 | ||
275 | // Add a user as a member to a group in groupStringList. | 276 | // Add a user as a member to a group in groupStringList. |
276 | bool Passwd::addGroupMember(QString groupname, QString member) { | 277 | bool Passwd::addGroupMember(QString groupname, QString member) { |
277 | if(!(findGroup(groupname))) return false; | 278 | if(!(findGroup(groupname))) return false; |
278 | gr_mem << member; | 279 | QRegExp memberRegExp(QString("^%1$").arg(member)); |
280 | QStringList templist=gr_mem.grep(memberRegExp); | ||
281 | if(templist.isEmpty()) gr_mem << member; | ||
279 | if(!(updateGroup(gr_gid))) return false; | 282 | if(!(updateGroup(gr_gid))) return false; |
280 | return true; | 283 | return true; |
281 | } | 284 | } |
282 | 285 | ||
283 | // Delete a user as a groupmember from a group in groupStringList. | 286 | // Delete a user as a groupmember from a group in groupStringList. |
284 | bool Passwd::delGroupMember(QString groupname, QString member) { | 287 | bool Passwd::delGroupMember(QString groupname, QString member) { |
285 | if(!(findGroup(groupname))) return false; | 288 | if(!(findGroup(groupname))) return false; |
286 | for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) { | 289 | for(QStringList::Iterator it=gr_mem.begin(); it!=gr_mem.end(); ++it) { |
287 | if(*it==member) { | 290 | if(*it==member) { |
288 | gr_mem.remove(it); | 291 | gr_mem.remove(it); |
289 | it=gr_mem.end(); | 292 | it=gr_mem.end(); |
290 | } | 293 | } |
291 | } | 294 | } |
292 | if(!(updateGroup(gr_gid))) return false; | 295 | if(!(updateGroup(gr_gid))) return false; |
293 | return true; | 296 | return true; |
294 | } | 297 | } |
295 | 298 | ||
296 | // Global Object | 299 | // Global Object |
297 | Passwd *accounts; | 300 | Passwd *accounts; |
diff --git a/noncore/settings/usermanager/userdialog.cpp b/noncore/settings/usermanager/userdialog.cpp index c82cc9d..0d2122b 100644 --- a/noncore/settings/usermanager/userdialog.cpp +++ b/noncore/settings/usermanager/userdialog.cpp | |||
@@ -240,185 +240,200 @@ bool UserDialog::addUser(int uid, int gid) { | |||
240 | // Add User to additional groups. | 240 | // Add User to additional groups. |
241 | QListViewItemIterator it( adduserDialog->groupsListView ); | 241 | QListViewItemIterator it( adduserDialog->groupsListView ); |
242 | for ( ; it.current(); ++it ) { | 242 | for ( ; it.current(); ++it ) { |
243 | temp=(QCheckListItem*)it.current(); | 243 | temp=(QCheckListItem*)it.current(); |
244 | if (temp->isOn() ) | 244 | if (temp->isOn() ) |
245 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); | 245 | accounts->addGroupMember(it.current()->text(0),adduserDialog->loginLineEdit->text()); |
246 | } | 246 | } |
247 | // Copy image to pics/users/ | 247 | // Copy image to pics/users/ |
248 | if(!(adduserDialog->userImage.isNull())) { | 248 | if(!(adduserDialog->userImage.isNull())) { |
249 | QDir d; | 249 | QDir d; |
250 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 250 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
251 | d.mkdir("/opt/QtPalmtop/pics/users"); | 251 | d.mkdir("/opt/QtPalmtop/pics/users"); |
252 | } | 252 | } |
253 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 253 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
254 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); | 254 | // adduserDialog->userImage=adduserDialog->userImage.smoothScale(48,48); |
255 | adduserDialog->userImage.save(filename,"PNG"); | 255 | adduserDialog->userImage.save(filename,"PNG"); |
256 | } | 256 | } |
257 | 257 | ||
258 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? | 258 | // Should we copy the skeleton homedirectory /etc/skel to the user's homedirectory? |
259 | accounts->findUser(adduserDialog->loginLineEdit->text()); | 259 | accounts->findUser(adduserDialog->loginLineEdit->text()); |
260 | if(adduserDialog->skelCheckBox->isChecked()) { | 260 | if(adduserDialog->skelCheckBox->isChecked()) { |
261 | QString command_cp; | 261 | QString command_cp; |
262 | QString command_chown; | 262 | QString command_chown; |
263 | 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()); |
264 | system(command_cp); | 264 | system(command_cp); |
265 | 265 | ||
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? | 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? |
267 | system(command_cp); | 267 | system(command_cp); |
268 | 268 | ||
269 | 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()); |
270 | system(command_chown); | 270 | system(command_chown); |
271 | } | 271 | } |
272 | 272 | ||
273 | return true; | 273 | return true; |
274 | } | 274 | } |
275 | 275 | ||
276 | /** | 276 | /** |
277 | * Deletes the user account. | 277 | * Deletes the user account. |
278 | * | 278 | * |
279 | * @param username User to be deleted. | 279 | * @param username User to be deleted. |
280 | * | 280 | * |
281 | * @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>. |
282 | * | 282 | * |
283 | */ | 283 | */ |
284 | bool UserDialog::delUser(const char *username) { | 284 | bool UserDialog::delUser(const char *username) { |
285 | if((accounts->findUser(username))) {// Does that user exist? | 285 | if((accounts->findUser(username))) {// Does that user exist? |
286 | if(!(accounts->delUser(username))) {// Delete the user. | 286 | if(!(accounts->delUser(username))) {// Delete the user. |
287 | 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)+"."); |
288 | } | 288 | } |
289 | } else { | 289 | } else { |
290 | 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."); |
291 | return false; | 291 | return false; |
292 | } | 292 | } |
293 | return true; | 293 | return true; |
294 | } | 294 | } |
295 | 295 | ||
296 | /** | 296 | /** |
297 | * 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. |
298 | * (And also deletes the account) | 298 | * (And also deletes the account) |
299 | * | 299 | * |
300 | * @param username User to be deleted. | 300 | * @param username User to be deleted. |
301 | * | 301 | * |
302 | * @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>. |
303 | * | 303 | * |
304 | */ | 304 | */ |
305 | bool UserDialog::editUser(const char *username) { | 305 | bool UserDialog::editUser(const char *username) { |
306 | int invalid_group=0; | 306 | int invalid_group=0; |
307 | // viewmode is a workaround for a bug in qte-2.3.4 that gives bus error on manipulating edituserDialog's widgets here. | 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 | 308 | UserDialog *edituserDialog=new UserDialog(VIEWMODE_EDIT);// Create Dialog |
309 | edituserDialog->setCaption(tr("Edit User")); | 309 | edituserDialog->setCaption(tr("Edit User")); |
310 | 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. |
311 | 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. |
312 | invalid_group=1; | 312 | invalid_group=1; |
313 | } | 313 | } |
314 | // Fill widgets with userinfo. | 314 | // Fill widgets with userinfo. |
315 | edituserDialog->loginLineEdit->setText(accounts->pw_name); | 315 | edituserDialog->loginLineEdit->setText(accounts->pw_name); |
316 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); | 316 | edituserDialog->uidLineEdit->setText(QString::number(accounts->pw_uid)); |
317 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); | 317 | edituserDialog->gecosLineEdit->setText(accounts->pw_gecos); |
318 | // 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. |
319 | edituserDialog->passwordLineEdit->setText("........"); | 319 | edituserDialog->passwordLineEdit->setText("........"); |
320 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. | 320 | // If this user is not using /bin/sh,/bin/ash or /bin/false as shell, add that entry to the shell-combobox. |
321 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { | 321 | if(accounts->pw_shell!="/bin/sh" && accounts->pw_shell!="/bin/ash" && accounts->pw_shell!="/bin/false") { |
322 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); | 322 | edituserDialog->shellComboBox->insertItem(accounts->pw_shell,0); |
323 | edituserDialog->shellComboBox->setCurrentItem(0); | 323 | edituserDialog->shellComboBox->setCurrentItem(0); |
324 | } | 324 | } |
325 | // Select the primary group for this user. | 325 | // Select the primary group for this user. |
326 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { | 326 | for(int i=0;i<edituserDialog->groupComboBox->count();++i) { |
327 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { | 327 | if(accounts->gr_name==edituserDialog->groupComboBox->text(i)) { |
328 | edituserDialog->groupComboBox->setCurrentItem(i); | 328 | edituserDialog->groupComboBox->setCurrentItem(i); |
329 | break; | 329 | break; |
330 | } | 330 | } |
331 | } | 331 | } |
332 | if(invalid_group) { | 332 | if(invalid_group) { |
333 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); | 333 | edituserDialog->groupComboBox->insertItem("<Undefined group>",0); |
334 | edituserDialog->groupComboBox->setCurrentItem(0); | 334 | edituserDialog->groupComboBox->setCurrentItem(0); |
335 | } | 335 | } |
336 | |||
336 | // Select the groups in the listview, to which the user belongs. | 337 | // Select the groups in the listview, to which the user belongs. |
337 | QCheckListItem *temp; | 338 | QCheckListItem *temp; |
338 | QRegExp userRegExp(QString("[:\\s]%1\\s").arg(username)); | 339 | // BAH!!! QRegExp in qt2 sucks... or maybe I do... can't figure out how to check for EITHER end of input ($) OR a comma, so here we do two different QRegExps instead. |
340 | QRegExp userRegExp(QString("[:,]%1$").arg(username));// The end of line variant. | ||
339 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. | 341 | QStringList tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. |
340 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. | 342 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. |
343 | qWarning(*it); | ||
344 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | ||
345 | for ( ; lvit.current(); ++lvit ) { | ||
346 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { | ||
347 | temp=(QCheckListItem*)lvit.current(); | ||
348 | temp->setOn(true);// If we find a line with that groupname, select it.; | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | userRegExp=QRegExp(QString("[:,]%1,").arg(username));// And the other one. (not end of line.) | ||
353 | tempList=accounts->groupStringList.grep(userRegExp);// Find all entries in the group database, that the user is a member of. | ||
354 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) {// Iterate over all of them. | ||
355 | qWarning(*it); | ||
341 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. | 356 | QListViewItemIterator lvit( edituserDialog->groupsListView );// Compare to all groups. |
342 | for ( ; lvit.current(); ++lvit ) { | 357 | for ( ; lvit.current(); ++lvit ) { |
343 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { | 358 | if(lvit.current()->text(0)==(*it).left((*it).find(":"))) { |
344 | temp=(QCheckListItem*)lvit.current(); | 359 | temp=(QCheckListItem*)lvit.current(); |
345 | temp->setOn(true);// If we find a line with that groupname, select it.; | 360 | temp->setOn(true);// If we find a line with that groupname, select it.; |
346 | } | 361 | } |
347 | } | 362 | } |
348 | } | 363 | } |
349 | 364 | ||
350 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! | 365 | if(!(edituserDialog->exec())) return false;// SHOW THE DIALOG! |
351 | 366 | ||
352 | accounts->findUser(username);// Fill user variables in 'acccounts' object. | 367 | accounts->findUser(username);// Fill user variables in 'acccounts' object. |
353 | accounts->pw_name=edituserDialog->loginLineEdit->text(); | 368 | accounts->pw_name=edituserDialog->loginLineEdit->text(); |
354 | // Has the password been changed ? Make a new "crypt":ed password. | 369 | // Has the password been changed ? Make a new "crypt":ed password. |
355 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); | 370 | if(edituserDialog->passwordLineEdit->text()!="........") accounts->pw_passwd=crypt(edituserDialog->passwordLineEdit->text(), accounts->crypt_make_salt()); |
356 | 371 | ||
357 | // Set all variables in accounts object, that will be used when calling 'updateUser()' | 372 | // Set all variables in accounts object, that will be used when calling 'updateUser()' |
358 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); | 373 | accounts->pw_uid=edituserDialog->uidLineEdit->text().toInt(); |
359 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. | 374 | if(accounts->findGroup(edituserDialog->groupComboBox->currentText())) {// Fill all group variables in 'accounts' object. |
360 | accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. | 375 | accounts->pw_gid=accounts->gr_gid;// Only do this if the group is a valid group (ie. "<Undefined group>"), otherwise keep the old group. |
361 | } | 376 | } |
362 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); | 377 | accounts->pw_gecos=edituserDialog->gecosLineEdit->text(); |
363 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); | 378 | accounts->pw_shell=edituserDialog->shellComboBox->currentText(); |
364 | // Update userinfo, using the information stored in the user variables stored in the accounts object. | 379 | // Update userinfo, using the information stored in the user variables stored in the accounts object. |
365 | accounts->updateUser(username); | 380 | accounts->updateUser(username); |
366 | 381 | ||
367 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) | 382 | // Remove user from all groups he/she is a member of. (could be done in a better way I guess, this was simple though.) |
368 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { | 383 | for(QStringList::Iterator it=tempList.begin(); it!=tempList.end(); ++it) { |
369 | accounts->delGroupMember((*it).left((*it).find(":")),username); | 384 | accounts->delGroupMember((*it).left((*it).find(":")),username); |
370 | } | 385 | } |
371 | 386 | ||
372 | // Add User to additional groups that he/she is a member of. | 387 | // Add User to additional groups that he/she is a member of. |
373 | QListViewItemIterator it( edituserDialog->groupsListView ); | 388 | QListViewItemIterator it( edituserDialog->groupsListView ); |
374 | for ( ; it.current(); ++it ) { | 389 | for ( ; it.current(); ++it ) { |
375 | temp=(QCheckListItem*)it.current(); | 390 | temp=(QCheckListItem*)it.current(); |
376 | if ( temp->isOn() ) | 391 | if ( temp->isOn() ) |
377 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); | 392 | accounts->addGroupMember(it.current()->text(0),edituserDialog->loginLineEdit->text()); |
378 | } | 393 | } |
379 | 394 | ||
380 | // Copy image to pics/users/ | 395 | // Copy image to pics/users/ |
381 | if(!(edituserDialog->userImage.isNull())) { | 396 | if(!(edituserDialog->userImage.isNull())) { |
382 | QDir d; | 397 | QDir d; |
383 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { | 398 | if(!(d.exists("/opt/QtPalmtop/pics/users"))) { |
384 | d.mkdir("/opt/QtPalmtop/pics/users"); | 399 | d.mkdir("/opt/QtPalmtop/pics/users"); |
385 | } | 400 | } |
386 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; | 401 | QString filename="/opt/QtPalmtop/pics/users/"+accounts->pw_name+".png"; |
387 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); | 402 | // edituserDialog->userImage=edituserDialog->userImage.smoothScale(48,48); |
388 | edituserDialog->userImage.save(filename,"PNG"); | 403 | edituserDialog->userImage.save(filename,"PNG"); |
389 | } | 404 | } |
390 | return true; | 405 | return true; |
391 | } | 406 | } |
392 | 407 | ||
393 | /** | 408 | /** |
394 | * "OK" has been clicked. Verify some information before closing the dialog. | 409 | * "OK" has been clicked. Verify some information before closing the dialog. |
395 | * | 410 | * |
396 | */ | 411 | */ |
397 | void UserDialog::accept() { | 412 | void UserDialog::accept() { |
398 | // Add checking... valid username? username taken? | 413 | // Add checking... valid username? username taken? |
399 | if(loginLineEdit->text().isEmpty()) { | 414 | if(loginLineEdit->text().isEmpty()) { |
400 | QMessageBox::information(0,"Empty Login","Please enter a login."); | 415 | QMessageBox::information(0,"Empty Login","Please enter a login."); |
401 | return; | 416 | return; |
402 | } | 417 | } |
403 | QDialog::accept(); | 418 | QDialog::accept(); |
404 | } | 419 | } |
405 | 420 | ||
406 | /** | 421 | /** |
407 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. | 422 | * This slot is called when the usericon is clicked, this loads (should) the iconselector. |
408 | * | 423 | * |
409 | */ | 424 | */ |
410 | void UserDialog::clickedPicture() { | 425 | void UserDialog::clickedPicture() { |
411 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); | 426 | QString filename=OFileDialog::getOpenFileName(OFileSelector::EXTENDED,"/opt/QtPalmtop/pics"); |
412 | if(!(filename.isEmpty())) { | 427 | if(!(filename.isEmpty())) { |
413 | userImage.reset(); | 428 | userImage.reset(); |
414 | if(!(userImage.load(filename))) { | 429 | if(!(userImage.load(filename))) { |
415 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); | 430 | QMessageBox::information(0,"Sorry!","That icon could not be loaded.\nLoading failed on: "+filename); |
416 | } else { | 431 | } else { |
417 | // userImage=userImage.smoothScale(48,48); | 432 | // userImage=userImage.smoothScale(48,48); |
418 | QPixmap *picture; | 433 | QPixmap *picture; |
419 | picture=(QPixmap *)picturePushButton->pixmap(); | 434 | picture=(QPixmap *)picturePushButton->pixmap(); |
420 | picture->convertFromImage(userImage,0); | 435 | picture->convertFromImage(userImage,0); |
421 | picturePushButton->update(); | 436 | picturePushButton->update(); |
422 | } | 437 | } |
423 | } | 438 | } |
424 | } | 439 | } |