aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_reliability.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-10-15 09:15:15 +0000
committerNathan S. Evans <evans@in.tum.de>2010-10-15 09:15:15 +0000
commit30b0be64642d294ab637dd1cc66e97bc4b36276a (patch)
tree3f5dc3c575b49cf598911b2b188c9ad6a1e7b063 /src/transport/test_transport_api_reliability.c
parente7a1d32b0871f484c80b8f7b585cd0b2b6cd93eb (diff)
downloadgnunet-30b0be64642d294ab637dd1cc66e97bc4b36276a.tar.gz
gnunet-30b0be64642d294ab637dd1cc66e97bc4b36276a.zip
fix logging for transport testcase, do suid nat binary check in reliability testcase (execution is pointless)
Diffstat (limited to 'src/transport/test_transport_api_reliability.c')
-rw-r--r--src/transport/test_transport_api_reliability.c185
1 files changed, 151 insertions, 34 deletions
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 01b58f4fe..1f0fcfd3c 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -47,7 +47,7 @@
47 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise 47 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
48 * messages may be dropped even for a reliable transport. 48 * messages may be dropped even for a reliable transport.
49 */ 49 */
50#define TOTAL_MSGS (10000) 50#define TOTAL_MSGS (10000 * 2)
51 51
52/** 52/**
53 * How long until we give up on transmitting the message? 53 * How long until we give up on transmitting the message?
@@ -507,6 +507,116 @@ exchange_hello (void *cls,
507 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); 507 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
508} 508}
509 509
510/**
511 * Return the actual path to a file found in the current
512 * PATH environment variable.
513 *
514 * @param binary the name of the file to find
515 */
516static char *
517get_path_from_PATH (char *binary)
518{
519 char *path;
520 char *pos;
521 char *end;
522 char *buf;
523 const char *p;
524
525 p = getenv ("PATH");
526 if (p == NULL)
527 {
528 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
529 _("PATH environment variable is unset.\n"));
530 return NULL;
531 }
532 path = GNUNET_strdup (p); /* because we write on it */
533 buf = GNUNET_malloc (strlen (path) + 20);
534 pos = path;
535
536 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
537 {
538 *end = '\0';
539 sprintf (buf, "%s/%s", pos, binary);
540 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
541 {
542 GNUNET_free (path);
543 return buf;
544 }
545 pos = end + 1;
546 }
547 sprintf (buf, "%s/%s", pos, binary);
548 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
549 {
550 GNUNET_free (path);
551 return buf;
552 }
553 GNUNET_free (buf);
554 GNUNET_free (path);
555 return NULL;
556}
557
558/**
559 * Check whether the suid bit is set on a file.
560 * Attempts to find the file using the current
561 * PATH environment variable as a search path.
562 *
563 * @param binary the name of the file to check
564 *
565 * @return GNUNET_YES if the binary is found and
566 * can be run properly, GNUNET_NO otherwise
567 */
568static int
569check_gnunet_nat_binary(char *binary)
570{
571 struct stat statbuf;
572 char *p;
573#ifdef MINGW
574 SOCKET rawsock;
575#endif
576
577#ifdef MINGW
578 char *binaryexe;
579 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
580 p = get_path_from_PATH (binaryexe);
581 free (binaryexe);
582#else
583 p = get_path_from_PATH (binary);
584#endif
585 if (p == NULL)
586 {
587 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
588 _("Could not find binary `%s' in PATH!\n"),
589 binary);
590 return GNUNET_NO;
591 }
592 if (0 != STAT (p, &statbuf))
593 {
594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
595 _("stat (%s) failed: %s\n"),
596 p,
597 STRERROR (errno));
598 GNUNET_free (p);
599 return GNUNET_SYSERR;
600 }
601 GNUNET_free (p);
602#ifndef MINGW
603 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
604 (statbuf.st_uid == 0) )
605 return GNUNET_YES;
606 return GNUNET_NO;
607#else
608 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
609 if (INVALID_SOCKET == rawsock)
610 {
611 DWORD err = GetLastError ();
612 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
613 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err);
614 return GNUNET_NO; /* not running as administrator */
615 }
616 closesocket (rawsock);
617 return GNUNET_YES;
618#endif
619}
510 620
511static void 621static void
512run (void *cls, 622run (void *cls,
@@ -573,6 +683,13 @@ check ()
573 setTransportOptions("test_transport_api_data.conf"); 683 setTransportOptions("test_transport_api_data.conf");
574#endif 684#endif
575 ok = 1; 685 ok = 1;
686
687 if ((GNUNET_YES == is_tcp_nat) && (check_gnunet_nat_binary("gnunet-nat-server") != GNUNET_YES))
688 {
689 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Not running NAT test case, binaries not properly installed.\n");
690 return 0;
691 }
692
576 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 693 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
577 argv, "test-transport-api-reliability", "nohelp", 694 argv, "test-transport-api-reliability", "nohelp",
578 options, &run, &ok); 695 options, &run, &ok);
@@ -581,42 +698,42 @@ check ()
581 698
582 if (is_https) 699 if (is_https)
583 { 700 {
584 struct stat sbuf; 701 struct stat sbuf;
585 if (0 == stat (cert_file_p1, &sbuf )) 702 if (0 == stat (cert_file_p1, &sbuf ))
586 { 703 {
587 if (0 == remove(cert_file_p1)) 704 if (0 == remove(cert_file_p1))
588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p1); 705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p1);
589 else 706 else
590 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p1); 707 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p1);
591 } 708 }
592 709
593 if (0 == stat (key_file_p1, &sbuf )) 710 if (0 == stat (key_file_p1, &sbuf ))
594 { 711 {
595 if (0 == remove(key_file_p1)) 712 if (0 == remove(key_file_p1))
596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p1); 713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p1);
597 else 714 else
598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p1); 715 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p1);
599 } 716 }
600 717
601 if (0 == stat (cert_file_p2, &sbuf )) 718 if (0 == stat (cert_file_p2, &sbuf ))
602 { 719 {
603 if (0 == remove(cert_file_p2)) 720 if (0 == remove(cert_file_p2))
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p2); 721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p2);
605 else 722 else
606 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p2); 723 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p2);
607 } 724 }
608 725
609 if (0 == stat (key_file_p2, &sbuf )) 726 if (0 == stat (key_file_p2, &sbuf ))
610 { 727 {
611 if (0 == remove(key_file_p2)) 728 if (0 == remove(key_file_p2))
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p2); 729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p2);
613 else 730 else
614 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p2); 731 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p2);
615 } 732 }
616 GNUNET_free(key_file_p1); 733 GNUNET_free(key_file_p1);
617 GNUNET_free(key_file_p2); 734 GNUNET_free(key_file_p2);
618 GNUNET_free(cert_file_p1); 735 GNUNET_free(cert_file_p1);
619 GNUNET_free(cert_file_p2); 736 GNUNET_free(cert_file_p2);
620 } 737 }
621 738
622 return ok; 739 return ok;