aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_transport_api.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-12-14 15:00:26 +0000
committerNathan S. Evans <evans@in.tum.de>2010-12-14 15:00:26 +0000
commitbdf316f723e8a1fd00fd1dac9a938c587a4ee6c1 (patch)
tree1c528d89ad124cf831ce17dbff156a294d9c9202 /src/transport/test_transport_api.c
parent99c2ab83dc36639d4ac9f46ef2362892f35775d9 (diff)
downloadgnunet-bdf316f723e8a1fd00fd1dac9a938c587a4ee6c1.tar.gz
gnunet-bdf316f723e8a1fd00fd1dac9a938c587a4ee6c1.zip
windoze friendly check for nat binaries
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r--src/transport/test_transport_api.c79
1 files changed, 66 insertions, 13 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 7ef60bdaa..c115d1e5d 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -470,9 +470,14 @@ check ()
470 return ok; 470 return ok;
471} 471}
472 472
473 473/**
474 * Return the actual path to a file found in the current
475 * PATH environment variable.
476 *
477 * @param binary the name of the file to find
478 */
474static char * 479static char *
475get_path_from_PATH () 480get_path_from_PATH (char *binary)
476{ 481{
477 char *path; 482 char *path;
478 char *pos; 483 char *pos;
@@ -482,7 +487,11 @@ get_path_from_PATH ()
482 487
483 p = getenv ("PATH"); 488 p = getenv ("PATH");
484 if (p == NULL) 489 if (p == NULL)
485 return NULL; 490 {
491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
492 _("PATH environment variable is unset.\n"));
493 return NULL;
494 }
486 path = GNUNET_strdup (p); /* because we write on it */ 495 path = GNUNET_strdup (p); /* because we write on it */
487 buf = GNUNET_malloc (strlen (path) + 20); 496 buf = GNUNET_malloc (strlen (path) + 20);
488 pos = path; 497 pos = path;
@@ -490,7 +499,7 @@ get_path_from_PATH ()
490 while (NULL != (end = strchr (pos, PATH_SEPARATOR))) 499 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
491 { 500 {
492 *end = '\0'; 501 *end = '\0';
493 sprintf (buf, "%s/%s", pos, "gnunet-nat-server"); 502 sprintf (buf, "%s/%s", pos, binary);
494 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 503 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
495 { 504 {
496 GNUNET_free (path); 505 GNUNET_free (path);
@@ -498,34 +507,78 @@ get_path_from_PATH ()
498 } 507 }
499 pos = end + 1; 508 pos = end + 1;
500 } 509 }
501 sprintf (buf, "%s/%s", pos, "gnunet-nat-server"); 510 sprintf (buf, "%s/%s", pos, binary);
502 GNUNET_free (path);
503 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 511 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
504 return buf; 512 {
513 GNUNET_free (path);
514 return buf;
515 }
505 GNUNET_free (buf); 516 GNUNET_free (buf);
517 GNUNET_free (path);
506 return NULL; 518 return NULL;
507} 519}
508 520
509 521/**
522 * Check whether the suid bit is set on a file.
523 * Attempts to find the file using the current
524 * PATH environment variable as a search path.
525 *
526 * @param binary the name of the file to check
527 *
528 * @return GNUNET_YES if the binary is found and
529 * can be run properly, GNUNET_NO otherwise
530 */
510static int 531static int
511check_gnunet_nat_server() 532check_gnunet_nat_binary(char *binary)
512{ 533{
513 struct stat statbuf; 534 struct stat statbuf;
514 char *p; 535 char *p;
536#ifdef MINGW
537 SOCKET rawsock;
538#endif
515 539
516 p = get_path_from_PATH (); 540#ifdef MINGW
541 char *binaryexe;
542 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
543 p = get_path_from_PATH (binaryexe);
544 free (binaryexe);
545#else
546 p = get_path_from_PATH (binary);
547#endif
517 if (p == NULL) 548 if (p == NULL)
518 return GNUNET_NO; 549 {
550 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
551 _("Could not find binary `%s' in PATH!\n"),
552 binary);
553 return GNUNET_NO;
554 }
519 if (0 != STAT (p, &statbuf)) 555 if (0 != STAT (p, &statbuf))
520 { 556 {
557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
558 _("stat (%s) failed: %s\n"),
559 p,
560 STRERROR (errno));
521 GNUNET_free (p); 561 GNUNET_free (p);
522 return GNUNET_SYSERR; 562 return GNUNET_SYSERR;
523 } 563 }
524 GNUNET_free (p); 564 GNUNET_free (p);
565#ifndef MINGW
525 if ( (0 != (statbuf.st_mode & S_ISUID)) && 566 if ( (0 != (statbuf.st_mode & S_ISUID)) &&
526 (statbuf.st_uid == 0) ) 567 (statbuf.st_uid == 0) )
527 return GNUNET_YES; 568 return GNUNET_YES;
528 return GNUNET_NO; 569 return GNUNET_NO;
570#else
571 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
572 if (INVALID_SOCKET == rawsock)
573 {
574 DWORD err = GetLastError ();
575 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
576 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err);
577 return GNUNET_NO; /* not running as administrator */
578 }
579 closesocket (rawsock);
580 return GNUNET_YES;
581#endif
529} 582}
530 583
531int 584int
@@ -547,7 +600,7 @@ main (int argc, char *argv[])
547 if (strstr(argv[0], "tcp_nat") != NULL) 600 if (strstr(argv[0], "tcp_nat") != NULL)
548 { 601 {
549 is_tcp_nat = GNUNET_YES; 602 is_tcp_nat = GNUNET_YES;
550 if (check_gnunet_nat_server() != GNUNET_OK) 603 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
551 { 604 {
552 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 605 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
553 "`%s' not properly installed, cannot run NAT test!\n", 606 "`%s' not properly installed, cannot run NAT test!\n",
@@ -562,7 +615,7 @@ main (int argc, char *argv[])
562 else if (strstr(argv[0], "udp_nat") != NULL) 615 else if (strstr(argv[0], "udp_nat") != NULL)
563 { 616 {
564 is_udp_nat = GNUNET_YES; 617 is_udp_nat = GNUNET_YES;
565 if (check_gnunet_nat_server() != GNUNET_OK) 618 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
566 { 619 {
567 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 620 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
568 "`%s' not properly installed, cannot run NAT test!\n", 621 "`%s' not properly installed, cannot run NAT test!\n",