/** * Starts a helper and begins reading from it. The helper process is * restarted when it dies except when it is stopped using GNUNET_HELPER_stop() * or when the exp_cb callback is not NULL. * * @param with_control_pipe does the helper support the use of a control pipe for signalling? * @param binary_name name of the binary to run * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this * argument must not be modified by the client for * the lifetime of the helper handle) * @param cb function to call if we get messages from the helper * @param exp_cb the exception callback to call. Set this to NULL if the helper * process has to be restarted automatically when it dies/crashes * @param cb_cls closure for the above callback * @return the new Handle, NULL on error */ struct GNUNET_HELPER_Handle * GNUNET_HELPER_start (int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_SERVER_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls) { struct GNUNET_HELPER_Handle *h; unsigned int c; h = GNUNET_new (struct GNUNET_HELPER_Handle); h->with_control_pipe = with_control_pipe; /* Lookup in libexec path only if we are starting gnunet helpers */ if (NULL != strstr (binary_name, "gnunet")) h->binary_name = GNUNET_OS_get_libexec_binary_path (binary_name); else h->binary_name = GNUNET_strdup (binary_name); for (c = 0; NULL != binary_argv[c]; c++); h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1)); for (c = 0; NULL != binary_argv[c]; c++) h->binary_argv[c] = GNUNET_strdup (binary_argv[c]); h->binary_argv[c] = NULL; h->cb_cls = cb_cls; if (NULL != cb) h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls); h->exp_cb = exp_cb; h->retry_back_off = 0; start_helper (h); return h; }
/** * Test killing via pipe. */ static int check_instant_kill () { char *fn; hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) { return 1; } fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, NULL, fn, "gnunet-service-resolver", "-", NULL); if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); } GNUNET_free (fn); GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); GNUNET_OS_process_destroy (proc); proc = NULL; GNUNET_DISK_pipe_close (hello_pipe_stdout); GNUNET_DISK_pipe_close (hello_pipe_stdin); return 0; }
static void setup_peer (struct PeerContext *p, const char *cfgname) { char *binary; binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, binary, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); p->ats = GNUNET_ATS_connectivity_init (p->cfg); GNUNET_assert (NULL != p->ats); p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, GNUNET_TRANSPORT_AC_ANY, &process_hello, p); GNUNET_free (binary); }
static int check () { char *const argv[] = { "test-sensor-api", NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; struct GNUNET_OS_Process *proc; char *path = GNUNET_OS_get_libexec_binary_path ("gnunet-service-sensor"); if (NULL == path) { fprintf (stderr, "Service executable not found `%s'\n", "gnunet-service-sensor"); return -1; } proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, NULL, NULL, path, "gnunet-service-sensor", NULL); GNUNET_free (path); GNUNET_assert (NULL != proc); GNUNET_PROGRAM_run (1, argv, "test-sensor-api", "nohelp", options, &run, &ok); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); return ok; }
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; }
int main (int argc, char *const argv[]) { struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; char *const argv_prog[] = { "test-stun", "-c", "test_stun.conf", NULL }; char *fn; struct GNUNET_OS_Process *proc; GNUNET_log_setup ("test-stun", "WARNING", NULL); /* Lets start resolver */ fn = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, fn, "gnunet-service-resolver", "-c", "test_stun.conf", NULL); if (NULL == proc) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, "This test was unable to start gnunet-service-resolver, and it is required to run ...\n"); exit(1); } GNUNET_PROGRAM_run (3, argv_prog, "test-stun", "nohelp", options, &run, NULL); /* Now kill the resolver */ if (0 != GNUNET_OS_process_kill (proc, GNUNET_TERM_SIG)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; GNUNET_free (fn); return ret; }
/** * Checks whether a host can be used to start testbed service * * @param host the host to check * @param config the configuration handle to lookup the path of the testbed * helper * @param cb the callback to call to inform about habitability of the given host * @param cb_cls the closure for the callback * @return NULL upon any error or a handle which can be passed to * GNUNET_TESTBED_is_host_habitable_cancel() */ struct GNUNET_TESTBED_HostHabitableCheckHandle * GNUNET_TESTBED_is_host_habitable (const struct GNUNET_TESTBED_Host *host, const struct GNUNET_CONFIGURATION_Handle *config, GNUNET_TESTBED_HostHabitableCallback cb, void *cb_cls) { struct GNUNET_TESTBED_HostHabitableCheckHandle *h; char **rsh_args; char **rsh_suffix_args; char *stat_args[3]; const char *hostname; char *port; h = GNUNET_new (struct GNUNET_TESTBED_HostHabitableCheckHandle); h->cb = cb; h->cb_cls = cb_cls; h->host = host; hostname = (NULL == host->hostname) ? "127.0.0.1" : host->hostname; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (config, "testbed", "HELPER_BINARY_PATH", &stat_args[1])) stat_args[1] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); GNUNET_asprintf (&port, "%u", host->port); rsh_args = gen_rsh_args (port, hostname, host->username); GNUNET_free (port); port = NULL; stat_args[0] = "stat"; stat_args[2] = NULL; rsh_suffix_args = gen_rsh_suffix_args ((const char **) stat_args); GNUNET_free (stat_args[1]); h->helper_argv = join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); free_argv (rsh_suffix_args); free_argv (rsh_args); h->auxp = GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, NULL, NULL, NULL, h->helper_argv[0], h->helper_argv); if (NULL == h->auxp) { GNUNET_break (0); /* Cannot exec SSH? */ GNUNET_free (h); return NULL; } h->wait_time = GNUNET_TIME_STD_BACKOFF (h->wait_time); h->habitability_check_task = GNUNET_SCHEDULER_add_delayed (h->wait_time, &habitability_check, h); return h; }
static void setup_peer (struct PeerContext *p, const char *cfgname) { char *binary; binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); GNUNET_free (binary); }
/** * 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); }
int main (int argc, char *argv_ign[]) { char *const argv[] = { "test-statistics-api", "-c", "test_statistics_api_data.conf", NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; struct GNUNET_OS_Process *proc; char *binary; binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary, "gnunet-service-statistics", "-c", "test_statistics_api_data.conf", NULL); GNUNET_assert (NULL != proc); ok = 3; ok2 = 1; GNUNET_PROGRAM_run (3, argv, "test-statistics-api", "nohelp", options, &run, NULL); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; GNUNET_free (binary); if ((0 == ok) && (0 == ok2)) return 0; return 1; }
/** * 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); }
static void setup_learn_peer (struct PeerContext *p, const char *cfgname) { char *filename; unsigned int result; char *binary; binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, binary, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, "HOSTLIST", "HOSTLISTFILE", &filename)) { if (GNUNET_YES == GNUNET_DISK_file_test (filename)) { result = UNLINK (filename); if (result == 0) GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Hostlist file `%s' was removed\n"), filename); } GNUNET_free (filename); } p->core = GNUNET_CORE_connect (p->cfg, NULL, NULL, NULL, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, learn_handlers); GNUNET_assert (NULL != p->core); p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); GNUNET_assert (NULL != p->stats); GNUNET_free (binary); }
/** * A client specifically requested starting of ARM itself. * This function is called with information about whether * or not ARM is running; if it is, report success. If * it is not, start the ARM process. * * @param cls the context for the request that we will report on (struct ARMControlMessage *) * @param result GNUNET_YES if ARM is running */ static void arm_service_report (void *cls, int result) { struct ARMControlMessage *cm = cls; struct GNUNET_ARM_Handle *h; struct GNUNET_OS_Process *proc; unsigned char test_is_active; char *cbinary; char *binary; char *quotedbinary; char *config; char *loprefix; char *lopostfix; test_is_active = cm->h->service_test_is_active; if ((GNUNET_YES == test_is_active) && (GNUNET_YES == result)) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Looks like `%s' is already running.\n", "gnunet-service-arm"); /* arm is running! */ if (cm->result_cont) cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_IS_STARTED_ALREADY); } if (GNUNET_NO == test_is_active) { /* User disconnected & destroyed ARM handle in the middle of * the service test, so we kept the handle around until now. */ GNUNET_CONFIGURATION_destroy (cm->h->cfg); GNUNET_free (cm->h); } if ((GNUNET_YES == result) || (GNUNET_NO == test_is_active)) { GNUNET_free (cm); return; } cm->h->service_test_is_active = GNUNET_NO; LOG (GNUNET_ERROR_TYPE_DEBUG, "Looks like `%s' is not running, will start it.\n", "gnunet-service-arm"); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string ( cm->h->cfg, "arm", "PREFIX", &loprefix)) loprefix = GNUNET_strdup (""); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string ( cm->h->cfg, "arm", "OPTIONS", &lopostfix)) lopostfix = GNUNET_strdup (""); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string ( cm->h->cfg, "arm", "BINARY", &cbinary)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY"); if (cm->result_cont) cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_IS_NOT_KNOWN); GNUNET_free (cm); GNUNET_free (loprefix); GNUNET_free (lopostfix); return; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename ( cm->h->cfg, "arm", "CONFIG", &config)) config = NULL; binary = GNUNET_OS_get_libexec_binary_path (cbinary); GNUNET_asprintf ("edbinary, "\"%s\"", binary); GNUNET_free (cbinary); if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value ( cm->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno ( cm->h->cfg, "TESTING", "WEAKRANDOM")) && (GNUNET_NO == GNUNET_CONFIGURATION_have_value ( cm->h->cfg, "TESTING", "HOSTFILE"))) { /* Means we are ONLY running locally */ /* we're clearly running a test, don't daemonize */ if (NULL == config) proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, NULL, loprefix, quotedbinary, /* no daemonization! */ lopostfix, NULL); else proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, NULL, loprefix, quotedbinary, "-c", config, /* no daemonization! */ lopostfix, NULL); } else { if (NULL == config) proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, NULL, loprefix, quotedbinary, "-d", lopostfix, NULL); else proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance, NULL, loprefix, quotedbinary, "-c", config, "-d", lopostfix, NULL); } GNUNET_free (binary); GNUNET_free (quotedbinary); GNUNET_free_non_null (config); GNUNET_free (loprefix); GNUNET_free (lopostfix); if (NULL == proc) { if (cm->result_cont) cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_START_FAILED); GNUNET_free (cm); return; } if (cm->result_cont) cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_STARTING); GNUNET_OS_process_destroy (proc); h = cm->h; GNUNET_free (cm); reconnect_arm (h); }
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; }
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; }
/** * Test our plugin's configuration (NAT traversal, etc.). * * @param cfg configuration to test */ static void do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) { char *plugins; char *tok; unsigned long long bnd_port; unsigned long long adv_port; struct TestContext *tc; char *binary; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins", &plugins)) { FPRINTF (stderr, "%s", _ ("No transport plugins configured, peer will never communicate\n") ); ret = 4; return; } for (tok = strtok (plugins, " "); tok != NULL ; tok = strtok (NULL, " ")) { char section[12 + strlen (tok)]; GNUNET_snprintf (section, sizeof(section), "transport-%s", tok); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port)) { FPRINTF (stderr, _("No port configured for plugin `%s', cannot test it\n"), tok); continue; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT", &adv_port)) adv_port = bnd_port; if (NULL == resolver) { binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-resolver"); resolver = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, binary, "gnunet-service-resolver", NULL ); GNUNET_free(binary); } resolver_users++; GNUNET_RESOLVER_connect (cfg); tc = GNUNET_new (struct TestContext); tc->name = GNUNET_strdup (tok); tc->tst = GNUNET_NAT_test_start (cfg, (0 == strcasecmp (tok, "udp")) ? GNUNET_NO : GNUNET_YES, (uint16_t) bnd_port, (uint16_t) adv_port, &result_callback, tc); if (NULL == tc->tst) { display_test_result (tc, GNUNET_SYSERR); continue; } tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc); } GNUNET_free(plugins); }
/** * Starts a controller process at the given host. The given host's configration * is used as a Template configuration to use for the remote controller; the * remote controller will be started with a slightly modified configuration * (port numbers, unix domain sockets and service home values are changed as per * TESTING library on the remote host). The modified configuration replaces the * host's existing configuration before signalling success through the * GNUNET_TESTBED_ControllerStatusCallback() * * @param trusted_ip the ip address of the controller which will be set as TRUSTED * HOST(all connections form this ip are permitted by the testbed) when * starting testbed controller at host. This can either be a single ip * address or a network address in CIDR notation. * @param host the host where the controller has to be started. CANNOT be NULL. * @param cb function called when the controller is successfully started or * dies unexpectedly; GNUNET_TESTBED_controller_stop shouldn't be * called if cb is called with GNUNET_SYSERR as status. Will never be * called in the same task as 'GNUNET_TESTBED_controller_start' * (synchronous errors will be signalled by returning NULL). This * parameter cannot be NULL. * @param cls closure for above callbacks * @return the controller process handle, NULL on errors */ struct GNUNET_TESTBED_ControllerProc * GNUNET_TESTBED_controller_start (const char *trusted_ip, struct GNUNET_TESTBED_Host *host, GNUNET_TESTBED_ControllerStatusCallback cb, void *cls) { struct GNUNET_TESTBED_ControllerProc *cp; struct GNUNET_TESTBED_HelperInit *msg; const struct GNUNET_CONFIGURATION_Handle *cfg; const char *hostname; static char *const binary_argv[] = { HELPER_TESTBED_BINARY, NULL }; GNUNET_assert (NULL != host); GNUNET_assert (NULL != (cfg = GNUNET_TESTBED_host_get_cfg_ (host))); hostname = NULL; API_VIOLATION (GNUNET_NO == host->locked, "Host is already locked by a previous call to GNUNET_TESTBED_controller_start()"); host->locked = GNUNET_YES; API_VIOLATION (GNUNET_NO == host->controller_started, "Attempting to start a controller on a host which is already started a controller"); cp = GNUNET_new (struct GNUNET_TESTBED_ControllerProc); if (0 == GNUNET_TESTBED_host_get_id_ (host)) { cp->helper = GNUNET_HELPER_start (GNUNET_YES, HELPER_TESTBED_BINARY, binary_argv, &helper_mst, &helper_exp_cb, cp); } else { char *helper_binary_path_args[2]; char **rsh_args; char **rsh_suffix_args; const char *username; char *port; char *argstr; char *aux; unsigned int cnt; username = host->username; hostname = host->hostname; GNUNET_asprintf (&port, "%u", host->port); LOG_DEBUG ("Starting remote connection to destination %s\n", hostname); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "testbed", "HELPER_BINARY_PATH", &helper_binary_path_args[0])) helper_binary_path_args[0] = GNUNET_OS_get_libexec_binary_path (HELPER_TESTBED_BINARY); helper_binary_path_args[1] = NULL; rsh_args = gen_rsh_args (port, hostname, username); rsh_suffix_args = gen_rsh_suffix_args ((const char **) helper_binary_path_args); cp->helper_argv = join_argv ((const char **) rsh_args, (const char **) rsh_suffix_args); free_argv (rsh_args); free_argv (rsh_suffix_args); GNUNET_free (port); argstr = GNUNET_strdup (""); for (cnt = 0; NULL != cp->helper_argv[cnt]; cnt++) { aux = argstr; GNUNET_assert (0 < GNUNET_asprintf (&argstr, "%s %s", aux, cp->helper_argv[cnt])); GNUNET_free (aux); } LOG_DEBUG ("Helper cmd str: %s\n", argstr); GNUNET_free (argstr); cp->helper = GNUNET_HELPER_start (GNUNET_NO, cp->helper_argv[0], cp->helper_argv, &helper_mst, &helper_exp_cb, cp); GNUNET_free (helper_binary_path_args[0]); } if (NULL == cp->helper) { if (NULL != cp->helper_argv) free_argv (cp->helper_argv); GNUNET_free (cp); return NULL; } cp->host = host; cp->cb = cb; cp->cls = cls; msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, hostname, cfg); cp->msg = &msg->header; cp->shandle = GNUNET_HELPER_send (cp->helper, &msg->header, GNUNET_NO, &clear_msg, cp); if (NULL == cp->shandle) { GNUNET_free (msg); GNUNET_TESTBED_controller_stop (cp); return NULL; } return cp; }
int main (int argc, char *argv_ign[]) { int ok = 1; char *const argv[] = { "test-statistics-api", "-c", "test_statistics_api_data.conf", "-L", "WARNING", NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; struct GNUNET_OS_Process *proc; char *binary; GNUNET_log_setup ("test_statistics_api", "WARNING", NULL); binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-statistics"); proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary, "gnunet-service-statistics", "-c", "test_statistics_api_data.conf", NULL); GNUNET_assert (NULL != proc); GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run, &ok); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; if (ok != 0) { GNUNET_free (binary); return ok; } ok = 1; /* restart to check persistence! */ proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary, "gnunet-service-statistics", "-c", "test_statistics_api_data.conf", NULL); GNUNET_PROGRAM_run (5, argv, "test-statistics-api", "nohelp", options, &run_more, &ok); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; GNUNET_free (binary); return ok; }