Exemplo n.º 1
0
int
main (int argc, char *const *argv)
{

  if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("gnunet-gns-proxy"))
  {
    fprintf (stderr, "Proxy binary not in PATH... skipping!\n");
    return 0;
  }

  if (GNUNET_YES != GNUNET_OS_check_helper_binary ("gnunet-helper-dns"))
  {
    fprintf (stderr, "DNS helper binary has wrong permissions... skipping!\n");
    return 0;
  }

  GNUNET_CRYPTO_rsa_setup_hostkey ("test_gns_proxy.conf");
  
  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
  {
    fprintf (stderr, "failed to initialize curl\n");
    return 2;
  }
  if (0 != GNUNET_TESTING_peer_run ("test-gnunet-gns-proxy",
				    "test_gns_proxy.conf",
				    &run, NULL))
    return 1;
  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-gns-proxy");
  return global_ret;
}
Exemplo n.º 2
0
int
main (int argc, char *const *argv)
{
  char *binary;

  if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("gnunet-gns-proxy", GNUNET_NO, NULL))
  {
    fprintf (stderr, "Proxy binary not in PATH... skipping!\n");
    return 0;
  }
  binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-dns");
  if (GNUNET_YES != GNUNET_OS_check_helper_binary (binary, GNUNET_YES, NULL)) // TODO: once we have a windows-testcase, add test parameters here
  {
    fprintf (stderr, "DNS helper binary has wrong permissions... skipping!\n");
    GNUNET_free (binary);
    return 0;
  }
    GNUNET_free (binary);

  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
  {
    fprintf (stderr, "failed to initialize curl\n");
    return 2;
  }
  if (0 != GNUNET_TESTING_peer_run ("test-gnunet-gns-proxy",
				    "test_gns_proxy.conf",
				    &run, NULL))
    return 1;
  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-gns-proxy");
  return global_ret;
}
Exemplo n.º 3
0
/**
 * Start mapping the given port using (mini)upnpc.  This function
 * should typically not be used directly (it is used within the
 * general-purpose #GNUNET_NAT_register() code).  However, it can be
 * used if specifically UPnP-based NAT traversal is to be used or
 * tested.
 *
 * @param port port to map
 * @param is_tcp #GNUNET_YES to map TCP, #GNUNET_NO for UDP
 * @param ac function to call with mapping result
 * @param ac_cls closure for @a ac
 * @return NULL on error (no 'upnpc' installed)
 */
struct GNUNET_NAT_MiniHandle *
GNUNET_NAT_mini_map_start (uint16_t port,
                           int is_tcp,
                           GNUNET_NAT_MiniAddressCallback ac,
                           void *ac_cls)
{
  struct GNUNET_NAT_MiniHandle *ret;

  if (GNUNET_SYSERR ==
      GNUNET_OS_check_helper_binary ("upnpc",
				     GNUNET_NO,
				     NULL))
  {
    LOG (GNUNET_ERROR_TYPE_INFO,
	 _("`upnpc' command not found\n"));
    ac (ac_cls,
        GNUNET_SYSERR,
        NULL, 0,
        GNUNET_NAT_ERROR_UPNPC_NOT_FOUND);
    return NULL;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Running `upnpc' to install mapping\n");
  ret = GNUNET_new (struct GNUNET_NAT_MiniHandle);
  ret->ac = ac;
  ret->ac_cls = ac_cls;
  ret->is_tcp = is_tcp;
  ret->port = port;
  ret->refresh_task =
    GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ,
				  &do_refresh,
				  ret);
  run_upnpc_r (ret);
  return ret;
}
Exemplo n.º 4
0
/**
 * Test if ICMP server is working
 *
 * @param ah auto setup context
 */
static void
test_icmp_server (struct GNUNET_NAT_AutoHandle *ah)
{

  int ext_ip;
  int nated;
  int binary;
  char *tmp;
  char *helper;
  ext_ip = GNUNET_NO;
  nated = GNUNET_NO;
  binary = GNUNET_NO;

  tmp = NULL;
  helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server");
  if ((GNUNET_OK ==
        GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "EXTERNAL_ADDRESS",
                                               &tmp)) && (0 < strlen (tmp))){
    ext_ip = GNUNET_OK;
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we have no public IPv4 address\n"));
  }
  else
    goto err;

  if (GNUNET_YES ==
        GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){
    nated = GNUNET_YES;
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n"));
  }
  else
    goto err;

  if (GNUNET_YES ==
        GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1" )){
    binary = GNUNET_OK; // use localhost as source for that one udp-port, ok for testing
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n"));
  }
err:
  GNUNET_free_non_null (tmp);
  GNUNET_free (helper);

  if (GNUNET_OK == ext_ip && GNUNET_YES == nated && GNUNET_OK == binary)
    ah->task = GNUNET_SCHEDULER_add_now (&reversal_test, ah);
  else
    next_phase (ah);

}
Exemplo n.º 5
0
/**
 * Test if UPnPC works.
 *
 * @param ah auto setup context
 */
static void
test_upnpc (struct GNUNET_NAT_AutoHandle *ah)
{

  int have_upnpc;

  if (GNUNET_NAT_ERROR_SUCCESS != ah->ret)
    next_phase (ah);

  // test if upnpc is available
  have_upnpc = (GNUNET_SYSERR !=
		GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL));
  //FIXME: test if upnpc is actually working, that is, if transports start to work once we use UPnP
  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
	      (have_upnpc)
	      ? _("upnpc found, enabling its use\n")
	      : _("upnpc not found\n"));
  GNUNET_CONFIGURATION_set_value_string (ah->cfg, "nat", "ENABLE_UPNP",
					 (GNUNET_YES == have_upnpc) ? "YES" : "NO");
  next_phase (ah);

}
Exemplo n.º 6
0
/**
 * Test if ICMP client is working
 *
 * @param ah auto setup context
 */
static void
test_icmp_client (struct GNUNET_NAT_AutoHandle *ah)
{


  char *tmp;
  char *helper;

  tmp = NULL;
  helper = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-client");
  if ((GNUNET_OK ==
        GNUNET_CONFIGURATION_get_value_string (ah->cfg, "nat", "INTERNAL_ADDRESS",
                                               &tmp)) && (0 < strlen (tmp)))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_client not possible, as we have no internal IPv4 address\n"));
  }
  else
    goto err;

  if (GNUNET_YES !=
      GNUNET_CONFIGURATION_get_value_yesno (ah->cfg, "nat", "BEHIND_NAT")){
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("test_icmp_server not possible, as we are not behind NAT\n"));
  }
  else
    goto err;

  if (GNUNET_YES ==
      GNUNET_OS_check_helper_binary (helper, GNUNET_YES, "-d 127.0.0.1 127.0.0.2 42")){
          // none of these parameters are actually used in privilege testing mode
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("No working gnunet-helper-nat-server found\n"));
  }
err:
  GNUNET_free_non_null (tmp);
  GNUNET_free (helper);

  next_phase (ah);

}
Exemplo n.º 7
0
int
main (int argc, char *const *argv)
{
    char *sbin_iptables;
    char *bin_vpn;
    char *bin_exit;
    char *bin_dns;
    char *srv_dns;
    struct stat s;
    gid_t my_gid;
    char *const iptables_args[] =
    {
        "iptables", "-t", "mangle", "-L", "-v", NULL
    };

    if (0 == access ("/sbin/iptables", X_OK))
        sbin_iptables = "/sbin/iptables";
    else if (0 == access ("/usr/sbin/iptables", X_OK))
        sbin_iptables = "/usr/sbin/iptables";
    else
    {
        fprintf (stderr,
                 "Executable iptables not found in approved directories: %s, skipping\n",
                 strerror (errno));
        return 0;
    }

    if (0 != fork_and_exec (sbin_iptables, iptables_args))
    {
        fprintf (stderr,
                 "Failed to run `iptables -t mangle -L -v'. Skipping test.\n");
        return 0;
    }

    if (0 != ACCESS ("/dev/net/tun", R_OK))
    {
        GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
                                  "access",
                                  "/dev/net/tun");
        fprintf (stderr,
                 "WARNING: System unable to run test, skipping.\n");
        return 0;
    }

    bin_vpn = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
    bin_exit = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
    bin_dns = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-dns");
    srv_dns = GNUNET_OS_get_libexec_binary_path ("gnunet-service-dns");
    if ( (0 != geteuid ()) &&
            ( (GNUNET_YES !=
               GNUNET_OS_check_helper_binary (bin_vpn, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) || //ipv4 only please!
              (GNUNET_YES !=
               GNUNET_OS_check_helper_binary (bin_exit, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")) || //no nat, ipv4 only
              (GNUNET_YES !=
               GNUNET_OS_check_helper_binary (bin_dns, GNUNET_YES, NULL))) ) // TODO: once we have a windows-testcase, add test parameters here
    {
        fprintf (stderr,
                 "WARNING: gnunet-helper-{exit,vpn,dns} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n");
        fprintf (stderr,
                 "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
        GNUNET_free (bin_vpn);
        GNUNET_free (bin_exit);
        GNUNET_free (bin_dns);
        GNUNET_free (srv_dns);
        return 0;
    }
    GNUNET_free (bin_vpn);
    GNUNET_free (bin_exit);
    my_gid = getgid ();
    if ( (0 != stat (bin_dns, &s)) ||
            (my_gid == s.st_gid) ||
            ( (0 == (S_ISUID & s.st_mode)) && (0 != getuid()) ) )
    {
        fprintf (stderr,
                 "WARNING: %s has wrong permissions (%d, %d, %d), refusing to run test (as it would have to fail).\n",
                 bin_dns,
                 (0 != stat (bin_dns, &s)),
                 (my_gid == s.st_gid),
                 (0 == (S_ISUID & s.st_mode)) || (0 != getuid()) );
        GNUNET_free (bin_dns);
        GNUNET_free (srv_dns);
        return 0;
    }
    if ( (0 != stat (srv_dns, &s)) ||
            (my_gid == s.st_gid) ||
            (0 == (S_ISGID & s.st_mode)) )
    {
        fprintf (stderr,
                 "WARNING: %s has wrong permissions (%d, %d, %d), refusing to run test (as it would have to fail).\n",
                 srv_dns,
                 (0 != stat (bin_dns, &s)),
                 (my_gid == s.st_gid),
                 (0 == (S_ISGID & s.st_mode)) );
        GNUNET_free (bin_dns);
        GNUNET_free (srv_dns);
        return 0;
    }
    GNUNET_free (bin_dns);
    GNUNET_free (srv_dns);

    dest_ip = "169.254.86.1";
    dest_af = AF_INET;
    src_af = AF_INET;

    if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
        use_v6 = GNUNET_YES;
    else
        use_v6 = GNUNET_NO;

    if ( (GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
            (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)) )
    {
        fprintf (stderr,
                 "Required address families not supported by this system, skipping test.\n");
        return 0;
    }
    if (0 != curl_global_init (CURL_GLOBAL_WIN32))
    {
        fprintf (stderr, "failed to initialize curl\n");
        return 2;
    }


    if (0 != GNUNET_TESTING_peer_run ("test-gnunet-vpn",
                                      "test_gns_vpn.conf",
                                      &run, NULL))
        return 1;
    GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
    return global_ret;
}
Exemplo n.º 8
0
int
main (int argc, char *const *argv)
{
  const char *type;
  const char *bin;
  char *vpn_binary;
  char *exit_binary;
  int ret=0;

#ifndef MINGW
  if (0 != ACCESS ("/dev/net/tun", R_OK))
  {
    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access",
                              "/dev/net/tun");
    fprintf (stderr,
             "WARNING: System unable to run test, skipping.\n");
    return 0;
  }
#endif
  vpn_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
  exit_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
  if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please!
      (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only
  {
    GNUNET_free (vpn_binary);
    GNUNET_free (exit_binary);
    fprintf (stderr,
             "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret);
    return 0;
  }

  GNUNET_free (vpn_binary);
  GNUNET_free (exit_binary);
  bin = argv[0];
  if (NULL != strstr (bin, "lt-"))
    bin = strstr (bin, "lt-") + 4;
  type = strstr (bin, "-");
  if (NULL == type)
  {
    fprintf (stderr,
             "invalid binary name\n");
    return 1;
  }
  type++;
  /* on Windows, .exe is suffixed to these binaries,
   * thus cease comparison after the 6th char.
   */
  if (0 == strncmp (type, "4_to_6",6))
  {
    dest_ip = "FC5A:04E1:C2BA::1";
    dest_af = AF_INET6;
    src_af = AF_INET;
  }
  else if (0 == strncmp (type, "6_to_4",6))
  {
    dest_ip = "169.254.86.1";
    dest_af = AF_INET;
    src_af = AF_INET6;
  }
  else if (0 == strncmp (type, "4_over",6))
  {
    dest_ip = "169.254.86.1";
    dest_af = AF_INET;
    src_af = AF_INET;
  }
  else if (0 == strncmp (type, "6_over",6))
  {
    dest_ip = "FC5A:04E1:C2BA::1";
    dest_af = AF_INET6;
    src_af = AF_INET6;
  }
  else
  {
    fprintf (stderr, "invalid binary suffix `%s'\n", type);
    return 1;
  }
  if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
      (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)))
  {
    fprintf (stderr,
             "Required address families not supported by this system, skipping test.\n");
    return 0;
  }
  if (0 != curl_global_init (CURL_GLOBAL_WIN32))
  {
    fprintf (stderr, "failed to initialize curl\n");
    return 2;
  }
  if (0 !=
      GNUNET_TESTING_peer_run ("test-gnunet-vpn", "test_gnunet_vpn.conf", &run,
                               NULL))
    return 1;
  GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
  return global_ret;
}
Exemplo n.º 9
0
/**
 * Try to get the external IPv4 address of this peer.
 *
 * @param cb function to call with result
 * @param cb_cls closure for @a cb
 * @return handle for cancellation (can only be used until @a cb is called), never NULL
 */
struct GNUNET_NAT_ExternalHandle *
GNUNET_NAT_mini_get_external_ipv4_ (GNUNET_NAT_IPCallback cb,
				    void *cb_cls)
{
  struct GNUNET_NAT_ExternalHandle *eh;

  eh = GNUNET_new (struct GNUNET_NAT_ExternalHandle);
  eh->cb = cb;
  eh->cb_cls = cb_cls;
  eh->ret = GNUNET_NAT_ERROR_SUCCESS;
  if (GNUNET_SYSERR ==
      GNUNET_OS_check_helper_binary ("external-ip",
				     GNUNET_NO,
				     NULL))
  {
    LOG (GNUNET_ERROR_TYPE_INFO,
	 _("`external-ip' command not found\n"));
    eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND;
    eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
                                         eh);
    return eh;
  }
  LOG (GNUNET_ERROR_TYPE_DEBUG,
       "Running `external-ip' to determine our external IP\n");
  eh->opipe = GNUNET_DISK_pipe (GNUNET_YES,
				GNUNET_YES,
				GNUNET_NO,
				GNUNET_YES);
  if (NULL == eh->opipe)
  {
    eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
    eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
                                         eh);
    return eh;
  }
  eh->eip =
      GNUNET_OS_start_process (GNUNET_NO,
			       0,
			       NULL,
			       eh->opipe,
			       NULL,
                               "external-ip",
			       "external-ip",
                               NULL);
  if (NULL == eh->eip)
  {
    GNUNET_DISK_pipe_close (eh->opipe);
    eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED;
    eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
                                         eh);
    return eh;
  }
  GNUNET_DISK_pipe_close_end (eh->opipe,
			      GNUNET_DISK_PIPE_END_WRITE);
  eh->r = GNUNET_DISK_pipe_handle (eh->opipe,
				   GNUNET_DISK_PIPE_END_READ);
  eh->task 
    = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
                                      eh->r,
                                      &read_external_ipv4,
				      eh);
  return eh;
}