Replace mesh with new version
[oweals/gnunet.git] / src / vpn / gnunet-helper-vpn-windows.c
index b810dc706ccdc90b7594c60f7e2deea788355983..0d31ee3996cbda41809b902f24de1dedafb22b06 100644 (file)
@@ -17,7 +17,6 @@
      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
      Boston, MA 02111-1307, USA.
  */
-
 /**
  * @file vpn/gnunet-helper-vpn-windows.c
  * @brief the helper for the VPN service in win32 builds. 
  */
 
 #include <stdio.h>
+#include <Winsock2.h>
 #include <windows.h>
 #include <setupapi.h>
+#ifndef __MINGW64_VERSION_MAJOR
 #include <ddk/cfgmgr32.h>
 #include <ddk/newdev.h>
-#include <Winsock2.h>
+#else
+#include <cfgmgr32.h>
+#include <newdev.h>
+#endif
 #include <time.h>
 #include "platform.h"
 #include "tap-windows.h"
 #define LOG_DEBUG(msg) do {} while (0)
 #endif
 
+/**
+ * Will this binary be run in permissions testing mode? 
+ */
+static boolean privilege_testing = FALSE;
 
 /**
  * Maximum size of a GNUnet message (GNUNET_SERVER_MAX_MESSAGE_SIZE)
  * Name or Path+Name of our win32 driver.
  * The .sys and .cat files HAVE to be in the same location as this file!
  */
-#define INF_FILE "share/gnunet/tapw32/OemWin2k.inf"
+#define INF_FILE "share/gnunet/openvpn-tap32/tapw32/OemWin2k.inf"
 
 /**
  * Name or Path+Name of our win64 driver.
  * The .sys and .cat files HAVE to be in the same location as this file!
  */
-#define INF_FILE64 "share/gnunet/tapw64/OemWin2k.inf"
+#define INF_FILE64 "share/gnunet/openvpn-tap32/tapw64/OemWin2k.inf"
 
 /**
  * Hardware ID used in the inf-file. 
@@ -335,9 +343,7 @@ set_address6 (const char *address, unsigned long prefix_len)
 /**
  * @brief Removes the IPv6-Address given in address from the interface dev
  *
- * @param dev the interface to remove
  * @param address the IPv4-Address
- * @param mask the netmask
  */
 static void
 remove_address6 (const char *address)
@@ -366,7 +372,6 @@ remove_address6 (const char *address)
 /**
  * @brief Sets the IPv4-Address given in address on the interface dev
  *
- * @param dev the interface to configure
  * @param address the IPv4-Address
  * @param mask the netmask
  */
@@ -388,8 +393,7 @@ set_address4 (const char *address, const char *mask)
                strerror (errno));
       return -1;
     }
-  // Set Device to Subnet-Mode? 
-  // do we really need tun.c:2925 ?
+  // Set Device to Subnet-Mode? do we really need openvpn/tun.c:2925 ?
 
   /*
    * prepare the command
@@ -412,9 +416,7 @@ set_address4 (const char *address, const char *mask)
 /**
  * @brief Removes the IPv4-Address given in address from the interface dev
  *
- * @param dev the interface to remove
  * @param address the IPv4-Address
- * @param mask the netmask
  */
 static void
 remove_address4 (const char *address)
@@ -1335,7 +1337,7 @@ initialize_io_facility (struct io_facility * elem,
 /**
  * Start forwarding to and from the tunnel.
  *
- * @param fd_tun tunnel FD
+ * @param tap_handle device handle for interacting with the Virtual interface
  */
 static void
 run (HANDLE tap_handle)
@@ -1359,8 +1361,8 @@ run (HANDLE tap_handle)
    * DHCP and such are all features we will never use in gnunet afaik.
    * But for openvpn those are essential.
    */
-  if (! tun_up (tap_handle))
-    return;
+  if ((privilege_testing) || (! tun_up (tap_handle)))
+    goto teardown_final;
 
   /* Initialize our overlapped IO structures*/
   if (! (initialize_io_facility (&tap_read, IOSTATE_READY, FALSE)
@@ -1414,9 +1416,9 @@ run (HANDLE tap_handle)
       goto teardown;
     }
 #endif
-  
+
   fprintf (stderr, "DEBUG: mainloop has begun\n");
-  
+
   while (std_out.path_open || tap_write.path_open)
     {
       /* perform READ from stdin if possible */
@@ -1436,16 +1438,12 @@ run (HANDLE tap_handle)
         break;
     }
 
-teardown:
-
   fprintf (stderr, "DEBUG: teardown initiated\n");
-      
+teardown:
   CancelIo (tap_handle);
   CancelIo (std_in.handle);
   CancelIo (std_out.handle);
-
 teardown_final:
-      
   CloseHandle (tap_handle);
 }
 
@@ -1455,11 +1453,12 @@ teardown_final:
  *
  * @param argc must be 6
  * @param argv 0: binary name (gnunet-helper-vpn)
- *             1: tunnel interface prefix (gnunet-vpn)
- *             2: IPv6 address (::1), "-" to disable
- *             3: IPv6 netmask length in bits (64), ignored if #2 is "-"
- *             4: IPv4 address (1.2.3.4), "-" to disable
- *             5: IPv4 netmask (255.255.0.0), ignored if #4 is "-"
+ *             [1: dryrun/testrun (does not execute mainloop)]
+ *             2: tunnel interface prefix (gnunet-vpn)
+ *             3: IPv6 address (::1), "-" to disable
+ *             4: IPv6 netmask length in bits (64), ignored if #2 is "-"
+ *             5: IPv4 address (1.2.3.4), "-" to disable
+ *             6: IPv4 netmask (255.255.0.0), ignored if #4 is "-"
  */
 int
 main (int argc, char **argv)
@@ -1469,10 +1468,17 @@ main (int argc, char **argv)
   int global_ret = 0;
   BOOL have_ip4 = FALSE;
   BOOL have_ip6 = FALSE;
-
+  
+  if (argc > 1 && 0 != strcmp (argv[1], "-d")){
+      privilege_testing = TRUE;
+      fprintf (stderr, "DEBUG: Running binary in privilege testing mode.", argv[0]);
+      argv++;
+      argc--;
+    }
+  
   if (6 != argc)
     {
-      fprintf (stderr, "FATAL: must supply 5 arguments\nUsage:\ngnunet-helper-vpn <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n", argv[0]);
+      fprintf (stderr, "FATAL: must supply 5 arguments\nUsage:\ngnunet-helper-vpn [-d] <if name prefix> <address6 or \"-\"> <netbits6> <address4 or \"-\"> <netmask4>\n", argv[0]);
       return 1;
     }
 
@@ -1533,7 +1539,6 @@ main (int argc, char **argv)
     }
 
   run (handle);
-  global_ret = 0;
 cleanup:
 
   if (have_ip4)