diff options
Diffstat (limited to 'src/transport/test_transport_api.c')
-rw-r--r-- | src/transport/test_transport_api.c | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 2db990e82..50bc02956 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include "gnunet_transport_service.h" | 36 | #include "gnunet_transport_service.h" |
37 | #include "transport.h" | 37 | #include "transport.h" |
38 | 38 | ||
39 | #define VERBOSE GNUNET_YES | 39 | #define VERBOSE GNUNET_NO |
40 | 40 | ||
41 | #define VERBOSE_ARM GNUNET_NO | 41 | #define VERBOSE_ARM GNUNET_NO |
42 | 42 | ||
@@ -335,20 +335,83 @@ check () | |||
335 | return ok; | 335 | return ok; |
336 | } | 336 | } |
337 | 337 | ||
338 | |||
339 | static char * | ||
340 | get_path_from_PATH () | ||
341 | { | ||
342 | char *path; | ||
343 | char *pos; | ||
344 | char *end; | ||
345 | char *buf; | ||
346 | const char *p; | ||
347 | |||
348 | p = getenv ("PATH"); | ||
349 | if (p == NULL) | ||
350 | return NULL; | ||
351 | path = GNUNET_strdup (p); /* because we write on it */ | ||
352 | buf = GNUNET_malloc (strlen (path) + 20); | ||
353 | pos = path; | ||
354 | |||
355 | while (NULL != (end = strchr (pos, ':'))) | ||
356 | { | ||
357 | *end = '\0'; | ||
358 | sprintf (buf, "%s/%s", pos, "gnunet-nat-server"); | ||
359 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
360 | { | ||
361 | pos = GNUNET_strdup (buf); | ||
362 | GNUNET_free (buf); | ||
363 | GNUNET_free (path); | ||
364 | return pos; | ||
365 | } | ||
366 | pos = end + 1; | ||
367 | } | ||
368 | sprintf (buf, "%s/%s", pos, "gnunet-nat-server"); | ||
369 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
370 | { | ||
371 | pos = GNUNET_strdup (buf); | ||
372 | GNUNET_free (buf); | ||
373 | GNUNET_free (path); | ||
374 | return pos; | ||
375 | } | ||
376 | GNUNET_free (buf); | ||
377 | GNUNET_free (path); | ||
378 | return NULL; | ||
379 | } | ||
380 | |||
381 | |||
382 | static int check_gnunet_nat_server() | ||
383 | { | ||
384 | struct stat statbuf; | ||
385 | |||
386 | stat(get_path_from_PATH(), &statbuf); | ||
387 | if ((statbuf.st_mode & S_ISUID) && (statbuf.st_uid == 0)) | ||
388 | { | ||
389 | return GNUNET_YES; | ||
390 | } | ||
391 | else | ||
392 | { | ||
393 | return GNUNET_NO; | ||
394 | } | ||
395 | } | ||
396 | |||
338 | int | 397 | int |
339 | main (int argc, char *argv[]) | 398 | main (int argc, char *argv[]) |
340 | { | 399 | { |
341 | int ret; | 400 | int ret; |
342 | 401 | #ifdef MINGW | |
402 | return GNUNET_SYSERR; | ||
403 | #endif | ||
343 | if (strstr(argv[0], "tcp") != NULL) | 404 | if (strstr(argv[0], "tcp") != NULL) |
344 | { | 405 | { |
345 | |||
346 | is_tcp = GNUNET_YES; | 406 | is_tcp = GNUNET_YES; |
347 | } | 407 | } |
348 | else if (strstr(argv[0], "udp_nat") != NULL) | 408 | else if (strstr(argv[0], "udp_nat") != NULL) |
349 | { | 409 | { |
350 | fprintf(stderr, "this is a udp_nat test!\n"); | ||
351 | is_udp_nat = GNUNET_YES; | 410 | is_udp_nat = GNUNET_YES; |
411 | if (check_gnunet_nat_server() == GNUNET_NO) | ||
412 | { | ||
413 | return GNUNET_SYSERR; | ||
414 | } | ||
352 | } | 415 | } |
353 | else if (strstr(argv[0], "udp") != NULL) | 416 | else if (strstr(argv[0], "udp") != NULL) |
354 | { | 417 | { |