aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-08-30 12:23:34 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-08-30 12:23:34 +0000
commit7797282ed6e91e3af427cbf9bae5372d2de2f79e (patch)
tree2215582be9893b250aca623edd2354b0c520e7a6 /src
parent019ee85a84a9d6657c562b8ea91a567977bd47b3 (diff)
downloadgnunet-7797282ed6e91e3af427cbf9bae5372d2de2f79e.tar.gz
gnunet-7797282ed6e91e3af427cbf9bae5372d2de2f79e.zip
tests now use GNUNET_OS_check_helper_binary to find helper executables
Diffstat (limited to 'src')
-rw-r--r--src/transport/test_transport_api.c134
-rw-r--r--src/transport/test_transport_api_reliability.c133
-rw-r--r--src/transport/test_transport_api_unreliability.c145
3 files changed, 47 insertions, 365 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 */
269static char *
270get_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 */
321static int
322check_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
374int 263int
375main (int argc, char *argv[]) 264main (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);
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 008bb9019..617092676 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -398,121 +398,11 @@ check ()
398 return ok; 398 return ok;
399} 399}
400 400
401/**
402 * Return the actual path to a file found in the current
403 * PATH environment variable.
404 *
405 * @param binary the name of the file to find
406 */
407static char *
408get_path_from_PATH (char *binary)
409{
410 char *path;
411 char *pos;
412 char *end;
413 char *buf;
414 const char *p;
415
416 p = getenv ("PATH");
417 if (p == NULL)
418 {
419 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
420 _("PATH environment variable is unset.\n"));
421 return NULL;
422 }
423 path = GNUNET_strdup (p); /* because we write on it */
424 buf = GNUNET_malloc (strlen (path) + 20);
425 pos = path;
426
427 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
428 {
429 *end = '\0';
430 sprintf (buf, "%s/%s", pos, binary);
431 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
432 {
433 GNUNET_free (path);
434 return buf;
435 }
436 pos = end + 1;
437 }
438 sprintf (buf, "%s/%s", pos, binary);
439 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
440 {
441 GNUNET_free (path);
442 return buf;
443 }
444 GNUNET_free (buf);
445 GNUNET_free (path);
446 return NULL;
447}
448
449/**
450 * Check whether the suid bit is set on a file.
451 * Attempts to find the file using the current
452 * PATH environment variable as a search path.
453 *
454 * @param binary the name of the file to check
455 *
456 * @return GNUNET_YES if the binary is found and
457 * can be run properly, GNUNET_NO otherwise
458 */
459static int
460check_gnunet_nat_binary (char *binary)
461{
462 struct stat statbuf;
463 char *p;
464
465#ifdef MINGW
466 SOCKET rawsock;
467#endif
468
469#ifdef MINGW
470 char *binaryexe;
471
472 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
473 p = get_path_from_PATH (binaryexe);
474 free (binaryexe);
475#else
476 p = get_path_from_PATH (binary);
477#endif
478 if (p == NULL)
479 {
480 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
481 _("Could not find binary `%s' in PATH!\n"), binary);
482 return GNUNET_NO;
483 }
484 if (0 != STAT (p, &statbuf))
485 {
486 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
487 STRERROR (errno));
488 GNUNET_free (p);
489 return GNUNET_SYSERR;
490 }
491 GNUNET_free (p);
492#ifndef MINGW
493 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
494 return GNUNET_YES;
495 return GNUNET_NO;
496#else
497 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
498 if (INVALID_SOCKET == rawsock)
499 {
500 DWORD err = GetLastError ();
501
502 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
503 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n",
504 err);
505 return GNUNET_NO; /* not running as administrator */
506 }
507 closesocket (rawsock);
508 return GNUNET_YES;
509#endif
510}
511
512int 401int
513main (int argc, char *argv[]) 402main (int argc, char *argv[])
514{ 403{
515 int ret; 404 int ret;
405 int nat_res;
516 406
517 GNUNET_log_setup ("test-transport-api", 407 GNUNET_log_setup ("test-transport-api",
518#if VERBOSE 408#if VERBOSE
@@ -545,27 +435,26 @@ main (int argc, char *argv[])
545 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename); 435 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
546 GNUNET_free (backup); 436 GNUNET_free (backup);
547 437
548 if (strstr (argv[0], "tcp_nat") != NULL) 438 if ((strstr (argv[0], "tcp_nat") != NULL) || (strstr (argv[0], "udp_nat") != NULL))
549 { 439 {
550 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server")) 440 nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server");
441 if (GNUNET_NO == nat_res)
551 { 442 {
552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 443 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
553 "`%s' not properly installed, cannot run NAT test!\n", 444 "Cannot run NAT test: `%s' %s \n",
554 "gnunet-nat-server"); 445 "gnunet-nat-server",
446 "SUID not set");
555 return 0; 447 return 0;
556 } 448 }
557 } 449 if (GNUNET_SYSERR == nat_res)
558 else if (strstr (argv[0], "udp_nat") != NULL)
559 {
560 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
561 { 450 {
562 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 451 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
563 "`%s' not properly installed, cannot run NAT test!\n", 452 "Cannot run NAT test: `%s' %s \n",
564 "gnunet-nat-server"); 453 "gnunet-nat-server",
454 "file not found");
565 return 0; 455 return 0;
566 } 456 }
567 } 457 }
568
569 ret = check (); 458 ret = check ();
570 459
571 GNUNET_free (cfg_file_p1); 460 GNUNET_free (cfg_file_p1);
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index 5eed408c0..32ebea221 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -598,119 +598,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
598 GNUNET_assert (p->th != NULL); 598 GNUNET_assert (p->th != NULL);
599} 599}
600 600
601
602/**
603 * Return the actual path to a file found in the current
604 * PATH environment variable.
605 *
606 * @param binary the name of the file to find
607 */
608static char *
609get_path_from_PATH (char *binary)
610{
611 char *path;
612 char *pos;
613 char *end;
614 char *buf;
615 const char *p;
616
617 p = getenv ("PATH");
618 if (p == NULL)
619 {
620 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
621 _("PATH environment variable is unset.\n"));
622 return NULL;
623 }
624 path = GNUNET_strdup (p); /* because we write on it */
625 buf = GNUNET_malloc (strlen (path) + 20);
626 pos = path;
627
628 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
629 {
630 *end = '\0';
631 sprintf (buf, "%s/%s", pos, binary);
632 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
633 {
634 GNUNET_free (path);
635 return buf;
636 }
637 pos = end + 1;
638 }
639 sprintf (buf, "%s/%s", pos, binary);
640 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
641 {
642 GNUNET_free (path);
643 return buf;
644 }
645 GNUNET_free (buf);
646 GNUNET_free (path);
647 return NULL;
648}
649
650/**
651 * Check whether the suid bit is set on a file.
652 * Attempts to find the file using the current
653 * PATH environment variable as a search path.
654 *
655 * @param binary the name of the file to check
656 *
657 * @return GNUNET_YES if the binary is found and
658 * can be run properly, GNUNET_NO otherwise
659 */
660static int
661check_gnunet_nat_binary (char *binary)
662{
663 struct stat statbuf;
664 char *p;
665
666#ifdef MINGW
667 SOCKET rawsock;
668#endif
669
670#ifdef MINGW
671 char *binaryexe;
672
673 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
674 p = get_path_from_PATH (binaryexe);
675 free (binaryexe);
676#else
677 p = get_path_from_PATH (binary);
678#endif
679 if (p == NULL)
680 {
681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
682 _("Could not find binary `%s' in PATH!\n"), binary);
683 return GNUNET_NO;
684 }
685 if (0 != STAT (p, &statbuf))
686 {
687 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p,
688 STRERROR (errno));
689 GNUNET_free (p);
690 return GNUNET_SYSERR;
691 }
692 GNUNET_free (p);
693#ifndef MINGW
694 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
695 return GNUNET_YES;
696 return GNUNET_NO;
697#else
698 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
699 if (INVALID_SOCKET == rawsock)
700 {
701 DWORD err = GetLastError ();
702
703 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
704 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n",
705 err);
706 return GNUNET_NO; /* not running as administrator */
707 }
708 closesocket (rawsock);
709 return GNUNET_YES;
710#endif
711}
712
713
714static void 601static void
715try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 602try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
716{ 603{
@@ -796,14 +683,6 @@ check ()
796#endif 683#endif
797 ok = 1; 684 ok = 1;
798 685
799 if ((GNUNET_YES == is_tcp_nat) &&
800 (check_gnunet_nat_binary ("gnunet-nat-server") != GNUNET_YES))
801 {
802 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
803 "Not running NAT test case, binaries not properly installed.\n");
804 return 0;
805 }
806
807 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 686 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
808 "test-transport-api-unreliability", "nohelp", options, 687 "test-transport-api-unreliability", "nohelp", options,
809 &run, &ok); 688 &run, &ok);
@@ -881,6 +760,7 @@ int
881main (int argc, char *argv[]) 760main (int argc, char *argv[])
882{ 761{
883 int ret; 762 int ret;
763 int nat_res;
884 764
885 test_failed = GNUNET_NO; 765 test_failed = GNUNET_NO;
886 766
@@ -928,6 +808,29 @@ main (int argc, char *argv[])
928 "WARNING", 808 "WARNING",
929#endif 809#endif
930 NULL); 810 NULL);
811
812
813 if ((strstr (argv[0], "tcp_nat") != NULL) || (strstr (argv[0], "udp_nat") != NULL))
814 {
815 nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server");
816 if (GNUNET_NO == nat_res)
817 {
818 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
819 "Cannot run NAT test: `%s' %s \n",
820 "gnunet-nat-server",
821 "SUID not set");
822 return 0;
823 }
824 if (GNUNET_SYSERR == nat_res)
825 {
826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
827 "Cannot run NAT test: `%s' %s \n",
828 "gnunet-nat-server",
829 "file not found");
830 return 0;
831 }
832 }
833
931 ret = check (); 834 ret = check ();
932 835
933 GNUNET_free_non_null (test_name); 836 GNUNET_free_non_null (test_name);