-fix ftbfs
[oweals/gnunet.git] / src / pt / test_gns_vpn.c
1 /*
2      This file is part of GNUnet
3      Copyright (C) 2007, 2009, 2011, 2012, 2015 Christian Grothoff
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file test_gns_vpn.c
23  * @brief testcase for accessing VPN services via GNS
24  * @author Martin Schanzenbach
25  */
26 #include "platform.h"
27 #include <curl/curl.h>
28 #include <microhttpd.h>
29 #include "gnunet_identity_service.h"
30 #include "gnunet_namestore_service.h"
31 #include "gnunet_gnsrecord_lib.h"
32 #include "gnunet_gns_service.h"
33 #include "gnunet_testing_lib.h"
34
35 #define PORT 8080
36 #define TEST_DOMAIN "www.gnu"
37
38 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
39
40 /**
41  * Return value for #main().
42  */
43 static int global_ret;
44
45 static struct GNUNET_NAMESTORE_Handle *namestore;
46
47 static struct MHD_Daemon *mhd;
48
49 static struct GNUNET_SCHEDULER_Task *mhd_task_id;
50
51 static struct GNUNET_SCHEDULER_Task *curl_task_id;
52
53 static struct GNUNET_IDENTITY_Handle *identity;
54
55 static struct GNUNET_NAMESTORE_QueueEntry *qe;
56
57 static CURL *curl;
58
59 static CURLM *multi;
60
61 static char *url;
62
63 static struct GNUNET_PeerIdentity id;
64
65 /**
66  * IP address of the ultimate destination.
67  */
68 static const char *dest_ip;
69
70 /**
71  * Address family of the dest_ip.
72  */
73 static int dest_af;
74
75 /**
76  * Address family to use by the curl client.
77  */
78 static int src_af;
79
80 static int use_v6;
81
82
83 struct CBC
84 {
85   char buf[1024];
86   size_t pos;
87 };
88
89 static struct CBC cbc;
90
91
92 static size_t
93 copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx)
94 {
95   struct CBC *cbc = ctx;
96
97   if (cbc->pos + size * nmemb > sizeof(cbc->buf))
98     return 0;                   /* overflow */
99   memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
100   cbc->pos += size * nmemb;
101   return size * nmemb;
102 }
103
104
105 static int
106 mhd_ahc (void *cls,
107           struct MHD_Connection *connection,
108           const char *url,
109           const char *method,
110           const char *version,
111           const char *upload_data, size_t *upload_data_size,
112           void **unused)
113 {
114   static int ptr;
115   struct MHD_Response *response;
116   int ret;
117
118   if (0 != strcmp ("GET", method))
119     return MHD_NO;              /* unexpected method */
120   if (&ptr != *unused)
121   {
122     *unused = &ptr;
123     return MHD_YES;
124   }
125   *unused = NULL;
126   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url);
127   response = MHD_create_response_from_buffer (strlen (url),
128                                               (void *) url,
129                                               MHD_RESPMEM_MUST_COPY);
130   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
131   MHD_destroy_response (response);
132   if (ret == MHD_NO)
133     abort ();
134   return ret;
135 }
136
137
138 static void
139 do_shutdown (void *cls,
140              const struct GNUNET_SCHEDULER_TaskContext *c)
141 {
142   if (mhd_task_id != NULL)
143   {
144     GNUNET_SCHEDULER_cancel (mhd_task_id);
145     mhd_task_id = NULL;
146   }
147   if (curl_task_id != NULL)
148   {
149     GNUNET_SCHEDULER_cancel (curl_task_id);
150     curl_task_id = NULL;
151   }
152   if (NULL != mhd)
153   {
154     MHD_stop_daemon (mhd);
155     mhd = NULL;
156   }
157   if (NULL != identity)
158   {
159     GNUNET_IDENTITY_disconnect (identity);
160     identity = NULL;
161   }
162   if (NULL != qe)
163   {
164     GNUNET_NAMESTORE_cancel (qe);
165     qe = NULL;
166   }
167   GNUNET_free_non_null (url);
168   url = NULL;
169 }
170
171
172 /**
173  * Function to run the HTTP client.
174  */
175 static void
176 curl_main (void);
177
178
179 static void
180 curl_task (void *cls,
181           const struct GNUNET_SCHEDULER_TaskContext *tc)
182 {
183   curl_task_id = NULL;
184   curl_main ();
185 }
186
187
188 static void
189 curl_main ()
190 {
191   fd_set rs;
192   fd_set ws;
193   fd_set es;
194   int max;
195   struct GNUNET_NETWORK_FDSet nrs;
196   struct GNUNET_NETWORK_FDSet nws;
197   struct GNUNET_TIME_Relative delay;
198   long timeout;
199   int running;
200   struct CURLMsg *msg;
201
202   max = 0;
203   FD_ZERO (&rs);
204   FD_ZERO (&ws);
205   FD_ZERO (&es);
206   curl_multi_perform (multi, &running);
207   if (running == 0)
208   {
209     GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running)));
210     if (msg->msg == CURLMSG_DONE)
211     {
212       if (msg->data.result != CURLE_OK)
213       {
214         fprintf (stderr,
215                  "%s failed at %s:%d: `%s'\n",
216                  "curl_multi_perform",
217                 __FILE__,
218                 __LINE__, curl_easy_strerror (msg->data.result));
219         global_ret = 1;
220       }
221     }
222     curl_multi_remove_handle (multi, curl);
223     curl_multi_cleanup (multi);
224     curl_easy_cleanup (curl);
225     curl = NULL;
226     multi = NULL;
227     if (cbc.pos != strlen ("/hello_world"))
228     {
229       GNUNET_break (0);
230       global_ret = 2;
231     }
232     if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
233     {
234       GNUNET_break (0);
235       global_ret = 3;
236     }
237     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n");
238     GNUNET_SCHEDULER_shutdown ();
239     return;
240   }
241   GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max));
242   if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) ||
243        (-1 == timeout) )
244     delay = GNUNET_TIME_UNIT_SECONDS;
245   else
246     delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout);
247   GNUNET_NETWORK_fdset_copy_native (&nrs,
248                                     &rs,
249                                     max + 1);
250   GNUNET_NETWORK_fdset_copy_native (&nws,
251                                     &ws,
252                                     max + 1);
253   curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
254                                               delay,
255                                               &nrs,
256                                               &nws,
257                                               &curl_task,
258                                               NULL);
259 }
260
261
262 static void
263 start_curl (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
264 {
265   GNUNET_asprintf (&url,
266                    "http://%s/hello_world",
267                    TEST_DOMAIN);
268   curl = curl_easy_init ();
269   curl_easy_setopt (curl, CURLOPT_URL, url);
270   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
271   curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc);
272   curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1);
273   curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
274   curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 150L);
275   curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
276
277   multi = curl_multi_init ();
278   GNUNET_assert (multi != NULL);
279   GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
280   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
281               "Beginning HTTP download from `%s'\n",
282               url);
283   curl_main ();
284 }
285
286
287 static void
288 disco_ns (void* cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
289 {
290   GNUNET_NAMESTORE_disconnect (namestore);
291   namestore = NULL;
292 }
293
294
295 /**
296  * Callback invoked from the namestore service once record is
297  * created.
298  *
299  * @param cls closure
300  * @param af address family, AF_INET or AF_INET6; AF_UNSPEC on error;
301  *                will match 'result_af' from the request
302  * @param address IP address (struct in_addr or struct in_addr6, depending on 'af')
303  *                that the VPN allocated for the redirection;
304  *                traffic to this IP will now be redirected to the
305  *                specified target peer; NULL on error
306  */
307 static void
308 commence_testing (void *cls,
309                   int32_t success,
310                   const char *emsg)
311 {
312   qe = NULL;
313   GNUNET_SCHEDULER_add_now (&disco_ns, NULL);
314
315   if ((emsg != NULL) && (GNUNET_YES != success))
316   {
317     fprintf (stderr,
318              "NS failed to create record %s\n",
319              emsg);
320     GNUNET_SCHEDULER_shutdown ();
321     return;
322   }
323   /* wait a little bit before downloading, as we just created the record */
324   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
325                                 (GNUNET_TIME_UNIT_SECONDS, 5),
326                                 &start_curl,
327                                 NULL);
328 }
329
330
331 /**
332  * Function to keep the HTTP server running.
333  */
334 static void
335 mhd_main (void);
336
337
338 static void
339 mhd_task (void *cls,
340           const struct GNUNET_SCHEDULER_TaskContext *tc)
341 {
342   mhd_task_id = NULL;
343   MHD_run (mhd);
344   mhd_main ();
345 }
346
347
348 static void
349 mhd_main ()
350 {
351   struct GNUNET_NETWORK_FDSet nrs;
352   struct GNUNET_NETWORK_FDSet nws;
353   fd_set rs;
354   fd_set ws;
355   fd_set es;
356   int max_fd;
357   unsigned MHD_LONG_LONG timeout;
358   struct GNUNET_TIME_Relative delay;
359
360   GNUNET_assert (NULL == mhd_task_id);
361   FD_ZERO (&rs);
362   FD_ZERO (&ws);
363   FD_ZERO (&es);
364   max_fd = -1;
365   GNUNET_assert (MHD_YES ==
366                  MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd));
367   if (MHD_YES == MHD_get_timeout (mhd, &timeout))
368     delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
369                                            (unsigned int) timeout);
370   else
371     delay = GNUNET_TIME_UNIT_FOREVER_REL;
372   GNUNET_NETWORK_fdset_copy_native (&nrs,
373                                     &rs,
374                                     max_fd + 1);
375   GNUNET_NETWORK_fdset_copy_native (&nws,
376                                     &ws,
377                                     max_fd + 1);
378   mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
379                                              delay,
380                                              &nrs,
381                                              &nws,
382                                              &mhd_task,
383                                              NULL);
384 }
385
386
387
388
389 /**
390  * Open '/dev/null' and make the result the given
391  * file descriptor.
392  *
393  * @param target_fd desired FD to point to /dev/null
394  * @param flags open flags (O_RDONLY, O_WRONLY)
395  */
396 static void
397 open_dev_null (int target_fd,
398                int flags)
399 {
400   int fd;
401
402   fd = open ("/dev/null", flags);
403   if (-1 == fd)
404     abort ();
405   if (fd == target_fd)
406     return;
407   if (-1 == dup2 (fd, target_fd))
408   {
409     (void) close (fd);
410     abort ();
411   }
412   (void) close (fd);
413 }
414
415
416 /**
417  * Run the given command and wait for it to complete.
418  *
419  * @param file name of the binary to run
420  * @param cmd command line arguments (as given to 'execv')
421  * @return 0 on success, 1 on any error
422  */
423 static int
424 fork_and_exec (const char *file,
425                char *const cmd[])
426 {
427   int status;
428   pid_t pid;
429   pid_t ret;
430
431   pid = fork ();
432   if (-1 == pid)
433   {
434     fprintf (stderr,
435              "fork failed: %s\n",
436              strerror (errno));
437     return 1;
438   }
439   if (0 == pid)
440   {
441     /* we are the child process */
442     /* close stdin/stdout to not cause interference
443        with the helper's main protocol! */
444     (void) close (0);
445     open_dev_null (0, O_RDONLY);
446     (void) close (1);
447     open_dev_null (1, O_WRONLY);
448     (void) execv (file, cmd);
449     /* can only get here on error */
450     fprintf (stderr,
451              "exec `%s' failed: %s\n",
452              file,
453              strerror (errno));
454     _exit (1);
455   }
456   /* keep running waitpid as long as the only error we get is 'EINTR' */
457   while ( (-1 == (ret = waitpid (pid, &status, 0))) &&
458           (errno == EINTR) );
459   if (-1 == ret)
460   {
461     fprintf (stderr,
462              "waitpid failed: %s\n",
463              strerror (errno));
464     return 1;
465   }
466   if (! (WIFEXITED (status) && (0 == WEXITSTATUS (status))))
467     return 1;
468   /* child process completed and returned success, we're happy */
469   return 0;
470 }
471
472
473
474 /**
475  * Method called to inform about the egos of this peer.
476  *
477  * When used with #GNUNET_IDENTITY_connect, this function is
478  * initially called for all egos and then again whenever a
479  * ego's name changes or if it is deleted.  At the end of
480  * the initial pass over all egos, the function is once called
481  * with 'NULL' for @a ego. That does NOT mean that the callback won't
482  * be invoked in the future or that there was an error.
483  *
484  * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
485  * this function is only called ONCE, and 'NULL' being passed in
486  * @a ego does indicate an error (i.e. name is taken or no default
487  * value is known).  If @a ego is non-NULL and if '*ctx'
488  * is set in those callbacks, the value WILL be passed to a subsequent
489  * call to the identity callback of #GNUNET_IDENTITY_connect (if
490  * that one was not NULL).
491  *
492  * When an identity is renamed, this function is called with the
493  * (known) @a ego but the NEW @a name.
494  *
495  * When an identity is deleted, this function is called with the
496  * (known) ego and "NULL" for the @a name.  In this case,
497  * the @a ego is henceforth invalid (and the @a ctx should also be
498  * cleaned up).
499  *
500  * @param cls closure
501  * @param ego ego handle
502  * @param ctx context for application to store data for this ego
503  *                 (during the lifetime of this process, initially NULL)
504  * @param name name assigned by the user for this ego,
505  *                   NULL if the user just deleted the ego and it
506  *                   must thus no longer be used
507  */
508 static void
509 identity_cb (void *cls,
510              struct GNUNET_IDENTITY_Ego *ego,
511              void **ctx,
512              const char *name)
513 {
514   const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key;
515   struct GNUNET_GNSRECORD_Data rd;
516   char *rd_string;
517   char *peername;
518
519   if (NULL == name)
520     return;
521   if (NULL == ego)
522   {
523     if (NULL == qe)
524     {
525       fprintf (stderr,
526                "Failed to find master-zone ego\n");
527       GNUNET_SCHEDULER_shutdown ();
528       return;
529     }
530     GNUNET_IDENTITY_disconnect (identity);
531     identity = NULL;
532     return;
533   }
534   GNUNET_assert (NULL != name);
535   if (0 != strcmp (name,
536                    "master-zone"))
537   {
538     fprintf (stderr,
539              "Unexpected name %s\n",
540              name);
541     return;
542   }
543   zone_key = GNUNET_IDENTITY_ego_get_private_key (ego);
544   rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us;
545   peername = GNUNET_strdup (GNUNET_i2s_full (&id));
546   GNUNET_asprintf (&rd_string,
547                    "6 %s %s",
548                    peername,
549                    "www");
550   GNUNET_free (peername);
551   GNUNET_assert (GNUNET_OK ==
552                  GNUNET_GNSRECORD_string_to_value (GNUNET_GNSRECORD_TYPE_VPN,
553                                                    rd_string,
554                                                    (void**) &rd.data,
555                                                    &rd.data_size));
556   rd.record_type = GNUNET_GNSRECORD_TYPE_VPN;
557
558   qe = GNUNET_NAMESTORE_records_store (namestore,
559                                        zone_key,
560                                        "www",
561                                        1, &rd,
562                                        &commence_testing,
563                                        NULL);
564   GNUNET_free ((void**)rd.data);
565   GNUNET_free (rd_string);
566 }
567
568
569 static void
570 run (void *cls,
571      const struct GNUNET_CONFIGURATION_Handle *cfg,
572      struct GNUNET_TESTING_Peer *peer)
573 {
574   enum MHD_FLAG flags;
575
576   char *bin;
577   char *bin_identity;
578   char *bin_gns;
579   char *config;
580
581   if (GNUNET_OK !=
582       GNUNET_CONFIGURATION_get_value_string (cfg,
583                                              "arm",
584                                              "CONFIG",
585                                              &config))
586   {
587     fprintf (stderr,
588              "Failed to locate configuration file. Skipping test.\n");
589     GNUNET_SCHEDULER_shutdown ();
590     return;
591   }
592
593   char *const identity_args[] =
594   {
595     "gnunet-identity",
596     "-C", "master-zone",
597     "-c", config,
598     NULL
599   };
600   char *const identity2_args[] =
601   {
602     "gnunet-identity",
603     "-e", "master-zone",
604     "-s", "gns-master",
605     "-c", config,
606     NULL
607   };
608   char *const identity3_args[] =
609   {
610     "gnunet-identity",
611     "-e", "master-zone",
612     "-s", "gns-intercept",
613     "-c", config,
614     NULL
615   };
616   char *const gns_args[] =
617   {
618     "gnunet-gns",
619     "-u", "www.gns",
620     "-c", config,
621     NULL
622   };
623   GNUNET_TESTING_peer_get_identity (peer, &id);
624   GNUNET_SCHEDULER_add_delayed (TIMEOUT,
625                                 &do_shutdown,
626                                 NULL);
627   bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
628   GNUNET_asprintf (&bin_identity,
629                    "%s/%s",
630                    bin,
631                    "gnunet-identity");
632   if (0 != fork_and_exec (bin_identity, identity_args))
633   {
634     fprintf (stderr,
635              "Failed to run `gnunet-identity -C. Skipping test.\n");
636     GNUNET_SCHEDULER_shutdown ();
637     GNUNET_free (bin_identity);
638     GNUNET_free (config);
639     GNUNET_free (bin);
640     return;
641   }
642   if (0 != fork_and_exec (bin_identity, identity2_args))
643   {
644     fprintf (stderr,
645              "Failed to run `gnunet-identity -e. Skipping test.\n");
646     GNUNET_SCHEDULER_shutdown ();
647     GNUNET_free (bin_identity);
648     GNUNET_free (config);
649     GNUNET_free (bin);
650     return;
651   }
652   if (0 != fork_and_exec (bin_identity, identity3_args))
653   {
654     fprintf (stderr,
655              "Failed to run `gnunet-identity -e. Skipping test.\n");
656     GNUNET_SCHEDULER_shutdown ();
657     GNUNET_free (bin_identity);
658     GNUNET_free (config);
659     GNUNET_free (bin);
660     return;
661   }
662   GNUNET_free (bin_identity);
663
664   /* do lookup just to launch GNS service */
665   GNUNET_asprintf (&bin_gns,
666                    "%s/%s",
667                    bin,
668                    "gnunet-gns");
669   if (0 != fork_and_exec (bin_gns, gns_args))
670   {
671     fprintf (stderr,
672              "Failed to run `gnunet-gns -u. Skipping test.\n");
673     GNUNET_SCHEDULER_shutdown ();
674     GNUNET_free (bin_gns);
675     GNUNET_free (config);
676     GNUNET_free (bin);
677     return;
678   }
679   GNUNET_free (config);
680   GNUNET_free (bin);
681
682
683   namestore = GNUNET_NAMESTORE_connect (cfg);
684   GNUNET_assert (NULL != namestore);
685   flags = MHD_USE_DEBUG;
686   if (GNUNET_YES == use_v6)
687     flags |= MHD_USE_DUAL_STACK;
688   mhd = MHD_start_daemon (flags,
689                           PORT,
690                           NULL, NULL,
691                           &mhd_ahc, NULL,
692                           MHD_OPTION_END);
693   GNUNET_assert (NULL != mhd);
694   mhd_main ();
695
696   identity = GNUNET_IDENTITY_connect (cfg,
697                                       &identity_cb,
698                                       NULL);
699 }
700
701
702 int
703 main (int argc, char *const *argv)
704 {
705   char *sbin_iptables;
706   char *bin_vpn;
707   char *bin_exit;
708   char *bin_dns;
709   char *srv_dns;
710   struct stat s;
711   gid_t my_gid;
712   char *const iptables_args[] =
713   {
714     "iptables", "-t", "mangle", "-L", "-v", NULL
715   };
716
717   if (0 == access ("/sbin/iptables", X_OK))
718     sbin_iptables = "/sbin/iptables";
719   else if (0 == access ("/usr/sbin/iptables", X_OK))
720     sbin_iptables = "/usr/sbin/iptables";
721   else
722   {
723     fprintf (stderr,
724              "Executable iptables not found in approved directories: %s, skipping\n",
725              strerror (errno));
726     return 0;
727   }
728
729   if (0 != fork_and_exec (sbin_iptables, iptables_args))
730   {
731     fprintf (stderr,
732              "Failed to run `iptables -t mangle -L -v'. Skipping test.\n");
733     return 0;
734   }
735
736   if (0 != ACCESS ("/dev/net/tun", R_OK))
737   {
738     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
739                               "access",
740                               "/dev/net/tun");
741     fprintf (stderr,
742              "WARNING: System unable to run test, skipping.\n");
743     return 0;
744   }
745
746   bin_vpn = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn");
747   bin_exit = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit");
748   bin_dns = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-dns");
749   srv_dns = GNUNET_OS_get_libexec_binary_path ("gnunet-service-dns");
750   if ( (0 != geteuid ()) &&
751        ( (GNUNET_YES !=
752           GNUNET_OS_check_helper_binary (bin_vpn, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) || //ipv4 only please!
753          (GNUNET_YES !=
754           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
755          (GNUNET_YES !=
756           GNUNET_OS_check_helper_binary (bin_dns, GNUNET_YES, NULL))) ) // TODO: once we have a windows-testcase, add test parameters here
757   {
758     fprintf (stderr,
759              "WARNING: gnunet-helper-{exit,vpn,dns} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n");
760     fprintf (stderr,
761              "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n");
762     GNUNET_free (bin_vpn);
763     GNUNET_free (bin_exit);
764     GNUNET_free (bin_dns);
765     GNUNET_free (srv_dns);
766     return 0;
767   }
768   GNUNET_free (bin_vpn);
769   GNUNET_free (bin_exit);
770   my_gid = getgid ();
771   if ( (0 != stat (bin_dns, &s)) ||
772        (my_gid == s.st_gid) ||
773        ( (0 == (S_ISUID & s.st_mode)) && (0 != getuid()) ) )
774   {
775     fprintf (stderr,
776              "WARNING: %s has wrong permissions (%d, %d, %d), refusing to run test (as it would have to fail).\n",
777              bin_dns,
778              (0 != stat (bin_dns, &s)),
779              (my_gid == s.st_gid),
780              (0 == (S_ISUID & s.st_mode)) || (0 != getuid()) );
781     GNUNET_free (bin_dns);
782     GNUNET_free (srv_dns);
783     return 0;
784   }
785   if ( (0 != stat (srv_dns, &s)) ||
786        (my_gid == s.st_gid) ||
787        (0 == (S_ISGID & s.st_mode)) )
788   {
789     fprintf (stderr,
790              "WARNING: %s has wrong permissions (%d, %d, %d), refusing to run test (as it would have to fail).\n",
791              srv_dns,
792              (0 != stat (bin_dns, &s)),
793              (my_gid == s.st_gid),
794              (0 == (S_ISGID & s.st_mode)) );
795     GNUNET_free (bin_dns);
796     GNUNET_free (srv_dns);
797     return 0;
798   }
799   GNUNET_free (bin_dns);
800   GNUNET_free (srv_dns);
801
802   dest_ip = "169.254.86.1";
803   dest_af = AF_INET;
804   src_af = AF_INET;
805
806   if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6))
807     use_v6 = GNUNET_YES;
808   else
809     use_v6 = GNUNET_NO;
810
811   if ( (GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) ||
812        (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)) )
813   {
814     fprintf (stderr,
815              "Required address families not supported by this system, skipping test.\n");
816     return 0;
817   }
818   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
819   {
820     fprintf (stderr, "failed to initialize curl\n");
821     return 2;
822   }
823
824
825   if (0 != GNUNET_TESTING_peer_run ("test-gnunet-vpn",
826                                     "test_gns_vpn.conf",
827                                     &run, NULL))
828     return 1;
829   GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn");
830   return global_ret;
831 }
832
833 /* end of test_gns_vpn.c */