diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-30 12:23:34 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-08-30 12:23:34 +0000 |
commit | 7797282ed6e91e3af427cbf9bae5372d2de2f79e (patch) | |
tree | 2215582be9893b250aca623edd2354b0c520e7a6 /src/transport/test_transport_api.c | |
parent | 019ee85a84a9d6657c562b8ea91a567977bd47b3 (diff) | |
download | gnunet-7797282ed6e91e3af427cbf9bae5372d2de2f79e.tar.gz gnunet-7797282ed6e91e3af427cbf9bae5372d2de2f79e.zip |
tests now use GNUNET_OS_check_helper_binary to find helper executables
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r-- | src/transport/test_transport_api.c | 134 |
1 files changed, 12 insertions, 122 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 29b465845..8f05d996d 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -260,117 +260,6 @@ check () | |||
260 | return ok; | 260 | return ok; |
261 | } | 261 | } |
262 | 262 | ||
263 | /** | ||
264 | * Return the actual path to a file found in the current | ||
265 | * PATH environment variable. | ||
266 | * | ||
267 | * @param binary the name of the file to find | ||
268 | */ | ||
269 | static char * | ||
270 | get_path_from_PATH (char *binary) | ||
271 | { | ||
272 | char *path; | ||
273 | char *pos; | ||
274 | char *end; | ||
275 | char *buf; | ||
276 | const char *p; | ||
277 | |||
278 | p = getenv ("PATH"); | ||
279 | if (p == NULL) | ||
280 | { | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
282 | _("PATH environment variable is unset.\n")); | ||
283 | return NULL; | ||
284 | } | ||
285 | path = GNUNET_strdup (p); /* because we write on it */ | ||
286 | buf = GNUNET_malloc (strlen (path) + 20); | ||
287 | pos = path; | ||
288 | |||
289 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) | ||
290 | { | ||
291 | *end = '\0'; | ||
292 | sprintf (buf, "%s/%s", pos, binary); | ||
293 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
294 | { | ||
295 | GNUNET_free (path); | ||
296 | return buf; | ||
297 | } | ||
298 | pos = end + 1; | ||
299 | } | ||
300 | sprintf (buf, "%s/%s", pos, binary); | ||
301 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
302 | { | ||
303 | GNUNET_free (path); | ||
304 | return buf; | ||
305 | } | ||
306 | GNUNET_free (buf); | ||
307 | GNUNET_free (path); | ||
308 | return NULL; | ||
309 | } | ||
310 | |||
311 | /** | ||
312 | * Check whether the suid bit is set on a file. | ||
313 | * Attempts to find the file using the current | ||
314 | * PATH environment variable as a search path. | ||
315 | * | ||
316 | * @param binary the name of the file to check | ||
317 | * | ||
318 | * @return GNUNET_YES if the binary is found and | ||
319 | * can be run properly, GNUNET_NO otherwise | ||
320 | */ | ||
321 | static int | ||
322 | check_gnunet_nat_binary (char *binary) | ||
323 | { | ||
324 | struct stat statbuf; | ||
325 | char *p; | ||
326 | |||
327 | #ifdef MINGW | ||
328 | SOCKET rawsock; | ||
329 | #endif | ||
330 | |||
331 | #ifdef MINGW | ||
332 | char *binaryexe; | ||
333 | |||
334 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); | ||
335 | p = get_path_from_PATH (binaryexe); | ||
336 | free (binaryexe); | ||
337 | #else | ||
338 | p = get_path_from_PATH (binary); | ||
339 | #endif | ||
340 | if (p == NULL) | ||
341 | { | ||
342 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
343 | _("Could not find binary `%s' in PATH!\n"), binary); | ||
344 | return GNUNET_NO; | ||
345 | } | ||
346 | if (0 != STAT (p, &statbuf)) | ||
347 | { | ||
348 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p, | ||
349 | STRERROR (errno)); | ||
350 | GNUNET_free (p); | ||
351 | return GNUNET_SYSERR; | ||
352 | } | ||
353 | GNUNET_free (p); | ||
354 | #ifndef MINGW | ||
355 | if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) | ||
356 | return GNUNET_YES; | ||
357 | return GNUNET_NO; | ||
358 | #else | ||
359 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); | ||
360 | if (INVALID_SOCKET == rawsock) | ||
361 | { | ||
362 | DWORD err = GetLastError (); | ||
363 | |||
364 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
365 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", | ||
366 | err); | ||
367 | return GNUNET_NO; /* not running as administrator */ | ||
368 | } | ||
369 | closesocket (rawsock); | ||
370 | return GNUNET_YES; | ||
371 | #endif | ||
372 | } | ||
373 | |||
374 | int | 263 | int |
375 | main (int argc, char *argv[]) | 264 | main (int argc, char *argv[]) |
376 | { | 265 | { |
@@ -388,6 +277,7 @@ main (int argc, char *argv[]) | |||
388 | char *backup = pch; | 277 | char *backup = pch; |
389 | char *filename = NULL; | 278 | char *filename = NULL; |
390 | char *dotexe; | 279 | char *dotexe; |
280 | int nat_res; | ||
391 | 281 | ||
392 | /* get executable filename */ | 282 | /* get executable filename */ |
393 | pch = strtok (pch, "/"); | 283 | pch = strtok (pch, "/"); |
@@ -407,27 +297,27 @@ main (int argc, char *argv[]) | |||
407 | GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename); | 297 | GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename); |
408 | GNUNET_free (backup); | 298 | GNUNET_free (backup); |
409 | 299 | ||
410 | if (strstr (argv[0], "tcp_nat") != NULL) | 300 | if ((strstr (argv[0], "tcp_nat") != NULL) || (strstr (argv[0], "udp_nat") != NULL)) |
411 | { | 301 | { |
412 | if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server")) | 302 | nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); |
303 | if (GNUNET_NO == nat_res) | ||
413 | { | 304 | { |
414 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 305 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
415 | "`%s' not properly installed, cannot run NAT test!\n", | 306 | "Cannot run NAT test: `%s' %s \n", |
416 | "gnunet-nat-server"); | 307 | "gnunet-nat-server", |
308 | "SUID not set"); | ||
417 | return 0; | 309 | return 0; |
418 | } | 310 | } |
419 | } | 311 | if (GNUNET_SYSERR == nat_res) |
420 | else if (strstr (argv[0], "udp_nat") != NULL) | ||
421 | { | ||
422 | if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server")) | ||
423 | { | 312 | { |
424 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
425 | "`%s' not properly installed, cannot run NAT test!\n", | 314 | "Cannot run NAT test: `%s' %s \n", |
426 | "gnunet-nat-server"); | 315 | "gnunet-nat-server", |
316 | "file not found"); | ||
427 | return 0; | 317 | return 0; |
428 | } | 318 | } |
429 | } | ||
430 | 319 | ||
320 | } | ||
431 | ret = check (); | 321 | ret = check (); |
432 | 322 | ||
433 | GNUNET_free (cfg_file_p1); | 323 | GNUNET_free (cfg_file_p1); |