aboutsummaryrefslogtreecommitdiff
path: root/src/pt
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-29 23:15:36 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-06-29 23:15:36 +0000
commit17831db01eb1033d04b0b535b808b124f1f75a00 (patch)
treeab379f1a5c0d792ee86988118e627c4fd0f48844 /src/pt
parentf501080b97356351732aee8302de888e89a1b502 (diff)
downloadgnunet-17831db01eb1033d04b0b535b808b124f1f75a00.tar.gz
gnunet-17831db01eb1033d04b0b535b808b124f1f75a00.zip
-check for ipt
Diffstat (limited to 'src/pt')
-rw-r--r--src/pt/test_gns_vpn.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c
index 6a5aa5e61..9789ce7d9 100644
--- a/src/pt/test_gns_vpn.c
+++ b/src/pt/test_gns_vpn.c
@@ -437,9 +437,88 @@ test_af (int af)
437} 437}
438 438
439 439
440/**
441 * Run the given command and wait for it to complete.
442 *
443 * @param file name of the binary to run
444 * @param cmd command line arguments (as given to 'execv')
445 * @return 0 on success, 1 on any error
446 */
447static int
448fork_and_exec (const char *file,
449 char *const cmd[])
450{
451 int status;
452 pid_t pid;
453 pid_t ret;
454
455 pid = fork ();
456 if (-1 == pid)
457 {
458 fprintf (stderr,
459 "fork failed: %s\n",
460 strerror (errno));
461 return 1;
462 }
463 if (0 == pid)
464 {
465 /* we are the child process */
466 /* close stdin/stdout to not cause interference
467 with the helper's main protocol! */
468 (void) close (0);
469 (void) close (1);
470 (void) execv (file, cmd);
471 /* can only get here on error */
472 fprintf (stderr,
473 "exec `%s' failed: %s\n",
474 file,
475 strerror (errno));
476 _exit (1);
477 }
478 /* keep running waitpid as long as the only error we get is 'EINTR' */
479 while ( (-1 == (ret = waitpid (pid, &status, 0))) &&
480 (errno == EINTR) );
481 if (-1 == ret)
482 {
483 fprintf (stderr,
484 "waitpid failed: %s\n",
485 strerror (errno));
486 return 1;
487 }
488 if (! (WIFEXITED (status) && (0 == WEXITSTATUS (status))))
489 return 1;
490 /* child process completed and returned success, we're happy */
491 return 0;
492}
493
440int 494int
441main (int argc, char *const *argv) 495main (int argc, char *const *argv)
442{ 496{
497 char *sbin_iptables;
498 char *const iptables_args[] =
499 {
500 "iptables", "-t", "mangle", "-L", "-v", NULL
501 };
502
503 if (0 == access ("/sbin/iptables", X_OK))
504 sbin_iptables = "/sbin/iptables";
505 else if (0 == access ("/usr/sbin/iptables", X_OK))
506 sbin_iptables = "/usr/sbin/iptables";
507 else
508 {
509 fprintf (stderr,
510 "Executable iptables not found in approved directories: %s, skipping\n",
511 strerror (errno));
512 return 0;
513 }
514
515 if (0 != fork_and_exec (sbin_iptables, iptables_args))
516 {
517 fprintf (stderr,
518 "IPtables not available, Skipping.\n");
519 return 0;
520 }
521
443 if (0 != ACCESS ("/dev/net/tun", R_OK)) 522 if (0 != ACCESS ("/dev/net/tun", R_OK))
444 { 523 {
445 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 524 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
@@ -449,6 +528,7 @@ main (int argc, char *const *argv)
449 "WARNING: System unable to run test, skipping.\n"); 528 "WARNING: System unable to run test, skipping.\n");
450 return 0; 529 return 0;
451 } 530 }
531
452 if ( (GNUNET_YES != 532 if ( (GNUNET_YES !=
453 GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) || 533 GNUNET_OS_check_helper_binary ("gnunet-helper-vpn")) ||
454 (GNUNET_YES != 534 (GNUNET_YES !=