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