Diffstat (limited to 'noncore/settings/networksettings/ppp/runtests.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/runtests.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/noncore/settings/networksettings/ppp/runtests.cpp b/noncore/settings/networksettings/ppp/runtests.cpp index 83ef2ea..5548601 100644 --- a/noncore/settings/networksettings/ppp/runtests.cpp +++ b/noncore/settings/networksettings/ppp/runtests.cpp | |||
@@ -1,96 +1,94 @@ | |||
1 | /* | 1 | /* |
2 | * kPPP: A pppd front end for the KDE project | 2 | * kPPP: A pppd front end for the KDE project |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | * | 5 | * |
6 | * Copyright (C) 1997 Bernd Johannes Wuebben | 6 | * Copyright (C) 1997 Bernd Johannes Wuebben |
7 | * wuebben@math.cornell.edu | 7 | * wuebben@math.cornell.edu |
8 | * | 8 | * |
9 | * This file was contributed by Mario Weilguni <mweilguni@sime.com> | 9 | * This file was contributed by Mario Weilguni <mweilguni@sime.com> |
10 | * Thanks Mario ! | 10 | * Thanks Mario ! |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or | 12 | * This program is free software; you can redistribute it and/or |
13 | * modify it under the terms of the GNU Library General Public | 13 | * modify it under the terms of the GNU Library General Public |
14 | * License as published by the Free Software Foundation; either | 14 | * License as published by the Free Software Foundation; either |
15 | * version 2 of the License, or (at your option) any later version. | 15 | * version 2 of the License, or (at your option) any later version. |
16 | * | 16 | * |
17 | * This program is distributed in the hope that it will be useful, | 17 | * This program is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
20 | * Library General Public License for more details. | 20 | * Library General Public License for more details. |
21 | * | 21 | * |
22 | * You should have received a copy of the GNU Library General Public | 22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with this program; if not, write to the Free | 23 | * License along with this program; if not, write to the Free |
24 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 24 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include <qdir.h> | 27 | #include <qdir.h> |
28 | #include "runtests.h" | 28 | #include "runtests.h" |
29 | #include <ctype.h> | 29 | #include <ctype.h> |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | #include <qmessagebox.h> | 31 | #include <qmessagebox.h> |
32 | #include <sys/stat.h> | 32 | #include <sys/stat.h> |
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | #include <sys/types.h> | 34 | #include <sys/types.h> |
35 | #include <pwd.h> | 35 | #include <pwd.h> |
36 | #include <netinet/in.h> | 36 | #include <netinet/in.h> |
37 | 37 | ||
38 | #ifdef HAVE_RESOLV_H | 38 | #ifdef HAVE_RESOLV_H |
39 | #include <arpa/nameser.h> | 39 | #include <arpa/nameser.h> |
40 | #include <resolv.h> | 40 | #include <resolv.h> |
41 | #endif | 41 | #endif |
42 | 42 | ||
43 | #ifndef _PATH_RESCONF | 43 | #ifndef _PATH_RESCONF |
44 | #define _PATH_RESCONF "/etc/resolv.conf" | 44 | #define _PATH_RESCONF "/etc/resolv.conf" |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | //#include <klocale.h> | ||
48 | #define i18n QObject::tr | ||
49 | #include "pppdata.h" | 47 | #include "pppdata.h" |
50 | 48 | ||
51 | // initial effective uid (main.cpp) | 49 | // initial effective uid (main.cpp) |
52 | extern uid_t euid; | 50 | extern uid_t euid; |
53 | 51 | ||
54 | // secure pppd location (opener.cpp) | 52 | // secure pppd location (opener.cpp) |
55 | extern const char* pppdPath(); | 53 | extern const char* pppdPath(); |
56 | 54 | ||
57 | // shamelessly stolen from pppd-2.3.5 | 55 | // shamelessly stolen from pppd-2.3.5 |
58 | /******************************************************************** | 56 | /******************************************************************** |
59 | * | 57 | * |
60 | * Internal routine to decode the version.modification.patch level | 58 | * Internal routine to decode the version.modification.patch level |
61 | */ | 59 | */ |
62 | 60 | ||
63 | static void decode_version (const char *_buf, int *version, | 61 | static void decode_version (const char *_buf, int *version, |
64 | int *modification, int *patch) | 62 | int *modification, int *patch) |
65 | { | 63 | { |
66 | char *buffer = qstrdup(_buf); | 64 | char *buffer = qstrdup(_buf); |
67 | char *buf = buffer; | 65 | char *buf = buffer; |
68 | *version = (int) strtoul (buf, &buf, 10); | 66 | *version = (int) strtoul (buf, &buf, 10); |
69 | *modification = 0; | 67 | *modification = 0; |
70 | *patch = 0; | 68 | *patch = 0; |
71 | 69 | ||
72 | if (*buf == '.') | 70 | if (*buf == '.') |
73 | { | 71 | { |
74 | ++buf; | 72 | ++buf; |
75 | *modification = (int) strtoul (buf, &buf, 10); | 73 | *modification = (int) strtoul (buf, &buf, 10); |
76 | if (*buf == '.') | 74 | if (*buf == '.') |
77 | { | 75 | { |
78 | ++buf; | 76 | ++buf; |
79 | *patch = (int) strtoul (buf, &buf, 10); | 77 | *patch = (int) strtoul (buf, &buf, 10); |
80 | } | 78 | } |
81 | } | 79 | } |
82 | 80 | ||
83 | if (*buf != '\0') | 81 | if (*buf != '\0') |
84 | { | 82 | { |
85 | *version = | 83 | *version = |
86 | *modification = | 84 | *modification = |
87 | *patch = 0; | 85 | *patch = 0; |
88 | } | 86 | } |
89 | 87 | ||
90 | delete [] buffer; | 88 | delete [] buffer; |
91 | } | 89 | } |
92 | 90 | ||
93 | 91 | ||
94 | void pppdVersion(int *version, int *modification, int *patch) { | 92 | void pppdVersion(int *version, int *modification, int *patch) { |
95 | char buffer[30]; | 93 | char buffer[30]; |
96 | const char *pppd; | 94 | const char *pppd; |
@@ -172,108 +170,108 @@ const char *homedirFromUid(uid_t uid) { | |||
172 | 170 | ||
173 | endpwent(); | 171 | endpwent(); |
174 | return d; | 172 | return d; |
175 | } | 173 | } |
176 | 174 | ||
177 | 175 | ||
178 | const char* getHomeDir() { | 176 | const char* getHomeDir() { |
179 | static const char *hd = 0; | 177 | static const char *hd = 0; |
180 | static bool ranTest = false; | 178 | static bool ranTest = false; |
181 | if(!ranTest) { | 179 | if(!ranTest) { |
182 | hd = homedirFromUid(getuid()); | 180 | hd = homedirFromUid(getuid()); |
183 | ranTest = true; | 181 | ranTest = true; |
184 | } | 182 | } |
185 | 183 | ||
186 | return hd; | 184 | return hd; |
187 | } | 185 | } |
188 | 186 | ||
189 | 187 | ||
190 | int runTests() { | 188 | int runTests() { |
191 | int warning = 0; | 189 | int warning = 0; |
192 | 190 | ||
193 | // Test pre-1: check if the user is allowed to dial-out | 191 | // Test pre-1: check if the user is allowed to dial-out |
194 | if(access("/etc/kppp.allow", R_OK) == 0 && getuid() != 0) { | 192 | if(access("/etc/kppp.allow", R_OK) == 0 && getuid() != 0) { |
195 | bool access = FALSE; | 193 | bool access = FALSE; |
196 | FILE *f; | 194 | FILE *f; |
197 | if((f = fopen("/etc/kppp.allow", "r")) != NULL) { | 195 | if((f = fopen("/etc/kppp.allow", "r")) != NULL) { |
198 | char buf[2048]; // safe | 196 | char buf[2048]; // safe |
199 | while(f != NULL && !feof(f)) { | 197 | while(f != NULL && !feof(f)) { |
200 | if(fgets(buf, sizeof(buf), f) != NULL) { | 198 | if(fgets(buf, sizeof(buf), f) != NULL) { |
201 | QString s(buf); | 199 | QString s(buf); |
202 | 200 | ||
203 | s = s.stripWhiteSpace(); | 201 | s = s.stripWhiteSpace(); |
204 | if(s[0] == '#' || s.length() == 0) | 202 | if(s[0] == '#' || s.length() == 0) |
205 | continue; | 203 | continue; |
206 | 204 | ||
207 | if((uid_t)uidFromName(QFile::encodeName(s)) == getuid()) { | 205 | if((uid_t)uidFromName(QFile::encodeName(s)) == getuid()) { |
208 | access = TRUE; | 206 | access = TRUE; |
209 | fclose(f); | 207 | fclose(f); |
210 | f = NULL; | 208 | f = NULL; |
211 | } | 209 | } |
212 | } | 210 | } |
213 | } | 211 | } |
214 | if(f) | 212 | if(f) |
215 | fclose(f); | 213 | fclose(f); |
216 | } | 214 | } |
217 | 215 | ||
218 | if(!access) { | 216 | if(!access) { |
219 | QMessageBox::warning(0,"error", | 217 | QMessageBox::warning(0,"error", |
220 | i18n("You're not allowed to dial out with " | 218 | QObject::tr("You're not allowed to dial out with " |
221 | "kppp.\nContact your system administrator.")); | 219 | "kppp.\nContact your system administrator.")); |
222 | return TEST_CRITICAL; | 220 | return TEST_CRITICAL; |
223 | } | 221 | } |
224 | } | 222 | } |
225 | 223 | ||
226 | // Test 1: search the pppd binary | 224 | // Test 1: search the pppd binary |
227 | const char *f = pppdPath(); | 225 | const char *f = pppdPath(); |
228 | 226 | ||
229 | if(!f) { | 227 | if(!f) { |
230 | QMessageBox::warning(0,"error", | 228 | QMessageBox::warning(0,"error", |
231 | i18n("Cannot find the PPP daemon!\n" | 229 | QObject::tr("Cannot find the PPP daemon!\n" |
232 | "Make sure that pppd is installed.")); | 230 | "Make sure that pppd is installed.")); |
233 | warning++; | 231 | warning++; |
234 | } | 232 | } |
235 | 233 | ||
236 | // Test 2: check access to the pppd binary | 234 | // Test 2: check access to the pppd binary |
237 | if(f) { | 235 | if(f) { |
238 | #if 0 | 236 | #if 0 |
239 | if(access(f, X_OK) != 0 /* && geteuid() != 0 */) { | 237 | if(access(f, X_OK) != 0 /* && geteuid() != 0 */) { |
240 | KMessageBox::warning(0, | 238 | KMessageBox::warning(0, |
241 | i18n("You do not have the permission " | 239 | QObject::tr("You do not have the permission " |
242 | "to start pppd!\n" | 240 | "to start pppd!\n" |
243 | "Contact your system administrator " | 241 | "Contact your system administrator " |
244 | "and ask to get access to pppd.")); | 242 | "and ask to get access to pppd.")); |
245 | return TEST_CRITICAL; | 243 | return TEST_CRITICAL; |
246 | } | 244 | } |
247 | #endif | 245 | #endif |
248 | 246 | ||
249 | if(geteuid() != 0) { | 247 | if(geteuid() != 0) { |
250 | struct stat st; | 248 | struct stat st; |
251 | stat(f, &st); | 249 | stat(f, &st); |
252 | if(st.st_uid != 0 || (st.st_mode & S_ISUID) == 0) { | 250 | if(st.st_uid != 0 || (st.st_mode & S_ISUID) == 0) { |
253 | QMessageBox::warning(0,"error", | 251 | QMessageBox::warning(0,"error", |
254 | i18n("You don't have sufficient permission to run\n" | 252 | QObject::tr("You don't have sufficient permission to run\n" |
255 | "%1\n" | 253 | "%1\n" |
256 | "Please make sure that kppp is owned by root " | 254 | "Please make sure that kppp is owned by root " |
257 | "and has the SUID bit set.").arg(f)); | 255 | "and has the SUID bit set.").arg(f)); |
258 | warning++; | 256 | warning++; |
259 | } | 257 | } |
260 | } | 258 | } |
261 | } | 259 | } |
262 | 260 | ||
263 | // Test 5: check for existence of /etc/resolv.conf | 261 | // Test 5: check for existence of /etc/resolv.conf |
264 | if (access(_PATH_RESCONF, R_OK) != 0) { | 262 | if (access(_PATH_RESCONF, R_OK) != 0) { |
265 | QString file = _PATH_RESCONF" "; | 263 | QString file = _PATH_RESCONF" "; |
266 | QString msgstr = i18n("%1 is missing or can't be read!\n" | 264 | QString msgstr = QObject::tr("%1 is missing or can't be read!\n" |
267 | "Ask your system administrator to create " | 265 | "Ask your system administrator to create " |
268 | "this file (can be empty) with appropriate " | 266 | "this file (can be empty) with appropriate " |
269 | "read and write permissions.").arg(file); | 267 | "read and write permissions.").arg(file); |
270 | QMessageBox::warning(0, "errror", msgstr); | 268 | QMessageBox::warning(0, "errror", msgstr); |
271 | warning ++; | 269 | warning ++; |
272 | } | 270 | } |
273 | 271 | ||
274 | if(warning == 0) | 272 | if(warning == 0) |
275 | return TEST_OK; | 273 | return TEST_OK; |
276 | else | 274 | else |
277 | return TEST_WARNING; | 275 | return TEST_WARNING; |
278 | } | 276 | } |
279 | 277 | ||