aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api_unreliability.c
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/transport/test_transport_api_unreliability.c
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/transport/test_transport_api_unreliability.c')
-rw-r--r--src/transport/test_transport_api_unreliability.c145
1 files changed, 24 insertions, 121 deletions
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);